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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 10965048: [BrowserTag] Send dib info with NavigateGuest message, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix OSX (this CL exposes this): manage transport dibs on mac ourselves, instead of letting browser … Created 8 years, 2 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 | Annotate | Revision Log
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/renderer/browser_plugin/browser_plugin.h" 5 #include "content/renderer/browser_plugin/browser_plugin.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #if defined (OS_WIN) 9 #if defined (OS_WIN)
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
11 #endif 11 #endif
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "content/common/browser_plugin_messages.h" 13 #include "content/common/browser_plugin_messages.h"
14 #include "content/common/view_messages.h"
14 #include "content/public/common/content_client.h" 15 #include "content/public/common/content_client.h"
15 #include "content/public/renderer/content_renderer_client.h" 16 #include "content/public/renderer/content_renderer_client.h"
16 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" 17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
17 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 18 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
18 #include "content/renderer/render_process_impl.h" 19 #include "content/renderer/render_process_impl.h"
19 #include "content/renderer/render_thread_impl.h" 20 #include "content/renderer/render_thread_impl.h"
20 #include "skia/ext/platform_canvas.h" 21 #include "skia/ext/platform_canvas.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 navigate_src_sent_(false), 65 navigate_src_sent_(false),
65 process_id_(-1), 66 process_id_(-1),
66 persist_storage_(false) { 67 persist_storage_(false) {
67 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); 68 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
68 bindings_.reset(new BrowserPluginBindings(this)); 69 bindings_.reset(new BrowserPluginBindings(this));
69 70
70 ParseAttributes(params); 71 ParseAttributes(params);
71 } 72 }
72 73
73 BrowserPlugin::~BrowserPlugin() { 74 BrowserPlugin::~BrowserPlugin() {
74 if (damage_buffer_) { 75 FreeDamageBuffer();
75 RenderProcess::current()->FreeTransportDIB(damage_buffer_);
76 damage_buffer_ = NULL;
77 }
78 RemoveEventListeners(); 76 RemoveEventListeners();
79 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); 77 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_);
80 BrowserPluginManager::Get()->Send( 78 BrowserPluginManager::Get()->Send(
81 new BrowserPluginHostMsg_PluginDestroyed( 79 new BrowserPluginHostMsg_PluginDestroyed(
82 render_view_->GetRoutingID(), 80 render_view_->GetRoutingID(),
83 instance_id_)); 81 instance_id_));
84 } 82 }
85 83
86 void BrowserPlugin::Cleanup() { 84 void BrowserPlugin::Cleanup() {
87 if (damage_buffer_) { 85 FreeDamageBuffer();
88 RenderProcess::current()->FreeTransportDIB(damage_buffer_);
89 damage_buffer_ = NULL;
90 }
91 } 86 }
92 87
93 std::string BrowserPlugin::GetSrcAttribute() const { 88 std::string BrowserPlugin::GetSrcAttribute() const {
94 return src_; 89 return src_;
95 } 90 }
96 91
97 void BrowserPlugin::SetSrcAttribute(const std::string& src) { 92 void BrowserPlugin::SetSrcAttribute(const std::string& src) {
98 if (src == src_ && !guest_crashed_) 93 if (src == src_ && !guest_crashed_)
99 return; 94 return;
100 if (!src.empty() || navigate_src_sent_) { 95 if (!src.empty() || navigate_src_sent_) {
96 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params(
97 GetPendingResizeParams());
98 DCHECK(!params->resize_pending);
101 BrowserPluginManager::Get()->Send( 99 BrowserPluginManager::Get()->Send(
102 new BrowserPluginHostMsg_NavigateGuest( 100 new BrowserPluginHostMsg_NavigateGuest(
103 render_view_->GetRoutingID(), 101 render_view_->GetRoutingID(),
104 instance_id_, 102 instance_id_,
105 src, 103 src,
106 gfx::Size(width(), height()))); 104 *params));
107 // Record that we sent a NavigateGuest message to embedder. Once we send 105 // Record that we sent a NavigateGuest message to embedder. Once we send
108 // such a message, subsequent SetSrcAttribute() calls must always send 106 // such a message, subsequent SetSrcAttribute() calls must always send
109 // NavigateGuest messages to the embedder (even if |src| is empty), so 107 // NavigateGuest messages to the embedder (even if |src| is empty), so
110 // resize works correctly for all cases (e.g. The embedder can reset the 108 // resize works correctly for all cases (e.g. The embedder can reset the
111 // guest's |src| to empty value, resize and then set the |src| to a 109 // guest's |src| to empty value, resize and then set the |src| to a
112 // non-empty value). 110 // non-empty value).
113 // Additionally, once this instance has navigated, the storage partition 111 // Additionally, once this instance has navigated, the storage partition
114 // cannot be changed, so this value is used for enforcing this. 112 // cannot be changed, so this value is used for enforcing this.
115 navigate_src_sent_ = true; 113 navigate_src_sent_ = true;
116 } 114 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 const WebRect& clip_rect, 403 const WebRect& clip_rect,
406 const WebVector<WebRect>& cut_outs_rects, 404 const WebVector<WebRect>& cut_outs_rects,
407 bool is_visible) { 405 bool is_visible) {
408 int old_width = width(); 406 int old_width = width();
409 int old_height = height(); 407 int old_height = height();
410 plugin_rect_ = window_rect; 408 plugin_rect_ = window_rect;
411 if (old_width == window_rect.width && 409 if (old_width == window_rect.width &&
412 old_height == window_rect.height) { 410 old_height == window_rect.height) {
413 return; 411 return;
414 } 412 }
415 // Until an actual navigation occurs, there is no browser side embedder
416 // present to notify about geometry updates. In this case, after we've updated
417 // the BrowserPlugin's state we are done and can return immediately.
418 if (!navigate_src_sent_)
419 return;
420 413
421 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); 414 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width);
422 // Make sure the size of the damage buffer is at least four bytes so that we 415 // Make sure the size of the damage buffer is at least four bytes so that we
423 // can fit in a magic word to verify that the memory is shared correctly. 416 // can fit in a magic word to verify that the memory is shared correctly.
424 size_t size = 417 size_t size =
425 std::max(sizeof(unsigned int), 418 std::max(sizeof(unsigned int),
426 static_cast<size_t>(window_rect.height * 419 static_cast<size_t>(window_rect.height *
427 stride * 420 stride *
428 GetDeviceScaleFactor() * 421 GetDeviceScaleFactor() *
429 GetDeviceScaleFactor())); 422 GetDeviceScaleFactor()));
430 423
431 // Don't drop the old damage buffer until after we've made sure that the 424 // Don't drop the old damage buffer until after we've made sure that the
432 // browser process has dropped it. 425 // browser process has dropped it.
426 #if defined(OS_MACOSX)
427 TransportDIB::Handle handle;
428 // On OSX we don't let the browser manage the transport dib. We manage the
429 // deletion of the dib in FreeDamageBuffer().
430 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(
431 size,
432 false, // cache in browser.
433 &handle);
433 TransportDIB* new_damage_buffer = NULL; 434 TransportDIB* new_damage_buffer = NULL;
434 #if defined(OS_WIN) 435 if (RenderThreadImpl::current()->Send(msg) && handle.fd >= 0)
435 size_t allocation_granularity = base::SysInfo::VMAllocationGranularity(); 436 new_damage_buffer = TransportDIB::Map(handle);
436 size_t shared_mem_size = size / allocation_granularity + 1;
437 shared_mem_size = shared_mem_size * allocation_granularity;
438
439 base::SharedMemory shared_mem;
440 if (!shared_mem.CreateAnonymous(shared_mem_size))
441 NOTREACHED() << "Unable to create shared memory of size:" << size;
442 new_damage_buffer = TransportDIB::Map(shared_mem.handle());
443 #else 437 #else
444 new_damage_buffer = RenderProcess::current()->CreateTransportDIB(size); 438 TransportDIB* new_damage_buffer =
439 RenderProcess::current()->CreateTransportDIB(size);
445 #endif 440 #endif
446 if (!new_damage_buffer) 441 if (!new_damage_buffer)
447 NOTREACHED() << "Unable to create damage buffer"; 442 NOTREACHED() << "Unable to create damage buffer";
443 #if defined(OS_WIN)
444 // Windows does not map the buffer by default.
445 CHECK(new_damage_buffer->Map());
446 #endif
448 DCHECK(new_damage_buffer->memory()); 447 DCHECK(new_damage_buffer->memory());
449 // Insert the magic word. 448 // Insert the magic word.
450 *static_cast<unsigned int*>(new_damage_buffer->memory()) = 0xdeadbeef; 449 *static_cast<unsigned int*>(new_damage_buffer->memory()) = 0xdeadbeef;
451 450
452 BrowserPluginHostMsg_ResizeGuest_Params params; 451 pending_resize_params_.reset();
453 params.damage_buffer_id = new_damage_buffer->id(); 452
453 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> params(
454 new BrowserPluginHostMsg_ResizeGuest_Params);
455 params->damage_buffer_id = new_damage_buffer->id();
456 #if defined(OS_MACOSX)
457 params->damage_buffer_handle = new_damage_buffer->handle();
458 #endif
454 #if defined(OS_WIN) 459 #if defined(OS_WIN)
455 params.damage_buffer_size = size; 460 params->damage_buffer_size = size;
456 #endif 461 #endif
457 params.width = window_rect.width; 462 params->width = window_rect.width;
458 params.height = window_rect.height; 463 params->height = window_rect.height;
459 params.resize_pending = resize_pending_; 464 params->resize_pending = resize_pending_;
460 params.scale_factor = GetDeviceScaleFactor(); 465 params->scale_factor = GetDeviceScaleFactor();
461 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_ResizeGuest(
462 render_view_->GetRoutingID(),
463 instance_id_,
464 params));
465 resize_pending_ = true;
466 466
467 if (damage_buffer_) { 467 if (navigate_src_sent_) {
468 RenderProcess::current()->FreeTransportDIB(damage_buffer_); 468 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_ResizeGuest(
469 damage_buffer_ = NULL; 469 render_view_->GetRoutingID(),
470 instance_id_,
471 *params));
472 resize_pending_ = true;
473 } else {
474 // Until an actual navigation occurs, there is no browser side embedder
475 // present to notify about geometry updates. In this case, after we've
476 // updated the BrowserPlugin's state we are done and we do not send a resize
477 // message to the browser.
478 pending_resize_params_.reset(params.release());
470 } 479 }
480 FreeDamageBuffer();
471 damage_buffer_ = new_damage_buffer; 481 damage_buffer_ = new_damage_buffer;
472 } 482 }
473 483
484 void BrowserPlugin::FreeDamageBuffer() {
485 if (damage_buffer_) {
486 #if defined(OS_MACOSX)
487 delete damage_buffer_;
Fady Samuel 2012/09/28 18:31:46 Please add a comment explaining why we don't need
lazyboy 2012/09/28 19:05:02 Done.
488 #else
489 RenderProcess::current()->FreeTransportDIB(damage_buffer_);
490 damage_buffer_ = NULL;
491 #endif
492 }
493 }
494
495 BrowserPluginHostMsg_ResizeGuest_Params*
496 BrowserPlugin::GetPendingResizeParams() {
497 if (pending_resize_params_.get()) {
498 resize_pending_ = true;
499 return pending_resize_params_.release();
500 } else {
501 BrowserPluginHostMsg_ResizeGuest_Params* params =
502 new BrowserPluginHostMsg_ResizeGuest_Params;
503
504 // We don't have a pending resize to send, so we send an invalid transport
505 // dib Id.
506 params->damage_buffer_id = TransportDIB::Id();
507 params->width = width();
508 params->height = height();
509 params->resize_pending = false;
510 return params;
511 }
512 }
513
474 void BrowserPlugin::updateFocus(bool focused) { 514 void BrowserPlugin::updateFocus(bool focused) {
475 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( 515 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus(
476 render_view_->GetRoutingID(), 516 render_view_->GetRoutingID(),
477 instance_id_, 517 instance_id_,
478 focused)); 518 focused));
479 } 519 }
480 520
481 void BrowserPlugin::updateVisibility(bool visible) { 521 void BrowserPlugin::updateVisibility(bool visible) {
482 } 522 }
483 523
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 void* notify_data) { 562 void* notify_data) {
523 } 563 }
524 564
525 void BrowserPlugin::didFailLoadingFrameRequest( 565 void BrowserPlugin::didFailLoadingFrameRequest(
526 const WebKit::WebURL& url, 566 const WebKit::WebURL& url,
527 void* notify_data, 567 void* notify_data,
528 const WebKit::WebURLError& error) { 568 const WebKit::WebURLError& error) {
529 } 569 }
530 570
531 } // namespace content 571 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | content/renderer/browser_plugin/browser_plugin_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698