blob: 815cf80079feb990a439a56ce9b334eebfc1629c [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2022 The Chromium Authors
Peter Kotwicz90c0dc222022-03-09 18:24:452// 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
Zachary Tan33092722022-11-15 18:59:387#include "chrome/browser/browser_features.h"
Nicolás Peña Moreno0c974faf2022-03-10 16:05:128#include "chrome/browser/content_settings/cookie_settings_factory.h"
Peter Kotwicz90c0dc222022-03-09 18:24:459#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Peter Kotwiczae649ee2022-04-22 16:01:0910#include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h"
Nicolás Peña Moreno0c974faf2022-03-10 16:05:1211#include "chrome/browser/profiles/profile.h"
Peter Kotwicz90c0dc222022-03-09 18:24:4512#include "components/content_settings/core/common/content_settings_types.h"
Peter Kotwiczae649ee2022-04-22 16:01:0913#include "components/permissions/permission_decision_auto_blocker.h"
14#include "components/permissions/permission_result.h"
Peter Kotwicz153898a2022-05-05 18:48:3915#include "content/public/common/content_features.h"
Peter Kotwiczae649ee2022-04-22 16:01:0916#include "url/origin.h"
Peter Kotwicz90c0dc222022-03-09 18:24:4517
Peter Kotwicz153898a2022-05-05 18:48:3918using PermissionStatus =
19 content::FederatedIdentityApiPermissionContextDelegate::PermissionStatus;
20
Peter Kotwicz90c0dc222022-03-09 18:24:4521FederatedIdentityApiPermissionContext::FederatedIdentityApiPermissionContext(
22 content::BrowserContext* browser_context)
23 : host_content_settings_map_(
Nicolás Peña Moreno0c974faf2022-03-10 16:05:1224 HostContentSettingsMapFactory::GetForProfile(browser_context)),
25 cookie_settings_(CookieSettingsFactory::GetForProfile(
Peter Kotwiczae649ee2022-04-22 16:01:0926 Profile::FromBrowserContext(browser_context))),
27 permission_autoblocker_(
28 PermissionDecisionAutoBlockerFactory::GetForProfile(
29 Profile::FromBrowserContext(browser_context))) {}
Peter Kotwicz90c0dc222022-03-09 18:24:4530
31FederatedIdentityApiPermissionContext::
32 ~FederatedIdentityApiPermissionContext() = default;
33
Peter Kotwicz153898a2022-05-05 18:48:3934content::FederatedIdentityApiPermissionContextDelegate::PermissionStatus
35FederatedIdentityApiPermissionContext::GetApiPermissionStatus(
Peter Kotwicz51d5ddf2022-08-19 23:20:4036 const url::Origin& relying_party_embedder) {
Peter Kotwicz153898a2022-05-05 18:48:3937 if (!base::FeatureList::IsEnabled(features::kFedCm))
38 return PermissionStatus::BLOCKED_VARIATIONS;
39
Peter Kotwiczaf746d32022-12-07 02:18:3640 const GURL rp_embedder_url = relying_party_embedder.GetURL();
41
Peter Kotwiczd4900eb82022-04-22 21:55:5942 const ContentSetting setting = host_content_settings_map_->GetContentSetting(
Peter Kotwicz51d5ddf2022-08-19 23:20:4043 rp_embedder_url, rp_embedder_url,
44 ContentSettingsType::FEDERATED_IDENTITY_API);
Peter Kotwiczd4900eb82022-04-22 21:55:5945 switch (setting) {
46 case CONTENT_SETTING_ALLOW:
47 break;
48 case CONTENT_SETTING_BLOCK:
Peter Kotwicz153898a2022-05-05 18:48:3949 return PermissionStatus::BLOCKED_SETTINGS;
Peter Kotwiczd4900eb82022-04-22 21:55:5950 default:
51 NOTREACHED();
Peter Kotwicz153898a2022-05-05 18:48:3952 return PermissionStatus::BLOCKED_SETTINGS;
Peter Kotwiczae649ee2022-04-22 16:01:0953 }
54
Peter Kotwicz63559a82022-06-07 03:46:3555 if (permission_autoblocker_->IsEmbargoed(
Peter Kotwicz51d5ddf2022-08-19 23:20:4056 rp_embedder_url, ContentSettingsType::FEDERATED_IDENTITY_API)) {
Peter Kotwicz153898a2022-05-05 18:48:3957 return PermissionStatus::BLOCKED_EMBARGO;
Peter Kotwicz63559a82022-06-07 03:46:3558 }
Christian Biesinger49ab6312023-08-10 20:07:3359 // TODO(npm): FedCM is currently restricted to contexts where third party
60 // cookies are not blocked unless the FedCmWithoutThirdPartyCookies flag or
61 // FedCmIdpSigninStatusEnabled flag is enabled. The IDP signin status API
62 // override is implemented in the caller because it can be enabled through
63 // origin trials. This block can be removed when the IDP Signin status API
64 // ships.
65 // See https://crbug.com/1451396
66 if (cookie_settings_->ShouldBlockThirdPartyCookies() &&
67 !cookie_settings_->IsThirdPartyAccessAllowed(rp_embedder_url) &&
68 !base::FeatureList::IsEnabled(features::kFedCmWithoutThirdPartyCookies)) {
69 return PermissionStatus::BLOCKED_THIRD_PARTY_COOKIES_BLOCKED;
70 }
71
Peter Kotwicz153898a2022-05-05 18:48:3972 return PermissionStatus::GRANTED;
Nicolás Peña Moreno0c974faf2022-03-10 16:05:1273}
Peter Kotwiczae649ee2022-04-22 16:01:0974
75void FederatedIdentityApiPermissionContext::RecordDismissAndEmbargo(
Peter Kotwicz51d5ddf2022-08-19 23:20:4076 const url::Origin& relying_party_embedder) {
77 const GURL rp_embedder_url = relying_party_embedder.GetURL();
78 // If content setting is allowed for `rp_embedder_url`, reset it.
Peter Kotwicz7236eac2022-07-11 22:05:0479 // See crbug.com/1340127 for why the resetting is not conditional on the
80 // default content setting state.
81 const ContentSetting setting = host_content_settings_map_->GetContentSetting(
Peter Kotwicz51d5ddf2022-08-19 23:20:4082 rp_embedder_url, rp_embedder_url,
83 ContentSettingsType::FEDERATED_IDENTITY_API);
Peter Kotwicz7236eac2022-07-11 22:05:0484 if (setting == CONTENT_SETTING_ALLOW) {
85 host_content_settings_map_->SetContentSettingDefaultScope(
Peter Kotwicz51d5ddf2022-08-19 23:20:4086 rp_embedder_url, rp_embedder_url,
87 ContentSettingsType::FEDERATED_IDENTITY_API, CONTENT_SETTING_DEFAULT);
Peter Kotwicz7236eac2022-07-11 22:05:0488 }
Peter Kotwiczae649ee2022-04-22 16:01:0989 permission_autoblocker_->RecordDismissAndEmbargo(
Peter Kotwicz51d5ddf2022-08-19 23:20:4090 rp_embedder_url, ContentSettingsType::FEDERATED_IDENTITY_API,
Peter Kotwiczae649ee2022-04-22 16:01:0991 false /* dismissed_prompt_was_quiet */);
92}
93
94void FederatedIdentityApiPermissionContext::RemoveEmbargoAndResetCounts(
Peter Kotwicz51d5ddf2022-08-19 23:20:4095 const url::Origin& relying_party_embedder) {
Peter Kotwiczae649ee2022-04-22 16:01:0996 permission_autoblocker_->RemoveEmbargoAndResetCounts(
Peter Kotwicz51d5ddf2022-08-19 23:20:4097 relying_party_embedder.GetURL(),
98 ContentSettingsType::FEDERATED_IDENTITY_API);
Peter Kotwiczae649ee2022-04-22 16:01:0999}