OLD | NEW |
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 "content/renderer/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 // Temporarily, just call back. | 847 // Temporarily, just call back. |
848 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); | 848 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); |
849 } | 849 } |
850 | 850 |
851 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) | 851 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) |
852 : content::RenderViewObserver(render_view), | 852 : content::RenderViewObserver(render_view), |
853 render_view_(render_view), | 853 render_view_(render_view), |
854 has_saved_context_menu_action_(false), | 854 has_saved_context_menu_action_(false), |
855 saved_context_menu_action_(0), | 855 saved_context_menu_action_(0), |
856 focused_plugin_(NULL), | 856 focused_plugin_(NULL), |
857 mouse_lock_owner_(NULL), | |
858 mouse_locked_(false), | |
859 pending_lock_request_(false), | |
860 pending_unlock_request_(false), | |
861 last_mouse_event_target_(NULL) { | 857 last_mouse_event_target_(NULL) { |
862 } | 858 } |
863 | 859 |
864 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { | 860 PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { |
865 DCHECK(!mouse_lock_owner_); | |
866 } | 861 } |
867 | 862 |
868 scoped_refptr<webkit::ppapi::PluginModule> | 863 scoped_refptr<webkit::ppapi::PluginModule> |
869 PepperPluginDelegateImpl::CreatePepperPluginModule( | 864 PepperPluginDelegateImpl::CreatePepperPluginModule( |
870 const webkit::WebPluginInfo& webplugin_info, | 865 const webkit::WebPluginInfo& webplugin_info, |
871 bool* pepper_plugin_was_registered) { | 866 bool* pepper_plugin_was_registered) { |
872 *pepper_plugin_was_registered = true; | 867 *pepper_plugin_was_registered = true; |
873 | 868 |
874 // See if a module has already been loaded for this plugin. | 869 // See if a module has already been loaded for this plugin. |
875 FilePath path(webplugin_info.path); | 870 FilePath path(webplugin_info.path); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 active_instances_.insert(instance); | 1154 active_instances_.insert(instance); |
1160 | 1155 |
1161 // Set the initial focus. | 1156 // Set the initial focus. |
1162 instance->SetContentAreaFocus(render_view_->has_focus()); | 1157 instance->SetContentAreaFocus(render_view_->has_focus()); |
1163 } | 1158 } |
1164 | 1159 |
1165 void PepperPluginDelegateImpl::InstanceDeleted( | 1160 void PepperPluginDelegateImpl::InstanceDeleted( |
1166 webkit::ppapi::PluginInstance* instance) { | 1161 webkit::ppapi::PluginInstance* instance) { |
1167 active_instances_.erase(instance); | 1162 active_instances_.erase(instance); |
1168 | 1163 |
1169 if (mouse_lock_owner_ && mouse_lock_owner_ == instance) { | 1164 UnlockMouse(instance); |
1170 // UnlockMouse() will determine whether a ViewHostMsg_UnlockMouse needs to | 1165 |
1171 // be sent, and set internal state properly. We only need to forget about | |
1172 // the current |mouse_lock_owner_|. | |
1173 UnlockMouse(mouse_lock_owner_); | |
1174 mouse_lock_owner_ = NULL; | |
1175 } | |
1176 if (last_mouse_event_target_ == instance) | 1166 if (last_mouse_event_target_ == instance) |
1177 last_mouse_event_target_ = NULL; | 1167 last_mouse_event_target_ = NULL; |
1178 if (focused_plugin_ == instance) | 1168 if (focused_plugin_ == instance) |
1179 PluginFocusChanged(instance, false); | 1169 PluginFocusChanged(instance, false); |
1180 } | 1170 } |
1181 | 1171 |
1182 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { | 1172 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { |
1183 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); | 1173 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); |
1184 } | 1174 } |
1185 | 1175 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = | 1336 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = |
1347 active_instances_.begin(); | 1337 active_instances_.begin(); |
1348 i != active_instances_.end(); ++i) | 1338 i != active_instances_.end(); ++i) |
1349 (*i)->SetContentAreaFocus(has_focus); | 1339 (*i)->SetContentAreaFocus(has_focus); |
1350 } | 1340 } |
1351 | 1341 |
1352 bool PepperPluginDelegateImpl::IsPluginFocused() const { | 1342 bool PepperPluginDelegateImpl::IsPluginFocused() const { |
1353 return focused_plugin_ != NULL; | 1343 return focused_plugin_ != NULL; |
1354 } | 1344 } |
1355 | 1345 |
1356 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { | 1346 void PepperPluginDelegateImpl::WillHandleMouseEvent() { |
1357 DCHECK(!mouse_locked_ && pending_lock_request_); | |
1358 | |
1359 mouse_locked_ = succeeded; | |
1360 pending_lock_request_ = false; | |
1361 if (pending_unlock_request_ && !succeeded) { | |
1362 // We have sent an unlock request after the lock request. However, since | |
1363 // the lock request has failed, the unlock request will be ignored by the | |
1364 // browser side and there won't be any response to it. | |
1365 pending_unlock_request_ = false; | |
1366 } | |
1367 // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL. | |
1368 if (mouse_lock_owner_) { | |
1369 webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_; | |
1370 if (!succeeded) { | |
1371 // Reset |mouse_lock_owner_| to NULL before calling OnLockMouseACK(), so | |
1372 // that if OnLockMouseACK() results in calls to any mouse lock method | |
1373 // (e.g., LockMouse()), the method will see consistent internal state. | |
1374 mouse_lock_owner_ = NULL; | |
1375 } | |
1376 | |
1377 last_mouse_lock_owner->OnLockMouseACK(succeeded ? PP_OK : PP_ERROR_FAILED); | |
1378 } | |
1379 } | |
1380 | |
1381 void PepperPluginDelegateImpl::OnMouseLockLost() { | |
1382 DCHECK(mouse_locked_ && !pending_lock_request_); | |
1383 | |
1384 mouse_locked_ = false; | |
1385 pending_unlock_request_ = false; | |
1386 // If the PluginInstance has been deleted, |mouse_lock_owner_| can be NULL. | |
1387 if (mouse_lock_owner_) { | |
1388 // Reset |mouse_lock_owner_| to NULL before calling OnMouseLockLost(), so | |
1389 // that if OnMouseLockLost() results in calls to any mouse lock method | |
1390 // (e.g., LockMouse()), the method will see consistent internal state. | |
1391 webkit::ppapi::PluginInstance* last_mouse_lock_owner = mouse_lock_owner_; | |
1392 mouse_lock_owner_ = NULL; | |
1393 | |
1394 last_mouse_lock_owner->OnMouseLockLost(); | |
1395 } | |
1396 } | |
1397 | |
1398 bool PepperPluginDelegateImpl::HandleMouseEvent( | |
1399 const WebKit::WebMouseEvent& event) { | |
1400 // This method is called for every mouse event that the render view receives. | 1347 // This method is called for every mouse event that the render view receives. |
1401 // And then the mouse event is forwarded to WebKit, which dispatches it to the | 1348 // And then the mouse event is forwarded to WebKit, which dispatches it to the |
1402 // event target. Potentially a Pepper plugin will receive the event. | 1349 // event target. Potentially a Pepper plugin will receive the event. |
1403 // In order to tell whether a plugin gets the last mouse event and which it | 1350 // In order to tell whether a plugin gets the last mouse event and which it |
1404 // is, we set |last_mouse_event_target_| to NULL here. If a plugin gets the | 1351 // is, we set |last_mouse_event_target_| to NULL here. If a plugin gets the |
1405 // event, it will notify us via DidReceiveMouseEvent() and set itself as | 1352 // event, it will notify us via DidReceiveMouseEvent() and set itself as |
1406 // |last_mouse_event_target_|. | 1353 // |last_mouse_event_target_|. |
1407 last_mouse_event_target_ = NULL; | 1354 last_mouse_event_target_ = NULL; |
1408 | |
1409 if (mouse_locked_) { | |
1410 if (mouse_lock_owner_) { | |
1411 // |cursor_info| is ignored since it is hidden when the mouse is locked. | |
1412 WebKit::WebCursorInfo cursor_info; | |
1413 mouse_lock_owner_->HandleInputEvent(event, &cursor_info); | |
1414 } | |
1415 | |
1416 // If the mouse is locked, only the current owner of the mouse lock can | |
1417 // process mouse events. | |
1418 return true; | |
1419 } | |
1420 return false; | |
1421 } | 1355 } |
1422 | 1356 |
1423 bool PepperPluginDelegateImpl::OpenFileSystem( | 1357 bool PepperPluginDelegateImpl::OpenFileSystem( |
1424 const GURL& url, | 1358 const GURL& url, |
1425 fileapi::FileSystemType type, | 1359 fileapi::FileSystemType type, |
1426 long long size, | 1360 long long size, |
1427 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1361 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
1428 FileSystemDispatcher* file_system_dispatcher = | 1362 FileSystemDispatcher* file_system_dispatcher = |
1429 ChildThread::current()->file_system_dispatcher(); | 1363 ChildThread::current()->file_system_dispatcher(); |
1430 return file_system_dispatcher->OpenFileSystem( | 1364 return file_system_dispatcher->OpenFileSystem( |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 DLOG(WARNING) << "Browser failed to allocate shared memory"; | 1882 DLOG(WARNING) << "Browser failed to allocate shared memory"; |
1949 return NULL; | 1883 return NULL; |
1950 } | 1884 } |
1951 return new base::SharedMemory(handle, false); | 1885 return new base::SharedMemory(handle, false); |
1952 } | 1886 } |
1953 | 1887 |
1954 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { | 1888 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { |
1955 return ppapi::Preferences(render_view_->webkit_preferences()); | 1889 return ppapi::Preferences(render_view_->webkit_preferences()); |
1956 } | 1890 } |
1957 | 1891 |
1958 void PepperPluginDelegateImpl::LockMouse( | 1892 bool PepperPluginDelegateImpl::LockMouse( |
1959 webkit::ppapi::PluginInstance* instance) { | 1893 webkit::ppapi::PluginInstance* instance) { |
1960 DCHECK(instance); | 1894 return render_view_->LockMouse(instance); |
1961 if (!MouseLockedOrPending()) { | |
1962 DCHECK(!mouse_lock_owner_); | |
1963 pending_lock_request_ = true; | |
1964 mouse_lock_owner_ = instance; | |
1965 | |
1966 render_view_->Send( | |
1967 new ViewHostMsg_LockMouse(render_view_->routing_id())); | |
1968 } else if (instance != mouse_lock_owner_) { | |
1969 // Another plugin instance is using mouse lock. Fail immediately. | |
1970 instance->OnLockMouseACK(PP_ERROR_FAILED); | |
1971 } else { | |
1972 if (mouse_locked_) { | |
1973 instance->OnLockMouseACK(PP_OK); | |
1974 } else if (pending_lock_request_) { | |
1975 instance->OnLockMouseACK(PP_ERROR_INPROGRESS); | |
1976 } else { | |
1977 // The only case left here is | |
1978 // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_, | |
1979 // which is not possible. | |
1980 NOTREACHED(); | |
1981 instance->OnLockMouseACK(PP_ERROR_FAILED); | |
1982 } | |
1983 } | |
1984 } | 1895 } |
1985 | 1896 |
1986 void PepperPluginDelegateImpl::UnlockMouse( | 1897 void PepperPluginDelegateImpl::UnlockMouse( |
1987 webkit::ppapi::PluginInstance* instance) { | 1898 webkit::ppapi::PluginInstance* instance) { |
1988 DCHECK(instance); | 1899 render_view_->UnlockMouse(instance); |
1989 | |
1990 // If no one is using mouse lock or the user is not |instance|, ignore | |
1991 // the unlock request. | |
1992 if (MouseLockedOrPending() && mouse_lock_owner_ == instance) { | |
1993 if (mouse_locked_ || pending_lock_request_) { | |
1994 DCHECK(!mouse_locked_ || !pending_lock_request_); | |
1995 if (!pending_unlock_request_) { | |
1996 pending_unlock_request_ = true; | |
1997 | |
1998 render_view_->Send( | |
1999 new ViewHostMsg_UnlockMouse(render_view_->routing_id())); | |
2000 } | |
2001 } else { | |
2002 // The only case left here is | |
2003 // !mouse_locked_ && !pending_lock_request_ && pending_unlock_request_, | |
2004 // which is not possible. | |
2005 NOTREACHED(); | |
2006 } | |
2007 } | |
2008 } | 1900 } |
2009 | 1901 |
2010 void PepperPluginDelegateImpl::DidChangeCursor( | 1902 void PepperPluginDelegateImpl::DidChangeCursor( |
2011 webkit::ppapi::PluginInstance* instance, | 1903 webkit::ppapi::PluginInstance* instance, |
2012 const WebKit::WebCursorInfo& cursor) { | 1904 const WebKit::WebCursorInfo& cursor) { |
2013 // Update the cursor appearance immediately if the requesting plugin is the | 1905 // Update the cursor appearance immediately if the requesting plugin is the |
2014 // one which receives the last mouse event. Otherwise, the new cursor won't be | 1906 // one which receives the last mouse event. Otherwise, the new cursor won't be |
2015 // picked up until the plugin gets the next input event. That is bad if, e.g., | 1907 // picked up until the plugin gets the next input event. That is bad if, e.g., |
2016 // the plugin would like to set an invisible cursor when there isn't any user | 1908 // the plugin would like to set an invisible cursor when there isn't any user |
2017 // input for a while. | 1909 // input for a while. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 | 2039 |
2148 bool PepperPluginDelegateImpl::CanUseSocketAPIs() { | 2040 bool PepperPluginDelegateImpl::CanUseSocketAPIs() { |
2149 WebView* webview = render_view_->webview(); | 2041 WebView* webview = render_view_->webview(); |
2150 WebFrame* main_frame = webview ? webview->mainFrame() : NULL; | 2042 WebFrame* main_frame = webview ? webview->mainFrame() : NULL; |
2151 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL()); | 2043 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL()); |
2152 if (!url.is_valid()) | 2044 if (!url.is_valid()) |
2153 return false; | 2045 return false; |
2154 | 2046 |
2155 return content::GetContentClient()->renderer()->AllowSocketAPI(url); | 2047 return content::GetContentClient()->renderer()->AllowSocketAPI(url); |
2156 } | 2048 } |
OLD | NEW |