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

Side by Side Diff: webkit/glue/plugins/plugin_list_linux.cc

Issue 173550: linux: scan more plugin directories, fix bugs (Closed)
Patch Set: fixes Created 11 years, 3 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
« no previous file with comments | « base/native_library_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/glue/plugins/plugin_list.h" 5 #include "webkit/glue/plugins/plugin_list.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 9
10 namespace {
11
12 // We build up a list of files and mtimes so we can sort them.
13 typedef std::pair<FilePath, base::Time> FileAndTime;
14 typedef std::vector<FileAndTime> FileTimeList;
15
16 // Comparator used to sort by descending mtime then ascending filename.
17 bool CompareTime(const FileAndTime& a, const FileAndTime& b) {
18 if (a.second == b.second) {
19 // Fall back on filename sorting, just to make the predicate valid.
20 return a.first < b.first;
21 }
22
23 // Sort by mtime, descending.
24 return a.second > b.second;
25 }
26
27 }
28
10 namespace NPAPI { 29 namespace NPAPI {
11 30
12 void PluginList::PlatformInit() { 31 void PluginList::PlatformInit() {
13 } 32 }
14 33
15 void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) { 34 void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) {
16 // Mozilla code to reference: 35 // Mozilla code to reference:
17 // http://mxr.mozilla.org/firefox/ident?i=NS_APP_PLUGINS_DIR_LIST 36 // http://mxr.mozilla.org/firefox/ident?i=NS_APP_PLUGINS_DIR_LIST
18 // and tens of accompanying files (mxr is very helpful). 37 // and tens of accompanying files (mxr is very helpful).
19 // This code carefully matches their behavior for compat reasons. 38 // This code carefully matches their behavior for compat reasons.
(...skipping 11 matching lines...) Expand all
31 plugin_dirs->push_back(FilePath(home).Append(".mozilla/plugins")); 50 plugin_dirs->push_back(FilePath(home).Append(".mozilla/plugins"));
32 // TODO(evanm): maybe consult our own plugins dir, like 51 // TODO(evanm): maybe consult our own plugins dir, like
33 // ~/.config/chromium/Plugins? 52 // ~/.config/chromium/Plugins?
34 53
35 // 3) NS_APP_PLUGINS_DIR: the binary dir + "plugins/". 54 // 3) NS_APP_PLUGINS_DIR: the binary dir + "plugins/".
36 FilePath dir; 55 FilePath dir;
37 PathService::Get(base::DIR_EXE, &dir); 56 PathService::Get(base::DIR_EXE, &dir);
38 plugin_dirs->push_back(dir.Append("plugins")); 57 plugin_dirs->push_back(dir.Append("plugins"));
39 58
40 // 4) NS_SYSTEM_PLUGINS_DIR: 59 // 4) NS_SYSTEM_PLUGINS_DIR:
41 // TODO(evanm): when we support 64-bit platforms, we'll need to fix this 60 // This varies across different versions of Firefox, so check 'em all.
42 // to be conditional.
43 COMPILE_ASSERT(sizeof(int)==4, fix_system_lib_path);
44 plugin_dirs->push_back(FilePath("/usr/lib/mozilla/plugins")); 61 plugin_dirs->push_back(FilePath("/usr/lib/mozilla/plugins"));
62 plugin_dirs->push_back(FilePath("/usr/lib/firefox/plugins"));
63 plugin_dirs->push_back(FilePath("/usr/lib/xulrunner-addons/plugins"));
45 } 64 }
46 65
47 void PluginList::LoadPluginsFromDir(const FilePath& path, 66 void PluginList::LoadPluginsFromDir(const FilePath& path,
48 std::vector<WebPluginInfo>* plugins) { 67 std::vector<WebPluginInfo>* plugins) {
68 // See ScanPluginsDirectory near
69 // http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginHostI mpl.cpp#5052
70
71 // Construct and stat a list of all filenames under consideration, for
72 // later sorting by mtime.
73 FileTimeList files;
49 file_util::FileEnumerator enumerator(path, 74 file_util::FileEnumerator enumerator(path,
50 false, // not recursive 75 false, // not recursive
51 file_util::FileEnumerator::FILES); 76 file_util::FileEnumerator::FILES);
52 for (FilePath path = enumerator.Next(); !path.value().empty(); 77 for (FilePath path = enumerator.Next(); !path.value().empty();
53 path = enumerator.Next()) { 78 path = enumerator.Next()) {
54 // Skip over Mozilla .xpt files. 79 // Skip over Mozilla .xpt files.
55 if (!path.MatchesExtension(FILE_PATH_LITERAL(".xpt"))) 80 if (path.MatchesExtension(FILE_PATH_LITERAL(".xpt")))
56 LoadPlugin(path, plugins); 81 continue;
82
83 // Java doesn't like being loaded through a symlink, since it uses
84 // its path to find dependent data files.
85 // file_util::AbsolutePath calls through to realpath(), which resolves
86 // symlinks.
87 file_util::AbsolutePath(&path);
88
89 // Get mtime.
90 file_util::FileInfo info;
91 if (!file_util::GetFileInfo(path, &info))
92 continue;
93
94 // Skip duplicates of the same file in our list.
95 bool skip = false;
96 for (size_t i = 0; i < plugins->size(); ++i) {
97 if (plugins->at(i).path == path) {
98 skip = true;
99 break;
100 }
101 }
102 if (skip)
103 continue;
104
105 files.push_back(std::make_pair(path, info.last_modified));
106 }
107
108 // Sort the file list by time (and filename).
109 std::sort(files.begin(), files.end(), CompareTime);
110
111 // Load the files in order.
112 for (FileTimeList::const_iterator i = files.begin(); i != files.end(); ++i) {
113 LoadPlugin(i->first, plugins);
57 } 114 }
58 } 115 }
59 116
60 bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info, 117 bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info,
61 std::vector<WebPluginInfo>* plugins) { 118 std::vector<WebPluginInfo>* plugins) {
62 // The equivalent Windows code verifies we haven't loaded a newer version 119 // TODO(evanm): blacklist nspluginwrapper here?
63 // of the same plugin, and then blacklists some known bad plugins. 120 // TODO(evanm): prefer the newest version of flash here?
64 // The equivalent Mac code verifies that plugins encountered first in the 121
65 // plugin list clobber later entries.
66 // TODO(evanm): figure out which behavior is appropriate for Linux.
67 // We don't need either yet as I'm just testing with Flash for now.
68 return true; 122 return true;
69 } 123 }
70 124
71 void PluginList::LoadInternalPlugins(std::vector<WebPluginInfo>* plugins) { 125 void PluginList::LoadInternalPlugins(std::vector<WebPluginInfo>* plugins) {
72 // none for now 126 // none for now
73 } 127 }
74 128
75 } // namespace NPAPI 129 } // namespace NPAPI
OLDNEW
« no previous file with comments | « base/native_library_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698