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 ClearContentSettingsFunction::RunImpl() { | 65 bool ContentSettingsClearFunction::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 GetContentSettingFunction::RunImpl() { | 99 bool ContentSettingsGetFunction::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 SetContentSettingFunction::RunImpl() { | 172 bool ContentSettingsSetFunction::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 GetResourceIdentifiersFunction::RunImpl() { | 253 bool ContentSettingsGetResourceIdentifiersFunction::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(&GetResourceIdentifiersFunction::OnGotPlugins, this)); | 264 base::Bind(&ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins, |
| 265 this)); |
265 } else { | 266 } else { |
266 OnGotPlugins(*g_testing_plugins_); | 267 OnGotPlugins(*g_testing_plugins_); |
267 } | 268 } |
268 return true; | 269 return true; |
269 } | 270 } |
270 | 271 |
271 void GetResourceIdentifiersFunction::OnGotPlugins( | 272 void ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins( |
272 const std::vector<webkit::WebPluginInfo>& plugins) { | 273 const std::vector<webkit::WebPluginInfo>& plugins) { |
273 PluginFinder* finder = PluginFinder::GetInstance(); | 274 PluginFinder* finder = PluginFinder::GetInstance(); |
274 std::set<std::string> group_identifiers; | 275 std::set<std::string> group_identifiers; |
275 ListValue* list = new ListValue(); | 276 ListValue* list = new ListValue(); |
276 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); | 277 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
277 it != plugins.end(); ++it) { | 278 it != plugins.end(); ++it) { |
278 scoped_ptr<PluginMetadata> plugin_metadata(finder->GetPluginMetadata(*it)); | 279 scoped_ptr<PluginMetadata> plugin_metadata(finder->GetPluginMetadata(*it)); |
279 const std::string& group_identifier = plugin_metadata->identifier(); | 280 const std::string& group_identifier = plugin_metadata->identifier(); |
280 if (group_identifiers.find(group_identifier) != group_identifiers.end()) | 281 if (group_identifiers.find(group_identifier) != group_identifiers.end()) |
281 continue; | 282 continue; |
282 | 283 |
283 group_identifiers.insert(group_identifier); | 284 group_identifiers.insert(group_identifier); |
284 DictionaryValue* dict = new DictionaryValue(); | 285 DictionaryValue* dict = new DictionaryValue(); |
285 dict->SetString(keys::kIdKey, group_identifier); | 286 dict->SetString(keys::kIdKey, group_identifier); |
286 dict->SetString(keys::kDescriptionKey, plugin_metadata->name()); | 287 dict->SetString(keys::kDescriptionKey, plugin_metadata->name()); |
287 list->Append(dict); | 288 list->Append(dict); |
288 } | 289 } |
289 SetResult(list); | 290 SetResult(list); |
290 BrowserThread::PostTask( | 291 BrowserThread::PostTask( |
291 BrowserThread::UI, FROM_HERE, base::Bind( | 292 BrowserThread::UI, FROM_HERE, base::Bind( |
292 &GetResourceIdentifiersFunction::SendResponse, this, true)); | 293 &ContentSettingsGetResourceIdentifiersFunction::SendResponse, |
| 294 this, |
| 295 true)); |
293 } | 296 } |
294 | 297 |
295 // static | 298 // static |
296 void GetResourceIdentifiersFunction::SetPluginsForTesting( | 299 void ContentSettingsGetResourceIdentifiersFunction::SetPluginsForTesting( |
297 const std::vector<webkit::WebPluginInfo>* plugins) { | 300 const std::vector<webkit::WebPluginInfo>* plugins) { |
298 g_testing_plugins_ = plugins; | 301 g_testing_plugins_ = plugins; |
299 } | 302 } |
300 | 303 |
301 } // namespace extensions | 304 } // namespace extensions |
OLD | NEW |