| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_content_settings_api.h" | 5 #include "chrome/browser/extensions/extension_content_settings_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" | 13 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" |
| 14 #include "chrome/browser/extensions/extension_content_settings_helpers.h" | 14 #include "chrome/browser/extensions/extension_content_settings_helpers.h" |
| 15 #include "chrome/browser/extensions/extension_content_settings_store.h" | 15 #include "chrome/browser/extensions/extension_content_settings_store.h" |
| 16 #include "chrome/browser/extensions/extension_preference_api_constants.h" | 16 #include "chrome/browser/extensions/extension_preference_api_constants.h" |
| 17 #include "chrome/browser/extensions/extension_preference_helpers.h" | 17 #include "chrome/browser/extensions/extension_preference_helpers.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/extensions/extension_error_utils.h" | 21 #include "chrome/common/extensions/extension_error_utils.h" |
| 22 #include "content/browser/plugin_service.h" |
| 22 #include "webkit/plugins/npapi/plugin_group.h" | 23 #include "webkit/plugins/npapi/plugin_group.h" |
| 23 #include "webkit/plugins/npapi/plugin_list.h" | |
| 24 | 24 |
| 25 namespace helpers = extension_content_settings_helpers; | 25 namespace helpers = extension_content_settings_helpers; |
| 26 namespace keys = extension_content_settings_api_constants; | 26 namespace keys = extension_content_settings_api_constants; |
| 27 namespace pref_helpers = extension_preference_helpers; | 27 namespace pref_helpers = extension_preference_helpers; |
| 28 namespace pref_keys = extension_preference_api_constants; | 28 namespace pref_keys = extension_preference_api_constants; |
| 29 | 29 |
| 30 namespace { | |
| 31 | |
| 32 webkit::npapi::PluginList* g_plugin_list = NULL; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 bool ClearContentSettingsFunction::RunImpl() { | 30 bool ClearContentSettingsFunction::RunImpl() { |
| 37 std::string content_type_str; | 31 std::string content_type_str; |
| 38 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | 32 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); |
| 39 ContentSettingsType content_type = | 33 ContentSettingsType content_type = |
| 40 helpers::StringToContentSettingsType(content_type_str); | 34 helpers::StringToContentSettingsType(content_type_str); |
| 41 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | 35 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); |
| 42 | 36 |
| 43 DictionaryValue* details = NULL; | 37 DictionaryValue* details = NULL; |
| 44 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | 38 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
| 45 | 39 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 bool GetResourceIdentifiersFunction::RunImpl() { | 252 bool GetResourceIdentifiersFunction::RunImpl() { |
| 259 std::string content_type_str; | 253 std::string content_type_str; |
| 260 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | 254 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); |
| 261 ContentSettingsType content_type = | 255 ContentSettingsType content_type = |
| 262 helpers::StringToContentSettingsType(content_type_str); | 256 helpers::StringToContentSettingsType(content_type_str); |
| 263 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | 257 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); |
| 264 | 258 |
| 265 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | 259 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 266 CommandLine::ForCurrentProcess()->HasSwitch( | 260 CommandLine::ForCurrentProcess()->HasSwitch( |
| 267 switches::kEnableResourceContentSettings)) { | 261 switches::kEnableResourceContentSettings)) { |
| 268 BrowserThread::PostTask( | 262 PluginService::GetInstance()->GetPluginGroups( |
| 269 BrowserThread::FILE, FROM_HERE, | 263 base::Bind(&GetResourceIdentifiersFunction::OnGotPluginGroups, this)); |
| 270 base::Bind(&GetResourceIdentifiersFunction::GetPluginsOnFileThread, | |
| 271 this)); | |
| 272 } else { | 264 } else { |
| 273 SendResponse(true); | 265 SendResponse(true); |
| 274 } | 266 } |
| 275 | 267 |
| 276 return true; | 268 return true; |
| 277 } | 269 } |
| 278 | 270 |
| 279 void GetResourceIdentifiersFunction::GetPluginsOnFileThread() { | 271 void GetResourceIdentifiersFunction::OnGotPluginGroups( |
| 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 272 const std::vector<webkit::npapi::PluginGroup>& groups) { |
| 281 webkit::npapi::PluginList* plugin_list = g_plugin_list; | |
| 282 if (!plugin_list) { | |
| 283 plugin_list = webkit::npapi::PluginList::Singleton(); | |
| 284 } | |
| 285 | |
| 286 std::vector<webkit::npapi::PluginGroup> groups; | |
| 287 plugin_list->GetPluginGroups(true, &groups); | |
| 288 | |
| 289 ListValue* list = new ListValue(); | 273 ListValue* list = new ListValue(); |
| 290 for (std::vector<webkit::npapi::PluginGroup>::iterator it = groups.begin(); | 274 for (std::vector<webkit::npapi::PluginGroup>::const_iterator it = |
| 275 groups.begin(); |
| 291 it != groups.end(); ++it) { | 276 it != groups.end(); ++it) { |
| 292 DictionaryValue* dict = new DictionaryValue(); | 277 DictionaryValue* dict = new DictionaryValue(); |
| 293 dict->SetString(keys::kIdKey, it->identifier()); | 278 dict->SetString(keys::kIdKey, it->identifier()); |
| 294 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); | 279 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); |
| 295 list->Append(dict); | 280 list->Append(dict); |
| 296 } | 281 } |
| 297 result_.reset(list); | 282 result_.reset(list); |
| 298 BrowserThread::PostTask( | 283 BrowserThread::PostTask( |
| 299 BrowserThread::UI, FROM_HERE, base::Bind( | 284 BrowserThread::UI, FROM_HERE, base::Bind( |
| 300 &GetResourceIdentifiersFunction::SendResponse, this, true)); | 285 &GetResourceIdentifiersFunction::SendResponse, this, true)); |
| 301 } | 286 } |
| 302 | |
| 303 // static | |
| 304 void GetResourceIdentifiersFunction::SetPluginListForTesting( | |
| 305 webkit::npapi::PluginList* plugin_list) { | |
| 306 g_plugin_list = plugin_list; | |
| 307 } | |
| OLD | NEW |