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 ATOM plugin_atom = reinterpret_cast<ATOM>( |
| 271 GetPropW(window, plugin_atom_property)); |
| 272 if (plugin_atom != 0) { |
| 273 WCHAR plugin_property_local[MAX_PATH] = {0}; |
| 274 GlobalGetAtomNameW(plugin_atom, |
| 275 plugin_property_local, |
| 276 ARRAYSIZE(plugin_property_local)); |
| 277 *plugin_property = plugin_property_local; |
| 278 return true; |
| 279 } |
| 280 return false; |
| 281 } |
| 282 |
266 } // namespace | 283 } // namespace |
267 | 284 |
268 bool WebPluginDelegateImpl::IsPluginDelegateWindow(HWND window) { | 285 bool WebPluginDelegateImpl::IsPluginDelegateWindow(HWND window) { |
269 static const int kBufLen = 64; | 286 static const int kBufLen = 64; |
270 wchar_t class_name[kBufLen]; | 287 wchar_t class_name[kBufLen]; |
271 if (!GetClassNameW(window, class_name, kBufLen)) | 288 if (!GetClassNameW(window, class_name, kBufLen)) |
272 return false; | 289 return false; |
273 return wcscmp(class_name, kNativeWindowClassName) == 0; | 290 return wcscmp(class_name, kNativeWindowClassName) == 0; |
274 } | 291 } |
275 | 292 |
276 // static | 293 // static |
277 bool WebPluginDelegateImpl::GetPluginNameFromWindow( | 294 bool WebPluginDelegateImpl::GetPluginNameFromWindow( |
278 HWND window, string16* plugin_name) { | 295 HWND window, string16* plugin_name) { |
279 if (NULL == plugin_name) { | 296 return IsPluginDelegateWindow(window) && |
280 return false; | 297 GetPluginPropertyFromWindow( |
281 } | 298 window, kPluginNameAtomProperty, plugin_name); |
282 if (!IsPluginDelegateWindow(window)) { | 299 } |
283 return false; | 300 |
284 } | 301 // static |
285 ATOM plugin_name_atom = reinterpret_cast<ATOM>( | 302 bool WebPluginDelegateImpl::GetPluginVersionFromWindow( |
286 GetPropW(window, kPluginNameAtomProperty)); | 303 HWND window, string16* plugin_version) { |
287 if (plugin_name_atom != 0) { | 304 return IsPluginDelegateWindow(window) && |
288 WCHAR plugin_name_local[MAX_PATH] = {0}; | 305 GetPluginPropertyFromWindow( |
289 GlobalGetAtomNameW(plugin_name_atom, | 306 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 } | 307 } |
297 | 308 |
298 bool WebPluginDelegateImpl::IsDummyActivationWindow(HWND window) { | 309 bool WebPluginDelegateImpl::IsDummyActivationWindow(HWND window) { |
299 if (!IsWindow(window)) | 310 if (!IsWindow(window)) |
300 return false; | 311 return false; |
301 | 312 |
302 wchar_t window_title[MAX_PATH + 1] = {0}; | 313 wchar_t window_title[MAX_PATH + 1] = {0}; |
303 if (GetWindowText(window, window_title, arraysize(window_title))) { | 314 if (GetWindowText(window, window_title, arraysize(window_title))) { |
304 return (0 == lstrcmpiW(window_title, kDummyActivationWindowName)); | 315 return (0 == lstrcmpiW(window_title, kDummyActivationWindowName)); |
305 } | 316 } |
(...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. | 699 // this window should be a child window of the parent window. |
689 // To satisfy both of the above conditions, this code once creates a | 700 // 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. | 701 // top-level window and change it to a child window of the parent window. |
691 SetWindowLongPtr(windowed_handle_, GWL_STYLE, | 702 SetWindowLongPtr(windowed_handle_, GWL_STYLE, |
692 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); | 703 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); |
693 SetParent(windowed_handle_, parent_); | 704 SetParent(windowed_handle_, parent_); |
694 } | 705 } |
695 | 706 |
696 BOOL result = SetProp(windowed_handle_, kWebPluginDelegateProperty, this); | 707 BOOL result = SetProp(windowed_handle_, kWebPluginDelegateProperty, this); |
697 DCHECK(result == TRUE) << "SetProp failed, last error = " << GetLastError(); | 708 DCHECK(result == TRUE) << "SetProp failed, last error = " << GetLastError(); |
698 // Get the name of the plugin, create an atom and set that in a window | 709 // 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 | 710 // window property. Use atoms so that other processes can access the name and |
700 // the plugin that this window is hosting | 711 // version of the plugin that this window is hosting. |
701 if (instance_ != NULL) { | 712 if (instance_ != NULL) { |
702 PluginLib* plugin_lib = instance()->plugin_lib(); | 713 PluginLib* plugin_lib = instance()->plugin_lib(); |
703 if (plugin_lib != NULL) { | 714 if (plugin_lib != NULL) { |
704 std::wstring plugin_name = plugin_lib->plugin_info().name; | 715 std::wstring plugin_name = plugin_lib->plugin_info().name; |
705 if (!plugin_name.empty()) { | 716 if (!plugin_name.empty()) { |
706 ATOM plugin_name_atom = GlobalAddAtomW(plugin_name.c_str()); | 717 ATOM plugin_name_atom = GlobalAddAtomW(plugin_name.c_str()); |
707 DCHECK(0 != plugin_name_atom); | 718 DCHECK(0 != plugin_name_atom); |
708 result = SetProp(windowed_handle_, | 719 result = SetProp(windowed_handle_, |
709 kPluginNameAtomProperty, | 720 kPluginNameAtomProperty, |
710 reinterpret_cast<HANDLE>(plugin_name_atom)); | 721 reinterpret_cast<HANDLE>(plugin_name_atom)); |
711 DCHECK(result == TRUE) << "SetProp failed, last error = " << | 722 DCHECK(result == TRUE) << "SetProp failed, last error = " << |
712 GetLastError(); | 723 GetLastError(); |
713 } | 724 } |
| 725 string16 plugin_version = plugin_lib->plugin_info().version; |
| 726 if (!plugin_version.empty()) { |
| 727 ATOM plugin_version_atom = GlobalAddAtomW(plugin_version.c_str()); |
| 728 DCHECK(0 != plugin_version_atom); |
| 729 result = SetProp(windowed_handle_, |
| 730 kPluginVersionAtomProperty, |
| 731 reinterpret_cast<HANDLE>(plugin_version_atom)); |
| 732 DCHECK(result == TRUE) << "SetProp failed, last error = " << |
| 733 GetLastError(); |
| 734 } |
714 } | 735 } |
715 } | 736 } |
716 | 737 |
717 // Calling SetWindowLongPtrA here makes the window proc ASCII, which is | 738 // Calling SetWindowLongPtrA here makes the window proc ASCII, which is |
718 // required by at least the Shockwave Director plug-in. | 739 // required by at least the Shockwave Director plug-in. |
719 SetWindowLongPtrA( | 740 SetWindowLongPtrA( |
720 windowed_handle_, GWL_WNDPROC, reinterpret_cast<LONG>(DefWindowProcA)); | 741 windowed_handle_, GWL_WNDPROC, reinterpret_cast<LONG>(DefWindowProcA)); |
721 | 742 |
722 return true; | 743 return true; |
723 } | 744 } |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 | 1221 |
1201 delegate->is_calling_wndproc = false; | 1222 delegate->is_calling_wndproc = false; |
1202 g_current_plugin_instance = last_plugin_instance; | 1223 g_current_plugin_instance = last_plugin_instance; |
1203 | 1224 |
1204 if (message == WM_NCDESTROY) { | 1225 if (message == WM_NCDESTROY) { |
1205 RemoveProp(hwnd, kWebPluginDelegateProperty); | 1226 RemoveProp(hwnd, kWebPluginDelegateProperty); |
1206 ATOM plugin_name_atom = reinterpret_cast<ATOM>( | 1227 ATOM plugin_name_atom = reinterpret_cast<ATOM>( |
1207 RemoveProp(hwnd, kPluginNameAtomProperty)); | 1228 RemoveProp(hwnd, kPluginNameAtomProperty)); |
1208 if (plugin_name_atom != 0) | 1229 if (plugin_name_atom != 0) |
1209 GlobalDeleteAtom(plugin_name_atom); | 1230 GlobalDeleteAtom(plugin_name_atom); |
| 1231 ATOM plugin_version_atom = reinterpret_cast<ATOM>( |
| 1232 RemoveProp(hwnd, kPluginVersionAtomProperty)); |
| 1233 if (plugin_version_atom != 0) |
| 1234 GlobalDeleteAtom(plugin_version_atom); |
1210 ClearThrottleQueueForWindow(hwnd); | 1235 ClearThrottleQueueForWindow(hwnd); |
1211 } | 1236 } |
1212 } | 1237 } |
1213 delegate->last_message_ = old_message; | 1238 delegate->last_message_ = old_message; |
1214 return result; | 1239 return result; |
1215 } | 1240 } |
1216 | 1241 |
1217 void WebPluginDelegateImpl::WindowlessUpdateGeometry( | 1242 void WebPluginDelegateImpl::WindowlessUpdateGeometry( |
1218 const gfx::Rect& window_rect, | 1243 const gfx::Rect& window_rect, |
1219 const gfx::Rect& clip_rect) { | 1244 const gfx::Rect& clip_rect) { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 ::ReleaseCapture(); | 1697 ::ReleaseCapture(); |
1673 break; | 1698 break; |
1674 | 1699 |
1675 default: | 1700 default: |
1676 break; | 1701 break; |
1677 } | 1702 } |
1678 } | 1703 } |
1679 | 1704 |
1680 } // namespace npapi | 1705 } // namespace npapi |
1681 } // namespace webkit | 1706 } // namespace webkit |
OLD | NEW |