Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: webkit/plugins/npapi/plugin_utils.cc

Issue 19844003: Remove webkit/plugins/npapi. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove GetDefaultWindowParent Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/npapi/plugin_utils.h"
6
7 #include <algorithm>
8
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "base/version.h"
12
13 #if defined(OS_WIN)
14 #include "ui/base/win/hwnd_util.h"
15 #endif
16
17 namespace webkit {
18 namespace npapi {
19
20 // Global variable used by the plugin quirk "die after unload".
21 bool g_forcefully_terminate_plugin_process = false;
22
23 void CreateVersionFromString(const base::string16& version_string,
24 Version* parsed_version) {
25 // Remove spaces and ')' from the version string,
26 // Replace any instances of 'r', ',' or '(' with a dot.
27 std::string version = UTF16ToASCII(version_string);
28 RemoveChars(version, ") ", &version);
29 std::replace(version.begin(), version.end(), 'd', '.');
30 std::replace(version.begin(), version.end(), 'r', '.');
31 std::replace(version.begin(), version.end(), ',', '.');
32 std::replace(version.begin(), version.end(), '(', '.');
33 std::replace(version.begin(), version.end(), '_', '.');
34
35 // Remove leading zeros from each of the version components.
36 std::string no_leading_zeros_version;
37 std::vector<std::string> numbers;
38 base::SplitString(version, '.', &numbers);
39 for (size_t i = 0; i < numbers.size(); ++i) {
40 size_t n = numbers[i].size();
41 size_t j = 0;
42 while (j < n && numbers[i][j] == '0') {
43 ++j;
44 }
45 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0";
46 if (i != numbers.size() - 1) {
47 no_leading_zeros_version += ".";
48 }
49 }
50
51 *parsed_version = Version(no_leading_zeros_version);
52 }
53
54 bool NPAPIPluginsSupported() {
55 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_ AURA))
56 return true;
57 #else
58 return false;
59 #endif
60 }
61
62 void SetForcefullyTerminatePluginProcess(bool value) {
63 g_forcefully_terminate_plugin_process = value;
64 }
65
66 bool ShouldForcefullyTerminatePluginProcess() {
67 return g_forcefully_terminate_plugin_process;
68 }
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
134 } // namespace npapi
135 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698