summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 18:54:38 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 18:54:38 +0000
commit740fab35301a73038485151be30940b214b571f7 (patch)
treef0a8c02dd94e9fc04c36f03a14105b64a0f01ecf /webkit
parent5ce2fd2d8edaf8f5e963f2e2a47f1872862284b7 (diff)
downloadchromium_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')
-rw-r--r--webkit/api/public/WebFrame.h7
-rw-r--r--webkit/glue/webframe.h7
-rw-r--r--webkit/glue/webframe_impl.cc19
-rw-r--r--webkit/glue/webframe_impl.h2
-rw-r--r--webkit/tools/test_shell/layout_test_controller.cc2
5 files changed, 32 insertions, 5 deletions
diff --git a/webkit/api/public/WebFrame.h b/webkit/api/public/WebFrame.h
index fa7e5f5..acb8dff 100644
--- a/webkit/api/public/WebFrame.h
+++ b/webkit/api/public/WebFrame.h
@@ -145,6 +145,13 @@ namespace WebKit {
virtual void executeScriptInNewContext(const WebScriptSource* sources,
unsigned numSources) = 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 WebScriptSource* sources,
+ unsigned numSources) = 0;
+
// Logs to the console associated with this frame.
virtual void addMessageToConsole(const WebConsoleMessage&) = 0;
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;
diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc
index 374f95f..5ae2bb3 100644
--- a/webkit/tools/test_shell/layout_test_controller.cc
+++ b/webkit/tools/test_shell/layout_test_controller.cc
@@ -351,7 +351,7 @@ class WorkItemIsolatedWorldScript : public LayoutTestController::WorkItem {
WorkItemIsolatedWorldScript(const string& script) : script_(script) {}
bool Run(TestShell* shell) {
WebScriptSource source(WebString::fromUTF8(script_));
- shell->webView()->GetMainFrame()->ExecuteScriptInNewContext(&source, 1);
+ shell->webView()->GetMainFrame()->ExecuteScriptInNewWorld(&source, 1);
return false;
}
private: