Chromium Code Reviews| 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 "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" |
| 21 | 22 |
| 22 using base::DictionaryValue; | 23 using base::DictionaryValue; |
| 23 | 24 |
| 25 namespace { | |
| 26 | |
| 27 // Gets the base name of the file path as the identifier. | |
| 28 static std::string GetIdentifier(const webkit::WebPluginInfo& plugin) { | |
| 29 #if defined(OS_POSIX) | |
| 30 return plugin.path.BaseName().value(); | |
| 31 #elif defined(OS_WIN) | |
| 32 return base::SysWideToUTF8(plugin.path.BaseName().value()); | |
| 33 #endif | |
| 34 } | |
| 35 | |
| 36 // Gets the plug-in group name as the plug-in name if it is not empty or | |
| 37 // the filename without extension if the name is empty. | |
| 38 static string16 GetGroupName(const webkit::WebPluginInfo& plugin) { | |
| 39 if (!plugin.name.empty()) | |
| 40 return plugin.name; | |
| 41 | |
| 42 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); | |
| 43 #if defined(OS_POSIX) | |
| 44 return UTF8ToUTF16(path); | |
| 45 #elif defined(OS_WIN) | |
| 46 return WideToUTF16(path); | |
| 47 #endif | |
| 48 } | |
| 49 | |
| 50 } // namespace | |
| 51 | |
| 24 // static | 52 // static |
| 25 void PluginFinder::Get(const base::Callback<void(PluginFinder*)>& cb) { | 53 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 | 54 // 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. | 55 // done asynchronously, like loading the plug-in list from disk or from a URL. |
| 28 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(cb, GetInstance())); | 56 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(cb, GetInstance())); |
| 29 } | 57 } |
| 30 | 58 |
| 31 // static | 59 // static |
| 32 PluginFinder* PluginFinder::GetInstance() { | 60 PluginFinder* PluginFinder::GetInstance() { |
| 33 // PluginFinder::GetInstance() is the only method that's allowed to call | 61 // PluginFinder::GetInstance() is the only method that's allowed to call |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 DCHECK(!installers_[identifier]); | 150 DCHECK(!installers_[identifier]); |
| 123 std::string url; | 151 std::string url; |
| 124 bool success = plugin_dict->GetString("url", &url); | 152 bool success = plugin_dict->GetString("url", &url); |
| 125 std::string help_url; | 153 std::string help_url; |
| 126 plugin_dict->GetString("help_url", &help_url); | 154 plugin_dict->GetString("help_url", &help_url); |
| 127 string16 name; | 155 string16 name; |
| 128 success = plugin_dict->GetString("name", &name); | 156 success = plugin_dict->GetString("name", &name); |
| 129 DCHECK(success); | 157 DCHECK(success); |
| 130 bool display_url = false; | 158 bool display_url = false; |
| 131 plugin_dict->GetBoolean("displayurl", &display_url); | 159 plugin_dict->GetBoolean("displayurl", &display_url); |
| 160 string16 group_name_matcher; | |
| 161 success = plugin_dict->GetString("group_name_matcher", &group_name_matcher); | |
| 162 DCHECK(success); | |
| 132 | 163 |
| 133 PluginInstaller* installer = new PluginInstaller(identifier, | 164 PluginInstaller* installer = new PluginInstaller(identifier, |
| 134 name, | 165 name, |
| 135 display_url, | 166 display_url, |
| 136 GURL(url), | 167 GURL(url), |
| 137 GURL(help_url)); | 168 GURL(help_url), |
| 169 group_name_matcher); | |
| 138 const ListValue* versions = NULL; | 170 const ListValue* versions = NULL; |
| 139 if (plugin_dict->GetList("versions", &versions)) { | 171 if (plugin_dict->GetList("versions", &versions)) { |
| 140 for (ListValue::const_iterator it = versions->begin(); | 172 for (ListValue::const_iterator it = versions->begin(); |
| 141 it != versions->end(); ++it) { | 173 it != versions->end(); ++it) { |
| 142 DictionaryValue* version_dict = NULL; | 174 DictionaryValue* version_dict = NULL; |
| 143 if (!(*it)->GetAsDictionary(&version_dict)) { | 175 if (!(*it)->GetAsDictionary(&version_dict)) { |
| 144 NOTREACHED(); | 176 NOTREACHED(); |
| 145 continue; | 177 continue; |
| 146 } | 178 } |
| 147 std::string version; | 179 std::string version; |
| 148 success = version_dict->GetString("version", &version); | 180 success = version_dict->GetString("version", &version); |
| 149 DCHECK(success); | 181 DCHECK(success); |
| 150 std::string status_str; | 182 std::string status_str; |
| 151 success = version_dict->GetString("status", &status_str); | 183 success = version_dict->GetString("status", &status_str); |
| 152 DCHECK(success); | 184 DCHECK(success); |
| 153 PluginInstaller::SecurityStatus status = | 185 PluginInstaller::SecurityStatus status = |
| 154 PluginInstaller::SECURITY_STATUS_UP_TO_DATE; | 186 PluginInstaller::SECURITY_STATUS_UP_TO_DATE; |
| 155 success = PluginInstaller::ParseSecurityStatus(status_str, &status); | 187 success = PluginInstaller::ParseSecurityStatus(status_str, &status); |
| 156 DCHECK(success); | 188 DCHECK(success); |
| 157 installer->AddVersion(Version(version), status); | 189 installer->AddVersion(Version(version), status); |
| 158 } | 190 } |
| 159 } | 191 } |
| 160 | 192 |
| 161 installers_[identifier] = installer; | 193 installers_[identifier] = installer; |
| 162 return installer; | 194 return installer; |
| 163 } | 195 } |
| 196 | |
| 197 PluginInstaller* PluginFinder::GetPluginInstaller( | |
| 198 const webkit::WebPluginInfo& plugin) { | |
| 199 if (name_installers_.find(plugin.name) != name_installers_.end()) | |
| 200 return name_installers_[plugin.name]; | |
| 201 | |
| 202 for (DictionaryValue::Iterator plugin_it(*plugin_list_); | |
| 203 plugin_it.HasNext(); plugin_it.Advance()) { | |
|
Bernhard Bauer
2012/08/23 09:05:07
Nit: I think aligning this line with `DictionaryVa
ibraaaa
2012/08/23 09:58:33
Done.
| |
| 204 // This method triggers the lazy initialization for all PluginInstallers. | |
| 205 FindPluginWithIdentifier(plugin_it.key()); | |
| 206 } | |
| 207 | |
| 208 // Use the group name matcher to find the plug-in installer we want. | |
| 209 for (std::map<std::string, PluginInstaller*>::const_iterator it = | |
| 210 installers_.begin(); it != installers_.end(); ++it) { | |
| 211 if (!it->second->IsPluginMatchingGroupMatcher(plugin)) | |
| 212 continue; | |
| 213 | |
| 214 name_installers_[plugin.name] = it->second; | |
| 215 return it->second; | |
| 216 } | |
| 217 | |
| 218 // The plug-in installer was not found, create a dummy one holding | |
| 219 // the name, identifier and group name only. | |
| 220 std::string identifier = GetIdentifier(plugin); | |
| 221 PluginInstaller* installer = new PluginInstaller(identifier, | |
| 222 GetGroupName(plugin), | |
| 223 false, GURL(), GURL(), | |
| 224 string16()); | |
| 225 installers_[identifier] = installer; | |
| 226 name_installers_[plugin.name] = installer; | |
| 227 return installer; | |
| 228 } | |
| OLD | NEW |