blob: 4b472d8d34b1fe005b271246a12a0993e16e83d6 [file] [log] [blame]
Peter Kotwicz90c0dc222022-03-09 18:24:451// 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 Moreno0c974faf2022-03-10 16:05:127#include "chrome/browser/content_settings/cookie_settings_factory.h"
Peter Kotwicz90c0dc222022-03-09 18:24:458#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Peter Kotwiczae649ee2022-04-22 16:01:099#include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h"
Nicolás Peña Moreno0c974faf2022-03-10 16:05:1210#include "chrome/browser/profiles/profile.h"
Peter Kotwicz90c0dc222022-03-09 18:24:4511#include "components/content_settings/core/common/content_settings_types.h"
Peter Kotwiczae649ee2022-04-22 16:01:0912#include "components/permissions/permission_decision_auto_blocker.h"
13#include "components/permissions/permission_result.h"
14#include "url/origin.h"
Peter Kotwicz90c0dc222022-03-09 18:24:4515
16FederatedIdentityApiPermissionContext::FederatedIdentityApiPermissionContext(
17 content::BrowserContext* browser_context)
18 : host_content_settings_map_(
Nicolás Peña Moreno0c974faf2022-03-10 16:05:1219 HostContentSettingsMapFactory::GetForProfile(browser_context)),
20 cookie_settings_(CookieSettingsFactory::GetForProfile(
Peter Kotwiczae649ee2022-04-22 16:01:0921 Profile::FromBrowserContext(browser_context))),
22 permission_autoblocker_(
23 PermissionDecisionAutoBlockerFactory::GetForProfile(
24 Profile::FromBrowserContext(browser_context))) {}
Peter Kotwicz90c0dc222022-03-09 18:24:4525
26FederatedIdentityApiPermissionContext::
27 ~FederatedIdentityApiPermissionContext() = default;
28
Peter Kotwiczae649ee2022-04-22 16:01:0929bool FederatedIdentityApiPermissionContext::HasApiPermission(
30 const url::Origin& rp_origin) {
Peter Kotwiczd4900eb82022-04-22 21:55:5931 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 Kotwiczae649ee2022-04-22 16:01:0942 }
43
44 permissions::PermissionResult permission_result =
45 permission_autoblocker_->GetEmbargoResult(
Peter Kotwiczd4900eb82022-04-22 21:55:5946 rp_url, ContentSettingsType::FEDERATED_IDENTITY_API);
Peter Kotwiczae649ee2022-04-22 16:01:0947 return (permission_result.content_setting !=
48 ContentSetting::CONTENT_SETTING_BLOCK);
Peter Kotwicz90c0dc222022-03-09 18:24:4549}
Nicolás Peña Moreno0c974faf2022-03-10 16:05:1250
51bool FederatedIdentityApiPermissionContext::AreThirdPartyCookiesBlocked() {
52 return cookie_settings_->ShouldBlockThirdPartyCookies();
53}
Peter Kotwiczae649ee2022-04-22 16:01:0954
55void 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
62void FederatedIdentityApiPermissionContext::RemoveEmbargoAndResetCounts(
63 const url::Origin& rp_origin) {
64 permission_autoblocker_->RemoveEmbargoAndResetCounts(
65 rp_origin.GetURL(), ContentSettingsType::FEDERATED_IDENTITY_API);
66}