diff options
author | fsamuel <fsamuel@chromium.org> | 2015-05-28 09:29:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-28 16:30:23 +0000 |
commit | af5bf6d16b1248654b940eb7337ef9734b384604 (patch) | |
tree | b6836917479c80558eb90a97c80f43b068b8498a /extensions/renderer/guest_view | |
parent | d5f30a32be8b582cb7dc8c2f918b7d0247df01ef (diff) | |
download | chromium_src-af5bf6d16b1248654b940eb7337ef9734b384604.zip chromium_src-af5bf6d16b1248654b940eb7337ef9734b384604.tar.gz chromium_src-af5bf6d16b1248654b940eb7337ef9734b384604.tar.bz2 |
Move GuestViewContainer to components
BUG=444869
Review URL: https://codereview.chromium.org/1129173007
Cr-Commit-Position: refs/heads/master@{#331796}
Diffstat (limited to 'extensions/renderer/guest_view')
7 files changed, 15 insertions, 456 deletions
diff --git a/extensions/renderer/guest_view/extensions_guest_view_container.h b/extensions/renderer/guest_view/extensions_guest_view_container.h index 0a29daf..0626da0 100644 --- a/extensions/renderer/guest_view/extensions_guest_view_container.h +++ b/extensions/renderer/guest_view/extensions_guest_view_container.h @@ -7,7 +7,7 @@ #include <queue> -#include "extensions/renderer/guest_view/guest_view_container.h" +#include "components/guest_view/renderer/guest_view_container.h" #include "v8/include/v8.h" namespace gfx { @@ -16,7 +16,7 @@ class Size; namespace extensions { -class ExtensionsGuestViewContainer : public GuestViewContainer { +class ExtensionsGuestViewContainer : public guest_view::GuestViewContainer { public: explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame); ~ExtensionsGuestViewContainer() override; diff --git a/extensions/renderer/guest_view/guest_view_container.cc b/extensions/renderer/guest_view/guest_view_container.cc deleted file mode 100644 index d09fa00..0000000 --- a/extensions/renderer/guest_view/guest_view_container.cc +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "extensions/renderer/guest_view/guest_view_container.h" - -#include "components/guest_view/common/guest_view_constants.h" -#include "components/guest_view/common/guest_view_messages.h" -#include "content/public/renderer/render_frame.h" -#include "content/public/renderer/render_frame_observer.h" -#include "content/public/renderer/render_view.h" -#include "extensions/common/guest_view/extensions_guest_view_messages.h" -#include "extensions/renderer/guest_view/guest_view_request.h" - -namespace { - -using GuestViewContainerMap = std::map<int, extensions::GuestViewContainer*>; -static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map = - LAZY_INSTANCE_INITIALIZER; - -} // namespace - -namespace extensions { - -class GuestViewContainer::RenderFrameLifetimeObserver - : public content::RenderFrameObserver { - public: - RenderFrameLifetimeObserver(GuestViewContainer* container, - content::RenderFrame* render_frame); - - // content::RenderFrameObserver overrides. - void OnDestruct() override; - - private: - GuestViewContainer* container_; - - DISALLOW_COPY_AND_ASSIGN(RenderFrameLifetimeObserver); -}; - -GuestViewContainer::RenderFrameLifetimeObserver::RenderFrameLifetimeObserver( - GuestViewContainer* container, - content::RenderFrame* render_frame) - : content::RenderFrameObserver(render_frame), - container_(container) {} - -void GuestViewContainer::RenderFrameLifetimeObserver::OnDestruct() { - container_->RenderFrameDestroyed(); -} - -GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame) - : element_instance_id_(guest_view::kInstanceIDNone), - render_frame_(render_frame), - ready_(false) { - render_frame_lifetime_observer_.reset( - new RenderFrameLifetimeObserver(this, render_frame_)); -} - -GuestViewContainer::~GuestViewContainer() { - if (element_instance_id() != guest_view::kInstanceIDNone) - g_guest_view_container_map.Get().erase(element_instance_id()); - - if (pending_response_.get()) - pending_response_->ExecuteCallbackIfAvailable(0 /* argc */, nullptr); - - while (pending_requests_.size() > 0) { - linked_ptr<GuestViewRequest> pending_request = pending_requests_.front(); - pending_requests_.pop_front(); - // Call the JavaScript callbacks with no arguments which implies an error. - pending_request->ExecuteCallbackIfAvailable(0 /* argc */, nullptr); - } -} - -// static. -GuestViewContainer* GuestViewContainer::FromID(int element_instance_id) { - GuestViewContainerMap* guest_view_containers = - g_guest_view_container_map.Pointer(); - auto it = guest_view_containers->find(element_instance_id); - return it == guest_view_containers->end() ? nullptr : it->second; -} - -void GuestViewContainer::RenderFrameDestroyed() { - OnRenderFrameDestroyed(); - render_frame_ = nullptr; -} - -void GuestViewContainer::IssueRequest(linked_ptr<GuestViewRequest> request) { - EnqueueRequest(request); - PerformPendingRequest(); -} - -void GuestViewContainer::EnqueueRequest(linked_ptr<GuestViewRequest> request) { - pending_requests_.push_back(request); -} - -void GuestViewContainer::PerformPendingRequest() { - if (!ready_ || pending_requests_.empty() || pending_response_.get()) - return; - - linked_ptr<GuestViewRequest> pending_request = pending_requests_.front(); - pending_requests_.pop_front(); - pending_request->PerformRequest(); - pending_response_ = pending_request; -} - -void GuestViewContainer::HandlePendingResponseCallback( - const IPC::Message& message) { - CHECK(pending_response_.get()); - linked_ptr<GuestViewRequest> pending_response(pending_response_.release()); - pending_response->HandleResponse(message); -} - -void GuestViewContainer::OnHandleCallback(const IPC::Message& message) { - // Handle the callback for the current request with a pending response. - HandlePendingResponseCallback(message); - // Perform the subsequent request if one exists. - PerformPendingRequest(); -} - -bool GuestViewContainer::OnMessage(const IPC::Message& message) { - return false; -} - -bool GuestViewContainer::OnMessageReceived(const IPC::Message& message) { - if (OnMessage(message)) - return true; - - OnHandleCallback(message); - return true; -} - -void GuestViewContainer::Ready() { - ready_ = true; - CHECK(!pending_response_.get()); - PerformPendingRequest(); - - // Give the derived type an opportunity to perform some actions when the - // container acquires a geometry. - OnReady(); -} - -void GuestViewContainer::SetElementInstanceID(int element_instance_id) { - DCHECK_EQ(element_instance_id_, guest_view::kInstanceIDNone); - element_instance_id_ = element_instance_id; - - DCHECK(!g_guest_view_container_map.Get().count(element_instance_id)); - g_guest_view_container_map.Get().insert( - std::make_pair(element_instance_id, this)); -} - -} // namespace extensions diff --git a/extensions/renderer/guest_view/guest_view_container.h b/extensions/renderer/guest_view/guest_view_container.h deleted file mode 100644 index 8855dd7..0000000 --- a/extensions/renderer/guest_view/guest_view_container.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_ -#define EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_ - -#include "base/memory/linked_ptr.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/renderer/browser_plugin_delegate.h" -#include "ipc/ipc_message.h" - -namespace extensions { - -class GuestViewRequest; - -class GuestViewContainer : public content::BrowserPluginDelegate { - public: - explicit GuestViewContainer(content::RenderFrame* render_frame); - ~GuestViewContainer() override; - - static GuestViewContainer* FromID(int element_instance_id); - - // IssueRequest queues up a |request| until the container is ready and - // the browser process has responded to the last request if it's still - // pending. - void IssueRequest(linked_ptr<GuestViewRequest> request); - - int element_instance_id() const { return element_instance_id_; } - content::RenderFrame* render_frame() const { return render_frame_; } - - // Called when the embedding RenderFrame is destroyed. - virtual void OnRenderFrameDestroyed() {} - - // Called to respond to IPCs from the browser process that have not been - // handled by GuestViewContainer. - virtual bool OnMessage(const IPC::Message& message); - - // Called to perform actions when a GuestViewContainer gets a geometry. - virtual void OnReady() {} - - private: - class RenderFrameLifetimeObserver; - friend class RenderFrameLifetimeObserver; - - void RenderFrameDestroyed(); - - void EnqueueRequest(linked_ptr<GuestViewRequest> request); - void PerformPendingRequest(); - void HandlePendingResponseCallback(const IPC::Message& message); - - void OnHandleCallback(const IPC::Message& message); - - // BrowserPluginDelegate implementation. - bool OnMessageReceived(const IPC::Message& message) final; - void Ready() final; - void SetElementInstanceID(int element_instance_id) final; - - int element_instance_id_; - content::RenderFrame* render_frame_; - scoped_ptr<RenderFrameLifetimeObserver> render_frame_lifetime_observer_; - - bool ready_; - - std::deque<linked_ptr<GuestViewRequest> > pending_requests_; - linked_ptr<GuestViewRequest> pending_response_; - - DISALLOW_COPY_AND_ASSIGN(GuestViewContainer); -}; - -} // namespace extensions - -#endif // EXTENSIONS_RENDERER_GUEST_VIEW_GUEST_VIEW_CONTAINER_H_ diff --git a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc index 902465f..a4b08d2 100644 --- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc +++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc @@ -8,12 +8,12 @@ #include "base/bind.h" #include "components/guest_view/common/guest_view_constants.h" +#include "components/guest_view/renderer/guest_view_request.h" #include "content/public/child/v8_value_converter.h" #include "content/public/renderer/render_view.h" #include "extensions/common/extension.h" #include "extensions/common/extension_messages.h" #include "extensions/renderer/guest_view/extensions_guest_view_container.h" -#include "extensions/renderer/guest_view/guest_view_request.h" #include "extensions/renderer/script_context.h" #include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebScopedUserGesture.h" @@ -66,7 +66,8 @@ void GuestViewInternalCustomBindings::AttachGuest( int element_instance_id = args[0]->Int32Value(); // An element instance ID uniquely identifies a GuestViewContainer. - auto guest_view_container = GuestViewContainer::FromID(element_instance_id); + auto guest_view_container = + guest_view::GuestViewContainer::FromID(element_instance_id); // TODO(fsamuel): Should we be reporting an error if the element instance ID // is invalid? @@ -89,8 +90,8 @@ void GuestViewInternalCustomBindings::AttachGuest( // logical units. params->SetBoolean(guest_view::kElementSizeIsLogical, true); - linked_ptr<GuestViewRequest> request( - new GuestViewAttachRequest( + linked_ptr<guest_view::GuestViewRequest> request( + new guest_view::GuestViewAttachRequest( guest_view_container, guest_instance_id, params.Pass(), args.Length() == 4 ? args[3].As<v8::Function>() : v8::Local<v8::Function>(), @@ -111,15 +112,16 @@ void GuestViewInternalCustomBindings::DetachGuest( int element_instance_id = args[0]->Int32Value(); // An element instance ID uniquely identifies a GuestViewContainer. - auto guest_view_container = GuestViewContainer::FromID(element_instance_id); + auto guest_view_container = + guest_view::GuestViewContainer::FromID(element_instance_id); // TODO(fsamuel): Should we be reporting an error if the element instance ID // is invalid? if (!guest_view_container) return; - linked_ptr<GuestViewRequest> request( - new GuestViewDetachRequest( + linked_ptr<guest_view::GuestViewRequest> request( + new guest_view::GuestViewDetachRequest( guest_view_container, args.Length() == 2 ? args[1].As<v8::Function>() : v8::Local<v8::Function>(), args.GetIsolate())); @@ -166,7 +168,7 @@ void GuestViewInternalCustomBindings::RegisterDestructionCallback( // An element instance ID uniquely identifies a ExtensionsGuestViewContainer // within a RenderView. auto guest_view_container = static_cast<ExtensionsGuestViewContainer*>( - GuestViewContainer::FromID(element_instance_id)); + guest_view::GuestViewContainer::FromID(element_instance_id)); if (!guest_view_container) return; @@ -189,7 +191,7 @@ void GuestViewInternalCustomBindings::RegisterElementResizeCallback( // An element instance ID uniquely identifies a ExtensionsGuestViewContainer // within a RenderView. auto guest_view_container = static_cast<ExtensionsGuestViewContainer*>( - GuestViewContainer::FromID(element_instance_id)); + guest_view::GuestViewContainer::FromID(element_instance_id)); if (!guest_view_container) return; diff --git a/extensions/renderer/guest_view/guest_view_request.cc b/extensions/renderer/guest_view/guest_view_request.cc deleted file mode 100644 index 78251d9..0000000 --- a/extensions/renderer/guest_view/guest_view_request.cc +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "extensions/renderer/guest_view/guest_view_request.h" - -#include "components/guest_view/common/guest_view_messages.h" -#include "content/public/renderer/render_frame.h" -#include "content/public/renderer/render_view.h" -#include "extensions/renderer/guest_view/guest_view_container.h" -#include "third_party/WebKit/public/web/WebLocalFrame.h" -#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" -#include "third_party/WebKit/public/web/WebView.h" - -namespace extensions { - -GuestViewRequest::GuestViewRequest(GuestViewContainer* container, - v8::Local<v8::Function> callback, - v8::Isolate* isolate) - : container_(container), - callback_(isolate, callback), - isolate_(isolate) { -} - -GuestViewRequest::~GuestViewRequest() { -} - -void GuestViewRequest::ExecuteCallbackIfAvailable( - int argc, - scoped_ptr<v8::Local<v8::Value>[]> argv) { - if (callback_.IsEmpty()) - return; - - v8::HandleScope handle_scope(isolate()); - v8::Local<v8::Function> callback = - v8::Local<v8::Function>::New(isolate_, callback_); - v8::Local<v8::Context> context = callback->CreationContext(); - if (context.IsEmpty()) - return; - - v8::Context::Scope context_scope(context); - blink::WebScopedMicrotaskSuppression suppression; - - callback->Call(context->Global(), argc, argv.get()); -} - -GuestViewAttachRequest::GuestViewAttachRequest( - GuestViewContainer* container, - int guest_instance_id, - scoped_ptr<base::DictionaryValue> params, - v8::Local<v8::Function> callback, - v8::Isolate* isolate) - : GuestViewRequest(container, callback, isolate), - guest_instance_id_(guest_instance_id), - params_(params.Pass()) { -} - -GuestViewAttachRequest::~GuestViewAttachRequest() { -} - -void GuestViewAttachRequest::PerformRequest() { - if (!container()->render_frame()) - return; - - // Step 1, send the attach params to extensions/. - container()->render_frame()->Send( - new GuestViewHostMsg_AttachGuest(container()->element_instance_id(), - guest_instance_id_, - *params_)); - - // Step 2, attach plugin through content/. - container()->render_frame()->AttachGuest(container()->element_instance_id()); -} - -void GuestViewAttachRequest::HandleResponse(const IPC::Message& message) { - // TODO(fsamuel): Rename this message so that it's apparent that this is a - // response to GuestViewHostMsg_AttachGuest. Perhaps - // GuestViewMsg_AttachGuest_ACK? - GuestViewMsg_GuestAttached::Param param; - if (!GuestViewMsg_GuestAttached::Read(&message, ¶m)) - return; - - content::RenderView* guest_proxy_render_view = - content::RenderView::FromRoutingID(get<1>(param)); - // TODO(fsamuel): Should we be reporting an error to JavaScript or DCHECKing? - if (!guest_proxy_render_view) - return; - - v8::HandleScope handle_scope(isolate()); - blink::WebFrame* frame = guest_proxy_render_view->GetWebView()->mainFrame(); - v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); - - const int argc = 1; - scoped_ptr<v8::Local<v8::Value>[]> argv(new v8::Local<v8::Value>[argc]); - argv[0] = window; - - // Call the AttachGuest API's callback with the guest proxy as the first - // parameter. - ExecuteCallbackIfAvailable(argc, argv.Pass()); -} - -GuestViewDetachRequest::GuestViewDetachRequest( - GuestViewContainer* container, - v8::Local<v8::Function> callback, - v8::Isolate* isolate) - : GuestViewRequest(container, callback, isolate) { -} - -GuestViewDetachRequest::~GuestViewDetachRequest() { -} - -void GuestViewDetachRequest::PerformRequest() { - if (!container()->render_frame()) - return; - - container()->render_frame()->DetachGuest(container()->element_instance_id()); -} - -void GuestViewDetachRequest::HandleResponse(const IPC::Message& message) { - ExecuteCallbackIfAvailable(0 /* argc */, nullptr); -} - -} // namespace extensions diff --git a/extensions/renderer/guest_view/guest_view_request.h b/extensions/renderer/guest_view/guest_view_request.h deleted file mode 100644 index dbb7343..0000000 --- a/extensions/renderer/guest_view/guest_view_request.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_REQUEST_H_ -#define EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_REQUEST_H_ - -#include "ipc/ipc_message.h" -#include "v8/include/v8.h" - -namespace extensions { - -class GuestViewContainer; - -// A GuestViewRequest is the base class for an asynchronous operation performed -// on a GuestView or GuestViewContainer from JavaScript. This operation may be -// queued until the container is ready to be operated upon (it has geometry). -// A GuestViewRequest may or may not have a callback back into JavaScript. -// Typically, performing a request involves sending an IPC to the browser -// process in PerformRequest. Handling a response involves receiving a related -// IPC from the browser process in HandleResponse. -class GuestViewRequest { - public: - GuestViewRequest(GuestViewContainer* container, - v8::Local<v8::Function> callback, - v8::Isolate* isolate); - virtual ~GuestViewRequest(); - - // Performs the associated request. - virtual void PerformRequest() = 0; - - // Called by GuestViewContainer when the browser process has responded to the - // request initiated by PerformRequest. - virtual void HandleResponse(const IPC::Message& message) = 0; - - // Called to call the callback associated with this request if one is - // available. - // Note: the callback may be called even if a response has not been heard from - // the browser process if the GuestViewContainer is being torn down. - void ExecuteCallbackIfAvailable(int argc, - scoped_ptr<v8::Local<v8::Value>[]> argv); - - GuestViewContainer* container() const { return container_; } - - v8::Isolate* isolate() const { return isolate_; } - - private: - GuestViewContainer* const container_; - v8::Global<v8::Function> callback_; - v8::Isolate* const isolate_; - - DISALLOW_COPY_AND_ASSIGN(GuestViewRequest); -}; - -// This class represents an AttachGuest request from Javascript. It includes -// the input parameters and the callback function. The Attach operation may -// not execute immediately, if the container is not ready or if there are -// other GuestViewRequests in flight. -class GuestViewAttachRequest : public GuestViewRequest { - public: - GuestViewAttachRequest(GuestViewContainer* container, - int guest_instance_id, - scoped_ptr<base::DictionaryValue> params, - v8::Local<v8::Function> callback, - v8::Isolate* isolate); - ~GuestViewAttachRequest() override; - - void PerformRequest() override; - void HandleResponse(const IPC::Message& message) override; - - private: - const int guest_instance_id_; - scoped_ptr<base::DictionaryValue> params_; - - DISALLOW_COPY_AND_ASSIGN(GuestViewAttachRequest); -}; - -// This class represents a DetachGuest request from Javascript. The Detach -// operation may not execute immediately, if the container is not ready or if -// there are other GuestViewRequests in flight. -class GuestViewDetachRequest : public GuestViewRequest { - public: - GuestViewDetachRequest(GuestViewContainer* container, - v8::Local<v8::Function> callback, - v8::Isolate* isolate); - ~GuestViewDetachRequest() override; - - void PerformRequest() override; - void HandleResponse(const IPC::Message& message) override; - - private: - DISALLOW_COPY_AND_ASSIGN(GuestViewDetachRequest); -}; - -} // namespace extensions - -#endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_ diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h index 00f0211..8cc31a1 100644 --- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h +++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h @@ -10,7 +10,7 @@ #include "base/memory/linked_ptr.h" #include "base/memory/weak_ptr.h" -#include "extensions/renderer/guest_view/guest_view_container.h" +#include "components/guest_view/renderer/guest_view_container.h" #include "third_party/WebKit/public/platform/WebURLLoader.h" #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" #include "ui/gfx/geometry/size.h" @@ -35,7 +35,7 @@ namespace extensions { // a WebURLLoader. In this case, the |didReceiveData| and |didFinishLoading| // (from WebURLLoaderClient) when data is received and when it has finished // being received. -class MimeHandlerViewContainer : public GuestViewContainer, +class MimeHandlerViewContainer : public guest_view::GuestViewContainer, public blink::WebURLLoaderClient { public: MimeHandlerViewContainer(content::RenderFrame* render_frame, |