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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 bool force_navigation) { | 973 bool force_navigation) { |
971 if (src.empty()) | 974 if (src.empty()) |
972 return; | 975 return; |
973 | 976 |
974 GURL url = ResolveURL(src); | 977 GURL url = ResolveURL(src); |
975 | 978 |
976 // We wait for all the content scripts to load and then navigate the guest | 979 // We wait for all the content scripts to load and then navigate the guest |
977 // if the navigation is embedder-initiated. For browser-initiated navigations, | 980 // if the navigation is embedder-initiated. For browser-initiated navigations, |
978 // content scripts will be ready. | 981 // content scripts will be ready. |
979 if (force_navigation) { | 982 if (force_navigation) { |
980 SignalWhenReady( | 983 SignalWhenReady(base::Bind( |
981 base::Bind(&WebViewGuest::LoadURLWithParams, | 984 &WebViewGuest::LoadURLWithParams, weak_ptr_factory_.GetWeakPtr(), url, |
982 weak_ptr_factory_.GetWeakPtr(), url, content::Referrer(), | 985 content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
983 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, force_navigation)); | 986 GlobalRequestID(), force_navigation)); |
984 return; | 987 return; |
985 } | 988 } |
986 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 989 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
987 force_navigation); | 990 GlobalRequestID(), force_navigation); |
988 } | 991 } |
989 | 992 |
990 bool WebViewGuest::HandleKeyboardShortcuts( | 993 bool WebViewGuest::HandleKeyboardShortcuts( |
991 const content::NativeWebKeyboardEvent& event) { | 994 const content::NativeWebKeyboardEvent& event) { |
992 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. | 995 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. |
993 if (!GuestViewManager::FromBrowserContext(browser_context())-> | 996 if (!GuestViewManager::FromBrowserContext(browser_context())-> |
994 IsOwnedByExtension(this)) { | 997 IsOwnedByExtension(this)) { |
995 return false; | 998 return false; |
996 } | 999 } |
997 | 1000 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 // decides that a fork should happen. At the time of writing this comment, | 1242 // decides that a fork should happen. At the time of writing this comment, |
1240 // the only way a well behaving guest could hit this code path is if it | 1243 // the only way a well behaving guest could hit this code path is if it |
1241 // navigates to a URL that's associated with the default search engine. | 1244 // navigates to a URL that's associated with the default search engine. |
1242 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks | 1245 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks |
1243 // are performed inside LoadURLWithParams such that if the guest attempts | 1246 // are performed inside LoadURLWithParams such that if the guest attempts |
1244 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' | 1247 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' |
1245 // event will fire in the embedder, and the guest will be navigated to | 1248 // event will fire in the embedder, and the guest will be navigated to |
1246 // about:blank. | 1249 // about:blank. |
1247 if (params.disposition == CURRENT_TAB) { | 1250 if (params.disposition == CURRENT_TAB) { |
1248 LoadURLWithParams(params.url, params.referrer, params.transition, | 1251 LoadURLWithParams(params.url, params.referrer, params.transition, |
| 1252 params.transferred_global_request_id, |
1249 true /* force_navigation */); | 1253 true /* force_navigation */); |
1250 return web_contents(); | 1254 return web_contents(); |
1251 } | 1255 } |
1252 | 1256 |
1253 // This code path is taken if Ctrl+Click, middle click or any of the | 1257 // This code path is taken if Ctrl+Click, middle click or any of the |
1254 // keyboard/mouse combinations are used to open a link in a new tab/window. | 1258 // keyboard/mouse combinations are used to open a link in a new tab/window. |
1255 // This code path is also taken on client-side redirects from about:blank. | 1259 // This code path is also taken on client-side redirects from about:blank. |
1256 CreateNewGuestWebViewWindow(params); | 1260 CreateNewGuestWebViewWindow(params); |
1257 return nullptr; | 1261 return nullptr; |
1258 } | 1262 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 void WebViewGuest::ExitFullscreenModeForTab( | 1298 void WebViewGuest::ExitFullscreenModeForTab( |
1295 content::WebContents* web_contents) { | 1299 content::WebContents* web_contents) { |
1296 SetFullscreenState(false); | 1300 SetFullscreenState(false); |
1297 } | 1301 } |
1298 | 1302 |
1299 bool WebViewGuest::IsFullscreenForTabOrPending( | 1303 bool WebViewGuest::IsFullscreenForTabOrPending( |
1300 const content::WebContents* web_contents) const { | 1304 const content::WebContents* web_contents) const { |
1301 return is_guest_fullscreen_; | 1305 return is_guest_fullscreen_; |
1302 } | 1306 } |
1303 | 1307 |
1304 void WebViewGuest::LoadURLWithParams(const GURL& url, | 1308 void WebViewGuest::LoadURLWithParams( |
1305 const content::Referrer& referrer, | 1309 const GURL& url, |
1306 ui::PageTransition transition_type, | 1310 const content::Referrer& referrer, |
1307 bool force_navigation) { | 1311 ui::PageTransition transition_type, |
| 1312 const GlobalRequestID& transferred_global_request_id, |
| 1313 bool force_navigation) { |
1308 // Do not allow navigating a guest to schemes other than known safe schemes. | 1314 // Do not allow navigating a guest to schemes other than known safe schemes. |
1309 // This will block the embedder trying to load unwanted schemes, e.g. | 1315 // This will block the embedder trying to load unwanted schemes, e.g. |
1310 // chrome://. | 1316 // chrome://. |
1311 bool scheme_is_blocked = | 1317 bool scheme_is_blocked = |
1312 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1318 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
1313 url.scheme()) && | 1319 url.scheme()) && |
1314 !url.SchemeIs(url::kAboutScheme)) || | 1320 !url.SchemeIs(url::kAboutScheme)) || |
1315 url.SchemeIs(url::kJavaScriptScheme); | 1321 url.SchemeIs(url::kJavaScriptScheme); |
1316 if (scheme_is_blocked || !url.is_valid()) { | 1322 if (scheme_is_blocked || !url.is_valid()) { |
1317 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, | 1323 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, |
1318 net::ErrorToShortString(net::ERR_ABORTED)); | 1324 net::ErrorToShortString(net::ERR_ABORTED)); |
1319 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); | 1325 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
1320 return; | 1326 return; |
1321 } | 1327 } |
1322 | 1328 |
1323 if (!force_navigation && (src_ == url)) | 1329 if (!force_navigation && (src_ == url)) |
1324 return; | 1330 return; |
1325 | 1331 |
1326 GURL validated_url(url); | 1332 GURL validated_url(url); |
1327 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 1333 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
1328 // As guests do not swap processes on navigation, only navigations to | 1334 // As guests do not swap processes on navigation, only navigations to |
1329 // normal web URLs are supported. No protocol handlers are installed for | 1335 // normal web URLs are supported. No protocol handlers are installed for |
1330 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 1336 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
1331 // can be granted to the guest process. | 1337 // can be granted to the guest process. |
1332 content::NavigationController::LoadURLParams load_url_params(validated_url); | 1338 content::NavigationController::LoadURLParams load_url_params(validated_url); |
1333 load_url_params.referrer = referrer; | 1339 load_url_params.referrer = referrer; |
1334 load_url_params.transition_type = transition_type; | 1340 load_url_params.transition_type = transition_type; |
1335 load_url_params.extra_headers = std::string(); | 1341 load_url_params.extra_headers = std::string(); |
| 1342 load_url_params.transferred_global_request_id = transferred_global_request_id; |
1336 if (is_overriding_user_agent_) { | 1343 if (is_overriding_user_agent_) { |
1337 load_url_params.override_user_agent = | 1344 load_url_params.override_user_agent = |
1338 content::NavigationController::UA_OVERRIDE_TRUE; | 1345 content::NavigationController::UA_OVERRIDE_TRUE; |
1339 } | 1346 } |
1340 GuestViewBase::LoadURLWithParams(load_url_params); | 1347 GuestViewBase::LoadURLWithParams(load_url_params); |
1341 | 1348 |
1342 src_ = validated_url; | 1349 src_ = validated_url; |
1343 } | 1350 } |
1344 | 1351 |
1345 void WebViewGuest::RequestNewWindowPermission( | 1352 void WebViewGuest::RequestNewWindowPermission( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1442 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1436 DispatchEventToView( | 1443 DispatchEventToView( |
1437 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1444 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1438 } | 1445 } |
1439 // Since we changed fullscreen state, sending a Resize message ensures that | 1446 // Since we changed fullscreen state, sending a Resize message ensures that |
1440 // renderer/ sees the change. | 1447 // renderer/ sees the change. |
1441 web_contents()->GetRenderViewHost()->WasResized(); | 1448 web_contents()->GetRenderViewHost()->WasResized(); |
1442 } | 1449 } |
1443 | 1450 |
1444 } // namespace extensions | 1451 } // namespace extensions |
OLD | NEW |