summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc4
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h1
-rw-r--r--chrome/browser/extensions/extension_event_names.cc1
-rw-r--r--chrome/browser/extensions/extension_event_names.h1
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc6
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc46
-rw-r--r--chrome/browser/extensions/extension_process_manager.h13
7 files changed, 69 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index 3bd807a..c7a5b33 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -329,6 +329,7 @@ void ExtensionBrowserEventRouter::TabChangedAt(TabContents* contents,
void ExtensionBrowserEventRouter::TabStripEmpty() { }
void ExtensionBrowserEventRouter::PageActionExecuted(Profile* profile,
+ std::string extension_id,
std::string page_action_id,
int tab_id,
std::string url) {
@@ -346,5 +347,6 @@ void ExtensionBrowserEventRouter::PageActionExecuted(Profile* profile,
std::string json_args;
JSONWriter::Write(&args, false, &json_args);
- DispatchEvent(profile, events::kOnPageActionExecuted, json_args);
+ std::string event_name = extension_id + std::string("/") + page_action_id;
+ DispatchEvent(profile, event_name.c_str(), json_args);
}
diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h
index 0cfd075..d2f7613 100644
--- a/chrome/browser/extensions/extension_browser_event_router.h
+++ b/chrome/browser/extensions/extension_browser_event_router.h
@@ -50,6 +50,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
// PageActions.
void PageActionExecuted(Profile* profile,
+ std::string extension_id,
std::string page_action_id,
int tab_id,
std::string url);
diff --git a/chrome/browser/extensions/extension_event_names.cc b/chrome/browser/extensions/extension_event_names.cc
index f4fd6e7..214d37b 100644
--- a/chrome/browser/extensions/extension_event_names.cc
+++ b/chrome/browser/extensions/extension_event_names.cc
@@ -6,7 +6,6 @@
namespace extension_event_names {
-const char kOnPageActionExecuted[] = "page-action-executed";
const char kOnTabAttached[] = "tab-attached";
const char kOnTabCreated[] = "tab-created";
const char kOnTabDetached[] = "tab-detached";
diff --git a/chrome/browser/extensions/extension_event_names.h b/chrome/browser/extensions/extension_event_names.h
index 9b9e3f2..3e3673a 100644
--- a/chrome/browser/extensions/extension_event_names.h
+++ b/chrome/browser/extensions/extension_event_names.h
@@ -9,7 +9,6 @@
namespace extension_event_names {
-extern const char kOnPageActionExecuted[];
extern const char kOnTabAttached[];
extern const char kOnTabCreated[];
extern const char kOnTabDetached[];
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 8238595..43aca30 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extension_page_actions_module.h"
#include "chrome/browser/extensions/extension_page_actions_module_constants.h"
+#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
#include "chrome/browser/extensions/extension_tabs_module_constants.h"
#include "chrome/browser/profile.h"
@@ -188,6 +189,11 @@ ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
// Ensure the message service is initialized.
ExtensionMessageService::GetInstance(profile()->GetRequestContext())->Init();
+
+ // Notify the ExtensionProcessManager that the view was created.
+ ExtensionProcessManager* epm = profile()->GetExtensionProcessManager();
+ epm->RegisterExtensionProcess(extension_id(),
+ render_view_host->process()->pid());
}
ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 4c2047b..3018ea8 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -9,9 +9,11 @@
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/site_instance.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
+#include "chrome/common/render_messages.h"
static void CreateBackgroundHosts(
ExtensionProcessManager* manager, const ExtensionList* extensions) {
@@ -33,6 +35,10 @@ ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED,
Source<Profile>(profile));
+ registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED,
+ NotificationService::AllSources());
}
ExtensionProcessManager::~ExtensionProcessManager() {
@@ -78,6 +84,39 @@ ExtensionHost* ExtensionProcessManager::CreateBackgroundHost(
return host;
}
+void ExtensionProcessManager::RegisterExtensionProcess(
+ std::string extension_id, int process_id) {
+ ProcessIDMap::const_iterator it = process_ids_.find(extension_id);
+ if (it != process_ids_.end() && (*it).second == process_id)
+ return;
+
+ process_ids_[extension_id] = process_id;
+
+ ExtensionsService* extension_service =
+ browsing_instance_->profile()->GetExtensionsService();
+
+ std::vector<std::string> page_action_ids;
+ Extension* extension = extension_service->GetExtensionById(extension_id);
+ for (PageActionMap::const_iterator i = extension->page_actions().begin();
+ i != extension->page_actions().end(); ++i) {
+ page_action_ids.push_back(i->first);
+ }
+
+ RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
+ rph->Send(new ViewMsg_Extension_UpdatePageActions(extension_id,
+ page_action_ids));
+}
+
+void ExtensionProcessManager::UnregisterExtensionProcess(int process_id) {
+ ProcessIDMap::iterator it = process_ids_.begin();
+ while (it != process_ids_.end()) {
+ if (it->second == process_id)
+ process_ids_.erase(it++);
+ else
+ ++it;
+ }
+}
+
SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
return browsing_instance_->GetSiteInstanceForURL(url);
}
@@ -122,6 +161,13 @@ void ExtensionProcessManager::Observe(NotificationType type,
break;
}
+ case NotificationType::RENDERER_PROCESS_TERMINATED:
+ case NotificationType::RENDERER_PROCESS_CLOSED: {
+ RenderProcessHost* host = Source<RenderProcessHost>(source).ptr();
+ UnregisterExtensionProcess(host->pid());
+ break;
+ }
+
default:
NOTREACHED();
}
diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h
index 58f6639..e3d6b76 100644
--- a/chrome/browser/extensions/extension_process_manager.h
+++ b/chrome/browser/extensions/extension_process_manager.h
@@ -5,7 +5,9 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
+#include <map>
#include <set>
+#include <string>
#include "base/ref_counted.h"
#include "chrome/common/notification_registrar.h"
@@ -43,6 +45,13 @@ class ExtensionProcessManager : public NotificationObserver {
// Returns the SiteInstance that the given URL belongs to.
SiteInstance* GetSiteInstanceForURL(const GURL& url);
+ // Register an extension process by |extension_id| and specifying which
+ // |process_id| it belongs to.
+ void RegisterExtensionProcess(std::string extension_id, int process_id);
+
+ // Unregister an extension process with specified |process_id|.
+ void UnregisterExtensionProcess(int process_id);
+
// NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
@@ -69,6 +78,10 @@ class ExtensionProcessManager : public NotificationObserver {
// controls process grouping.
scoped_refptr<BrowsingInstance> browsing_instance_;
+ // A map of extension ID to the render_process_id that the extension lives in.
+ typedef std::map<std::string, int> ProcessIDMap;
+ ProcessIDMap process_ids_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
};