| 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/plugins/plugin_finder.h" | 5 #include "chrome/browser/plugins/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" | 11 #include "base/sys_string_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/plugins/plugin_installer.h" | 15 #include "chrome/browser/plugins/plugin_metadata.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/plugin_service.h" | 19 #include "content/public/browser/plugin_service.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "grit/browser_resources.h" | 21 #include "grit/browser_resources.h" |
| 22 #include "ui/base/layout.h" | 22 #include "ui/base/layout.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 24 | 24 |
| 25 #if defined(ENABLE_PLUGIN_INSTALLATION) | 25 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 49 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); | 49 FilePath::StringType path = plugin.path.BaseName().RemoveExtension().value(); |
| 50 #if defined(OS_POSIX) | 50 #if defined(OS_POSIX) |
| 51 return UTF8ToUTF16(path); | 51 return UTF8ToUTF16(path); |
| 52 #elif defined(OS_WIN) | 52 #elif defined(OS_WIN) |
| 53 return WideToUTF16(path); | 53 return WideToUTF16(path); |
| 54 #endif | 54 #endif |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 // TODO(ibraaaa): DELETE. http://crbug.com/124396 | |
| 60 // static | |
| 61 void PluginFinder::Get(const base::Callback<void(PluginFinder*)>& cb) { | |
| 62 // At a later point we might want to do intialization here that needs to be | |
| 63 // done asynchronously, like loading the plug-in list from disk or from a URL. | |
| 64 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(cb, GetInstance())); | |
| 65 } | |
| 66 | |
| 67 // static | 59 // static |
| 68 PluginFinder* PluginFinder::GetInstance() { | 60 PluginFinder* PluginFinder::GetInstance() { |
| 69 // PluginFinder::GetInstance() is the only method that's allowed to call | 61 // PluginFinder::GetInstance() is the only method that's allowed to call |
| 70 // Singleton<PluginFinder>::get(). | 62 // Singleton<PluginFinder>::get(). |
| 71 return Singleton<PluginFinder>::get(); | 63 return Singleton<PluginFinder>::get(); |
| 72 } | 64 } |
| 73 | 65 |
| 74 PluginFinder::PluginFinder() { | 66 PluginFinder::PluginFinder() { |
| 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 67 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 76 } | 68 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 base::AutoLock lock(mutex_); | 165 base::AutoLock lock(mutex_); |
| 174 std::map<std::string, PluginInstaller*>::const_iterator it = | 166 std::map<std::string, PluginInstaller*>::const_iterator it = |
| 175 installers_.find(identifier); | 167 installers_.find(identifier); |
| 176 if (it != installers_.end()) | 168 if (it != installers_.end()) |
| 177 return it->second; | 169 return it->second; |
| 178 | 170 |
| 179 return NULL; | 171 return NULL; |
| 180 } | 172 } |
| 181 #endif | 173 #endif |
| 182 | 174 |
| 183 PluginMetadata* PluginFinder::FindPluginMetadataWithIdentifier( | 175 string16 PluginFinder::FindPluginNameWithIdentifier( |
| 184 const std::string& identifier) { | 176 const std::string& identifier) { |
| 185 base::AutoLock lock(mutex_); | 177 base::AutoLock lock(mutex_); |
| 186 std::map<std::string, PluginMetadata*>::const_iterator it = | 178 std::map<std::string, PluginMetadata*>::const_iterator it = |
| 187 identifier_plugin_.find(identifier); | 179 identifier_plugin_.find(identifier); |
| 180 string16 name; |
| 188 if (it != identifier_plugin_.end()) | 181 if (it != identifier_plugin_.end()) |
| 189 return it->second; | 182 name = it->second->name(); |
| 190 | 183 |
| 191 return NULL; | 184 return name.empty() ? UTF8ToUTF16(identifier) : name; |
| 192 } | 185 } |
| 193 | 186 |
| 194 PluginMetadata* PluginFinder::CreatePluginMetadata( | 187 PluginMetadata* PluginFinder::CreatePluginMetadata( |
| 195 const std::string& identifier, | 188 const std::string& identifier, |
| 196 const DictionaryValue* plugin_dict) { | 189 const DictionaryValue* plugin_dict) { |
| 197 DCHECK(!identifier_plugin_[identifier]); | 190 DCHECK(!identifier_plugin_[identifier]); |
| 198 std::string url; | 191 std::string url; |
| 199 bool success = plugin_dict->GetString("url", &url); | 192 bool success = plugin_dict->GetString("url", &url); |
| 200 std::string help_url; | 193 std::string help_url; |
| 201 plugin_dict->GetString("help_url", &help_url); | 194 plugin_dict->GetString("help_url", &help_url); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 std::string identifier = GetIdentifier(plugin); | 254 std::string identifier = GetIdentifier(plugin); |
| 262 PluginMetadata* metadata = new PluginMetadata(identifier, | 255 PluginMetadata* metadata = new PluginMetadata(identifier, |
| 263 GetGroupName(plugin), | 256 GetGroupName(plugin), |
| 264 false, GURL(), GURL(), | 257 false, GURL(), GURL(), |
| 265 GetGroupName(plugin)); | 258 GetGroupName(plugin)); |
| 266 | 259 |
| 267 name_plugin_[plugin.name] = metadata; | 260 name_plugin_[plugin.name] = metadata; |
| 268 identifier_plugin_[identifier] = metadata; | 261 identifier_plugin_[identifier] = metadata; |
| 269 return metadata; | 262 return metadata; |
| 270 } | 263 } |
| OLD | NEW |