summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/render_view.cc5
-rw-r--r--chrome/renderer/user_script_slave.cc27
-rw-r--r--chrome/renderer/user_script_slave.h2
3 files changed, 30 insertions, 4 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index ae98ac3..7c626ad 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -3606,8 +3606,9 @@ void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
sources.push_back(
WebScriptSource(WebString::fromUTF8(code_string)));
UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
- main_frame->executeScriptInNewWorld(&sources.front(), sources.size(),
- EXTENSION_GROUP_CONTENT_SCRIPTS);
+ main_frame->executeScriptInIsolatedWorld(
+ UserScriptSlave::GetIsolatedWorldId(extension_id),
+ &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
} else {
main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
}
diff --git a/chrome/renderer/user_script_slave.cc b/chrome/renderer/user_script_slave.cc
index f76a1e7..86fcc1a 100644
--- a/chrome/renderer/user_script_slave.cc
+++ b/chrome/renderer/user_script_slave.cc
@@ -32,6 +32,25 @@ static const char kInitExtension[] =
"chrome.extension = new chrome.Extension('%s');"
"chrome.self.onConnect = chrome.extension.onConnect;";
+int UserScriptSlave::GetIsolatedWorldId(const std::string& extension_id) {
+ typedef std::map<std::string, int> IsolatedWorldMap;
+
+ static IsolatedWorldMap g_isolated_world_ids;
+ static int g_next_isolated_world_id = 1;
+
+ IsolatedWorldMap::iterator iter = g_isolated_world_ids.find(extension_id);
+ if (iter != g_isolated_world_ids.end())
+ return iter->second;
+
+ int new_id = g_next_isolated_world_id;
+ ++g_next_isolated_world_id;
+
+ // This map will tend to pile up over time, but realistically, you're never
+ // going to have enough extensions for it to matter.
+ g_isolated_world_ids[extension_id] = new_id;
+ return new_id;
+}
+
UserScriptSlave::UserScriptSlave()
: shared_memory_(NULL),
script_deleter_(&scripts_),
@@ -159,6 +178,8 @@ bool UserScriptSlave::InjectScripts(WebFrame* frame,
}
if (!sources.empty()) {
+ int isolated_world_id = 0;
+
if (script->is_standalone()) {
// For standalone scripts, we try to emulate the Greasemonkey API.
sources.insert(sources.begin(),
@@ -167,10 +188,12 @@ bool UserScriptSlave::InjectScripts(WebFrame* frame,
// Setup chrome.self to contain an Extension object with the correct
// ID.
InsertInitExtensionCode(&sources, script->extension_id());
+ isolated_world_id = GetIsolatedWorldId(script->extension_id());
}
- frame->executeScriptInNewWorld(&sources.front(), sources.size(),
- EXTENSION_GROUP_CONTENT_SCRIPTS);
+ frame->executeScriptInIsolatedWorld(
+ isolated_world_id, &sources.front(), sources.size(),
+ EXTENSION_GROUP_CONTENT_SCRIPTS);
}
}
diff --git a/chrome/renderer/user_script_slave.h b/chrome/renderer/user_script_slave.h
index 39407f1..8232ec4 100644
--- a/chrome/renderer/user_script_slave.h
+++ b/chrome/renderer/user_script_slave.h
@@ -35,6 +35,8 @@ class UserScriptSlave {
// testability.
bool InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location);
+ static int GetIsolatedWorldId(const std::string& extension_id);
+
static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources,
const std::string& extension_id);
private: