summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 20:08:33 +0000
committeraa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 20:08:33 +0000
commitf29acf538815f1d71638ac9db8798998a113955f (patch)
tree9f06b1775d4b4fa81a81482b7f95640eeb17177d
parent7ca2af2c8cb95ea08207b53076f183408e18f2ee (diff)
downloadchromium_src-f29acf538815f1d71638ac9db8798998a113955f.zip
chromium_src-f29acf538815f1d71638ac9db8798998a113955f.tar.gz
chromium_src-f29acf538815f1d71638ac9db8798998a113955f.tar.bz2
Change some places where we were using javascript: URLs to use
WebFrame::ExecuteJavaScript() instead. Review URL: http://codereview.chromium.org/8826 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4480 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider.cc8
-rw-r--r--chrome/browser/browser_focus_uitest.cc6
-rw-r--r--chrome/browser/debugger/debugger_view.cc3
-rw-r--r--chrome/browser/dom_ui/dom_ui_host.cc12
-rw-r--r--chrome/browser/resource_dispatcher_host_uitest.cc3
-rw-r--r--chrome/browser/ssl_uitest.cc36
-rw-r--r--chrome/renderer/debug_message_handler.cc6
-rw-r--r--chrome/renderer/debug_message_handler.h2
-rw-r--r--chrome/renderer/render_view.cc9
-rw-r--r--chrome/renderer/render_view.h6
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc24
11 files changed, 44 insertions, 71 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 7b9214c..820d446 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -1605,13 +1605,13 @@ void AutomationProvider::ExecuteJavascript(const IPC::Message& message,
// This routing id needs to be remembered for the reverse
// communication while sending back the response of
// this javascript execution.
- std::wstring url;
- SStringPrintf(&url,
- L"javascript:void(window.domAutomationController.setAutomationId(%d));",
+ std::wstring set_automation_id;
+ SStringPrintf(&set_automation_id,
+ L"window.domAutomationController.setAutomationId(%d);",
message.routing_id());
web_contents->render_view_host()->ExecuteJavascriptInWebFrame(
- frame_xpath, url);
+ frame_xpath, set_automation_id);
web_contents->render_view_host()->ExecuteJavascriptInWebFrame(
frame_xpath, script);
succeeded = true;
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index ec14e5e..c93c58b 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -304,8 +304,7 @@ TEST_F(BrowserFocusTest, FocusTraversal) {
// Let's make sure the focus is on the expected element in the page.
std::wstring actual;
ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(getFocusedElement());",
+ L"window.domAutomationController.send(getFocusedElement());",
&actual));
ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
@@ -329,8 +328,7 @@ TEST_F(BrowserFocusTest, FocusTraversal) {
// Let's make sure the focus is on the expected element in the page.
std::wstring actual;
ASSERT_TRUE(tab->ExecuteAndExtractString(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(getFocusedElement());",
+ L"window.domAutomationController.send(getFocusedElement());",
&actual));
ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str());
}
diff --git a/chrome/browser/debugger/debugger_view.cc b/chrome/browser/debugger/debugger_view.cc
index 89cb4e8..127c987 100644
--- a/chrome/browser/debugger/debugger_view.cc
+++ b/chrome/browser/debugger/debugger_view.cc
@@ -132,9 +132,8 @@ void DebuggerView::OpenURLFromTab(TabContents* source,
}
void DebuggerView::ExecuteJavascript(const std::string& js) {
- const std::string url = StringPrintf("javascript:void(%s)", js.c_str());
web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(L"",
- UTF8ToWide(url));
+ UTF8ToWide(js));
}
void DebuggerView::LoadingStateChanged(TabContents* source) {
diff --git a/chrome/browser/dom_ui/dom_ui_host.cc b/chrome/browser/dom_ui/dom_ui_host.cc
index 2541e71..d9d0333 100644
--- a/chrome/browser/dom_ui/dom_ui_host.cc
+++ b/chrome/browser/dom_ui/dom_ui_host.cc
@@ -102,16 +102,6 @@ WebPreferences DOMUIHost::GetWebkitPrefs() {
}
void DOMUIHost::ExecuteJavascript(const std::wstring& javascript) {
- // We're taking a string and making a javascript URL out of it. This means
- // that escaping will follow the rules of a URL. Yet, the JSON text may have
- // stuff in it that would be interpreted as escaped characters in a URL, but
- // we want to preserve them literally.
- //
- // We just escape all the percents to avoid this, since when this javascript
- // URL is interpreted, it will be unescaped.
- std::wstring escaped_js(javascript);
- ReplaceSubstringsAfterOffset(&escaped_js, 0, L"%", L"%25");
- render_view_host()->ExecuteJavascriptInWebFrame(std::wstring(),
- L"javascript:" + escaped_js);
+ render_view_host()->ExecuteJavascriptInWebFrame(std::wstring(), javascript);
}
diff --git a/chrome/browser/resource_dispatcher_host_uitest.cc b/chrome/browser/resource_dispatcher_host_uitest.cc
index 6db69fa..2f83e73 100644
--- a/chrome/browser/resource_dispatcher_host_uitest.cc
+++ b/chrome/browser/resource_dispatcher_host_uitest.cc
@@ -95,8 +95,7 @@ TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) {
// Let's check the XMLHttpRequest ran successfully.
bool success = false;
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(DidSyncRequestSucceed());",
+ L"window.domAutomationController.send(DidSyncRequestSucceed());",
&success));
EXPECT_TRUE(success);
}
diff --git a/chrome/browser/ssl_uitest.cc b/chrome/browser/ssl_uitest.cc
index 4446a02..7915cfe 100644
--- a/chrome/browser/ssl_uitest.cc
+++ b/chrome/browser/ssl_uitest.cc
@@ -236,8 +236,7 @@ TEST_F(SSLUITest, TestMixedContents) {
// The image should be filtered.
int img_width;
EXPECT_TRUE(tab->ExecuteAndExtractInt(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(ImageWidth());",
+ L"window.domAutomationController.send(ImageWidth());",
&img_width));
// In order to check that the image was not loaded, we check its width.
// The actual image (Google logo) is 114 pixels wide, we assume the broken
@@ -261,8 +260,7 @@ TEST_F(SSLUITest, TestMixedContents) {
// The image should show now.
EXPECT_TRUE(tab->ExecuteAndExtractInt(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(ImageWidth());",
+ L"window.domAutomationController.send(ImageWidth());",
&img_width));
EXPECT_LT(100, img_width);
@@ -314,8 +312,7 @@ TEST_F(SSLUITest, TestUnsafeContents) {
int img_width;
EXPECT_TRUE(tab->ExecuteAndExtractInt(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(ImageWidth());",
+ L"window.domAutomationController.send(ImageWidth());",
&img_width));
// In order to check that the image was not loaded, we check its width.
// The actual image (Google logo) is 114 pixels wide, we assume the broken
@@ -324,8 +321,7 @@ TEST_F(SSLUITest, TestUnsafeContents) {
bool js_result = false;
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(IsFooSet());",
+ L"window.domAutomationController.send(IsFooSet());",
&js_result));
EXPECT_FALSE(js_result);
}
@@ -355,7 +351,7 @@ TEST_F(SSLUITest, TestMixedContentsLoadedFromJS) {
// Load the insecure image.
bool js_result = false;
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:loadBadImage();",
+ L"loadBadImage();",
&js_result));
EXPECT_TRUE(js_result);
@@ -741,8 +737,7 @@ TEST_F(SSLUITest, TestGoodFrameNavigation) {
int64 last_nav_time = 0;
EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(clickLink('goodHTTPSLink'));",
+ L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
EXPECT_TRUE(success);
EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
@@ -757,8 +752,7 @@ TEST_F(SSLUITest, TestGoodFrameNavigation) {
// Now let's hit a bad page.
EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(clickLink('badHTTPSLink'));",
+ L"window.domAutomationController.send(clickLink('badHTTPSLink'));",
&success));
EXPECT_TRUE(success);
EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
@@ -774,7 +768,7 @@ TEST_F(SSLUITest, TestGoodFrameNavigation) {
bool is_content_evil = true;
std::wstring content_frame_xpath(L"html/frameset/frame[2]");
std::wstring is_frame_evil_js(
- L"javascript:void(window.domAutomationController)"
+ L"window.domAutomationController"
L".send(document.getElementById('evilDiv') != null);");
EXPECT_TRUE(tab->ExecuteAndExtractBool(content_frame_xpath,
is_frame_evil_js,
@@ -792,8 +786,7 @@ TEST_F(SSLUITest, TestGoodFrameNavigation) {
// Navigate to a page served over HTTP.
EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(clickLink('HTTPLink'));",
+ L"window.domAutomationController.send(clickLink('HTTPLink'));",
&success));
EXPECT_TRUE(success);
EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
@@ -845,8 +838,7 @@ TEST_F(SSLUITest, TestBadFrameNavigation) {
int64 last_nav_time = 0;
EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(clickLink('goodHTTPSLink'));",
+ L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
EXPECT_TRUE(success);
EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
@@ -887,8 +879,7 @@ TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) {
int64 last_nav_time = 0;
EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(clickLink('goodHTTPSLink'));",
+ L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
EXPECT_TRUE(success);
EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
@@ -903,8 +894,7 @@ TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) {
// Now navigate to a bad HTTPS frame.
EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
- L"javascript:void(window.domAutomationController)"
- L".send(clickLink('badHTTPSLink'));",
+ L"window.domAutomationController.send(clickLink('badHTTPSLink'));",
&success));
EXPECT_TRUE(success);
EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
@@ -920,7 +910,7 @@ TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) {
bool is_content_evil = true;
std::wstring content_frame_xpath(L"html/frameset/frame[2]");
std::wstring is_frame_evil_js(
- L"javascript:void(window.domAutomationController)"
+ L"window.domAutomationController"
L".send(document.getElementById('evilDiv') != null);");
EXPECT_TRUE(tab->ExecuteAndExtractBool(content_frame_xpath,
is_frame_evil_js,
diff --git a/chrome/renderer/debug_message_handler.cc b/chrome/renderer/debug_message_handler.cc
index 7faa430..451a28b 100644
--- a/chrome/renderer/debug_message_handler.cc
+++ b/chrome/renderer/debug_message_handler.cc
@@ -17,12 +17,12 @@ DebugMessageHandler::DebugMessageHandler(RenderView* view) :
DebugMessageHandler::~DebugMessageHandler() {
}
-void DebugMessageHandler::EvaluateScriptUrl(const std::wstring& url) {
+void DebugMessageHandler::EvaluateScript(const std::wstring& script) {
DCHECK(MessageLoop::current() == view_loop_);
// It's possible that this will get cleared out from under us.
RenderView* view = view_;
if (view) {
- view->EvaluateScriptUrl(L"", url);
+ view->EvaluateScript(L"", script);
}
}
@@ -37,7 +37,7 @@ void DebugMessageHandler::OnBreak(bool force) {
debugger_->Break(force);
if (force && view_loop_) {
view_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &DebugMessageHandler::EvaluateScriptUrl,
+ this, &DebugMessageHandler::EvaluateScript,
std::wstring(L"javascript:void(0)")));
}
}
diff --git a/chrome/renderer/debug_message_handler.h b/chrome/renderer/debug_message_handler.h
index d7724d0..f02ad88 100644
--- a/chrome/renderer/debug_message_handler.h
+++ b/chrome/renderer/debug_message_handler.h
@@ -22,7 +22,7 @@ class DebugMessageHandler : public IPC::ChannelProxy::MessageFilter,
private:
// evaluate javascript URL in the renderer
- void EvaluateScriptUrl(const std::wstring& url);
+ void EvaluateScript(const std::wstring& script);
// Debugger::Delegate callback method to handle debugger output.
void DebuggerOutput(const std::wstring& out);
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index e283499..5c0ab5a 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -2337,19 +2337,18 @@ WebFrame* RenderView::GetChildFrame(const std::wstring& frame_xpath) const {
return web_frame;
}
-void RenderView::EvaluateScriptUrl(const std::wstring& frame_xpath,
- const std::wstring& js_url) {
+void RenderView::EvaluateScript(const std::wstring& frame_xpath,
+ const std::wstring& script) {
WebFrame* web_frame = GetChildFrame(frame_xpath);
if (!web_frame)
return;
- scoped_ptr<WebRequest> request(WebRequest::Create(GURL(js_url)));
- web_frame->LoadRequest(request.get());
+ web_frame->ExecuteJavaScript(WideToUTF8(script), "");
}
void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
const std::wstring& jscript) {
- EvaluateScriptUrl(frame_xpath, jscript);
+ EvaluateScript(frame_xpath, jscript);
}
void RenderView::OnAddMessageToConsole(const std::wstring& frame_xpath,
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index e468e98..caed67d 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -289,9 +289,9 @@ class RenderView : public RenderWidget, public WebViewDelegate,
// periodic timer so we don't send too many messages.
void SyncNavigationState();
- // Evaluates a javascript: URL
- void EvaluateScriptUrl(const std::wstring& frame_xpath,
- const std::wstring& jscript);
+ // Evaluates a string of JavaScript in a particular frame.
+ void EvaluateScript(const std::wstring& frame_xpath,
+ const std::wstring& jscript);
// Called when the Javascript debugger is no longer attached.
// This is called from within the renderer, not via an IPC message.
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index 330ca2d..aa24354 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -503,10 +503,10 @@ class AutomationProxyTest4 : public UITest {
}
};
-std::wstring SynthesizeJSURL(const std::wstring& value) {
+std::wstring CreateJSString(const std::wstring& value) {
std::wstring jscript;
SStringPrintf(&jscript,
- L"javascript:void(window.domAutomationController.send(%ls));",
+ L"window.domAutomationController.send(%ls);",
value.c_str());
return jscript;
}
@@ -519,7 +519,7 @@ TEST_F(AutomationProxyTest4, StringValueIsEchoedByDomAutomationController) {
ASSERT_TRUE(tab.get());
std::wstring expected(L"string");
- std::wstring jscript = SynthesizeJSURL(L"\"" + expected + L"\"");
+ std::wstring jscript = CreateJSString(L"\"" + expected + L"\"");
std::wstring actual;
ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual));
ASSERT_STREQ(expected.c_str(), actual.c_str());
@@ -541,7 +541,7 @@ TEST_F(AutomationProxyTest4, BooleanValueIsEchoedByDomAutomationController) {
ASSERT_TRUE(tab.get());
bool expected = true;
- std::wstring jscript = SynthesizeJSURL(BooleanToString(expected));
+ std::wstring jscript = CreateJSString(BooleanToString(expected));
bool actual = false;
ASSERT_TRUE(tab->ExecuteAndExtractBool(L"", jscript, &actual));
ASSERT_EQ(expected, actual);
@@ -558,7 +558,7 @@ TEST_F(AutomationProxyTest4, NumberValueIsEchoedByDomAutomationController) {
int actual = 0;
std::wstring expected_string;
SStringPrintf(&expected_string, L"%d", expected);
- std::wstring jscript = SynthesizeJSURL(expected_string);
+ std::wstring jscript = CreateJSString(expected_string);
ASSERT_TRUE(tab->ExecuteAndExtractInt(L"", jscript, &actual));
ASSERT_EQ(expected, actual);
}
@@ -580,12 +580,10 @@ class AutomationProxyTest3 : public UITest {
std::wstring document1_;
};
-std::wstring SynthesizeJSURLForDOMQuery(const std::wstring& id) {
- std::wstring jscript;
- SStringPrintf(&jscript,
- L"javascript:void(window.domAutomationController)");
+std::wstring CreateJSStringForDOMQuery(const std::wstring& id) {
+ std::wstring jscript(L"window.domAutomationController");
StringAppendF(&jscript, L".send(document.getElementById('%ls').nodeName);",
- id.c_str());
+ id.c_str());
return jscript;
}
@@ -598,17 +596,17 @@ TEST_F(AutomationProxyTest3, FrameDocumentCanBeAccessed) {
std::wstring actual;
std::wstring xpath1 = L""; // top level frame
- std::wstring jscript1 = SynthesizeJSURLForDOMQuery(L"myinput");
+ std::wstring jscript1 = CreateJSStringForDOMQuery(L"myinput");
ASSERT_TRUE(tab->ExecuteAndExtractString(xpath1, jscript1, &actual));
ASSERT_EQ(L"INPUT", actual);
std::wstring xpath2 = L"/html/body/iframe";
- std::wstring jscript2 = SynthesizeJSURLForDOMQuery(L"myspan");
+ std::wstring jscript2 = CreateJSStringForDOMQuery(L"myspan");
ASSERT_TRUE(tab->ExecuteAndExtractString(xpath2, jscript2, &actual));
ASSERT_EQ(L"SPAN", actual);
std::wstring xpath3 = L"/html/body/iframe\n/html/body/iframe";
- std::wstring jscript3 = SynthesizeJSURLForDOMQuery(L"mydiv");
+ std::wstring jscript3 = CreateJSStringForDOMQuery(L"mydiv");
ASSERT_TRUE(tab->ExecuteAndExtractString(xpath3, jscript3, &actual));
ASSERT_EQ(L"DIV", actual);