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