diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 01:52:56 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 01:52:56 +0000 |
commit | 146486ff9a39e4d323df0e60e891e33a1e8d8390 (patch) | |
tree | f61da72a65c5c94807b639a6c88b7d8b4369dfb2 /chrome/renderer/user_script_slave.cc | |
parent | a74efa3f82f1ce5ed2d61cfc1ac22410355eb32f (diff) | |
download | chromium_src-146486ff9a39e4d323df0e60e891e33a1e8d8390.zip chromium_src-146486ff9a39e4d323df0e60e891e33a1e8d8390.tar.gz chromium_src-146486ff9a39e4d323df0e60e891e33a1e8d8390.tar.bz2 |
Make all content scripts from an extension run in the same
isolated world. Chromium side of change.
Review URL: http://codereview.chromium.org/262002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/user_script_slave.cc')
-rw-r--r-- | chrome/renderer/user_script_slave.cc | 27 |
1 files changed, 25 insertions, 2 deletions
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); } } |