OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/common/content_constants_internal.h" | 25 #include "content/common/content_constants_internal.h" |
26 #include "content/common/drag_messages.h" | 26 #include "content/common/drag_messages.h" |
27 #include "content/common/gpu/gpu_messages.h" | 27 #include "content/common/gpu/gpu_messages.h" |
28 #include "content/common/input_messages.h" | 28 #include "content/common/input_messages.h" |
29 #include "content/common/view_messages.h" | 29 #include "content/common/view_messages.h" |
30 #include "content/port/browser/render_view_host_delegate_view.h" | 30 #include "content/port/browser/render_view_host_delegate_view.h" |
31 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
32 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
33 #include "content/public/browser/geolocation_permission_context.h" | 33 #include "content/public/browser/geolocation_permission_context.h" |
34 #include "content/public/browser/navigation_controller.h" | 34 #include "content/public/browser/navigation_controller.h" |
35 #include "content/public/browser/notification_service.h" | |
36 #include "content/public/browser/notification_types.h" | |
37 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
39 #include "content/public/browser/resource_request_details.h" | 37 #include "content/public/browser/resource_request_details.h" |
40 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 39 #include "content/public/browser/web_contents_observer.h" |
41 #include "content/public/browser/web_contents_view.h" | 40 #include "content/public/browser/web_contents_view.h" |
42 #include "content/public/common/drop_data.h" | 41 #include "content/public/common/drop_data.h" |
43 #include "content/public/common/media_stream_request.h" | 42 #include "content/public/common/media_stream_request.h" |
44 #include "content/public/common/result_codes.h" | 43 #include "content/public/common/result_codes.h" |
45 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
46 #include "content/public/common/url_utils.h" | 45 #include "content/public/common/url_utils.h" |
47 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
48 #include "third_party/WebKit/public/web/WebCursorInfo.h" | 47 #include "third_party/WebKit/public/web/WebCursorInfo.h" |
49 #include "ui/events/keycodes/keyboard_codes.h" | 48 #include "ui/events/keycodes/keyboard_codes.h" |
50 #include "ui/surface/transport_dib.h" | 49 #include "ui/surface/transport_dib.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 GlobalRequestID global_id(render_process_id, url_request_id); | 294 GlobalRequestID global_id(render_process_id, url_request_id); |
296 net::URLRequest* url_request = | 295 net::URLRequest* url_request = |
297 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 296 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
298 if (url_request) | 297 if (url_request) |
299 return url_request->url().possibly_invalid_spec(); | 298 return url_request->url().possibly_invalid_spec(); |
300 return std::string(); | 299 return std::string(); |
301 } | 300 } |
302 | 301 |
303 } // namespace | 302 } // namespace |
304 | 303 |
305 class BrowserPluginGuest::EmbedderRenderViewHostObserver | 304 class BrowserPluginGuest::EmbedderWebContentsObserver |
306 : public RenderViewHostObserver { | 305 : public WebContentsObserver { |
307 public: | 306 public: |
308 explicit EmbedderRenderViewHostObserver(BrowserPluginGuest* guest) | 307 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) |
309 : RenderViewHostObserver( | 308 : WebContentsObserver(guest->embedder_web_contents()), |
310 guest->embedder_web_contents()->GetRenderViewHost()), | |
311 browser_plugin_guest_(guest) { | 309 browser_plugin_guest_(guest) { |
312 } | 310 } |
313 | 311 |
314 virtual ~EmbedderRenderViewHostObserver() { | 312 virtual ~EmbedderWebContentsObserver() { |
315 } | 313 } |
316 | 314 |
317 // RenderViewHostObserver: | 315 // WebContentsObserver: |
318 virtual void RenderViewHostDestroyed( | 316 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { |
319 RenderViewHost* render_view_host) OVERRIDE { | |
320 browser_plugin_guest_->EmbedderDestroyed(); | 317 browser_plugin_guest_->EmbedderDestroyed(); |
321 } | 318 } |
322 | 319 |
| 320 virtual void WasShown() OVERRIDE { |
| 321 browser_plugin_guest_->EmbedderVisibilityChanged(true); |
| 322 } |
| 323 |
| 324 virtual void WasHidden() OVERRIDE { |
| 325 browser_plugin_guest_->EmbedderVisibilityChanged(false); |
| 326 } |
| 327 |
323 private: | 328 private: |
324 BrowserPluginGuest* browser_plugin_guest_; | 329 BrowserPluginGuest* browser_plugin_guest_; |
325 | 330 |
326 DISALLOW_COPY_AND_ASSIGN(EmbedderRenderViewHostObserver); | 331 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); |
327 }; | 332 }; |
328 | 333 |
329 BrowserPluginGuest::BrowserPluginGuest( | 334 BrowserPluginGuest::BrowserPluginGuest( |
330 int instance_id, | 335 int instance_id, |
331 WebContentsImpl* web_contents, | 336 WebContentsImpl* web_contents, |
332 BrowserPluginGuest* opener, | 337 BrowserPluginGuest* opener, |
333 bool has_render_view) | 338 bool has_render_view) |
334 : WebContentsObserver(web_contents), | 339 : WebContentsObserver(web_contents), |
335 weak_ptr_factory_(this), | 340 weak_ptr_factory_(this), |
336 embedder_web_contents_(NULL), | 341 embedder_web_contents_(NULL), |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 // We would like the guest to report changes to frame names so that we can | 571 // We would like the guest to report changes to frame names so that we can |
567 // update the BrowserPlugin's corresponding 'name' attribute. | 572 // update the BrowserPlugin's corresponding 'name' attribute. |
568 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. | 573 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. |
569 renderer_prefs->report_frame_name_changes = true; | 574 renderer_prefs->report_frame_name_changes = true; |
570 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 575 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
571 // navigations still continue to function inside the app. | 576 // navigations still continue to function inside the app. |
572 renderer_prefs->browser_handles_all_top_level_requests = false; | 577 renderer_prefs->browser_handles_all_top_level_requests = false; |
573 // Disable "client blocked" error page for browser plugin. | 578 // Disable "client blocked" error page for browser plugin. |
574 renderer_prefs->disable_client_blocked_error_page = true; | 579 renderer_prefs->disable_client_blocked_error_page = true; |
575 | 580 |
576 // Listen to embedder visibility changes so that the guest is in a 'shown' | 581 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); |
577 // state if both the embedder is visible and the BrowserPlugin is marked as | |
578 // visible. | |
579 notification_registrar_.Add( | |
580 this, NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | |
581 Source<WebContents>(embedder_web_contents_)); | |
582 | |
583 embedder_rvh_observer_.reset(new EmbedderRenderViewHostObserver(this)); | |
584 | 582 |
585 OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params); | 583 OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params); |
586 | 584 |
587 // Create a swapped out RenderView for the guest in the embedder render | 585 // Create a swapped out RenderView for the guest in the embedder render |
588 // process, so that the embedder can access the guest's window object. | 586 // process, so that the embedder can access the guest's window object. |
589 int guest_routing_id = | 587 int guest_routing_id = |
590 GetWebContents()->CreateSwappedOutRenderView( | 588 GetWebContents()->CreateSwappedOutRenderView( |
591 embedder_web_contents_->GetSiteInstance()); | 589 embedder_web_contents_->GetSiteInstance()); |
592 SendMessageToEmbedder( | 590 SendMessageToEmbedder( |
593 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, | 591 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 OnSetVisibility(instance_id_, visible()); | 678 OnSetVisibility(instance_id_, visible()); |
681 } | 679 } |
682 | 680 |
683 // screen. | 681 // screen. |
684 gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { | 682 gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { |
685 gfx::Rect guest_rect(bounds); | 683 gfx::Rect guest_rect(bounds); |
686 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); | 684 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); |
687 return guest_rect; | 685 return guest_rect; |
688 } | 686 } |
689 | 687 |
690 void BrowserPluginGuest::Observe(int type, | 688 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
691 const NotificationSource& source, | 689 embedder_visible_ = visible; |
692 const NotificationDetails& details) { | 690 UpdateVisibility(); |
693 switch (type) { | |
694 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { | |
695 DCHECK_EQ(Source<WebContents>(source).ptr(), embedder_web_contents_); | |
696 embedder_visible_ = *Details<bool>(details).ptr(); | |
697 UpdateVisibility(); | |
698 break; | |
699 } | |
700 default: | |
701 NOTREACHED() << "Unexpected notification sent."; | |
702 break; | |
703 } | |
704 } | 691 } |
705 | 692 |
706 void BrowserPluginGuest::AddNewContents(WebContents* source, | 693 void BrowserPluginGuest::AddNewContents(WebContents* source, |
707 WebContents* new_contents, | 694 WebContents* new_contents, |
708 WindowOpenDisposition disposition, | 695 WindowOpenDisposition disposition, |
709 const gfx::Rect& initial_pos, | 696 const gfx::Rect& initial_pos, |
710 bool user_gesture, | 697 bool user_gesture, |
711 bool* was_blocked) { | 698 bool* was_blocked) { |
712 if (was_blocked) | 699 if (was_blocked) |
713 *was_blocked = false; | 700 *was_blocked = false; |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 request_info.Set(browser_plugin::kRequestMethod, | 1720 request_info.Set(browser_plugin::kRequestMethod, |
1734 base::Value::CreateStringValue(request_method)); | 1721 base::Value::CreateStringValue(request_method)); |
1735 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1722 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
1736 | 1723 |
1737 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1724 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
1738 new DownloadRequest(callback), | 1725 new DownloadRequest(callback), |
1739 request_info); | 1726 request_info); |
1740 } | 1727 } |
1741 | 1728 |
1742 } // namespace content | 1729 } // namespace content |
OLD | NEW |