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

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

Issue 584713002: Browser Plugin: Remove dependency on NPAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_content_window
Patch Set: Even more cleanup! Created 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "content/common/browser_plugin/browser_plugin_constants.h" 11 #include "content/common/browser_plugin/browser_plugin_constants.h"
12 #include "content/common/browser_plugin/browser_plugin_messages.h" 12 #include "content/common/browser_plugin/browser_plugin_messages.h"
13 #include "content/common/view_messages.h" 13 #include "content/common/view_messages.h"
14 #include "content/public/common/content_client.h" 14 #include "content/public/common/content_client.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/renderer/browser_plugin_delegate.h" 16 #include "content/public/renderer/browser_plugin_delegate.h"
17 #include "content/public/renderer/content_renderer_client.h" 17 #include "content/public/renderer/content_renderer_client.h"
18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
19 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 18 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
20 #include "content/renderer/child_frame_compositing_helper.h" 19 #include "content/renderer/child_frame_compositing_helper.h"
21 #include "content/renderer/cursor_utils.h" 20 #include "content/renderer/cursor_utils.h"
22 #include "content/renderer/drop_data_builder.h" 21 #include "content/renderer/drop_data_builder.h"
23 #include "content/renderer/render_thread_impl.h" 22 #include "content/renderer/render_thread_impl.h"
24 #include "content/renderer/sad_plugin.h" 23 #include "content/renderer/sad_plugin.h"
25 #include "third_party/WebKit/public/platform/WebRect.h" 24 #include "third_party/WebKit/public/platform/WebRect.h"
26 #include "third_party/WebKit/public/web/WebBindings.h"
27 #include "third_party/WebKit/public/web/WebDocument.h"
28 #include "third_party/WebKit/public/web/WebElement.h" 25 #include "third_party/WebKit/public/web/WebElement.h"
29 #include "third_party/WebKit/public/web/WebInputEvent.h" 26 #include "third_party/WebKit/public/web/WebInputEvent.h"
30 #include "third_party/WebKit/public/web/WebPluginContainer.h" 27 #include "third_party/WebKit/public/web/WebPluginContainer.h"
31 #include "third_party/WebKit/public/web/WebPluginParams.h" 28 #include "third_party/WebKit/public/web/WebPluginParams.h"
32 #include "third_party/WebKit/public/web/WebView.h" 29 #include "third_party/WebKit/public/web/WebView.h"
33 #include "third_party/skia/include/core/SkCanvas.h" 30 #include "third_party/skia/include/core/SkCanvas.h"
34 #include "ui/events/keycodes/keyboard_codes.h" 31 #include "ui/events/keycodes/keyboard_codes.h"
35 32
36 using blink::WebCanvas; 33 using blink::WebCanvas;
37 using blink::WebPluginContainer; 34 using blink::WebPluginContainer;
(...skipping 27 matching lines...) Expand all
65 blink::WebFrame* frame, 62 blink::WebFrame* frame,
66 scoped_ptr<BrowserPluginDelegate> delegate) 63 scoped_ptr<BrowserPluginDelegate> delegate)
67 : attached_(false), 64 : attached_(false),
68 attach_pending_(false), 65 attach_pending_(false),
69 render_view_(render_view->AsWeakPtr()), 66 render_view_(render_view->AsWeakPtr()),
70 render_view_routing_id_(render_view->GetRoutingID()), 67 render_view_routing_id_(render_view->GetRoutingID()),
71 container_(NULL), 68 container_(NULL),
72 last_device_scale_factor_(GetDeviceScaleFactor()), 69 last_device_scale_factor_(GetDeviceScaleFactor()),
73 sad_guest_(NULL), 70 sad_guest_(NULL),
74 guest_crashed_(false), 71 guest_crashed_(false),
75 content_window_routing_id_(MSG_ROUTING_NONE),
76 plugin_focused_(false), 72 plugin_focused_(false),
77 visible_(true), 73 visible_(true),
78 mouse_locked_(false), 74 mouse_locked_(false),
79 browser_plugin_manager_(render_view->GetBrowserPluginManager()), 75 browser_plugin_manager_(render_view->GetBrowserPluginManager()),
80 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), 76 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone),
77 contents_opaque_(true),
81 delegate_(delegate.Pass()), 78 delegate_(delegate.Pass()),
82 weak_ptr_factory_(this) { 79 weak_ptr_factory_(this) {
83 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); 80 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID();
84 81
85 if (delegate_) 82 if (delegate_)
86 delegate_->SetElementInstanceID(browser_plugin_instance_id_); 83 delegate_->SetElementInstanceID(browser_plugin_instance_id_);
87 } 84 }
88 85
89 BrowserPlugin::~BrowserPlugin() { 86 BrowserPlugin::~BrowserPlugin() {
90 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_); 87 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_);
(...skipping 10 matching lines...) Expand all
101 bool handled = true; 98 bool handled = true;
102 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) 99 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message)
103 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) 100 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK)
104 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) 101 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus)
105 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) 102 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped)
106 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, 103 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped,
107 OnCompositorFrameSwapped(message)) 104 OnCompositorFrameSwapped(message))
108 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface, 105 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface,
109 OnCopyFromCompositingSurface) 106 OnCopyFromCompositingSurface)
110 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) 107 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone)
108 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetContentsOpaque, OnSetContentsOpaque)
111 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) 109 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor)
112 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) 110 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock)
113 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, 111 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents,
114 OnShouldAcceptTouchEvents) 112 OnShouldAcceptTouchEvents)
115 IPC_MESSAGE_UNHANDLED(handled = false) 113 IPC_MESSAGE_UNHANDLED(handled = false)
116 IPC_END_MESSAGE_MAP() 114 IPC_END_MESSAGE_MAP()
117 return handled; 115 return handled;
118 } 116 }
119 117
120 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, 118 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name,
121 const std::string& attribute_value) { 119 const std::string& attribute_value) {
122 if (!container()) 120 if (!container())
123 return; 121 return;
124 122
125 blink::WebElement element = container()->element(); 123 blink::WebElement element = container()->element();
126 blink::WebString web_attribute_name = 124 blink::WebString web_attribute_name =
127 blink::WebString::fromUTF8(attribute_name); 125 blink::WebString::fromUTF8(attribute_name);
128 if (!HasDOMAttribute(attribute_name) || 126 element.setAttribute(web_attribute_name,
129 (std::string(element.getAttribute(web_attribute_name).utf8()) != 127 blink::WebString::fromUTF8(attribute_value));
130 attribute_value)) {
131 element.setAttribute(web_attribute_name,
132 blink::WebString::fromUTF8(attribute_value));
133 }
134 }
135
136 void BrowserPlugin::RemoveDOMAttribute(const std::string& attribute_name) {
137 if (!container())
138 return;
139
140 container()->element().removeAttribute(
141 blink::WebString::fromUTF8(attribute_name));
142 }
143
144 std::string BrowserPlugin::GetDOMAttributeValue(
145 const std::string& attribute_name) const {
146 if (!container())
147 return std::string();
148
149 return container()->element().getAttribute(
150 blink::WebString::fromUTF8(attribute_name)).utf8();
151 }
152
153 bool BrowserPlugin::HasDOMAttribute(const std::string& attribute_name) const {
154 if (!container())
155 return false;
156
157 return container()->element().hasAttribute(
158 blink::WebString::fromUTF8(attribute_name));
159 }
160
161 bool BrowserPlugin::GetAllowTransparencyAttribute() const {
162 return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency);
163 }
164
165 void BrowserPlugin::ParseAllowTransparencyAttribute() {
166 if (!ready())
167 return;
168
169 bool opaque = !GetAllowTransparencyAttribute();
170
171 if (compositing_helper_.get())
172 compositing_helper_->SetContentsOpaque(opaque);
173
174 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque(
175 render_view_routing_id_,
176 browser_plugin_instance_id_,
177 opaque));
178 } 128 }
179 129
180 void BrowserPlugin::Attach() { 130 void BrowserPlugin::Attach() {
181 if (ready()) { 131 if (ready()) {
182 attached_ = false; 132 attached_ = false;
183 guest_crashed_ = false; 133 guest_crashed_ = false;
184 EnableCompositing(false); 134 EnableCompositing(false);
185 if (compositing_helper_.get()) { 135 if (compositing_helper_.get()) {
186 compositing_helper_->OnContainerDestroy(); 136 compositing_helper_->OnContainerDestroy();
187 compositing_helper_ = NULL; 137 compositing_helper_ = NULL;
188 } 138 }
189 } 139 }
190 140
191 // TODO(fsamuel): Add support for reattachment. 141 // TODO(fsamuel): Add support for reattachment.
192 BrowserPluginHostMsg_Attach_Params attach_params; 142 BrowserPluginHostMsg_Attach_Params attach_params;
193 attach_params.focused = ShouldGuestBeFocused(); 143 attach_params.focused = ShouldGuestBeFocused();
194 attach_params.visible = visible_; 144 attach_params.visible = visible_;
195 attach_params.opaque = !GetAllowTransparencyAttribute();
196 attach_params.origin = plugin_rect().origin(); 145 attach_params.origin = plugin_rect().origin();
197 gfx::Size view_size(width(), height()); 146 gfx::Size view_size(width(), height());
198 if (!view_size.IsEmpty()) { 147 if (!view_size.IsEmpty()) {
199 PopulateResizeGuestParameters(view_size, 148 PopulateResizeGuestParameters(view_size,
200 &attach_params.resize_guest_params); 149 &attach_params.resize_guest_params);
201 } 150 }
202 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( 151 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach(
203 render_view_routing_id_, 152 render_view_routing_id_,
204 browser_plugin_instance_id_, 153 browser_plugin_instance_id_,
205 attach_params)); 154 attach_params));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // Queue up showing the sad graphic to give content embedders an opportunity 232 // Queue up showing the sad graphic to give content embedders an opportunity
284 // to fire their listeners and potentially overlay the webview with custom 233 // to fire their listeners and potentially overlay the webview with custom
285 // behavior. If the BrowserPlugin is destroyed in the meantime, then the 234 // behavior. If the BrowserPlugin is destroyed in the meantime, then the
286 // task will not be executed. 235 // task will not be executed.
287 base::MessageLoop::current()->PostTask( 236 base::MessageLoop::current()->PostTask(
288 FROM_HERE, 237 FROM_HERE,
289 base::Bind(&BrowserPlugin::ShowSadGraphic, 238 base::Bind(&BrowserPlugin::ShowSadGraphic,
290 weak_ptr_factory_.GetWeakPtr())); 239 weak_ptr_factory_.GetWeakPtr()));
291 } 240 }
292 241
242 void BrowserPlugin::OnSetContentsOpaque(int browser_plugin_instance_id,
243 bool opaque) {
244 if (contents_opaque_ == opaque)
245 return;
246 contents_opaque_ = opaque;
247 if (compositing_helper_.get())
248 compositing_helper_->SetContentsOpaque(opaque);
249 }
250
293 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, 251 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id,
294 const WebCursor& cursor) { 252 const WebCursor& cursor) {
295 cursor_ = cursor; 253 cursor_ = cursor;
296 } 254 }
297 255
298 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id, 256 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id,
299 bool enable) { 257 bool enable) {
300 if (enable) { 258 if (enable) {
301 if (mouse_locked_) 259 if (mouse_locked_)
302 return; 260 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 320 }
363 321
364 WebPluginContainer* BrowserPlugin::container() const { 322 WebPluginContainer* BrowserPlugin::container() const {
365 return container_; 323 return container_;
366 } 324 }
367 325
368 bool BrowserPlugin::initialize(WebPluginContainer* container) { 326 bool BrowserPlugin::initialize(WebPluginContainer* container) {
369 if (!container) 327 if (!container)
370 return false; 328 return false;
371 329
372 // Tell |container| to allow this plugin to use script objects.
373 npp_.reset(new NPP_t);
374 container->allowScriptObjects();
375
376 bindings_.reset(new BrowserPluginBindings(this));
377 container_ = container; 330 container_ = container;
378 container_->setWantsWheelEvents(true); 331 container_->setWantsWheelEvents(true);
379 332
380 g_plugin_container_map.Get().insert(std::make_pair(container_, this)); 333 g_plugin_container_map.Get().insert(std::make_pair(container_, this));
381 334
382 // This is a way to notify observers of our attributes that this plugin is 335 // This is a way to notify observers of our attributes that this plugin is
383 // available in render tree. 336 // available in render tree.
384 // TODO(lazyboy): This should be done through the delegate instead. Perhaps 337 // TODO(lazyboy): This should be done through the delegate instead. Perhaps
385 // by firing an event from there. 338 // by firing an event from there.
386 UpdateDOMAttribute("internalinstanceid", 339 UpdateDOMAttribute("internalinstanceid",
387 base::IntToString(browser_plugin_instance_id_)); 340 base::IntToString(browser_plugin_instance_id_));
388 341
389 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); 342 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this);
390 return true; 343 return true;
391 } 344 }
392 345
393 void BrowserPlugin::EnableCompositing(bool enable) { 346 void BrowserPlugin::EnableCompositing(bool enable) {
394 bool enabled = !!compositing_helper_.get(); 347 bool enabled = !!compositing_helper_.get();
395 if (enabled == enable) 348 if (enabled == enable)
396 return; 349 return;
397 350
398 if (enable) { 351 if (enable) {
399 DCHECK(!compositing_helper_.get()); 352 DCHECK(!compositing_helper_.get());
400 if (!compositing_helper_.get()) { 353 if (!compositing_helper_.get()) {
401 compositing_helper_ = ChildFrameCompositingHelper::CreateForBrowserPlugin( 354 compositing_helper_ = ChildFrameCompositingHelper::CreateForBrowserPlugin(
402 weak_ptr_factory_.GetWeakPtr()); 355 weak_ptr_factory_.GetWeakPtr());
403 } 356 }
404 } 357 }
405 compositing_helper_->EnableCompositing(enable); 358 compositing_helper_->EnableCompositing(enable);
406 compositing_helper_->SetContentsOpaque(!GetAllowTransparencyAttribute()); 359 compositing_helper_->SetContentsOpaque(contents_opaque_);
407 360
408 if (!enable) { 361 if (!enable) {
409 DCHECK(compositing_helper_.get()); 362 DCHECK(compositing_helper_.get());
410 compositing_helper_->OnContainerDestroy(); 363 compositing_helper_->OnContainerDestroy();
411 compositing_helper_ = NULL; 364 compositing_helper_ = NULL;
412 } 365 }
413 } 366 }
414 367
415 void BrowserPlugin::destroy() { 368 void BrowserPlugin::destroy() {
416 // If the plugin was initialized then it has a valid |npp_| identifier, and
417 // the |container_| must clear references to the plugin's script objects.
418 DCHECK(!npp_ || container_);
419 if (container_) { 369 if (container_) {
420 container_->clearScriptObjects(); 370 //container_->clearScriptObjects();
421 371
422 // The BrowserPlugin's WebPluginContainer is deleted immediately after this 372 // The BrowserPlugin's WebPluginContainer is deleted immediately after this
423 // call returns, so let's not keep a reference to it around. 373 // call returns, so let's not keep a reference to it around.
424 g_plugin_container_map.Get().erase(container_); 374 g_plugin_container_map.Get().erase(container_);
425 } 375 }
426 376
427 if (compositing_helper_.get()) 377 if (compositing_helper_.get())
428 compositing_helper_->OnContainerDestroy(); 378 compositing_helper_->OnContainerDestroy();
429 container_ = NULL; 379 container_ = NULL;
430 // Will be a no-op if the mouse is not currently locked. 380 // Will be a no-op if the mouse is not currently locked.
431 if (render_view_) 381 if (render_view_)
432 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); 382 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this);
433 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 383 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
434 } 384 }
435 385
436 NPObject* BrowserPlugin::scriptableObject() {
437 if (!bindings_)
438 return NULL;
439
440 NPObject* browser_plugin_np_object(bindings_->np_object());
441 // The object is expected to be retained before it is returned.
442 blink::WebBindings::retainObject(browser_plugin_np_object);
443 return browser_plugin_np_object;
444 }
445
446 NPP BrowserPlugin::pluginNPP() {
447 return npp_.get();
448 }
449
450 bool BrowserPlugin::supportsKeyboardFocus() const { 386 bool BrowserPlugin::supportsKeyboardFocus() const {
451 return true; 387 return true;
452 } 388 }
453 389
454 bool BrowserPlugin::supportsEditCommands() const { 390 bool BrowserPlugin::supportsEditCommands() const {
455 return true; 391 return true;
456 } 392 }
457 393
458 bool BrowserPlugin::supportsInputMethod() const { 394 bool BrowserPlugin::supportsInputMethod() const {
459 return true; 395 return true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // static 430 // static
495 bool BrowserPlugin::ShouldForwardToBrowserPlugin( 431 bool BrowserPlugin::ShouldForwardToBrowserPlugin(
496 const IPC::Message& message) { 432 const IPC::Message& message) {
497 switch (message.type()) { 433 switch (message.type()) {
498 case BrowserPluginMsg_Attach_ACK::ID: 434 case BrowserPluginMsg_Attach_ACK::ID:
499 case BrowserPluginMsg_AdvanceFocus::ID: 435 case BrowserPluginMsg_AdvanceFocus::ID:
500 case BrowserPluginMsg_BuffersSwapped::ID: 436 case BrowserPluginMsg_BuffersSwapped::ID:
501 case BrowserPluginMsg_CompositorFrameSwapped::ID: 437 case BrowserPluginMsg_CompositorFrameSwapped::ID:
502 case BrowserPluginMsg_CopyFromCompositingSurface::ID: 438 case BrowserPluginMsg_CopyFromCompositingSurface::ID:
503 case BrowserPluginMsg_GuestGone::ID: 439 case BrowserPluginMsg_GuestGone::ID:
440 case BrowserPluginMsg_SetContentsOpaque::ID:
504 case BrowserPluginMsg_SetCursor::ID: 441 case BrowserPluginMsg_SetCursor::ID:
505 case BrowserPluginMsg_SetMouseLock::ID: 442 case BrowserPluginMsg_SetMouseLock::ID:
506 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: 443 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID:
507 return true; 444 return true;
508 default: 445 default:
509 break; 446 break;
510 } 447 }
511 return false; 448 return false;
512 } 449 }
513 450
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 const blink::WebMouseEvent& event) { 667 const blink::WebMouseEvent& event) {
731 browser_plugin_manager()->Send( 668 browser_plugin_manager()->Send(
732 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, 669 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_,
733 browser_plugin_instance_id_, 670 browser_plugin_instance_id_,
734 plugin_rect_, 671 plugin_rect_,
735 &event)); 672 &event));
736 return true; 673 return true;
737 } 674 }
738 675
739 } // namespace content 676 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698