| 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 "chrome/browser/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/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 "chrome/browser/extensions/api/web_request/web_request_api.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 embedder_render_process_host->GetBrowserContext(), | 246 embedder_render_process_host->GetBrowserContext(), |
| 247 guest_site_instance); | 247 guest_site_instance); |
| 248 params.guest_delegate = this; | 248 params.guest_delegate = this; |
| 249 callback.Run(WebContents::Create(params)); | 249 callback.Run(WebContents::Create(params)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void WebViewGuest::DidAttachToEmbedder() { | 252 void WebViewGuest::DidAttachToEmbedder() { |
| 253 SetUpAutoSize(); | 253 SetUpAutoSize(); |
| 254 | 254 |
| 255 std::string name; | 255 std::string name; |
| 256 if (extra_params()->GetString(webview::kName, &name)) { | 256 if (attach_params()->GetString(webview::kName, &name)) { |
| 257 // If the guest window's name is empty, then the WebView tag's name is | 257 // If the guest window's name is empty, then the WebView tag's name is |
| 258 // assigned. Otherwise, the guest window's name takes precedence over the | 258 // assigned. Otherwise, the guest window's name takes precedence over the |
| 259 // WebView tag's name. | 259 // WebView tag's name. |
| 260 if (name_.empty()) | 260 if (name_.empty()) |
| 261 name_ = name; | 261 name_ = name; |
| 262 } | 262 } |
| 263 ReportFrameNameChange(name_); | 263 ReportFrameNameChange(name_); |
| 264 | 264 |
| 265 std::string user_agent_override; | 265 std::string user_agent_override; |
| 266 if (extra_params()->GetString(webview::kParameterUserAgentOverride, | 266 if (attach_params()->GetString(webview::kParameterUserAgentOverride, |
| 267 &user_agent_override)) { | 267 &user_agent_override)) { |
| 268 SetUserAgentOverride(user_agent_override); | 268 SetUserAgentOverride(user_agent_override); |
| 269 } else { | 269 } else { |
| 270 SetUserAgentOverride(""); | 270 SetUserAgentOverride(""); |
| 271 } | 271 } |
| 272 | 272 |
| 273 std::string src; | 273 std::string src; |
| 274 if (extra_params()->GetString("src", &src) && !src.empty()) | 274 if (attach_params()->GetString("src", &src) && !src.empty()) |
| 275 NavigateGuest(src); | 275 NavigateGuest(src); |
| 276 | 276 |
| 277 if (GetOpener()) { | 277 if (GetOpener()) { |
| 278 // We need to do a navigation here if the target URL has changed between | 278 // We need to do a navigation here if the target URL has changed between |
| 279 // the time the WebContents was created and the time it was attached. | 279 // the time the WebContents was created and the time it was attached. |
| 280 // We also need to do an initial navigation if a RenderView was never | 280 // We also need to do an initial navigation if a RenderView was never |
| 281 // created for the new window in cases where there is no referrer. | 281 // created for the new window in cases where there is no referrer. |
| 282 PendingWindowMap::iterator it = | 282 PendingWindowMap::iterator it = |
| 283 GetOpener()->pending_new_windows_.find(this); | 283 GetOpener()->pending_new_windows_.find(this); |
| 284 if (it != GetOpener()->pending_new_windows_.end()) { | 284 if (it != GetOpener()->pending_new_windows_.end()) { |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 return true; | 928 return true; |
| 929 } | 929 } |
| 930 #endif | 930 #endif |
| 931 | 931 |
| 932 return false; | 932 return false; |
| 933 } | 933 } |
| 934 | 934 |
| 935 void WebViewGuest::SetUpAutoSize() { | 935 void WebViewGuest::SetUpAutoSize() { |
| 936 // Read the autosize parameters passed in from the embedder. | 936 // Read the autosize parameters passed in from the embedder. |
| 937 bool auto_size_enabled = false; | 937 bool auto_size_enabled = false; |
| 938 extra_params()->GetBoolean(webview::kAttributeAutoSize, &auto_size_enabled); | 938 attach_params()->GetBoolean(webview::kAttributeAutoSize, &auto_size_enabled); |
| 939 | 939 |
| 940 int max_height = 0; | 940 int max_height = 0; |
| 941 int max_width = 0; | 941 int max_width = 0; |
| 942 extra_params()->GetInteger(webview::kAttributeMaxHeight, &max_height); | 942 attach_params()->GetInteger(webview::kAttributeMaxHeight, &max_height); |
| 943 extra_params()->GetInteger(webview::kAttributeMaxWidth, &max_width); | 943 attach_params()->GetInteger(webview::kAttributeMaxWidth, &max_width); |
| 944 | 944 |
| 945 int min_height = 0; | 945 int min_height = 0; |
| 946 int min_width = 0; | 946 int min_width = 0; |
| 947 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height); | 947 attach_params()->GetInteger(webview::kAttributeMinHeight, &min_height); |
| 948 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width); | 948 attach_params()->GetInteger(webview::kAttributeMinWidth, &min_width); |
| 949 | 949 |
| 950 // Call SetAutoSize to apply all the appropriate validation and clipping of | 950 // Call SetAutoSize to apply all the appropriate validation and clipping of |
| 951 // values. | 951 // values. |
| 952 SetAutoSize(auto_size_enabled, | 952 SetAutoSize(auto_size_enabled, |
| 953 gfx::Size(min_width, min_height), | 953 gfx::Size(min_width, min_height), |
| 954 gfx::Size(max_width, max_height)); | 954 gfx::Size(max_width, max_height)); |
| 955 } | 955 } |
| 956 | 956 |
| 957 void WebViewGuest::ShowContextMenu( | 957 void WebViewGuest::ShowContextMenu( |
| 958 int request_id, | 958 int request_id, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 // Retrieve the opener partition info if we have it. | 1063 // Retrieve the opener partition info if we have it. |
| 1064 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); | 1064 const GURL& site_url = new_contents->GetSiteInstance()->GetSiteURL(); |
| 1065 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); | 1065 std::string storage_partition_id = GetStoragePartitionIdFromSiteURL(site_url); |
| 1066 | 1066 |
| 1067 base::DictionaryValue request_info; | 1067 base::DictionaryValue request_info; |
| 1068 request_info.SetInteger(webview::kInitialHeight, initial_bounds.height()); | 1068 request_info.SetInteger(webview::kInitialHeight, initial_bounds.height()); |
| 1069 request_info.SetInteger(webview::kInitialWidth, initial_bounds.width()); | 1069 request_info.SetInteger(webview::kInitialWidth, initial_bounds.width()); |
| 1070 request_info.Set(webview::kTargetURL, | 1070 request_info.Set(webview::kTargetURL, |
| 1071 new base::StringValue(new_window_info.url.spec())); | 1071 new base::StringValue(new_window_info.url.spec())); |
| 1072 request_info.Set(webview::kName, new base::StringValue(new_window_info.name)); | 1072 request_info.Set(webview::kName, new base::StringValue(new_window_info.name)); |
| 1073 request_info.SetInteger(webview::kWindowID, guest->GetGuestInstanceID()); | 1073 request_info.SetInteger(webview::kWindowID, guest->guest_instance_id()); |
| 1074 // We pass in partition info so that window-s created through newwindow | 1074 // We pass in partition info so that window-s created through newwindow |
| 1075 // API can use it to set their partition attribute. | 1075 // API can use it to set their partition attribute. |
| 1076 request_info.Set(webview::kStoragePartitionId, | 1076 request_info.Set(webview::kStoragePartitionId, |
| 1077 new base::StringValue(storage_partition_id)); | 1077 new base::StringValue(storage_partition_id)); |
| 1078 request_info.Set( | 1078 request_info.Set( |
| 1079 webview::kWindowOpenDisposition, | 1079 webview::kWindowOpenDisposition, |
| 1080 new base::StringValue(WindowOpenDispositionToString(disposition))); | 1080 new base::StringValue(WindowOpenDispositionToString(disposition))); |
| 1081 | 1081 |
| 1082 web_view_permission_helper_-> | 1082 web_view_permission_helper_-> |
| 1083 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1083 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| 1084 request_info, | 1084 request_info, |
| 1085 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1085 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| 1086 base::Unretained(this), | 1086 base::Unretained(this), |
| 1087 guest->GetGuestInstanceID()), | 1087 guest->guest_instance_id()), |
| 1088 false /* allowed_by_default */); | 1088 false /* allowed_by_default */); |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 void WebViewGuest::DestroyUnattachedWindows() { | 1091 void WebViewGuest::DestroyUnattachedWindows() { |
| 1092 // Destroy() reaches in and removes the WebViewGuest from its opener's | 1092 // Destroy() reaches in and removes the WebViewGuest from its opener's |
| 1093 // pending_new_windows_ set. To avoid mutating the set while iterating, we | 1093 // pending_new_windows_ set. To avoid mutating the set while iterating, we |
| 1094 // create a copy of the pending new windows set and iterate over the copy. | 1094 // create a copy of the pending new windows set and iterate over the copy. |
| 1095 PendingWindowMap pending_new_windows(pending_new_windows_); | 1095 PendingWindowMap pending_new_windows(pending_new_windows_); |
| 1096 // Clean up unattached new windows opened by this guest. | 1096 // Clean up unattached new windows opened by this guest. |
| 1097 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); | 1097 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1122 WebViewGuest* guest = | 1122 WebViewGuest* guest = |
| 1123 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1123 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1124 if (!guest) | 1124 if (!guest) |
| 1125 return; | 1125 return; |
| 1126 | 1126 |
| 1127 if (!allow) | 1127 if (!allow) |
| 1128 guest->Destroy(); | 1128 guest->Destroy(); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 } // namespace extensions | 1131 } // namespace extensions |
| OLD | NEW |