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/npapi/webplugin_delegate_impl.h" | 5 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... | |
41 using WebKit::WebInputEvent; | 41 using WebKit::WebInputEvent; |
42 using WebKit::WebMouseEvent; | 42 using WebKit::WebMouseEvent; |
43 | 43 |
44 namespace webkit { | 44 namespace webkit { |
45 namespace npapi { | 45 namespace npapi { |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 const wchar_t kWebPluginDelegateProperty[] = L"WebPluginDelegateProperty"; | 49 const wchar_t kWebPluginDelegateProperty[] = L"WebPluginDelegateProperty"; |
50 const wchar_t kPluginNameAtomProperty[] = L"PluginNameAtom"; | 50 const wchar_t kPluginNameAtomProperty[] = L"PluginNameAtom"; |
51 const wchar_t kPluginVersionAtomProperty[] = L"PluginVersionAtom"; | |
51 const wchar_t kDummyActivationWindowName[] = L"DummyWindowForActivation"; | 52 const wchar_t kDummyActivationWindowName[] = L"DummyWindowForActivation"; |
52 const wchar_t kPluginFlashThrottle[] = L"FlashThrottle"; | 53 const wchar_t kPluginFlashThrottle[] = L"FlashThrottle"; |
53 | 54 |
54 // The fastest we are willing to process WM_USER+1 events for Flash. | 55 // The fastest we are willing to process WM_USER+1 events for Flash. |
55 // Flash can easily exceed the limits of our CPU if we don't throttle it. | 56 // Flash can easily exceed the limits of our CPU if we don't throttle it. |
56 // The throttle has been chosen by testing various delays and compromising | 57 // The throttle has been chosen by testing various delays and compromising |
57 // on acceptable Flash performance and reasonable CPU consumption. | 58 // on acceptable Flash performance and reasonable CPU consumption. |
58 // | 59 // |
59 // I'd like to make the throttle delay variable, based on the amount of | 60 // I'd like to make the throttle delay variable, based on the amount of |
60 // time currently required to paint Flash plugins. There isn't a good | 61 // time currently required to paint Flash plugins. There isn't a good |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 int GetPluginMajorVersion(const WebPluginInfo& plugin_info) { | 257 int GetPluginMajorVersion(const WebPluginInfo& plugin_info) { |
257 scoped_ptr<Version> plugin_version(PluginGroup::CreateVersionFromString( | 258 scoped_ptr<Version> plugin_version(PluginGroup::CreateVersionFromString( |
258 plugin_info.version)); | 259 plugin_info.version)); |
259 int major_version = 0; | 260 int major_version = 0; |
260 if (plugin_version.get()) { | 261 if (plugin_version.get()) { |
261 major_version = plugin_version->components()[0]; | 262 major_version = plugin_version->components()[0]; |
262 } | 263 } |
263 return major_version; | 264 return major_version; |
264 } | 265 } |
265 | 266 |
267 bool GetPluginPropertyFromWindow( | |
268 HWND window, const wchar_t* plugin_atom_property, | |
269 string16* plugin_property) { | |
270 if (NULL == plugin_atom_property || NULL == plugin_property) { | |
jam
2012/04/03 16:18:02
nit: this isn't necessary, if someone passes in NU
whyuan
2012/04/03 17:35:07
Done.
| |
271 return false; | |
272 } | |
273 ATOM plugin_atom = reinterpret_cast<ATOM>( | |
274 GetPropW(window, plugin_atom_property)); | |
275 if (plugin_atom != 0) { | |
276 WCHAR plugin_property_local[MAX_PATH] = {0}; | |
277 GlobalGetAtomNameW(plugin_atom, | |
278 plugin_property_local, | |
279 ARRAYSIZE(plugin_property_local)); | |
280 *plugin_property = plugin_property_local; | |
281 return true; | |
282 } | |
283 return false; | |
284 } | |
285 | |
266 } // namespace | 286 } // namespace |
267 | 287 |
268 bool WebPluginDelegateImpl::IsPluginDelegateWindow(HWND window) { | 288 bool WebPluginDelegateImpl::IsPluginDelegateWindow(HWND window) { |
269 static const int kBufLen = 64; | 289 static const int kBufLen = 64; |
270 wchar_t class_name[kBufLen]; | 290 wchar_t class_name[kBufLen]; |
271 if (!GetClassNameW(window, class_name, kBufLen)) | 291 if (!GetClassNameW(window, class_name, kBufLen)) |
272 return false; | 292 return false; |
273 return wcscmp(class_name, kNativeWindowClassName) == 0; | 293 return wcscmp(class_name, kNativeWindowClassName) == 0; |
274 } | 294 } |
275 | 295 |
276 // static | 296 // static |
277 bool WebPluginDelegateImpl::GetPluginNameFromWindow( | 297 bool WebPluginDelegateImpl::GetPluginNameFromWindow( |
278 HWND window, string16* plugin_name) { | 298 HWND window, string16* plugin_name) { |
279 if (NULL == plugin_name) { | 299 return IsPluginDelegateWindow(window) && |
280 return false; | 300 GetPluginPropertyFromWindow( |
jam
2012/04/03 16:18:02
nit: here and below, indentation is 4 spaces
whyuan
2012/04/03 17:35:07
Done.
| |
281 } | 301 window, kPluginNameAtomProperty, plugin_name); |
282 if (!IsPluginDelegateWindow(window)) { | 302 } |
283 return false; | 303 |
284 } | 304 // static |
285 ATOM plugin_name_atom = reinterpret_cast<ATOM>( | 305 bool WebPluginDelegateImpl::GetPluginVersionFromWindow( |
286 GetPropW(window, kPluginNameAtomProperty)); | 306 HWND window, string16* plugin_version) { |
287 if (plugin_name_atom != 0) { | 307 return IsPluginDelegateWindow(window) && |
288 WCHAR plugin_name_local[MAX_PATH] = {0}; | 308 GetPluginPropertyFromWindow( |
289 GlobalGetAtomNameW(plugin_name_atom, | 309 window, kPluginVersionAtomProperty, plugin_version); |
290 plugin_name_local, | |
291 ARRAYSIZE(plugin_name_local)); | |
292 *plugin_name = plugin_name_local; | |
293 return true; | |
294 } | |
295 return false; | |
296 } | 310 } |
297 | 311 |
298 bool WebPluginDelegateImpl::IsDummyActivationWindow(HWND window) { | 312 bool WebPluginDelegateImpl::IsDummyActivationWindow(HWND window) { |
299 if (!IsWindow(window)) | 313 if (!IsWindow(window)) |
300 return false; | 314 return false; |
301 | 315 |
302 wchar_t window_title[MAX_PATH + 1] = {0}; | 316 wchar_t window_title[MAX_PATH + 1] = {0}; |
303 if (GetWindowText(window, window_title, arraysize(window_title))) { | 317 if (GetWindowText(window, window_title, arraysize(window_title))) { |
304 return (0 == lstrcmpiW(window_title, kDummyActivationWindowName)); | 318 return (0 == lstrcmpiW(window_title, kDummyActivationWindowName)); |
305 } | 319 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 // this window should be a child window of the parent window. | 702 // this window should be a child window of the parent window. |
689 // To satisfy both of the above conditions, this code once creates a | 703 // To satisfy both of the above conditions, this code once creates a |
690 // top-level window and change it to a child window of the parent window. | 704 // top-level window and change it to a child window of the parent window. |
691 SetWindowLongPtr(windowed_handle_, GWL_STYLE, | 705 SetWindowLongPtr(windowed_handle_, GWL_STYLE, |
692 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); | 706 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); |
693 SetParent(windowed_handle_, parent_); | 707 SetParent(windowed_handle_, parent_); |
694 } | 708 } |
695 | 709 |
696 BOOL result = SetProp(windowed_handle_, kWebPluginDelegateProperty, this); | 710 BOOL result = SetProp(windowed_handle_, kWebPluginDelegateProperty, this); |
697 DCHECK(result == TRUE) << "SetProp failed, last error = " << GetLastError(); | 711 DCHECK(result == TRUE) << "SetProp failed, last error = " << GetLastError(); |
698 // Get the name of the plugin, create an atom and set that in a window | 712 // Get the name and version of the plugin, create atoms and set them in a |
699 // property. Use an atom so that other processes can access the name of | 713 // window property. Use atoms so that other processes can access the name and |
700 // the plugin that this window is hosting | 714 // version of the plugin that this window is hosting. |
701 if (instance_ != NULL) { | 715 if (instance_ != NULL) { |
702 PluginLib* plugin_lib = instance()->plugin_lib(); | 716 PluginLib* plugin_lib = instance()->plugin_lib(); |
703 if (plugin_lib != NULL) { | 717 if (plugin_lib != NULL) { |
704 std::wstring plugin_name = plugin_lib->plugin_info().name; | 718 std::wstring plugin_name = plugin_lib->plugin_info().name; |
705 if (!plugin_name.empty()) { | 719 if (!plugin_name.empty()) { |
706 ATOM plugin_name_atom = GlobalAddAtomW(plugin_name.c_str()); | 720 ATOM plugin_name_atom = GlobalAddAtomW(plugin_name.c_str()); |
707 DCHECK(0 != plugin_name_atom); | 721 DCHECK(0 != plugin_name_atom); |
708 result = SetProp(windowed_handle_, | 722 result = SetProp(windowed_handle_, |
709 kPluginNameAtomProperty, | 723 kPluginNameAtomProperty, |
710 reinterpret_cast<HANDLE>(plugin_name_atom)); | 724 reinterpret_cast<HANDLE>(plugin_name_atom)); |
711 DCHECK(result == TRUE) << "SetProp failed, last error = " << | 725 DCHECK(result == TRUE) << "SetProp failed, last error = " << |
712 GetLastError(); | 726 GetLastError(); |
713 } | 727 } |
728 std::wstring plugin_version = plugin_lib->plugin_info().version; | |
729 if (!plugin_version.empty()) { | |
730 ATOM plugin_version_atom = GlobalAddAtomW(plugin_version.c_str()); | |
731 DCHECK(0 != plugin_version_atom); | |
732 result = SetProp(windowed_handle_, | |
733 kPluginVersionAtomProperty, | |
734 reinterpret_cast<HANDLE>(plugin_version_atom)); | |
735 DCHECK(result == TRUE) << "SetProp failed, last error = " << | |
736 GetLastError(); | |
737 } | |
714 } | 738 } |
715 } | 739 } |
716 | 740 |
717 // Calling SetWindowLongPtrA here makes the window proc ASCII, which is | 741 // Calling SetWindowLongPtrA here makes the window proc ASCII, which is |
718 // required by at least the Shockwave Director plug-in. | 742 // required by at least the Shockwave Director plug-in. |
719 SetWindowLongPtrA( | 743 SetWindowLongPtrA( |
720 windowed_handle_, GWL_WNDPROC, reinterpret_cast<LONG>(DefWindowProcA)); | 744 windowed_handle_, GWL_WNDPROC, reinterpret_cast<LONG>(DefWindowProcA)); |
721 | 745 |
722 return true; | 746 return true; |
723 } | 747 } |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1200 | 1224 |
1201 delegate->is_calling_wndproc = false; | 1225 delegate->is_calling_wndproc = false; |
1202 g_current_plugin_instance = last_plugin_instance; | 1226 g_current_plugin_instance = last_plugin_instance; |
1203 | 1227 |
1204 if (message == WM_NCDESTROY) { | 1228 if (message == WM_NCDESTROY) { |
1205 RemoveProp(hwnd, kWebPluginDelegateProperty); | 1229 RemoveProp(hwnd, kWebPluginDelegateProperty); |
1206 ATOM plugin_name_atom = reinterpret_cast<ATOM>( | 1230 ATOM plugin_name_atom = reinterpret_cast<ATOM>( |
1207 RemoveProp(hwnd, kPluginNameAtomProperty)); | 1231 RemoveProp(hwnd, kPluginNameAtomProperty)); |
1208 if (plugin_name_atom != 0) | 1232 if (plugin_name_atom != 0) |
1209 GlobalDeleteAtom(plugin_name_atom); | 1233 GlobalDeleteAtom(plugin_name_atom); |
1234 ATOM plugin_version_atom = reinterpret_cast<ATOM>( | |
1235 RemoveProp(hwnd, kPluginVersionAtomProperty)); | |
1236 if (plugin_version_atom != 0) | |
1237 GlobalDeleteAtom(plugin_version_atom); | |
1210 ClearThrottleQueueForWindow(hwnd); | 1238 ClearThrottleQueueForWindow(hwnd); |
1211 } | 1239 } |
1212 } | 1240 } |
1213 delegate->last_message_ = old_message; | 1241 delegate->last_message_ = old_message; |
1214 return result; | 1242 return result; |
1215 } | 1243 } |
1216 | 1244 |
1217 void WebPluginDelegateImpl::WindowlessUpdateGeometry( | 1245 void WebPluginDelegateImpl::WindowlessUpdateGeometry( |
1218 const gfx::Rect& window_rect, | 1246 const gfx::Rect& window_rect, |
1219 const gfx::Rect& clip_rect) { | 1247 const gfx::Rect& clip_rect) { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1672 ::ReleaseCapture(); | 1700 ::ReleaseCapture(); |
1673 break; | 1701 break; |
1674 | 1702 |
1675 default: | 1703 default: |
1676 break; | 1704 break; |
1677 } | 1705 } |
1678 } | 1706 } |
1679 | 1707 |
1680 } // namespace npapi | 1708 } // namespace npapi |
1681 } // namespace webkit | 1709 } // namespace webkit |
OLD | NEW |