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> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/command_line.h" | |
7 #include "base/values.h" | 11 #include "base/values.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
9 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" | 13 #include "chrome/browser/extensions/extension_content_settings_api_constants.h" |
10 #include "chrome/browser/extensions/extension_content_settings_helpers.h" | 14 #include "chrome/browser/extensions/extension_content_settings_helpers.h" |
11 #include "chrome/browser/extensions/extension_content_settings_store.h" | 15 #include "chrome/browser/extensions/extension_content_settings_store.h" |
12 #include "chrome/browser/extensions/extension_preference_api_constants.h" | 16 #include "chrome/browser/extensions/extension_preference_api_constants.h" |
13 #include "chrome/browser/extensions/extension_preference_helpers.h" | 17 #include "chrome/browser/extensions/extension_preference_helpers.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/chrome_switches.h" | |
16 #include "chrome/common/extensions/extension_error_utils.h" | 21 #include "chrome/common/extensions/extension_error_utils.h" |
22 #include "webkit/plugins/npapi/plugin_group.h" | |
23 #include "webkit/plugins/npapi/plugin_list.h" | |
17 | 24 |
18 namespace helpers = extension_content_settings_helpers; | 25 namespace helpers = extension_content_settings_helpers; |
19 namespace keys = extension_content_settings_api_constants; | 26 namespace keys = extension_content_settings_api_constants; |
20 namespace pref_helpers = extension_preference_helpers; | 27 namespace pref_helpers = extension_preference_helpers; |
21 namespace pref_keys = extension_preference_api_constants; | 28 namespace pref_keys = extension_preference_api_constants; |
22 | 29 |
30 namespace { | |
31 | |
32 webkit::npapi::PluginList* g_plugin_list = NULL; | |
battre
2011/06/15 12:53:39
should this now be called g_plugin_list_for_testin
| |
33 | |
34 } // namespace | |
35 | |
23 bool ClearContentSettingsFunction::RunImpl() { | 36 bool ClearContentSettingsFunction::RunImpl() { |
24 std::string content_type_str; | 37 std::string content_type_str; |
25 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | 38 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); |
26 ContentSettingsType content_type = | 39 ContentSettingsType content_type = |
27 helpers::StringToContentSettingsType(content_type_str); | 40 helpers::StringToContentSettingsType(content_type_str); |
28 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | 41 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); |
29 | 42 |
30 DictionaryValue* details = NULL; | 43 DictionaryValue* details = NULL; |
31 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | 44 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
32 | 45 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 return false; | 247 return false; |
235 } | 248 } |
236 | 249 |
237 ExtensionContentSettingsStore* store = | 250 ExtensionContentSettingsStore* store = |
238 profile_->GetExtensionService()->GetExtensionContentSettingsStore(); | 251 profile_->GetExtensionService()->GetExtensionContentSettingsStore(); |
239 store->SetExtensionContentSetting(extension_id(), top_level_pattern, | 252 store->SetExtensionContentSetting(extension_id(), top_level_pattern, |
240 embedded_pattern, content_type, | 253 embedded_pattern, content_type, |
241 resource_identifier, setting, scope); | 254 resource_identifier, setting, scope); |
242 return true; | 255 return true; |
243 } | 256 } |
257 | |
258 bool GetResourceIdentifiersFunction::RunImpl() { | |
259 std::string content_type_str; | |
260 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | |
261 ContentSettingsType content_type = | |
262 helpers::StringToContentSettingsType(content_type_str); | |
263 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | |
264 | |
265 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | |
266 CommandLine::ForCurrentProcess()->HasSwitch( | |
267 switches::kEnableResourceContentSettings)) { | |
268 BrowserThread::PostTask( | |
269 BrowserThread::FILE, FROM_HERE, | |
270 base::Bind(&GetResourceIdentifiersFunction::GetPluginsOnFileThread, | |
271 this)); | |
272 } else { | |
273 SendResponse(true); | |
274 } | |
275 | |
276 return true; | |
277 } | |
278 | |
279 void GetResourceIdentifiersFunction::GetPluginsOnFileThread() { | |
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
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(); | |
290 for (std::vector<webkit::npapi::PluginGroup>::iterator it = groups.begin(); | |
291 it != groups.end(); ++it) { | |
292 DictionaryValue* dict = new DictionaryValue(); | |
293 dict->SetString(keys::kIdKey, it->identifier()); | |
294 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); | |
295 list->Append(dict); | |
296 } | |
297 result_.reset(list); | |
298 BrowserThread::PostTask( | |
299 BrowserThread::UI, FROM_HERE, base::Bind( | |
300 &GetResourceIdentifiersFunction::SendResponse, this, true)); | |
301 } | |
302 | |
303 // static | |
304 void GetResourceIdentifiersFunction::SetPluginListForTesting( | |
305 webkit::npapi::PluginList* plugin_list) { | |
306 g_plugin_list = plugin_list; | |
307 } | |
OLD | NEW |