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 { | 30 namespace { |
31 | 31 |
32 webkit::npapi::PluginList* g_plugin_list = NULL; | 32 const std::vector<webkit::npapi::PluginGroup>* g_testing_plugin_groups_; |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 bool ClearContentSettingsFunction::RunImpl() { | 36 bool ClearContentSettingsFunction::RunImpl() { |
37 std::string content_type_str; | 37 std::string content_type_str; |
38 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | 38 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); |
39 ContentSettingsType content_type = | 39 ContentSettingsType content_type = |
40 helpers::StringToContentSettingsType(content_type_str); | 40 helpers::StringToContentSettingsType(content_type_str); |
41 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | 41 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); |
42 | 42 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 bool GetResourceIdentifiersFunction::RunImpl() { | 258 bool GetResourceIdentifiersFunction::RunImpl() { |
259 std::string content_type_str; | 259 std::string content_type_str; |
260 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | 260 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); |
261 ContentSettingsType content_type = | 261 ContentSettingsType content_type = |
262 helpers::StringToContentSettingsType(content_type_str); | 262 helpers::StringToContentSettingsType(content_type_str); |
263 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | 263 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); |
264 | 264 |
265 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | 265 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
266 CommandLine::ForCurrentProcess()->HasSwitch( | 266 CommandLine::ForCurrentProcess()->HasSwitch( |
267 switches::kEnableResourceContentSettings)) { | 267 switches::kEnableResourceContentSettings)) { |
268 BrowserThread::PostTask( | 268 PluginService::GetInstance()->LoadPluginList(false, |
269 BrowserThread::FILE, FROM_HERE, | 269 base::Bind(&GetResourceIdentifiersFunction::OnPluginsLoaded, this)); |
270 base::Bind(&GetResourceIdentifiersFunction::GetPluginsOnFileThread, | |
271 this)); | |
272 } else { | 270 } else { |
273 SendResponse(true); | 271 SendResponse(true); |
274 } | 272 } |
275 | 273 |
276 return true; | 274 return true; |
277 } | 275 } |
278 | 276 |
279 void GetResourceIdentifiersFunction::GetPluginsOnFileThread() { | 277 void GetResourceIdentifiersFunction::OnPluginsLoaded() { |
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; | 278 std::vector<webkit::npapi::PluginGroup> groups; |
287 plugin_list->GetPluginGroups(true, &groups); | 279 if (g_testing_plugin_groups_) |
| 280 groups = *g_testing_plugin_groups_; |
| 281 else |
| 282 PluginService::GetInstance()->GetPluginGroups(&groups); |
288 | 283 |
289 ListValue* list = new ListValue(); | 284 ListValue* list = new ListValue(); |
290 for (std::vector<webkit::npapi::PluginGroup>::iterator it = groups.begin(); | 285 for (std::vector<webkit::npapi::PluginGroup>::iterator it = groups.begin(); |
291 it != groups.end(); ++it) { | 286 it != groups.end(); ++it) { |
292 DictionaryValue* dict = new DictionaryValue(); | 287 DictionaryValue* dict = new DictionaryValue(); |
293 dict->SetString(keys::kIdKey, it->identifier()); | 288 dict->SetString(keys::kIdKey, it->identifier()); |
294 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); | 289 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); |
295 list->Append(dict); | 290 list->Append(dict); |
296 } | 291 } |
297 result_.reset(list); | 292 result_.reset(list); |
298 BrowserThread::PostTask( | 293 BrowserThread::PostTask( |
299 BrowserThread::UI, FROM_HERE, base::Bind( | 294 BrowserThread::UI, FROM_HERE, base::Bind( |
300 &GetResourceIdentifiersFunction::SendResponse, this, true)); | 295 &GetResourceIdentifiersFunction::SendResponse, this, true)); |
301 } | 296 } |
302 | 297 |
303 // static | 298 // static |
304 void GetResourceIdentifiersFunction::SetPluginListForTesting( | 299 void GetResourceIdentifiersFunction::SetPluginGroupsForTesting( |
305 webkit::npapi::PluginList* plugin_list) { | 300 const std::vector<webkit::npapi::PluginGroup>* plugin_groups) { |
306 g_plugin_list = plugin_list; | 301 g_testing_plugin_groups_ = plugin_groups; |
307 } | 302 } |
OLD | NEW |