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 |