diff options
6 files changed, 30 insertions, 8 deletions
diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc index 8de21df..6b22998 100644 --- a/chrome/browser/extensions/extension_function.cc +++ b/chrome/browser/extensions/extension_function.cc @@ -21,6 +21,10 @@ void ExtensionFunction::SendResponse(bool success) { } } +std::string ExtensionFunction::extension_id() { + return dispatcher_->extension_id(); +} + Profile* ExtensionFunction::profile() { return dispatcher_->profile(); } diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h index ed8fe9e..cc1d049 100644 --- a/chrome/browser/extensions/extension_function.h +++ b/chrome/browser/extensions/extension_function.h @@ -52,6 +52,8 @@ class ExtensionFunction { protected: void SendResponse(bool success); + std::string extension_id(); + Profile* profile(); // The arguments to the API. Only non-null if argument were specfied. diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 195b99e..56a4f61 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -96,8 +96,11 @@ void ExtensionFunctionDispatcher::GetAllFunctionNames( }
ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
- RenderViewHost* render_view_host)
- : render_view_host_(render_view_host) {}
+ RenderViewHost* render_view_host,
+ const std::string& extension_id)
+ : render_view_host_(render_view_host),
+ extension_id_(extension_id) {
+}
void ExtensionFunctionDispatcher::HandleRequest(const std::string& name,
const std::string& args,
@@ -151,4 +154,3 @@ void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) { Profile* ExtensionFunctionDispatcher::profile() {
return render_view_host_->process()->profile();
}
-
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h index 13057d8..ab3a07d 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.h +++ b/chrome/browser/extensions/extension_function_dispatcher.h @@ -22,7 +22,8 @@ class ExtensionFunctionDispatcher { // Gets a list of all known extension function names. static void GetAllFunctionNames(std::vector<std::string>* names); - ExtensionFunctionDispatcher(RenderViewHost* render_view_host); + ExtensionFunctionDispatcher(RenderViewHost* render_view_host, + const std::string& extension_id); // Handle a request to execute an extension function. void HandleRequest(const std::string& name, const std::string& args, @@ -35,11 +36,16 @@ class ExtensionFunctionDispatcher { // the renderer. void HandleBadMessage(ExtensionFunction* api); + // Gets the ID for this extension. + std::string extension_id() { return extension_id_; } + // The profile that this dispatcher is associated with. Profile* profile(); private: RenderViewHost* render_view_host_; + + std::string extension_id_; }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index c6165e6..73d888d6 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -102,8 +102,7 @@ RenderViewHost::RenderViewHost(SiteInstance* instance, run_modal_reply_msg_(NULL), has_unload_listener_(false), is_waiting_for_unload_ack_(false), - are_javascript_messages_suppressed_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(extension_function_dispatcher_(this)) { + are_javascript_messages_suppressed_(false) { DCHECK(instance_); DCHECK(delegate_); if (modal_dialog_event == NULL) @@ -893,6 +892,15 @@ void RenderViewHost::OnMsgNavigate(const IPC::Message& msg) { delegate_->DidNavigate(this, validated_params); + if (PageTransition::IsMainFrame(validated_params.transition)) { + ExtensionFunctionDispatcher* new_efd = NULL; + if (validated_params.url.SchemeIs(chrome::kExtensionScheme)) { + new_efd = new ExtensionFunctionDispatcher(this, + validated_params.url.host()); + } + extension_function_dispatcher_.reset(new_efd); + } + UpdateBackForwardListCount(); } @@ -1353,7 +1361,7 @@ void RenderViewHost::OnExtensionRequest(const std::string& name, int callback_id) { // TODO(aa): Here is where we can check that this renderer was supposed to be // able to call extension APIs. - extension_function_dispatcher_.HandleRequest(name, args, callback_id); + extension_function_dispatcher_->HandleRequest(name, args, callback_id); } void RenderViewHost::SendExtensionResponse(int callback_id, diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index babb93d..635f587 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -620,7 +620,7 @@ class RenderViewHost : public RenderWidgetHost { bool are_javascript_messages_suppressed_; // Handles processing IPC messages request extension functions be executed. - ExtensionFunctionDispatcher extension_function_dispatcher_; + scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; DISALLOW_COPY_AND_ASSIGN(RenderViewHost); }; |