Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 1123783002: Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/render_frame_host_impl.cc
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
index 81aa7c30c1a561f5f76398b39242903972e2dcac..c7314b4ad4b5645f75fe126caa498a8326fe197f 100644
--- a/content/browser/frame_host/render_frame_host_impl.cc
+++ b/content/browser/frame_host/render_frame_host_impl.cc
@@ -92,6 +92,10 @@ int g_next_accessibility_reset_token = 1;
// The next value to use for the javascript callback id.
int g_next_javascript_callback_id = 1;
+// Whether to allow injecting javascript into any kind of frame (for Android
+// WebView).
+bool g_allow_injecting_javascript = false;
+
// The (process id, routing id) pair that identifies one RenderFrame.
typedef std::pair<int32, int32> RenderFrameHostID;
typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
@@ -127,6 +131,11 @@ RenderFrameHost* RenderFrameHost::FromID(int render_process_id,
}
// static
+void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() {
+ g_allow_injecting_javascript = true;
+}
+
+// static
RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id,
int routing_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -272,6 +281,7 @@ void RenderFrameHostImpl::AddMessageToConsole(ConsoleMessageLevel level,
void RenderFrameHostImpl::ExecuteJavaScript(
const base::string16& javascript) {
+ CHECK(CanExecuteJavaScript());
Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
javascript,
0, false));
@@ -280,6 +290,7 @@ void RenderFrameHostImpl::ExecuteJavaScript(
void RenderFrameHostImpl::ExecuteJavaScript(
const base::string16& javascript,
const JavaScriptResultCallback& callback) {
+ CHECK(CanExecuteJavaScript());
int key = g_next_javascript_callback_id++;
Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
javascript,
@@ -287,6 +298,23 @@ void RenderFrameHostImpl::ExecuteJavaScript(
javascript_callbacks_.insert(std::make_pair(key, callback));
}
+void RenderFrameHostImpl::ExecuteJavaScriptForTests(
+ const base::string16& javascript) {
+ Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_,
+ javascript,
+ 0, false, false));
+}
+
+void RenderFrameHostImpl::ExecuteJavaScriptForTests(
+ const base::string16& javascript,
+ const JavaScriptResultCallback& callback) {
+ int key = g_next_javascript_callback_id++;
+ Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, javascript,
+ key, true, false));
+ javascript_callbacks_.insert(std::make_pair(key, callback));
+}
+
+
void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests(
const base::string16& javascript) {
Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_,
@@ -2132,4 +2160,16 @@ void RenderFrameHostImpl::UpdatePermissionsForNavigation(
}
}
+bool RenderFrameHostImpl::CanExecuteJavaScript() {
+ return g_allow_injecting_javascript ||
+ frame_tree_node_->current_url().SchemeIs(kChromeDevToolsScheme) ||
+ ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
+ GetProcess()->GetID()) ||
+ // It's possible to load about:blank in a Web UI renderer.
+ // See http://crbug.com/42547
+ (frame_tree_node_->current_url().spec() == url::kAboutBlankURL) ||
+ // InterstitialPageImpl should be the only case matching this.
+ (delegate_->GetAsWebContents() == nullptr);
+}
+
} // namespace content
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/browser/web_contents/web_contents_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698