| 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/extensions/api/content_settings/content_settings_api.h" | 5 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 using content::PluginService; | 33 using content::PluginService; |
| 34 | 34 |
| 35 namespace Clear = extensions::api::content_settings::ContentSetting::Clear; | 35 namespace Clear = extensions::api::content_settings::ContentSetting::Clear; |
| 36 namespace Get = extensions::api::content_settings::ContentSetting::Get; | 36 namespace Get = extensions::api::content_settings::ContentSetting::Get; |
| 37 namespace Set = extensions::api::content_settings::ContentSetting::Set; | 37 namespace Set = extensions::api::content_settings::ContentSetting::Set; |
| 38 namespace pref_helpers = extensions::preference_helpers; | 38 namespace pref_helpers = extensions::preference_helpers; |
| 39 namespace pref_keys = extensions::preference_api_constants; | 39 namespace pref_keys = extensions::preference_api_constants; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const std::vector<webkit::WebPluginInfo>* g_testing_plugins_; | |
| 44 | |
| 45 bool RemoveContentType(base::ListValue* args, | 43 bool RemoveContentType(base::ListValue* args, |
| 46 ContentSettingsType* content_type) { | 44 ContentSettingsType* content_type) { |
| 47 std::string content_type_str; | 45 std::string content_type_str; |
| 48 if (!args->GetString(0, &content_type_str)) | 46 if (!args->GetString(0, &content_type_str)) |
| 49 return false; | 47 return false; |
| 50 // We remove the ContentSettingsType parameter since this is added by the | 48 // We remove the ContentSettingsType parameter since this is added by the |
| 51 // renderer, and is not part of the JSON schema. | 49 // renderer, and is not part of the JSON schema. |
| 52 args->Remove(0, NULL); | 50 args->Remove(0, NULL); |
| 53 *content_type = | 51 *content_type = |
| 54 extensions::content_settings_helpers::StringToContentSettingsType( | 52 extensions::content_settings_helpers::StringToContentSettingsType( |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 251 |
| 254 bool ContentSettingsContentSettingGetResourceIdentifiersFunction::RunImpl() { | 252 bool ContentSettingsContentSettingGetResourceIdentifiersFunction::RunImpl() { |
| 255 ContentSettingsType content_type; | 253 ContentSettingsType content_type; |
| 256 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 254 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| 257 | 255 |
| 258 if (content_type != CONTENT_SETTINGS_TYPE_PLUGINS) { | 256 if (content_type != CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 259 SendResponse(true); | 257 SendResponse(true); |
| 260 return true; | 258 return true; |
| 261 } | 259 } |
| 262 | 260 |
| 263 if (!g_testing_plugins_) { | 261 PluginService::GetInstance()->GetPlugins( |
| 264 PluginService::GetInstance()->GetPlugins( | 262 base::Bind(&ContentSettingsContentSettingGetResourceIdentifiersFunction:: |
| 265 base::Bind(&ContentSettingsContentSettingGetResourceIdentifiersFunction:
: | 263 OnGotPlugins, |
| 266 OnGotPlugins, | 264 this)); |
| 267 this)); | |
| 268 } else { | |
| 269 OnGotPlugins(*g_testing_plugins_); | |
| 270 } | |
| 271 return true; | 265 return true; |
| 272 } | 266 } |
| 273 | 267 |
| 274 void ContentSettingsContentSettingGetResourceIdentifiersFunction::OnGotPlugins( | 268 void ContentSettingsContentSettingGetResourceIdentifiersFunction::OnGotPlugins( |
| 275 const std::vector<webkit::WebPluginInfo>& plugins) { | 269 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 276 PluginFinder* finder = PluginFinder::GetInstance(); | 270 PluginFinder* finder = PluginFinder::GetInstance(); |
| 277 std::set<std::string> group_identifiers; | 271 std::set<std::string> group_identifiers; |
| 278 base::ListValue* list = new base::ListValue(); | 272 base::ListValue* list = new base::ListValue(); |
| 279 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); | 273 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
| 280 it != plugins.end(); ++it) { | 274 it != plugins.end(); ++it) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 291 } | 285 } |
| 292 SetResult(list); | 286 SetResult(list); |
| 293 BrowserThread::PostTask( | 287 BrowserThread::PostTask( |
| 294 BrowserThread::UI, FROM_HERE, base::Bind( | 288 BrowserThread::UI, FROM_HERE, base::Bind( |
| 295 &ContentSettingsContentSettingGetResourceIdentifiersFunction:: | 289 &ContentSettingsContentSettingGetResourceIdentifiersFunction:: |
| 296 SendResponse, | 290 SendResponse, |
| 297 this, | 291 this, |
| 298 true)); | 292 true)); |
| 299 } | 293 } |
| 300 | 294 |
| 301 // static | |
| 302 void ContentSettingsContentSettingGetResourceIdentifiersFunction:: | |
| 303 SetPluginsForTesting(const std::vector<webkit::WebPluginInfo>* plugins) { | |
| 304 g_testing_plugins_ = plugins; | |
| 305 } | |
| 306 | |
| 307 } // namespace extensions | 295 } // namespace extensions |
| OLD | NEW |