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