1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERMISSIONS_CONTENT_SETTING_PERMISSION_CONTEXT_BASE_H_
#define COMPONENTS_PERMISSIONS_CONTENT_SETTING_PERMISSION_CONTEXT_BASE_H_
#include "components/permissions/permission_context_base.h"
namespace permissions {
// This context base class implements common functionality shared by permissions
// that fulfill the restriction that their permission state can be fully
// represented with a `ContentSetting` value. This means they have no need to
// support multi-state information such as permission options or chooser data.
// This allows them to be handled in a standardized way, reducing the complexity
// of their implementation.
class ContentSettingPermissionContextBase : public PermissionContextBase {
public:
explicit ContentSettingPermissionContextBase(
content::BrowserContext* browser_context,
ContentSettingsType content_settings_type,
network::mojom::PermissionsPolicyFeature permissions_policy_feature);
// Resets the content setting value
void ResetPermission(const GURL& requesting_origin,
const GURL& embedding_origin) override;
protected:
// Store the decided permission state. Virtual since the permission might be
// stored with different restrictions (for example for desktop notifications).
virtual void UpdateContentSetting(const PermissionRequestData& request_data,
ContentSetting content_setting,
bool is_one_time);
// Retrieve the current permission state. Virtual since the permission might
// want to customize logic around retrieving permission states.
virtual ContentSetting GetContentSettingStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const;
private:
// The private final methods below are used to hide base::Value from
// subclasses. Override the corresponding protected virtual methods to
// override permission-specific functionality.
// PermissionContextBase:
base::Value GetPermissionStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const final;
// PermissionContextBase:
void UpdateSetting(const PermissionRequestData& request_data,
base::Value content_setting,
bool is_one_time) final;
};
} // namespace permissions
#endif // COMPONENTS_PERMISSIONS_CONTENT_SETTING_PERMISSION_CONTEXT_BASE_H_
|