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

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

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: integrate windows fix by Fady (original cl #10910228) Created 8 years, 3 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/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)
10 #include "base/sys_info.h"
11 #endif
9 #include "content/common/browser_plugin_messages.h" 12 #include "content/common/browser_plugin_messages.h"
10 #include "content/public/common/content_client.h" 13 #include "content/public/common/content_client.h"
11 #include "content/public/renderer/content_renderer_client.h" 14 #include "content/public/renderer/content_renderer_client.h"
12 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" 15 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
13 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 16 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
14 #include "content/renderer/render_process_impl.h" 17 #include "content/renderer/render_process_impl.h"
15 #include "content/renderer/render_thread_impl.h" 18 #include "content/renderer/render_thread_impl.h"
16 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
(...skipping 28 matching lines...) Expand all
47 RenderViewImpl* render_view, 50 RenderViewImpl* render_view,
48 WebKit::WebFrame* frame, 51 WebKit::WebFrame* frame,
49 const WebPluginParams& params) 52 const WebPluginParams& params)
50 : instance_id_(instance_id), 53 : instance_id_(instance_id),
51 render_view_(render_view), 54 render_view_(render_view),
52 container_(NULL), 55 container_(NULL),
53 damage_buffer_(NULL), 56 damage_buffer_(NULL),
54 sad_guest_(NULL), 57 sad_guest_(NULL),
55 guest_crashed_(false), 58 guest_crashed_(false),
56 resize_pending_(false), 59 resize_pending_(false),
60 navigate_src_sent_(false),
57 parent_frame_(frame->identifier()) { 61 parent_frame_(frame->identifier()) {
58 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); 62 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
59 bindings_.reset(new BrowserPluginBindings(this)); 63 bindings_.reset(new BrowserPluginBindings(this));
60 64
61 std::string src; 65 std::string src;
62 if (ParseSrcAttribute(params, &src)) 66 if (ParseSrcAttribute(params, &src))
63 SetSrcAttribute(src); 67 SetSrcAttribute(src);
64 } 68 }
65 69
66 BrowserPlugin::~BrowserPlugin() { 70 BrowserPlugin::~BrowserPlugin() {
(...skipping 16 matching lines...) Expand all
83 } 87 }
84 } 88 }
85 89
86 std::string BrowserPlugin::GetSrcAttribute() const { 90 std::string BrowserPlugin::GetSrcAttribute() const {
87 return src_; 91 return src_;
88 } 92 }
89 93
90 void BrowserPlugin::SetSrcAttribute(const std::string& src) { 94 void BrowserPlugin::SetSrcAttribute(const std::string& src) {
91 if (src == src_ && !guest_crashed_) 95 if (src == src_ && !guest_crashed_)
92 return; 96 return;
93 if (!src.empty()) { 97 if (!src.empty() || navigate_src_sent_) {
94 BrowserPluginManager::Get()->Send( 98 BrowserPluginManager::Get()->Send(
95 new BrowserPluginHostMsg_NavigateOrCreateGuest( 99 new BrowserPluginHostMsg_NavigateGuest(
96 render_view_->GetRoutingID(), 100 render_view_->GetRoutingID(),
97 instance_id_, 101 instance_id_,
98 parent_frame_, 102 parent_frame_,
99 src)); 103 src,
104 gfx::Size(width(), height())));
105 // Record that we sent a NavigateGuest message to embedder. Once we send
106 // such a message, subsequent SetSrcAttribute() calls must always send
107 // NavigateGuest messages to the embedder (even if |src| is empty), so
108 // resize works correctly for all cases (e.g. The embedder can reset the
109 // guest's |src| to empty value, resize and then set the |src| to a
110 // non-empty value).
Charlie Reis 2012/09/13 00:51:44 I don't think we can just tell the guest to naviga
lazyboy 2012/09/13 15:56:24 I sent you a proposal for handling empty src in em
111 navigate_src_sent_ = true;
100 } 112 }
101 src_ = src; 113 src_ = src;
102 guest_crashed_ = false; 114 guest_crashed_ = false;
103 } 115 }
104 116
105 bool BrowserPlugin::ParseSrcAttribute( 117 bool BrowserPlugin::ParseSrcAttribute(
106 const WebKit::WebPluginParams& params, 118 const WebKit::WebPluginParams& params,
107 std::string* src) { 119 std::string* src) {
108 // Get the src attribute from the attributes vector 120 // Get the src attribute from the attributes vector
109 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { 121 for (unsigned i = 0; i < params.attributeNames.size(); ++i) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 332
321 void BrowserPlugin::updateGeometry( 333 void BrowserPlugin::updateGeometry(
322 const WebRect& window_rect, 334 const WebRect& window_rect,
323 const WebRect& clip_rect, 335 const WebRect& clip_rect,
324 const WebVector<WebRect>& cut_outs_rects, 336 const WebVector<WebRect>& cut_outs_rects,
325 bool is_visible) { 337 bool is_visible) {
326 int old_width = width(); 338 int old_width = width();
327 int old_height = height(); 339 int old_height = height();
328 plugin_rect_ = window_rect; 340 plugin_rect_ = window_rect;
329 if (old_width == window_rect.width && 341 if (old_width == window_rect.width &&
330 old_height == window_rect.height) 342 old_height == window_rect.height) {
343 return;
344 }
345 // Until an actual navigation occurs, there is no browser side embedder
346 // present to notify about geometry updates. In this case, after we've updated
347 // the BrowserPlugin's state we are done and can return immediately.
348 if (src_.empty() && !navigate_src_sent_)
331 return; 349 return;
332 350
333 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width); 351 const size_t stride = skia::PlatformCanvas::StrideForWidth(window_rect.width);
334 const size_t size = window_rect.height * 352 // Make sure the size of the damage buffer is at least four bytes so that we
335 stride * 353 // can fit in a magic word to verify that the memory is shared correctly.
336 GetDeviceScaleFactor() * 354 size_t size =
337 GetDeviceScaleFactor(); 355 std::max(sizeof(unsigned int),
356 static_cast<size_t>(window_rect.height *
357 stride *
358 GetDeviceScaleFactor() *
359 GetDeviceScaleFactor()));
338 360
339 // Don't drop the old damage buffer until after we've made sure that the 361 // Don't drop the old damage buffer until after we've made sure that the
340 // browser process has dropped it. 362 // browser process has dropped it.
341 TransportDIB* new_damage_buffer = 363 TransportDIB* new_damage_buffer = NULL;
342 RenderProcess::current()->CreateTransportDIB(size); 364 #if defined(OS_WIN)
343 DCHECK(new_damage_buffer); 365 size_t allocation_granularity = base::SysInfo::VMAllocationGranularity();
366 size_t shared_mem_size = size / allocation_granularity + 1;
367 shared_mem_size = shared_mem_size * allocation_granularity;
368
369 base::SharedMemory shared_mem;
370 if (!shared_mem.CreateAnonymous(shared_mem_size))
371 NOTREACHED() << "Unable to create shared memory of size:" << size;
372 new_damage_buffer = TransportDIB::Map(shared_mem.handle());
373 #else
374 new_damage_buffer = RenderProcess::current()->CreateTransportDIB(size);
375 #endif
376 if (!new_damage_buffer)
377 NOTREACHED() << "Unable to create damage buffer";
378 DCHECK(new_damage_buffer->memory());
379 // Insert the magic word.
380 *static_cast<unsigned int*>(new_damage_buffer->memory()) = 0xdeadbeef;
344 381
345 BrowserPluginHostMsg_ResizeGuest_Params params; 382 BrowserPluginHostMsg_ResizeGuest_Params params;
346 params.damage_buffer_id = new_damage_buffer->id(); 383 params.damage_buffer_id = new_damage_buffer->id();
384 #if defined(OS_WIN)
385 params.damage_buffer_size = size;
386 #endif
347 params.width = window_rect.width; 387 params.width = window_rect.width;
348 params.height = window_rect.height; 388 params.height = window_rect.height;
349 params.resize_pending = resize_pending_; 389 params.resize_pending = resize_pending_;
350 params.scale_factor = GetDeviceScaleFactor(); 390 params.scale_factor = GetDeviceScaleFactor();
351 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_ResizeGuest( 391 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_ResizeGuest(
352 render_view_->GetRoutingID(), 392 render_view_->GetRoutingID(),
353 instance_id_, 393 instance_id_,
354 params)); 394 params));
355 resize_pending_ = true; 395 resize_pending_ = true;
356 396
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void* notify_data) { 452 void* notify_data) {
413 } 453 }
414 454
415 void BrowserPlugin::didFailLoadingFrameRequest( 455 void BrowserPlugin::didFailLoadingFrameRequest(
416 const WebKit::WebURL& url, 456 const WebKit::WebURL& url,
417 void* notify_data, 457 void* notify_data,
418 const WebKit::WebURLError& error) { 458 const WebKit::WebURLError& error) {
419 } 459 }
420 460
421 } // namespace content 461 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698