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

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: Adding a method to PluginFinder to get a PluginInstaller by WebPluginInfo. Created 8 years, 4 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
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/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/plugin_installer.h" 14 #include "chrome/browser/plugin_installer.h"
14 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
19 #include "ui/base/layout.h" 20 #include "ui/base/layout.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DCHECK(!installers_[identifier]); 123 DCHECK(!installers_[identifier]);
123 std::string url; 124 std::string url;
124 bool success = plugin_dict->GetString("url", &url); 125 bool success = plugin_dict->GetString("url", &url);
125 std::string help_url; 126 std::string help_url;
126 plugin_dict->GetString("help_url", &help_url); 127 plugin_dict->GetString("help_url", &help_url);
127 string16 name; 128 string16 name;
128 success = plugin_dict->GetString("name", &name); 129 success = plugin_dict->GetString("name", &name);
129 DCHECK(success); 130 DCHECK(success);
130 bool display_url = false; 131 bool display_url = false;
131 plugin_dict->GetBoolean("displayurl", &display_url); 132 plugin_dict->GetBoolean("displayurl", &display_url);
133 string16 group_name_matcher;
134 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher);
135 DCHECK(success);
132 136
133 PluginInstaller* installer = new PluginInstaller(identifier, 137 PluginInstaller* installer = new PluginInstaller(identifier,
134 name, 138 name,
135 display_url, 139 display_url,
136 GURL(url), 140 GURL(url),
137 GURL(help_url)); 141 GURL(help_url),
142 group_name_matcher);
138 const ListValue* versions = NULL; 143 const ListValue* versions = NULL;
139 if (plugin_dict->GetList("versions", &versions)) { 144 if (plugin_dict->GetList("versions", &versions)) {
140 for (ListValue::const_iterator it = versions->begin(); 145 for (ListValue::const_iterator it = versions->begin();
141 it != versions->end(); ++it) { 146 it != versions->end(); ++it) {
142 DictionaryValue* version_dict = NULL; 147 DictionaryValue* version_dict = NULL;
143 if (!(*it)->GetAsDictionary(&version_dict)) { 148 if (!(*it)->GetAsDictionary(&version_dict)) {
144 NOTREACHED(); 149 NOTREACHED();
145 continue; 150 continue;
146 } 151 }
147 std::string version; 152 std::string version;
148 success = version_dict->GetString("version", &version); 153 success = version_dict->GetString("version", &version);
149 DCHECK(success); 154 DCHECK(success);
150 std::string status_str; 155 std::string status_str;
151 success = version_dict->GetString("status", &status_str); 156 success = version_dict->GetString("status", &status_str);
152 DCHECK(success); 157 DCHECK(success);
153 PluginInstaller::SecurityStatus status = 158 PluginInstaller::SecurityStatus status =
154 PluginInstaller::SECURITY_STATUS_UP_TO_DATE; 159 PluginInstaller::SECURITY_STATUS_UP_TO_DATE;
155 success = PluginInstaller::ParseSecurityStatus(status_str, &status); 160 success = PluginInstaller::ParseSecurityStatus(status_str, &status);
156 DCHECK(success); 161 DCHECK(success);
157 installer->AddVersion(Version(version), status); 162 installer->AddVersion(Version(version), status);
158 } 163 }
159 } 164 }
160 165
161 installers_[identifier] = installer; 166 installers_[identifier] = installer;
162 return installer; 167 return installer;
163 } 168 }
169
170 PluginInstaller* PluginFinder::GetPluginInstaller(
171 const webkit::WebPluginInfo& plugin) {
ibraaaa 2012/08/22 14:44:13 We can use a hash_map<plugin name, PluginInstaller
Bernhard Bauer 2012/08/22 15:11:30 Hm, if the PluginInstaller is owned by |installers
ibraaaa 2012/08/22 17:04:54 I think just making the second map have a pointer
Bernhard Bauer 2012/08/22 19:45:57 Yes, exactly. Conceptually, we can say that |insta
172 for (DictionaryValue::Iterator plugin_it(*plugin_list_);
173 plugin_it.HasNext(); plugin_it.Advance()) {
174 // This method triggers the lazy initialization for all PluginInstallers.
175 FindPluginWithIdentifier(plugin_it.key());
176 }
177
178 // Use the group name matcher to find the plug-in installer we want.
179 for (std::map<std::string, PluginInstaller*>::const_iterator it =
180 installers_.begin(); it != installers_.end(); ++it) {
181 if (plugin.name.find(it->second->group_name_matcher()) == std::string::npos)
182 continue;
183
184 if (it->second->group_name().empty())
185 it->second->set_group_name(GetGroupName(plugin));
186
187 return it->second;
188 }
189
190 // The plug-in installer was not found, create a dummy one holding
191 // the name, identifier and group name only.
192 std::string identifier = GetIdentifier(plugin);
193 PluginInstaller* installer = new PluginInstaller(identifier, plugin.name,
194 false, GURL(), GURL(),
195 string16());
196 installer->set_group_name(GetGroupName(plugin));
197 installers_[identifier] = installer;
198 return installer;
199 }
200
201 // static
202 std::string PluginFinder::GetIdentifier(const webkit::WebPluginInfo& plugin) {
Bernhard Bauer 2012/08/22 15:11:30 Are you planning to call these methods from other
ibraaaa 2012/08/22 18:29:25 Done, I was not planning to use them in any other
Bernhard Bauer 2012/08/22 19:45:57 Yes, that's the only reason.
203 #if defined(OS_POSIX)
204 return plugin.path.BaseName().value();
205 #elif defined(OS_WIN)
206 return base::SysWideToUTF8(plugin.path.BaseName().value());
207 #endif
208 }
209
210 // static
211 string16 PluginFinder::GetGroupName(const webkit::WebPluginInfo& plugin) {
212 if (!plugin.name.empty())
213 return plugin.name;
214
215 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value();
216 #if defined(OS_POSIX)
217 return UTF8ToUTF16(path);
218 #elif defined(OS_WIN)
219 return WideToUTF16(path);
220 #endif
221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698