#include "components/permissions/permission_request.h"
#include <string>
#include <utility>
#include "base/check.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_util.h"
#include "components/permissions/request_type.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/elide_url.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/text_elider.h"
#include "ui/strings/grit/ui_strings.h"
namespace permissions {
PermissionRequest::PermissionRequest(
const GURL& requesting_origin,
RequestType request_type,
bool has_gesture,
PermissionDecidedCallback permission_decided_callback,
base::OnceClosure delete_callback)
: … { … }
PermissionRequest::PermissionRequest(
PermissionRequestData request_data,
PermissionDecidedCallback permission_decided_callback,
base::OnceClosure delete_callback,
bool uses_automatic_embargo)
: … { … }
PermissionRequest::~PermissionRequest() { … }
RequestType PermissionRequest::request_type() const { … }
bool PermissionRequest::IsDuplicateOf(PermissionRequest* other_request) const { … }
base::WeakPtr<PermissionRequest> PermissionRequest::GetWeakPtr() { … }
#if BUILDFLAG(IS_ANDROID)
PermissionRequest::AnnotatedMessageText::AnnotatedMessageText(
std::u16string text,
std::vector<std::pair<size_t, size_t>> bolded_ranges)
: text(text), bolded_ranges(bolded_ranges) {}
PermissionRequest::AnnotatedMessageText::~AnnotatedMessageText() = default;
PermissionRequest::AnnotatedMessageText
PermissionRequest::GetDialogAnnotatedMessageText(
const GURL& embedding_origin) const {
int message_id = 0;
std::u16string requesting_origin_string_formatted =
url_formatter::FormatUrlForSecurityDisplay(
requesting_origin(),
url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
std::u16string embedding_origin_string_formatted =
url_formatter::FormatUrlForSecurityDisplay(
embedding_origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
switch (request_type()) {
case RequestType::kAccessibilityEvents:
message_id = IDS_ACCESSIBILITY_EVENTS_INFOBAR_TEXT;
break;
case RequestType::kArSession:
message_id = IDS_AR_INFOBAR_TEXT;
break;
case RequestType::kCameraStream:
message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_INFOBAR_TEXT;
break;
case RequestType::kClipboard:
message_id = IDS_CLIPBOARD_INFOBAR_TEXT;
break;
case RequestType::kDiskQuota:
NOTREACHED_IN_MIGRATION();
break;
case RequestType::kHandTracking:
message_id = IDS_HAND_TRACKING_INFOBAR_TEXT;
break;
case RequestType::kGeolocation:
message_id = IDS_GEOLOCATION_INFOBAR_TEXT;
break;
case RequestType::kIdleDetection:
message_id = IDS_IDLE_DETECTION_INFOBAR_TEXT;
break;
case RequestType::kMicStream:
message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_INFOBAR_TEXT;
break;
case RequestType::kMidiSysex:
message_id = IDS_MIDI_SYSEX_INFOBAR_TEXT;
break;
case RequestType::kMultipleDownloads:
message_id = IDS_MULTI_DOWNLOAD_WARNING;
break;
case RequestType::kNfcDevice:
message_id = IDS_NFC_INFOBAR_TEXT;
break;
case RequestType::kNotifications:
message_id = IDS_NOTIFICATIONS_INFOBAR_TEXT;
break;
case RequestType::kProtectedMediaIdentifier:
message_id =
IDS_PROTECTED_MEDIA_IDENTIFIER_PER_ORIGIN_PROVISIONING_INFOBAR_TEXT;
break;
case RequestType::kStorageAccess:
return AnnotatedMessageText(
l10n_util::GetStringFUTF16(
IDS_CONCAT_TWO_STRINGS_WITH_PERIODS,
l10n_util::GetStringFUTF16(
IDS_STORAGE_ACCESS_PERMISSION_TWO_ORIGIN_PROMPT_TITLE,
requesting_origin_string_formatted),
l10n_util::GetStringFUTF16(
IDS_STORAGE_ACCESS_PERMISSION_TWO_ORIGIN_EXPLANATION,
requesting_origin_string_formatted,
embedding_origin_string_formatted)),
{});
case RequestType::kTopLevelStorageAccess:
NOTREACHED_IN_MIGRATION();
break;
case RequestType::kVrSession:
message_id = IDS_VR_INFOBAR_TEXT;
break;
case RequestType::kIdentityProvider:
message_id = IDS_IDENTITY_PROVIDER_INFOBAR_TEXT;
break;
}
DCHECK_NE(0, message_id);
return GetDialogAnnotatedMessageText(
requesting_origin_string_formatted, message_id,
permissions::PermissionUtil::DoesSupportTemporaryGrants(
GetContentSettingsType()));
}
PermissionRequest::AnnotatedMessageText
PermissionRequest::GetDialogAnnotatedMessageText(
std::u16string requesting_origin_formatted_for_display,
int message_id,
bool format_origin_bold) {
std::vector<size_t> offsets;
std::u16string text = l10n_util::GetStringFUTF16(
message_id, {requesting_origin_formatted_for_display}, &offsets);
std::vector<std::pair<size_t, size_t>> bolded_ranges;
if (format_origin_bold) {
for (auto offset : offsets) {
bolded_ranges.emplace_back(
offset, offset + requesting_origin_formatted_for_display.length());
}
}
return AnnotatedMessageText(text, bolded_ranges);
}
#endif
bool PermissionRequest::IsEmbeddedPermissionElementInitiated() const { … }
std::optional<gfx::Rect> PermissionRequest::GetAnchorElementPosition() const { … }
#if !BUILDFLAG(IS_ANDROID)
bool PermissionRequest::IsConfirmationChipSupported() { … }
IconId PermissionRequest::GetIconForChip() { … }
IconId PermissionRequest::GetBlockedIconForChip() { … }
std::optional<std::u16string> PermissionRequest::GetRequestChipText(
ChipTextType type) const { … }
std::u16string PermissionRequest::GetMessageTextFragment() const { … }
#endif
std::optional<std::u16string> PermissionRequest::GetAllowAlwaysText() const { … }
bool PermissionRequest::ShouldUseTwoOriginPrompt() const { … }
void PermissionRequest::PermissionGranted(bool is_one_time) { … }
void PermissionRequest::PermissionDenied() { … }
void PermissionRequest::Cancelled(bool is_final_decision) { … }
void PermissionRequest::RequestFinished() { … }
PermissionRequestGestureType PermissionRequest::GetGestureType() const { … }
const std::vector<std::string>&
PermissionRequest::GetRequestedAudioCaptureDeviceIds() const { … }
const std::vector<std::string>&
PermissionRequest::GetRequestedVideoCaptureDeviceIds() const { … }
ContentSettingsType PermissionRequest::GetContentSettingsType() const { … }
std::u16string PermissionRequest::GetPermissionNameTextFragment() const { … }
void PermissionRequest::SetEmbeddedPermissionElementInitiatedForTesting(
bool embedded_permission_element_initiated) { … }
}