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

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: Make <webview> work without --site-per-process as well 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/web_cache/browser/web_cache_manager.h" 12 #include "components/web_cache/browser/web_cache_manager.h"
12 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/child_process_security_policy.h" 15 #include "content/public/browser/child_process_security_policy.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 16 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/browser/navigation_entry.h" 17 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/render_widget_host_view.h" 24 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/resource_request_details.h" 25 #include "content/public/browser/resource_request_details.h"
25 #include "content/public/browser/site_instance.h" 26 #include "content/public/browser/site_instance.h"
26 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
27 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_delegate.h" 30 #include "content/public/browser/web_contents_delegate.h"
31 #include "content/public/common/content_switches.h"
30 #include "content/public/common/media_stream_request.h" 32 #include "content/public/common/media_stream_request.h"
31 #include "content/public/common/page_zoom.h" 33 #include "content/public/common/page_zoom.h"
32 #include "content/public/common/result_codes.h" 34 #include "content/public/common/result_codes.h"
33 #include "content/public/common/stop_find_action.h" 35 #include "content/public/common/stop_find_action.h"
34 #include "content/public/common/url_constants.h" 36 #include "content/public/common/url_constants.h"
35 #include "extensions/browser/api/declarative/rules_registry_service.h" 37 #include "extensions/browser/api/declarative/rules_registry_service.h"
36 #include "extensions/browser/api/extensions_api_client.h" 38 #include "extensions/browser/api/extensions_api_client.h"
37 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" 39 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h"
38 #include "extensions/browser/api/web_request/web_request_api.h" 40 #include "extensions/browser/api/web_request/web_request_api.h"
39 #include "extensions/browser/extension_system.h" 41 #include "extensions/browser/extension_system.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 335
334 rules_registry_id_ = GetOrGenerateRulesRegistryID( 336 rules_registry_id_ = GetOrGenerateRulesRegistryID(
335 owner_web_contents()->GetRenderProcessHost()->GetID(), 337 owner_web_contents()->GetRenderProcessHost()->GetID(),
336 view_instance_id()); 338 view_instance_id());
337 339
338 // We must install the mapping from guests to WebViews prior to resuming 340 // We must install the mapping from guests to WebViews prior to resuming
339 // suspended resource loads so that the WebRequest API will catch resource 341 // suspended resource loads so that the WebRequest API will catch resource
340 // requests. 342 // requests.
341 PushWebViewStateToIOThread(); 343 PushWebViewStateToIOThread();
342 344
343 ApplyAttributes(create_params); 345 // TODO(lazyboy): Fix this, site-per-process should also use this code path.
346 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
347 switches::kSitePerProcess)) {
348 ApplyAttributes(create_params);
349 }
344 } 350 }
345 351
346 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { 352 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
347 if (web_view_guest_delegate_) 353 if (web_view_guest_delegate_)
348 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); 354 web_view_guest_delegate_->OnAttachWebViewHelpers(contents);
349 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); 355 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
350 } 356 }
351 357
352 void WebViewGuest::ClearDataInternal(base::Time remove_since, 358 void WebViewGuest::ClearDataInternal(base::Time remove_since,
353 uint32 removal_mask, 359 uint32 removal_mask,
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 838 }
833 839
834 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host, 840 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host,
835 const std::string& name) { 841 const std::string& name) {
836 if (render_frame_host->GetParent()) 842 if (render_frame_host->GetParent())
837 return; 843 return;
838 844
839 if (name_ == name) 845 if (name_ == name)
840 return; 846 return;
841 847
842 ReportFrameNameChange(name); 848 //ReportFrameNameChange(name);
843 } 849 }
844 850
845 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 851 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
846 name_ = name; 852 name_ = name;
847 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 853 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
848 args->SetString(webview::kName, name); 854 args->SetString(webview::kName, name);
849 DispatchEventToView( 855 DispatchEventToView(
850 new GuestViewEvent(webview::kEventFrameNameChanged, args.Pass())); 856 new GuestViewEvent(webview::kEventFrameNameChanged, args.Pass()));
851 } 857 }
852 858
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 1034
1029 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { 1035 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) {
1030 std::string name; 1036 std::string name;
1031 if (params.GetString(webview::kAttributeName, &name)) { 1037 if (params.GetString(webview::kAttributeName, &name)) {
1032 // If the guest window's name is empty, then the WebView tag's name is 1038 // If the guest window's name is empty, then the WebView tag's name is
1033 // assigned. Otherwise, the guest window's name takes precedence over the 1039 // assigned. Otherwise, the guest window's name takes precedence over the
1034 // WebView tag's name. 1040 // WebView tag's name.
1035 if (name_.empty()) 1041 if (name_.empty())
1036 SetName(name); 1042 SetName(name);
1037 } 1043 }
1038 if (attached()) 1044 //if (attached())
1039 ReportFrameNameChange(name_); 1045 // ReportFrameNameChange(name_);
1040 1046
1041 std::string user_agent_override; 1047 std::string user_agent_override;
1042 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); 1048 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override);
1043 SetUserAgentOverride(user_agent_override); 1049 SetUserAgentOverride(user_agent_override);
1044 1050
1045 bool allow_transparency = false; 1051 bool allow_transparency = false;
1046 if (params.GetBoolean(webview::kAttributeAllowTransparency, 1052 if (params.GetBoolean(webview::kAttributeAllowTransparency,
1047 &allow_transparency)) { 1053 &allow_transparency)) {
1048 // We need to set the background opaque flag after navigation to ensure that 1054 // We need to set the background opaque flag after navigation to ensure that
1049 // there is a RenderWidgetHostView available. 1055 // there is a RenderWidgetHostView available.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 // Chrome Apps and WebUI. This is a browser initiated request and so 1207 // Chrome Apps and WebUI. This is a browser initiated request and so
1202 // we pass it along to the embedder's WebContentsDelegate to get the 1208 // we pass it along to the embedder's WebContentsDelegate to get the
1203 // browser to perform the action for the <webview>. 1209 // browser to perform the action for the <webview>.
1204 if (!params.is_renderer_initiated) { 1210 if (!params.is_renderer_initiated) {
1205 if (!owner_web_contents()->GetDelegate()) 1211 if (!owner_web_contents()->GetDelegate())
1206 return nullptr; 1212 return nullptr;
1207 return owner_web_contents()->GetDelegate()->OpenURLFromTab( 1213 return owner_web_contents()->GetDelegate()->OpenURLFromTab(
1208 owner_web_contents(), params); 1214 owner_web_contents(), params);
1209 } 1215 }
1210 1216
1217 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1218 switches::kSitePerProcess)) {
1219 return OpenURLFromTabForSitePerProcess(source, params);
1220 }
1221
1211 // If the guest wishes to navigate away prior to attachment then we save the 1222 // If the guest wishes to navigate away prior to attachment then we save the
1212 // navigation to perform upon attachment. Navigation initializes a lot of 1223 // navigation to perform upon attachment. Navigation initializes a lot of
1213 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. 1224 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest.
1214 // Navigation also resumes resource loading which we don't want to allow 1225 // Navigation also resumes resource loading which we don't want to allow
1215 // until attachment. 1226 // until attachment.
1216 if (!attached()) { 1227 if (!attached()) {
1217 WebViewGuest* opener = GetOpener(); 1228 WebViewGuest* opener = GetOpener();
1218 auto it = opener->pending_new_windows_.find(this); 1229 auto it = opener->pending_new_windows_.find(this);
1219 if (it == opener->pending_new_windows_.end()) 1230 if (it == opener->pending_new_windows_.end())
1220 return nullptr; 1231 return nullptr;
(...skipping 19 matching lines...) Expand all
1240 return web_contents(); 1251 return web_contents();
1241 } 1252 }
1242 1253
1243 // This code path is taken if Ctrl+Click, middle click or any of the 1254 // This code path is taken if Ctrl+Click, middle click or any of the
1244 // keyboard/mouse combinations are used to open a link in a new tab/window. 1255 // keyboard/mouse combinations are used to open a link in a new tab/window.
1245 // This code path is also taken on client-side redirects from about:blank. 1256 // This code path is also taken on client-side redirects from about:blank.
1246 CreateNewGuestWebViewWindow(params); 1257 CreateNewGuestWebViewWindow(params);
1247 return nullptr; 1258 return nullptr;
1248 } 1259 }
1249 1260
1261 content::WebContents* WebViewGuest::OpenURLFromTabForSitePerProcess(
1262 content::WebContents* source, const content::OpenURLParams& params) {
1263 // site-per-process
1264 LOG(WARNING) << "source: " << source << ", web_contents: "<< web_contents();
1265 //CHECK(0);
1266 content::NavigationController::LoadURLParams load_url_params(
1267 params.url);
1268 load_url_params.referrer = params.referrer;
1269 load_url_params.transition_type = params.transition;
1270 load_url_params.extra_headers = std::string();
1271 //load_url_params.frame_tree_node_id = params.frame_tree_node_id;
1272 load_url_params.transferred_global_request_id =
1273 params.transferred_global_request_id;
1274 source->GetController().LoadURLWithParams(load_url_params);
1275 return source;
1276 }
1277
1250 void WebViewGuest::WebContentsCreated(WebContents* source_contents, 1278 void WebViewGuest::WebContentsCreated(WebContents* source_contents,
1251 int opener_render_frame_id, 1279 int opener_render_frame_id,
1252 const base::string16& frame_name, 1280 const base::string16& frame_name,
1253 const GURL& target_url, 1281 const GURL& target_url,
1254 content::WebContents* new_contents) { 1282 content::WebContents* new_contents) {
1255 auto guest = WebViewGuest::FromWebContents(new_contents); 1283 auto guest = WebViewGuest::FromWebContents(new_contents);
1256 CHECK(guest); 1284 CHECK(guest);
1257 guest->SetOpener(this); 1285 guest->SetOpener(this);
1258 std::string guest_name = base::UTF16ToUTF8(frame_name); 1286 std::string guest_name = base::UTF16ToUTF8(frame_name);
1259 guest->name_ = guest_name; 1287 guest->name_ = guest_name;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1453 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1426 DispatchEventToView( 1454 DispatchEventToView(
1427 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass())); 1455 new GuestViewEvent(webview::kEventExitFullscreen, args.Pass()));
1428 } 1456 }
1429 // Since we changed fullscreen state, sending a Resize message ensures that 1457 // Since we changed fullscreen state, sending a Resize message ensures that
1430 // renderer/ sees the change. 1458 // renderer/ sees the change.
1431 web_contents()->GetRenderViewHost()->WasResized(); 1459 web_contents()->GetRenderViewHost()->WasResized();
1432 } 1460 }
1433 1461
1434 } // namespace extensions 1462 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698