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" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/child_process_security_policy.h" | 12 #include "content/public/browser/child_process_security_policy.h" |
13 #include "content/public/browser/native_web_keyboard_event.h" | 13 #include "content/public/browser/native_web_keyboard_event.h" |
14 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
15 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" |
21 #include "content/public/browser/resource_request_details.h" | 22 #include "content/public/browser/resource_request_details.h" |
22 #include "content/public/browser/site_instance.h" | 23 #include "content/public/browser/site_instance.h" |
23 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
24 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
27 #include "content/public/common/media_stream_request.h" | 28 #include "content/public/common/media_stream_request.h" |
28 #include "content/public/common/page_zoom.h" | 29 #include "content/public/common/page_zoom.h" |
29 #include "content/public/common/result_codes.h" | 30 #include "content/public/common/result_codes.h" |
30 #include "content/public/common/stop_find_action.h" | 31 #include "content/public/common/stop_find_action.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 WebContents::CreateParams params( | 237 WebContents::CreateParams params( |
237 embedder_render_process_host->GetBrowserContext(), | 238 embedder_render_process_host->GetBrowserContext(), |
238 guest_site_instance); | 239 guest_site_instance); |
239 params.guest_delegate = this; | 240 params.guest_delegate = this; |
240 callback.Run(WebContents::Create(params)); | 241 callback.Run(WebContents::Create(params)); |
241 } | 242 } |
242 | 243 |
243 void WebViewGuest::DidAttachToEmbedder() { | 244 void WebViewGuest::DidAttachToEmbedder() { |
244 SetUpAutoSize(); | 245 SetUpAutoSize(); |
245 | 246 |
| 247 bool allow_transparency = false; |
| 248 attach_params()->GetBoolean(webview::kAttributeAllowTransparency, |
| 249 &allow_transparency); |
| 250 SetAllowTransparency(allow_transparency); |
| 251 |
246 std::string name; | 252 std::string name; |
247 if (attach_params()->GetString(webview::kName, &name)) { | 253 if (attach_params()->GetString(webview::kAttributeName, &name)) { |
248 // If the guest window's name is empty, then the WebView tag's name is | 254 // If the guest window's name is empty, then the WebView tag's name is |
249 // assigned. Otherwise, the guest window's name takes precedence over the | 255 // assigned. Otherwise, the guest window's name takes precedence over the |
250 // WebView tag's name. | 256 // WebView tag's name. |
251 if (name_.empty()) | 257 if (name_.empty()) |
252 name_ = name; | 258 name_ = name; |
253 } | 259 } |
254 ReportFrameNameChange(name_); | 260 ReportFrameNameChange(name_); |
255 | 261 |
256 std::string user_agent_override; | 262 std::string user_agent_override; |
257 if (attach_params()->GetString(webview::kParameterUserAgentOverride, | 263 if (attach_params()->GetString(webview::kParameterUserAgentOverride, |
258 &user_agent_override)) { | 264 &user_agent_override)) { |
259 SetUserAgentOverride(user_agent_override); | 265 SetUserAgentOverride(user_agent_override); |
260 } else { | 266 } else { |
261 SetUserAgentOverride(""); | 267 SetUserAgentOverride(""); |
262 } | 268 } |
263 | 269 |
264 std::string src; | 270 std::string src; |
265 if (attach_params()->GetString("src", &src) && !src.empty()) | 271 if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty()) |
266 NavigateGuest(src); | 272 NavigateGuest(src); |
267 | 273 |
268 if (GetOpener()) { | 274 if (GetOpener()) { |
269 // We need to do a navigation here if the target URL has changed between | 275 // We need to do a navigation here if the target URL has changed between |
270 // the time the WebContents was created and the time it was attached. | 276 // the time the WebContents was created and the time it was attached. |
271 // We also need to do an initial navigation if a RenderView was never | 277 // We also need to do an initial navigation if a RenderView was never |
272 // created for the new window in cases where there is no referrer. | 278 // created for the new window in cases where there is no referrer. |
273 PendingWindowMap::iterator it = | 279 PendingWindowMap::iterator it = |
274 GetOpener()->pending_new_windows_.find(this); | 280 GetOpener()->pending_new_windows_.find(this); |
275 if (it != GetOpener()->pending_new_windows_.end()) { | 281 if (it != GetOpener()->pending_new_windows_.end()) { |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 name_ = name; | 954 name_ = name; |
949 | 955 |
950 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); | 956 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); |
951 } | 957 } |
952 | 958 |
953 void WebViewGuest::SetZoom(double zoom_factor) { | 959 void WebViewGuest::SetZoom(double zoom_factor) { |
954 if (web_view_guest_delegate_) | 960 if (web_view_guest_delegate_) |
955 web_view_guest_delegate_->OnSetZoom(zoom_factor); | 961 web_view_guest_delegate_->OnSetZoom(zoom_factor); |
956 } | 962 } |
957 | 963 |
| 964 void WebViewGuest::SetAllowTransparency(bool allow) { |
| 965 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow); |
| 966 } |
| 967 |
958 void WebViewGuest::AddNewContents(content::WebContents* source, | 968 void WebViewGuest::AddNewContents(content::WebContents* source, |
959 content::WebContents* new_contents, | 969 content::WebContents* new_contents, |
960 WindowOpenDisposition disposition, | 970 WindowOpenDisposition disposition, |
961 const gfx::Rect& initial_pos, | 971 const gfx::Rect& initial_pos, |
962 bool user_gesture, | 972 bool user_gesture, |
963 bool* was_blocked) { | 973 bool* was_blocked) { |
964 if (was_blocked) | 974 if (was_blocked) |
965 *was_blocked = false; | 975 *was_blocked = false; |
966 RequestNewWindowPermission(disposition, | 976 RequestNewWindowPermission(disposition, |
967 initial_pos, | 977 initial_pos, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 WebViewGuest* guest = | 1113 WebViewGuest* guest = |
1104 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1114 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1105 if (!guest) | 1115 if (!guest) |
1106 return; | 1116 return; |
1107 | 1117 |
1108 if (!allow) | 1118 if (!allow) |
1109 guest->Destroy(); | 1119 guest->Destroy(); |
1110 } | 1120 } |
1111 | 1121 |
1112 } // namespace extensions | 1122 } // namespace extensions |
OLD | NEW |