diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2015-06-10 16:32:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-10 23:33:30 +0000 |
commit | cb2ec659ab8741962f3391970a5fff512ebb6509 (patch) | |
tree | 84c87ca2540a0f0e7dc66bb0b82a5abc79ad012b /extensions/browser/app_window | |
parent | 1bcab9592f6213b9f44379bb66ce7b613b371e0b (diff) | |
download | chromium_src-cb2ec659ab8741962f3391970a5fff512ebb6509.zip chromium_src-cb2ec659ab8741962f3391970a5fff512ebb6509.tar.gz chromium_src-cb2ec659ab8741962f3391970a5fff512ebb6509.tar.bz2 |
[Extensions] Clean up the handling of ExtensionHostMsg_Request
ExtensionHostMsg_Request is sent when an extension calls an API function. Before
this patch, this IPC would be sent to one of 11 different call sites, all of
which then routed it to the ExtensionFunctionDispatcher - and all of which
have to implement ExtensionFunctionDispatcher::Delegate.
Instead, have ExtensionWebContentsObserver handle the IPC, since it is created
(or should be) for all extension web contents. This also lets us eliminate many
(though not all) of the ExtensionFunctionDispatcher::Delegate implementations
(I will try to clean more up in a later patch).
The size of this patch is due to a number of yaks that needed shaving along the
way - in particular, around GuestView.
BUG=498017
BUG=405246
Review URL: https://codereview.chromium.org/1169223002
Cr-Commit-Position: refs/heads/master@{#333843}
Diffstat (limited to 'extensions/browser/app_window')
6 files changed, 31 insertions, 27 deletions
diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc index c1959a9..4aa2dea 100644 --- a/extensions/browser/app_window/app_window.cc +++ b/extensions/browser/app_window/app_window.cc @@ -30,6 +30,7 @@ #include "extensions/browser/app_window/size_constraints.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" +#include "extensions/browser/extension_web_contents_observer.h" #include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/notification_types.h" #include "extensions/browser/process_manager.h" @@ -258,6 +259,9 @@ void AppWindow::Init(const GURL& url, SetViewType(web_contents(), VIEW_TYPE_APP_WINDOW); app_delegate_->InitWebContents(web_contents()); + ExtensionWebContentsObserver::GetForWebContents(web_contents())-> + dispatcher()->set_delegate(this); + WebContentsModalDialogManager::CreateForWebContents(web_contents()); web_contents()->SetDelegate(this); @@ -922,6 +926,14 @@ blink::WebDisplayMode AppWindow::GetDisplayMode( : blink::WebDisplayModeStandalone; } +WindowController* AppWindow::GetExtensionWindowController() const { + return app_window_contents_->GetWindowController(); +} + +content::WebContents* AppWindow::GetAssociatedWebContents() const { + return web_contents(); +} + void AppWindow::OnExtensionUnloaded(BrowserContext* browser_context, const Extension* extension, UnloadedExtensionInfo::Reason reason) { diff --git a/extensions/browser/app_window/app_window.h b/extensions/browser/app_window/app_window.h index 1112d38..10267f6 100644 --- a/extensions/browser/app_window/app_window.h +++ b/extensions/browser/app_window/app_window.h @@ -15,6 +15,7 @@ #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +#include "extensions/browser/extension_function_dispatcher.h" #include "extensions/browser/extension_icon_image.h" #include "extensions/browser/extension_registry_observer.h" #include "ui/base/ui_base_types.h" // WindowShowState @@ -70,6 +71,8 @@ class AppWindowContents { virtual content::WebContents* GetWebContents() const = 0; + virtual extensions::WindowController* GetWindowController() const = 0; + private: DISALLOW_COPY_AND_ASSIGN(AppWindowContents); }; @@ -80,6 +83,7 @@ class AppWindow : public content::WebContentsDelegate, public content::WebContentsObserver, public web_modal::WebContentsModalDialogManagerDelegate, public IconImage::Observer, + public ExtensionFunctionDispatcher::Delegate, public ExtensionRegistryObserver { public: enum WindowType { @@ -408,6 +412,10 @@ class AppWindow : public content::WebContentsDelegate, void RenderViewCreated(content::RenderViewHost* render_view_host) override; void DidFirstVisuallyNonEmptyPaint() override; + // ExtensionFunctionDispatcher::Delegate implementation. + WindowController* GetExtensionWindowController() const override; + content::WebContents* GetAssociatedWebContents() const override; + // ExtensionRegistryObserver implementation. void OnExtensionUnloaded(content::BrowserContext* browser_context, const Extension* extension, diff --git a/extensions/browser/app_window/app_window_contents.cc b/extensions/browser/app_window/app_window_contents.cc index 6c3909a..396a638 100644 --- a/extensions/browser/app_window/app_window_contents.cc +++ b/extensions/browser/app_window/app_window_contents.cc @@ -28,9 +28,6 @@ void AppWindowContentsImpl::Initialize(content::BrowserContext* context, const GURL& url) { url_ = url; - extension_function_dispatcher_.reset( - new ExtensionFunctionDispatcher(context, this)); - web_contents_.reset( content::WebContents::Create(content::WebContents::CreateParams( context, content::SiteInstance::CreateForURL(context, url_)))); @@ -96,10 +93,13 @@ content::WebContents* AppWindowContentsImpl::GetWebContents() const { return web_contents_.get(); } +WindowController* AppWindowContentsImpl::GetWindowController() const { + return nullptr; +} + bool AppWindowContentsImpl::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(AppWindowContentsImpl, message) - IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) IPC_MESSAGE_HANDLER(ExtensionHostMsg_UpdateDraggableRegions, UpdateDraggableRegions) IPC_MESSAGE_UNHANDLED(handled = false) @@ -107,20 +107,6 @@ bool AppWindowContentsImpl::OnMessageReceived(const IPC::Message& message) { return handled; } -WindowController* AppWindowContentsImpl::GetExtensionWindowController() const { - return NULL; -} - -content::WebContents* AppWindowContentsImpl::GetAssociatedWebContents() const { - return web_contents_.get(); -} - -void AppWindowContentsImpl::OnRequest( - const ExtensionHostMsg_Request_Params& params) { - extension_function_dispatcher_->Dispatch( - params, web_contents_->GetRenderViewHost()); -} - void AppWindowContentsImpl::UpdateDraggableRegions( const std::vector<DraggableRegion>& regions) { host_->UpdateDraggableRegions(regions); diff --git a/extensions/browser/app_window/app_window_contents.h b/extensions/browser/app_window/app_window_contents.h index ab07ca6..56c1664 100644 --- a/extensions/browser/app_window/app_window_contents.h +++ b/extensions/browser/app_window/app_window_contents.h @@ -10,7 +10,6 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/web_contents_observer.h" #include "extensions/browser/app_window/app_window.h" -#include "extensions/browser/extension_function_dispatcher.h" #include "url/gurl.h" namespace content { @@ -25,8 +24,7 @@ struct DraggableRegion; // WebContents instance and observes it for the purpose of passing // messages to the extensions system. class AppWindowContentsImpl : public AppWindowContents, - public content::WebContentsObserver, - public ExtensionFunctionDispatcher::Delegate { + public content::WebContentsObserver { public: explicit AppWindowContentsImpl(AppWindow* host); ~AppWindowContentsImpl() override; @@ -38,23 +36,18 @@ class AppWindowContentsImpl : public AppWindowContents, void NativeWindowClosed() override; void DispatchWindowShownForTests() const override; content::WebContents* GetWebContents() const override; + WindowController* GetWindowController() const override; private: // content::WebContentsObserver bool OnMessageReceived(const IPC::Message& message) override; - // ExtensionFunctionDispatcher::Delegate - WindowController* GetExtensionWindowController() const override; - content::WebContents* GetAssociatedWebContents() const override; - - void OnRequest(const ExtensionHostMsg_Request_Params& params); void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions); void SuspendRenderViewHost(content::RenderViewHost* rvh); AppWindow* host_; // This class is owned by |host_| GURL url_; scoped_ptr<content::WebContents> web_contents_; - scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; DISALLOW_COPY_AND_ASSIGN(AppWindowContentsImpl); }; diff --git a/extensions/browser/app_window/test_app_window_contents.cc b/extensions/browser/app_window/test_app_window_contents.cc index 4cc856d6..18401e7 100644 --- a/extensions/browser/app_window/test_app_window_contents.cc +++ b/extensions/browser/app_window/test_app_window_contents.cc @@ -36,4 +36,8 @@ content::WebContents* TestAppWindowContents::GetWebContents() const { return web_contents_.get(); } +WindowController* TestAppWindowContents::GetWindowController() const { + return nullptr; +} + } // namespace extensions diff --git a/extensions/browser/app_window/test_app_window_contents.h b/extensions/browser/app_window/test_app_window_contents.h index 018b33e..d52fb97 100644 --- a/extensions/browser/app_window/test_app_window_contents.h +++ b/extensions/browser/app_window/test_app_window_contents.h @@ -28,6 +28,7 @@ class TestAppWindowContents : public AppWindowContents { void NativeWindowClosed() override; void DispatchWindowShownForTests() const override; content::WebContents* GetWebContents() const override; + WindowController* GetWindowController() const override; private: scoped_ptr<content::WebContents> web_contents_; |