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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 content::Source<WebContents>(web_contents())); | 315 content::Source<WebContents>(web_contents())); |
316 | 316 |
317 if (web_view_guest_delegate_) | 317 if (web_view_guest_delegate_) |
318 web_view_guest_delegate_->OnDidInitialize(); | 318 web_view_guest_delegate_->OnDidInitialize(); |
319 AttachWebViewHelpers(web_contents()); | 319 AttachWebViewHelpers(web_contents()); |
320 | 320 |
321 rules_registry_id_ = GetOrGenerateRulesRegistryID( | 321 rules_registry_id_ = GetOrGenerateRulesRegistryID( |
322 owner_web_contents()->GetRenderProcessHost()->GetID(), | 322 owner_web_contents()->GetRenderProcessHost()->GetID(), |
323 view_instance_id()); | 323 view_instance_id()); |
324 | 324 |
325 // We must install the mapping from guests to WebViews prior to resuming | 325 // NOTE: Calling this prior to attachment breaks OOPIF <webview>. |
326 // suspended resource loads so that the WebRequest API will catch resource | 326 //// We must install the mapping from guests to WebViews prior to resuming |
327 // requests. | 327 //// suspended resource loads so that the WebRequest API will catch resource |
328 PushWebViewStateToIOThread(); | 328 //// requests. |
| 329 //PushWebViewStateToIOThread(); |
329 | 330 |
330 ApplyAttributes(create_params); | 331 //ApplyAttributes(create_params); |
331 } | 332 } |
332 | 333 |
333 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { | 334 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { |
334 if (web_view_guest_delegate_) | 335 if (web_view_guest_delegate_) |
335 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); | 336 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); |
336 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 337 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
337 } | 338 } |
338 | 339 |
339 void WebViewGuest::ClearDataInternal(base::Time remove_since, | 340 void WebViewGuest::ClearDataInternal(base::Time remove_since, |
340 uint32 removal_mask, | 341 uint32 removal_mask, |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 } | 794 } |
794 | 795 |
795 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host, | 796 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host, |
796 const std::string& name) { | 797 const std::string& name) { |
797 if (render_frame_host->GetParent()) | 798 if (render_frame_host->GetParent()) |
798 return; | 799 return; |
799 | 800 |
800 if (name_ == name) | 801 if (name_ == name) |
801 return; | 802 return; |
802 | 803 |
803 ReportFrameNameChange(name); | 804 //ReportFrameNameChange(name); |
804 } | 805 } |
805 | 806 |
806 void WebViewGuest::ReportFrameNameChange(const std::string& name) { | 807 void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
807 name_ = name; | 808 name_ = name; |
808 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 809 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
809 args->SetString(webview::kName, name); | 810 args->SetString(webview::kName, name); |
810 DispatchEventToView( | 811 DispatchEventToView( |
811 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); | 812 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
812 } | 813 } |
813 | 814 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 } | 908 } |
908 | 909 |
909 void WebViewGuest::WillAttachToEmbedder() { | 910 void WebViewGuest::WillAttachToEmbedder() { |
910 rules_registry_id_ = GetOrGenerateRulesRegistryID( | 911 rules_registry_id_ = GetOrGenerateRulesRegistryID( |
911 owner_web_contents()->GetRenderProcessHost()->GetID(), | 912 owner_web_contents()->GetRenderProcessHost()->GetID(), |
912 view_instance_id()); | 913 view_instance_id()); |
913 | 914 |
914 // We must install the mapping from guests to WebViews prior to resuming | 915 // We must install the mapping from guests to WebViews prior to resuming |
915 // suspended resource loads so that the WebRequest API will catch resource | 916 // suspended resource loads so that the WebRequest API will catch resource |
916 // requests. | 917 // requests. |
917 PushWebViewStateToIOThread(); | 918 //PushWebViewStateToIOThread(); |
918 } | 919 } |
919 | 920 |
920 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( | 921 content::JavaScriptDialogManager* WebViewGuest::GetJavaScriptDialogManager( |
921 WebContents* source) { | 922 WebContents* source) { |
922 return &javascript_dialog_helper_; | 923 return &javascript_dialog_helper_; |
923 } | 924 } |
924 | 925 |
925 void WebViewGuest::NavigateGuest(const std::string& src, | 926 void WebViewGuest::NavigateGuest(const std::string& src, |
926 bool force_navigation) { | 927 bool force_navigation) { |
927 if (src.empty()) | 928 if (src.empty()) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 | 981 |
981 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { | 982 void WebViewGuest::ApplyAttributes(const base::DictionaryValue& params) { |
982 std::string name; | 983 std::string name; |
983 if (params.GetString(webview::kAttributeName, &name)) { | 984 if (params.GetString(webview::kAttributeName, &name)) { |
984 // If the guest window's name is empty, then the WebView tag's name is | 985 // If the guest window's name is empty, then the WebView tag's name is |
985 // assigned. Otherwise, the guest window's name takes precedence over the | 986 // assigned. Otherwise, the guest window's name takes precedence over the |
986 // WebView tag's name. | 987 // WebView tag's name. |
987 if (name_.empty()) | 988 if (name_.empty()) |
988 SetName(name); | 989 SetName(name); |
989 } | 990 } |
990 if (attached()) | 991 //if (attached()) |
991 ReportFrameNameChange(name_); | 992 // ReportFrameNameChange(name_); |
992 | 993 |
993 std::string user_agent_override; | 994 std::string user_agent_override; |
994 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); | 995 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); |
995 SetUserAgentOverride(user_agent_override); | 996 SetUserAgentOverride(user_agent_override); |
996 | 997 |
997 bool allow_transparency = false; | 998 bool allow_transparency = false; |
998 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); | 999 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); |
999 // We need to set the background opaque flag after navigation to ensure that | 1000 // We need to set the background opaque flag after navigation to ensure that |
1000 // there is a RenderWidgetHostView available. | 1001 // there is a RenderWidgetHostView available. |
1001 SetAllowTransparency(allow_transparency); | 1002 SetAllowTransparency(allow_transparency); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 return nullptr; | 1161 return nullptr; |
1161 return owner_web_contents()->GetDelegate()->OpenURLFromTab( | 1162 return owner_web_contents()->GetDelegate()->OpenURLFromTab( |
1162 owner_web_contents(), params); | 1163 owner_web_contents(), params); |
1163 } | 1164 } |
1164 | 1165 |
1165 // If the guest wishes to navigate away prior to attachment then we save the | 1166 // If the guest wishes to navigate away prior to attachment then we save the |
1166 // navigation to perform upon attachment. Navigation initializes a lot of | 1167 // navigation to perform upon attachment. Navigation initializes a lot of |
1167 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. | 1168 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. |
1168 // Navigation also resumes resource loading which we don't want to allow | 1169 // Navigation also resumes resource loading which we don't want to allow |
1169 // until attachment. | 1170 // until attachment. |
| 1171 // site-per-process |
| 1172 printf("source: [%p], web_contents(): [%p]\n", source, web_contents()); |
| 1173 printf("web_contents(): [%p]\n", web_contents()); |
| 1174 //CHECK(0); |
| 1175 content::NavigationController::LoadURLParams load_url_params( |
| 1176 params.url); |
| 1177 load_url_params.referrer = params.referrer; |
| 1178 load_url_params.transition_type = params.transition; |
| 1179 load_url_params.extra_headers = std::string(); |
| 1180 //load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
| 1181 load_url_params.transferred_global_request_id = |
| 1182 params.transferred_global_request_id; |
| 1183 source->GetController().LoadURLWithParams(load_url_params); |
| 1184 return source; |
| 1185 |
| 1186 // Note: IGNORED. |
1170 if (!attached()) { | 1187 if (!attached()) { |
1171 WebViewGuest* opener = GetOpener(); | 1188 WebViewGuest* opener = GetOpener(); |
1172 auto it = opener->pending_new_windows_.find(this); | 1189 auto it = opener->pending_new_windows_.find(this); |
1173 if (it == opener->pending_new_windows_.end()) | 1190 if (it == opener->pending_new_windows_.end()) |
1174 return nullptr; | 1191 return nullptr; |
1175 const NewWindowInfo& info = it->second; | 1192 const NewWindowInfo& info = it->second; |
1176 NewWindowInfo new_window_info(params.url, info.name); | 1193 NewWindowInfo new_window_info(params.url, info.name); |
1177 new_window_info.changed = new_window_info.url != info.url; | 1194 new_window_info.changed = new_window_info.url != info.url; |
1178 it->second = new_window_info; | 1195 it->second = new_window_info; |
1179 return nullptr; | 1196 return nullptr; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1394 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1378 DispatchEventToView( | 1395 DispatchEventToView( |
1379 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass())); | 1396 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass())); |
1380 } | 1397 } |
1381 // Since we changed fullscreen state, sending a Resize message ensures that | 1398 // Since we changed fullscreen state, sending a Resize message ensures that |
1382 // renderer/ sees the change. | 1399 // renderer/ sees the change. |
1383 web_contents()->GetRenderViewHost()->WasResized(); | 1400 web_contents()->GetRenderViewHost()->WasResized(); |
1384 } | 1401 } |
1385 | 1402 |
1386 } // namespace extensions | 1403 } // namespace extensions |
OLD | NEW |