| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 return *content_type != CONTENT_SETTINGS_TYPE_DEFAULT; | 55 return *content_type != CONTENT_SETTINGS_TYPE_DEFAULT; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 namespace extensions { | 60 namespace extensions { |
| 61 | 61 |
| 62 namespace helpers = content_settings_helpers; | 62 namespace helpers = content_settings_helpers; |
| 63 namespace keys = content_settings_api_constants; | 63 namespace keys = content_settings_api_constants; |
| 64 | 64 |
| 65 bool ContentSettingsClearFunction::RunImpl() { | 65 bool ClearContentSettingsFunction::RunImpl() { |
| 66 ContentSettingsType content_type; | 66 ContentSettingsType content_type; |
| 67 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 67 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| 68 | 68 |
| 69 scoped_ptr<Clear::Params> params(Clear::Params::Create(*args_)); | 69 scoped_ptr<Clear::Params> params(Clear::Params::Create(*args_)); |
| 70 EXTENSION_FUNCTION_VALIDATE(params.get()); | 70 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 71 | 71 |
| 72 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; | 72 ExtensionPrefsScope scope = kExtensionPrefsScopeRegular; |
| 73 bool incognito = false; | 73 bool incognito = false; |
| 74 if (params->details.scope == | 74 if (params->details.scope == |
| 75 Clear::Params::Details::SCOPE_INCOGNITO_SESSION_ONLY) { | 75 Clear::Params::Details::SCOPE_INCOGNITO_SESSION_ONLY) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 ContentSettingsStore* store = extensions::ExtensionSystem::Get(profile_)-> | 92 ContentSettingsStore* store = extensions::ExtensionSystem::Get(profile_)-> |
| 93 extension_service()->GetContentSettingsStore(); | 93 extension_service()->GetContentSettingsStore(); |
| 94 store->ClearContentSettingsForExtension(extension_id(), scope); | 94 store->ClearContentSettingsForExtension(extension_id(), scope); |
| 95 | 95 |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool ContentSettingsGetFunction::RunImpl() { | 99 bool GetContentSettingFunction::RunImpl() { |
| 100 ContentSettingsType content_type; | 100 ContentSettingsType content_type; |
| 101 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 101 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| 102 | 102 |
| 103 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); | 103 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); |
| 104 EXTENSION_FUNCTION_VALIDATE(params.get()); | 104 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 105 | 105 |
| 106 GURL primary_url(params->details.primary_url); | 106 GURL primary_url(params->details.primary_url); |
| 107 if (!primary_url.is_valid()) { | 107 if (!primary_url.is_valid()) { |
| 108 error_ = ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, | 108 error_ = ErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, |
| 109 params->details.primary_url); | 109 params->details.primary_url); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 DictionaryValue* result = new DictionaryValue(); | 163 DictionaryValue* result = new DictionaryValue(); |
| 164 result->SetString(keys::kContentSettingKey, | 164 result->SetString(keys::kContentSettingKey, |
| 165 helpers::ContentSettingToString(setting)); | 165 helpers::ContentSettingToString(setting)); |
| 166 | 166 |
| 167 SetResult(result); | 167 SetResult(result); |
| 168 | 168 |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool ContentSettingsSetFunction::RunImpl() { | 172 bool SetContentSettingFunction::RunImpl() { |
| 173 ContentSettingsType content_type; | 173 ContentSettingsType content_type; |
| 174 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 174 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| 175 | 175 |
| 176 scoped_ptr<Set::Params> params(Set::Params::Create(*args_)); | 176 scoped_ptr<Set::Params> params(Set::Params::Create(*args_)); |
| 177 EXTENSION_FUNCTION_VALIDATE(params.get()); | 177 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 178 | 178 |
| 179 std::string primary_error; | 179 std::string primary_error; |
| 180 ContentSettingsPattern primary_pattern = | 180 ContentSettingsPattern primary_pattern = |
| 181 helpers::ParseExtensionPattern(params->details.primary_pattern, | 181 helpers::ParseExtensionPattern(params->details.primary_pattern, |
| 182 &primary_error); | 182 &primary_error); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 243 } |
| 244 | 244 |
| 245 ContentSettingsStore* store = extensions::ExtensionSystem::Get(profile_)-> | 245 ContentSettingsStore* store = extensions::ExtensionSystem::Get(profile_)-> |
| 246 extension_service()->GetContentSettingsStore(); | 246 extension_service()->GetContentSettingsStore(); |
| 247 store->SetExtensionContentSetting(extension_id(), primary_pattern, | 247 store->SetExtensionContentSetting(extension_id(), primary_pattern, |
| 248 secondary_pattern, content_type, | 248 secondary_pattern, content_type, |
| 249 resource_identifier, setting, scope); | 249 resource_identifier, setting, scope); |
| 250 return true; | 250 return true; |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool ContentSettingsGetResourceIdentifiersFunction::RunImpl() { | 253 bool GetResourceIdentifiersFunction::RunImpl() { |
| 254 ContentSettingsType content_type; | 254 ContentSettingsType content_type; |
| 255 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 255 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| 256 | 256 |
| 257 if (content_type != CONTENT_SETTINGS_TYPE_PLUGINS) { | 257 if (content_type != CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 258 SendResponse(true); | 258 SendResponse(true); |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 | 261 |
| 262 if (!g_testing_plugins_) { | 262 if (!g_testing_plugins_) { |
| 263 PluginService::GetInstance()->GetPlugins( | 263 PluginService::GetInstance()->GetPlugins( |
| 264 base::Bind(&ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins, | 264 base::Bind(&GetResourceIdentifiersFunction::OnGotPlugins, this)); |
| 265 this)); | |
| 266 } else { | 265 } else { |
| 267 OnGotPlugins(*g_testing_plugins_); | 266 OnGotPlugins(*g_testing_plugins_); |
| 268 } | 267 } |
| 269 return true; | 268 return true; |
| 270 } | 269 } |
| 271 | 270 |
| 272 void ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins( | 271 void GetResourceIdentifiersFunction::OnGotPlugins( |
| 273 const std::vector<webkit::WebPluginInfo>& plugins) { | 272 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 274 PluginFinder* finder = PluginFinder::GetInstance(); | 273 PluginFinder* finder = PluginFinder::GetInstance(); |
| 275 std::set<std::string> group_identifiers; | 274 std::set<std::string> group_identifiers; |
| 276 ListValue* list = new ListValue(); | 275 ListValue* list = new ListValue(); |
| 277 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); | 276 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
| 278 it != plugins.end(); ++it) { | 277 it != plugins.end(); ++it) { |
| 279 scoped_ptr<PluginMetadata> plugin_metadata(finder->GetPluginMetadata(*it)); | 278 scoped_ptr<PluginMetadata> plugin_metadata(finder->GetPluginMetadata(*it)); |
| 280 const std::string& group_identifier = plugin_metadata->identifier(); | 279 const std::string& group_identifier = plugin_metadata->identifier(); |
| 281 if (group_identifiers.find(group_identifier) != group_identifiers.end()) | 280 if (group_identifiers.find(group_identifier) != group_identifiers.end()) |
| 282 continue; | 281 continue; |
| 283 | 282 |
| 284 group_identifiers.insert(group_identifier); | 283 group_identifiers.insert(group_identifier); |
| 285 DictionaryValue* dict = new DictionaryValue(); | 284 DictionaryValue* dict = new DictionaryValue(); |
| 286 dict->SetString(keys::kIdKey, group_identifier); | 285 dict->SetString(keys::kIdKey, group_identifier); |
| 287 dict->SetString(keys::kDescriptionKey, plugin_metadata->name()); | 286 dict->SetString(keys::kDescriptionKey, plugin_metadata->name()); |
| 288 list->Append(dict); | 287 list->Append(dict); |
| 289 } | 288 } |
| 290 SetResult(list); | 289 SetResult(list); |
| 291 BrowserThread::PostTask( | 290 BrowserThread::PostTask( |
| 292 BrowserThread::UI, FROM_HERE, base::Bind( | 291 BrowserThread::UI, FROM_HERE, base::Bind( |
| 293 &ContentSettingsGetResourceIdentifiersFunction::SendResponse, | 292 &GetResourceIdentifiersFunction::SendResponse, this, true)); |
| 294 this, | |
| 295 true)); | |
| 296 } | 293 } |
| 297 | 294 |
| 298 // static | 295 // static |
| 299 void ContentSettingsGetResourceIdentifiersFunction::SetPluginsForTesting( | 296 void GetResourceIdentifiersFunction::SetPluginsForTesting( |
| 300 const std::vector<webkit::WebPluginInfo>* plugins) { | 297 const std::vector<webkit::WebPluginInfo>* plugins) { |
| 301 g_testing_plugins_ = plugins; | 298 g_testing_plugins_ = plugins; |
| 302 } | 299 } |
| 303 | 300 |
| 304 } // namespace extensions | 301 } // namespace extensions |
| OLD | NEW |