diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-16 18:54:38 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-16 18:54:38 +0000 |
commit | 740fab35301a73038485151be30940b214b571f7 (patch) | |
tree | f0a8c02dd94e9fc04c36f03a14105b64a0f01ecf /webkit/glue | |
parent | 5ce2fd2d8edaf8f5e963f2e2a47f1872862284b7 (diff) | |
download | chromium_src-740fab35301a73038485151be30940b214b571f7.zip chromium_src-740fab35301a73038485151be30940b214b571f7.tar.gz chromium_src-740fab35301a73038485151be30940b214b571f7.tar.bz2 |
Enable isolated worlds for content scripts.
R=aa
TEST=LayoutTests/http/tests/security/isolatedWorld/ (will be landing soon after this patch)
BUG=12218
Review URL: http://codereview.chromium.org/155626
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20883 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/webframe.h | 7 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 19 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 2 |
3 files changed, 24 insertions, 4 deletions
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 2d624d4..4fdede8 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -143,6 +143,13 @@ class WebFrame { virtual void ExecuteScriptInNewContext( const WebKit::WebScriptSource* sources, int num_sources) = 0; + // Executes JavaScript in a new world associated with the web frame. The + // script gets its own global scope and its own prototypes for intrinsic + // JavaScript objects (String, Array, and so-on). It also gets its own + // wrappers for all DOM nodes and DOM constructors. + virtual void ExecuteScriptInNewWorld( + const WebKit::WebScriptSource* sources, int num_sources) = 0; + // Inserts the given CSS styles at the beginning of the document. virtual bool InsertCSSStyles(const std::string& css) = 0; diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index f74dd2c..09a049f 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -1604,10 +1604,21 @@ void WebFrameImpl::ExecuteScriptInNewContext( sources_in[i].startLine)); } - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kIsolatedWorld)) - frame_->script()->evaluateInNewWorld(sources); - else - frame_->script()->evaluateInNewContext(sources); + frame_->script()->evaluateInNewContext(sources); +} + +void WebFrameImpl::ExecuteScriptInNewWorld( + const WebScriptSource* sources_in, int num_sources) { + Vector<WebCore::ScriptSourceCode> sources; + + for (int i = 0; i < num_sources; ++i) { + sources.append(WebCore::ScriptSourceCode( + webkit_glue::WebStringToString(sources_in[i].code), + webkit_glue::WebURLToKURL(sources_in[i].url), + sources_in[i].startLine)); + } + + frame_->script()->evaluateInNewWorld(sources); } std::wstring WebFrameImpl::GetName() { diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index f22f58b..1795bc8 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -105,6 +105,8 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual void ExecuteScript(const WebKit::WebScriptSource& source); virtual void ExecuteScriptInNewContext( const WebKit::WebScriptSource* sources, int num_sources); + virtual void ExecuteScriptInNewWorld( + const WebKit::WebScriptSource* sources, int num_sources); virtual bool InsertCSSStyles(const std::string& css); virtual WebKit::WebHistoryItem GetPreviousHistoryItem() const; virtual WebKit::WebHistoryItem GetCurrentHistoryItem() const; |