Peter Kotwicz | 90c0dc22 | 2022-03-09 18:24:45 | [diff] [blame] | 1 | // Copyright 2022 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 | |
| 5 | #include "chrome/browser/webid/federated_identity_api_permission_context.h" |
| 6 | |
Nicolás Peña Moreno | 0c974faf | 2022-03-10 16:05:12 | [diff] [blame] | 7 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
Peter Kotwicz | 90c0dc22 | 2022-03-09 18:24:45 | [diff] [blame] | 8 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 9 | #include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h" |
Nicolás Peña Moreno | 0c974faf | 2022-03-10 16:05:12 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
Peter Kotwicz | 90c0dc22 | 2022-03-09 18:24:45 | [diff] [blame] | 11 | #include "components/content_settings/core/common/content_settings_types.h" |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 12 | #include "components/permissions/permission_decision_auto_blocker.h" |
| 13 | #include "components/permissions/permission_result.h" |
| 14 | #include "url/origin.h" |
Peter Kotwicz | 90c0dc22 | 2022-03-09 18:24:45 | [diff] [blame] | 15 | |
| 16 | FederatedIdentityApiPermissionContext::FederatedIdentityApiPermissionContext( |
| 17 | content::BrowserContext* browser_context) |
| 18 | : host_content_settings_map_( |
Nicolás Peña Moreno | 0c974faf | 2022-03-10 16:05:12 | [diff] [blame] | 19 | HostContentSettingsMapFactory::GetForProfile(browser_context)), |
| 20 | cookie_settings_(CookieSettingsFactory::GetForProfile( |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 21 | Profile::FromBrowserContext(browser_context))), |
| 22 | permission_autoblocker_( |
| 23 | PermissionDecisionAutoBlockerFactory::GetForProfile( |
| 24 | Profile::FromBrowserContext(browser_context))) {} |
Peter Kotwicz | 90c0dc22 | 2022-03-09 18:24:45 | [diff] [blame] | 25 | |
| 26 | FederatedIdentityApiPermissionContext:: |
| 27 | ~FederatedIdentityApiPermissionContext() = default; |
| 28 | |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 29 | bool FederatedIdentityApiPermissionContext::HasApiPermission( |
| 30 | const url::Origin& rp_origin) { |
Peter Kotwicz | d4900eb8 | 2022-04-22 21:55:59 | [diff] [blame^] | 31 | const GURL rp_url = rp_origin.GetURL(); |
| 32 | const ContentSetting setting = host_content_settings_map_->GetContentSetting( |
| 33 | rp_url, rp_url, ContentSettingsType::FEDERATED_IDENTITY_API); |
| 34 | switch (setting) { |
| 35 | case CONTENT_SETTING_ALLOW: |
| 36 | break; |
| 37 | case CONTENT_SETTING_BLOCK: |
| 38 | return false; |
| 39 | default: |
| 40 | NOTREACHED(); |
| 41 | return false; |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | permissions::PermissionResult permission_result = |
| 45 | permission_autoblocker_->GetEmbargoResult( |
Peter Kotwicz | d4900eb8 | 2022-04-22 21:55:59 | [diff] [blame^] | 46 | rp_url, ContentSettingsType::FEDERATED_IDENTITY_API); |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 47 | return (permission_result.content_setting != |
| 48 | ContentSetting::CONTENT_SETTING_BLOCK); |
Peter Kotwicz | 90c0dc22 | 2022-03-09 18:24:45 | [diff] [blame] | 49 | } |
Nicolás Peña Moreno | 0c974faf | 2022-03-10 16:05:12 | [diff] [blame] | 50 | |
| 51 | bool FederatedIdentityApiPermissionContext::AreThirdPartyCookiesBlocked() { |
| 52 | return cookie_settings_->ShouldBlockThirdPartyCookies(); |
| 53 | } |
Peter Kotwicz | ae649ee | 2022-04-22 16:01:09 | [diff] [blame] | 54 | |
| 55 | void FederatedIdentityApiPermissionContext::RecordDismissAndEmbargo( |
| 56 | const url::Origin& rp_origin) { |
| 57 | permission_autoblocker_->RecordDismissAndEmbargo( |
| 58 | rp_origin.GetURL(), ContentSettingsType::FEDERATED_IDENTITY_API, |
| 59 | false /* dismissed_prompt_was_quiet */); |
| 60 | } |
| 61 | |
| 62 | void FederatedIdentityApiPermissionContext::RemoveEmbargoAndResetCounts( |
| 63 | const url::Origin& rp_origin) { |
| 64 | permission_autoblocker_->RemoveEmbargoAndResetCounts( |
| 65 | rp_origin.GetURL(), ContentSettingsType::FEDERATED_IDENTITY_API); |
| 66 | } |