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 | |
99 // The (process id, routing id) pair that identifies one RenderFrame. | 95 // The (process id, routing id) pair that identifies one RenderFrame. |
100 typedef std::pair<int32, int32> RenderFrameHostID; | 96 typedef std::pair<int32, int32> RenderFrameHostID; |
101 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> | 97 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
102 RoutingIDFrameMap; | 98 RoutingIDFrameMap; |
103 base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = | 99 base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = |
104 LAZY_INSTANCE_INITIALIZER; | 100 LAZY_INSTANCE_INITIALIZER; |
105 | 101 |
106 // Translate a WebKit text direction into a base::i18n one. | 102 // Translate a WebKit text direction into a base::i18n one. |
107 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( | 103 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( |
108 blink::WebTextDirection dir) { | 104 blink::WebTextDirection dir) { |
(...skipping 15 matching lines...) Expand all Loading... |
124 return rfh_state == STATE_DEFAULT; | 120 return rfh_state == STATE_DEFAULT; |
125 } | 121 } |
126 | 122 |
127 // static | 123 // static |
128 RenderFrameHost* RenderFrameHost::FromID(int render_process_id, | 124 RenderFrameHost* RenderFrameHost::FromID(int render_process_id, |
129 int render_frame_id) { | 125 int render_frame_id) { |
130 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 126 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
131 } | 127 } |
132 | 128 |
133 // static | 129 // static |
134 void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() { | |
135 g_allow_injecting_javascript = true; | |
136 } | |
137 | |
138 // static | |
139 RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id, | 130 RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id, |
140 int routing_id) { | 131 int routing_id) { |
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
142 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); | 133 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); |
143 RoutingIDFrameMap::iterator it = frames->find( | 134 RoutingIDFrameMap::iterator it = frames->find( |
144 RenderFrameHostID(process_id, routing_id)); | 135 RenderFrameHostID(process_id, routing_id)); |
145 return it == frames->end() ? NULL : it->second; | 136 return it == frames->end() ? NULL : it->second; |
146 } | 137 } |
147 | 138 |
148 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, | 139 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return view->GetNativeView(); | 265 return view->GetNativeView(); |
275 } | 266 } |
276 | 267 |
277 void RenderFrameHostImpl::AddMessageToConsole(ConsoleMessageLevel level, | 268 void RenderFrameHostImpl::AddMessageToConsole(ConsoleMessageLevel level, |
278 const std::string& message) { | 269 const std::string& message) { |
279 Send(new FrameMsg_AddMessageToConsole(routing_id_, level, message)); | 270 Send(new FrameMsg_AddMessageToConsole(routing_id_, level, message)); |
280 } | 271 } |
281 | 272 |
282 void RenderFrameHostImpl::ExecuteJavaScript( | 273 void RenderFrameHostImpl::ExecuteJavaScript( |
283 const base::string16& javascript) { | 274 const base::string16& javascript) { |
284 CHECK(CanExecuteJavaScript()); | |
285 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, | 275 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, |
286 javascript, | 276 javascript, |
287 0, false)); | 277 0, false)); |
288 } | 278 } |
289 | 279 |
290 void RenderFrameHostImpl::ExecuteJavaScript( | 280 void RenderFrameHostImpl::ExecuteJavaScript( |
291 const base::string16& javascript, | 281 const base::string16& javascript, |
292 const JavaScriptResultCallback& callback) { | 282 const JavaScriptResultCallback& callback) { |
293 CHECK(CanExecuteJavaScript()); | |
294 int key = g_next_javascript_callback_id++; | 283 int key = g_next_javascript_callback_id++; |
295 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, | 284 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, |
296 javascript, | 285 javascript, |
297 key, true)); | 286 key, true)); |
298 javascript_callbacks_.insert(std::make_pair(key, callback)); | 287 javascript_callbacks_.insert(std::make_pair(key, callback)); |
299 } | 288 } |
300 | 289 |
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 | |
318 void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests( | 290 void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests( |
319 const base::string16& javascript) { | 291 const base::string16& javascript) { |
320 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, | 292 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, |
321 javascript, | 293 javascript, |
322 0, false, true)); | 294 0, false, true)); |
323 } | 295 } |
324 | 296 |
325 void RenderFrameHostImpl::ExecuteJavaScriptInIsolatedWorld( | 297 void RenderFrameHostImpl::ExecuteJavaScriptInIsolatedWorld( |
326 const base::string16& javascript, | 298 const base::string16& javascript, |
327 const JavaScriptResultCallback& callback, | 299 const JavaScriptResultCallback& callback, |
(...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 | 2125 |
2154 // We may be returning to an existing NavigationEntry that had been granted | 2126 // We may be returning to an existing NavigationEntry that had been granted |
2155 // file access. If this is a different process, we will need to grant the | 2127 // file access. If this is a different process, we will need to grant the |
2156 // access again. The files listed in the page state are validated when they | 2128 // access again. The files listed in the page state are validated when they |
2157 // are received from the renderer to prevent abuse. | 2129 // are received from the renderer to prevent abuse. |
2158 if (request_params.page_state.IsValid()) { | 2130 if (request_params.page_state.IsValid()) { |
2159 render_view_host_->GrantFileAccessFromPageState(request_params.page_state); | 2131 render_view_host_->GrantFileAccessFromPageState(request_params.page_state); |
2160 } | 2132 } |
2161 } | 2133 } |
2162 | 2134 |
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 | |
2175 } // namespace content | 2135 } // namespace content |
OLD | NEW |