Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chrome/browser/extensions/api/content_settings/content_settings_api.cc

Issue 10876083: [4] Changing content_settings_api to use PluginFinder's async interface (Closed) Base URL: http://git.chromium.org/chromium/src.git@async_start
Patch Set: Substitute include with forward declaration in .h file Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co nstants.h" 13 #include "chrome/browser/extensions/api/content_settings/content_settings_api_co nstants.h"
13 #include "chrome/browser/extensions/api/content_settings/content_settings_helper s.h" 14 #include "chrome/browser/extensions/api/content_settings/content_settings_helper s.h"
14 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h" 15 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h"
15 #include "chrome/browser/content_settings/cookie_settings.h" 16 #include "chrome/browser/content_settings/cookie_settings.h"
16 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
17 #include "chrome/browser/extensions/extension_preference_api_constants.h" 18 #include "chrome/browser/extensions/extension_preference_api_constants.h"
18 #include "chrome/browser/extensions/extension_preference_helpers.h" 19 #include "chrome/browser/extensions/extension_preference_helpers.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/plugin_finder.h"
22 #include "chrome/browser/plugin_installer.h"
20 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/extensions/api/content_settings.h" 26 #include "chrome/common/extensions/api/content_settings.h"
24 #include "chrome/common/extensions/extension_error_utils.h" 27 #include "chrome/common/extensions/extension_error_utils.h"
25 #include "content/public/browser/plugin_service.h" 28 #include "content/public/browser/plugin_service.h"
26 #include "webkit/plugins/npapi/plugin_group.h" 29 #include "webkit/plugins/npapi/plugin_group.h"
27 30
28 using content::BrowserThread; 31 using content::BrowserThread;
29 using content::PluginService; 32 using content::PluginService;
30 33
31 namespace Clear = extensions::api::content_settings::ContentSetting::Clear; 34 namespace Clear = extensions::api::content_settings::ContentSetting::Clear;
32 namespace Get = extensions::api::content_settings::ContentSetting::Get; 35 namespace Get = extensions::api::content_settings::ContentSetting::Get;
33 namespace Set = extensions::api::content_settings::ContentSetting::Set; 36 namespace Set = extensions::api::content_settings::ContentSetting::Set;
34 namespace pref_helpers = extension_preference_helpers; 37 namespace pref_helpers = extension_preference_helpers;
35 namespace pref_keys = extension_preference_api_constants; 38 namespace pref_keys = extension_preference_api_constants;
36 39
37 namespace { 40 namespace {
38 41
39 const std::vector<webkit::npapi::PluginGroup>* g_testing_plugin_groups_; 42 const std::vector<webkit::WebPluginInfo>* g_testing_plugins_;
40 43
41 bool RemoveContentType(ListValue* args, ContentSettingsType* content_type) { 44 bool RemoveContentType(ListValue* args, ContentSettingsType* content_type) {
42 std::string content_type_str; 45 std::string content_type_str;
43 if (!args->GetString(0, &content_type_str)) 46 if (!args->GetString(0, &content_type_str))
44 return false; 47 return false;
45 // We remove the ContentSettingsType parameter since this is added by the 48 // We remove the ContentSettingsType parameter since this is added by the
46 // renderer, and is not part of the JSON schema. 49 // renderer, and is not part of the JSON schema.
47 args->Remove(0, NULL); 50 args->Remove(0, NULL);
48 *content_type = 51 *content_type =
49 extensions::content_settings_helpers::StringToContentSettingsType( 52 extensions::content_settings_helpers::StringToContentSettingsType(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 store->SetExtensionContentSetting(extension_id(), primary_pattern, 246 store->SetExtensionContentSetting(extension_id(), primary_pattern,
244 secondary_pattern, content_type, 247 secondary_pattern, content_type,
245 resource_identifier, setting, scope); 248 resource_identifier, setting, scope);
246 return true; 249 return true;
247 } 250 }
248 251
249 bool GetResourceIdentifiersFunction::RunImpl() { 252 bool GetResourceIdentifiersFunction::RunImpl() {
250 ContentSettingsType content_type; 253 ContentSettingsType content_type;
251 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); 254 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type));
252 255
253 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 256 if (content_type != CONTENT_SETTINGS_TYPE_PLUGINS) {
254 if (g_testing_plugin_groups_) {
255 OnGotPluginGroups(*g_testing_plugin_groups_);
256 } else {
257 PluginService::GetInstance()->GetPluginGroups(
258 base::Bind(&GetResourceIdentifiersFunction::OnGotPluginGroups, this));
259 }
260 } else {
261 SendResponse(true); 257 SendResponse(true);
258 return true;
262 } 259 }
263 260
261 if (!g_testing_plugins_) {
262 PluginFinder::GetPluginsAndPluginFinder(
263 base::Bind(&GetResourceIdentifiersFunction::OnGotPlugins, this));
264 } else {
265 PluginFinder::Get(
266 base::Bind(&GetResourceIdentifiersFunction::OnGotPlugins, this,
267 *g_testing_plugins_));
268 }
264 return true; 269 return true;
265 } 270 }
266 271
267 void GetResourceIdentifiersFunction::OnGotPluginGroups( 272 void GetResourceIdentifiersFunction::OnGotPlugins(
268 const std::vector<webkit::npapi::PluginGroup>& groups) { 273 const std::vector<webkit::WebPluginInfo>& plugins,
274 PluginFinder* finder) {
275 std::set<std::string> group_identifiers;
269 ListValue* list = new ListValue(); 276 ListValue* list = new ListValue();
270 for (std::vector<webkit::npapi::PluginGroup>::const_iterator it = 277 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin();
271 groups.begin(); 278 it != plugins.end(); ++it) {
272 it != groups.end(); ++it) { 279 PluginInstaller* installer = finder->GetPluginInstaller(*it);
280 const std::string& group_identifier = installer->identifier();
281 if (group_identifiers.find(group_identifier) != group_identifiers.end())
282 continue;
283
284 group_identifiers.insert(group_identifier);
273 DictionaryValue* dict = new DictionaryValue(); 285 DictionaryValue* dict = new DictionaryValue();
274 dict->SetString(keys::kIdKey, it->identifier()); 286 dict->SetString(keys::kIdKey, group_identifier);
275 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); 287 dict->SetString(keys::kDescriptionKey, installer->name());
276 list->Append(dict); 288 list->Append(dict);
277 } 289 }
278 SetResult(list); 290 SetResult(list);
279 BrowserThread::PostTask( 291 BrowserThread::PostTask(
280 BrowserThread::UI, FROM_HERE, base::Bind( 292 BrowserThread::UI, FROM_HERE, base::Bind(
281 &GetResourceIdentifiersFunction::SendResponse, this, true)); 293 &GetResourceIdentifiersFunction::SendResponse, this, true));
282 } 294 }
283 295
284 // static 296 // static
285 void GetResourceIdentifiersFunction::SetPluginGroupsForTesting( 297 void GetResourceIdentifiersFunction::SetPluginsForTesting(
286 const std::vector<webkit::npapi::PluginGroup>* plugin_groups) { 298 const std::vector<webkit::WebPluginInfo>* plugins) {
287 g_testing_plugin_groups_ = plugin_groups; 299 g_testing_plugins_ = plugins;
288 } 300 }
289 301
290 } // namespace extensions 302 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698