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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1141 return focused_plugin_->IsPluginAcceptingCompositionEvents(); | 1136 return focused_plugin_->IsPluginAcceptingCompositionEvents(); |
1142 } | 1137 } |
1143 | 1138 |
1144 bool PepperPluginDelegateImpl::CanComposeInline() const { | 1139 bool PepperPluginDelegateImpl::CanComposeInline() const { |
1145 return IsPluginAcceptingCompositionEvents(); | 1140 return IsPluginAcceptingCompositionEvents(); |
1146 } | 1141 } |
1147 | 1142 |
1148 void PepperPluginDelegateImpl::PluginCrashed( | 1143 void PepperPluginDelegateImpl::PluginCrashed( |
1149 webkit::ppapi::PluginInstance* instance) { | 1144 webkit::ppapi::PluginInstance* instance) { |
1150 render_view_->PluginCrashed(instance->module()->path()); | 1145 render_view_->PluginCrashed(instance->module()->path()); |
1151 | 1146 UnSetAndDeleteLockTargetAdapter(instance); |
1152 UnlockMouse(instance); | |
1153 } | 1147 } |
1154 | 1148 |
1155 void PepperPluginDelegateImpl::InstanceCreated( | 1149 void PepperPluginDelegateImpl::InstanceCreated( |
1156 webkit::ppapi::PluginInstance* instance) { | 1150 webkit::ppapi::PluginInstance* instance) { |
1157 active_instances_.insert(instance); | 1151 active_instances_.insert(instance); |
1158 | 1152 |
1159 // Set the initial focus. | 1153 // Set the initial focus. |
1160 instance->SetContentAreaFocus(render_view_->has_focus()); | 1154 instance->SetContentAreaFocus(render_view_->has_focus()); |
1161 } | 1155 } |
1162 | 1156 |
1163 void PepperPluginDelegateImpl::InstanceDeleted( | 1157 void PepperPluginDelegateImpl::InstanceDeleted( |
1164 webkit::ppapi::PluginInstance* instance) { | 1158 webkit::ppapi::PluginInstance* instance) { |
1165 active_instances_.erase(instance); | 1159 active_instances_.erase(instance); |
1160 UnSetAndDeleteLockTargetAdapter(instance); | |
1166 | 1161 |
1167 if (mouse_lock_owner_ && mouse_lock_owner_ == instance) { | |
1168 // UnlockMouse() will determine whether a ViewHostMsg_UnlockMouse needs to | |
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) | 1162 if (last_mouse_event_target_ == instance) |
1175 last_mouse_event_target_ = NULL; | 1163 last_mouse_event_target_ = NULL; |
1176 if (focused_plugin_ == instance) | 1164 if (focused_plugin_ == instance) |
1177 PluginFocusChanged(instance, false); | 1165 PluginFocusChanged(instance, false); |
1178 } | 1166 } |
1179 | 1167 |
1180 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { | 1168 SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { |
1181 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); | 1169 return content::GetContentClient()->renderer()->GetSadPluginBitmap(); |
1182 } | 1170 } |
1183 | 1171 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = | 1342 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = |
1355 active_instances_.begin(); | 1343 active_instances_.begin(); |
1356 i != active_instances_.end(); ++i) | 1344 i != active_instances_.end(); ++i) |
1357 (*i)->PageVisibilityChanged(is_visible); | 1345 (*i)->PageVisibilityChanged(is_visible); |
1358 } | 1346 } |
1359 | 1347 |
1360 bool PepperPluginDelegateImpl::IsPluginFocused() const { | 1348 bool PepperPluginDelegateImpl::IsPluginFocused() const { |
1361 return focused_plugin_ != NULL; | 1349 return focused_plugin_ != NULL; |
1362 } | 1350 } |
1363 | 1351 |
1364 void PepperPluginDelegateImpl::OnLockMouseACK(bool succeeded) { | 1352 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. | 1353 // 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 | 1354 // 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. | 1355 // 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 | 1356 // 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 | 1357 // 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 | 1358 // event, it will notify us via DidReceiveMouseEvent() and set itself as |
1414 // |last_mouse_event_target_|. | 1359 // |last_mouse_event_target_|. |
1415 last_mouse_event_target_ = NULL; | 1360 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 } | 1361 } |
1430 | 1362 |
1431 bool PepperPluginDelegateImpl::OpenFileSystem( | 1363 bool PepperPluginDelegateImpl::OpenFileSystem( |
1432 const GURL& url, | 1364 const GURL& url, |
1433 fileapi::FileSystemType type, | 1365 fileapi::FileSystemType type, |
1434 long long size, | 1366 long long size, |
1435 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1367 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
1436 FileSystemDispatcher* file_system_dispatcher = | 1368 FileSystemDispatcher* file_system_dispatcher = |
1437 ChildThread::current()->file_system_dispatcher(); | 1369 ChildThread::current()->file_system_dispatcher(); |
1438 return file_system_dispatcher->OpenFileSystem( | 1370 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"; | 1888 DLOG(WARNING) << "Browser failed to allocate shared memory"; |
1957 return NULL; | 1889 return NULL; |
1958 } | 1890 } |
1959 return new base::SharedMemory(handle, false); | 1891 return new base::SharedMemory(handle, false); |
1960 } | 1892 } |
1961 | 1893 |
1962 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { | 1894 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { |
1963 return ppapi::Preferences(render_view_->webkit_preferences()); | 1895 return ppapi::Preferences(render_view_->webkit_preferences()); |
1964 } | 1896 } |
1965 | 1897 |
1966 void PepperPluginDelegateImpl::LockMouse( | 1898 bool PepperPluginDelegateImpl::LockMouse( |
1967 webkit::ppapi::PluginInstance* instance) { | 1899 webkit::ppapi::PluginInstance* instance) { |
1968 DCHECK(instance); | |
1969 if (!MouseLockedOrPending()) { | |
1970 DCHECK(!mouse_lock_owner_); | |
1971 pending_lock_request_ = true; | |
1972 mouse_lock_owner_ = instance; | |
1973 | 1900 |
1974 render_view_->Send( | 1901 return render_view_->mouse_lock_dispatcher()->LockMouse( |
1975 new ViewHostMsg_LockMouse(render_view_->routing_id())); | 1902 GetOrCreateLockTargetAdapter(instance)); |
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_->mouse_lock_dispatcher()->UnlockMouse( |
1908 GetOrCreateLockTargetAdapter(instance)); | |
1909 } | |
1997 | 1910 |
1998 // If no one is using mouse lock or the user is not |instance|, ignore | 1911 bool PepperPluginDelegateImpl::IsMouseLocked( |
1999 // the unlock request. | 1912 webkit::ppapi::PluginInstance* instance) { |
2000 if (MouseLockedOrPending() && mouse_lock_owner_ == instance) { | 1913 return render_view_->mouse_lock_dispatcher()->IsMouseLockedTo( |
2001 if (mouse_locked_ || pending_lock_request_) { | 1914 GetOrCreateLockTargetAdapter(instance)); |
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 } | 1915 } |
2017 | 1916 |
2018 void PepperPluginDelegateImpl::DidChangeCursor( | 1917 void PepperPluginDelegateImpl::DidChangeCursor( |
2019 webkit::ppapi::PluginInstance* instance, | 1918 webkit::ppapi::PluginInstance* instance, |
2020 const WebKit::WebCursorInfo& cursor) { | 1919 const WebKit::WebCursorInfo& cursor) { |
2021 // Update the cursor appearance immediately if the requesting plugin is the | 1920 // 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 | 1921 // 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., | 1922 // 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 | 1923 // the plugin would like to set an invisible cursor when there isn't any user |
2025 // input for a while. | 1924 // input for a while. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2165 | 2064 |
2166 bool PepperPluginDelegateImpl::CanUseSocketAPIs() { | 2065 bool PepperPluginDelegateImpl::CanUseSocketAPIs() { |
2167 WebView* webview = render_view_->webview(); | 2066 WebView* webview = render_view_->webview(); |
2168 WebFrame* main_frame = webview ? webview->mainFrame() : NULL; | 2067 WebFrame* main_frame = webview ? webview->mainFrame() : NULL; |
2169 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL()); | 2068 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL()); |
2170 if (!url.is_valid()) | 2069 if (!url.is_valid()) |
2171 return false; | 2070 return false; |
2172 | 2071 |
2173 return content::GetContentClient()->renderer()->AllowSocketAPI(url); | 2072 return content::GetContentClient()->renderer()->AllowSocketAPI(url); |
2174 } | 2073 } |
2074 | |
2075 MouseLockDispatcher::LockTarget* | |
2076 PepperPluginDelegateImpl::GetOrCreateLockTargetAdapter( | |
2077 webkit::ppapi::PluginInstance* instance) { | |
2078 MouseLockDispatcher::LockTarget* target = mouse_lock_instances_[instance]; | |
2079 if (target) | |
2080 return target; | |
2081 | |
2082 return mouse_lock_instances_[instance] = | |
2083 MouseLockDispatcher::CreateLockTarget(instance); | |
yzshen1
2012/01/24 18:56:08
4 space indent, please.
scheib
2012/01/25 00:27:11
Done.
| |
2084 } | |
2085 | |
2086 void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter( | |
2087 webkit::ppapi::PluginInstance* instance) { | |
2088 if (mouse_lock_instances_.find(instance) != mouse_lock_instances_.end()) { | |
2089 render_view_->mouse_lock_dispatcher()->UnlockMouseAndClearTarget( | |
2090 mouse_lock_instances_[instance]); | |
2091 mouse_lock_instances_.erase(instance); | |
piman
2012/01/24 02:27:37
I think you still need to delete the LockTarget he
scheib
2012/01/25 00:27:11
Done.
| |
2092 } | |
2093 } | |
OLD | NEW |