Chromium Code Reviews| 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 "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 content::Source<WebContents>(web_contents())); | 287 content::Source<WebContents>(web_contents())); |
| 288 | 288 |
| 289 if (web_view_guest_delegate_) | 289 if (web_view_guest_delegate_) |
| 290 web_view_guest_delegate_->OnDidInitialize(); | 290 web_view_guest_delegate_->OnDidInitialize(); |
| 291 AttachWebViewHelpers(web_contents()); | 291 AttachWebViewHelpers(web_contents()); |
| 292 | 292 |
| 293 rules_registry_id_ = GetOrGenerateRulesRegistryID( | 293 rules_registry_id_ = GetOrGenerateRulesRegistryID( |
| 294 owner_web_contents()->GetRenderProcessHost()->GetID(), | 294 owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 295 view_instance_id()); | 295 view_instance_id()); |
| 296 | 296 |
| 297 // We must install the mapping from guests to WebViews prior to resuming | 297 // NOTE: Calling this prior to attachment breaks OOPIF <webview>. |
| 298 // suspended resource loads so that the WebRequest API will catch resource | 298 //// We must install the mapping from guests to WebViews prior to resuming |
| 299 // requests. | 299 //// suspended resource loads so that the WebRequest API will catch resource |
| 300 PushWebViewStateToIOThread(); | 300 //// requests. |
| 301 //PushWebViewStateToIOThread(); | |
|
Fady Samuel
2015/03/04 20:44:47
This makes me sad.
lazyboy
2015/04/01 21:47:58
These changes here are temporary, I'll fix these o
| |
| 301 | 302 |
| 302 ApplyAttributes(create_params); | 303 //ApplyAttributes(create_params); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { | 306 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { |
| 306 if (web_view_guest_delegate_) | 307 if (web_view_guest_delegate_) |
| 307 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); | 308 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); |
| 308 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 309 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
| 309 } | 310 } |
| 310 | 311 |
| 311 void WebViewGuest::DidStopLoading() { | 312 void WebViewGuest::DidStopLoading() { |
| 312 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 313 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 } | 470 } |
| 470 | 471 |
| 471 void WebViewGuest::OnFrameNameChanged(bool is_top_level, | 472 void WebViewGuest::OnFrameNameChanged(bool is_top_level, |
| 472 const std::string& name) { | 473 const std::string& name) { |
| 473 if (!is_top_level) | 474 if (!is_top_level) |
| 474 return; | 475 return; |
| 475 | 476 |
| 476 if (name_ == name) | 477 if (name_ == name) |
| 477 return; | 478 return; |
| 478 | 479 |
| 479 ReportFrameNameChange(name); | 480 //ReportFrameNameChange(name); |
|
Fady Samuel
2015/03/04 20:44:47
This makes me sad.
| |
| 480 } | 481 } |
| 481 | 482 |
| 482 void WebViewGuest::CreateNewGuestWebViewWindow( | 483 void WebViewGuest::CreateNewGuestWebViewWindow( |
| 483 const content::OpenURLParams& params) { | 484 const content::OpenURLParams& params) { |
| 484 GuestViewManager* guest_manager = | 485 GuestViewManager* guest_manager = |
| 485 GuestViewManager::FromBrowserContext(browser_context()); | 486 GuestViewManager::FromBrowserContext(browser_context()); |
| 486 // Set the attach params to use the same partition as the opener. | 487 // Set the attach params to use the same partition as the opener. |
| 487 // We pull the partition information from the site's URL, which is of the | 488 // We pull the partition information from the site's URL, which is of the |
| 488 // form guest://site/{persist}?{partition_name}. | 489 // form guest://site/{persist}?{partition_name}. |
| 489 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); | 490 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 } | 854 } |
| 854 | 855 |
| 855 void WebViewGuest::WillAttachToEmbedder() { | 856 void WebViewGuest::WillAttachToEmbedder() { |
| 856 rules_registry_id_ = GetOrGenerateRulesRegistryID( | 857 rules_registry_id_ = GetOrGenerateRulesRegistryID( |
| 857 owner_web_contents()->GetRenderProcessHost()->GetID(), | 858 owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 858 view_instance_id()); | 859 view_instance_id()); |
| 859 | 860 |
| 860 // We must install the mapping from guests to WebViews prior to resuming | 861 // We must install the mapping from guests to WebViews prior to resuming |
| 861 // suspended resource loads so that the WebRequest API will catch resource | 862 // suspended resource loads so that the WebRequest API will catch resource |
| 862 // requests. | 863 // requests. |
| 863 PushWebViewStateToIOThread(); | 864 //PushWebViewStateToIOThread(); |
|
Fady Samuel
2015/03/04 20:44:47
This makes me sad.
| |
| 864 } | 865 } |
| 865 | 866 |
| 866 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( | 867 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( |
| 867 WebContents* source) { | 868 WebContents* source) { |
| 868 return &javascript_dialog_helper_; | 869 return &javascript_dialog_helper_; |
| 869 } | 870 } |
| 870 | 871 |
| 871 void WebViewGuest::NavigateGuest(const std::string& src, | 872 void WebViewGuest::NavigateGuest(const std::string& src, |
| 872 bool force_navigation) { | 873 bool force_navigation) { |
| 873 if (src.empty()) | 874 if (src.empty()) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 891 } | 892 } |
| 892 if (!force_navigation && (src_ == url)) | 893 if (!force_navigation && (src_ == url)) |
| 893 return; | 894 return; |
| 894 | 895 |
| 895 GURL validated_url(url); | 896 GURL validated_url(url); |
| 896 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 897 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
| 897 // As guests do not swap processes on navigation, only navigations to | 898 // As guests do not swap processes on navigation, only navigations to |
| 898 // normal web URLs are supported. No protocol handlers are installed for | 899 // normal web URLs are supported. No protocol handlers are installed for |
| 899 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 900 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 900 // can be granted to the guest process. | 901 // can be granted to the guest process. |
| 902 printf("Calling LoadURLWithParams\n"); | |
| 901 LoadURLWithParams(validated_url, | 903 LoadURLWithParams(validated_url, |
| 902 content::Referrer(), | 904 content::Referrer(), |
| 903 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 905 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 904 web_contents()); | 906 web_contents()); |
| 905 | 907 |
| 906 src_ = validated_url; | 908 src_ = validated_url; |
| 907 } | 909 } |
| 908 | 910 |
| 909 bool WebViewGuest::HandleKeyboardShortcuts( | 911 bool WebViewGuest::HandleKeyboardShortcuts( |
| 910 const content::NativeWebKeyboardEvent& event) { | 912 const content::NativeWebKeyboardEvent& event) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 | 954 |
| 953 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { | 955 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { |
| 954 std::string name; | 956 std::string name; |
| 955 if (params.GetString(webview::kAttributeName, &name)) { | 957 if (params.GetString(webview::kAttributeName, &name)) { |
| 956 // If the guest window's name is empty, then the WebView tag's name is | 958 // If the guest window's name is empty, then the WebView tag's name is |
| 957 // assigned. Otherwise, the guest window's name takes precedence over the | 959 // assigned. Otherwise, the guest window's name takes precedence over the |
| 958 // WebView tag's name. | 960 // WebView tag's name. |
| 959 if (name_.empty()) | 961 if (name_.empty()) |
| 960 SetName(name); | 962 SetName(name); |
| 961 } | 963 } |
| 962 if (attached()) | 964 //if (attached()) |
| 963 ReportFrameNameChange(name_); | 965 // ReportFrameNameChange(name_); |
| 964 | 966 |
| 965 std::string user_agent_override; | 967 std::string user_agent_override; |
| 966 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); | 968 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); |
| 967 SetUserAgentOverride(user_agent_override); | 969 SetUserAgentOverride(user_agent_override); |
| 968 | 970 |
| 969 bool allow_transparency = false; | 971 bool allow_transparency = false; |
| 970 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); | 972 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); |
| 971 // We need to set the background opaque flag after navigation to ensure that | 973 // We need to set the background opaque flag after navigation to ensure that |
| 972 // there is a RenderWidgetHostView available. | 974 // there is a RenderWidgetHostView available. |
| 973 SetAllowTransparency(allow_transparency); | 975 SetAllowTransparency(allow_transparency); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 } | 1118 } |
| 1117 | 1119 |
| 1118 content::WebContents* WebViewGuest::OpenURLFromTab( | 1120 content::WebContents* WebViewGuest::OpenURLFromTab( |
| 1119 content::WebContents* source, | 1121 content::WebContents* source, |
| 1120 const content::OpenURLParams& params) { | 1122 const content::OpenURLParams& params) { |
| 1121 // If the guest wishes to navigate away prior to attachment then we save the | 1123 // If the guest wishes to navigate away prior to attachment then we save the |
| 1122 // navigation to perform upon attachment. Navigation initializes a lot of | 1124 // navigation to perform upon attachment. Navigation initializes a lot of |
| 1123 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. | 1125 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. |
| 1124 // Navigation also resumes resource loading which we don't want to allow | 1126 // Navigation also resumes resource loading which we don't want to allow |
| 1125 // until attachment. | 1127 // until attachment. |
| 1128 // site-per-process | |
| 1129 printf("source: [%p], web_contents(): [%p]\n", source, web_contents()); | |
|
Fady Samuel
2015/03/04 20:44:47
This basically breaks the new window API. Why is t
| |
| 1130 printf("web_contents(): [%p]\n", web_contents()); | |
| 1131 //CHECK(0); | |
| 1132 content::NavigationController::LoadURLParams load_url_params( | |
| 1133 params.url); | |
| 1134 load_url_params.referrer = params.referrer; | |
| 1135 load_url_params.transition_type = params.transition; | |
| 1136 load_url_params.extra_headers = std::string(); | |
| 1137 //load_url_params.frame_tree_node_id = params.frame_tree_node_id; | |
| 1138 load_url_params.transferred_global_request_id = | |
| 1139 params.transferred_global_request_id; | |
| 1140 source->GetController().LoadURLWithParams(load_url_params); | |
| 1141 return source; | |
| 1142 | |
| 1143 // Note: IGNORED. | |
| 1126 if (!attached()) { | 1144 if (!attached()) { |
| 1127 WebViewGuest* opener = GetOpener(); | 1145 WebViewGuest* opener = GetOpener(); |
| 1128 auto it = opener->pending_new_windows_.find(this); | 1146 auto it = opener->pending_new_windows_.find(this); |
| 1129 if (it == opener->pending_new_windows_.end()) | 1147 if (it == opener->pending_new_windows_.end()) |
| 1130 return nullptr; | 1148 return nullptr; |
| 1131 const NewWindowInfo& info = it->second; | 1149 const NewWindowInfo& info = it->second; |
| 1132 NewWindowInfo new_window_info(params.url, info.name); | 1150 NewWindowInfo new_window_info(params.url, info.name); |
| 1133 new_window_info.changed = new_window_info.url != info.url; | 1151 new_window_info.changed = new_window_info.url != info.url; |
| 1134 it->second = new_window_info; | 1152 it->second = new_window_info; |
| 1135 return nullptr; | 1153 return nullptr; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1232 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1250 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 1233 new_window_instance_id); | 1251 new_window_instance_id); |
| 1234 if (!guest) | 1252 if (!guest) |
| 1235 return; | 1253 return; |
| 1236 | 1254 |
| 1237 if (!allow) | 1255 if (!allow) |
| 1238 guest->Destroy(); | 1256 guest->Destroy(); |
| 1239 } | 1257 } |
| 1240 | 1258 |
| 1241 } // namespace extensions | 1259 } // namespace extensions |
| OLD | NEW |