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_list.h" | 5 #include "webkit/plugins/npapi/plugin_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/cpu.h" | |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/sha1.h" | 12 #include "base/sha1.h" |
12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
13 #include "base/string_split.h" | 14 #include "base/string_split.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 | 17 |
17 namespace webkit { | 18 namespace webkit { |
18 namespace npapi { | 19 namespace npapi { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // We build up a list of files and mtimes so we can sort them. | 23 // We build up a list of files and mtimes so we can sort them. |
23 typedef std::pair<FilePath, base::Time> FileAndTime; | 24 typedef std::pair<FilePath, base::Time> FileAndTime; |
24 typedef std::vector<FileAndTime> FileTimeList; | 25 typedef std::vector<FileAndTime> FileTimeList; |
25 | 26 |
27 enum PluginQuark { | |
Bernhard Bauer
2012/08/02 03:18:19
Do you mean quirk? Or am I missing something and w
Lei Zhang
2012/08/02 03:25:12
Done.
| |
28 // No quarks - plugin is outright banned. | |
29 PLUGIN_QUARK_NONE = 0, | |
30 // Plugin is using SSE2 instructions without checking for SSE2 instruction | |
31 // support. Ban the plugin if the system has no SSE2 support. | |
32 PLUGIN_QUARK_MISSING_SSE2_CHECK = 1 << 0, | |
33 }; | |
34 | |
26 // Comparator used to sort by descending mtime then ascending filename. | 35 // Comparator used to sort by descending mtime then ascending filename. |
27 bool CompareTime(const FileAndTime& a, const FileAndTime& b) { | 36 bool CompareTime(const FileAndTime& a, const FileAndTime& b) { |
28 if (a.second == b.second) { | 37 if (a.second == b.second) { |
29 // Fall back on filename sorting, just to make the predicate valid. | 38 // Fall back on filename sorting, just to make the predicate valid. |
30 return a.first < b.first; | 39 return a.first < b.first; |
31 } | 40 } |
32 | 41 |
33 // Sort by mtime, descending. | 42 // Sort by mtime, descending. |
34 return a.second > b.second; | 43 return a.second > b.second; |
35 } | 44 } |
36 | 45 |
46 // Checks to see if the current environment meets any of the condtions set in | |
47 // |quarks|. Returns true if any of the conditions are met, or if |quarks| is | |
48 // PLUGIN_QUARK_NONE. | |
49 bool CheckQuarks(PluginQuark quarks) { | |
50 if (quarks == PLUGIN_QUARK_NONE) | |
Bernhard Bauer
2012/08/02 03:18:19
Can you convert this to a switch statement so that
Lei Zhang
2012/08/02 03:25:12
I hope we don't have to do this very often, but po
Bernhard Bauer
2012/08/02 04:10:31
Oh right, it's a bit field.
| |
51 return true; | |
52 | |
53 if ((quarks & PLUGIN_QUARK_MISSING_SSE2_CHECK) != 0) { | |
54 base::CPU cpu; | |
55 if (!cpu.has_sse2()) { | |
Bernhard Bauer
2012/08/02 03:18:19
Nit: no braces?
Lei Zhang
2012/08/02 03:25:12
Done.
| |
56 return true; | |
57 } | |
58 } | |
59 | |
60 return false; | |
61 } | |
62 | |
37 // Return true if |path| matches a known (file size, sha1sum) pair. | 63 // Return true if |path| matches a known (file size, sha1sum) pair. |
64 // Also check against any PluginQuarks the bad plugin may have. | |
38 // The use of the file size is an optimization so we don't have to read in | 65 // The use of the file size is an optimization so we don't have to read in |
39 // the entire file unless we have to. | 66 // the entire file unless we have to. |
40 bool IsBlacklistedBySha1sum(const FilePath& path) { | 67 bool IsBlacklistedBySha1sumAndQuarks(const FilePath& path) { |
41 const struct BadEntry { | 68 const struct BadEntry { |
42 int64 size; | 69 int64 size; |
43 std::string sha1; | 70 std::string sha1; |
71 PluginQuark quarks; | |
44 } bad_entries[] = { | 72 } bad_entries[] = { |
45 // Flash 9 r31 - http://crbug.com/29237 | 73 // Flash 9 r31 - http://crbug.com/29237 |
46 { 7040080, "fa5803061125ca47846713b34a26a42f1f1e98bb" }, | 74 { 7040080, "fa5803061125ca47846713b34a26a42f1f1e98bb", PLUGIN_QUARK_NONE }, |
47 // Flash 9 r48 - http://crbug.com/29237 | 75 // Flash 9 r48 - http://crbug.com/29237 |
48 { 7040036, "0c4b3768a6d4bfba003088e4b9090d381de1af2b" }, | 76 { 7040036, "0c4b3768a6d4bfba003088e4b9090d381de1af2b", PLUGIN_QUARK_NONE }, |
77 // Flash 11.2.202.236, 32-bit - http://crbug.com/140086 | |
78 { 17406436, "1e07eac912faf9426c52a288c76c3b6238f90b6b", | |
79 PLUGIN_QUARK_MISSING_SSE2_CHECK }, | |
49 }; | 80 }; |
50 | 81 |
51 int64 size; | 82 int64 size; |
52 if (!file_util::GetFileSize(path, &size)) | 83 if (!file_util::GetFileSize(path, &size)) |
53 return false; | 84 return false; |
54 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bad_entries); i++) { | 85 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bad_entries); i++) { |
55 if (bad_entries[i].size != size) | 86 if (bad_entries[i].size != size) |
56 continue; | 87 continue; |
57 | 88 |
58 std::string file_content; | 89 std::string file_content; |
59 if (!file_util::ReadFileToString(path, &file_content)) | 90 if (!file_util::ReadFileToString(path, &file_content)) |
60 continue; | 91 continue; |
61 std::string sha1 = base::SHA1HashString(file_content); | 92 std::string sha1 = base::SHA1HashString(file_content); |
62 std::string sha1_readable; | 93 std::string sha1_readable; |
63 for (size_t j = 0; j < sha1.size(); j++) | 94 for (size_t j = 0; j < sha1.size(); j++) |
64 base::StringAppendF(&sha1_readable, "%02x", sha1[j] & 0xFF); | 95 base::StringAppendF(&sha1_readable, "%02x", sha1[j] & 0xFF); |
65 if (bad_entries[i].sha1 == sha1_readable) | 96 if (bad_entries[i].sha1 == sha1_readable) |
66 return true; | 97 return CheckQuarks(bad_entries[i].quarks); |
67 } | 98 } |
68 return false; | 99 return false; |
69 } | 100 } |
70 | 101 |
71 // Some plugins are shells around other plugins; we prefer to use the | 102 // Some plugins are shells around other plugins; we prefer to use the |
72 // real plugin directly, if it's available. This function returns | 103 // real plugin directly, if it's available. This function returns |
73 // true if we should prefer other plugins over this one. We'll still | 104 // true if we should prefer other plugins over this one. We'll still |
74 // use a "undesirable" plugin if no other option is available. | 105 // use a "undesirable" plugin if no other option is available. |
75 bool IsUndesirablePlugin(const WebPluginInfo& info) { | 106 bool IsUndesirablePlugin(const WebPluginInfo& info) { |
76 std::string filename = info.path.BaseName().value(); | 107 std::string filename = info.path.BaseName().value(); |
(...skipping 16 matching lines...) Expand all Loading... | |
93 bool IsBlacklistedPlugin(const FilePath& path) { | 124 bool IsBlacklistedPlugin(const FilePath& path) { |
94 const char* kBlackListedPlugins[] = { | 125 const char* kBlackListedPlugins[] = { |
95 "nppdf.so", // Adobe PDF | 126 "nppdf.so", // Adobe PDF |
96 }; | 127 }; |
97 std::string filename = path.BaseName().value(); | 128 std::string filename = path.BaseName().value(); |
98 for (size_t i = 0; i < arraysize(kBlackListedPlugins); i++) { | 129 for (size_t i = 0; i < arraysize(kBlackListedPlugins); i++) { |
99 if (filename.find(kBlackListedPlugins[i]) != std::string::npos) { | 130 if (filename.find(kBlackListedPlugins[i]) != std::string::npos) { |
100 return true; | 131 return true; |
101 } | 132 } |
102 } | 133 } |
103 return IsBlacklistedBySha1sum(path); | 134 return IsBlacklistedBySha1sumAndQuarks(path); |
104 } | 135 } |
105 | 136 |
106 } // namespace | 137 } // namespace |
107 | 138 |
108 void PluginList::PlatformInit() { | 139 void PluginList::PlatformInit() { |
109 } | 140 } |
110 | 141 |
111 void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) { | 142 void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) { |
112 // See http://groups.google.com/group/chromium-dev/browse_thread/thread/7a70e5 fcbac786a9 | 143 // See http://groups.google.com/group/chromium-dev/browse_thread/thread/7a70e5 fcbac786a9 |
113 // for discussion. | 144 // for discussion. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 | 296 |
266 // TODO(evanm): prefer the newest version of flash, etc. here? | 297 // TODO(evanm): prefer the newest version of flash, etc. here? |
267 | 298 |
268 VLOG_IF(1, PluginList::DebugPluginLoading()) << "Using " << info.path.value(); | 299 VLOG_IF(1, PluginList::DebugPluginLoading()) << "Using " << info.path.value(); |
269 | 300 |
270 return true; | 301 return true; |
271 } | 302 } |
272 | 303 |
273 } // namespace npapi | 304 } // namespace npapi |
274 } // namespace webkit | 305 } // namespace webkit |
OLD | NEW |