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_host.h" | 5 #include "content/browser/browser_plugin/browser_plugin_host.h" |
6 | 6 |
7 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" | 7 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
11 #include "content/public/browser/notification_details.h" | 11 #include "content/public/browser/notification_details.h" |
12 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
13 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
16 #include "content/public/browser/site_instance.h" | 16 #include "content/public/browser/site_instance.h" |
17 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
18 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 BrowserPluginHost::BrowserPluginHost( | 22 BrowserPluginHost::BrowserPluginHost( |
23 WebContentsImpl* web_contents) | 23 WebContentsImpl* web_contents) |
24 : WebContentsObserver(web_contents), | 24 : WebContentsObserver(web_contents), |
25 embedder_render_process_host_(NULL), | 25 embedder_render_process_host_(NULL), |
26 instance_id_(0), | 26 instance_id_(0) { |
27 pending_render_view_host_(NULL) { | |
28 // Listen to visibility changes so that an embedder hides its guests | 27 // Listen to visibility changes so that an embedder hides its guests |
29 // as well. | 28 // as well. |
30 registrar_.Add(this, | 29 registrar_.Add(this, |
31 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 30 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
32 Source<WebContents>(web_contents)); | 31 Source<WebContents>(web_contents)); |
33 // Construct plumbing helpers when a new RenderViewHost is created for | 32 // Construct plumbing helpers when a new RenderViewHost is created for |
34 // this BrowserPluginHost's WebContentsImpl. | 33 // this BrowserPluginHost's WebContentsImpl. |
35 registrar_.Add(this, | 34 registrar_.Add(this, |
36 NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 35 NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
37 Source<WebContents>(web_contents)); | 36 Source<WebContents>(web_contents)); |
(...skipping 11 matching lines...) Expand all Loading... |
49 } | 48 } |
50 | 49 |
51 void BrowserPluginHost::RegisterContainerInstance( | 50 void BrowserPluginHost::RegisterContainerInstance( |
52 int container_id, | 51 int container_id, |
53 BrowserPluginHost* observer) { | 52 BrowserPluginHost* observer) { |
54 DCHECK(guests_by_container_id_.find(container_id) == | 53 DCHECK(guests_by_container_id_.find(container_id) == |
55 guests_by_container_id_.end()); | 54 guests_by_container_id_.end()); |
56 guests_by_container_id_[container_id] = observer; | 55 guests_by_container_id_[container_id] = observer; |
57 } | 56 } |
58 | 57 |
59 void BrowserPluginHost::OnPendingNavigation(RenderViewHost* dest_rvh) { | |
60 if (web_contents()->GetRenderViewHost() != dest_rvh) { | |
61 pending_render_view_host_ = dest_rvh; | |
62 } | |
63 } | |
64 | |
65 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { | 58 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { |
66 bool handled = true; | 59 bool handled = true; |
67 IPC_BEGIN_MESSAGE_MAP(BrowserPluginHost, message) | 60 IPC_BEGIN_MESSAGE_MAP(BrowserPluginHost, message) |
68 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateFromGuest, | 61 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateFromGuest, |
69 OnNavigateFromGuest) | 62 OnNavigateFromGuest) |
70 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_MapInstance, | |
71 OnMapInstance) | |
72 IPC_MESSAGE_UNHANDLED(handled = false) | 63 IPC_MESSAGE_UNHANDLED(handled = false) |
73 IPC_END_MESSAGE_MAP() | 64 IPC_END_MESSAGE_MAP() |
74 return handled; | 65 return handled; |
75 } | 66 } |
76 | 67 |
77 void BrowserPluginHost::NavigateGuestFromEmbedder( | 68 void BrowserPluginHost::NavigateGuestFromEmbedder( |
78 RenderViewHost* render_view_host, | 69 RenderViewHost* render_view_host, |
79 int container_instance_id, | 70 int container_instance_id, |
80 long long frame_id, | 71 long long frame_id, |
81 const std::string& src, | 72 const std::string& src) { |
82 const gfx::Size& size) { | |
83 BrowserPluginHost* guest_observer = | 73 BrowserPluginHost* guest_observer = |
84 GetGuestByContainerID(container_instance_id); | 74 GetGuestByContainerID(container_instance_id); |
85 WebContentsImpl* guest_web_contents = | 75 WebContentsImpl* guest_web_contents = |
86 guest_observer ? | 76 guest_observer ? |
87 static_cast<WebContentsImpl*>(guest_observer->web_contents()): NULL; | 77 static_cast<WebContentsImpl*>(guest_observer->web_contents()): NULL; |
88 if (!guest_observer) { | 78 if (!guest_observer) { |
89 guest_web_contents = | 79 guest_web_contents = |
90 static_cast<WebContentsImpl*>( | 80 static_cast<WebContentsImpl*>( |
91 WebContents::Create( | 81 WebContents::Create( |
92 web_contents()->GetBrowserContext(), | 82 web_contents()->GetBrowserContext(), |
93 render_view_host->GetSiteInstance(), | 83 render_view_host->GetSiteInstance(), |
94 MSG_ROUTING_NONE, | 84 MSG_ROUTING_NONE, |
95 NULL, // base WebContents | 85 NULL, // base WebContents |
96 NULL // session storage namespace | 86 NULL // session storage namespace |
97 )); | 87 )); |
98 guest_observer = | 88 guest_observer = |
99 guest_web_contents->browser_plugin_host(); | 89 guest_web_contents->browser_plugin_host(); |
100 guest_observer->set_embedder_render_process_host( | 90 guest_observer->set_embedder_render_process_host( |
101 render_view_host->GetProcess()); | 91 render_view_host->GetProcess()); |
102 guest_observer->set_instance_id(container_instance_id); | 92 guest_observer->set_instance_id(container_instance_id); |
103 guest_observer->set_initial_size(size); | |
104 RegisterContainerInstance(container_instance_id, guest_observer); | 93 RegisterContainerInstance(container_instance_id, guest_observer); |
105 AddGuest(guest_web_contents, frame_id); | 94 AddGuest(guest_web_contents, frame_id); |
106 } | 95 } |
107 | |
108 GURL url(src); | 96 GURL url(src); |
109 guest_observer->web_contents()->SetDelegate(guest_observer); | 97 guest_observer->web_contents()->SetDelegate(guest_observer); |
110 guest_observer->web_contents()->GetController().LoadURL( | 98 guest_observer->web_contents()->GetController().LoadURL( |
111 url, | 99 url, |
112 Referrer(), | 100 Referrer(), |
113 PAGE_TRANSITION_AUTO_SUBFRAME, | 101 PAGE_TRANSITION_AUTO_SUBFRAME, |
114 std::string()); | 102 std::string()); |
115 } | 103 } |
116 | 104 |
117 void BrowserPluginHost::OnNavigateFromGuest( | 105 void BrowserPluginHost::OnNavigateFromGuest( |
118 PP_Instance instance, | 106 PP_Instance instance, |
119 const std::string& src) { | 107 const std::string& src) { |
120 DCHECK(embedder_render_process_host()); | 108 DCHECK(embedder_render_process_host()); |
121 GURL url(src); | 109 GURL url(src); |
122 web_contents()->GetController().LoadURL( | 110 web_contents()->GetController().LoadURL( |
123 url, | 111 url, |
124 Referrer(), | 112 Referrer(), |
125 PAGE_TRANSITION_AUTO_SUBFRAME, | 113 PAGE_TRANSITION_AUTO_SUBFRAME, |
126 std::string()); | 114 std::string()); |
127 } | 115 } |
128 | 116 |
129 // TODO(fsamuel): This handler is all kinds of bad and could be racy. | |
130 // Between the time we set the pending_render_view_host and use it here, | |
131 // the pending_render_view_host may no longer be valid and this message | |
132 // may not go to the right place. | |
133 // See https://code.google.com/p/chromium/issues/detail?id=128976. | |
134 // The correct solution is probably to send | |
135 // "BrowserPluginMsg_CompleteNavigation" over the pepper channel to the guest | |
136 // and then have the guest send the browser "BrowserPluginHostMsg_ResizeGuest" | |
137 // to resize appropriately. | |
138 void BrowserPluginHost::OnMapInstance(int container_instance_id, | |
139 PP_Instance instance) { | |
140 BrowserPluginHost* guest_observer = | |
141 GetGuestByContainerID(container_instance_id); | |
142 WebContentsImpl* guest_web_contents = | |
143 static_cast<WebContentsImpl*>(guest_observer->web_contents()); | |
144 RenderViewHost* rvh = guest_observer->pending_render_view_host() ? | |
145 guest_observer->pending_render_view_host() : | |
146 guest_web_contents->GetRenderViewHost(); | |
147 | |
148 guest_web_contents->GetView()->SizeContents(guest_observer->initial_size()); | |
149 | |
150 rvh->Send(new BrowserPluginMsg_CompleteNavigation( | |
151 rvh->GetRoutingID(), | |
152 instance)); | |
153 } | |
154 | |
155 void BrowserPluginHost::ConnectEmbedderToChannel( | 117 void BrowserPluginHost::ConnectEmbedderToChannel( |
156 RenderViewHost* render_view_host, | 118 RenderViewHost* render_view_host, |
157 const IPC::ChannelHandle& channel_handle) { | 119 const IPC::ChannelHandle& channel_handle) { |
158 DCHECK(embedder_render_process_host()); | 120 DCHECK(embedder_render_process_host()); |
159 // Tell the BrowserPlugin in the embedder that we're done and that it can | 121 // Tell the BrowserPlugin in the embedder that we're done and that it can |
160 // begin using the guest renderer. | 122 // begin using the guest renderer. |
161 embedder_render_process_host()->Send( | 123 embedder_render_process_host()->Send( |
162 new BrowserPluginMsg_LoadGuest( | 124 new BrowserPluginMsg_LoadGuest( |
163 instance_id(), | 125 instance_id(), |
164 render_view_host->GetProcess()-> | 126 render_view_host->GetProcess()-> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 web_contents->HideContents(); | 212 web_contents->HideContents(); |
251 } | 213 } |
252 break; | 214 break; |
253 } | 215 } |
254 default: | 216 default: |
255 NOTREACHED() << "Unexpected notification type: " << type; | 217 NOTREACHED() << "Unexpected notification type: " << type; |
256 } | 218 } |
257 } | 219 } |
258 | 220 |
259 } // namespace content | 221 } // namespace content |
OLD | NEW |