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

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: 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 <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/hash_tables.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_installer.h"
20 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/extensions/api/content_settings.h" 25 #include "chrome/common/extensions/api/content_settings.h"
24 #include "chrome/common/extensions/extension_error_utils.h" 26 #include "chrome/common/extensions/extension_error_utils.h"
25 #include "content/public/browser/plugin_service.h" 27 #include "content/public/browser/plugin_service.h"
26 #include "webkit/plugins/npapi/plugin_group.h" 28 #include "webkit/plugins/npapi/plugin_group.h"
27 29
28 using content::BrowserThread; 30 using content::BrowserThread;
29 using content::PluginService; 31 using content::PluginService;
30 32
31 namespace Clear = extensions::api::content_settings::ContentSetting::Clear; 33 namespace Clear = extensions::api::content_settings::ContentSetting::Clear;
32 namespace Get = extensions::api::content_settings::ContentSetting::Get; 34 namespace Get = extensions::api::content_settings::ContentSetting::Get;
33 namespace Set = extensions::api::content_settings::ContentSetting::Set; 35 namespace Set = extensions::api::content_settings::ContentSetting::Set;
34 namespace pref_helpers = extension_preference_helpers; 36 namespace pref_helpers = extension_preference_helpers;
35 namespace pref_keys = extension_preference_api_constants; 37 namespace pref_keys = extension_preference_api_constants;
36 38
37 namespace { 39 namespace {
38 40
39 const std::vector<webkit::npapi::PluginGroup>* g_testing_plugin_groups_; 41 const std::vector<webkit::WebPluginInfo>* g_testing_plugins_;
40 42
41 bool RemoveContentType(ListValue* args, ContentSettingsType* content_type) { 43 bool RemoveContentType(ListValue* args, ContentSettingsType* content_type) {
42 std::string content_type_str; 44 std::string content_type_str;
43 if (!args->GetString(0, &content_type_str)) 45 if (!args->GetString(0, &content_type_str))
44 return false; 46 return false;
45 // We remove the ContentSettingsType parameter since this is added by the 47 // We remove the ContentSettingsType parameter since this is added by the
46 // renderer, and is not part of the JSON schema. 48 // renderer, and is not part of the JSON schema.
47 args->Remove(0, NULL); 49 args->Remove(0, NULL);
48 *content_type = 50 *content_type =
49 extensions::content_settings_helpers::StringToContentSettingsType( 51 extensions::content_settings_helpers::StringToContentSettingsType(
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 secondary_pattern, content_type, 246 secondary_pattern, content_type,
245 resource_identifier, setting, scope); 247 resource_identifier, setting, scope);
246 return true; 248 return true;
247 } 249 }
248 250
249 bool GetResourceIdentifiersFunction::RunImpl() { 251 bool GetResourceIdentifiersFunction::RunImpl() {
250 ContentSettingsType content_type; 252 ContentSettingsType content_type;
251 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); 253 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type));
252 254
253 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 255 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
254 if (g_testing_plugin_groups_) { 256 PluginFinder::Get(base::Bind(
255 OnGotPluginGroups(*g_testing_plugin_groups_); 257 &GetResourceIdentifiersFunction::GetPluginFinderForRunImpl, this));
256 } else {
257 PluginService::GetInstance()->GetPluginGroups(
258 base::Bind(&GetResourceIdentifiersFunction::OnGotPluginGroups, this));
259 }
260 } else { 258 } else {
261 SendResponse(true); 259 SendResponse(true);
262 } 260 }
263 261
264 return true; 262 return true;
265 } 263 }
266 264
267 void GetResourceIdentifiersFunction::OnGotPluginGroups( 265 void GetResourceIdentifiersFunction::GetPluginFinderForRunImpl(
Mattias Nissler (ping if slow) 2012/08/27 15:42:09 The name of this function is unfortunate. It actua
268 const std::vector<webkit::npapi::PluginGroup>& groups) { 266 PluginFinder* finder) {
267 if (g_testing_plugins_) {
268 OnGotPlugins(finder, *g_testing_plugins_);
269 return;
270 }
271 PluginService::GetInstance()->GetPlugins(
272 base::Bind(&GetResourceIdentifiersFunction::OnGotPlugins, this,
273 finder));
Mattias Nissler (ping if slow) 2012/08/27 15:42:09 Aha, so we make a call to PluginFinder::Get that i
ibraaaa 2012/08/27 17:34:05 Unfortunately, we can't make PluginService::GetPlu
Bernhard Bauer 2012/08/29 12:56:54 Also, PluginService lives in content/, so it can't
ibraaaa 2012/08/29 16:39:37 mmm, let me clarify how can we end up with PluginF
Bernhard Bauer 2012/08/29 16:59:15 It's similar to the CallbackBarrier we use in Plug
274 }
275
276 void GetResourceIdentifiersFunction::OnGotPlugins(
277 PluginFinder* finder,
278 const std::vector<webkit::WebPluginInfo>& plugins) {
279 base::hash_set<std::string> group_identifiers;
269 ListValue* list = new ListValue(); 280 ListValue* list = new ListValue();
270 for (std::vector<webkit::npapi::PluginGroup>::const_iterator it = 281 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin();
271 groups.begin(); 282 it != plugins.end(); ++it) {
272 it != groups.end(); ++it) { 283 PluginInstaller* installer = finder->GetPluginInstaller(*it);
284 const std::string& group_identifier = installer->identifier();
285 if (group_identifiers.find(group_identifier) != group_identifiers.end())
286 continue;
287
288 group_identifiers.insert(group_identifier);
273 DictionaryValue* dict = new DictionaryValue(); 289 DictionaryValue* dict = new DictionaryValue();
274 dict->SetString(keys::kIdKey, it->identifier()); 290 dict->SetString(keys::kIdKey, group_identifier);
275 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); 291 dict->SetString(keys::kDescriptionKey, installer->name());
276 list->Append(dict); 292 list->Append(dict);
277 } 293 }
278 SetResult(list); 294 SetResult(list);
279 BrowserThread::PostTask( 295 BrowserThread::PostTask(
280 BrowserThread::UI, FROM_HERE, base::Bind( 296 BrowserThread::UI, FROM_HERE, base::Bind(
281 &GetResourceIdentifiersFunction::SendResponse, this, true)); 297 &GetResourceIdentifiersFunction::SendResponse, this, true));
282 } 298 }
283 299
284 // static 300 // static
285 void GetResourceIdentifiersFunction::SetPluginGroupsForTesting( 301 void GetResourceIdentifiersFunction::SetPluginsForTesting(
286 const std::vector<webkit::npapi::PluginGroup>* plugin_groups) { 302 const std::vector<webkit::WebPluginInfo>* plugins) {
287 g_testing_plugin_groups_ = plugin_groups; 303 g_testing_plugins_ = plugins;
288 } 304 }
289 305
290 } // namespace extensions 306 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698