Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_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( |
| 50 content_type_str); | 52 content_type_str); |
| 51 return *content_type != CONTENT_SETTINGS_TYPE_DEFAULT; | 53 return *content_type != CONTENT_SETTINGS_TYPE_DEFAULT; |
| 52 } | 54 } |
| 53 | 55 |
| 56 class CallbackBarrier : public base::RefCountedThreadSafe<CallbackBarrier> { | |
|
ibraaaa
2012/08/30 08:51:52
How about moving this to chrome/browser/plugins_pl
ibraaaa
2012/08/30 11:58:51
we can also update code here to make use of it: ht
ibraaaa
2012/08/31 12:48:49
Apparently the callback required to get plugins (I
Bernhard Bauer
2012/08/31 12:55:55
SGTM! (Both here and in PluginInfoMessageFilter)
Bernhard Bauer
2012/08/31 12:55:55
The plugins are used in PluginInfoMessageFilter::P
| |
| 57 public: | |
| 58 typedef std::vector<webkit::WebPluginInfo> PluginVector; | |
| 59 typedef base::Callback<void(PluginFinder*, const PluginVector&)> | |
| 60 CombinedCallback; | |
| 61 | |
| 62 explicit CallbackBarrier(const CombinedCallback& callback) | |
| 63 : callback_(callback), | |
| 64 finder_(NULL), | |
| 65 plugins_(NULL) { | |
|
Bernhard Bauer
2012/08/31 12:55:55
The default constructor for a scoped_ptr already i
| |
| 66 DCHECK(!callback_.is_null()); | |
| 67 if (g_testing_plugins_) { | |
| 68 plugins_.reset(new PluginVector(g_testing_plugins_->begin(), | |
| 69 g_testing_plugins_->end())); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 base::Callback<void(PluginFinder*)> CreateGetPluginFinderCallback() { | |
| 74 return base::Bind(&CallbackBarrier::SavePluginFinderAndMaybeRunCallback, | |
| 75 this); | |
| 76 } | |
| 77 | |
| 78 base::Callback<void(const PluginVector&)> CreateGetPluginVectorCallback() { | |
| 79 return base::Bind(&CallbackBarrier::SavePluginVectorAndMaybeRunCallback, | |
| 80 this); | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 friend class base::RefCountedThreadSafe<CallbackBarrier>; | |
| 85 | |
| 86 ~CallbackBarrier() { | |
| 87 DCHECK(callback_.is_null()); | |
| 88 } | |
| 89 | |
| 90 void SavePluginFinderAndMaybeRunCallback(PluginFinder* finder) { | |
|
Bernhard Bauer
2012/08/31 12:55:55
This method name is a bit verbose. Maybe just GotP
| |
| 91 finder_ = finder; | |
| 92 MaybeRunCallback(); | |
| 93 } | |
| 94 | |
| 95 void SavePluginVectorAndMaybeRunCallback(const PluginVector& plugins) { | |
| 96 plugins_.reset(new PluginVector(plugins.begin(), plugins.end())); | |
|
Bernhard Bauer
2012/08/31 12:55:55
Could you simply use the copy constructor on vecto
| |
| 97 MaybeRunCallback(); | |
| 98 } | |
| 99 | |
| 100 void MaybeRunCallback() { | |
| 101 if (!finder_ || !plugins_.get()) | |
| 102 return; | |
| 103 callback_.Run(finder_, *plugins_); | |
| 104 callback_.Reset(); | |
| 105 } | |
| 106 | |
| 107 CombinedCallback callback_; | |
| 108 PluginFinder* finder_; | |
| 109 scoped_ptr<std::vector<webkit::WebPluginInfo> > plugins_; | |
|
Bernhard Bauer
2012/08/31 12:55:55
You typedef'd this as PluginVector above, so you c
| |
| 110 }; | |
| 111 | |
| 54 } // namespace | 112 } // namespace |
| 55 | 113 |
| 56 namespace extensions { | 114 namespace extensions { |
| 57 | 115 |
| 58 namespace helpers = content_settings_helpers; | 116 namespace helpers = content_settings_helpers; |
| 59 namespace keys = content_settings_api_constants; | 117 namespace keys = content_settings_api_constants; |
| 60 | 118 |
| 61 bool ClearContentSettingsFunction::RunImpl() { | 119 bool ClearContentSettingsFunction::RunImpl() { |
| 62 ContentSettingsType content_type; | 120 ContentSettingsType content_type; |
| 63 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 121 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 secondary_pattern, content_type, | 302 secondary_pattern, content_type, |
| 245 resource_identifier, setting, scope); | 303 resource_identifier, setting, scope); |
| 246 return true; | 304 return true; |
| 247 } | 305 } |
| 248 | 306 |
| 249 bool GetResourceIdentifiersFunction::RunImpl() { | 307 bool GetResourceIdentifiersFunction::RunImpl() { |
| 250 ContentSettingsType content_type; | 308 ContentSettingsType content_type; |
| 251 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); | 309 EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); |
| 252 | 310 |
| 253 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 311 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 254 if (g_testing_plugin_groups_) { | 312 scoped_refptr<CallbackBarrier> barrier = new CallbackBarrier( |
| 255 OnGotPluginGroups(*g_testing_plugin_groups_); | 313 base::Bind(&GetResourceIdentifiersFunction::OnGotPlugins, this)); |
| 256 } else { | 314 |
| 257 PluginService::GetInstance()->GetPluginGroups( | 315 PluginFinder::Get(base::Bind(barrier->CreateGetPluginFinderCallback())); |
| 258 base::Bind(&GetResourceIdentifiersFunction::OnGotPluginGroups, this)); | 316 if (!g_testing_plugins_) { |
| 317 PluginService::GetInstance()->GetPlugins( | |
|
Bernhard Bauer
2012/08/31 12:55:55
You could switch the order of the parameters in On
| |
| 318 base::Bind(barrier->CreateGetPluginVectorCallback())); | |
| 259 } | 319 } |
| 260 } else { | 320 } else { |
| 261 SendResponse(true); | 321 SendResponse(true); |
| 262 } | 322 } |
| 263 | 323 |
| 264 return true; | 324 return true; |
| 265 } | 325 } |
| 266 | 326 |
| 267 void GetResourceIdentifiersFunction::OnGotPluginGroups( | 327 void GetResourceIdentifiersFunction::OnGotPlugins( |
| 268 const std::vector<webkit::npapi::PluginGroup>& groups) { | 328 PluginFinder* finder, |
| 329 const std::vector<webkit::WebPluginInfo>& plugins) { | |
| 330 std::set<std::string> group_identifiers; | |
| 269 ListValue* list = new ListValue(); | 331 ListValue* list = new ListValue(); |
| 270 for (std::vector<webkit::npapi::PluginGroup>::const_iterator it = | 332 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
| 271 groups.begin(); | 333 it != plugins.end(); ++it) { |
| 272 it != groups.end(); ++it) { | 334 PluginInstaller* installer = finder->GetPluginInstaller(*it); |
| 335 const std::string& group_identifier = installer->identifier(); | |
| 336 if (group_identifiers.find(group_identifier) != group_identifiers.end()) | |
| 337 continue; | |
| 338 | |
| 339 group_identifiers.insert(group_identifier); | |
| 273 DictionaryValue* dict = new DictionaryValue(); | 340 DictionaryValue* dict = new DictionaryValue(); |
| 274 dict->SetString(keys::kIdKey, it->identifier()); | 341 dict->SetString(keys::kIdKey, group_identifier); |
| 275 dict->SetString(keys::kDescriptionKey, it->GetGroupName()); | 342 dict->SetString(keys::kDescriptionKey, installer->name()); |
| 276 list->Append(dict); | 343 list->Append(dict); |
| 277 } | 344 } |
| 278 SetResult(list); | 345 SetResult(list); |
| 279 BrowserThread::PostTask( | 346 BrowserThread::PostTask( |
| 280 BrowserThread::UI, FROM_HERE, base::Bind( | 347 BrowserThread::UI, FROM_HERE, base::Bind( |
| 281 &GetResourceIdentifiersFunction::SendResponse, this, true)); | 348 &GetResourceIdentifiersFunction::SendResponse, this, true)); |
| 282 } | 349 } |
| 283 | 350 |
| 284 // static | 351 // static |
| 285 void GetResourceIdentifiersFunction::SetPluginGroupsForTesting( | 352 void GetResourceIdentifiersFunction::SetPluginsForTesting( |
| 286 const std::vector<webkit::npapi::PluginGroup>* plugin_groups) { | 353 const std::vector<webkit::WebPluginInfo>* plugins) { |
| 287 g_testing_plugin_groups_ = plugin_groups; | 354 g_testing_plugins_ = plugins; |
| 288 } | 355 } |
| 289 | 356 |
| 290 } // namespace extensions | 357 } // namespace extensions |
| OLD | NEW |