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/plugin_list.h" | 5 #include "content/common/plugin_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "net/base/mime_util.h" | 16 #include "net/base/mime_util.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 #include "webkit/plugins/npapi/plugin_utils.h" | 18 #include "webkit/plugins/npapi/plugin_utils.h" |
19 #include "webkit/plugins/plugin_switches.h" | 19 #include "webkit/plugins/plugin_switches.h" |
20 | 20 |
21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
22 #include "webkit/plugins/npapi/plugin_constants_win.h" | 22 #include "content/common/plugin_constants_win.h" |
23 #endif | 23 #endif |
24 | 24 |
| 25 using webkit::WebPluginInfo; |
| 26 using webkit::WebPluginMimeType; |
| 27 |
| 28 namespace content { |
| 29 |
25 namespace { | 30 namespace { |
26 | 31 |
27 using webkit::npapi::PluginList; | |
28 | |
29 const char kApplicationOctetStream[] = "application/octet-stream"; | 32 const char kApplicationOctetStream[] = "application/octet-stream"; |
30 | 33 |
31 base::LazyInstance<PluginList> g_singleton = LAZY_INSTANCE_INITIALIZER; | 34 base::LazyInstance<PluginList> g_singleton = LAZY_INSTANCE_INITIALIZER; |
32 | 35 |
33 bool AllowMimeTypeMismatch(const std::string& orig_mime_type, | 36 bool AllowMimeTypeMismatch(const std::string& orig_mime_type, |
34 const std::string& actual_mime_type) { | 37 const std::string& actual_mime_type) { |
35 if (orig_mime_type == actual_mime_type) { | 38 if (orig_mime_type == actual_mime_type) { |
36 NOTREACHED(); | 39 NOTREACHED(); |
37 return true; | 40 return true; |
38 } | 41 } |
39 | 42 |
40 // We do not permit URL-sniff based plug-in MIME type overrides aside from | 43 // We do not permit URL-sniff based plug-in MIME type overrides aside from |
41 // the case where the "type" was initially missing or generic | 44 // the case where the "type" was initially missing or generic |
42 // (application/octet-stream). | 45 // (application/octet-stream). |
43 // We collected stats to determine this approach isn't a major compat issue, | 46 // We collected stats to determine this approach isn't a major compat issue, |
44 // and we defend against content confusion attacks in various cases, such | 47 // and we defend against content confusion attacks in various cases, such |
45 // as when the user doesn't have the Flash plug-in enabled. | 48 // as when the user doesn't have the Flash plug-in enabled. |
46 bool allow = orig_mime_type.empty() || | 49 bool allow = orig_mime_type.empty() || |
47 orig_mime_type == kApplicationOctetStream; | 50 orig_mime_type == kApplicationOctetStream; |
48 LOG_IF(INFO, !allow) << "Ignoring plugin with unexpected MIME type " | 51 LOG_IF(INFO, !allow) << "Ignoring plugin with unexpected MIME type " |
49 << actual_mime_type << " (expected " << orig_mime_type | 52 << actual_mime_type << " (expected " << orig_mime_type |
50 << ")"; | 53 << ")"; |
51 return allow; | 54 return allow; |
52 } | 55 } |
53 | 56 |
54 } // namespace | 57 } // namespace |
55 | 58 |
56 namespace webkit { | |
57 namespace npapi { | |
58 | |
59 // static | 59 // static |
60 PluginList* PluginList::Singleton() { | 60 PluginList* PluginList::Singleton() { |
61 return g_singleton.Pointer(); | 61 return g_singleton.Pointer(); |
62 } | 62 } |
63 | 63 |
64 // static | 64 // static |
65 bool PluginList::DebugPluginLoading() { | 65 bool PluginList::DebugPluginLoading() { |
66 return CommandLine::ForCurrentProcess()->HasSwitch( | 66 return CommandLine::ForCurrentProcess()->HasSwitch( |
67 switches::kDebugPluginLoading); | 67 switches::kDebugPluginLoading); |
68 } | 68 } |
69 | 69 |
70 void PluginList::DisablePluginsDiscovery() { | 70 void PluginList::DisablePluginsDiscovery() { |
71 plugins_discovery_disabled_ = true; | 71 plugins_discovery_disabled_ = true; |
72 } | 72 } |
73 | 73 |
74 void PluginList::RefreshPlugins() { | 74 void PluginList::RefreshPlugins() { |
75 base::AutoLock lock(lock_); | 75 base::AutoLock lock(lock_); |
76 loading_state_ = LOADING_STATE_NEEDS_REFRESH; | 76 loading_state_ = LOADING_STATE_NEEDS_REFRESH; |
77 } | 77 } |
78 | 78 |
79 void PluginList::AddExtraPluginPath(const base::FilePath& plugin_path) { | 79 void PluginList::AddExtraPluginPath(const base::FilePath& plugin_path) { |
80 if (!NPAPIPluginsSupported()) { | 80 if (!webkit::npapi::NPAPIPluginsSupported()) { |
81 // TODO(jam): remove and just have CHECK once we're sure this doesn't get | 81 // TODO(jam): remove and just have CHECK once we're sure this doesn't get |
82 // triggered. | 82 // triggered. |
83 DLOG(INFO) << "NPAPI plugins not supported"; | 83 DLOG(INFO) << "NPAPI plugins not supported"; |
84 return; | 84 return; |
85 } | 85 } |
86 | 86 |
87 // Chrome OS only loads plugins from /opt/google/chrome/plugins. | 87 // Chrome OS only loads plugins from /opt/google/chrome/plugins. |
88 #if !defined(OS_CHROMEOS) | 88 #if !defined(OS_CHROMEOS) |
89 base::AutoLock lock(lock_); | 89 base::AutoLock lock(lock_); |
90 extra_plugin_paths_.push_back(plugin_path); | 90 extra_plugin_paths_.push_back(plugin_path); |
(...skipping 12 matching lines...) Expand all Loading... |
103 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) { | 103 void PluginList::AddExtraPluginDir(const base::FilePath& plugin_dir) { |
104 // Chrome OS only loads plugins from /opt/google/chrome/plugins. | 104 // Chrome OS only loads plugins from /opt/google/chrome/plugins. |
105 #if !defined(OS_CHROMEOS) | 105 #if !defined(OS_CHROMEOS) |
106 base::AutoLock lock(lock_); | 106 base::AutoLock lock(lock_); |
107 extra_plugin_dirs_.push_back(plugin_dir); | 107 extra_plugin_dirs_.push_back(plugin_dir); |
108 #endif | 108 #endif |
109 } | 109 } |
110 | 110 |
111 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info, | 111 void PluginList::RegisterInternalPlugin(const webkit::WebPluginInfo& info, |
112 bool add_at_beginning) { | 112 bool add_at_beginning) { |
113 if (!NPAPIPluginsSupported() && | 113 if (!webkit::npapi::NPAPIPluginsSupported() && |
114 info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { | 114 info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { |
115 DLOG(INFO) << "Don't register NPAPI plugins when they're not supported"; | 115 DLOG(INFO) << "Don't register NPAPI plugins when they're not supported"; |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 base::AutoLock lock(lock_); | 119 base::AutoLock lock(lock_); |
120 | 120 |
121 internal_plugins_.push_back(info); | 121 internal_plugins_.push_back(info); |
122 if (add_at_beginning) { | 122 if (add_at_beginning) { |
123 // Newer registrations go earlier in the list so they can override the MIME | 123 // Newer registrations go earlier in the list so they can override the MIME |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | 301 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { |
302 const base::FilePath& path = extra_plugin_paths[i]; | 302 const base::FilePath& path = extra_plugin_paths[i]; |
303 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != | 303 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != |
304 plugin_paths->end()) { | 304 plugin_paths->end()) { |
305 continue; | 305 continue; |
306 } | 306 } |
307 plugin_paths->push_back(path); | 307 plugin_paths->push_back(path); |
308 } | 308 } |
309 | 309 |
310 if (NPAPIPluginsSupported()) { | 310 if (webkit::npapi::NPAPIPluginsSupported()) { |
311 // A bit confusingly, this function is used to load Pepper plugins as well. | 311 // A bit confusingly, this function is used to load Pepper plugins as well. |
312 // Those are all internal plugins so we have to use extra_plugin_paths. | 312 // Those are all internal plugins so we have to use extra_plugin_paths. |
313 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) | 313 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) |
314 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); | 314 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); |
315 | 315 |
316 std::vector<base::FilePath> directories_to_scan; | 316 std::vector<base::FilePath> directories_to_scan; |
317 GetPluginDirectories(&directories_to_scan); | 317 GetPluginDirectories(&directories_to_scan); |
318 for (size_t i = 0; i < directories_to_scan.size(); ++i) | 318 for (size_t i = 0; i < directories_to_scan.size(); ++i) |
319 GetPluginsInDir(directories_to_scan[i], plugin_paths); | 319 GetPluginsInDir(directories_to_scan[i], plugin_paths); |
320 | 320 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 437 } |
438 } | 438 } |
439 } | 439 } |
440 return false; | 440 return false; |
441 } | 441 } |
442 | 442 |
443 PluginList::~PluginList() { | 443 PluginList::~PluginList() { |
444 } | 444 } |
445 | 445 |
446 | 446 |
447 } // namespace npapi | 447 } // namespace content |
448 } // namespace webkit | |
OLD | NEW |