test_permissions_client.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/permissions/test/test_permissions_client.h"
  5. #include "components/content_settings/core/browser/cookie_settings.h"
  6. #include "components/permissions/permission_actions_history.h"
  7. #include "components/sync_preferences/testing_pref_service_syncable.h"
  8. #include "content/public/browser/web_contents.h"
  9. namespace permissions {
  10. namespace {
  11. scoped_refptr<HostContentSettingsMap> CreateSettingsMap(
  12. sync_preferences::TestingPrefServiceSyncable* prefs) {
  13. HostContentSettingsMap::RegisterProfilePrefs(prefs->registry());
  14. return base::MakeRefCounted<HostContentSettingsMap>(
  15. prefs, false /* is_off_the_record */, false /* store_last_modified */,
  16. false /* restore_session */);
  17. }
  18. } // namespace
  19. TestPermissionsClient::TestPermissionsClient()
  20. : settings_map_(CreateSettingsMap(&prefs_)),
  21. autoblocker_(settings_map_.get()),
  22. permission_actions_history_(&prefs_) {
  23. PermissionActionsHistory::RegisterProfilePrefs(prefs_.registry());
  24. }
  25. TestPermissionsClient::~TestPermissionsClient() {
  26. settings_map_->ShutdownOnUIThread();
  27. }
  28. HostContentSettingsMap* TestPermissionsClient::GetSettingsMap(
  29. content::BrowserContext* browser_context) {
  30. return settings_map_.get();
  31. }
  32. scoped_refptr<content_settings::CookieSettings>
  33. TestPermissionsClient::GetCookieSettings(
  34. content::BrowserContext* browser_context) {
  35. return nullptr;
  36. }
  37. bool TestPermissionsClient::IsSubresourceFilterActivated(
  38. content::BrowserContext* browser_context,
  39. const GURL& url) {
  40. return false;
  41. }
  42. PermissionActionsHistory* TestPermissionsClient::GetPermissionActionsHistory(
  43. content::BrowserContext* browser_context) {
  44. return &permission_actions_history_;
  45. }
  46. PermissionDecisionAutoBlocker*
  47. TestPermissionsClient::GetPermissionDecisionAutoBlocker(
  48. content::BrowserContext* browser_context) {
  49. return &autoblocker_;
  50. }
  51. ObjectPermissionContextBase* TestPermissionsClient::GetChooserContext(
  52. content::BrowserContext* browser_context,
  53. ContentSettingsType type) {
  54. return nullptr;
  55. }
  56. void TestPermissionsClient::GetUkmSourceId(
  57. content::BrowserContext* browser_context,
  58. content::WebContents* web_contents,
  59. const GURL& requesting_origin,
  60. GetUkmSourceIdCallback callback) {
  61. if (web_contents) {
  62. ukm::SourceId source_id =
  63. web_contents->GetPrimaryMainFrame()->GetPageUkmSourceId();
  64. std::move(callback).Run(source_id);
  65. } else {
  66. std::move(callback).Run(absl::nullopt);
  67. }
  68. }
  69. } // namespace permissions