OLD | NEW |
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" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 return false; | 293 return false; |
294 | 294 |
295 container_ = container; | 295 container_ = container; |
296 container_->setWantsWheelEvents(true); | 296 container_->setWantsWheelEvents(true); |
297 | 297 |
298 g_plugin_container_map.Get().insert(std::make_pair(container_, this)); | 298 g_plugin_container_map.Get().insert(std::make_pair(container_, this)); |
299 | 299 |
300 BrowserPluginManager::Get()->AddBrowserPlugin( | 300 BrowserPluginManager::Get()->AddBrowserPlugin( |
301 browser_plugin_instance_id_, this); | 301 browser_plugin_instance_id_, this); |
302 | 302 |
303 // This is a way to notify observers of our attributes that this plugin is | 303 // Defer attach call so that if there's any pending browser plugin |
304 // available in render tree. | 304 // destruction, then it can progress first. |
305 // TODO(lazyboy): This should be done through the delegate instead. Perhaps | 305 base::MessageLoop::current()->PostTask( |
306 // by firing an event from there. | 306 FROM_HERE, |
307 UpdateDOMAttribute( | 307 base::Bind(&BrowserPlugin::UpdateInternalInstanceId, |
308 "internalinstanceid", | 308 weak_ptr_factory_.GetWeakPtr())); |
309 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); | |
310 | |
311 return true; | 309 return true; |
312 } | 310 } |
313 | 311 |
314 void BrowserPlugin::EnableCompositing(bool enable) { | 312 void BrowserPlugin::EnableCompositing(bool enable) { |
315 bool enabled = !!compositing_helper_.get(); | 313 bool enabled = !!compositing_helper_.get(); |
316 if (enabled == enable) | 314 if (enabled == enable) |
317 return; | 315 return; |
318 | 316 |
319 if (enable) { | 317 if (enable) { |
320 DCHECK(!compositing_helper_.get()); | 318 DCHECK(!compositing_helper_.get()); |
321 if (!compositing_helper_.get()) { | 319 if (!compositing_helper_.get()) { |
322 compositing_helper_ = ChildFrameCompositingHelper::CreateForBrowserPlugin( | 320 compositing_helper_ = ChildFrameCompositingHelper::CreateForBrowserPlugin( |
323 weak_ptr_factory_.GetWeakPtr()); | 321 weak_ptr_factory_.GetWeakPtr()); |
324 } | 322 } |
325 } | 323 } |
326 compositing_helper_->EnableCompositing(enable); | 324 compositing_helper_->EnableCompositing(enable); |
327 compositing_helper_->SetContentsOpaque(contents_opaque_); | 325 compositing_helper_->SetContentsOpaque(contents_opaque_); |
328 | 326 |
329 if (!enable) { | 327 if (!enable) { |
330 DCHECK(compositing_helper_.get()); | 328 DCHECK(compositing_helper_.get()); |
331 compositing_helper_->OnContainerDestroy(); | 329 compositing_helper_->OnContainerDestroy(); |
332 compositing_helper_ = nullptr; | 330 compositing_helper_ = nullptr; |
333 } | 331 } |
334 } | 332 } |
335 | 333 |
| 334 void BrowserPlugin::UpdateInternalInstanceId() { |
| 335 // This is a way to notify observers of our attributes that this plugin is |
| 336 // available in render tree. |
| 337 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
| 338 // by firing an event from there. |
| 339 UpdateDOMAttribute( |
| 340 "internalinstanceid", |
| 341 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); |
| 342 } |
| 343 |
336 void BrowserPlugin::destroy() { | 344 void BrowserPlugin::destroy() { |
337 if (container_) { | 345 if (container_) { |
338 // The BrowserPlugin's WebPluginContainer is deleted immediately after this | 346 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
339 // call returns, so let's not keep a reference to it around. | 347 // call returns, so let's not keep a reference to it around. |
340 g_plugin_container_map.Get().erase(container_); | 348 g_plugin_container_map.Get().erase(container_); |
341 } | 349 } |
342 | 350 |
343 container_ = nullptr; | 351 container_ = nullptr; |
344 // Will be a no-op if the mouse is not currently locked. | 352 // Will be a no-op if the mouse is not currently locked. |
345 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); | 353 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 bool BrowserPlugin::HandleMouseLockedInputEvent( | 628 bool BrowserPlugin::HandleMouseLockedInputEvent( |
621 const blink::WebMouseEvent& event) { | 629 const blink::WebMouseEvent& event) { |
622 BrowserPluginManager::Get()->Send( | 630 BrowserPluginManager::Get()->Send( |
623 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, | 631 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, |
624 view_rect_, | 632 view_rect_, |
625 &event)); | 633 &event)); |
626 return true; | 634 return true; |
627 } | 635 } |
628 | 636 |
629 } // namespace content | 637 } // namespace content |
OLD | NEW |