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/extension_web_contents_observer.h | |
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/extension_web_contents_observer.h')
-rw-r--r-- | extensions/browser/extension_web_contents_observer.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/extensions/browser/extension_web_contents_observer.h b/extensions/browser/extension_web_contents_observer.h index d36d782..2989e05 100644 --- a/extensions/browser/extension_web_contents_observer.h +++ b/extensions/browser/extension_web_contents_observer.h @@ -10,6 +10,7 @@ #include "base/compiler_specific.h" #include "base/macros.h" #include "content/public/browser/web_contents_observer.h" +#include "extensions/browser/extension_function_dispatcher.h" namespace content { class BrowserContext; @@ -28,13 +29,25 @@ class Extension; // WebContents. It must be a subclass so that creating an instance via // content::WebContentsUserData::CreateForWebContents() provides an object of // the correct type. For an example, see ChromeExtensionWebContentsObserver. -class ExtensionWebContentsObserver : public content::WebContentsObserver { +class ExtensionWebContentsObserver + : public content::WebContentsObserver, + public ExtensionFunctionDispatcher::Delegate { + public: + // Returns the ExtensionWebContentsObserver for the given |web_contents|. + static ExtensionWebContentsObserver* GetForWebContents( + content::WebContents* web_contents); + + ExtensionFunctionDispatcher* dispatcher() { return &dispatcher_; } + protected: explicit ExtensionWebContentsObserver(content::WebContents* web_contents); ~ExtensionWebContentsObserver() override; content::BrowserContext* browser_context() { return browser_context_; } + // ExtensionFunctionDispatcher::Delegate overrides. + content::WebContents* GetAssociatedWebContents() const override; + // content::WebContentsObserver overrides. // A subclass should invoke this method to finish extension process setup. @@ -42,6 +55,9 @@ class ExtensionWebContentsObserver : public content::WebContentsObserver { void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; + // Subclasses should call this first before doing their own message handling. + bool OnMessageReceived(const IPC::Message& message) override; + // Per the documentation in WebContentsObserver, these two methods are // appropriate to track the set of current RenderFrameHosts. // NOTE: FrameDeleted() != RenderFrameDeleted(). @@ -66,9 +82,13 @@ class ExtensionWebContentsObserver : public content::WebContentsObserver { static std::string GetExtensionId(content::RenderViewHost* render_view_host); private: + void OnRequest(const ExtensionHostMsg_Request_Params& params); + // The BrowserContext associated with the WebContents being observed. content::BrowserContext* browser_context_; + ExtensionFunctionDispatcher dispatcher_; + DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver); }; |