OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" | 11 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" |
11 #include "components/guest_view/browser/guest_view_event.h" | 12 #include "components/guest_view/browser/guest_view_event.h" |
12 #include "components/guest_view/browser/guest_view_manager.h" | 13 #include "components/guest_view/browser/guest_view_manager.h" |
13 #include "components/guest_view/common/guest_view_constants.h" | 14 #include "components/guest_view/common/guest_view_constants.h" |
14 #include "components/web_cache/browser/web_cache_manager.h" | 15 #include "components/web_cache/browser/web_cache_manager.h" |
15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/child_process_security_policy.h" | 18 #include "content/public/browser/child_process_security_policy.h" |
18 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
27 #include "content/public/browser/resource_request_details.h" | 28 #include "content/public/browser/resource_request_details.h" |
28 #include "content/public/browser/site_instance.h" | 29 #include "content/public/browser/site_instance.h" |
29 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
30 #include "content/public/browser/user_metrics.h" | 31 #include "content/public/browser/user_metrics.h" |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_contents_delegate.h" | 33 #include "content/public/browser/web_contents_delegate.h" |
| 34 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/media_stream_request.h" | 35 #include "content/public/common/media_stream_request.h" |
34 #include "content/public/common/page_zoom.h" | 36 #include "content/public/common/page_zoom.h" |
35 #include "content/public/common/result_codes.h" | 37 #include "content/public/common/result_codes.h" |
36 #include "content/public/common/stop_find_action.h" | 38 #include "content/public/common/stop_find_action.h" |
37 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
38 #include "extensions/browser/api/declarative/rules_registry_service.h" | 40 #include "extensions/browser/api/declarative/rules_registry_service.h" |
39 #include "extensions/browser/api/extensions_api_client.h" | 41 #include "extensions/browser/api/extensions_api_client.h" |
40 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" | 42 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" |
41 #include "extensions/browser/api/web_request/web_request_api.h" | 43 #include "extensions/browser/api/web_request/web_request_api.h" |
42 #include "extensions/browser/extension_system.h" | 44 #include "extensions/browser/extension_system.h" |
43 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 45 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
44 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager
.h" | 46 #include "extensions/browser/guest_view/web_view/web_view_content_script_manager
.h" |
45 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 47 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
46 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 48 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
47 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 49 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
48 #include "extensions/common/constants.h" | 50 #include "extensions/common/constants.h" |
49 #include "extensions/common/extension_messages.h" | 51 #include "extensions/common/extension_messages.h" |
50 #include "extensions/strings/grit/extensions_strings.h" | 52 #include "extensions/strings/grit/extensions_strings.h" |
51 #include "ipc/ipc_message_macros.h" | 53 #include "ipc/ipc_message_macros.h" |
52 #include "net/base/escape.h" | 54 #include "net/base/escape.h" |
53 #include "net/base/net_errors.h" | 55 #include "net/base/net_errors.h" |
54 #include "ui/base/models/simple_menu_model.h" | 56 #include "ui/base/models/simple_menu_model.h" |
55 #include "url/url_constants.h" | 57 #include "url/url_constants.h" |
56 | 58 |
57 using base::UserMetricsAction; | 59 using base::UserMetricsAction; |
| 60 using content::GlobalRequestID; |
58 using content::RenderFrameHost; | 61 using content::RenderFrameHost; |
59 using content::ResourceType; | 62 using content::ResourceType; |
60 using content::StoragePartition; | 63 using content::StoragePartition; |
61 using content::WebContents; | 64 using content::WebContents; |
62 using guest_view::GuestViewBase; | 65 using guest_view::GuestViewBase; |
63 using guest_view::GuestViewEvent; | 66 using guest_view::GuestViewEvent; |
64 using guest_view::GuestViewManager; | 67 using guest_view::GuestViewManager; |
65 using ui_zoom::ZoomController; | 68 using ui_zoom::ZoomController; |
66 | 69 |
67 namespace extensions { | 70 namespace extensions { |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 bool force_navigation) { | 977 bool force_navigation) { |
975 if (src.empty()) | 978 if (src.empty()) |
976 return; | 979 return; |
977 | 980 |
978 GURL url = ResolveURL(src); | 981 GURL url = ResolveURL(src); |
979 | 982 |
980 // We wait for all the content scripts to load and then navigate the guest | 983 // We wait for all the content scripts to load and then navigate the guest |
981 // if the navigation is embedder-initiated. For browser-initiated navigations, | 984 // if the navigation is embedder-initiated. For browser-initiated navigations, |
982 // content scripts will be ready. | 985 // content scripts will be ready. |
983 if (force_navigation) { | 986 if (force_navigation) { |
984 SignalWhenReady( | 987 SignalWhenReady(base::Bind( |
985 base::Bind(&WebViewGuest::LoadURLWithParams, | 988 &WebViewGuest::LoadURLWithParams, weak_ptr_factory_.GetWeakPtr(), url, |
986 weak_ptr_factory_.GetWeakPtr(), url, content::Referrer(), | 989 content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
987 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, force_navigation)); | 990 GlobalRequestID(), force_navigation)); |
988 return; | 991 return; |
989 } | 992 } |
990 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 993 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
991 force_navigation); | 994 GlobalRequestID(), force_navigation); |
992 } | 995 } |
993 | 996 |
994 bool WebViewGuest::HandleKeyboardShortcuts( | 997 bool WebViewGuest::HandleKeyboardShortcuts( |
995 const content::NativeWebKeyboardEvent& event) { | 998 const content::NativeWebKeyboardEvent& event) { |
996 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. | 999 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. |
997 if (!GuestViewManager::FromBrowserContext(browser_context())-> | 1000 if (!GuestViewManager::FromBrowserContext(browser_context())-> |
998 IsOwnedByExtension(this)) { | 1001 IsOwnedByExtension(this)) { |
999 return false; | 1002 return false; |
1000 } | 1003 } |
1001 | 1004 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 // decides that a fork should happen. At the time of writing this comment, | 1246 // decides that a fork should happen. At the time of writing this comment, |
1244 // the only way a well behaving guest could hit this code path is if it | 1247 // the only way a well behaving guest could hit this code path is if it |
1245 // navigates to a URL that's associated with the default search engine. | 1248 // navigates to a URL that's associated with the default search engine. |
1246 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks | 1249 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks |
1247 // are performed inside LoadURLWithParams such that if the guest attempts | 1250 // are performed inside LoadURLWithParams such that if the guest attempts |
1248 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' | 1251 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' |
1249 // event will fire in the embedder, and the guest will be navigated to | 1252 // event will fire in the embedder, and the guest will be navigated to |
1250 // about:blank. | 1253 // about:blank. |
1251 if (params.disposition == CURRENT_TAB) { | 1254 if (params.disposition == CURRENT_TAB) { |
1252 LoadURLWithParams(params.url, params.referrer, params.transition, | 1255 LoadURLWithParams(params.url, params.referrer, params.transition, |
| 1256 params.transferred_global_request_id, |
1253 true /* force_navigation */); | 1257 true /* force_navigation */); |
1254 return web_contents(); | 1258 return web_contents(); |
1255 } | 1259 } |
1256 | 1260 |
1257 // This code path is taken if Ctrl+Click, middle click or any of the | 1261 // This code path is taken if Ctrl+Click, middle click or any of the |
1258 // keyboard/mouse combinations are used to open a link in a new tab/window. | 1262 // keyboard/mouse combinations are used to open a link in a new tab/window. |
1259 // This code path is also taken on client-side redirects from about:blank. | 1263 // This code path is also taken on client-side redirects from about:blank. |
1260 CreateNewGuestWebViewWindow(params); | 1264 CreateNewGuestWebViewWindow(params); |
1261 return nullptr; | 1265 return nullptr; |
1262 } | 1266 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 void WebViewGuest::ExitFullscreenModeForTab( | 1302 void WebViewGuest::ExitFullscreenModeForTab( |
1299 content::WebContents* web_contents) { | 1303 content::WebContents* web_contents) { |
1300 SetFullscreenState(false); | 1304 SetFullscreenState(false); |
1301 } | 1305 } |
1302 | 1306 |
1303 bool WebViewGuest::IsFullscreenForTabOrPending( | 1307 bool WebViewGuest::IsFullscreenForTabOrPending( |
1304 const content::WebContents* web_contents) const { | 1308 const content::WebContents* web_contents) const { |
1305 return is_guest_fullscreen_; | 1309 return is_guest_fullscreen_; |
1306 } | 1310 } |
1307 | 1311 |
1308 void WebViewGuest::LoadURLWithParams(const GURL& url, | 1312 void WebViewGuest::LoadURLWithParams( |
1309 const content::Referrer& referrer, | 1313 const GURL& url, |
1310 ui::PageTransition transition_type, | 1314 const content::Referrer& referrer, |
1311 bool force_navigation) { | 1315 ui::PageTransition transition_type, |
| 1316 const GlobalRequestID& transferred_global_request_id, |
| 1317 bool force_navigation) { |
1312 // Do not allow navigating a guest to schemes other than known safe schemes. | 1318 // Do not allow navigating a guest to schemes other than known safe schemes. |
1313 // This will block the embedder trying to load unwanted schemes, e.g. | 1319 // This will block the embedder trying to load unwanted schemes, e.g. |
1314 // chrome://. | 1320 // chrome://. |
1315 bool scheme_is_blocked = | 1321 bool scheme_is_blocked = |
1316 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1322 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
1317 url.scheme()) && | 1323 url.scheme()) && |
1318 !url.SchemeIs(url::kAboutScheme)) || | 1324 !url.SchemeIs(url::kAboutScheme)) || |
1319 url.SchemeIs(url::kJavaScriptScheme); | 1325 url.SchemeIs(url::kJavaScriptScheme); |
1320 if (scheme_is_blocked || !url.is_valid()) { | 1326 if (scheme_is_blocked || !url.is_valid()) { |
1321 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, | 1327 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, |
1322 net::ErrorToShortString(net::ERR_ABORTED)); | 1328 net::ErrorToShortString(net::ERR_ABORTED)); |
1323 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); | 1329 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
1324 return; | 1330 return; |
1325 } | 1331 } |
1326 | 1332 |
1327 if (!force_navigation && (src_ == url)) | 1333 if (!force_navigation && (src_ == url)) |
1328 return; | 1334 return; |
1329 | 1335 |
1330 GURL validated_url(url); | 1336 GURL validated_url(url); |
1331 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 1337 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
1332 // As guests do not swap processes on navigation, only navigations to | 1338 // As guests do not swap processes on navigation, only navigations to |
1333 // normal web URLs are supported. No protocol handlers are installed for | 1339 // normal web URLs are supported. No protocol handlers are installed for |
1334 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 1340 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
1335 // can be granted to the guest process. | 1341 // can be granted to the guest process. |
1336 content::NavigationController::LoadURLParams load_url_params(validated_url); | 1342 content::NavigationController::LoadURLParams load_url_params(validated_url); |
1337 load_url_params.referrer = referrer; | 1343 load_url_params.referrer = referrer; |
1338 load_url_params.transition_type = transition_type; | 1344 load_url_params.transition_type = transition_type; |
1339 load_url_params.extra_headers = std::string(); | 1345 load_url_params.extra_headers = std::string(); |
| 1346 load_url_params.transferred_global_request_id = transferred_global_request_id; |
1340 if (is_overriding_user_agent_) { | 1347 if (is_overriding_user_agent_) { |
1341 load_url_params.override_user_agent = | 1348 load_url_params.override_user_agent = |
1342 content::NavigationController::UA_OVERRIDE_TRUE; | 1349 content::NavigationController::UA_OVERRIDE_TRUE; |
1343 } | 1350 } |
1344 GuestViewBase::LoadURLWithParams(load_url_params); | 1351 GuestViewBase::LoadURLWithParams(load_url_params); |
1345 | 1352 |
1346 src_ = validated_url; | 1353 src_ = validated_url; |
1347 } | 1354 } |
1348 | 1355 |
1349 void WebViewGuest::RequestNewWindowPermission( | 1356 void WebViewGuest::RequestNewWindowPermission( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1446 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1440 DispatchEventToView( | 1447 DispatchEventToView( |
1441 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1448 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1442 } | 1449 } |
1443 // Since we changed fullscreen state, sending a Resize message ensures that | 1450 // Since we changed fullscreen state, sending a Resize message ensures that |
1444 // renderer/ sees the change. | 1451 // renderer/ sees the change. |
1445 web_contents()->GetRenderViewHost()->WasResized(); | 1452 web_contents()->GetRenderViewHost()->WasResized(); |
1446 } | 1453 } |
1447 | 1454 |
1448 } // namespace extensions | 1455 } // namespace extensions |
OLD | NEW |