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

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 584713002: Browser Plugin: Remove dependency on NPAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_content_window
Patch Set: Updated histograms.xml Created 6 years, 3 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/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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
246 std::string name; 247 std::string name;
247 if (attach_params()->GetString(webview::kName, &name)) { 248 if (attach_params()->GetString(webview::kAttributeName, &name)) {
248 // If the guest window's name is empty, then the WebView tag's name is 249 // 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 250 // assigned. Otherwise, the guest window's name takes precedence over the
250 // WebView tag's name. 251 // WebView tag's name.
251 if (name_.empty()) 252 if (name_.empty())
252 name_ = name; 253 name_ = name;
253 } 254 }
254 ReportFrameNameChange(name_); 255 ReportFrameNameChange(name_);
255 256
256 std::string user_agent_override; 257 std::string user_agent_override;
257 if (attach_params()->GetString(webview::kParameterUserAgentOverride, 258 if (attach_params()->GetString(webview::kParameterUserAgentOverride,
258 &user_agent_override)) { 259 &user_agent_override)) {
259 SetUserAgentOverride(user_agent_override); 260 SetUserAgentOverride(user_agent_override);
260 } else { 261 } else {
261 SetUserAgentOverride(""); 262 SetUserAgentOverride("");
262 } 263 }
263 264
264 std::string src; 265 std::string src;
265 if (attach_params()->GetString("src", &src) && !src.empty()) 266 if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty())
266 NavigateGuest(src); 267 NavigateGuest(src);
267 268
268 if (GetOpener()) { 269 if (GetOpener()) {
269 // We need to do a navigation here if the target URL has changed between 270 // 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. 271 // 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 272 // 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. 273 // created for the new window in cases where there is no referrer.
273 PendingWindowMap::iterator it = 274 PendingWindowMap::iterator it =
274 GetOpener()->pending_new_windows_.find(this); 275 GetOpener()->pending_new_windows_.find(this);
275 if (it != GetOpener()->pending_new_windows_.end()) { 276 if (it != GetOpener()->pending_new_windows_.end()) {
276 const NewWindowInfo& new_window_info = it->second; 277 const NewWindowInfo& new_window_info = it->second;
277 if (new_window_info.changed || !web_contents()->HasOpener()) 278 if (new_window_info.changed || !web_contents()->HasOpener())
278 NavigateGuest(new_window_info.url.spec()); 279 NavigateGuest(new_window_info.url.spec());
279 } else { 280 } else {
280 NOTREACHED(); 281 NOTREACHED();
281 } 282 }
282 283
283 // Once a new guest is attached to the DOM of the embedder page, then the 284 // Once a new guest is attached to the DOM of the embedder page, then the
284 // lifetime of the new guest is no longer managed by the opener guest. 285 // lifetime of the new guest is no longer managed by the opener guest.
285 GetOpener()->pending_new_windows_.erase(this); 286 GetOpener()->pending_new_windows_.erase(this);
286 } 287 }
288
289 bool allow_transparency = false;
290 attach_params()->GetBoolean(webview::kAttributeAllowTransparency,
291 &allow_transparency);
292 // We need to set the background opaque flag after navigation to ensure that
293 // there is a RenderWidgetHostView available.
294 SetAllowTransparency(allow_transparency);
287 } 295 }
288 296
289 void WebViewGuest::DidInitialize() { 297 void WebViewGuest::DidInitialize() {
290 script_executor_.reset( 298 script_executor_.reset(
291 new ScriptExecutor(web_contents(), &script_observers_)); 299 new ScriptExecutor(web_contents(), &script_observers_));
292 300
293 notification_registrar_.Add(this, 301 notification_registrar_.Add(this,
294 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 302 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
295 content::Source<WebContents>(web_contents())); 303 content::Source<WebContents>(web_contents()));
296 304
(...skipping 27 matching lines...) Expand all
324 // Clean up custom context menu items for this guest. 332 // Clean up custom context menu items for this guest.
325 if (web_view_guest_delegate_) 333 if (web_view_guest_delegate_)
326 web_view_guest_delegate_->OnGuestDestroyed(); 334 web_view_guest_delegate_->OnGuestDestroyed();
327 RemoveWebViewStateFromIOThread(web_contents()); 335 RemoveWebViewStateFromIOThread(web_contents());
328 } 336 }
329 337
330 void WebViewGuest::GuestReady() { 338 void WebViewGuest::GuestReady() {
331 // The guest RenderView should always live in an isolated guest process. 339 // The guest RenderView should always live in an isolated guest process.
332 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); 340 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
333 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); 341 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_));
342
343 // We don't want to accidentally set the opacity of an interstitial page.
344 // WebContents::GetRenderWidgetHostView will return the RWHV of an
345 // interstitial page if one is showing at this time. We only want opacity
346 // to apply to web pages.
347 web_contents()->GetRenderViewHost()->GetView()->
348 SetBackgroundOpaque(guest_opaque_);
334 } 349 }
335 350
336 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, 351 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
337 const gfx::Size& new_size) { 352 const gfx::Size& new_size) {
338 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 353 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
339 args->SetInteger(webview::kOldHeight, old_size.height()); 354 args->SetInteger(webview::kOldHeight, old_size.height());
340 args->SetInteger(webview::kOldWidth, old_size.width()); 355 args->SetInteger(webview::kOldWidth, old_size.width());
341 args->SetInteger(webview::kNewHeight, new_size.height()); 356 args->SetInteger(webview::kNewHeight, new_size.height());
342 args->SetInteger(webview::kNewWidth, new_size.width()); 357 args->SetInteger(webview::kNewWidth, new_size.width());
343 DispatchEventToEmbedder( 358 DispatchEventToEmbedder(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 base::Time::Now(), 626 base::Time::Now(),
612 callback); 627 callback);
613 return true; 628 return true;
614 } 629 }
615 630
616 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 631 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
617 int guest_instance_id) 632 int guest_instance_id)
618 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 633 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
619 find_helper_(this), 634 find_helper_(this),
620 is_overriding_user_agent_(false), 635 is_overriding_user_agent_(false),
636 guest_opaque_(true),
621 javascript_dialog_helper_(this) { 637 javascript_dialog_helper_(this) {
622 web_view_guest_delegate_.reset( 638 web_view_guest_delegate_.reset(
623 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 639 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
624 } 640 }
625 641
626 WebViewGuest::~WebViewGuest() { 642 WebViewGuest::~WebViewGuest() {
627 } 643 }
628 644
629 void WebViewGuest::DidCommitProvisionalLoadForFrame( 645 void WebViewGuest::DidCommitProvisionalLoadForFrame(
630 content::RenderFrameHost* render_frame_host, 646 content::RenderFrameHost* render_frame_host,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 name_ = name; 964 name_ = name;
949 965
950 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); 966 Send(new ExtensionMsg_SetFrameName(routing_id(), name_));
951 } 967 }
952 968
953 void WebViewGuest::SetZoom(double zoom_factor) { 969 void WebViewGuest::SetZoom(double zoom_factor) {
954 if (web_view_guest_delegate_) 970 if (web_view_guest_delegate_)
955 web_view_guest_delegate_->OnSetZoom(zoom_factor); 971 web_view_guest_delegate_->OnSetZoom(zoom_factor);
956 } 972 }
957 973
974 void WebViewGuest::SetAllowTransparency(bool allow) {
975 if (guest_opaque_ != allow)
976 return;
977
978 guest_opaque_ = !allow;
979 if (!web_contents()->GetRenderViewHost()->GetView())
980 return;
981
982 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow);
983 }
984
958 void WebViewGuest::AddNewContents(content::WebContents* source, 985 void WebViewGuest::AddNewContents(content::WebContents* source,
959 content::WebContents* new_contents, 986 content::WebContents* new_contents,
960 WindowOpenDisposition disposition, 987 WindowOpenDisposition disposition,
961 const gfx::Rect& initial_pos, 988 const gfx::Rect& initial_pos,
962 bool user_gesture, 989 bool user_gesture,
963 bool* was_blocked) { 990 bool* was_blocked) {
964 if (was_blocked) 991 if (was_blocked)
965 *was_blocked = false; 992 *was_blocked = false;
966 RequestNewWindowPermission(disposition, 993 RequestNewWindowPermission(disposition,
967 initial_pos, 994 initial_pos,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 WebViewGuest* guest = 1130 WebViewGuest* guest =
1104 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1131 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1105 if (!guest) 1132 if (!guest)
1106 return; 1133 return;
1107 1134
1108 if (!allow) 1135 if (!allow)
1109 guest->Destroy(); 1136 guest->Destroy();
1110 } 1137 }
1111 1138
1112 } // namespace extensions 1139 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/web_view/web_view_guest.h ('k') | extensions/common/api/web_view_internal.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698