#include "components/permissions/permission_context_base.h"
#include <stddef.h>
#include <optional>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/not_fatal_until.h"
#include "base/observer_list.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/content_settings_registry.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_context_base.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "components/permissions/permission_request.h"
#include "components/permissions/permission_request_id.h"
#include "components/permissions/permission_request_manager.h"
#include "components/permissions/permission_uma_util.h"
#include "components/permissions/permission_util.h"
#include "components/permissions/permissions_client.h"
#include "components/permissions/request_type.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom.h"
#include "url/gurl.h"
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
#include "components/guest_view/browser/guest_view_base.h"
#endif
namespace permissions {
namespace {
PermissionStatus;
const char kPermissionBlockedKillSwitchMessage[] = …;
#if BUILDFLAG(IS_ANDROID)
const char kPermissionBlockedRepeatedDismissalsMessage[] =
"%s permission has been blocked as the user has dismissed the permission "
"prompt several times. This can be reset in Site Settings. See "
"https://www.chromestatus.com/feature/6443143280984064 for more "
"information.";
const char kPermissionBlockedRepeatedIgnoresMessage[] =
"%s permission has been blocked as the user has ignored the permission "
"prompt several times. This can be reset in Site Settings. See "
"https://www.chromestatus.com/feature/6443143280984064 for more "
"information.";
#else
const char kPermissionBlockedRepeatedDismissalsMessage[] = …;
const char kPermissionBlockedRepeatedIgnoresMessage[] = …;
#endif
const char kPermissionBlockedRecentDisplayMessage[] = …;
const char kPermissionBlockedPermissionsPolicyMessage[] = …;
void LogPermissionBlockedMessage(content::RenderFrameHost* rfh,
const char* message,
ContentSettingsType type) { … }
}
const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = …;
const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = …;
PermissionContextBase::PermissionContextBase(
content::BrowserContext* browser_context,
ContentSettingsType content_settings_type,
blink::mojom::PermissionsPolicyFeature permissions_policy_feature)
: … { … }
PermissionContextBase::~PermissionContextBase() { … }
void PermissionContextBase::RequestPermission(
PermissionRequestData request_data,
BrowserPermissionCallback callback) { … }
bool PermissionContextBase::IsRestrictedToSecureOrigins() const { … }
void PermissionContextBase::UserMadePermissionDecision(
const PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
ContentSetting content_setting) { … }
std::unique_ptr<PermissionRequest>
PermissionContextBase::CreatePermissionRequest(
content::WebContents* web_contents,
PermissionRequestData request_data,
PermissionRequest::PermissionDecidedCallback permission_decided_callback,
base::OnceClosure delete_callback) const { … }
bool PermissionContextBase::UsesAutomaticEmbargo() const { … }
content::PermissionResult PermissionContextBase::GetPermissionStatus(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const { … }
bool PermissionContextBase::IsPermissionAvailableToOrigins(
const GURL& requesting_origin,
const GURL& embedding_origin) const { … }
content::PermissionResult
PermissionContextBase::UpdatePermissionStatusWithDeviceStatus(
content::PermissionResult result,
const GURL& requesting_origin,
const GURL& embedding_origin) { … }
void PermissionContextBase::ResetPermission(const GURL& requesting_origin,
const GURL& embedding_origin) { … }
bool PermissionContextBase::AlwaysIncludeDeviceStatus() const { … }
bool PermissionContextBase::IsPermissionKillSwitchOn() const { … }
ContentSetting PermissionContextBase::GetPermissionStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const { … }
void PermissionContextBase::DecidePermission(
PermissionRequestData request_data,
BrowserPermissionCallback callback) { … }
void PermissionContextBase::PermissionDecided(const PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
ContentSetting content_setting,
bool is_one_time,
bool is_final_decision) { … }
content::BrowserContext* PermissionContextBase::browser_context() const { … }
void PermissionContextBase::OnContentSettingChanged(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsTypeSet content_type_set) { … }
void PermissionContextBase::AddObserver(
permissions::Observer* permission_observer) { … }
void PermissionContextBase::RemoveObserver(
permissions::Observer* permission_observer) { … }
void PermissionContextBase::MaybeUpdatePermissionStatusWithDeviceStatus() { … }
void PermissionContextBase::NotifyPermissionSet(
const PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
BrowserPermissionCallback callback,
bool persist,
ContentSetting content_setting,
bool is_one_time,
bool is_final_decision) { … }
void PermissionContextBase::CleanUpRequest(
const PermissionRequestID& id,
bool embedded_permission_element_initiated) { … }
void PermissionContextBase::UpdateContentSetting(const GURL& requesting_origin,
const GURL& embedding_origin,
ContentSetting content_setting,
bool is_one_time) { … }
bool PermissionContextBase::PermissionAllowedByPermissionsPolicy(
content::RenderFrameHost* rfh) const { … }
void PermissionContextBase::NotifyObservers(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsTypeSet content_type_set) const { … }
}