| Index: chrome/browser/plugin_finder.cc
|
| diff --git a/chrome/browser/plugin_finder.cc b/chrome/browser/plugin_finder.cc
|
| index 2e90b5450293574e103bdf6b6c221d2a1e8dfa49..bcba7dcca9cc0b7fec5559f29af0a6b47133bb0e 100644
|
| --- a/chrome/browser/plugin_finder.cc
|
| +++ b/chrome/browser/plugin_finder.cc
|
| @@ -18,24 +18,35 @@
|
| #include "grit/browser_resources.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
|
|
| +using base::DictionaryValue;
|
| +
|
| +// static
|
| +void PluginFinder::Get(const base::Callback<void(PluginFinder*)>& cb) {
|
| + // At a later point we might want to do intialization here that needs to be
|
| + // done asynchronously, like loading the plug-in list from disk or from a URL.
|
| + MessageLoop::current()->PostTask(FROM_HERE, base::Bind(cb, GetInstance()));
|
| +}
|
| +
|
| // static
|
| PluginFinder* PluginFinder::GetInstance() {
|
| + // PluginFinder::GetInstance() is the only method that's allowed to call
|
| + // Singleton<PluginFinder>::get().
|
| return Singleton<PluginFinder>::get();
|
| }
|
|
|
| PluginFinder::PluginFinder() : plugin_list_(LoadPluginList()) {
|
| if (!plugin_list_.get()) {
|
| NOTREACHED();
|
| - plugin_list_.reset(new base::ListValue());
|
| + plugin_list_.reset(new DictionaryValue());
|
| }
|
| }
|
|
|
| // static
|
| -scoped_ptr<base::ListValue> PluginFinder::LoadPluginList() {
|
| - return scoped_ptr<base::ListValue>(LoadPluginListInternal()).Pass();
|
| +scoped_ptr<DictionaryValue> PluginFinder::LoadPluginList() {
|
| + return scoped_ptr<DictionaryValue>(LoadPluginListInternal());
|
| }
|
|
|
| -base::ListValue* PluginFinder::LoadPluginListInternal() {
|
| +DictionaryValue* PluginFinder::LoadPluginListInternal() {
|
| #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
|
| base::StringPiece json_resource(
|
| ResourceBundle::GetSharedInstance().GetRawDataResource(
|
| @@ -51,15 +62,11 @@ base::ListValue* PluginFinder::LoadPluginListInternal() {
|
| DLOG(ERROR) << error_str;
|
| return NULL;
|
| }
|
| - base::DictionaryValue* dict = NULL;
|
| - if (!value->GetAsDictionary(&dict))
|
| + if (value->GetType() != base::Value::TYPE_DICTIONARY)
|
| return NULL;
|
| - base::ListValue* list = NULL;
|
| - if (!dict->GetList("plugins", &list))
|
| - return NULL;
|
| - return list->DeepCopy();
|
| + return static_cast<base::DictionaryValue*>(value.release());
|
| #else
|
| - return new base::ListValue();
|
| + return new DictionaryValue();
|
| #endif
|
| }
|
|
|
| @@ -67,46 +74,58 @@ PluginFinder::~PluginFinder() {
|
| STLDeleteValues(&installers_);
|
| }
|
|
|
| -void PluginFinder::FindPlugin(
|
| - const std::string& mime_type,
|
| - const std::string& language,
|
| - const FindPluginCallback& callback) {
|
| - PluginInstaller* installer = FindPluginInternal(mime_type, language);
|
| - MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, installer));
|
| -}
|
| -
|
| -void PluginFinder::FindPluginWithIdentifier(
|
| - const std::string& identifier,
|
| - const FindPluginCallback& found_callback) {
|
| - PluginInstaller* installer = NULL;
|
| - std::map<std::string, PluginInstaller*>::const_iterator it =
|
| - installers_.find(identifier);
|
| - if (it != installers_.end()) {
|
| - installer = it->second;
|
| - } else {
|
| - for (ListValue::const_iterator plugin_it = plugin_list_->begin();
|
| - plugin_it != plugin_list_->end(); ++plugin_it) {
|
| - const base::DictionaryValue* plugin = NULL;
|
| - if (!(*plugin_it)->GetAsDictionary(&plugin)) {
|
| - NOTREACHED();
|
| - continue;
|
| - }
|
| - std::string id;
|
| - bool success = plugin->GetString("identifier", &id);
|
| +PluginInstaller* PluginFinder::FindPlugin(const std::string& mime_type,
|
| + const std::string& language) {
|
| + if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder))
|
| + return NULL;
|
| + for (DictionaryValue::Iterator plugin_it(*plugin_list_);
|
| + plugin_it.HasNext(); plugin_it.Advance()) {
|
| + const DictionaryValue* plugin = NULL;
|
| + if (!plugin_it.value().GetAsDictionary(&plugin)) {
|
| + NOTREACHED();
|
| + continue;
|
| + }
|
| + std::string language_str;
|
| + bool success = plugin->GetString("lang", &language_str);
|
| + DCHECK(success);
|
| + if (language_str != language)
|
| + continue;
|
| + ListValue* mime_types = NULL;
|
| + plugin->GetList("mime_types", &mime_types);
|
| + DCHECK(success);
|
| + for (ListValue::const_iterator mime_type_it = mime_types->begin();
|
| + mime_type_it != mime_types->end(); ++mime_type_it) {
|
| + std::string mime_type_str;
|
| + success = (*mime_type_it)->GetAsString(&mime_type_str);
|
| DCHECK(success);
|
| - if (id == identifier) {
|
| - installer = CreateInstaller(identifier, plugin);
|
| - break;
|
| + if (mime_type_str == mime_type) {
|
| + std::string identifier = plugin_it.key();
|
| + std::map<std::string, PluginInstaller*>::const_iterator installer =
|
| + installers_.find(identifier);
|
| + if (installer != installers_.end())
|
| + return installer->second;
|
| + return CreateInstaller(identifier, plugin);
|
| }
|
| }
|
| }
|
| - MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::Bind(found_callback, installer));
|
| + return NULL;
|
| +}
|
| +
|
| +PluginInstaller* PluginFinder::FindPluginWithIdentifier(
|
| + const std::string& identifier) {
|
| + std::map<std::string, PluginInstaller*>::const_iterator it =
|
| + installers_.find(identifier);
|
| + if (it != installers_.end())
|
| + return it->second;
|
| + DictionaryValue* plugin = NULL;
|
| + if (plugin_list_->GetDictionaryWithoutPathExpansion(identifier, &plugin))
|
| + return CreateInstaller(identifier, plugin);
|
| + return NULL;
|
| }
|
|
|
| PluginInstaller* PluginFinder::CreateInstaller(
|
| const std::string& identifier,
|
| - const base::DictionaryValue* plugin_dict) {
|
| + const DictionaryValue* plugin_dict) {
|
| DCHECK(!installers_[identifier]);
|
| std::string url;
|
| bool success = plugin_dict->GetString("url", &url);
|
| @@ -118,52 +137,14 @@ PluginInstaller* PluginFinder::CreateInstaller(
|
| DCHECK(success);
|
| bool display_url = false;
|
| plugin_dict->GetBoolean("displayurl", &display_url);
|
| - PluginInstaller*installer = new PluginInstaller(identifier,
|
| - GURL(url),
|
| - GURL(help_url),
|
| - name,
|
| - display_url);
|
| + bool requires_authorization = true;
|
| + plugin_dict->GetBoolean("requires_authorization", &display_url);
|
| + PluginInstaller* installer = new PluginInstaller(identifier,
|
| + GURL(url),
|
| + GURL(help_url),
|
| + name,
|
| + display_url,
|
| + requires_authorization);
|
| installers_[identifier] = installer;
|
| return installer;
|
| }
|
| -
|
| -PluginInstaller* PluginFinder::FindPluginInternal(
|
| - const std::string& mime_type,
|
| - const std::string& language) {
|
| - if (!g_browser_process->local_state()->GetBoolean(
|
| - prefs::kDisablePluginFinder)) {
|
| - for (ListValue::const_iterator plugin_it = plugin_list_->begin();
|
| - plugin_it != plugin_list_->end(); ++plugin_it) {
|
| - const base::DictionaryValue* plugin = NULL;
|
| - if (!(*plugin_it)->GetAsDictionary(&plugin)) {
|
| - NOTREACHED();
|
| - continue;
|
| - }
|
| - std::string language_str;
|
| - bool success = plugin->GetString("lang", &language_str);
|
| - DCHECK(success);
|
| - if (language_str != language)
|
| - continue;
|
| - ListValue* mime_types = NULL;
|
| - success = plugin->GetList("mime_types", &mime_types);
|
| - DCHECK(success);
|
| - for (ListValue::const_iterator mime_type_it = mime_types->begin();
|
| - mime_type_it != mime_types->end(); ++mime_type_it) {
|
| - std::string mime_type_str;
|
| - success = (*mime_type_it)->GetAsString(&mime_type_str);
|
| - DCHECK(success);
|
| - if (mime_type_str == mime_type) {
|
| - std::string identifier;
|
| - bool success = plugin->GetString("identifier", &identifier);
|
| - DCHECK(success);
|
| - std::map<std::string, PluginInstaller*>::const_iterator it =
|
| - installers_.find(identifier);
|
| - if (it != installers_.end())
|
| - return it->second;
|
| - return CreateInstaller(identifier, plugin);
|
| - }
|
| - }
|
| - }
|
| - }
|
| - return NULL;
|
| -}
|
|
|