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 "webkit/plugins/npapi/plugin_utils.h" | 5 #include "webkit/plugins/npapi/plugin_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/version.h" | 11 #include "base/version.h" |
12 | 12 |
| 13 #if defined(OS_WIN) |
| 14 #include "ui/base/win/hwnd_util.h" |
| 15 #endif |
| 16 |
13 namespace webkit { | 17 namespace webkit { |
14 namespace npapi { | 18 namespace npapi { |
15 | 19 |
16 // Global variable used by the plugin quirk "die after unload". | 20 // Global variable used by the plugin quirk "die after unload". |
17 bool g_forcefully_terminate_plugin_process = false; | 21 bool g_forcefully_terminate_plugin_process = false; |
18 | 22 |
19 void CreateVersionFromString(const base::string16& version_string, | 23 void CreateVersionFromString(const base::string16& version_string, |
20 Version* parsed_version) { | 24 Version* parsed_version) { |
21 // Remove spaces and ')' from the version string, | 25 // Remove spaces and ')' from the version string, |
22 // Replace any instances of 'r', ',' or '(' with a dot. | 26 // Replace any instances of 'r', ',' or '(' with a dot. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 60 } |
57 | 61 |
58 void SetForcefullyTerminatePluginProcess(bool value) { | 62 void SetForcefullyTerminatePluginProcess(bool value) { |
59 g_forcefully_terminate_plugin_process = value; | 63 g_forcefully_terminate_plugin_process = value; |
60 } | 64 } |
61 | 65 |
62 bool ShouldForcefullyTerminatePluginProcess() { | 66 bool ShouldForcefullyTerminatePluginProcess() { |
63 return g_forcefully_terminate_plugin_process; | 67 return g_forcefully_terminate_plugin_process; |
64 } | 68 } |
65 | 69 |
| 70 #if defined(OS_WIN) |
| 71 |
| 72 const char16 kNativeWindowClassName[] = L"NativeWindowClass"; |
| 73 const char16 kPluginNameAtomProperty[] = L"PluginNameAtom"; |
| 74 const char16 kPluginVersionAtomProperty[] = L"PluginVersionAtom"; |
| 75 const char16 kDummyActivationWindowName[] = L"DummyWindowForActivation"; |
| 76 |
| 77 namespace { |
| 78 |
| 79 bool GetPluginPropertyFromWindow( |
| 80 HWND window, const wchar_t* plugin_atom_property, |
| 81 base::string16* plugin_property) { |
| 82 ATOM plugin_atom = reinterpret_cast<ATOM>( |
| 83 GetPropW(window, plugin_atom_property)); |
| 84 if (plugin_atom != 0) { |
| 85 WCHAR plugin_property_local[MAX_PATH] = {0}; |
| 86 GlobalGetAtomNameW(plugin_atom, |
| 87 plugin_property_local, |
| 88 ARRAYSIZE(plugin_property_local)); |
| 89 *plugin_property = plugin_property_local; |
| 90 return true; |
| 91 } |
| 92 return false; |
| 93 } |
| 94 |
| 95 } // namespace |
| 96 |
| 97 bool IsPluginDelegateWindow(HWND window) { |
| 98 return ui::GetClassName(window) == base::string16(kNativeWindowClassName); |
| 99 } |
| 100 |
| 101 // static |
| 102 bool GetPluginNameFromWindow( |
| 103 HWND window, base::string16* plugin_name) { |
| 104 return IsPluginDelegateWindow(window) && |
| 105 GetPluginPropertyFromWindow( |
| 106 window, kPluginNameAtomProperty, plugin_name); |
| 107 } |
| 108 |
| 109 // static |
| 110 bool GetPluginVersionFromWindow( |
| 111 HWND window, base::string16* plugin_version) { |
| 112 return IsPluginDelegateWindow(window) && |
| 113 GetPluginPropertyFromWindow( |
| 114 window, kPluginVersionAtomProperty, plugin_version); |
| 115 } |
| 116 |
| 117 bool IsDummyActivationWindow(HWND window) { |
| 118 if (!IsWindow(window)) |
| 119 return false; |
| 120 |
| 121 wchar_t window_title[MAX_PATH + 1] = {0}; |
| 122 if (GetWindowText(window, window_title, arraysize(window_title))) { |
| 123 return (0 == lstrcmpiW(window_title, kDummyActivationWindowName)); |
| 124 } |
| 125 return false; |
| 126 } |
| 127 |
| 128 HWND GetDefaultWindowParent() { |
| 129 return GetDesktopWindow(); |
| 130 } |
| 131 |
| 132 #endif |
| 133 |
66 } // namespace npapi | 134 } // namespace npapi |
67 } // namespace webkit | 135 } // namespace webkit |
OLD | NEW |