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

Side by Side Diff: chrome/browser/plugin_finder.cc

Issue 10881002: [2] Adding a method to PluginFinder to get a PluginInstaller by WebPluginInfo. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing Windows Compilation Error Created 8 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 | « chrome/browser/plugin_finder.h ('k') | chrome/browser/plugin_installer.h » ('j') | 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) 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 "chrome/browser/plugin_finder.h" 5 #include "chrome/browser/plugin_finder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/sys_string_conversions.h"
12 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/plugin_installer.h" 15 #include "chrome/browser/plugin_installer.h"
14 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
18 #include "grit/browser_resources.h" 20 #include "grit/browser_resources.h"
19 #include "ui/base/layout.h" 21 #include "ui/base/layout.h"
20 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
21 23
22 using base::DictionaryValue; 24 using base::DictionaryValue;
23 25
26 namespace {
27
28 // Gets the base name of the file path as the identifier.
29 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) {
30 #if defined(OS_POSIX)
31 return plugin.path.BaseName().value();
32 #elif defined(OS_WIN)
33 return base::SysWideToUTF8(plugin.path.BaseName().value());
34 #endif
35 }
36
37 // Gets the plug-in group name as the plug-in name if it is not empty or
38 // the filename without extension if the name is empty.
39 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) {
40 if (!plugin.name.empty())
41 return plugin.name;
42
43 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value();
44 #if defined(OS_POSIX)
45 return UTF8ToUTF16(path);
46 #elif defined(OS_WIN)
47 return WideToUTF16(path);
48 #endif
49 }
50
51 } // namespace
52
24 // static 53 // static
25 void PluginFinder::Get(const base::Callback<void(PluginFinder*)>& cb) { 54 void PluginFinder::Get(const base::Callback<void(PluginFinder*)>& cb) {
26 // At a later point we might want to do intialization here that needs to be 55 // At a later point we might want to do intialization here that needs to be
27 // done asynchronously, like loading the plug-in list from disk or from a URL. 56 // done asynchronously, like loading the plug-in list from disk or from a URL.
28 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(cb, GetInstance())); 57 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(cb, GetInstance()));
29 } 58 }
30 59
31 // static 60 // static
32 PluginFinder* PluginFinder::GetInstance() { 61 PluginFinder* PluginFinder::GetInstance() {
33 // PluginFinder::GetInstance() is the only method that's allowed to call 62 // PluginFinder::GetInstance() is the only method that's allowed to call
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DCHECK(!installers_[identifier]); 151 DCHECK(!installers_[identifier]);
123 std::string url; 152 std::string url;
124 bool success = plugin_dict->GetString("url", &url); 153 bool success = plugin_dict->GetString("url", &url);
125 std::string help_url; 154 std::string help_url;
126 plugin_dict->GetString("help_url", &help_url); 155 plugin_dict->GetString("help_url", &help_url);
127 string16 name; 156 string16 name;
128 success = plugin_dict->GetString("name", &name); 157 success = plugin_dict->GetString("name", &name);
129 DCHECK(success); 158 DCHECK(success);
130 bool display_url = false; 159 bool display_url = false;
131 plugin_dict->GetBoolean("displayurl", &display_url); 160 plugin_dict->GetBoolean("displayurl", &display_url);
161 string16 group_name_matcher;
162 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher);
163 DCHECK(success);
132 164
133 PluginInstaller* installer = new PluginInstaller(identifier, 165 PluginInstaller* installer = new PluginInstaller(identifier,
134 name, 166 name,
135 display_url, 167 display_url,
136 GURL(url), 168 GURL(url),
137 GURL(help_url)); 169 GURL(help_url),
170 group_name_matcher);
138 const ListValue* versions = NULL; 171 const ListValue* versions = NULL;
139 if (plugin_dict->GetList("versions", &versions)) { 172 if (plugin_dict->GetList("versions", &versions)) {
140 for (ListValue::const_iterator it = versions->begin(); 173 for (ListValue::const_iterator it = versions->begin();
141 it != versions->end(); ++it) { 174 it != versions->end(); ++it) {
142 DictionaryValue* version_dict = NULL; 175 DictionaryValue* version_dict = NULL;
143 if (!(*it)->GetAsDictionary(&version_dict)) { 176 if (!(*it)->GetAsDictionary(&version_dict)) {
144 NOTREACHED(); 177 NOTREACHED();
145 continue; 178 continue;
146 } 179 }
147 std::string version; 180 std::string version;
148 success = version_dict->GetString("version", &version); 181 success = version_dict->GetString("version", &version);
149 DCHECK(success); 182 DCHECK(success);
150 std::string status_str; 183 std::string status_str;
151 success = version_dict->GetString("status", &status_str); 184 success = version_dict->GetString("status", &status_str);
152 DCHECK(success); 185 DCHECK(success);
153 PluginInstaller::SecurityStatus status = 186 PluginInstaller::SecurityStatus status =
154 PluginInstaller::SECURITY_STATUS_UP_TO_DATE; 187 PluginInstaller::SECURITY_STATUS_UP_TO_DATE;
155 success = PluginInstaller::ParseSecurityStatus(status_str, &status); 188 success = PluginInstaller::ParseSecurityStatus(status_str, &status);
156 DCHECK(success); 189 DCHECK(success);
157 installer->AddVersion(Version(version), status); 190 installer->AddVersion(Version(version), status);
158 } 191 }
159 } 192 }
160 193
161 installers_[identifier] = installer; 194 installers_[identifier] = installer;
162 return installer; 195 return installer;
163 } 196 }
197
198 PluginInstaller* PluginFinder::GetPluginInstaller(
199 const webkit::WebPluginInfo& plugin) {
200 if (name_installers_.find(plugin.name) != name_installers_.end())
201 return name_installers_[plugin.name];
202
203 for (DictionaryValue::Iterator plugin_it(*plugin_list_);
204 plugin_it.HasNext(); plugin_it.Advance()) {
205 // This method triggers the lazy initialization for all PluginInstallers.
206 FindPluginWithIdentifier(plugin_it.key());
207 }
208
209 // Use the group name matcher to find the plug-in installer we want.
210 for (std::map<std::string, PluginInstaller*>::const_iterator it =
211 installers_.begin(); it != installers_.end(); ++it) {
212 if (!it->second->MatchesPlugin(plugin))
213 continue;
214
215 name_installers_[plugin.name] = it->second;
216 return it->second;
217 }
218
219 // The plug-in installer was not found, create a dummy one holding
220 // the name, identifier and group name only.
221 std::string identifier = GetIdentifier(plugin);
222 PluginInstaller* installer = new PluginInstaller(identifier,
223 GetGroupName(plugin),
224 false, GURL(), GURL(),
225 GetGroupName(plugin));
226 installers_[identifier] = installer;
227 name_installers_[plugin.name] = installer;
228 return installer;
229 }
OLDNEW
« no previous file with comments | « chrome/browser/plugin_finder.h ('k') | chrome/browser/plugin_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698