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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 8970016: refactoring mouse lock to support pepper and WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 desired_fullscreen_state_(false), 297 desired_fullscreen_state_(false),
298 fullscreen_(false), 298 fullscreen_(false),
299 message_channel_(NULL), 299 message_channel_(NULL),
300 sad_plugin_(NULL), 300 sad_plugin_(NULL),
301 input_event_mask_(0), 301 input_event_mask_(0),
302 filtered_input_event_mask_(0), 302 filtered_input_event_mask_(0),
303 text_input_type_(kPluginDefaultTextInputType), 303 text_input_type_(kPluginDefaultTextInputType),
304 text_input_caret_(0, 0, 0, 0), 304 text_input_caret_(0, 0, 0, 0),
305 text_input_caret_bounds_(0, 0, 0, 0), 305 text_input_caret_bounds_(0, 0, 0, 0),
306 text_input_caret_set_(false), 306 text_input_caret_set_(false),
307 mouse_locked_to_this_instance_(false),
307 lock_mouse_callback_(PP_BlockUntilComplete()) { 308 lock_mouse_callback_(PP_BlockUntilComplete()) {
308 pp_instance_ = HostGlobals::Get()->AddInstance(this); 309 pp_instance_ = HostGlobals::Get()->AddInstance(this);
309 310
310 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 311 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
311 DCHECK(delegate); 312 DCHECK(delegate);
312 module_->InstanceCreated(this); 313 module_->InstanceCreated(this);
313 delegate_->InstanceCreated(this); 314 delegate_->InstanceCreated(this);
314 message_channel_.reset(new MessageChannel(this)); 315 message_channel_.reset(new MessageChannel(this));
315 } 316 }
316 317
317 PluginInstance::~PluginInstance() { 318 PluginInstance::~PluginInstance() {
318 DCHECK(!fullscreen_container_); 319 DCHECK(!fullscreen_container_);
319 320
320 // Free all the plugin objects. This will automatically clear the back- 321 // Free all the plugin objects. This will automatically clear the back-
321 // pointer from the NPObject so WebKit can't call into the plugin any more. 322 // pointer from the NPObject so WebKit can't call into the plugin any more.
322 // 323 //
323 // Swap out the set so we can delete from it (the objects will try to 324 // Swap out the set so we can delete from it (the objects will try to
324 // unregister themselves inside the delete call). 325 // unregister themselves inside the delete call).
325 PluginObjectSet plugin_object_copy; 326 PluginObjectSet plugin_object_copy;
326 live_plugin_objects_.swap(plugin_object_copy); 327 live_plugin_objects_.swap(plugin_object_copy);
327 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 328 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
328 i != plugin_object_copy.end(); ++i) 329 i != plugin_object_copy.end(); ++i)
329 delete *i; 330 delete *i;
330 331
331 if (lock_mouse_callback_.func) 332 if (lock_mouse_callback_.func) {
333 mouse_locked_to_this_instance_ = false;
332 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED); 334 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED);
335 }
333 336
334 delegate_->InstanceDeleted(this); 337 delegate_->InstanceDeleted(this);
335 module_->InstanceDeleted(this); 338 module_->InstanceDeleted(this);
336 339
337 HostGlobals::Get()->InstanceDeleted(pp_instance_); 340 HostGlobals::Get()->InstanceDeleted(pp_instance_);
338 } 341 }
339 342
340 // NOTE: Any of these methods that calls into the plugin needs to take into 343 // NOTE: Any of these methods that calls into the plugin needs to take into
341 // account that the plugin may use Var to remove the <embed> from the DOM, which 344 // account that the plugin may use Var to remove the <embed> from the DOM, which
342 // will make the WebPluginImpl drop its reference, usually the last one. If a 345 // will make the WebPluginImpl drop its reference, usually the last one. If a
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 // Don't actually verify that the object is in the set since during module 1566 // Don't actually verify that the object is in the set since during module
1564 // deletion we'll be in the process of freeing them. 1567 // deletion we'll be in the process of freeing them.
1565 live_plugin_objects_.erase(plugin_object); 1568 live_plugin_objects_.erase(plugin_object);
1566 } 1569 }
1567 1570
1568 bool PluginInstance::IsFullPagePlugin() const { 1571 bool PluginInstance::IsFullPagePlugin() const {
1569 WebFrame* frame = container()->element().document().frame(); 1572 WebFrame* frame = container()->element().document().frame();
1570 return frame->view()->mainFrame()->document().isPluginDocument(); 1573 return frame->view()->mainFrame()->document().isPluginDocument();
1571 } 1574 }
1572 1575
1573 void PluginInstance::OnLockMouseACK(int32_t result) { 1576 void PluginInstance::OnLockMouseACK2(bool succeeded) {
1577 fprintf(stderr, "PluginInstance::OnLockMouseACK2(%d)\n", succeeded);
1574 if (!lock_mouse_callback_.func) { 1578 if (!lock_mouse_callback_.func) {
1575 NOTREACHED(); 1579 NOTREACHED();
1580 fprintf(stderr, "PluginInstance::OnLockMouseACK2 !!!!!\n");
1576 return; 1581 return;
1577 } 1582 }
1578 1583 mouse_locked_to_this_instance_ = succeeded;
1579 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, result); 1584 PP_RunAndClearCompletionCallback(&lock_mouse_callback_,
1585 succeeded ? PP_OK : PP_ERROR_FAILED);
1580 } 1586 }
1581 1587
1582 void PluginInstance::OnMouseLockLost() { 1588 void PluginInstance::OnMouseLockLost2() {
1589 fprintf(stderr, "PluginInstance::OnMouseLockLost2()\n");
1583 if (LoadMouseLockInterface()) 1590 if (LoadMouseLockInterface())
1584 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); 1591 plugin_mouse_lock_interface_->MouseLockLost(pp_instance());
1592 mouse_locked_to_this_instance_ = false;
1593 }
1594
1595 void PluginInstance::HandleMouseLockedInputEvent(
1596 const WebKit::WebMouseEvent& event) {
1597 // |cursor_info| is ignored since it is hidden when the mouse is locked.
1598 WebKit::WebCursorInfo cursor_info;
1599 HandleInputEvent(event, &cursor_info);
1585 } 1600 }
1586 1601
1587 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) { 1602 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) {
1588 WebView* web_view = container()->element().document().frame()->view(); 1603 WebView* web_view = container()->element().document().frame()->view();
1589 if (!web_view) { 1604 if (!web_view) {
1590 NOTREACHED(); 1605 NOTREACHED();
1591 return; 1606 return;
1592 } 1607 }
1593 1608
1594 std::vector<linked_ptr<WebInputEvent> > events = 1609 std::vector<linked_ptr<WebInputEvent> > events =
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 } 1873 }
1859 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); 1874 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor);
1860 } 1875 }
1861 1876
1862 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { 1877 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) {
1863 message_channel_->PostMessageToJavaScript(message); 1878 message_channel_->PostMessageToJavaScript(message);
1864 } 1879 }
1865 1880
1866 int32_t PluginInstance::LockMouse(PP_Instance instance, 1881 int32_t PluginInstance::LockMouse(PP_Instance instance,
1867 PP_CompletionCallback callback) { 1882 PP_CompletionCallback callback) {
1883 fprintf(stderr, "PluginInstance::LockMouse: ");
1868 if (!callback.func) { 1884 if (!callback.func) {
1869 // Don't support synchronous call. 1885 // Don't support synchronous call.
1870 return PP_ERROR_BLOCKS_MAIN_THREAD; 1886 return PP_ERROR_BLOCKS_MAIN_THREAD;
1871 } 1887 }
1872 if (lock_mouse_callback_.func) 1888 if (lock_mouse_callback_.func) // a lock is pending
1889 {
1890 fprintf(stderr, "lock_mouse_callback_.func PP_ERROR_INPROGRESS\n");
1873 return PP_ERROR_INPROGRESS; 1891 return PP_ERROR_INPROGRESS;
1892 }
1893 if (mouse_locked_to_this_instance_)
1894 {
1895 fprintf(stderr, "mouse_locked_to_this_instance_ PP_OK\n");
1896 return PP_OK;
1897 }
1874 if (!CanAccessMainFrame()) 1898 if (!CanAccessMainFrame())
1875 return PP_ERROR_NOACCESS; 1899 return PP_ERROR_NOACCESS;
1876 1900
1877 lock_mouse_callback_ = callback; 1901 if (delegate()->LockMouse(this)) {
yzshen1 2012/01/04 00:50:00 It seems better to *not* have |mouse_locked_to_thi
1878 // We will be notified on completion via OnLockMouseACK(), either 1902 fprintf(stderr, "delegate()->LockMouse(this) == true\n");
1879 // synchronously or asynchronously. 1903 lock_mouse_callback_ = callback;
1880 delegate()->LockMouse(this); 1904 return PP_OK_COMPLETIONPENDING;
1881 return PP_OK_COMPLETIONPENDING; 1905 } else
1906 {
1907 fprintf(stderr, "delegate()->LockMouse(this) == false PP_ERROR_FAILED\n");
1908 return PP_ERROR_FAILED;
1909 }
1882 } 1910 }
1883 1911
1884 void PluginInstance::UnlockMouse(PP_Instance instance) { 1912 void PluginInstance::UnlockMouse(PP_Instance instance) {
1913 fprintf(stderr, "PluginInstance::UnlockMouse\n");
1885 delegate()->UnlockMouse(this); 1914 delegate()->UnlockMouse(this);
1886 } 1915 }
1887 1916
1888 PP_Var PluginInstance::ResolveRelativeToDocument( 1917 PP_Var PluginInstance::ResolveRelativeToDocument(
1889 PP_Instance instance, 1918 PP_Instance instance,
1890 PP_Var relative, 1919 PP_Var relative,
1891 PP_URLComponents_Dev* components) { 1920 PP_URLComponents_Dev* components) {
1892 StringVar* relative_string = StringVar::FromPPVar(relative); 1921 StringVar* relative_string = StringVar::FromPPVar(relative);
1893 if (!relative_string) 1922 if (!relative_string)
1894 return PP_MakeNull(); 1923 return PP_MakeNull();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 screen_size_for_fullscreen_ = gfx::Size(); 2043 screen_size_for_fullscreen_ = gfx::Size();
2015 WebElement element = container_->element(); 2044 WebElement element = container_->element();
2016 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2045 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2017 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2046 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2018 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2047 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2019 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2048 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2020 } 2049 }
2021 2050
2022 } // namespace ppapi 2051 } // namespace ppapi
2023 } // namespace webkit 2052 } // namespace webkit
OLDNEW
« webkit/plugins/ppapi/plugin_delegate.h ('K') | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698