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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_host.cc

Issue 10735010: 3D Compositing in <browser>, first draft. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Major changes to clean up deadlock & other issues Created 8 years, 4 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 (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 "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "content/browser/browser_plugin/browser_plugin_host_helper.h" 8 #include "content/browser/browser_plugin/browser_plugin_host_helper.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
(...skipping 24 matching lines...) Expand all
35 damage_buffer_(NULL), 35 damage_buffer_(NULL),
36 pending_update_counter_(0) { 36 pending_update_counter_(0) {
37 // Listen to visibility changes so that an embedder hides its guests 37 // Listen to visibility changes so that an embedder hides its guests
38 // as well. 38 // as well.
39 registrar_.Add(this, 39 registrar_.Add(this,
40 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, 40 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
41 Source<WebContents>(web_contents)); 41 Source<WebContents>(web_contents));
42 // Construct plumbing helpers when a new RenderViewHost is created for 42 // Construct plumbing helpers when a new RenderViewHost is created for
43 // this BrowserPluginHost's WebContentsImpl. 43 // this BrowserPluginHost's WebContentsImpl.
44 registrar_.Add(this, 44 registrar_.Add(this,
45 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, 45 NOTIFICATION_WILL_CREATE_RENDER_VIEW,
46 Source<WebContents>(web_contents)); 46 Source<WebContents>(web_contents));
47 } 47 }
48 48
49 BrowserPluginHost::~BrowserPluginHost() { 49 BrowserPluginHost::~BrowserPluginHost() {
50 if (damage_buffer_) 50 if (damage_buffer_)
51 delete damage_buffer_; 51 delete damage_buffer_;
52 } 52 }
53 53
54 BrowserPluginHost* BrowserPluginHost::GetGuestByInstanceID( 54 BrowserPluginHost* BrowserPluginHost::GetGuestByInstanceID(
55 int container_id) const { 55 int container_id) const {
56 ContainerInstanceMap::const_iterator it = 56 ContainerInstanceMap::const_iterator it =
57 guests_by_instance_id_.find(container_id); 57 guests_by_instance_id_.find(container_id);
58 if (it != guests_by_instance_id_.end()) 58 if (it != guests_by_instance_id_.end())
59 return it->second; 59 return it->second;
60 return NULL; 60 return NULL;
61 } 61 }
62 62
63 void BrowserPluginHost::AddGuest(int instance_id, 63 void BrowserPluginHost::AddGuest(int instance_id,
64 BrowserPluginHost* guest, 64 BrowserPluginHost* guest,
65 int64 frame_id) { 65 int64 frame_id) {
66 DCHECK(guests_by_instance_id_.find(instance_id) == 66 DCHECK(guests_by_instance_id_.find(instance_id) ==
67 guests_by_instance_id_.end()); 67 guests_by_instance_id_.end());
68 guests_by_instance_id_[instance_id] = guest; 68 guests_by_instance_id_[instance_id] = guest;
69 guests_[guest->web_contents()] = frame_id; 69 guests_[guest->web_contents()] = frame_id;
70 } 70 }
71 71
72 bool BrowserPluginHost::TakeFocus(bool reverse) { 72 bool BrowserPluginHost::TakeFocus(WebContents* source, bool reverse) {
73 embedder_render_process_host()->Send( 73 embedder_render_process_host()->Send(
74 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); 74 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse));
75 return true; 75 return true;
76 } 76 }
77 77
78 void BrowserPluginHost::RendererUnresponsive(WebContents* source) { 78 void BrowserPluginHost::RendererUnresponsive(WebContents* source) {
79 base::ProcessHandle process_handle = 79 base::ProcessHandle process_handle =
80 web_contents()->GetRenderProcessHost()->GetHandle(); 80 web_contents()->GetRenderProcessHost()->GetHandle();
81 base::KillProcess(process_handle, RESULT_CODE_HUNG, false); 81 base::KillProcess(process_handle, RESULT_CODE_HUNG, false);
82 } 82 }
83 83
84 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) { 84 bool BrowserPluginHost::OnMessageReceived(const IPC::Message& message) {
85 return false; 85 return false;
86 } 86 }
87 87
88 void BrowserPluginHost::NavigateOrCreateGuest( 88 void BrowserPluginHost::NavigateOrCreateGuest(
89 RenderViewHost* render_view_host, 89 RenderViewHost* render_view_host,
90 int instance_id, 90 int instance_id,
91 long long frame_id, 91 long long frame_id,
92 const std::string& src) { 92 const std::string& src,
93 const BrowserPluginHostMsg_Surface_Params& params) {
93 BrowserPluginHost* guest = 94 BrowserPluginHost* guest =
94 GetGuestByInstanceID(instance_id); 95 GetGuestByInstanceID(instance_id);
95 WebContentsImpl* guest_web_contents = 96 WebContentsImpl* guest_web_contents =
96 guest ? 97 guest ?
97 static_cast<WebContentsImpl*>(guest->web_contents()): NULL; 98 static_cast<WebContentsImpl*>(guest->web_contents()): NULL;
99 surface_params_ = params;
98 GURL url(src); 100 GURL url(src);
99 if (!guest) { 101 if (!guest) {
100 std::string host = render_view_host->GetSiteInstance()->GetSite().host(); 102 std::string host = render_view_host->GetSiteInstance()->GetSite().host();
101 GURL guest_url( 103 GURL guest_url(
102 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str())); 104 base::StringPrintf("%s://%s", chrome::kGuestScheme, host.c_str()));
103 // The SiteInstance of a given guest is based on the fact that it's a guest 105 // The SiteInstance of a given guest is based on the fact that it's a guest
104 // in addition to which platform application the guest belongs to, rather 106 // in addition to which platform application the guest belongs to, rather
105 // than the URL that the guest is being navigated to. 107 // than the URL that the guest is being navigated to.
106 SiteInstance* guest_site_instance = 108 SiteInstance* guest_site_instance =
107 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(), 109 SiteInstance::CreateForURL(web_contents()->GetBrowserContext(),
108 guest_url); 110 guest_url);
109 guest_web_contents = 111 guest_web_contents =
110 static_cast<WebContentsImpl*>( 112 static_cast<WebContentsImpl*>(
111 WebContents::Create( 113 WebContents::Create(
112 web_contents()->GetBrowserContext(), 114 web_contents()->GetBrowserContext(),
113 guest_site_instance, 115 guest_site_instance,
114 MSG_ROUTING_NONE, 116 MSG_ROUTING_NONE,
115 NULL, // base WebContents 117 NULL, // base WebContents
116 NULL // session storage namespace 118 NULL // session storage namespace
117 )); 119 ));
118 guest = guest_web_contents->browser_plugin_host(); 120 guest = guest_web_contents->browser_plugin_host();
121 guest->set_surface_params(params);
119 guest->set_embedder_render_process_host( 122 guest->set_embedder_render_process_host(
120 render_view_host->GetProcess()); 123 render_view_host->GetProcess());
121 guest->set_instance_id(instance_id); 124 guest->set_instance_id(instance_id);
122 guest_web_contents->GetMutableRendererPrefs()-> 125 guest_web_contents->GetMutableRendererPrefs()->
123 throttle_input_events = false; 126 throttle_input_events = false;
124 AddGuest(instance_id, guest, frame_id); 127 AddGuest(instance_id, guest, frame_id);
125 } 128 }
126 guest->web_contents()->SetDelegate(guest); 129 guest->web_contents()->SetDelegate(guest);
127 guest->web_contents()->GetController().LoadURL( 130 guest->web_contents()->GetController().LoadURL(
128 url, 131 url,
(...skipping 21 matching lines...) Expand all
150 WebContentsImpl* guest_web_contents = 153 WebContentsImpl* guest_web_contents =
151 guest ? static_cast<WebContentsImpl*>(guest->web_contents()): NULL; 154 guest ? static_cast<WebContentsImpl*>(guest->web_contents()): NULL;
152 guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor); 155 guest->SetDamageBuffer(damage_buffer, gfx::Size(width, height), scale_factor);
153 if (!resize_pending) 156 if (!resize_pending)
154 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height)); 157 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height));
155 } 158 }
156 159
157 void BrowserPluginHost::UpdateRect( 160 void BrowserPluginHost::UpdateRect(
158 RenderViewHost* render_view_host, 161 RenderViewHost* render_view_host,
159 const ViewHostMsg_UpdateRect_Params& params) { 162 const ViewHostMsg_UpdateRect_Params& params) {
160 // This handler is only of interest to us for the 2D software rendering path.
161 // needs_ack should always be true for the 2D path.
162 // TODO(fsamuel): Do we need to do something different in the 3D case?
163 if (!params.needs_ack)
164 return;
165
166 // Only copy damage if the guest's view size is equal to the damage buffer's 163 // Only copy damage if the guest's view size is equal to the damage buffer's
167 // size and the guest's scale factor is equal to the damage buffer's scale 164 // size and the guest's scale factor is equal to the damage buffer's scale
168 // factor. 165 // factor.
169 if (params.view_size.width() == damage_buffer_size().width() && 166 if (params.view_size.width() == damage_buffer_size().width() &&
170 params.view_size.height() == damage_buffer_size().height() && 167 params.view_size.height() == damage_buffer_size().height() &&
171 params.scale_factor == damage_buffer_scale_factor()) { 168 params.scale_factor == damage_buffer_scale_factor()) {
172 TransportDIB* dib = render_view_host->GetProcess()-> 169 TransportDIB* dib = render_view_host->GetProcess()->
173 GetTransportDIB(params.bitmap); 170 GetTransportDIB(params.bitmap);
174 if (dib) { 171 if (dib) {
175 void* guest_memory = dib->memory(); 172 void* guest_memory = dib->memory();
176 void* embedder_memory = damage_buffer_->memory(); 173 void* embedder_memory = damage_buffer_->memory();
177 int size = std::min(dib->size(), damage_buffer_->size()); 174 int size = std::min(dib->size(), damage_buffer_->size());
178 memcpy(embedder_memory, guest_memory, size); 175 memcpy(embedder_memory, guest_memory, size);
179 } 176 }
180 } 177 }
181 DCHECK(embedder_render_process_host()); 178 DCHECK(embedder_render_process_host());
182 BrowserPluginMsg_UpdateRect_Params relay_params; 179 BrowserPluginMsg_UpdateRect_Params relay_params;
183 relay_params.bitmap_rect = params.bitmap_rect; 180 relay_params.bitmap_rect = params.bitmap_rect;
184 relay_params.dx = params.dx; 181 relay_params.dx = params.dx;
185 relay_params.dy = params.dy; 182 relay_params.dy = params.dy;
186 relay_params.scroll_rect = params.scroll_rect; 183 relay_params.scroll_rect = params.scroll_rect;
187 relay_params.copy_rects = params.copy_rects; 184 relay_params.copy_rects = params.copy_rects;
188 relay_params.view_size = params.view_size; 185 relay_params.view_size = params.view_size;
189 relay_params.scale_factor = params.scale_factor; 186 relay_params.scale_factor = params.scale_factor;
190 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( 187 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
191 params.flags); 188 params.flags);
189 relay_params.needs_ack = params.needs_ack;
192 190
193 // We need to send the ACK to the same render_view_host that issued 191 // We need to send the ACK to the same render_view_host that issued
194 // the UpdateRect. We keep track of this correspondence via a message_id. 192 // the UpdateRect. We keep track of this correspondence via a message_id.
195 int message_id = pending_update_counter_++; 193 int message_id = pending_update_counter_++;
196 pending_updates_.AddWithID(render_view_host, message_id); 194 pending_updates_.AddWithID(render_view_host, message_id);
197 195
198 embedder_render_process_host()->Send( 196 embedder_render_process_host()->Send(
199 new BrowserPluginMsg_UpdateRect(instance_id(), 197 new BrowserPluginMsg_UpdateRect(instance_id(),
200 message_id, 198 message_id,
201 relay_params)); 199 relay_params));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void BrowserPluginHost::HandleInputEventAck(RenderViewHost* render_view_host, 249 void BrowserPluginHost::HandleInputEventAck(RenderViewHost* render_view_host,
252 bool handled) { 250 bool handled) {
253 DCHECK(pending_input_event_reply_.get()); 251 DCHECK(pending_input_event_reply_.get());
254 IPC::Message* reply_message = pending_input_event_reply_.release(); 252 IPC::Message* reply_message = pending_input_event_reply_.release();
255 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, 253 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message,
256 handled, 254 handled,
257 cursor_); 255 cursor_);
258 embedder_render_process_host()->Send(reply_message); 256 embedder_render_process_host()->Send(reply_message);
259 RenderViewHostImpl* guest_rvh = 257 RenderViewHostImpl* guest_rvh =
260 static_cast<RenderViewHostImpl*>(render_view_host); 258 static_cast<RenderViewHostImpl*>(render_view_host);
261 if (guest_rvh->decrement_in_flight_event_count() == 0) 259 if (guest_rvh->decrement_in_flight_event_count() == 0) {
scshunt 2012/08/12 01:42:45 Unnecessary.
scshunt 2012/08/17 17:30:28 Done.
262 guest_rvh->StopHangMonitorTimeout(); 260 guest_rvh->StopHangMonitorTimeout();
261 }
263 } 262 }
264 263
265 void BrowserPluginHost::SetFocus(bool focused) { 264 void BrowserPluginHost::SetFocus(bool focused) {
266 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); 265 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost();
267 render_view_host->Send( 266 render_view_host->Send(
268 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused)); 267 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused));
269 } 268 }
270 269
270 void BrowserPluginHost::SendBuffersSwappedToEmbedder(
271 uint64 surface_handle,
272 const BrowserPlugin_SwapInfo& info) {
273 DCHECK(embedder_render_process_host());
274 embedder_render_process_host()->Send(
275 new BrowserPluginMsg_BuffersSwapped(instance_id_, surface_handle, info));
276 }
277
278 void BrowserPluginHost::SendSurfaceResizeToEmbedder(const gfx::Size& size) {
279 DCHECK(embedder_render_process_host());
280 embedder_render_process_host()->Send(
281 new BrowserPluginMsg_SurfaceResize(instance_id_, size));
282 }
283
271 void BrowserPluginHost::ShowWidget(RenderViewHost* render_view_host, 284 void BrowserPluginHost::ShowWidget(RenderViewHost* render_view_host,
272 int route_id, 285 int route_id,
273 const gfx::Rect& initial_pos) { 286 const gfx::Rect& initial_pos) {
274 RenderWidgetHostView* popup_rwhv = 287 RenderWidgetHostView* popup_rwhv =
275 static_cast<WebContentsImpl*>(web_contents())-> 288 static_cast<WebContentsImpl*>(web_contents())->
276 GetCreatedWidget(route_id); 289 GetCreatedWidget(route_id);
277 290
278 RenderWidgetHostViewPort* widget_host_view = 291 RenderWidgetHostViewPort* widget_host_view =
279 RenderWidgetHostViewPort::FromRWHV(popup_rwhv); 292 RenderWidgetHostViewPort::FromRWHV(popup_rwhv);
280 if (!widget_host_view) 293 if (!widget_host_view)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 iter.Advance(); 384 iter.Advance();
372 } 385 }
373 } 386 }
374 } 387 }
375 388
376 void BrowserPluginHost::Observe( 389 void BrowserPluginHost::Observe(
377 int type, 390 int type,
378 const NotificationSource& source, 391 const NotificationSource& source,
379 const NotificationDetails& details) { 392 const NotificationDetails& details) {
380 switch (type) { 393 switch (type) {
381 case NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: { 394 case NOTIFICATION_WILL_CREATE_RENDER_VIEW: {
382 RenderViewHost* render_view_host = 395 RenderViewHost* render_view_host =
383 Details<RenderViewHost>(details).ptr(); 396 Details<RenderViewHost>(details).ptr();
384 // BrowserPluginHostHelper is destroyed when its associated RenderViewHost 397 // BrowserPluginHostHelper is destroyed when its associated RenderViewHost
385 // is destroyed. 398 // is destroyed.
386 new BrowserPluginHostHelper(this, render_view_host); 399 new BrowserPluginHostHelper(this, render_view_host, surface_params_);
387 break; 400 break;
388 } 401 }
389 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { 402 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
390 bool visible = *Details<bool>(details).ptr(); 403 bool visible = *Details<bool>(details).ptr();
391 // If the embedder is hidden we need to hide the guests as well. 404 // If the embedder is hidden we need to hide the guests as well.
392 for (GuestMap::const_iterator it = guests_.begin(); 405 for (GuestMap::const_iterator it = guests_.begin();
393 it != guests_.end(); ++it) { 406 it != guests_.end(); ++it) {
394 WebContents* web_contents = it->first; 407 WebContents* web_contents = it->first;
395 if (visible) 408 if (visible)
396 web_contents->WasShown(); 409 web_contents->WasShown();
397 else 410 else
398 web_contents->WasHidden(); 411 web_contents->WasHidden();
399 } 412 }
400 break; 413 break;
401 } 414 }
402 default: 415 default:
403 NOTREACHED() << "Unexpected notification type: " << type; 416 NOTREACHED() << "Unexpected notification type: " << type;
404 } 417 }
405 } 418 }
406 419
407 } // namespace content 420 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698