summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 00:38:25 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-01 00:38:25 +0000
commit1a0436898a9e983e4b0188c9a7f124c5668a29a7 (patch)
tree452cba4b28542845ebb7af6fa8f68a4bdcace14e /extensions
parentfc339ed2b3623705f3109a74f477626c26859b68 (diff)
downloadchromium_src-1a0436898a9e983e4b0188c9a7f124c5668a29a7.zip
chromium_src-1a0436898a9e983e4b0188c9a7f124c5668a29a7.tar.gz
chromium_src-1a0436898a9e983e4b0188c9a7f124c5668a29a7.tar.bz2
extensions: Remove ChromeRenderMessageFilter dependency.
Move handling of ExtensionHostMsg_RequestForIOThread messages from ChromeRenderMessageFilter to ExtensionMessageFilter. BUG=339637 TBR=darin@chromium.org Review URL: https://codereview.chromium.org/218623003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260720 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/extension_function.cc2
-rw-r--r--extensions/browser/extension_function.h21
-rw-r--r--extensions/browser/extension_function_dispatcher.cc69
-rw-r--r--extensions/browser/extension_function_dispatcher.h30
-rw-r--r--extensions/browser/extension_message_filter.cc21
-rw-r--r--extensions/browser/extension_message_filter.h14
6 files changed, 94 insertions, 63 deletions
diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc
index 7b1b89e..d79b1d0 100644
--- a/extensions/browser/extension_function.cc
+++ b/extensions/browser/extension_function.cc
@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "base/metrics/sparse_histogram.h"
-#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
@@ -14,6 +13,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/extension_function_dispatcher.h"
+#include "extensions/browser/extension_message_filter.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_messages.h"
diff --git a/extensions/browser/extension_function.h b/extensions/browser/extension_function.h
index 996fbce..6090857 100644
--- a/extensions/browser/extension_function.h
+++ b/extensions/browser/extension_function.h
@@ -22,9 +22,7 @@
#include "extensions/common/extension.h"
#include "ipc/ipc_message.h"
-class ChromeRenderMessageFilter;
class ExtensionFunction;
-class ExtensionFunctionDispatcher;
class UIThreadExtensionFunction;
class IOThreadExtensionFunction;
@@ -41,6 +39,8 @@ class WebContents;
}
namespace extensions {
+class ExtensionFunctionDispatcher;
+class ExtensionMessageFilter;
class QuotaLimitHeuristic;
}
@@ -316,11 +316,11 @@ class UIThreadExtensionFunction : public ExtensionFunction {
return render_frame_host_;
}
- void set_dispatcher(
- const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher) {
+ void set_dispatcher(const base::WeakPtr<
+ extensions::ExtensionFunctionDispatcher>& dispatcher) {
dispatcher_ = dispatcher;
}
- ExtensionFunctionDispatcher* dispatcher() const {
+ extensions::ExtensionFunctionDispatcher* dispatcher() const {
return dispatcher_.get();
}
@@ -342,7 +342,7 @@ class UIThreadExtensionFunction : public ExtensionFunction {
virtual void SendResponse(bool success) OVERRIDE;
// The dispatcher that will service this extension function call.
- base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_;
+ base::WeakPtr<extensions::ExtensionFunctionDispatcher> dispatcher_;
// The RenderViewHost we will send responses to.
content::RenderViewHost* render_view_host_;
@@ -377,13 +377,14 @@ class IOThreadExtensionFunction : public ExtensionFunction {
virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction() OVERRIDE;
- void set_ipc_sender(base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
- int routing_id) {
+ void set_ipc_sender(
+ base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender,
+ int routing_id) {
ipc_sender_ = ipc_sender;
routing_id_ = routing_id;
}
- base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_weak() const {
+ base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender_weak() const {
return ipc_sender_;
}
@@ -408,7 +409,7 @@ class IOThreadExtensionFunction : public ExtensionFunction {
virtual void SendResponse(bool success) OVERRIDE;
private:
- base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_;
+ base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender_;
int routing_id_;
scoped_refptr<const extensions::InfoMap> extension_info_map_;
diff --git a/extensions/browser/extension_function_dispatcher.cc b/extensions/browser/extension_function_dispatcher.cc
index e5ab1e4..5e0cffe 100644
--- a/extensions/browser/extension_function_dispatcher.cc
+++ b/extensions/browser/extension_function_dispatcher.cc
@@ -12,7 +12,6 @@
#include "base/process/process.h"
#include "base/values.h"
#include "build/build_config.h"
-#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
@@ -23,6 +22,7 @@
#include "content/public/common/result_codes.h"
#include "extensions/browser/api_activity_monitor.h"
#include "extensions/browser/extension_function_registry.h"
+#include "extensions/browser/extension_message_filter.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
@@ -35,14 +35,10 @@
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
-using extensions::Extension;
-using extensions::ExtensionAPI;
-using extensions::ExtensionsBrowserClient;
-using extensions::ExtensionSystem;
-using extensions::Feature;
using content::BrowserThread;
using content::RenderViewHost;
+namespace extensions {
namespace {
// Notifies the ApiActivityMonitor that an extension API function has been
@@ -67,7 +63,7 @@ void NotifyApiFunctionCalled(const std::string& extension_id,
if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
return;
- extensions::ApiActivityMonitor* monitor =
+ ApiActivityMonitor* monitor =
ExtensionsBrowserClient::Get()->GetApiActivityMonitor(browser_context);
if (monitor)
monitor->OnApiFunctionCalled(extension_id, api_name, args.Pass());
@@ -77,10 +73,8 @@ void NotifyApiFunctionCalled(const std::string& extension_id,
// this because ExtensionAPI has mutable data. It should be possible to remove
// this once all the extension APIs are updated to the feature system.
struct Static {
- Static()
- : api(extensions::ExtensionAPI::CreateWithDefaultConfiguration()) {
- }
- scoped_ptr<extensions::ExtensionAPI> api;
+ Static() : api(ExtensionAPI::CreateWithDefaultConfiguration()) {}
+ scoped_ptr<ExtensionAPI> api;
};
base::LazyInstance<Static> g_global_io_data = LAZY_INSTANCE_INITIALIZER;
@@ -124,7 +118,7 @@ void CommonResponseCallback(IPC::Sender* ipc_sender,
}
void IOThreadResponseCallback(
- const base::WeakPtr<ChromeRenderMessageFilter>& ipc_sender,
+ const base::WeakPtr<ExtensionMessageFilter>& ipc_sender,
int routing_id,
int request_id,
ExtensionFunction::ResponseType type,
@@ -200,9 +194,8 @@ class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper
DISALLOW_COPY_AND_ASSIGN(UIThreadResponseCallbackWrapper);
};
-extensions::WindowController*
-ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController()
- const {
+WindowController*
+ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() const {
return NULL;
}
@@ -229,10 +222,10 @@ bool ExtensionFunctionDispatcher::OverrideFunction(
// static
void ExtensionFunctionDispatcher::DispatchOnIOThread(
- extensions::InfoMap* extension_info_map,
- void* browser_context,
+ InfoMap* extension_info_map,
+ void* profile_id,
int render_process_id,
- base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
+ base::WeakPtr<ExtensionMessageFilter> ipc_sender,
int routing_id,
const ExtensionHostMsg_Request_Params& params) {
const Extension* extension =
@@ -243,10 +236,13 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
params.request_id));
scoped_refptr<ExtensionFunction> function(
- CreateExtensionFunction(params, extension, render_process_id,
+ CreateExtensionFunction(params,
+ extension,
+ render_process_id,
extension_info_map->process_map(),
g_global_io_data.Get().api.get(),
- browser_context, callback));
+ profile_id,
+ callback));
if (!function.get())
return;
@@ -264,18 +260,17 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
if (!CheckPermissions(function.get(), extension, params, callback))
return;
- extensions::QuotaService* quota = extension_info_map->GetQuotaService();
+ QuotaService* quota = extension_info_map->GetQuotaService();
std::string violation_error = quota->Assess(extension->id(),
function.get(),
&params.arguments,
base::TimeTicks::Now());
if (violation_error.empty()) {
scoped_ptr<base::ListValue> args(params.arguments.DeepCopy());
- NotifyApiFunctionCalled(
- extension->id(),
- params.name,
- args.Pass(),
- static_cast<content::BrowserContext*>(browser_context));
+ NotifyApiFunctionCalled(extension->id(),
+ params.name,
+ args.Pass(),
+ static_cast<content::BrowserContext*>(profile_id));
function->Run();
} else {
function->OnQuotaExceeded(violation_error);
@@ -326,13 +321,11 @@ void ExtensionFunctionDispatcher::DispatchWithCallbackInternal(
DCHECK(render_view_host || render_frame_host);
// TODO(yzshen): There is some shared logic between this method and
// DispatchOnIOThread(). It is nice to deduplicate.
- extensions::ProcessMap* process_map =
- extensions::ProcessMap::Get(browser_context_);
+ ProcessMap* process_map = ProcessMap::Get(browser_context_);
if (!process_map)
return;
- extensions::ExtensionRegistry* registry =
- extensions::ExtensionRegistry::Get(browser_context_);
+ ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
const Extension* extension = registry->enabled_extensions().GetByID(
params.extension_id);
if (!extension) {
@@ -347,7 +340,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallbackInternal(
extension,
process_id,
*process_map,
- extensions::ExtensionAPI::GetSharedInstance(),
+ ExtensionAPI::GetSharedInstance(),
browser_context_,
callback));
if (!function.get())
@@ -374,7 +367,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallbackInternal(
return;
ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_);
- extensions::QuotaService* quota = extension_system->quota_service();
+ QuotaService* quota = extension_system->quota_service();
std::string violation_error = quota->Assess(extension->id(),
function.get(),
&params.arguments,
@@ -437,7 +430,7 @@ namespace {
bool AllowHostedAppAPICall(const Extension& extension,
const GURL& source_url,
const std::string& function_name) {
- if (extension.location() != extensions::Manifest::COMPONENT)
+ if (extension.location() != Manifest::COMPONENT)
return false;
if (!extension.web_extent().MatchesURL(source_url))
@@ -461,9 +454,9 @@ ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction(
const ExtensionHostMsg_Request_Params& params,
const Extension* extension,
int requesting_process_id,
- const extensions::ProcessMap& process_map,
- extensions::ExtensionAPI* api,
- void* profile,
+ const ProcessMap& process_map,
+ ExtensionAPI* api,
+ void* profile_id,
const ExtensionFunction::ResponseCallback& callback) {
if (!extension) {
LOG(ERROR) << "Specified extension does not exist.";
@@ -503,7 +496,7 @@ ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction(
function->set_has_callback(params.has_callback);
function->set_user_gesture(params.user_gesture);
function->set_extension(extension);
- function->set_profile_id(profile);
+ function->set_profile_id(profile_id);
function->set_response_callback(callback);
function->set_source_tab_id(params.source_tab_id);
@@ -517,3 +510,5 @@ void ExtensionFunctionDispatcher::SendAccessDenied(
callback.Run(ExtensionFunction::FAILED, empty_list,
"Access to extension API denied.");
}
+
+} // namespace extensions
diff --git a/extensions/browser/extension_function_dispatcher.h b/extensions/browser/extension_function_dispatcher.h
index 7514505..e6ef445 100644
--- a/extensions/browser/extension_function_dispatcher.h
+++ b/extensions/browser/extension_function_dispatcher.h
@@ -13,7 +13,6 @@
#include "extensions/browser/extension_function.h"
#include "ipc/ipc_sender.h"
-class ChromeRenderMessageFilter;
struct ExtensionHostMsg_Request_Params;
namespace content {
@@ -24,12 +23,13 @@ class WebContents;
}
namespace extensions {
+
class Extension;
class ExtensionAPI;
+class ExtensionMessageFilter;
class InfoMap;
class ProcessMap;
class WindowController;
-}
// A factory function for creating new ExtensionFunction instances.
typedef ExtensionFunction* (*ExtensionFunctionFactory)();
@@ -52,9 +52,9 @@ class ExtensionFunctionDispatcher
public:
class Delegate {
public:
- // Returns the extensions::WindowController associated with this delegate,
- // or NULL if no window is associated with the delegate.
- virtual extensions::WindowController* GetExtensionWindowController() const;
+ // Returns the WindowController associated with this delegate, or NULL if no
+ // window is associated with the delegate.
+ virtual WindowController* GetExtensionWindowController() const;
// Asks the delegate for any relevant WebContents associated with this
// context. For example, the WebContents in which an infobar or
@@ -82,10 +82,10 @@ class ExtensionFunctionDispatcher
// Dispatches an IO-thread extension function. Only used for specific
// functions that must be handled on the IO-thread.
static void DispatchOnIOThread(
- extensions::InfoMap* extension_info_map,
- void* profile,
+ InfoMap* extension_info_map,
+ void* profile_id,
int render_process_id,
- base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
+ base::WeakPtr<ExtensionMessageFilter> ipc_sender,
int routing_id,
const ExtensionHostMsg_Request_Params& params);
@@ -115,7 +115,7 @@ class ExtensionFunctionDispatcher
// Called when an ExtensionFunction is done executing, after it has sent
// a response (if any) to the extension.
- void OnExtensionFunctionCompleted(const extensions::Extension* extension);
+ void OnExtensionFunctionCompleted(const Extension* extension);
// The BrowserContext that this dispatcher is associated with.
content::BrowserContext* browser_context() { return browser_context_; }
@@ -134,7 +134,7 @@ class ExtensionFunctionDispatcher
// is returned. |function| must not be run in that case.
static bool CheckPermissions(
ExtensionFunction* function,
- const extensions::Extension* extension,
+ const Extension* extension,
const ExtensionHostMsg_Request_Params& params,
const ExtensionFunction::ResponseCallback& callback);
@@ -143,11 +143,11 @@ class ExtensionFunctionDispatcher
// Does not set subclass properties, or include_incognito.
static ExtensionFunction* CreateExtensionFunction(
const ExtensionHostMsg_Request_Params& params,
- const extensions::Extension* extension,
+ const Extension* extension,
int requesting_process_id,
- const extensions::ProcessMap& process_map,
- extensions::ExtensionAPI* api,
- void* profile,
+ const ProcessMap& process_map,
+ ExtensionAPI* api,
+ void* profile_id,
const ExtensionFunction::ResponseCallback& callback);
// Helper to run the response callback with an access denied error. Can be
@@ -173,4 +173,6 @@ class ExtensionFunctionDispatcher
UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_;
};
+} // namespace extensions
+
#endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_DISPATCHER_H_
diff --git a/extensions/browser/extension_message_filter.cc b/extensions/browser/extension_message_filter.cc
index d31f6e0..3a06493 100644
--- a/extensions/browser/extension_message_filter.cc
+++ b/extensions/browser/extension_message_filter.cc
@@ -8,7 +8,9 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_dispatcher_host.h"
#include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/info_map.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension_messages.h"
#include "ipc/ipc_message_macros.h"
@@ -22,7 +24,9 @@ ExtensionMessageFilter::ExtensionMessageFilter(int render_process_id,
content::BrowserContext* context)
: BrowserMessageFilter(ExtensionMsgStart),
render_process_id_(render_process_id),
- browser_context_(context) {
+ browser_context_(context),
+ extension_info_map_(ExtensionSystem::Get(context)->info_map()),
+ weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
@@ -71,6 +75,8 @@ bool ExtensionMessageFilter::OnMessageReceived(const IPC::Message& message,
OnExtensionGenerateUniqueID)
IPC_MESSAGE_HANDLER(ExtensionHostMsg_ResumeRequests,
OnExtensionResumeRequests);
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestForIOThread,
+ OnExtensionRequestForIOThread)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -172,4 +178,17 @@ void ExtensionMessageFilter::OnExtensionResumeRequests(int route_id) {
render_process_id_, route_id);
}
+void ExtensionMessageFilter::OnExtensionRequestForIOThread(
+ int routing_id,
+ const ExtensionHostMsg_Request_Params& params) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ExtensionFunctionDispatcher::DispatchOnIOThread(
+ extension_info_map_.get(),
+ browser_context_,
+ render_process_id_,
+ weak_ptr_factory_.GetWeakPtr(),
+ routing_id,
+ params);
+}
+
} // namespace extensions
diff --git a/extensions/browser/extension_message_filter.h b/extensions/browser/extension_message_filter.h
index 8518bf9e..62c4f02 100644
--- a/extensions/browser/extension_message_filter.h
+++ b/extensions/browser/extension_message_filter.h
@@ -9,8 +9,11 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
#include "content/public/browser/browser_message_filter.h"
+struct ExtensionHostMsg_Request_Params;
+
namespace base {
class DictionaryValue;
}
@@ -21,6 +24,8 @@ class BrowserContext;
namespace extensions {
+class InfoMap;
+
// This class filters out incoming extension-specific IPC messages from the
// renderer process. It is created on the UI thread. Messages may be handled on
// the IO thread or the UI thread.
@@ -29,6 +34,8 @@ class ExtensionMessageFilter : public content::BrowserMessageFilter {
ExtensionMessageFilter(int render_process_id,
content::BrowserContext* context);
+ int render_process_id() { return render_process_id_; }
+
private:
virtual ~ExtensionMessageFilter();
@@ -63,12 +70,19 @@ class ExtensionMessageFilter : public content::BrowserMessageFilter {
// Message handlers on the IO thread.
void OnExtensionGenerateUniqueID(int* unique_id);
void OnExtensionResumeRequests(int route_id);
+ void OnExtensionRequestForIOThread(
+ int routing_id,
+ const ExtensionHostMsg_Request_Params& params);
const int render_process_id_;
// Should only be accessed on the UI thread.
content::BrowserContext* browser_context_;
+ scoped_refptr<extensions::InfoMap> extension_info_map_;
+
+ base::WeakPtrFactory<ExtensionMessageFilter> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter);
};