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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #endif | 100 #endif |
101 | 101 |
102 using base::StringPrintf; | 102 using base::StringPrintf; |
103 using ppapi::InputEventData; | 103 using ppapi::InputEventData; |
104 using ppapi::PpapiGlobals; | 104 using ppapi::PpapiGlobals; |
105 using ppapi::PPB_InputEvent_Shared; | 105 using ppapi::PPB_InputEvent_Shared; |
106 using ppapi::PPB_View_Shared; | 106 using ppapi::PPB_View_Shared; |
107 using ppapi::PPP_Instance_Combined; | 107 using ppapi::PPP_Instance_Combined; |
108 using ppapi::ScopedPPResource; | 108 using ppapi::ScopedPPResource; |
109 using ppapi::StringVar; | 109 using ppapi::StringVar; |
| 110 using ppapi::TrackedCallback; |
110 using ppapi::thunk::EnterResourceNoLock; | 111 using ppapi::thunk::EnterResourceNoLock; |
111 using ppapi::thunk::PPB_Buffer_API; | 112 using ppapi::thunk::PPB_Buffer_API; |
112 using ppapi::thunk::PPB_Graphics2D_API; | 113 using ppapi::thunk::PPB_Graphics2D_API; |
113 using ppapi::thunk::PPB_Graphics3D_API; | 114 using ppapi::thunk::PPB_Graphics3D_API; |
114 using ppapi::thunk::PPB_ImageData_API; | 115 using ppapi::thunk::PPB_ImageData_API; |
115 using ppapi::Var; | 116 using ppapi::Var; |
116 using ppapi::ViewData; | 117 using ppapi::ViewData; |
117 using WebKit::WebBindings; | 118 using WebKit::WebBindings; |
118 using WebKit::WebCanvas; | 119 using WebKit::WebCanvas; |
119 using WebKit::WebCursorInfo; | 120 using WebKit::WebCursorInfo; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 message_channel_(NULL), | 344 message_channel_(NULL), |
344 sad_plugin_(NULL), | 345 sad_plugin_(NULL), |
345 input_event_mask_(0), | 346 input_event_mask_(0), |
346 filtered_input_event_mask_(0), | 347 filtered_input_event_mask_(0), |
347 text_input_type_(kPluginDefaultTextInputType), | 348 text_input_type_(kPluginDefaultTextInputType), |
348 text_input_caret_(0, 0, 0, 0), | 349 text_input_caret_(0, 0, 0, 0), |
349 text_input_caret_bounds_(0, 0, 0, 0), | 350 text_input_caret_bounds_(0, 0, 0, 0), |
350 text_input_caret_set_(false), | 351 text_input_caret_set_(false), |
351 selection_caret_(0), | 352 selection_caret_(0), |
352 selection_anchor_(0), | 353 selection_anchor_(0), |
353 lock_mouse_callback_(PP_BlockUntilComplete()), | |
354 pending_user_gesture_(0.0), | 354 pending_user_gesture_(0.0), |
355 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 355 flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
356 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 356 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
357 | 357 |
358 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 358 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
359 DCHECK(delegate); | 359 DCHECK(delegate); |
360 module_->InstanceCreated(this); | 360 module_->InstanceCreated(this); |
361 delegate_->InstanceCreated(this); | 361 delegate_->InstanceCreated(this); |
362 message_channel_.reset(new MessageChannel(this)); | 362 message_channel_.reset(new MessageChannel(this)); |
363 | 363 |
364 view_data_.is_page_visible = delegate->IsPageVisible(); | 364 view_data_.is_page_visible = delegate->IsPageVisible(); |
365 } | 365 } |
366 | 366 |
367 PluginInstance::~PluginInstance() { | 367 PluginInstance::~PluginInstance() { |
368 DCHECK(!fullscreen_container_); | 368 DCHECK(!fullscreen_container_); |
369 | 369 |
370 // Free all the plugin objects. This will automatically clear the back- | 370 // Free all the plugin objects. This will automatically clear the back- |
371 // pointer from the NPObject so WebKit can't call into the plugin any more. | 371 // pointer from the NPObject so WebKit can't call into the plugin any more. |
372 // | 372 // |
373 // Swap out the set so we can delete from it (the objects will try to | 373 // Swap out the set so we can delete from it (the objects will try to |
374 // unregister themselves inside the delete call). | 374 // unregister themselves inside the delete call). |
375 PluginObjectSet plugin_object_copy; | 375 PluginObjectSet plugin_object_copy; |
376 live_plugin_objects_.swap(plugin_object_copy); | 376 live_plugin_objects_.swap(plugin_object_copy); |
377 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 377 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
378 i != plugin_object_copy.end(); ++i) | 378 i != plugin_object_copy.end(); ++i) |
379 delete *i; | 379 delete *i; |
380 | 380 |
381 if (lock_mouse_callback_.func) | 381 if (lock_mouse_callback_) |
382 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED); | 382 TrackedCallback::ClearAndAbort(&lock_mouse_callback_); |
383 | 383 |
384 delegate_->InstanceDeleted(this); | 384 delegate_->InstanceDeleted(this); |
385 module_->InstanceDeleted(this); | 385 module_->InstanceDeleted(this); |
386 | 386 |
387 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 387 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
388 } | 388 } |
389 | 389 |
390 // NOTE: Any of these methods that calls into the plugin needs to take into | 390 // NOTE: Any of these methods that calls into the plugin needs to take into |
391 // account that the plugin may use Var to remove the <embed> from the DOM, which | 391 // account that the plugin may use Var to remove the <embed> from the DOM, which |
392 // will make the WebPluginImpl drop its reference, usually the last one. If a | 392 // will make the WebPluginImpl drop its reference, usually the last one. If a |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 bool PluginInstance::IsProcessingUserGesture() { | 1588 bool PluginInstance::IsProcessingUserGesture() { |
1589 PP_TimeTicks now = | 1589 PP_TimeTicks now = |
1590 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | 1590 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); |
1591 // Give a lot of slack so tests won't be flaky. Well behaved plugins will | 1591 // Give a lot of slack so tests won't be flaky. Well behaved plugins will |
1592 // close the user gesture. | 1592 // close the user gesture. |
1593 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; | 1593 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; |
1594 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); | 1594 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); |
1595 } | 1595 } |
1596 | 1596 |
1597 void PluginInstance::OnLockMouseACK(bool succeeded) { | 1597 void PluginInstance::OnLockMouseACK(bool succeeded) { |
1598 if (!lock_mouse_callback_.func) { | 1598 if (TrackedCallback::IsPending(lock_mouse_callback_)) { |
1599 NOTREACHED(); | 1599 NOTREACHED(); |
1600 return; | 1600 return; |
1601 } | 1601 } |
1602 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, | 1602 TrackedCallback::ClearAndRun(&lock_mouse_callback_, |
1603 succeeded ? PP_OK : PP_ERROR_FAILED); | 1603 succeeded ? PP_OK : PP_ERROR_FAILED); |
1604 } | 1604 } |
1605 | 1605 |
1606 void PluginInstance::OnMouseLockLost() { | 1606 void PluginInstance::OnMouseLockLost() { |
1607 if (LoadMouseLockInterface()) | 1607 if (LoadMouseLockInterface()) |
1608 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); | 1608 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); |
1609 } | 1609 } |
1610 | 1610 |
1611 void PluginInstance::HandleMouseLockedInputEvent( | 1611 void PluginInstance::HandleMouseLockedInputEvent( |
1612 const WebKit::WebMouseEvent& event) { | 1612 const WebKit::WebMouseEvent& event) { |
1613 // |cursor_info| is ignored since it is hidden when the mouse is locked. | 1613 // |cursor_info| is ignored since it is hidden when the mouse is locked. |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(), | 1947 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(), |
1948 bitmap->config())) { | 1948 bitmap->config())) { |
1949 return PP_FALSE; | 1949 return PP_FALSE; |
1950 } | 1950 } |
1951 | 1951 |
1952 DoSetCursor(custom_cursor.release()); | 1952 DoSetCursor(custom_cursor.release()); |
1953 return PP_TRUE; | 1953 return PP_TRUE; |
1954 } | 1954 } |
1955 | 1955 |
1956 int32_t PluginInstance::LockMouse(PP_Instance instance, | 1956 int32_t PluginInstance::LockMouse(PP_Instance instance, |
1957 PP_CompletionCallback callback) { | 1957 scoped_refptr<TrackedCallback> callback) { |
1958 if (!callback.func) { | 1958 if (TrackedCallback::IsPending(lock_mouse_callback_)) |
1959 // Don't support synchronous call. | |
1960 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
1961 } | |
1962 if (lock_mouse_callback_.func) // A lock is pending. | |
1963 return PP_ERROR_INPROGRESS; | 1959 return PP_ERROR_INPROGRESS; |
1964 | 1960 |
1965 if (delegate()->IsMouseLocked(this)) | 1961 if (delegate()->IsMouseLocked(this)) |
1966 return PP_OK; | 1962 return PP_OK; |
1967 | 1963 |
1968 if (!CanAccessMainFrame()) | 1964 if (!CanAccessMainFrame()) |
1969 return PP_ERROR_NOACCESS; | 1965 return PP_ERROR_NOACCESS; |
1970 | 1966 |
1971 if (delegate()->LockMouse(this)) { | 1967 if (delegate()->LockMouse(this)) { |
1972 lock_mouse_callback_ = callback; | 1968 lock_mouse_callback_ = callback; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 screen_size_for_fullscreen_ = gfx::Size(); | 2197 screen_size_for_fullscreen_ = gfx::Size(); |
2202 WebElement element = container_->element(); | 2198 WebElement element = container_->element(); |
2203 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2199 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2204 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2200 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2205 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2201 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2206 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2202 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2207 } | 2203 } |
2208 | 2204 |
2209 } // namespace ppapi | 2205 } // namespace ppapi |
2210 } // namespace webkit | 2206 } // namespace webkit |
OLD | NEW |