OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 namespace content { | 85 namespace content { |
86 | 86 |
87 namespace { | 87 namespace { |
88 | 88 |
89 // The next value to use for the accessibility reset token. | 89 // The next value to use for the accessibility reset token. |
90 int g_next_accessibility_reset_token = 1; | 90 int g_next_accessibility_reset_token = 1; |
91 | 91 |
92 // The next value to use for the javascript callback id. | 92 // The next value to use for the javascript callback id. |
93 int g_next_javascript_callback_id = 1; | 93 int g_next_javascript_callback_id = 1; |
94 | 94 |
| 95 // Whether to allow injecting javascript into any kind of frame (for Android |
| 96 // WebView). |
| 97 bool g_allow_injecting_javascript = false; |
| 98 |
95 // The (process id, routing id) pair that identifies one RenderFrame. | 99 // The (process id, routing id) pair that identifies one RenderFrame. |
96 typedef std::pair<int32, int32> RenderFrameHostID; | 100 typedef std::pair<int32, int32> RenderFrameHostID; |
97 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> | 101 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
98 RoutingIDFrameMap; | 102 RoutingIDFrameMap; |
99 base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = | 103 base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = |
100 LAZY_INSTANCE_INITIALIZER; | 104 LAZY_INSTANCE_INITIALIZER; |
101 | 105 |
102 // Translate a WebKit text direction into a base::i18n one. | 106 // Translate a WebKit text direction into a base::i18n one. |
103 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( | 107 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( |
104 blink::WebTextDirection dir) { | 108 blink::WebTextDirection dir) { |
(...skipping 15 matching lines...) Expand all Loading... |
120 return rfh_state == STATE_DEFAULT; | 124 return rfh_state == STATE_DEFAULT; |
121 } | 125 } |
122 | 126 |
123 // static | 127 // static |
124 RenderFrameHost* RenderFrameHost::FromID(int render_process_id, | 128 RenderFrameHost* RenderFrameHost::FromID(int render_process_id, |
125 int render_frame_id) { | 129 int render_frame_id) { |
126 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 130 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
127 } | 131 } |
128 | 132 |
129 // static | 133 // static |
| 134 void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() { |
| 135 g_allow_injecting_javascript = true; |
| 136 } |
| 137 |
| 138 // static |
130 RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id, | 139 RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id, |
131 int routing_id) { | 140 int routing_id) { |
132 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
133 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); | 142 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); |
134 RoutingIDFrameMap::iterator it = frames->find( | 143 RoutingIDFrameMap::iterator it = frames->find( |
135 RenderFrameHostID(process_id, routing_id)); | 144 RenderFrameHostID(process_id, routing_id)); |
136 return it == frames->end() ? NULL : it->second; | 145 return it == frames->end() ? NULL : it->second; |
137 } | 146 } |
138 | 147 |
139 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, | 148 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return view->GetNativeView(); | 274 return view->GetNativeView(); |
266 } | 275 } |
267 | 276 |
268 void RenderFrameHostImpl::AddMessageToConsole(ConsoleMessageLevel level, | 277 void RenderFrameHostImpl::AddMessageToConsole(ConsoleMessageLevel level, |
269 const std::string& message) { | 278 const std::string& message) { |
270 Send(new FrameMsg_AddMessageToConsole(routing_id_, level, message)); | 279 Send(new FrameMsg_AddMessageToConsole(routing_id_, level, message)); |
271 } | 280 } |
272 | 281 |
273 void RenderFrameHostImpl::ExecuteJavaScript( | 282 void RenderFrameHostImpl::ExecuteJavaScript( |
274 const base::string16& javascript) { | 283 const base::string16& javascript) { |
| 284 CHECK(CanExecuteJavaScript()); |
275 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, | 285 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, |
276 javascript, | 286 javascript, |
277 0, false)); | 287 0, false)); |
278 } | 288 } |
279 | 289 |
280 void RenderFrameHostImpl::ExecuteJavaScript( | 290 void RenderFrameHostImpl::ExecuteJavaScript( |
281 const base::string16& javascript, | 291 const base::string16& javascript, |
282 const JavaScriptResultCallback& callback) { | 292 const JavaScriptResultCallback& callback) { |
| 293 CHECK(CanExecuteJavaScript()); |
283 int key = g_next_javascript_callback_id++; | 294 int key = g_next_javascript_callback_id++; |
284 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, | 295 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, |
285 javascript, | 296 javascript, |
286 key, true)); | 297 key, true)); |
287 javascript_callbacks_.insert(std::make_pair(key, callback)); | 298 javascript_callbacks_.insert(std::make_pair(key, callback)); |
288 } | 299 } |
289 | 300 |
| 301 void RenderFrameHostImpl::ExecuteJavaScriptForTests( |
| 302 const base::string16& javascript) { |
| 303 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, |
| 304 javascript, |
| 305 0, false, false)); |
| 306 } |
| 307 |
| 308 void RenderFrameHostImpl::ExecuteJavaScriptForTests( |
| 309 const base::string16& javascript, |
| 310 const JavaScriptResultCallback& callback) { |
| 311 int key = g_next_javascript_callback_id++; |
| 312 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, javascript, |
| 313 key, true, false)); |
| 314 javascript_callbacks_.insert(std::make_pair(key, callback)); |
| 315 } |
| 316 |
| 317 |
290 void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests( | 318 void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests( |
291 const base::string16& javascript) { | 319 const base::string16& javascript) { |
292 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, | 320 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, |
293 javascript, | 321 javascript, |
294 0, false, true)); | 322 0, false, true)); |
295 } | 323 } |
296 | 324 |
297 void RenderFrameHostImpl::ExecuteJavaScriptInIsolatedWorld( | 325 void RenderFrameHostImpl::ExecuteJavaScriptInIsolatedWorld( |
298 const base::string16& javascript, | 326 const base::string16& javascript, |
299 const JavaScriptResultCallback& callback, | 327 const JavaScriptResultCallback& callback, |
(...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 | 2153 |
2126 // We may be returning to an existing NavigationEntry that had been granted | 2154 // We may be returning to an existing NavigationEntry that had been granted |
2127 // file access. If this is a different process, we will need to grant the | 2155 // file access. If this is a different process, we will need to grant the |
2128 // access again. The files listed in the page state are validated when they | 2156 // access again. The files listed in the page state are validated when they |
2129 // are received from the renderer to prevent abuse. | 2157 // are received from the renderer to prevent abuse. |
2130 if (request_params.page_state.IsValid()) { | 2158 if (request_params.page_state.IsValid()) { |
2131 render_view_host_->GrantFileAccessFromPageState(request_params.page_state); | 2159 render_view_host_->GrantFileAccessFromPageState(request_params.page_state); |
2132 } | 2160 } |
2133 } | 2161 } |
2134 | 2162 |
| 2163 bool RenderFrameHostImpl::CanExecuteJavaScript() { |
| 2164 return g_allow_injecting_javascript || |
| 2165 frame_tree_node_->current_url().SchemeIs(kChromeDevToolsScheme) || |
| 2166 ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 2167 GetProcess()->GetID()) || |
| 2168 // It's possible to load about:blank in a Web UI renderer. |
| 2169 // See http://crbug.com/42547 |
| 2170 (frame_tree_node_->current_url().spec() == url::kAboutBlankURL) || |
| 2171 // InterstitialPageImpl should be the only case matching this. |
| 2172 (delegate_->GetAsWebContents() == nullptr); |
| 2173 } |
| 2174 |
2135 } // namespace content | 2175 } // namespace content |
OLD | NEW |