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/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" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 local_state->RegisterBooleanPref(prefs::kDisablePluginFinder, false); | 139 local_state->RegisterBooleanPref(prefs::kDisablePluginFinder, false); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // static | 142 // static |
| 143 PluginFinder* PluginFinder::GetInstance() { | 143 PluginFinder* PluginFinder::GetInstance() { |
| 144 // PluginFinder::GetInstance() is the only method that's allowed to call | 144 // PluginFinder::GetInstance() is the only method that's allowed to call |
| 145 // Singleton<PluginFinder>::get(). | 145 // Singleton<PluginFinder>::get(). |
| 146 return Singleton<PluginFinder>::get(); | 146 return Singleton<PluginFinder>::get(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 PluginFinder::PluginFinder() { | 149 PluginFinder::PluginFinder() : version_(-1) { |
| 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void PluginFinder::Init() { | 153 void PluginFinder::Init() { |
| 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 155 plugin_list_.reset(ComputePluginList()); | 155 scoped_ptr<DictionaryValue> plugin_list(ComputePluginList()); |
|
cevans
2013/02/05 21:06:52
I think I'd have found a comment here useful, alon
Bernhard Bauer
2013/02/06 20:08:24
Done.
| |
| 156 DCHECK(plugin_list_.get()); | 156 if (plugin_list) |
| 157 | 157 ReinitializePlugins(plugin_list.Pass()); |
|
cevans
2013/02/05 21:06:52
In the common case (ENABLE_PLUGIN_INSTALLATION), R
| |
| 158 InitInternal(); | |
| 159 } | 158 } |
| 160 | 159 |
| 161 // static | 160 // static |
| 162 DictionaryValue* PluginFinder::ComputePluginList() { | 161 DictionaryValue* PluginFinder::ComputePluginList() { |
| 163 #if defined(ENABLE_PLUGIN_INSTALLATION) | 162 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 164 const base::DictionaryValue* metadata = | 163 scoped_ptr<DictionaryValue> plugin_list(LoadPluginList()); |
| 165 g_browser_process->local_state()->GetDictionary(prefs::kPluginsMetadata); | 164 if (plugin_list) |
| 166 if (!metadata->empty()) | 165 ReinitializePlugins(plugin_list.Pass()); |
| 167 return metadata->DeepCopy(); | |
| 168 #endif | 166 #endif |
| 169 base::DictionaryValue* result = LoadPluginList(); | 167 base::DictionaryValue* result = LoadPluginList(); |
|
cevans
2013/02/05 21:06:52
I'm kind of confused -- we just called LoadPluginL
Bernhard Bauer
2013/02/06 20:08:24
Yes, that's what I meant by "merging it with upstr
| |
| 170 if (result) | 168 if (result) |
| 171 return result; | 169 return result; |
| 172 return new base::DictionaryValue(); | 170 return new base::DictionaryValue(); |
| 173 } | 171 } |
| 174 | 172 |
| 175 // static | 173 // static |
| 176 DictionaryValue* PluginFinder::LoadPluginList() { | 174 DictionaryValue* PluginFinder::LoadPluginList() { |
| 177 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 175 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| 178 base::StringPiece json_resource( | 176 base::StringPiece json_resource( |
| 179 ResourceBundle::GetSharedInstance().GetRawDataResource( | 177 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 202 #endif | 200 #endif |
| 203 STLDeleteValues(&identifier_plugin_); | 201 STLDeleteValues(&identifier_plugin_); |
| 204 } | 202 } |
| 205 | 203 |
| 206 #if defined(ENABLE_PLUGIN_INSTALLATION) | 204 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 207 bool PluginFinder::FindPlugin( | 205 bool PluginFinder::FindPlugin( |
| 208 const std::string& mime_type, | 206 const std::string& mime_type, |
| 209 const std::string& language, | 207 const std::string& language, |
| 210 PluginInstaller** installer, | 208 PluginInstaller** installer, |
| 211 scoped_ptr<PluginMetadata>* plugin_metadata) { | 209 scoped_ptr<PluginMetadata>* plugin_metadata) { |
| 212 base::AutoLock lock(mutex_); | |
| 213 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) | 210 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) |
| 214 return false; | 211 return false; |
| 215 | 212 |
| 213 base::AutoLock lock(mutex_); | |
| 216 PluginMap::const_iterator metadata_it = identifier_plugin_.begin(); | 214 PluginMap::const_iterator metadata_it = identifier_plugin_.begin(); |
| 217 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { | 215 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { |
| 218 if (language == metadata_it->second->language() && | 216 if (language == metadata_it->second->language() && |
| 219 metadata_it->second->HasMimeType(mime_type)) { | 217 metadata_it->second->HasMimeType(mime_type)) { |
| 220 *plugin_metadata = metadata_it->second->Clone(); | 218 *plugin_metadata = metadata_it->second->Clone(); |
| 221 | 219 |
| 222 std::map<std::string, PluginInstaller*>::const_iterator installer_it = | 220 std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| 223 installers_.find(metadata_it->second->identifier()); | 221 installers_.find(metadata_it->second->identifier()); |
| 224 DCHECK(installer_it != installers_.end()); | 222 DCHECK(installer_it != installers_.end()); |
| 225 *installer = installer_it->second; | 223 *installer = installer_it->second; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 243 std::map<std::string, PluginInstaller*>::const_iterator installer_it = | 241 std::map<std::string, PluginInstaller*>::const_iterator installer_it = |
| 244 installers_.find(identifier); | 242 installers_.find(identifier); |
| 245 if (installer_it == installers_.end()) | 243 if (installer_it == installers_.end()) |
| 246 return false; | 244 return false; |
| 247 *installer = installer_it->second; | 245 *installer = installer_it->second; |
| 248 } | 246 } |
| 249 return true; | 247 return true; |
| 250 } | 248 } |
| 251 | 249 |
| 252 void PluginFinder::ReinitializePlugins( | 250 void PluginFinder::ReinitializePlugins( |
| 253 const base::DictionaryValue& json_metadata) { | 251 scoped_ptr<base::DictionaryValue> json_metadata) { |
| 254 base::AutoLock lock(mutex_); | 252 base::AutoLock lock(mutex_); |
| 253 int version = 0; // If no version is defined, we default to 0. | |
| 254 const char kVersionKey[] = "x-version"; | |
| 255 json_metadata->GetInteger(kVersionKey, &version); | |
| 256 if (version <= version_) | |
| 257 return; | |
| 258 | |
| 259 json_metadata->Remove(kVersionKey, NULL); | |
| 260 | |
| 261 version_ = version; | |
| 262 | |
| 255 STLDeleteValues(&identifier_plugin_); | 263 STLDeleteValues(&identifier_plugin_); |
| 256 identifier_plugin_.clear(); | 264 identifier_plugin_.clear(); |
| 257 | 265 |
| 258 plugin_list_.reset(json_metadata.DeepCopy()); | 266 InitInternal(json_metadata.Pass()); |
| 259 InitInternal(); | |
| 260 } | 267 } |
| 261 #endif | 268 #endif |
| 262 | 269 |
| 263 string16 PluginFinder::FindPluginNameWithIdentifier( | 270 string16 PluginFinder::FindPluginNameWithIdentifier( |
| 264 const std::string& identifier) { | 271 const std::string& identifier) { |
| 265 base::AutoLock lock(mutex_); | 272 base::AutoLock lock(mutex_); |
| 266 PluginMap::const_iterator it = identifier_plugin_.find(identifier); | 273 PluginMap::const_iterator it = identifier_plugin_.find(identifier); |
| 267 string16 name; | 274 string16 name; |
| 268 if (it != identifier_plugin_.end()) | 275 if (it != identifier_plugin_.end()) |
| 269 name = it->second->name(); | 276 name = it->second->name(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 295 | 302 |
| 296 DCHECK(metadata->MatchesPlugin(plugin)); | 303 DCHECK(metadata->MatchesPlugin(plugin)); |
| 297 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) | 304 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) |
| 298 identifier = GetLongIdentifier(plugin); | 305 identifier = GetLongIdentifier(plugin); |
| 299 | 306 |
| 300 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); | 307 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); |
| 301 identifier_plugin_[identifier] = metadata; | 308 identifier_plugin_[identifier] = metadata; |
| 302 return metadata->Clone(); | 309 return metadata->Clone(); |
| 303 } | 310 } |
| 304 | 311 |
| 305 void PluginFinder::InitInternal() { | 312 void PluginFinder::InitInternal(scoped_ptr<base::DictionaryValue> plugin_list) { |
| 306 for (DictionaryValue::Iterator plugin_it(*plugin_list_); | 313 for (DictionaryValue::Iterator plugin_it(*plugin_list); |
| 307 plugin_it.HasNext(); plugin_it.Advance()) { | 314 plugin_it.HasNext(); plugin_it.Advance()) { |
| 308 DictionaryValue* plugin = NULL; | 315 DictionaryValue* plugin = NULL; |
| 309 const std::string& identifier = plugin_it.key(); | 316 const std::string& identifier = plugin_it.key(); |
| 310 if (plugin_list_->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { | 317 if (plugin_list->GetDictionaryWithoutPathExpansion(identifier, &plugin)) { |
| 311 DCHECK(!identifier_plugin_[identifier]); | 318 DCHECK(!identifier_plugin_[identifier]); |
| 312 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); | 319 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin); |
| 313 | 320 |
| 314 #if defined(ENABLE_PLUGIN_INSTALLATION) | 321 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 315 if (installers_.find(identifier) == installers_.end()) | 322 if (installers_.find(identifier) == installers_.end()) |
| 316 installers_[identifier] = new PluginInstaller(); | 323 installers_[identifier] = new PluginInstaller(); |
| 317 #endif | 324 #endif |
| 318 } | 325 } |
| 319 } | 326 } |
| 320 } | 327 } |
| OLD | NEW |