Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 972313002: Make <webview> use out-of-process iframe architecture. (Closed) Base URL: ssh://saopaulo.wat/mnt/dev/shared/src@testoopif2z-better-chrome
Patch Set: address comments from nasko@ Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 bool force_navigation) { 979 bool force_navigation) {
979 if (src.empty()) 980 if (src.empty())
980 return; 981 return;
981 982
982 GURL url = ResolveURL(src); 983 GURL url = ResolveURL(src);
983 984
984 // We wait for all the content scripts to load and then navigate the guest 985 // We wait for all the content scripts to load and then navigate the guest
985 // if the navigation is embedder-initiated. For browser-initiated navigations, 986 // if the navigation is embedder-initiated. For browser-initiated navigations,
986 // content scripts will be ready. 987 // content scripts will be ready.
987 if (force_navigation) { 988 if (force_navigation) {
988 SignalWhenReady( 989 SignalWhenReady(base::Bind(
989 base::Bind(&WebViewGuest::LoadURLWithParams, 990 &WebViewGuest::LoadURLWithParams, weak_ptr_factory_.GetWeakPtr(), url,
990 weak_ptr_factory_.GetWeakPtr(), url, content::Referrer(), 991 content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
991 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, force_navigation)); 992 GlobalRequestID(), force_navigation));
992 return; 993 return;
993 } 994 }
994 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 995 LoadURLWithParams(url, content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
995 force_navigation); 996 GlobalRequestID(), force_navigation);
996 } 997 }
997 998
998 bool WebViewGuest::HandleKeyboardShortcuts( 999 bool WebViewGuest::HandleKeyboardShortcuts(
999 const content::NativeWebKeyboardEvent& event) { 1000 const content::NativeWebKeyboardEvent& event) {
1000 // <webview> outside of Chrome Apps do not handle keyboard shortcuts. 1001 // <webview> outside of Chrome Apps do not handle keyboard shortcuts.
1001 if (!GuestViewManager::FromBrowserContext(browser_context())-> 1002 if (!GuestViewManager::FromBrowserContext(browser_context())->
1002 IsOwnedByExtension(this)) { 1003 IsOwnedByExtension(this)) {
1003 return false; 1004 return false;
1004 } 1005 }
1005 1006
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 // decides that a fork should happen. At the time of writing this comment, 1248 // decides that a fork should happen. At the time of writing this comment,
1248 // the only way a well behaving guest could hit this code path is if it 1249 // the only way a well behaving guest could hit this code path is if it
1249 // navigates to a URL that's associated with the default search engine. 1250 // navigates to a URL that's associated with the default search engine.
1250 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks 1251 // This list of URLs is generated by chrome::GetSearchURLs. Validity checks
1251 // are performed inside LoadURLWithParams such that if the guest attempts 1252 // are performed inside LoadURLWithParams such that if the guest attempts
1252 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort' 1253 // to navigate to a URL that it is not allowed to navigate to, a 'loadabort'
1253 // event will fire in the embedder, and the guest will be navigated to 1254 // event will fire in the embedder, and the guest will be navigated to
1254 // about:blank. 1255 // about:blank.
1255 if (params.disposition == CURRENT_TAB) { 1256 if (params.disposition == CURRENT_TAB) {
1256 LoadURLWithParams(params.url, params.referrer, params.transition, 1257 LoadURLWithParams(params.url, params.referrer, params.transition,
1258 params.transferred_global_request_id,
1257 true /* force_navigation */); 1259 true /* force_navigation */);
1258 return web_contents(); 1260 return web_contents();
1259 } 1261 }
1260 1262
1261 // This code path is taken if Ctrl+Click, middle click or any of the 1263 // This code path is taken if Ctrl+Click, middle click or any of the
1262 // keyboard/mouse combinations are used to open a link in a new tab/window. 1264 // keyboard/mouse combinations are used to open a link in a new tab/window.
1263 // This code path is also taken on client-side redirects from about:blank. 1265 // This code path is also taken on client-side redirects from about:blank.
1264 CreateNewGuestWebViewWindow(params); 1266 CreateNewGuestWebViewWindow(params);
1265 return nullptr; 1267 return nullptr;
1266 } 1268 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 void WebViewGuest::ExitFullscreenModeForTab( 1304 void WebViewGuest::ExitFullscreenModeForTab(
1303 content::WebContents* web_contents) { 1305 content::WebContents* web_contents) {
1304 SetFullscreenState(false); 1306 SetFullscreenState(false);
1305 } 1307 }
1306 1308
1307 bool WebViewGuest::IsFullscreenForTabOrPending( 1309 bool WebViewGuest::IsFullscreenForTabOrPending(
1308 const content::WebContents* web_contents) const { 1310 const content::WebContents* web_contents) const {
1309 return is_guest_fullscreen_; 1311 return is_guest_fullscreen_;
1310 } 1312 }
1311 1313
1312 void WebViewGuest::LoadURLWithParams(const GURL& url, 1314 void WebViewGuest::LoadURLWithParams(
1313 const content::Referrer& referrer, 1315 const GURL& url,
1314 ui::PageTransition transition_type, 1316 const content::Referrer& referrer,
1315 bool force_navigation) { 1317 ui::PageTransition transition_type,
1318 const GlobalRequestID& transferred_global_request_id,
1319 bool force_navigation) {
1316 // Do not allow navigating a guest to schemes other than known safe schemes. 1320 // Do not allow navigating a guest to schemes other than known safe schemes.
1317 // This will block the embedder trying to load unwanted schemes, e.g. 1321 // This will block the embedder trying to load unwanted schemes, e.g.
1318 // chrome://. 1322 // chrome://.
1319 bool scheme_is_blocked = 1323 bool scheme_is_blocked =
1320 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( 1324 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme(
1321 url.scheme()) && 1325 url.scheme()) &&
1322 !url.SchemeIs(url::kAboutScheme)) || 1326 !url.SchemeIs(url::kAboutScheme)) ||
1323 url.SchemeIs(url::kJavaScriptScheme); 1327 url.SchemeIs(url::kJavaScriptScheme);
1324 if (scheme_is_blocked || !url.is_valid()) { 1328 if (scheme_is_blocked || !url.is_valid()) {
1325 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED, 1329 LoadAbort(true /* is_top_level */, url, net::ERR_ABORTED,
1326 net::ErrorToShortString(net::ERR_ABORTED)); 1330 net::ErrorToShortString(net::ERR_ABORTED));
1327 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */); 1331 NavigateGuest(url::kAboutBlankURL, false /* force_navigation */);
1328 return; 1332 return;
1329 } 1333 }
1330 1334
1331 if (!force_navigation && (src_ == url)) 1335 if (!force_navigation && (src_ == url))
1332 return; 1336 return;
1333 1337
1334 GURL validated_url(url); 1338 GURL validated_url(url);
1335 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); 1339 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url);
1336 // As guests do not swap processes on navigation, only navigations to 1340 // As guests do not swap processes on navigation, only navigations to
1337 // normal web URLs are supported. No protocol handlers are installed for 1341 // normal web URLs are supported. No protocol handlers are installed for
1338 // other schemes (e.g., WebUI or extensions), and no permissions or bindings 1342 // other schemes (e.g., WebUI or extensions), and no permissions or bindings
1339 // can be granted to the guest process. 1343 // can be granted to the guest process.
1340 content::NavigationController::LoadURLParams load_url_params(validated_url); 1344 content::NavigationController::LoadURLParams load_url_params(validated_url);
1341 load_url_params.referrer = referrer; 1345 load_url_params.referrer = referrer;
1342 load_url_params.transition_type = transition_type; 1346 load_url_params.transition_type = transition_type;
1343 load_url_params.extra_headers = std::string(); 1347 load_url_params.extra_headers = std::string();
1348 load_url_params.transferred_global_request_id = transferred_global_request_id;
1344 if (is_overriding_user_agent_) { 1349 if (is_overriding_user_agent_) {
1345 load_url_params.override_user_agent = 1350 load_url_params.override_user_agent =
1346 content::NavigationController::UA_OVERRIDE_TRUE; 1351 content::NavigationController::UA_OVERRIDE_TRUE;
1347 } 1352 }
1348 GuestViewBase::LoadURLWithParams(load_url_params); 1353 GuestViewBase::LoadURLWithParams(load_url_params);
1349 1354
1350 src_ = validated_url; 1355 src_ = validated_url;
1351 } 1356 }
1352 1357
1353 void WebViewGuest::RequestNewWindowPermission( 1358 void WebViewGuest::RequestNewWindowPermission(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1448 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1444 DispatchEventToView( 1449 DispatchEventToView(
1445 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); 1450 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass()));
1446 } 1451 }
1447 // Since we changed fullscreen state, sending a Resize message ensures that 1452 // Since we changed fullscreen state, sending a Resize message ensures that
1448 // renderer/ sees the change. 1453 // renderer/ sees the change.
1449 web_contents()->GetRenderViewHost()->WasResized(); 1454 web_contents()->GetRenderViewHost()->WasResized();
1450 } 1455 }
1451 1456
1452 } // namespace extensions 1457 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698