summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_function_dispatcher.h
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-11 06:24:35 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-11 06:24:35 +0000
commit474a38fc5b87adffa43cb75d1cb81114ec5a0843 (patch)
treeb1ba7e3bb714a33485ed0037cacdad747a1b2244 /chrome/browser/extensions/extension_function_dispatcher.h
parent76b6d6a9d0bfd4331cd13c77aede5df81bccda97 (diff)
downloadchromium_src-474a38fc5b87adffa43cb75d1cb81114ec5a0843.zip
chromium_src-474a38fc5b87adffa43cb75d1cb81114ec5a0843.tar.gz
chromium_src-474a38fc5b87adffa43cb75d1cb81114ec5a0843.tar.bz2
Looks like this introduced leaks in sync ui tests. Sigh.
Revert "Move ExtensionFunctionDispatcher to ExtensionTabHelper. This" This reverts commit 4f08bad13a0cb2e40835869a9a7d9edb16a5be9a. Revert "Fix clang warning." This reverts commit 1663f72a9360677aad91a9417b44afd03a41181f. Revert "Fix chrome os" This reverts commit 1abb1afe1b78de4bc92a82fdd1e266166bc74707. TBR=mpcomplete@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_function_dispatcher.h')
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.h71
1 files changed, 45 insertions, 26 deletions
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h
index d3b8d1c..9f91d9d 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.h
+++ b/chrome/browser/extensions/extension_function_dispatcher.h
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "googleurl/src/gurl.h"
+#include "ipc/ipc_channel.h"
#include "ui/gfx/native_widget_types.h"
class Browser;
@@ -26,19 +27,9 @@ struct ExtensionHostMsg_Request_Params;
typedef ExtensionFunction* (*ExtensionFunctionFactory)();
// ExtensionFunctionDispatcher receives requests to execute functions from
-// Chrome extensions running in a RenderViewHost and dispatches them to the
+// Chromium extensions running in a RenderViewHost and dispatches them to the
// appropriate handler. It lives entirely on the UI thread.
-//
-// ExtensionFunctionDispatcher should be a member of some class that hosts
-// RenderViewHosts and wants them to be able to display extension content.
-// This class should also implement ExtensionFunctionDispatcher::Delegate.
-//
-// Note that a single ExtensionFunctionDispatcher does *not* correspond to a
-// single RVH, a single extension, or a single URL. This is by design so that
-// we can gracefully handle cases like TabContents, where the RVH, extension,
-// and URL can all change over the lifetime of the tab. Instead, these items
-// are all passed into each request.
-class ExtensionFunctionDispatcher {
+class ExtensionFunctionDispatcher : public IPC::Channel::Listener {
public:
class Delegate {
public:
@@ -54,7 +45,7 @@ class ExtensionFunctionDispatcher {
// context. For example, the TabContents in which an infobar or
// chrome-extension://<id> URL are being shown. Callers must check for a
// NULL return value (as in the case of a background page).
- virtual TabContents* GetAssociatedTabContents() const = 0;
+ virtual TabContents* associated_tab_contents() const = 0;
protected:
virtual ~Delegate() {}
@@ -85,19 +76,21 @@ class ExtensionFunctionDispatcher {
// Resets all functions to their initial implementation.
static void ResetFunctions();
- // Public constructor. Callers must ensure that:
- // - |delegate| outlives this object.
- // - This object outlives any RenderViewHost's passed to created
- // ExtensionFunctions.
- ExtensionFunctionDispatcher(Profile* profile, Delegate* delegate);
+ // Creates an instance for the specified RenderViewHost and URL. If the URL
+ // does not contain a valid extension, returns NULL.
+ static ExtensionFunctionDispatcher* Create(RenderViewHost* render_view_host,
+ Delegate* delegate,
+ const GURL& url);
~ExtensionFunctionDispatcher();
Delegate* delegate() { return delegate_; }
- // Message handlers.
- void Dispatch(const ExtensionHostMsg_Request_Params& params,
- RenderViewHost* sender);
+ // If |message| is an extension request, handle it. Returns true if handled.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ // Send a response to a function.
+ void SendResponse(ExtensionFunction* api, bool success);
// Returns the current browser. Callers should generally prefer
// ExtensionFunction::GetCurrentBrowser() over this method, as that one
@@ -105,20 +98,46 @@ class ExtensionFunctionDispatcher {
//
// See the comments for ExtensionFunction::GetCurrentBrowser() for more
// details.
- Browser* GetCurrentBrowser(RenderViewHost* render_view_host,
- bool include_incognito);
+ Browser* GetCurrentBrowser(bool include_incognito);
+
+ // Handle a malformed message. Possibly the result of an attack, so kill
+ // the renderer.
+ void HandleBadMessage(ExtensionFunction* api);
+
+ // Gets the URL for the view we're displaying.
+ const GURL& url() { return url_; }
+
+ // Gets the ID for this extension.
+ const std::string extension_id() { return extension_id_; }
// The profile that this dispatcher is associated with.
- Profile* profile() { return profile_; }
+ Profile* profile();
+
+ // The RenderViewHost this dispatcher is associated with.
+ RenderViewHost* render_view_host() { return render_view_host_; }
private:
- // Helper to send an access denied error to the requesting render view.
- void SendAccessDenied(RenderViewHost* render_view_host, int request_id);
+ ExtensionFunctionDispatcher(RenderViewHost* render_view_host,
+ Delegate* delegate,
+ const Extension* extension,
+ const GURL& url);
+ // Message handlers.
+ void OnRequest(const ExtensionHostMsg_Request_Params& params);
+
+ // We need to keep a pointer to the profile because we use it in the dtor
+ // in sending EXTENSION_FUNCTION_DISPATCHER_DESTROYED, but by that point
+ // the render_view_host_ has been deleted.
Profile* profile_;
+ RenderViewHost* render_view_host_;
+
Delegate* delegate_;
+ GURL url_;
+
+ std::string extension_id_;
+
scoped_refptr<Peer> peer_;
};