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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 bool force_navigation) { | 977 bool force_navigation) { |
977 if (src.empty()) | 978 if (src.empty()) |
978 return; | 979 return; |
979 | 980 |
980 GURL url = ResolveURL(src); | 981 GURL url = ResolveURL(src); |
981 | 982 |
982 // 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 |
983 // if the navigation is embedder-initiated. For browser-initiated navigations, | 984 // if the navigation is embedder-initiated. For browser-initiated navigations, |
984 // content scripts will be ready. | 985 // content scripts will be ready. |
985 if (force_navigation) { | 986 if (force_navigation) { |
986 SignalWhenReady( | 987 SignalWhenReady(base::Bind( |
987 base::Bind(&WebViewGuest::LoadURLWithParams, | 988 &WebViewGuest::LoadURLWithParams, weak_ptr_factory_.GetWeakPtr(), url, |
988 weak_ptr_factory_.GetWeakPtr(), url, content::Referrer(), | 989 content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
989 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, force_navigation)); | 990 GlobalRequestID(), force_navigation)); |
990 return; | 991 return; |
991 } | 992 } |
992 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 993 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
993 force_navigation); | 994 GlobalRequestID(), force_navigation); |
994 } | 995 } |
995 | 996 |
996 bool WebViewGuest::HandleKeyboardShortcuts( | 997 bool WebViewGuest::HandleKeyboardShortcuts( |
997 const content::NativeWebKeyboardEvent& event) { | 998 const content::NativeWebKeyboardEvent& event) { |
998 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. | 999 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. |
999 if (!GuestViewManager::FromBrowserContext(browser_context())-> | 1000 if (!GuestViewManager::FromBrowserContext(browser_context())-> |
1000 IsOwnedByExtension(this)) { | 1001 IsOwnedByExtension(this)) { |
1001 return false; | 1002 return false; |
1002 } | 1003 } |
1003 | 1004 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 // 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, |
1246 // 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 |
1247 // 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. |
1248 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks | 1249 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks |
1249 // are performed inside LoadURLWithParams such that if the guest attempts | 1250 // are performed inside LoadURLWithParams such that if the guest attempts |
1250 // 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' |
1251 // 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 |
1252 // about:blank. | 1253 // about:blank. |
1253 if (params.disposition == CURRENT_TAB) { | 1254 if (params.disposition == CURRENT_TAB) { |
1254 LoadURLWithParams(params.url, params.referrer, params.transition, | 1255 LoadURLWithParams(params.url, params.referrer, params.transition, |
| 1256 params.transferred_global_request_id, |
1255 true /* force_navigation */); | 1257 true /* force_navigation */); |
1256 return web_contents(); | 1258 return web_contents(); |
1257 } | 1259 } |
1258 | 1260 |
1259 // 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 |
1260 // 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. |
1261 // 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. |
1262 CreateNewGuestWebViewWindow(params); | 1264 CreateNewGuestWebViewWindow(params); |
1263 return nullptr; | 1265 return nullptr; |
1264 } | 1266 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 void WebViewGuest::ExitFullscreenModeForTab( | 1302 void WebViewGuest::ExitFullscreenModeForTab( |
1301 content::WebContents* web_contents) { | 1303 content::WebContents* web_contents) { |
1302 SetFullscreenState(false); | 1304 SetFullscreenState(false); |
1303 } | 1305 } |
1304 | 1306 |
1305 bool WebViewGuest::IsFullscreenForTabOrPending( | 1307 bool WebViewGuest::IsFullscreenForTabOrPending( |
1306 const content::WebContents* web_contents) const { | 1308 const content::WebContents* web_contents) const { |
1307 return is_guest_fullscreen_; | 1309 return is_guest_fullscreen_; |
1308 } | 1310 } |
1309 | 1311 |
1310 void WebViewGuest::LoadURLWithParams(const GURL& url, | 1312 void WebViewGuest::LoadURLWithParams( |
1311 const content::Referrer& referrer, | 1313 const GURL& url, |
1312 ui::PageTransition transition_type, | 1314 const content::Referrer& referrer, |
1313 bool force_navigation) { | 1315 ui::PageTransition transition_type, |
| 1316 const GlobalRequestID& transferred_global_request_id, |
| 1317 bool force_navigation) { |
1314 // 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. |
1315 // 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. |
1316 // chrome://. | 1320 // chrome://. |
1317 bool scheme_is_blocked = | 1321 bool scheme_is_blocked = |
1318 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 1322 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
1319 url.scheme()) && | 1323 url.scheme()) && |
1320 !url.SchemeIs(url::kAboutScheme)) || | 1324 !url.SchemeIs(url::kAboutScheme)) || |
1321 url.SchemeIs(url::kJavaScriptScheme); | 1325 url.SchemeIs(url::kJavaScriptScheme); |
1322 if (scheme_is_blocked || !url.is_valid()) { | 1326 if (scheme_is_blocked || !url.is_valid()) { |
1323 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, | 1327 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, |
1324 net::ErrorToShortString(net::ERR_ABORTED)); | 1328 net::ErrorToShortString(net::ERR_ABORTED)); |
1325 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); | 1329 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); |
1326 return; | 1330 return; |
1327 } | 1331 } |
1328 | 1332 |
1329 if (!force_navigation && (src_ == url)) | 1333 if (!force_navigation && (src_ == url)) |
1330 return; | 1334 return; |
1331 | 1335 |
1332 GURL validated_url(url); | 1336 GURL validated_url(url); |
1333 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 1337 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
1334 // As guests do not swap processes on navigation, only navigations to | 1338 // As guests do not swap processes on navigation, only navigations to |
1335 // normal web URLs are supported. No protocol handlers are installed for | 1339 // normal web URLs are supported. No protocol handlers are installed for |
1336 // 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 |
1337 // can be granted to the guest process. | 1341 // can be granted to the guest process. |
1338 content::NavigationController::LoadURLParams load_url_params(validated_url); | 1342 content::NavigationController::LoadURLParams load_url_params(validated_url); |
1339 load_url_params.referrer = referrer; | 1343 load_url_params.referrer = referrer; |
1340 load_url_params.transition_type = transition_type; | 1344 load_url_params.transition_type = transition_type; |
1341 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; |
1342 if (is_overriding_user_agent_) { | 1347 if (is_overriding_user_agent_) { |
1343 load_url_params.override_user_agent = | 1348 load_url_params.override_user_agent = |
1344 content::NavigationController::UA_OVERRIDE_TRUE; | 1349 content::NavigationController::UA_OVERRIDE_TRUE; |
1345 } | 1350 } |
1346 GuestViewBase::LoadURLWithParams(load_url_params); | 1351 GuestViewBase::LoadURLWithParams(load_url_params); |
1347 | 1352 |
1348 src_ = validated_url; | 1353 src_ = validated_url; |
1349 } | 1354 } |
1350 | 1355 |
1351 void WebViewGuest::RequestNewWindowPermission( | 1356 void WebViewGuest::RequestNewWindowPermission( |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1446 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1442 DispatchEventToView( | 1447 DispatchEventToView( |
1443 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); | 1448 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); |
1444 } | 1449 } |
1445 // Since we changed fullscreen state, sending a Resize message ensures that | 1450 // Since we changed fullscreen state, sending a Resize message ensures that |
1446 // renderer/ sees the change. | 1451 // renderer/ sees the change. |
1447 web_contents()->GetRenderViewHost()->WasResized(); | 1452 web_contents()->GetRenderViewHost()->WasResized(); |
1448 } | 1453 } |
1449 | 1454 |
1450 } // namespace extensions | 1455 } // namespace extensions |
OLD | NEW |