summaryrefslogtreecommitdiffstats
path: root/extensions/browser
diff options
context:
space:
mode:
authorrdevlin.cronin <rdevlin.cronin@chromium.org>2015-06-10 16:32:41 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-10 23:33:30 +0000
commitcb2ec659ab8741962f3391970a5fff512ebb6509 (patch)
tree84c87ca2540a0f0e7dc66bb0b82a5abc79ad012b /extensions/browser
parent1bcab9592f6213b9f44379bb66ce7b613b371e0b (diff)
downloadchromium_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')
-rw-r--r--extensions/browser/api/extensions_api_client.cc10
-rw-r--r--extensions/browser/api/extensions_api_client.h12
-rw-r--r--extensions/browser/api/mime_handler_private/mime_handler_private_unittest.cc1
-rw-r--r--extensions/browser/api_test_utils.cc20
-rw-r--r--extensions/browser/app_window/app_window.cc12
-rw-r--r--extensions/browser/app_window/app_window.h8
-rw-r--r--extensions/browser/app_window/app_window_contents.cc22
-rw-r--r--extensions/browser/app_window/app_window_contents.h11
-rw-r--r--extensions/browser/app_window/test_app_window_contents.cc4
-rw-r--r--extensions/browser/app_window/test_app_window_contents.h1
-rw-r--r--extensions/browser/extension_function.cc2
-rw-r--r--extensions/browser/extension_function_dispatcher.cc26
-rw-r--r--extensions/browser/extension_function_dispatcher.h17
-rw-r--r--extensions/browser/extension_host.cc10
-rw-r--r--extensions/browser/extension_host.h3
-rw-r--r--extensions/browser/extension_web_contents_observer.cc31
-rw-r--r--extensions/browser/extension_web_contents_observer.h22
-rw-r--r--extensions/browser/extensions_browser_client.h5
-rw-r--r--extensions/browser/guest_view/app_view/app_view_guest.cc25
-rw-r--r--extensions/browser/guest_view/app_view/app_view_guest.h14
-rw-r--r--extensions/browser/guest_view/extension_options/extension_options_guest.cc26
-rw-r--r--extensions/browser/guest_view/extension_options/extension_options_guest.h11
-rw-r--r--extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h3
-rw-r--r--extensions/browser/guest_view/extension_view/extension_view_guest.cc27
-rw-r--r--extensions/browser/guest_view/extension_view/extension_view_guest.h10
-rw-r--r--extensions/browser/guest_view/extension_view/extension_view_guest_delegate.cc17
-rw-r--r--extensions/browser/guest_view/extension_view/extension_view_guest_delegate.h34
-rw-r--r--extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc30
-rw-r--r--extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h13
-rw-r--r--extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h5
-rw-r--r--extensions/browser/guest_view/web_view/web_view_guest.cc9
-rw-r--r--extensions/browser/guest_view/web_view/web_view_guest.h2
-rw-r--r--extensions/browser/guest_view/web_view/web_view_guest_delegate.h3
-rw-r--r--extensions/browser/test_extensions_browser_client.cc6
-rw-r--r--extensions/browser/test_extensions_browser_client.h2
35 files changed, 157 insertions, 297 deletions
diff --git a/extensions/browser/api/extensions_api_client.cc b/extensions/browser/api/extensions_api_client.cc
index adf9090..5fc571c 100644
--- a/extensions/browser/api/extensions_api_client.cc
+++ b/extensions/browser/api/extensions_api_client.cc
@@ -33,6 +33,10 @@ void ExtensionsAPIClient::AddAdditionalValueStoreCaches(
std::map<settings_namespace::Namespace, ValueStoreCache*>* caches) {
}
+void ExtensionsAPIClient::AttachWebContentsHelpers(
+ content::WebContents* web_contents) const {
+}
+
AppViewGuestDelegate* ExtensionsAPIClient::CreateAppViewGuestDelegate() const {
return NULL;
}
@@ -43,12 +47,6 @@ ExtensionsAPIClient::CreateExtensionOptionsGuestDelegate(
return NULL;
}
-ExtensionViewGuestDelegate*
-ExtensionsAPIClient::CreateExtensionViewGuestDelegate(
- ExtensionViewGuest* guest) const {
- return NULL;
-}
-
scoped_ptr<MimeHandlerViewGuestDelegate>
ExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
MimeHandlerViewGuest* guest) const {
diff --git a/extensions/browser/api/extensions_api_client.h b/extensions/browser/api/extensions_api_client.h
index 4800040..35f0114 100644
--- a/extensions/browser/api/extensions_api_client.h
+++ b/extensions/browser/api/extensions_api_client.h
@@ -31,8 +31,6 @@ class ContentRulesRegistry;
class DevicePermissionsPrompt;
class ExtensionOptionsGuest;
class ExtensionOptionsGuestDelegate;
-class ExtensionViewGuest;
-class ExtensionViewGuestDelegate;
class ManagementAPIDelegate;
class MimeHandlerViewGuest;
class MimeHandlerViewGuestDelegate;
@@ -72,6 +70,11 @@ class ExtensionsAPIClient {
observers,
std::map<settings_namespace::Namespace, ValueStoreCache*>* caches);
+ // Attaches any extra web contents helpers (like ExtensionWebContentsObserver)
+ // to |web_contents|.
+ virtual void AttachWebContentsHelpers(content::WebContents* web_contents)
+ const;
+
// Creates the AppViewGuestDelegate.
virtual AppViewGuestDelegate* CreateAppViewGuestDelegate() const;
@@ -80,11 +83,6 @@ class ExtensionsAPIClient {
virtual ExtensionOptionsGuestDelegate* CreateExtensionOptionsGuestDelegate(
ExtensionOptionsGuest* guest) const;
- // Returns a delegate for ExtensionViewGuest. The caller owns the returned
- // ExtensionViewGuestDelegate.
- virtual ExtensionViewGuestDelegate* CreateExtensionViewGuestDelegate(
- ExtensionViewGuest* guest) const;
-
// Creates a delegate for MimeHandlerViewGuest.
virtual scoped_ptr<MimeHandlerViewGuestDelegate>
CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest* guest) const;
diff --git a/extensions/browser/api/mime_handler_private/mime_handler_private_unittest.cc b/extensions/browser/api/mime_handler_private/mime_handler_private_unittest.cc
index 9b7cee4..7f36a399 100644
--- a/extensions/browser/api/mime_handler_private/mime_handler_private_unittest.cc
+++ b/extensions/browser/api/mime_handler_private/mime_handler_private_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
#include "content/public/browser/stream_handle.h"
#include "content/public/browser/stream_info.h"
#include "extensions/browser/api/mime_handler_private/mime_handler_private.h"
diff --git a/extensions/browser/api_test_utils.cc b/extensions/browser/api_test_utils.cc
index 4affb86..587f8e2 100644
--- a/extensions/browser/api_test_utils.cc
+++ b/extensions/browser/api_test_utils.cc
@@ -19,17 +19,6 @@ using extensions::ExtensionFunctionDispatcher;
namespace {
-class TestFunctionDispatcherDelegate
- : public ExtensionFunctionDispatcher::Delegate {
- public:
- TestFunctionDispatcherDelegate() {}
- ~TestFunctionDispatcherDelegate() override {}
-
- // NULL implementation.
- private:
- DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate);
-};
-
scoped_ptr<base::Value> ParseJSON(const std::string& data) {
return base::JSONReader::Read(data);
}
@@ -185,9 +174,8 @@ base::Value* RunFunctionAndReturnSingleResult(
const std::string& args,
content::BrowserContext* context,
RunFunctionFlags flags) {
- TestFunctionDispatcherDelegate delegate;
scoped_ptr<ExtensionFunctionDispatcher> dispatcher(
- new ExtensionFunctionDispatcher(context, &delegate));
+ new ExtensionFunctionDispatcher(context));
return RunFunctionWithDelegateAndReturnSingleResult(
function, args, context, dispatcher.Pass(), flags);
@@ -203,9 +191,8 @@ std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
const std::string& args,
content::BrowserContext* context,
RunFunctionFlags flags) {
- TestFunctionDispatcherDelegate delegate;
scoped_ptr<ExtensionFunctionDispatcher> dispatcher(
- new ExtensionFunctionDispatcher(context, &delegate));
+ new ExtensionFunctionDispatcher(context));
scoped_refptr<ExtensionFunction> function_owner(function);
// Without a callback the function will not generate a result.
function->set_has_callback(true);
@@ -217,9 +204,8 @@ std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
bool RunFunction(UIThreadExtensionFunction* function,
const std::string& args,
content::BrowserContext* context) {
- TestFunctionDispatcherDelegate delegate;
scoped_ptr<ExtensionFunctionDispatcher> dispatcher(
- new ExtensionFunctionDispatcher(context, &delegate));
+ new ExtensionFunctionDispatcher(context));
return RunFunction(function, args, context, dispatcher.Pass(), NONE);
}
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_;
diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc
index f7c7097..624bfe7 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -464,7 +464,7 @@ void UIThreadExtensionFunction::SetRenderFrameHost(
content::WebContents* UIThreadExtensionFunction::GetAssociatedWebContents() {
content::WebContents* web_contents = NULL;
if (dispatcher())
- web_contents = dispatcher()->delegate()->GetAssociatedWebContents();
+ web_contents = dispatcher()->GetAssociatedWebContents();
return web_contents;
}
diff --git a/extensions/browser/extension_function_dispatcher.cc b/extensions/browser/extension_function_dispatcher.cc
index 917ce65..9a30d2e 100644
--- a/extensions/browser/extension_function_dispatcher.cc
+++ b/extensions/browser/extension_function_dispatcher.cc
@@ -205,12 +205,12 @@ class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper
WindowController*
ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() const {
- return NULL;
+ return nullptr;
}
content::WebContents*
ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const {
- return NULL;
+ return nullptr;
}
content::WebContents*
@@ -301,10 +301,8 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
}
ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
- content::BrowserContext* browser_context,
- Delegate* delegate)
- : browser_context_(browser_context),
- delegate_(delegate) {
+ content::BrowserContext* browser_context)
+ : browser_context_(browser_context) {
}
ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
@@ -440,6 +438,22 @@ void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
}
}
+WindowController*
+ExtensionFunctionDispatcher::GetExtensionWindowController() const {
+ return delegate_ ? delegate_->GetExtensionWindowController() : nullptr;
+}
+
+content::WebContents*
+ExtensionFunctionDispatcher::GetAssociatedWebContents() const {
+ return delegate_ ? delegate_->GetAssociatedWebContents() : nullptr;
+}
+
+content::WebContents*
+ExtensionFunctionDispatcher::GetVisibleWebContents() const {
+ return delegate_ ? delegate_->GetVisibleWebContents() :
+ GetAssociatedWebContents();
+}
+
// static
bool ExtensionFunctionDispatcher::CheckPermissions(
ExtensionFunction* function,
diff --git a/extensions/browser/extension_function_dispatcher.h b/extensions/browser/extension_function_dispatcher.h
index 9224bbd..2764449 100644
--- a/extensions/browser/extension_function_dispatcher.h
+++ b/extensions/browser/extension_function_dispatcher.h
@@ -90,16 +90,12 @@ class ExtensionFunctionDispatcher
const ExtensionHostMsg_Request_Params& params);
// Public constructor. Callers must ensure that:
- // - |delegate| outlives this object.
// - This object outlives any RenderViewHost's passed to created
// ExtensionFunctions.
- ExtensionFunctionDispatcher(content::BrowserContext* browser_context,
- Delegate* delegate);
-
+ explicit ExtensionFunctionDispatcher(
+ content::BrowserContext* browser_context);
~ExtensionFunctionDispatcher();
- Delegate* delegate() { return delegate_; }
-
// Message handlers.
// The response is sent to the corresponding render view in an
// ExtensionMsg_Response message.
@@ -111,9 +107,18 @@ class ExtensionFunctionDispatcher
// a response (if any) to the extension.
void OnExtensionFunctionCompleted(const Extension* extension);
+ // See the Delegate class for documentation on these methods.
+ // TODO(devlin): None of these belong here. We should kill
+ // ExtensionFunctionDispatcher::Delegate.
+ WindowController* GetExtensionWindowController() const;
+ content::WebContents* GetAssociatedWebContents() const;
+ content::WebContents* GetVisibleWebContents() const;
+
// The BrowserContext that this dispatcher is associated with.
content::BrowserContext* browser_context() { return browser_context_; }
+ void set_delegate(Delegate* delegate) { delegate_ = delegate; }
+
private:
// For a given RenderViewHost instance, UIThreadResponseCallbackWrapper
// creates ExtensionFunction::ResponseCallback instances which send responses
diff --git a/extensions/browser/extension_host.cc b/extensions/browser/extension_host.cc
index 124a8fd..c3e041a 100644
--- a/extensions/browser/extension_host.cc
+++ b/extensions/browser/extension_host.cc
@@ -27,6 +27,7 @@
#include "extensions/browser/extension_host_queue.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/load_monitoring_extension_host_queue.h"
#include "extensions/browser/notification_types.h"
@@ -62,7 +63,6 @@ ExtensionHost::ExtensionHost(const Extension* extension,
has_loaded_once_(false),
document_element_available_(false),
initial_url_(url),
- extension_function_dispatcher_(browser_context_, this),
extension_host_type_(host_type) {
// Not used for panels, see PanelHost.
DCHECK(host_type == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE ||
@@ -82,6 +82,9 @@ ExtensionHost::ExtensionHost(const Extension* extension,
// Set up web contents observers and pref observers.
delegate_->OnExtensionHostCreated(host_contents());
+
+ ExtensionWebContentsObserver::GetForWebContents(host_contents())->
+ dispatcher()->set_delegate(this);
}
ExtensionHost::~ExtensionHost() {
@@ -321,7 +324,6 @@ void ExtensionHost::CloseContents(WebContents* contents) {
bool ExtensionHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ExtensionHost, message)
- IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_EventAck, OnEventAck)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_IncrementLazyKeepaliveCount,
OnIncrementLazyKeepaliveCount)
@@ -332,10 +334,6 @@ bool ExtensionHost::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
- extension_function_dispatcher_.Dispatch(params, render_view_host());
-}
-
void ExtensionHost::OnEventAck(int event_id) {
EventRouter* router = EventRouter::Get(browser_context_);
if (router)
diff --git a/extensions/browser/extension_host.h b/extensions/browser/extension_host.h
index 846eb50..d82c427 100644
--- a/extensions/browser/extension_host.h
+++ b/extensions/browser/extension_host.h
@@ -151,7 +151,6 @@ class ExtensionHost : public DeferredStartRenderHost,
DeferredStartRenderHostObserver* observer) override;
// Message handlers.
- void OnRequest(const ExtensionHostMsg_Request_Params& params);
void OnEventAck(int event_id);
void OnIncrementLazyKeepaliveCount();
void OnDecrementLazyKeepaliveCount();
@@ -193,8 +192,6 @@ class ExtensionHost : public DeferredStartRenderHost,
// Messages sent out to the renderer that have not been acknowledged yet.
std::set<int> unacked_messages_;
- ExtensionFunctionDispatcher extension_function_dispatcher_;
-
// The type of view being hosted.
ViewType extension_host_type_;
diff --git a/extensions/browser/extension_web_contents_observer.cc b/extensions/browser/extension_web_contents_observer.cc
index 1b1cad8..779f9a0 100644
--- a/extensions/browser/extension_web_contents_observer.cc
+++ b/extensions/browser/extension_web_contents_observer.cc
@@ -45,19 +45,33 @@ const Extension* GetExtensionForRenderFrame(
} // namespace
+// static
+ExtensionWebContentsObserver* ExtensionWebContentsObserver::GetForWebContents(
+ content::WebContents* web_contents) {
+ return ExtensionsBrowserClient::Get()->GetExtensionWebContentsObserver(
+ web_contents);
+}
+
ExtensionWebContentsObserver::ExtensionWebContentsObserver(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
- browser_context_(web_contents->GetBrowserContext()) {
+ browser_context_(web_contents->GetBrowserContext()),
+ dispatcher_(browser_context_) {
NotifyRenderViewType(web_contents->GetRenderViewHost());
content::RenderFrameHost* host = web_contents->GetMainFrame();
if (host)
RenderFrameHostChanged(nullptr, host);
+ dispatcher_.set_delegate(this);
}
ExtensionWebContentsObserver::~ExtensionWebContentsObserver() {
}
+content::WebContents* ExtensionWebContentsObserver::GetAssociatedWebContents()
+ const {
+ return web_contents();
+}
+
void ExtensionWebContentsObserver::RenderViewCreated(
content::RenderViewHost* render_view_host) {
NotifyRenderViewType(render_view_host);
@@ -110,6 +124,16 @@ void ExtensionWebContentsObserver::RenderFrameCreated(
}
}
+bool ExtensionWebContentsObserver::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ExtensionWebContentsObserver, message)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
void ExtensionWebContentsObserver::FrameDeleted(
content::RenderFrameHost* render_frame_host) {
ProcessManager::Get(browser_context_)->UnregisterRenderFrameHost(
@@ -189,4 +213,9 @@ std::string ExtensionWebContentsObserver::GetExtensionId(
return site.host();
}
+void ExtensionWebContentsObserver::OnRequest(
+ const ExtensionHostMsg_Request_Params& params) {
+ dispatcher_.Dispatch(params, web_contents()->GetRenderViewHost());
+}
+
} // namespace extensions
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);
};
diff --git a/extensions/browser/extensions_browser_client.h b/extensions/browser/extensions_browser_client.h
index 49d00db..6e99f7f 100644
--- a/extensions/browser/extensions_browser_client.h
+++ b/extensions/browser/extensions_browser_client.h
@@ -44,6 +44,7 @@ class ExtensionHostDelegate;
class ExtensionPrefsObserver;
class ExtensionSystem;
class ExtensionSystemProvider;
+class ExtensionWebContentsObserver;
class InfoMap;
class ProcessManagerDelegate;
class RuntimeAPIDelegate;
@@ -212,6 +213,10 @@ class ExtensionsBrowserClient {
// is left up to the embedder.
virtual bool IsMinBrowserVersionSupported(const std::string& min_version) = 0;
+ // Returns the ExtensionWebContentsObserver for the given |web_contents|.
+ virtual ExtensionWebContentsObserver* GetExtensionWebContentsObserver(
+ content::WebContents* web_contents) = 0;
+
// Returns the single instance of |this|.
static ExtensionsBrowserClient* Get();
diff --git a/extensions/browser/guest_view/app_view/app_view_guest.cc b/extensions/browser/guest_view/app_view/app_view_guest.cc
index 9c157d0..108b9b3 100644
--- a/extensions/browser/guest_view/app_view/app_view_guest.cc
+++ b/extensions/browser/guest_view/app_view/app_view_guest.cc
@@ -104,23 +104,6 @@ AppViewGuest::AppViewGuest(content::WebContents* owner_web_contents)
AppViewGuest::~AppViewGuest() {
}
-WindowController* AppViewGuest::GetExtensionWindowController() const {
- return nullptr;
-}
-
-content::WebContents* AppViewGuest::GetAssociatedWebContents() const {
- return web_contents();
-}
-
-bool AppViewGuest::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message)
- IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) {
if (app_view_guest_delegate_) {
return app_view_guest_delegate_->HandleContextMenu(web_contents(), params);
@@ -226,8 +209,7 @@ void AppViewGuest::CreateWebContents(
}
void AppViewGuest::DidInitialize(const base::DictionaryValue& create_params) {
- extension_function_dispatcher_.reset(
- new ExtensionFunctionDispatcher(browser_context(), this));
+ ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents());
if (!url_.is_valid())
return;
@@ -244,11 +226,6 @@ int AppViewGuest::GetTaskPrefix() const {
return IDS_EXTENSION_TASK_MANAGER_APPVIEW_TAG_PREFIX;
}
-void AppViewGuest::OnRequest(const ExtensionHostMsg_Request_Params& params) {
- extension_function_dispatcher_->Dispatch(params,
- web_contents()->GetRenderViewHost());
-}
-
void AppViewGuest::CompleteCreateWebContents(
const GURL& url,
const Extension* guest_extension,
diff --git a/extensions/browser/guest_view/app_view/app_view_guest.h b/extensions/browser/guest_view/app_view/app_view_guest.h
index 4b05d1a..81cf44d 100644
--- a/extensions/browser/guest_view/app_view/app_view_guest.h
+++ b/extensions/browser/guest_view/app_view/app_view_guest.h
@@ -7,7 +7,6 @@
#include "base/id_map.h"
#include "components/guest_view/browser/guest_view.h"
-#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/guest_view/app_view/app_view_guest_delegate.h"
namespace extensions {
@@ -18,8 +17,7 @@ class ExtensionHost;
// AppViewGuest is created on attachment. That is, when a guest WebContents is
// associated with a particular embedder WebContents. This happens on calls to
// the connect API.
-class AppViewGuest : public guest_view::GuestView<AppViewGuest>,
- public ExtensionFunctionDispatcher::Delegate {
+class AppViewGuest : public guest_view::GuestView<AppViewGuest> {
public:
static const char Type[];
@@ -33,13 +31,6 @@ class AppViewGuest : public guest_view::GuestView<AppViewGuest>,
static GuestViewBase* Create(content::WebContents* owner_web_contents);
- // ExtensionFunctionDispatcher::Delegate implementation.
- WindowController* GetExtensionWindowController() const override;
- content::WebContents* GetAssociatedWebContents() const override;
-
- // content::WebContentsObserver implementation.
- bool OnMessageReceived(const IPC::Message& message) override;
-
// content::WebContentsDelegate implementation.
bool HandleContextMenu(const content::ContextMenuParams& params) override;
void RequestMediaAccessPermission(
@@ -66,8 +57,6 @@ class AppViewGuest : public guest_view::GuestView<AppViewGuest>,
~AppViewGuest() override;
- void OnRequest(const ExtensionHostMsg_Request_Params& params);
-
void CompleteCreateWebContents(const GURL& url,
const Extension* guest_extension,
const WebContentsCreatedCallback& callback);
@@ -78,7 +67,6 @@ class AppViewGuest : public guest_view::GuestView<AppViewGuest>,
GURL url_;
std::string guest_extension_id_;
- scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
scoped_ptr<AppViewGuestDelegate> app_view_guest_delegate_;
scoped_ptr<AppDelegate> app_delegate_;
diff --git a/extensions/browser/guest_view/extension_options/extension_options_guest.cc b/extensions/browser/guest_view/extension_options/extension_options_guest.cc
index c882315..339906a 100644
--- a/extensions/browser/guest_view/extension_options/extension_options_guest.cc
+++ b/extensions/browser/guest_view/extension_options/extension_options_guest.cc
@@ -17,7 +17,6 @@
#include "extensions/browser/bad_message.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/extension_web_contents_observer.h"
#include "extensions/browser/guest_view/extension_options/extension_options_constants.h"
#include "extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h"
#include "extensions/common/api/extension_options_internal.h"
@@ -117,11 +116,7 @@ void ExtensionOptionsGuest::CreateWebContents(
void ExtensionOptionsGuest::DidInitialize(
const base::DictionaryValue& create_params) {
- extension_function_dispatcher_.reset(
- new extensions::ExtensionFunctionDispatcher(browser_context(), this));
- if (extension_options_guest_delegate_) {
- extension_options_guest_delegate_->DidInitialize();
- }
+ ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents());
web_contents()->GetController().LoadURL(options_page_,
content::Referrer(),
ui::PAGE_TRANSITION_LINK,
@@ -160,10 +155,6 @@ void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) {
options.ToValue()));
}
-content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const {
- return web_contents();
-}
-
content::WebContents* ExtensionOptionsGuest::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
@@ -244,19 +235,4 @@ void ExtensionOptionsGuest::DidNavigateMainFrame(
}
}
-bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message)
- IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void ExtensionOptionsGuest::OnRequest(
- const ExtensionHostMsg_Request_Params& params) {
- extension_function_dispatcher_->Dispatch(params,
- web_contents()->GetRenderViewHost());
-}
-
} // namespace extensions
diff --git a/extensions/browser/guest_view/extension_options/extension_options_guest.h b/extensions/browser/guest_view/extension_options/extension_options_guest.h
index b62d81a..088c78b 100644
--- a/extensions/browser/guest_view/extension_options/extension_options_guest.h
+++ b/extensions/browser/guest_view/extension_options/extension_options_guest.h
@@ -7,7 +7,6 @@
#include "base/macros.h"
#include "components/guest_view/browser/guest_view.h"
-#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h"
#include "url/gurl.h"
@@ -18,8 +17,7 @@ class BrowserContext;
namespace extensions {
class ExtensionOptionsGuest
- : public guest_view::GuestView<ExtensionOptionsGuest>,
- public extensions::ExtensionFunctionDispatcher::Delegate {
+ : public guest_view::GuestView<ExtensionOptionsGuest> {
public:
static const char Type[];
static guest_view::GuestViewBase* Create(
@@ -37,9 +35,6 @@ class ExtensionOptionsGuest
bool IsDragAndDropEnabled() const override;
void OnPreferredSizeChanged(const gfx::Size& pref_size) override;
- // ExtensionFunctionDispatcher::Delegate implementation.
- content::WebContents* GetAssociatedWebContents() const override;
-
// content::WebContentsDelegate implementation.
content::WebContents* OpenURLFromTab(
content::WebContents* source,
@@ -60,15 +55,11 @@ class ExtensionOptionsGuest
void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
- bool OnMessageReceived(const IPC::Message& message) override;
private:
explicit ExtensionOptionsGuest(content::WebContents* owner_web_contents);
~ExtensionOptionsGuest() override;
- void OnRequest(const ExtensionHostMsg_Request_Params& params);
- scoped_ptr<extensions::ExtensionFunctionDispatcher>
- extension_function_dispatcher_;
scoped_ptr<extensions::ExtensionOptionsGuestDelegate>
extension_options_guest_delegate_;
GURL options_page_;
diff --git a/extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h b/extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h
index bbeed90..4052c8b 100644
--- a/extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h
+++ b/extensions/browser/guest_view/extension_options/extension_options_guest_delegate.h
@@ -24,9 +24,6 @@ class ExtensionOptionsGuestDelegate {
explicit ExtensionOptionsGuestDelegate(ExtensionOptionsGuest* guest);
virtual ~ExtensionOptionsGuestDelegate();
- // Called from ExtensionOptionsGuest::DidInitialize().
- virtual void DidInitialize() = 0;
-
// Shows the context menu for the guest.
// Returns true if the context menu was handled.
virtual bool HandleContextMenu(const content::ContextMenuParams& params) = 0;
diff --git a/extensions/browser/guest_view/extension_view/extension_view_guest.cc b/extensions/browser/guest_view/extension_view/extension_view_guest.cc
index b9f73f4..ff2bcf9 100644
--- a/extensions/browser/guest_view/extension_view/extension_view_guest.cc
+++ b/extensions/browser/guest_view/extension_view/extension_view_guest.cc
@@ -28,10 +28,7 @@ const char ExtensionViewGuest::Type[] = "extensionview";
ExtensionViewGuest::ExtensionViewGuest(
content::WebContents* owner_web_contents)
- : GuestView<ExtensionViewGuest>(owner_web_contents),
- extension_view_guest_delegate_(
- extensions::ExtensionsAPIClient::Get()
- ->CreateExtensionViewGuestDelegate(this)) {
+ : GuestView<ExtensionViewGuest>(owner_web_contents) {
}
ExtensionViewGuest::~ExtensionViewGuest() {
@@ -104,11 +101,7 @@ void ExtensionViewGuest::CreateWebContents(
void ExtensionViewGuest::DidInitialize(
const base::DictionaryValue& create_params) {
- extension_function_dispatcher_.reset(
- new extensions::ExtensionFunctionDispatcher(browser_context(), this));
-
- if (extension_view_guest_delegate_)
- extension_view_guest_delegate_->DidInitialize();
+ ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents());
ApplyAttributes(create_params);
}
@@ -157,22 +150,6 @@ void ExtensionViewGuest::DidNavigateMainFrame(
}
}
-bool ExtensionViewGuest::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(ExtensionViewGuest, message)
- IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-// Private
-void ExtensionViewGuest::OnRequest(
- const ExtensionHostMsg_Request_Params& params) {
- extension_function_dispatcher_->Dispatch(params,
- web_contents()->GetRenderViewHost());
-}
-
void ExtensionViewGuest::ApplyAttributes(const base::DictionaryValue& params) {
std::string src;
params.GetString(extensionview::kAttributeSrc, &src);
diff --git a/extensions/browser/guest_view/extension_view/extension_view_guest.h b/extensions/browser/guest_view/extension_view/extension_view_guest.h
index 8a3fd7d..ffd72a4 100644
--- a/extensions/browser/guest_view/extension_view/extension_view_guest.h
+++ b/extensions/browser/guest_view/extension_view/extension_view_guest.h
@@ -8,7 +8,6 @@
#include "base/macros.h"
#include "components/guest_view/browser/guest_view.h"
#include "extensions/browser/extension_function_dispatcher.h"
-#include "extensions/browser/guest_view/extension_view/extension_view_guest_delegate.h"
#include "url/gurl.h"
namespace content {
@@ -18,8 +17,7 @@ class BrowserContext;
namespace extensions {
class ExtensionViewGuest
- : public guest_view::GuestView<ExtensionViewGuest>,
- public ExtensionFunctionDispatcher::Delegate {
+ : public guest_view::GuestView<ExtensionViewGuest> {
public:
static const char Type[];
static guest_view::GuestViewBase* Create(
@@ -45,20 +43,14 @@ class ExtensionViewGuest
void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
- bool OnMessageReceived(const IPC::Message& message) override;
private:
ExtensionViewGuest(content::WebContents* owner_web_contents);
~ExtensionViewGuest() override;
- void OnRequest(const ExtensionHostMsg_Request_Params& params);
// Applies attributes to the extensionview.
void ApplyAttributes(const base::DictionaryValue& params);
- scoped_ptr<extensions::ExtensionFunctionDispatcher>
- extension_function_dispatcher_;
- scoped_ptr<extensions::ExtensionViewGuestDelegate>
- extension_view_guest_delegate_;
GURL view_page_;
GURL extension_url_;
diff --git a/extensions/browser/guest_view/extension_view/extension_view_guest_delegate.cc b/extensions/browser/guest_view/extension_view/extension_view_guest_delegate.cc
deleted file mode 100644
index 26fcbb2..0000000
--- a/extensions/browser/guest_view/extension_view/extension_view_guest_delegate.cc
+++ /dev/null
@@ -1,17 +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/browser/guest_view/extension_view/extension_view_guest_delegate.h"
-
-namespace extensions {
-
-ExtensionViewGuestDelegate::ExtensionViewGuestDelegate(
- ExtensionViewGuest* guest)
- : guest_(guest) {
-}
-
-ExtensionViewGuestDelegate::~ExtensionViewGuestDelegate() {
-}
-
-} // namespace extensions
diff --git a/extensions/browser/guest_view/extension_view/extension_view_guest_delegate.h b/extensions/browser/guest_view/extension_view/extension_view_guest_delegate.h
deleted file mode 100644
index 6f5a2da..0000000
--- a/extensions/browser/guest_view/extension_view/extension_view_guest_delegate.h
+++ /dev/null
@@ -1,34 +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_BROWSER_GUEST_VIEW_EXTENSION_VIEW_EXTENSION_VIEW_GUEST_DELEGATE_H_
-#define EXTENSIONS_BROWSER_GUEST_VIEW_EXTENSION_VIEW_EXTENSION_VIEW_GUEST_DELEGATE_H_
-
-#include "base/macros.h"
-
-namespace extensions {
-
-class ExtensionViewGuest;
-
-// Interface to handle communication between ExtensionViewGuest and
-// the browser.
-class ExtensionViewGuestDelegate {
- public:
- explicit ExtensionViewGuestDelegate(ExtensionViewGuest* guest);
- virtual ~ExtensionViewGuestDelegate();
-
- // Called from ExtensionViewGuest::DidInitialize().
- virtual void DidInitialize() = 0;
-
- ExtensionViewGuest* extension_view_guest() const { return guest_; }
-
- private:
- ExtensionViewGuest* const guest_;
-
- DISALLOW_COPY_AND_ASSIGN(ExtensionViewGuestDelegate);
-};
-
-} // namespace extensions
-
-#endif // EXTENSIONS_BROWSER_GUEST_VIEW_EXTENSION_VIEW_EXTENSION_VIEW_GUEST_DELEGATE_H_
diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
index 61fd142..2f446623 100644
--- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
+++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
@@ -82,14 +82,6 @@ MimeHandlerViewGuest::MimeHandlerViewGuest(
MimeHandlerViewGuest::~MimeHandlerViewGuest() {
}
-WindowController* MimeHandlerViewGuest::GetExtensionWindowController() const {
- return nullptr;
-}
-
-WebContents* MimeHandlerViewGuest::GetAssociatedWebContents() const {
- return web_contents();
-}
-
const char* MimeHandlerViewGuest::GetAPINamespace() const {
return "mimeHandlerViewGuestInternal";
}
@@ -155,10 +147,7 @@ void MimeHandlerViewGuest::DidAttachToEmbedder() {
void MimeHandlerViewGuest::DidInitialize(
const base::DictionaryValue& create_params) {
- extension_function_dispatcher_.reset(
- new ExtensionFunctionDispatcher(browser_context(), this));
- if (delegate_)
- delegate_->AttachHelpers();
+ ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents());
}
bool MimeHandlerViewGuest::ZoomPropagatesFromEmbedderToGuest() const {
@@ -251,27 +240,10 @@ void MimeHandlerViewGuest::DocumentOnLoadCompletedInMainFrame() {
element_instance_id()));
}
-bool MimeHandlerViewGuest::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(MimeHandlerViewGuest, message)
- IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
base::WeakPtr<StreamContainer> MimeHandlerViewGuest::GetStream() const {
if (!stream_)
return base::WeakPtr<StreamContainer>();
return stream_->GetWeakPtr();
}
-void MimeHandlerViewGuest::OnRequest(
- const ExtensionHostMsg_Request_Params& params) {
- if (extension_function_dispatcher_) {
- extension_function_dispatcher_->Dispatch(
- params, web_contents()->GetRenderViewHost());
- }
-}
-
} // namespace extensions
diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h
index f95aab7..33ff28e 100644
--- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h
+++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h
@@ -7,7 +7,6 @@
#include "base/memory/weak_ptr.h"
#include "components/guest_view/browser/guest_view.h"
-#include "extensions/browser/extension_function_dispatcher.h"
namespace content {
class WebContents;
@@ -50,18 +49,14 @@ class StreamContainer {
base::WeakPtrFactory<StreamContainer> weak_factory_;
};
-class MimeHandlerViewGuest : public guest_view::GuestView<MimeHandlerViewGuest>,
- public ExtensionFunctionDispatcher::Delegate {
+class MimeHandlerViewGuest :
+ public guest_view::GuestView<MimeHandlerViewGuest> {
public:
static guest_view::GuestViewBase* Create(
content::WebContents* owner_web_contents);
static const char Type[];
- // ExtensionFunctionDispatcher::Delegate implementation.
- WindowController* GetExtensionWindowController() const override;
- content::WebContents* GetAssociatedWebContents() const override;
-
// GuestViewBase implementation.
const char* GetAPINamespace() const override;
int GetTaskPrefix() const override;
@@ -96,7 +91,6 @@ class MimeHandlerViewGuest : public guest_view::GuestView<MimeHandlerViewGuest>,
// content::WebContentsObserver implementation.
void DocumentOnLoadCompletedInMainFrame() override;
- bool OnMessageReceived(const IPC::Message& message) override;
std::string view_id() const { return view_id_; }
base::WeakPtr<StreamContainer> GetStream() const;
@@ -106,10 +100,7 @@ class MimeHandlerViewGuest : public guest_view::GuestView<MimeHandlerViewGuest>,
~MimeHandlerViewGuest() override;
private:
- void OnRequest(const ExtensionHostMsg_Request_Params& params);
-
scoped_ptr<MimeHandlerViewGuestDelegate> delegate_;
- scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
scoped_ptr<StreamContainer> stream_;
std::string view_id_;
diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h
index b9a6fe3..e065104d 100644
--- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h
+++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h
@@ -19,12 +19,9 @@ class MimeHandlerViewGuest;
// A delegate class of MimeHandlerViewGuest that are not a part of chrome.
class MimeHandlerViewGuestDelegate {
public:
- explicit MimeHandlerViewGuestDelegate(MimeHandlerViewGuest* guest) {}
+ MimeHandlerViewGuestDelegate() {}
virtual ~MimeHandlerViewGuestDelegate() {}
- // Attaches helpers upon initializing the WebContents.
- virtual void AttachHelpers() {}
-
// Handles context menu, or returns false if unhandled.
virtual bool HandleContextMenu(content::WebContents* web_contents,
const content::ContextMenuParams& params);
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc
index fe72e68..0907b3aa 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.cc
+++ b/extensions/browser/guest_view/web_view/web_view_guest.cc
@@ -362,7 +362,8 @@ void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) {
if (web_view_guest_delegate_)
web_view_guest_delegate_->OnDidInitialize();
- AttachWebViewHelpers(web_contents());
+ ExtensionsAPIClient::Get()->AttachWebContentsHelpers(web_contents());
+ web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
rules_registry_id_ = GetOrGenerateRulesRegistryID(
owner_web_contents()->GetRenderProcessHost()->GetID(),
@@ -376,12 +377,6 @@ void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) {
ApplyAttributes(create_params);
}
-void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
- if (web_view_guest_delegate_)
- web_view_guest_delegate_->OnAttachWebViewHelpers(contents);
- web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
-}
-
void WebViewGuest::ClearDataInternal(base::Time remove_since,
uint32 removal_mask,
const base::Closure& callback) {
diff --git a/extensions/browser/guest_view/web_view/web_view_guest.h b/extensions/browser/guest_view/web_view/web_view_guest.h
index 08bd060..ea7b4f6 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest.h
+++ b/extensions/browser/guest_view/web_view/web_view_guest.h
@@ -268,8 +268,6 @@ class WebViewGuest : public guest_view::GuestView<WebViewGuest>,
~WebViewGuest() override;
- void AttachWebViewHelpers(content::WebContents* contents);
-
void ClearDataInternal(const base::Time remove_since,
uint32 removal_mask,
const base::Closure& callback);
diff --git a/extensions/browser/guest_view/web_view/web_view_guest_delegate.h b/extensions/browser/guest_view/web_view/web_view_guest_delegate.h
index cf827ba..1fbabf8 100644
--- a/extensions/browser/guest_view/web_view/web_view_guest_delegate.h
+++ b/extensions/browser/guest_view/web_view/web_view_guest_delegate.h
@@ -35,9 +35,6 @@ class WebViewGuestDelegate {
// Called when context menu operation was handled.
virtual bool HandleContextMenu(const content::ContextMenuParams& params) = 0;
- // Called to attach helpers just after additional initialization is performed.
- virtual void OnAttachWebViewHelpers(content::WebContents* contents) = 0;
-
// Called just after additional initialization is performed.
virtual void OnDidInitialize() = 0;
diff --git a/extensions/browser/test_extensions_browser_client.cc b/extensions/browser/test_extensions_browser_client.cc
index 30e39b0..6f2821d 100644
--- a/extensions/browser/test_extensions_browser_client.cc
+++ b/extensions/browser/test_extensions_browser_client.cc
@@ -198,4 +198,10 @@ bool TestExtensionsBrowserClient::IsMinBrowserVersionSupported(
return true;
}
+ExtensionWebContentsObserver*
+TestExtensionsBrowserClient::GetExtensionWebContentsObserver(
+ content::WebContents* web_contents) {
+ return nullptr;
+}
+
} // namespace extensions
diff --git a/extensions/browser/test_extensions_browser_client.h b/extensions/browser/test_extensions_browser_client.h
index 84a4ed3..9adf4d5 100644
--- a/extensions/browser/test_extensions_browser_client.h
+++ b/extensions/browser/test_extensions_browser_client.h
@@ -94,6 +94,8 @@ class TestExtensionsBrowserClient : public ExtensionsBrowserClient {
ExtensionCache* GetExtensionCache() override;
bool IsBackgroundUpdateAllowed() override;
bool IsMinBrowserVersionSupported(const std::string& min_version) override;
+ ExtensionWebContentsObserver* GetExtensionWebContentsObserver(
+ content::WebContents* web_contents) override;
private:
content::BrowserContext* main_context_; // Not owned.