summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 07:47:39 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 07:47:39 +0000
commitc8865964330959b40718c0e6148288da64f14fec (patch)
tree78a39905db0a850690c673a76ef59eadb28f54d6 /chrome/renderer
parent3ce10b7c419cc4522f885008cbb3c76b02256ba3 (diff)
downloadchromium_src-c8865964330959b40718c0e6148288da64f14fec.zip
chromium_src-c8865964330959b40718c0e6148288da64f14fec.tar.gz
chromium_src-c8865964330959b40718c0e6148288da64f14fec.tar.bz2
Fix regression where we stopped running content scripts in
extension processes. BUG=29621 Review URL: http://codereview.chromium.org/505012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34668 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc20
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.h4
-rw-r--r--chrome/renderer/render_thread.cc15
-rw-r--r--chrome/renderer/render_thread.h4
-rw-r--r--chrome/renderer/user_script_slave.cc26
-rw-r--r--chrome/renderer/user_script_slave.h4
6 files changed, 42 insertions, 31 deletions
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index 7af9b5f..e7aef4b 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -12,7 +12,6 @@
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/singleton.h"
-#include "chrome/common/child_process_logging.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_message_bundle.h"
@@ -23,6 +22,7 @@
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/js_only_v8_extensions.h"
#include "chrome/renderer/extensions/renderer_extension_bindings.h"
+#include "chrome/renderer/user_script_slave.h"
#include "chrome/renderer/render_view.h"
#include "grit/common_resources.h"
#include "grit/renderer_resources.h"
@@ -105,17 +105,14 @@ static L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id) {
}
}
-static std::vector<std::string> GetActiveExtensionIDs() {
- std::vector<std::string> extension_ids;
+static void GetActiveExtensionIDs(std::set<std::string>* extension_ids) {
ExtensionPermissionsMap& permissions =
Singleton<SingletonData>()->permissions_;
for (ExtensionPermissionsMap::iterator iter = permissions.begin();
iter != permissions.end(); ++iter) {
- extension_ids.push_back(iter->first);
+ extension_ids->insert(iter->first);
}
-
- return extension_ids;
}
// A RenderViewVisitor class that iterates through the set of available
@@ -585,6 +582,11 @@ v8::Extension* ExtensionProcessBindings::Get() {
return extension;
}
+void ExtensionProcessBindings::GetActiveExtensions(
+ std::set<std::string>* extension_ids) {
+ GetActiveExtensionIDs(extension_ids);
+}
+
void ExtensionProcessBindings::SetFunctionNames(
const std::vector<std::string>& names) {
ExtensionImpl::SetFunctionNames(names);
@@ -653,12 +655,6 @@ void ExtensionProcessBindings::SetAPIPermissions(
permissions_map[Extension::kPermissionNames[i]] = false;
for (size_t i = 0; i < permissions.size(); ++i)
permissions_map[permissions[i]] = true;
-
- // Ugly hack. We also update our list of active extensions here. This always
- // gets called, even if the extension has no api permissions. In single
- // process, this has already been done in the browser code.
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
- child_process_logging::SetActiveExtensions(GetActiveExtensionIDs());
}
// static
diff --git a/chrome/renderer/extensions/extension_process_bindings.h b/chrome/renderer/extensions/extension_process_bindings.h
index 1009932..08f068d2 100644
--- a/chrome/renderer/extensions/extension_process_bindings.h
+++ b/chrome/renderer/extensions/extension_process_bindings.h
@@ -8,6 +8,7 @@
#define CHROME_RENDERER_EXTENSIONS_EXTENSION_PROCESS_BINDINGS_H_
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -26,6 +27,9 @@ class ExtensionProcessBindings {
static void SetFunctionNames(const std::vector<std::string>& names);
static v8::Extension* Get();
+ // Gets the set of extensions running in this process.
+ static void GetActiveExtensions(std::set<std::string>* extension_ids);
+
// Handles a response to an API request.
static void HandleResponse(int request_id, bool success,
const std::string& response,
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index dafe2a2..df6dc42 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -26,6 +26,7 @@
#include "base/string_util.h"
#include "base/thread_local.h"
#include "chrome/common/appcache/appcache_dispatcher.h"
+#include "chrome/common/child_process_logging.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/db_message_filter.h"
#include "chrome/common/render_messages.h"
@@ -288,6 +289,7 @@ void RenderThread::OnUpdateUserScripts(
base::SharedMemoryHandle scripts) {
DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle";
user_script_slave_->UpdateScripts(scripts);
+ UpdateActiveExtensions();
}
void RenderThread::OnSetExtensionFunctionNames(
@@ -309,6 +311,8 @@ void RenderThread::OnExtensionSetAPIPermissions(
// This is called when starting a new extension page, so start the idle
// handler ticking.
ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
+
+ UpdateActiveExtensions();
}
void RenderThread::OnExtensionSetHostPermissions(
@@ -494,6 +498,17 @@ void RenderThread::SetCacheMode(bool enabled) {
Send(new ViewHostMsg_SetCacheMode(enabled));
}
+void RenderThread::UpdateActiveExtensions() {
+ // In single-process mode, the browser process reports the active extensions.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
+ return;
+
+ std::set<std::string> active_extensions;
+ user_script_slave_->GetActiveExtensions(&active_extensions);
+ ExtensionProcessBindings::GetActiveExtensions(&active_extensions);
+ child_process_logging::SetActiveExtensions(active_extensions);
+}
+
static void* CreateHistogram(
const char *name, int min, int max, size_t buckets) {
if (min <= 0)
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 8a376aa..2b5693a 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -5,6 +5,7 @@
#ifndef CHROME_RENDERER_RENDER_THREAD_H_
#define CHROME_RENDERER_RENDER_THREAD_H_
+#include <set>
#include <string>
#include <vector>
@@ -145,6 +146,9 @@ class RenderThread : public RenderThreadBase,
// Sends a message to the browser to enable or disable the disk cache.
void SetCacheMode(bool enabled);
+ // Update the list of active extensions that will be reported when we crash.
+ void UpdateActiveExtensions();
+
private:
virtual void OnControlMessageReceived(const IPC::Message& msg);
diff --git a/chrome/renderer/user_script_slave.cc b/chrome/renderer/user_script_slave.cc
index 7ddbd71..a06d856 100644
--- a/chrome/renderer/user_script_slave.cc
+++ b/chrome/renderer/user_script_slave.cc
@@ -12,7 +12,6 @@
#include "base/pickle.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
-#include "chrome/common/child_process_logging.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -62,6 +61,13 @@ UserScriptSlave::UserScriptSlave()
IDR_GREASEMONKEY_API_JS);
}
+void UserScriptSlave::GetActiveExtensions(std::set<std::string>* extension_ids) {
+ for (size_t i = 0; i < scripts_.size(); ++i) {
+ DCHECK(!scripts_[i]->extension_id().empty());
+ extension_ids->insert(scripts_[i]->extension_id());
+ }
+}
+
bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) {
scripts_.clear();
@@ -114,24 +120,6 @@ bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) {
}
}
- // Update the crash reporter with all loaded extensions. In single process,
- // this has already been done in the browser code.
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
- std::vector<std::string> extension_ids;
- for (size_t i = 0; i < num_scripts; ++i) {
- DCHECK(!scripts_[i]->extension_id().empty());
-
- // We must check this because there can be multiple scripts from a single
- // extension. n^2, but meh, it's a small list.
- if (std::find(extension_ids.begin(), extension_ids.end(),
- scripts_[i]->extension_id()) == extension_ids.end()) {
- extension_ids.push_back(scripts_[i]->extension_id());
- }
- }
-
- child_process_logging::SetActiveExtensions(extension_ids);
- }
-
return true;
}
diff --git a/chrome/renderer/user_script_slave.h b/chrome/renderer/user_script_slave.h
index 6c32c42..cf8fb8d 100644
--- a/chrome/renderer/user_script_slave.h
+++ b/chrome/renderer/user_script_slave.h
@@ -6,6 +6,7 @@
#define CHROME_RENDERER_USER_SCRIPT_SLAVE_H_
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -27,6 +28,9 @@ class UserScriptSlave {
public:
UserScriptSlave();
+ // Returns the unique set of extension IDs this UserScriptSlave knows about.
+ void GetActiveExtensions(std::set<std::string>* extension_ids);
+
// Update the parsed scripts from shared memory.
bool UpdateScripts(base::SharedMemoryHandle shared_memory);