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

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: add basic postMessage test Created 5 years, 7 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/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"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 336
335 rules_registry_id_ = GetOrGenerateRulesRegistryID( 337 rules_registry_id_ = GetOrGenerateRulesRegistryID(
336 owner_web_contents()->GetRenderProcessHost()->GetID(), 338 owner_web_contents()->GetRenderProcessHost()->GetID(),
337 view_instance_id()); 339 view_instance_id());
338 340
339 // We must install the mapping from guests to WebViews prior to resuming 341 // We must install the mapping from guests to WebViews prior to resuming
340 // suspended resource loads so that the WebRequest API will catch resource 342 // suspended resource loads so that the WebRequest API will catch resource
341 // requests. 343 // requests.
342 PushWebViewStateToIOThread(); 344 PushWebViewStateToIOThread();
343 345
344 ApplyAttributes(create_params); 346 // TODO(lazyboy): Fix this, site-per-process should also use this code path.
347 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
348 switches::kSitePerProcess)) {
349 ApplyAttributes(create_params);
350 }
345 } 351 }
346 352
347 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { 353 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
348 if (web_view_guest_delegate_) 354 if (web_view_guest_delegate_)
349 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); 355 web_view_guest_delegate_->OnAttachWebViewHelpers(contents);
350 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); 356 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
351 } 357 }
352 358
353 void WebViewGuest::ClearDataInternal(base::Time remove_since, 359 void WebViewGuest::ClearDataInternal(base::Time remove_since,
354 uint32 removal_mask, 360 uint32 removal_mask,
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 } 835 }
830 836
831 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host, 837 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host,
832 const std::string& name) { 838 const std::string& name) {
833 if (render_frame_host->GetParent()) 839 if (render_frame_host->GetParent())
834 return; 840 return;
835 841
836 if (name_ == name) 842 if (name_ == name)
837 return; 843 return;
838 844
839 ReportFrameNameChange(name); 845 // ReportFrameNameChange(name);
840 } 846 }
841 847
842 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 848 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
843 name_ = name; 849 name_ = name;
844 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 850 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
845 args->SetString(webview::kName, name); 851 args->SetString(webview::kName, name);
846 DispatchEventToView( 852 DispatchEventToView(
847 new GuestViewEvent(webview::kEventFrameNameChanged, args.Pass())); 853 new GuestViewEvent(webview::kEventFrameNameChanged, args.Pass()));
848 } 854 }
849 855
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1045
1040 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { 1046 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) {
1041 std::string name; 1047 std::string name;
1042 if (params.GetString(webview::kAttributeName, &name)) { 1048 if (params.GetString(webview::kAttributeName, &name)) {
1043 // If the guest window's name is empty, then the WebView tag's name is 1049 // If the guest window's name is empty, then the WebView tag's name is
1044 // assigned. Otherwise, the guest window's name takes precedence over the 1050 // assigned. Otherwise, the guest window's name takes precedence over the
1045 // WebView tag's name. 1051 // WebView tag's name.
1046 if (name_.empty()) 1052 if (name_.empty())
1047 SetName(name); 1053 SetName(name);
1048 } 1054 }
1049 if (attached()) 1055 // if (attached())
1050 ReportFrameNameChange(name_); 1056 // ReportFrameNameChange(name_);
1051 1057
1052 std::string user_agent_override; 1058 std::string user_agent_override;
1053 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); 1059 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override);
1054 SetUserAgentOverride(user_agent_override); 1060 SetUserAgentOverride(user_agent_override);
1055 1061
1056 bool allow_transparency = false; 1062 bool allow_transparency = false;
1057 if (params.GetBoolean(webview::kAttributeAllowTransparency, 1063 if (params.GetBoolean(webview::kAttributeAllowTransparency,
1058 &allow_transparency)) { 1064 &allow_transparency)) {
1059 // We need to set the background opaque flag after navigation to ensure that 1065 // We need to set the background opaque flag after navigation to ensure that
1060 // there is a RenderWidgetHostView available. 1066 // there is a RenderWidgetHostView available.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 // Chrome Apps and WebUI. This is a browser initiated request and so 1221 // Chrome Apps and WebUI. This is a browser initiated request and so
1216 // we pass it along to the embedder's WebContentsDelegate to get the 1222 // we pass it along to the embedder's WebContentsDelegate to get the
1217 // browser to perform the action for the <webview>. 1223 // browser to perform the action for the <webview>.
1218 if (!params.is_renderer_initiated) { 1224 if (!params.is_renderer_initiated) {
1219 if (!owner_web_contents()->GetDelegate()) 1225 if (!owner_web_contents()->GetDelegate())
1220 return nullptr; 1226 return nullptr;
1221 return owner_web_contents()->GetDelegate()->OpenURLFromTab( 1227 return owner_web_contents()->GetDelegate()->OpenURLFromTab(
1222 owner_web_contents(), params); 1228 owner_web_contents(), params);
1223 } 1229 }
1224 1230
1231 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1232 switches::kSitePerProcess)) {
1233 return OpenURLFromTabForSitePerProcess(source, params);
1234 }
1235
1225 // If the guest wishes to navigate away prior to attachment then we save the 1236 // If the guest wishes to navigate away prior to attachment then we save the
1226 // navigation to perform upon attachment. Navigation initializes a lot of 1237 // navigation to perform upon attachment. Navigation initializes a lot of
1227 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. 1238 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest.
1228 // Navigation also resumes resource loading which we don't want to allow 1239 // Navigation also resumes resource loading which we don't want to allow
1229 // until attachment. 1240 // until attachment.
1230 if (!attached()) { 1241 if (!attached()) {
1231 WebViewGuest* opener = GetOpener(); 1242 WebViewGuest* opener = GetOpener();
1232 auto it = opener->pending_new_windows_.find(this); 1243 auto it = opener->pending_new_windows_.find(this);
1233 if (it == opener->pending_new_windows_.end()) 1244 if (it == opener->pending_new_windows_.end())
1234 return nullptr; 1245 return nullptr;
(...skipping 19 matching lines...) Expand all
1254 return web_contents(); 1265 return web_contents();
1255 } 1266 }
1256 1267
1257 // This code path is taken if Ctrl+Click, middle click or any of the 1268 // 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. 1269 // 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. 1270 // This code path is also taken on client-side redirects from about:blank.
1260 CreateNewGuestWebViewWindow(params); 1271 CreateNewGuestWebViewWindow(params);
1261 return nullptr; 1272 return nullptr;
1262 } 1273 }
1263 1274
1275 content::WebContents* WebViewGuest::OpenURLFromTabForSitePerProcess(
1276 content::WebContents* source,
1277 const content::OpenURLParams& params) {
1278 // site-per-process
1279 LOG(WARNING) << "source: " << source << ", web_contents: " << web_contents();
1280 // CHECK(0);
1281 content::NavigationController::LoadURLParams load_url_params(params.url);
1282 load_url_params.referrer = params.referrer;
1283 load_url_params.transition_type = params.transition;
1284 load_url_params.extra_headers = std::string();
1285 // load_url_params.frame_tree_node_id = params.frame_tree_node_id;
1286 load_url_params.transferred_global_request_id =
1287 params.transferred_global_request_id;
1288 source->GetController().LoadURLWithParams(load_url_params);
1289 return source;
1290 }
1291
1264 void WebViewGuest::WebContentsCreated(WebContents* source_contents, 1292 void WebViewGuest::WebContentsCreated(WebContents* source_contents,
1265 int opener_render_frame_id, 1293 int opener_render_frame_id,
1266 const base::string16& frame_name, 1294 const base::string16& frame_name,
1267 const GURL& target_url, 1295 const GURL& target_url,
1268 content::WebContents* new_contents) { 1296 content::WebContents* new_contents) {
1269 auto guest = WebViewGuest::FromWebContents(new_contents); 1297 auto guest = WebViewGuest::FromWebContents(new_contents);
1270 CHECK(guest); 1298 CHECK(guest);
1271 guest->SetOpener(this); 1299 guest->SetOpener(this);
1272 std::string guest_name = base::UTF16ToUTF8(frame_name); 1300 std::string guest_name = base::UTF16ToUTF8(frame_name);
1273 guest->name_ = guest_name; 1301 guest->name_ = guest_name;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1467 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1440 DispatchEventToView( 1468 DispatchEventToView(
1441 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); 1469 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass()));
1442 } 1470 }
1443 // Since we changed fullscreen state, sending a Resize message ensures that 1471 // Since we changed fullscreen state, sending a Resize message ensures that
1444 // renderer/ sees the change. 1472 // renderer/ sees the change.
1445 web_contents()->GetRenderViewHost()->WasResized(); 1473 web_contents()->GetRenderViewHost()->WasResized();
1446 } 1474 }
1447 1475
1448 } // namespace extensions 1476 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698