summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_service.cc35
-rw-r--r--chrome/browser/extensions/user_script_master.cc32
-rw-r--r--chrome/browser/extensions/user_script_master.h5
-rw-r--r--chrome/browser/extensions/user_script_master_unittest.cc4
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.cc48
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.h6
6 files changed, 123 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 8b7c516..00f1800 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -62,12 +62,14 @@
#include "chrome/common/extensions/extension_error_utils.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_l10n_util.h"
+#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/extension_resource.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/browser/browser_thread.h"
#include "content/browser/plugin_process_host.h"
#include "content/browser/plugin_service.h"
+#include "content/browser/renderer_host/render_process_host.h"
#include "content/common/json_value_serializer.h"
#include "content/common/notification_service.h"
#include "content/common/notification_type.h"
@@ -436,6 +438,8 @@ ExtensionService::ExtensionService(Profile* profile,
registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED,
NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED,
+ NotificationService::AllSources());
pref_change_registrar_.Init(profile->GetPrefs());
pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this);
pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this);
@@ -1087,6 +1091,12 @@ void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
Source<Profile>(profile_),
Details<const Extension>(extension));
+ for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance()) {
+ i.GetCurrentValue()->Send(
+ new ExtensionMsg_Loaded(ExtensionMsg_Loaded_Params(extension)));
+ }
+
bool plugins_changed = false;
for (size_t i = 0; i < extension->plugins().size(); ++i) {
const Extension::PluginInfo& plugin = extension->plugins()[i];
@@ -1121,6 +1131,11 @@ void ExtensionService::NotifyExtensionUnloaded(
Source<Profile>(profile_),
Details<UnloadedExtensionInfo>(&details));
+ for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance()) {
+ i.GetCurrentValue()->Send(new ExtensionMsg_Unloaded(extension->id()));
+ }
+
if (profile_) {
profile_->UnregisterExtensionWithRequestContexts(extension);
profile_->GetExtensionSpecialStoragePolicy()->
@@ -2028,7 +2043,25 @@ void ExtensionService::Observe(NotificationType type,
UnloadedExtensionInfo::DISABLE));
break;
}
-
+ case NotificationType::RENDERER_PROCESS_CREATED: {
+ RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
+ // Valid extension function names, used to setup bindings in renderer.
+ std::vector<std::string> function_names;
+ ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
+ process->Send(new ExtensionMsg_SetFunctionNames(function_names));
+
+ // Scripting whitelist. This is modified by tests and must be communicated
+ // to renderers.
+ process->Send(new ExtensionMsg_SetScriptingWhitelist(
+ *Extension::GetScriptingWhitelist()));
+
+ // Loaded extensions.
+ for (size_t i = 0; i < extensions_.size(); ++i) {
+ process->Send(new ExtensionMsg_Loaded(
+ ExtensionMsg_Loaded_Params(extensions_[i])));
+ }
+ break;
+ }
case NotificationType::PREF_CHANGED: {
std::string* pref_name = Details<std::string>(details).ptr();
if (*pref_name == prefs::kExtensionInstallAllowList ||
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index 88903d8..1bbab5d 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -18,8 +18,10 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/extension_resource.h"
#include "chrome/common/url_constants.h"
+#include "content/browser/renderer_host/render_process_host.h"
#include "content/common/notification_service.h"
#include "net/base/net_util.h"
@@ -303,6 +305,8 @@ UserScriptMaster::UserScriptMaster(const FilePath& script_dir, Profile* profile)
Source<Profile>(profile_));
registrar_.Add(this, NotificationType::EXTENSION_USER_SCRIPTS_UPDATED,
Source<Profile>(profile_));
+ registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED,
+ NotificationService::AllSources());
}
UserScriptMaster::~UserScriptMaster() {
@@ -325,6 +329,11 @@ void UserScriptMaster::NewScriptsAvailable(base::SharedMemory* handle) {
// We've got scripts ready to go.
shared_memory_.swap(handle_deleter);
+ for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance()) {
+ SendUpdate(i.GetCurrentValue(), handle);
+ }
+
NotificationService::current()->Notify(
NotificationType::USER_SCRIPTS_UPDATED,
Source<Profile>(profile_),
@@ -387,7 +396,12 @@ void UserScriptMaster::Observe(NotificationType type,
StartScan();
break;
}
-
+ case NotificationType::RENDERER_PROCESS_CREATED: {
+ RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
+ if (ScriptsReady())
+ SendUpdate(process, GetSharedMemory());
+ break;
+ }
default:
DCHECK(false);
}
@@ -399,3 +413,19 @@ void UserScriptMaster::StartScan() {
script_reloader_->StartScan(user_script_dir_, lone_scripts_);
}
+
+void UserScriptMaster::SendUpdate(RenderProcessHost* process,
+ base::SharedMemory* shared_memory) {
+ // If the process is being started asynchronously, early return. We'll end up
+ // calling InitUserScripts when it's created which will call this again.
+ base::ProcessHandle handle = process->GetHandle();
+ if (!handle)
+ return;
+
+ base::SharedMemoryHandle handle_for_process;
+ if (!shared_memory->ShareToProcess(handle, &handle_for_process))
+ return; // This can legitimately fail if the renderer asserts at startup.
+
+ if (base::SharedMemory::IsHandleValid(handle_for_process))
+ process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process));
+}
diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h
index 3b883df..4a21eb0 100644
--- a/chrome/browser/extensions/user_script_master.h
+++ b/chrome/browser/extensions/user_script_master.h
@@ -20,6 +20,7 @@ class StringPiece;
}
class Profile;
+class RenderProcessHost;
// Manages a segment of shared memory that contains the user scripts the user
// has installed. Lives on the UI thread.
@@ -129,6 +130,10 @@ class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
const NotificationSource& source,
const NotificationDetails& details);
+ // Sends the renderer process a new set of user scripts.
+ void SendUpdate(RenderProcessHost* process,
+ base::SharedMemory* shared_memory);
+
// Manages our notification registrations.
NotificationRegistrar registrar_;
diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc
index 14cc21b..30ab5e8 100644
--- a/chrome/browser/extensions/user_script_master_unittest.cc
+++ b/chrome/browser/extensions/user_script_master_unittest.cc
@@ -40,10 +40,13 @@ class UserScriptMasterTest : public testing::Test,
// thread look like one.
file_thread_.reset(new BrowserThread(
BrowserThread::FILE, MessageLoop::current()));
+ ui_thread_.reset(new BrowserThread(
+ BrowserThread::UI, MessageLoop::current()));
}
virtual void TearDown() {
file_thread_.reset();
+ ui_thread_.reset();
}
virtual void Observe(NotificationType type,
@@ -65,6 +68,7 @@ class UserScriptMasterTest : public testing::Test,
MessageLoop message_loop_;
scoped_ptr<BrowserThread> file_thread_;
+ scoped_ptr<BrowserThread> ui_thread_;
// Updated to the script shared memory when we get notified.
base::SharedMemory* shared_memory_;
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc
index 67e8286..8094fe5 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.cc
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc
@@ -7,6 +7,7 @@
#include "base/file_path.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extension_event_router.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/metrics/histogram_synchronizer.h"
#include "chrome/browser/nacl_host/nacl_process_host.h"
@@ -20,6 +21,7 @@
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
+#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#if defined(USE_TCMALLOC)
@@ -57,6 +59,10 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle,
OnGetExtensionMessageBundle)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddListener, OnExtensionAddListener)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_RemoveListener,
+ OnExtensionRemoveListener)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel)
#if defined(USE_TCMALLOC)
IPC_MESSAGE_HANDLER(ViewHostMsg_RendererTcmalloc, OnRendererTcmalloc)
#endif
@@ -75,12 +81,18 @@ void ChromeRenderMessageFilter::OnDestruct() const {
void ChromeRenderMessageFilter::OverrideThreadForMessage(
const IPC::Message& message, BrowserThread::ID* thread) {
- if (message.type() == ViewHostMsg_ResourceTypeStats::ID ||
+ switch (message.type()) {
+ case ViewHostMsg_ResourceTypeStats::ID:
#if defined(USE_TCMALLOC)
- message.type() == ViewHostMsg_RendererTcmalloc::ID ||
+ case ViewHostMsg_RendererTcmalloc::ID:
#endif
- message.type() == ViewHostMsg_ResourceTypeStats::ID) {
- *thread = BrowserThread::UI;
+ case ExtensionHostMsg_AddListener::ID:
+ case ExtensionHostMsg_RemoveListener::ID:
+ case ExtensionHostMsg_CloseChannel::ID:
+ *thread = BrowserThread::UI;
+ break;
+ default:
+ break;
}
}
@@ -227,6 +239,34 @@ void ChromeRenderMessageFilter::OnGetExtensionMessageBundleOnFileThread(
Send(reply_msg);
}
+void ChromeRenderMessageFilter::OnExtensionAddListener(
+ const std::string& extension_id,
+ const std::string& event_name) {
+ RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_);
+ if (!profile_->GetExtensionEventRouter() || !process)
+ return;
+
+ profile_->GetExtensionEventRouter()->AddEventListener(
+ event_name, process, extension_id);
+}
+
+void ChromeRenderMessageFilter::OnExtensionRemoveListener(
+ const std::string& extension_id,
+ const std::string& event_name) {
+ RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_);
+ if (!profile_->GetExtensionEventRouter() || !process)
+ return;
+
+ profile_->GetExtensionEventRouter()->RemoveEventListener(
+ event_name, process, extension_id);
+}
+
+void ChromeRenderMessageFilter::OnExtensionCloseChannel(int port_id) {
+ if (profile_->GetExtensionMessageService())
+ profile_->GetExtensionMessageService()->CloseChannel(port_id);
+}
+
+
#if defined(USE_TCMALLOC)
void ChromeRenderMessageFilter::OnRendererTcmalloc(base::ProcessId pid,
const std::string& output) {
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h
index 25a8ef8..aa06817 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.h
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.h
@@ -64,7 +64,6 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter {
int receiver_port_id,
int tab_id, const std::string& extension_id,
const std::string& channel_name);
-
void OnGetExtensionMessageBundle(const std::string& extension_id,
IPC::Message* reply_msg);
void OnGetExtensionMessageBundleOnFileThread(
@@ -72,6 +71,11 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter {
const std::string& extension_id,
const std::string& default_locale,
IPC::Message* reply_msg);
+ void OnExtensionAddListener(const std::string& extension_id,
+ const std::string& event_name);
+ void OnExtensionRemoveListener(const std::string& extension_id,
+ const std::string& event_name);
+ void OnExtensionCloseChannel(int port_id);
#if defined(USE_TCMALLOC)
void OnRendererTcmalloc(base::ProcessId pid, const std::string& output);
#endif