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.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 IPC_END_MESSAGE_MAP() | 200 IPC_END_MESSAGE_MAP() |
201 return handled; | 201 return handled; |
202 } | 202 } |
203 | 203 |
204 void BrowserPluginGuest::Initialize( | 204 void BrowserPluginGuest::Initialize( |
205 WebContentsImpl* embedder_web_contents, | 205 WebContentsImpl* embedder_web_contents, |
206 const BrowserPluginHostMsg_CreateGuest_Params& params) { | 206 const BrowserPluginHostMsg_CreateGuest_Params& params) { |
207 focused_ = params.focused; | 207 focused_ = params.focused; |
208 guest_visible_ = params.visible; | 208 guest_visible_ = params.visible; |
209 if (!params.name.empty()) | 209 if (!params.name.empty()) |
210 name_ = params.name; | 210 GetWebContents()->SetWindowName(params.name); |
Charlie Reis
2013/04/18 21:26:51
Why is this needed? Won't the RenderView tell the
| |
211 auto_size_enabled_ = params.auto_size_params.enable; | 211 auto_size_enabled_ = params.auto_size_params.enable; |
212 max_auto_size_ = params.auto_size_params.max_size; | 212 max_auto_size_ = params.auto_size_params.max_size; |
213 min_auto_size_ = params.auto_size_params.min_size; | 213 min_auto_size_ = params.auto_size_params.min_size; |
214 | 214 |
215 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 215 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
216 // be attached. | 216 // be attached. |
217 embedder_web_contents_ = embedder_web_contents; | 217 embedder_web_contents_ = embedder_web_contents; |
218 | 218 |
219 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 219 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
220 new BrowserPluginGuestHelper(this, GetWebContents()->GetRenderViewHost()); | 220 new BrowserPluginGuestHelper(this, GetWebContents()->GetRenderViewHost()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 | 366 |
367 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 367 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
368 int64 source_frame_id, | 368 int64 source_frame_id, |
369 const string16& frame_name, | 369 const string16& frame_name, |
370 const GURL& target_url, | 370 const GURL& target_url, |
371 WebContents* new_contents) { | 371 WebContents* new_contents) { |
372 WebContentsImpl* new_contents_impl = | 372 WebContentsImpl* new_contents_impl = |
373 static_cast<WebContentsImpl*>(new_contents); | 373 static_cast<WebContentsImpl*>(new_contents); |
374 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); | 374 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); |
375 guest->opener_ = this; | 375 guest->opener_ = this; |
376 guest->name_ = UTF16ToUTF8(frame_name); | 376 new_contents_impl->SetWindowName(UTF16ToUTF8(frame_name)); |
Charlie Reis
2013/04/18 21:26:51
Again, won't RenderView tell us?
| |
377 // Take ownership of the new guest until it is attached to the embedder's DOM | 377 // Take ownership of the new guest until it is attached to the embedder's DOM |
378 // tree to avoid leaking a guest if this guest is destroyed before attaching | 378 // tree to avoid leaking a guest if this guest is destroyed before attaching |
379 // the new guest. | 379 // the new guest. |
380 pending_new_windows_.insert(make_pair(guest, target_url.spec())); | 380 pending_new_windows_.insert(make_pair(guest, target_url.spec())); |
381 } | 381 } |
382 | 382 |
383 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { | 383 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { |
384 int process_id = | 384 int process_id = |
385 GetWebContents()->GetRenderProcessHost()->GetID(); | 385 GetWebContents()->GetRenderProcessHost()->GetID(); |
386 SendMessageToEmbedder( | 386 SendMessageToEmbedder( |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 // Initiating a drag from inside a guest is currently not supported. So inject | 609 // Initiating a drag from inside a guest is currently not supported. So inject |
610 // some JS to disable it. http://crbug.com/161112 | 610 // some JS to disable it. http://crbug.com/161112 |
611 const char script[] = "window.addEventListener('dragstart', function() { " | 611 const char script[] = "window.addEventListener('dragstart', function() { " |
612 " window.event.preventDefault(); " | 612 " window.event.preventDefault(); " |
613 "});"; | 613 "});"; |
614 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 614 render_view_host->ExecuteJavascriptInWebFrame(string16(), |
615 ASCIIToUTF16(script)); | 615 ASCIIToUTF16(script)); |
616 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); | 616 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(instance_id())); |
617 } | 617 } |
618 | 618 |
619 void BrowserPluginGuest::DidUpdateFrameName(int frame_id, | |
620 bool is_top_level, | |
621 const std::string& name, | |
622 RenderViewHost* render_view_host) { | |
623 if (!is_top_level) | |
624 return; | |
625 | |
626 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); | |
627 } | |
628 | |
619 void BrowserPluginGuest::RenderViewReady() { | 629 void BrowserPluginGuest::RenderViewReady() { |
620 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 630 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
621 // here (see http://crbug.com/158151). | 631 // here (see http://crbug.com/158151). |
622 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 632 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
623 UpdateVisibility(); | 633 UpdateVisibility(); |
624 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 634 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
625 if (auto_size_enabled_) | 635 if (auto_size_enabled_) |
626 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); | 636 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
627 else | 637 else |
628 rvh->DisableAutoResize(damage_view_size_); | 638 rvh->DisableAutoResize(damage_view_size_); |
629 | 639 |
630 Send(new ViewMsg_SetName(routing_id(), name_)); | |
631 | |
632 RenderWidgetHostImpl::From(rvh)-> | 640 RenderWidgetHostImpl::From(rvh)-> |
633 set_hung_renderer_delay_ms(guest_hang_timeout_); | 641 set_hung_renderer_delay_ms(guest_hang_timeout_); |
634 } | 642 } |
635 | 643 |
636 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { | 644 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
637 int process_id = GetWebContents()->GetRenderProcessHost()->GetID(); | 645 int process_id = GetWebContents()->GetRenderProcessHost()->GetID(); |
638 SendMessageToEmbedder( | 646 SendMessageToEmbedder( |
639 new BrowserPluginMsg_GuestGone(instance_id(), process_id, status)); | 647 new BrowserPluginMsg_GuestGone(instance_id(), process_id, status)); |
640 switch (status) { | 648 switch (status) { |
641 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 649 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 #if defined(OS_MACOSX) | 714 #if defined(OS_MACOSX) |
707 // MacOSX creates and populates platform-specific select drop-down menus | 715 // MacOSX creates and populates platform-specific select drop-down menus |
708 // whereas other platforms merely create a popup window that the guest | 716 // whereas other platforms merely create a popup window that the guest |
709 // renderer process paints inside. | 717 // renderer process paints inside. |
710 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 718 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
711 #endif | 719 #endif |
712 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 720 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
713 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 721 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
714 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 722 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
715 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | 723 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) |
716 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) | |
717 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 724 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
718 IPC_MESSAGE_UNHANDLED(handled = false) | 725 IPC_MESSAGE_UNHANDLED(handled = false) |
719 IPC_END_MESSAGE_MAP() | 726 IPC_END_MESSAGE_MAP() |
720 return handled; | 727 return handled; |
721 } | 728 } |
722 | 729 |
723 void BrowserPluginGuest::Attach( | 730 void BrowserPluginGuest::Attach( |
724 WebContentsImpl* embedder_web_contents, | 731 WebContentsImpl* embedder_web_contents, |
725 BrowserPluginHostMsg_CreateGuest_Params params) { | 732 BrowserPluginHostMsg_CreateGuest_Params params) { |
726 const std::string target_url = opener()->pending_new_windows_[this]; | 733 const std::string target_url = opener()->pending_new_windows_[this]; |
727 if (!GetWebContents()->opener()) { | 734 if (!GetWebContents()->opener()) { |
728 // For guests that have a suppressed opener, we navigate now. | 735 // For guests that have a suppressed opener, we navigate now. |
729 // Navigation triggers the creation of a RenderWidgetHostViewGuest so | 736 // Navigation triggers the creation of a RenderWidgetHostViewGuest so |
730 // we don't need to create one manually. | 737 // we don't need to create one manually. |
731 params.src = target_url; | 738 params.src = target_url; |
732 } else { | 739 } else { |
733 // Ensure that the newly attached guest gets a RenderWidgetHostViewGuest. | 740 // Ensure that the newly attached guest gets a RenderWidgetHostViewGuest. |
734 WebContentsViewGuest* new_view = | 741 WebContentsViewGuest* new_view = |
735 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 742 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
736 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 743 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
737 } | 744 } |
738 // Once a new guest is attached to the DOM of the embedder page, then the | 745 // Once a new guest is attached to the DOM of the embedder page, then the |
739 // lifetime of the new guest is no longer managed by the opener guest. | 746 // lifetime of the new guest is no longer managed by the opener guest. |
740 opener()->pending_new_windows_.erase(this); | 747 opener()->pending_new_windows_.erase(this); |
741 | 748 |
742 // The guest's frame name takes precedence over the BrowserPlugin's name. | 749 // The guest's frame name takes precedence over the BrowserPlugin's name. |
743 // The guest's frame name is assigned in | 750 // The guest's frame name is assigned in |
744 // BrowserPluginGuest::WebContentsCreated. | 751 // BrowserPluginGuest::WebContentsCreated. |
745 if (!name_.empty()) | 752 if (!GetWebContents()->GetWindowName().empty()) |
746 params.name.clear(); | 753 params.name.clear(); |
747 | 754 |
748 Initialize(embedder_web_contents, params); | 755 Initialize(embedder_web_contents, params); |
749 | 756 |
750 // We initialize the RenderViewHost after a BrowserPlugin has been attached | 757 // We initialize the RenderViewHost after a BrowserPlugin has been attached |
751 // to it and is ready to receive pixels. Until a RenderViewHost is | 758 // to it and is ready to receive pixels. Until a RenderViewHost is |
752 // initialized, it will not allow any resize requests. | 759 // initialized, it will not allow any resize requests. |
753 if (!GetWebContents()->GetRenderViewHost()->IsRenderViewLive()) { | 760 if (!GetWebContents()->GetRenderViewHost()->IsRenderViewLive()) { |
754 static_cast<RenderViewHostImpl*>( | 761 static_cast<RenderViewHostImpl*>( |
755 GetWebContents()->GetRenderViewHost())->Init(); | 762 GetWebContents()->GetRenderViewHost())->Init(); |
756 } | 763 } |
757 | 764 |
758 // Inform the embedder of the guest's information. | 765 // Inform the embedder of the guest's information. |
759 // We pull the partition information from the site's URL, which is of the form | 766 // We pull the partition information from the site's URL, which is of the form |
760 // guest://site/{persist}?{partition_name}. | 767 // guest://site/{persist}?{partition_name}. |
761 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); | 768 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); |
762 BrowserPluginMsg_Attach_ACK_Params ack_params; | 769 BrowserPluginMsg_Attach_ACK_Params ack_params; |
763 ack_params.storage_partition_id = site_url.query(); | 770 ack_params.storage_partition_id = site_url.query(); |
764 ack_params.persist_storage = | 771 ack_params.persist_storage = |
765 site_url.path().find("persist") != std::string::npos; | 772 site_url.path().find("persist") != std::string::npos; |
766 ack_params.name = name_; | 773 ack_params.name = GetWebContents()->GetWindowName(); |
767 SendMessageToEmbedder( | 774 SendMessageToEmbedder( |
768 new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params)); | 775 new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params)); |
769 } | 776 } |
770 | 777 |
771 void BrowserPluginGuest::OnCompositorFrameACK( | 778 void BrowserPluginGuest::OnCompositorFrameACK( |
772 int instance_id, | 779 int instance_id, |
773 int route_id, | 780 int route_id, |
774 int renderer_host_id, | 781 int renderer_host_id, |
775 const cc::CompositorFrameAck& ack) { | 782 const cc::CompositorFrameAck& ack) { |
776 RenderWidgetHostImpl::SendSwapCompositorFrameAck(route_id, | 783 RenderWidgetHostImpl::SendSwapCompositorFrameAck(route_id, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 } | 955 } |
949 | 956 |
950 void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { | 957 void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { |
951 if (focused_ == focused) | 958 if (focused_ == focused) |
952 return; | 959 return; |
953 focused_ = focused; | 960 focused_ = focused; |
954 Send(new ViewMsg_SetFocus(routing_id(), focused)); | 961 Send(new ViewMsg_SetFocus(routing_id(), focused)); |
955 } | 962 } |
956 | 963 |
957 void BrowserPluginGuest::OnSetName(int instance_id, const std::string& name) { | 964 void BrowserPluginGuest::OnSetName(int instance_id, const std::string& name) { |
958 if (name == name_) | 965 GetWebContents()->SetWindowName(name); |
Charlie Reis
2013/04/18 21:26:51
Again, why is this needed? If we change the name
| |
959 return; | |
960 name_ = name; | |
961 Send(new ViewMsg_SetName(routing_id(), name)); | |
962 } | 966 } |
963 | 967 |
964 void BrowserPluginGuest::OnSetSize( | 968 void BrowserPluginGuest::OnSetSize( |
965 int instance_id, | 969 int instance_id, |
966 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, | 970 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, |
967 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { | 971 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { |
968 bool old_auto_size_enabled = auto_size_enabled_; | 972 bool old_auto_size_enabled = auto_size_enabled_; |
969 gfx::Size old_max_size = max_auto_size_; | 973 gfx::Size old_max_size = max_auto_size_; |
970 gfx::Size old_min_size = min_auto_size_; | 974 gfx::Size old_min_size = min_auto_size_; |
971 auto_size_enabled_ = auto_size_params.enable; | 975 auto_size_enabled_ = auto_size_params.enable; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 RenderViewHostImpl* embedder_render_view_host = | 1120 RenderViewHostImpl* embedder_render_view_host = |
1117 static_cast<RenderViewHostImpl*>( | 1121 static_cast<RenderViewHostImpl*>( |
1118 embedder_web_contents_->GetRenderViewHost()); | 1122 embedder_web_contents_->GetRenderViewHost()); |
1119 CHECK(embedder_render_view_host); | 1123 CHECK(embedder_render_view_host); |
1120 RenderViewHostDelegateView* view = | 1124 RenderViewHostDelegateView* view = |
1121 embedder_render_view_host->GetDelegate()->GetDelegateView(); | 1125 embedder_render_view_host->GetDelegate()->GetDelegateView(); |
1122 if (view) | 1126 if (view) |
1123 view->UpdateDragCursor(operation); | 1127 view->UpdateDragCursor(operation); |
1124 } | 1128 } |
1125 | 1129 |
1126 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, | |
1127 bool is_top_level, | |
1128 const std::string& name) { | |
1129 if (!is_top_level) | |
1130 return; | |
1131 | |
1132 name_ = name; | |
1133 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName(instance_id_, name)); | |
1134 } | |
1135 | |
1136 void BrowserPluginGuest::RequestMediaAccessPermission( | 1130 void BrowserPluginGuest::RequestMediaAccessPermission( |
1137 WebContents* web_contents, | 1131 WebContents* web_contents, |
1138 const MediaStreamRequest& request, | 1132 const MediaStreamRequest& request, |
1139 const MediaResponseCallback& callback) { | 1133 const MediaResponseCallback& callback) { |
1140 if (media_requests_map_.size() >= kNumMaxOutstandingPermissionRequests) { | 1134 if (media_requests_map_.size() >= kNumMaxOutstandingPermissionRequests) { |
1141 // Deny the media request. | 1135 // Deny the media request. |
1142 callback.Run(MediaStreamDevices()); | 1136 callback.Run(MediaStreamDevices()); |
1143 return; | 1137 return; |
1144 } | 1138 } |
1145 int request_id = next_permission_request_id_++; | 1139 int request_id = next_permission_request_id_++; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1320 base::Value::CreateStringValue(request_method)); | 1314 base::Value::CreateStringValue(request_method)); |
1321 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1315 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
1322 | 1316 |
1323 SendMessageToEmbedder( | 1317 SendMessageToEmbedder( |
1324 new BrowserPluginMsg_RequestPermission(instance_id(), | 1318 new BrowserPluginMsg_RequestPermission(instance_id(), |
1325 BrowserPluginPermissionTypeDownload, permission_request_id, | 1319 BrowserPluginPermissionTypeDownload, permission_request_id, |
1326 request_info)); | 1320 request_info)); |
1327 } | 1321 } |
1328 | 1322 |
1329 } // namespace content | 1323 } // namespace content |
OLD | NEW |