OLD | NEW |
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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 #include "ui/gfx/gdi_util.h" | 97 #include "ui/gfx/gdi_util.h" |
98 #endif | 98 #endif |
99 | 99 |
100 using base::StringPrintf; | 100 using base::StringPrintf; |
101 using ppapi::InputEventData; | 101 using ppapi::InputEventData; |
102 using ppapi::PPB_InputEvent_Shared; | 102 using ppapi::PPB_InputEvent_Shared; |
103 using ppapi::PpapiGlobals; | 103 using ppapi::PpapiGlobals; |
104 using ppapi::PPB_View_Shared; | 104 using ppapi::PPB_View_Shared; |
105 using ppapi::ScopedPPResource; | 105 using ppapi::ScopedPPResource; |
106 using ppapi::StringVar; | 106 using ppapi::StringVar; |
| 107 using ppapi::TrackedCallback; |
107 using ppapi::thunk::EnterResourceNoLock; | 108 using ppapi::thunk::EnterResourceNoLock; |
108 using ppapi::thunk::PPB_Buffer_API; | 109 using ppapi::thunk::PPB_Buffer_API; |
109 using ppapi::thunk::PPB_Graphics2D_API; | 110 using ppapi::thunk::PPB_Graphics2D_API; |
110 using ppapi::thunk::PPB_Graphics3D_API; | 111 using ppapi::thunk::PPB_Graphics3D_API; |
111 using ppapi::thunk::PPB_ImageData_API; | 112 using ppapi::thunk::PPB_ImageData_API; |
112 using ppapi::Var; | 113 using ppapi::Var; |
113 using ppapi::ViewData; | 114 using ppapi::ViewData; |
114 using WebKit::WebBindings; | 115 using WebKit::WebBindings; |
115 using WebKit::WebCanvas; | 116 using WebKit::WebCanvas; |
116 using WebKit::WebCursorInfo; | 117 using WebKit::WebCursorInfo; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 message_channel_(NULL), | 327 message_channel_(NULL), |
327 sad_plugin_(NULL), | 328 sad_plugin_(NULL), |
328 input_event_mask_(0), | 329 input_event_mask_(0), |
329 filtered_input_event_mask_(0), | 330 filtered_input_event_mask_(0), |
330 text_input_type_(kPluginDefaultTextInputType), | 331 text_input_type_(kPluginDefaultTextInputType), |
331 text_input_caret_(0, 0, 0, 0), | 332 text_input_caret_(0, 0, 0, 0), |
332 text_input_caret_bounds_(0, 0, 0, 0), | 333 text_input_caret_bounds_(0, 0, 0, 0), |
333 text_input_caret_set_(false), | 334 text_input_caret_set_(false), |
334 selection_caret_(0), | 335 selection_caret_(0), |
335 selection_anchor_(0), | 336 selection_anchor_(0), |
336 lock_mouse_callback_(PP_BlockUntilComplete()), | |
337 pending_user_gesture_(0.0), | 337 pending_user_gesture_(0.0), |
338 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 338 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
339 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 339 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
340 | 340 |
341 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 341 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
342 DCHECK(delegate); | 342 DCHECK(delegate); |
343 module_->InstanceCreated(this); | 343 module_->InstanceCreated(this); |
344 delegate_->InstanceCreated(this); | 344 delegate_->InstanceCreated(this); |
345 message_channel_.reset(new MessageChannel(this)); | 345 message_channel_.reset(new MessageChannel(this)); |
346 | 346 |
347 view_data_.is_page_visible = delegate->IsPageVisible(); | 347 view_data_.is_page_visible = delegate->IsPageVisible(); |
348 } | 348 } |
349 | 349 |
350 PluginInstance::~PluginInstance() { | 350 PluginInstance::~PluginInstance() { |
351 DCHECK(!fullscreen_container_); | 351 DCHECK(!fullscreen_container_); |
352 | 352 |
353 // Free all the plugin objects. This will automatically clear the back- | 353 // Free all the plugin objects. This will automatically clear the back- |
354 // pointer from the NPObject so WebKit can't call into the plugin any more. | 354 // pointer from the NPObject so WebKit can't call into the plugin any more. |
355 // | 355 // |
356 // Swap out the set so we can delete from it (the objects will try to | 356 // Swap out the set so we can delete from it (the objects will try to |
357 // unregister themselves inside the delete call). | 357 // unregister themselves inside the delete call). |
358 PluginObjectSet plugin_object_copy; | 358 PluginObjectSet plugin_object_copy; |
359 live_plugin_objects_.swap(plugin_object_copy); | 359 live_plugin_objects_.swap(plugin_object_copy); |
360 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 360 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
361 i != plugin_object_copy.end(); ++i) | 361 i != plugin_object_copy.end(); ++i) |
362 delete *i; | 362 delete *i; |
363 | 363 |
364 if (lock_mouse_callback_.func) | 364 if (lock_mouse_callback_) |
365 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED); | 365 TrackedCallback::ClearAndAbort(&lock_mouse_callback_); |
366 | 366 |
367 delegate_->InstanceDeleted(this); | 367 delegate_->InstanceDeleted(this); |
368 module_->InstanceDeleted(this); | 368 module_->InstanceDeleted(this); |
369 | 369 |
370 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 370 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
371 } | 371 } |
372 | 372 |
373 // NOTE: Any of these methods that calls into the plugin needs to take into | 373 // NOTE: Any of these methods that calls into the plugin needs to take into |
374 // account that the plugin may use Var to remove the <embed> from the DOM, which | 374 // account that the plugin may use Var to remove the <embed> from the DOM, which |
375 // will make the WebPluginImpl drop its reference, usually the last one. If a | 375 // will make the WebPluginImpl drop its reference, usually the last one. If a |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 bool PluginInstance::IsProcessingUserGesture() { | 1558 bool PluginInstance::IsProcessingUserGesture() { |
1559 PP_TimeTicks now = | 1559 PP_TimeTicks now = |
1560 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | 1560 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); |
1561 // Give a lot of slack so tests won't be flaky. Well behaved plugins will | 1561 // Give a lot of slack so tests won't be flaky. Well behaved plugins will |
1562 // close the user gesture. | 1562 // close the user gesture. |
1563 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; | 1563 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; |
1564 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); | 1564 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); |
1565 } | 1565 } |
1566 | 1566 |
1567 void PluginInstance::OnLockMouseACK(bool succeeded) { | 1567 void PluginInstance::OnLockMouseACK(bool succeeded) { |
1568 if (!lock_mouse_callback_.func) { | 1568 if (TrackedCallback::IsPending(lock_mouse_callback_)) { |
1569 NOTREACHED(); | 1569 NOTREACHED(); |
1570 return; | 1570 return; |
1571 } | 1571 } |
1572 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, | 1572 TrackedCallback::ClearAndRun(&lock_mouse_callback_, |
1573 succeeded ? PP_OK : PP_ERROR_FAILED); | 1573 succeeded ? PP_OK : PP_ERROR_FAILED); |
1574 } | 1574 } |
1575 | 1575 |
1576 void PluginInstance::OnMouseLockLost() { | 1576 void PluginInstance::OnMouseLockLost() { |
1577 if (LoadMouseLockInterface()) | 1577 if (LoadMouseLockInterface()) |
1578 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); | 1578 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); |
1579 } | 1579 } |
1580 | 1580 |
1581 void PluginInstance::HandleMouseLockedInputEvent( | 1581 void PluginInstance::HandleMouseLockedInputEvent( |
1582 const WebKit::WebMouseEvent& event) { | 1582 const WebKit::WebMouseEvent& event) { |
1583 // |cursor_info| is ignored since it is hidden when the mouse is locked. | 1583 // |cursor_info| is ignored since it is hidden when the mouse is locked. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(), | 1867 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(), |
1868 bitmap->config())) { | 1868 bitmap->config())) { |
1869 return PP_FALSE; | 1869 return PP_FALSE; |
1870 } | 1870 } |
1871 | 1871 |
1872 DoSetCursor(custom_cursor.release()); | 1872 DoSetCursor(custom_cursor.release()); |
1873 return PP_TRUE; | 1873 return PP_TRUE; |
1874 } | 1874 } |
1875 | 1875 |
1876 int32_t PluginInstance::LockMouse(PP_Instance instance, | 1876 int32_t PluginInstance::LockMouse(PP_Instance instance, |
1877 PP_CompletionCallback callback) { | 1877 scoped_refptr<TrackedCallback> callback) { |
1878 if (!callback.func) { | 1878 if (TrackedCallback::IsPending(lock_mouse_callback_)) |
1879 // Don't support synchronous call. | |
1880 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
1881 } | |
1882 if (lock_mouse_callback_.func) // A lock is pending. | |
1883 return PP_ERROR_INPROGRESS; | 1879 return PP_ERROR_INPROGRESS; |
1884 | 1880 |
1885 if (delegate()->IsMouseLocked(this)) | 1881 if (delegate()->IsMouseLocked(this)) |
1886 return PP_OK; | 1882 return PP_OK; |
1887 | 1883 |
1888 if (!CanAccessMainFrame()) | 1884 if (!CanAccessMainFrame()) |
1889 return PP_ERROR_NOACCESS; | 1885 return PP_ERROR_NOACCESS; |
1890 | 1886 |
1891 if (delegate()->LockMouse(this)) { | 1887 if (delegate()->LockMouse(this)) { |
1892 lock_mouse_callback_ = callback; | 1888 lock_mouse_callback_ = callback; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 screen_size_for_fullscreen_ = gfx::Size(); | 2064 screen_size_for_fullscreen_ = gfx::Size(); |
2069 WebElement element = container_->element(); | 2065 WebElement element = container_->element(); |
2070 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2066 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2071 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2067 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2072 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2068 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2073 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2069 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2074 } | 2070 } |
2075 | 2071 |
2076 } // namespace ppapi | 2072 } // namespace ppapi |
2077 } // namespace webkit | 2073 } // namespace webkit |
OLD | NEW |