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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" | 10 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "extensions/common/constants.h" | 48 #include "extensions/common/constants.h" |
49 #include "extensions/common/extension_messages.h" | 49 #include "extensions/common/extension_messages.h" |
50 #include "extensions/strings/grit/extensions_strings.h" | 50 #include "extensions/strings/grit/extensions_strings.h" |
51 #include "ipc/ipc_message_macros.h" | 51 #include "ipc/ipc_message_macros.h" |
52 #include "net/base/escape.h" | 52 #include "net/base/escape.h" |
53 #include "net/base/net_errors.h" | 53 #include "net/base/net_errors.h" |
54 #include "ui/base/models/simple_menu_model.h" | 54 #include "ui/base/models/simple_menu_model.h" |
55 #include "url/url_constants.h" | 55 #include "url/url_constants.h" |
56 | 56 |
57 using base::UserMetricsAction; | 57 using base::UserMetricsAction; |
| 58 using content::GlobalRequestID; |
58 using content::RenderFrameHost; | 59 using content::RenderFrameHost; |
59 using content::ResourceType; | 60 using content::ResourceType; |
60 using content::StoragePartition; | 61 using content::StoragePartition; |
61 using content::WebContents; | 62 using content::WebContents; |
62 using guest_view::GuestViewBase; | 63 using guest_view::GuestViewBase; |
63 using guest_view::GuestViewEvent; | 64 using guest_view::GuestViewEvent; |
64 using guest_view::GuestViewManager; | 65 using guest_view::GuestViewManager; |
65 using ui_zoom::ZoomController; | 66 using ui_zoom::ZoomController; |
66 | 67 |
67 namespace extensions { | 68 namespace extensions { |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 bool force_navigation) { | 992 bool force_navigation) { |
992 if (src.empty()) | 993 if (src.empty()) |
993 return; | 994 return; |
994 | 995 |
995 GURL url = ResolveURL(src); | 996 GURL url = ResolveURL(src); |
996 | 997 |
997 // We wait for all the content scripts to load and then navigate the guest | 998 // We wait for all the content scripts to load and then navigate the guest |
998 // if the navigation is embedder-initiated. For browser-initiated navigations, | 999 // if the navigation is embedder-initiated. For browser-initiated navigations, |
999 // content scripts will be ready. | 1000 // content scripts will be ready. |
1000 if (force_navigation) { | 1001 if (force_navigation) { |
1001 SignalWhenReady( | 1002 SignalWhenReady(base::Bind( |
1002 base::Bind(&WebViewGuest::LoadURLWithParams, | 1003 &WebViewGuest::LoadURLWithParams, weak_ptr_factory_.GetWeakPtr(), url, |
1003 weak_ptr_factory_.GetWeakPtr(), url, content::Referrer(), | 1004 content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1004 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, force_navigation)); | 1005 GlobalRequestID(), force_navigation)); |
1005 return; | 1006 return; |
1006 } | 1007 } |
1007 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1008 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1008 force_navigation); | 1009 GlobalRequestID(), force_navigation); |
1009 } | 1010 } |
1010 | 1011 |
1011 bool WebViewGuest::HandleKeyboardShortcuts( | 1012 bool WebViewGuest::HandleKeyboardShortcuts( |
1012 const content::NativeWebKeyboardEvent& event) { | 1013 const content::NativeWebKeyboardEvent& event) { |
1013 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. | 1014 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. |
1014 if (!GuestViewManager::FromBrowserContext(browser_context())-> | 1015 if (!GuestViewManager::FromBrowserContext(browser_context())-> |
1015 IsOwnedByExtension(this)) { | 1016 IsOwnedByExtension(this)) { |
1016 return false; | 1017 return false; |
1017 } | 1018 } |
1018 | 1019 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 // decides that a fork should happen. At the time of writing this comment, | 1261 // decides that a fork should happen. At the time of writing this comment, |
1261 // the only way a well behaving guest could hit this code path is if it | 1262 // the only way a well behaving guest could hit this code path is if it |
1262 // navigates to a URL that's associated with the default search engine. | 1263 // navigates to a URL that's associated with the default search engine. |
1263 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks | 1264 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks |
1264 // are performed inside LoadURLWithParams such that if the guest attempts | 1265 // are performed inside LoadURLWithParams such that if the guest attempts |
1265 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' | 1266 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' |
1266 // event will fire in the embedder, and the guest will be navigated to | 1267 // event will fire in the embedder, and the guest will be navigated to |
1267 // about:blank. | 1268 // about:blank. |
1268 if (params.disposition == CURRENT_TAB) { | 1269 if (params.disposition == CURRENT_TAB) { |
1269 LoadURLWithParams(params.url, params.referrer, params.transition, | 1270 LoadURLWithParams(params.url, params.referrer, params.transition, |
| 1271 params.transferred_global_request_id, |
1270 true /* force_navigation */); | 1272 true /* force_navigation */); |
1271 return web_contents(); | 1273 return web_contents(); |
1272 } | 1274 } |
1273 | 1275 |
1274 // This code path is taken if Ctrl+Click, middle click or any of the | 1276 // This code path is taken if Ctrl+Click, middle click or any of the |
1275 // keyboard/mouse combinations are used to open a link in a new tab/window. | 1277 // keyboard/mouse combinations are used to open a link in a new tab/window. |
1276 // This code path is also taken on client-side redirects from about:blank. | 1278 // This code path is also taken on client-side redirects from about:blank. |
1277 CreateNewGuestWebViewWindow(params); | 1279 CreateNewGuestWebViewWindow(params); |
1278 return nullptr; | 1280 return nullptr; |
1279 } | 1281 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 void WebViewGuest::ExitFullscreenModeForTab( | 1317 void WebViewGuest::ExitFullscreenModeForTab( |
1316 content::WebContents* web_contents) { | 1318 content::WebContents* web_contents) { |
1317 SetFullscreenState(false); | 1319 SetFullscreenState(false); |
1318 } | 1320 } |
1319 | 1321 |
1320 bool WebViewGuest::IsFullscreenForTabOrPending( | 1322 bool WebViewGuest::IsFullscreenForTabOrPending( |
1321 const content::WebContents* web_contents) const { | 1323 const content::WebContents* web_contents) const { |
1322 return is_guest_fullscreen_; | 1324 return is_guest_fullscreen_; |
1323 } | 1325 } |
1324 | 1326 |
1325 void WebViewGuest::LoadURLWithParams(const GURL& url, | 1327 void WebViewGuest::LoadURLWithParams( |
1326 const content::Referrer& referrer, | 1328 const GURL& url, |
1327 ui::PageTransition transition_type, | 1329 const content::Referrer& referrer, |
1328 bool force_navigation) { | 1330 ui::PageTransition transition_type, |
| 1331 const GlobalRequestID& transferred_global_request_id, |
| 1332 bool force_navigation) { |
1329 // Do not allow navigating a guest to schemes other than known safe schemes. | 1333 // Do not allow navigating a guest to schemes other than known safe schemes. |
1330 // This will block the embedder trying to load unwanted schemes, e.g. | 1334 // This will block the embedder trying to load unwanted schemes, e.g. |
1331 // chrome://. | 1335 // chrome://. |
1332 bool scheme_is_blocked = | 1336 bool scheme_is_blocked = |
1333 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1337 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
1334 url.scheme()) && | 1338 url.scheme()) && |
1335 !url.SchemeIs(url::kAboutScheme)) || | 1339 !url.SchemeIs(url::kAboutScheme)) || |
1336 url.SchemeIs(url::kJavaScriptScheme); | 1340 url.SchemeIs(url::kJavaScriptScheme); |
1337 if (scheme_is_blocked || !url.is_valid()) { | 1341 if (scheme_is_blocked || !url.is_valid()) { |
1338 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, | 1342 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, |
1339 net::ErrorToShortString(net::ERR_ABORTED)); | 1343 net::ErrorToShortString(net::ERR_ABORTED)); |
1340 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); | 1344 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
1341 return; | 1345 return; |
1342 } | 1346 } |
1343 | 1347 |
1344 if (!force_navigation && (src_ == url)) | 1348 if (!force_navigation && (src_ == url)) |
1345 return; | 1349 return; |
1346 | 1350 |
1347 GURL validated_url(url); | 1351 GURL validated_url(url); |
1348 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 1352 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
1349 // As guests do not swap processes on navigation, only navigations to | 1353 // As guests do not swap processes on navigation, only navigations to |
1350 // normal web URLs are supported. No protocol handlers are installed for | 1354 // normal web URLs are supported. No protocol handlers are installed for |
1351 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 1355 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
1352 // can be granted to the guest process. | 1356 // can be granted to the guest process. |
1353 content::NavigationController::LoadURLParams load_url_params(validated_url); | 1357 content::NavigationController::LoadURLParams load_url_params(validated_url); |
1354 load_url_params.referrer = referrer; | 1358 load_url_params.referrer = referrer; |
1355 load_url_params.transition_type = transition_type; | 1359 load_url_params.transition_type = transition_type; |
1356 load_url_params.extra_headers = std::string(); | 1360 load_url_params.extra_headers = std::string(); |
| 1361 load_url_params.transferred_global_request_id = transferred_global_request_id; |
1357 if (is_overriding_user_agent_) { | 1362 if (is_overriding_user_agent_) { |
1358 load_url_params.override_user_agent = | 1363 load_url_params.override_user_agent = |
1359 content::NavigationController::UA_OVERRIDE_TRUE; | 1364 content::NavigationController::UA_OVERRIDE_TRUE; |
1360 } | 1365 } |
1361 GuestViewBase::LoadURLWithParams(load_url_params); | 1366 GuestViewBase::LoadURLWithParams(load_url_params); |
1362 | 1367 |
1363 src_ = validated_url; | 1368 src_ = validated_url; |
1364 } | 1369 } |
1365 | 1370 |
1366 void WebViewGuest::RequestNewWindowPermission( | 1371 void WebViewGuest::RequestNewWindowPermission( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1461 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1457 DispatchEventToView( | 1462 DispatchEventToView( |
1458 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1463 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1459 } | 1464 } |
1460 // Since we changed fullscreen state, sending a Resize message ensures that | 1465 // Since we changed fullscreen state, sending a Resize message ensures that |
1461 // renderer/ sees the change. | 1466 // renderer/ sees the change. |
1462 web_contents()->GetRenderViewHost()->WasResized(); | 1467 web_contents()->GetRenderViewHost()->WasResized(); |
1463 } | 1468 } |
1464 | 1469 |
1465 } // namespace extensions | 1470 } // namespace extensions |
OLD | NEW |