#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/web_applications/web_app.h"
#include <array>
#include <bitset>
#include <ostream>
#include <string>
#include <tuple>
#include <utility>
#include "base/check.h"
#include "base/check_is_test.h"
#include "base/check_op.h"
#include "base/containers/flat_tree.h"
#include "base/containers/to_value_list.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/numerics/clamped_math.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/to_string.h"
#include "base/types/optional_util.h"
#include "base/values.h"
#include "chrome/browser/web_applications/generated_icon_fix_util.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_storage_location.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom-shared.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/proto/web_app_proto_package.pb.h"
#include "chrome/browser/web_applications/user_display_mode.h"
#include "chrome/browser/web_applications/web_app_chromeos_data.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_proto_utils.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "components/sync/base/time.h"
#include "components/sync/protocol/proto_value_conversions.h"
#include "components/sync/protocol/web_app_specifics.pb.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h"
#include "third_party/blink/public/common/permissions_policy/policy_helper_public.h"
#include "third_party/blink/public/common/safe_url_pattern.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/manifest_launch_handler.mojom-shared.h"
#include "third_party/liburlpattern/options.h"
#include "third_party/liburlpattern/pattern.h"
#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/size.h"
#include "url/origin.h"
namespace web_app {
namespace {
template <typename T>
base::Value OptionalToStringValue(const std::optional<T>& optional) { … }
template <typename T>
base::Value OptionalAsDebugValue(const std::optional<T>& optional) { … }
std::string ColorToString(std::optional<SkColor> color) { … }
std::string ApiApprovalStateToString(ApiApprovalState state) { … }
std::string GetRunOnOsLoginMode(const proto::RunOnOsLoginMode& mode) { … }
base::Value OsStatesDebugValue(
const proto::WebAppOsIntegrationState& current_states) { … }
base::Value::Dict ImageResourceDebugDict(
const blink::Manifest::ImageResource& icon) { … }
base::Value::Dict UrlPatternDebugValue(const blink::SafeUrlPattern& pattern) { … }
base::Value OptTabStripToDebugValue(
std::optional<blink::Manifest::TabStrip> tab_strip) { … }
}
WebApp::WebApp(const webapps::AppId& app_id)
: … { … }
WebApp::~WebApp() = default;
WebApp::WebApp(const WebApp& web_app) = default;
WebApp& WebApp::operator=(WebApp&& web_app) = default;
const SortedSizesPx& WebApp::downloaded_icon_sizes(IconPurpose purpose) const { … }
webapps::ManifestId WebApp::manifest_id() const { … }
void WebApp::AddSource(WebAppManagement::Type source) { … }
void WebApp::RemoveSource(WebAppManagement::Type source) { … }
bool WebApp::HasAnySources() const { … }
bool WebApp::HasOnlySource(WebAppManagement::Type source) const { … }
WebAppManagementTypes WebApp::GetSources() const { … }
bool WebApp::IsSynced() const { … }
bool WebApp::IsPreinstalledApp() const { … }
bool WebApp::IsPolicyInstalledApp() const { … }
bool WebApp::IsIwaPolicyInstalledApp() const { … }
bool WebApp::IsIwaShimlessRmaApp() const { … }
bool WebApp::IsSystemApp() const { … }
bool WebApp::IsWebAppStoreInstalledApp() const { … }
bool WebApp::IsSubAppInstalledApp() const { … }
bool WebApp::IsKioskInstalledApp() const { … }
bool WebApp::CanUserUninstallWebApp() const { … }
bool WebApp::WasInstalledByUser() const { … }
WebAppManagement::Type WebApp::GetHighestPrioritySource() const { … }
void WebApp::SetName(const std::string& name) { … }
void WebApp::SetDescription(const std::string& description) { … }
void WebApp::SetStartUrl(const GURL& start_url) { … }
void WebApp::SetScope(const GURL& scope) { … }
void WebApp::SetThemeColor(std::optional<SkColor> theme_color) { … }
void WebApp::SetDarkModeThemeColor(
std::optional<SkColor> dark_mode_theme_color) { … }
void WebApp::SetBackgroundColor(std::optional<SkColor> background_color) { … }
void WebApp::SetDarkModeBackgroundColor(
std::optional<SkColor> dark_mode_background_color) { … }
void WebApp::SetDisplayMode(DisplayMode display_mode) { … }
void WebApp::SetUserDisplayMode(mojom::UserDisplayMode user_display_mode) { … }
void WebApp::SetDisplayModeOverride(
std::vector<DisplayMode> display_mode_override) { … }
void WebApp::SetWebAppChromeOsData(
std::optional<WebAppChromeOsData> chromeos_data) { … }
void WebApp::SetInstallState(proto::InstallState install_state) { … }
void WebApp::SetIsFromSyncAndPendingInstallation(
bool is_from_sync_and_pending_installation) { … }
void WebApp::SetIsUninstalling(bool is_uninstalling) { … }
void WebApp::SetManifestIcons(std::vector<apps::IconInfo> manifest_icons) { … }
void WebApp::SetDownloadedIconSizes(IconPurpose purpose, SortedSizesPx sizes) { … }
void WebApp::SetIsGeneratedIcon(bool is_generated_icon) { … }
void WebApp::SetFileHandlers(apps::FileHandlers file_handlers) { … }
void WebApp::SetFileHandlerApprovalState(ApiApprovalState approval_state) { … }
void WebApp::SetShareTarget(std::optional<apps::ShareTarget> share_target) { … }
void WebApp::SetAdditionalSearchTerms(
std::vector<std::string> additional_search_terms) { … }
void WebApp::SetProtocolHandlers(
std::vector<apps::ProtocolHandlerInfo> handlers) { … }
void WebApp::SetAllowedLaunchProtocols(
base::flat_set<std::string> allowed_launch_protocols) { … }
void WebApp::SetDisallowedLaunchProtocols(
base::flat_set<std::string> disallowed_launch_protocols) { … }
void WebApp::SetUrlHandlers(apps::UrlHandlers url_handlers) { … }
void WebApp::SetScopeExtensions(
base::flat_set<ScopeExtensionInfo> scope_extensions) { … }
void WebApp::SetValidatedScopeExtensions(
base::flat_set<ScopeExtensionInfo> validated_scope_extensions) { … }
void WebApp::SetLockScreenStartUrl(const GURL& lock_screen_start_url) { … }
void WebApp::SetNoteTakingNewNoteUrl(const GURL& note_taking_new_note_url) { … }
void WebApp::SetShortcutsMenuInfo(
std::vector<WebAppShortcutsMenuItemInfo> shortcuts_menu_item_infos) { … }
void WebApp::SetLastBadgingTime(const base::Time& time) { … }
void WebApp::SetLastLaunchTime(const base::Time& time) { … }
void WebApp::SetFirstInstallTime(const base::Time& time) { … }
void WebApp::SetManifestUpdateTime(const base::Time& time) { … }
void WebApp::SetRunOnOsLoginMode(RunOnOsLoginMode mode) { … }
void WebApp::SetSyncProto(sync_pb::WebAppSpecifics sync_proto) { … }
void WebApp::SetCaptureLinks(blink::mojom::CaptureLinks capture_links) { … }
void WebApp::SetLaunchQueryParams(
std::optional<std::string> launch_query_params) { … }
void WebApp::SetManifestUrl(const GURL& manifest_url) { … }
void WebApp::SetManifestId(const webapps::ManifestId& manifest_id) { … }
void WebApp::SetWindowControlsOverlayEnabled(bool enabled) { … }
void WebApp::SetLaunchHandler(std::optional<LaunchHandler> launch_handler) { … }
void WebApp::SetParentAppId(
const std::optional<webapps::AppId>& parent_app_id) { … }
void WebApp::SetPermissionsPolicy(
blink::ParsedPermissionsPolicy permissions_policy) { … }
void WebApp::SetLatestInstallSource(
std::optional<webapps::WebappInstallSource> latest_install_source) { … }
void WebApp::SetAppSizeInBytes(std::optional<int64_t> app_size_in_bytes) { … }
void WebApp::SetDataSizeInBytes(std::optional<int64_t> data_size_in_bytes) { … }
void WebApp::SetWebAppManagementExternalConfigMap(
ExternalConfigMap management_to_external_config_map) { … }
void WebApp::SetTabStrip(std::optional<blink::Manifest::TabStrip> tab_strip) { … }
void WebApp::SetCurrentOsIntegrationStates(
proto::WebAppOsIntegrationState current_os_integration_states) { … }
void WebApp::SetIsolationData(IsolationData isolation_data) { … }
void WebApp::SetLinkCapturingUserPreference(
proto::LinkCapturingUserPreference user_link_capturing_preference) { … }
void WebApp::SetSupportedLinksOfferIgnoreCount(int ignore_count) { … }
void WebApp::SetSupportedLinksOfferDismissCount(int dismiss_count) { … }
void WebApp::SetIsDiyApp(bool is_diy_app) { … }
void WebApp::AddPlaceholderInfoToManagementExternalConfigMap(
WebAppManagement::Type type,
bool is_placeholder) { … }
void WebApp::AddInstallURLToManagementExternalConfigMap(
WebAppManagement::Type type,
GURL install_url) { … }
void WebApp::AddPolicyIdToManagementExternalConfigMap(
WebAppManagement::Type type,
std::string policy_id) { … }
void WebApp::AddExternalSourceInformation(WebAppManagement::Type type,
GURL install_url,
bool is_placeholder) { … }
bool WebApp::RemoveInstallUrlForSource(WebAppManagement::Type type,
const GURL& install_url) { … }
void WebApp::SetAlwaysShowToolbarInFullscreen(bool show) { … }
void WebApp::SetLatestInstallTime(const base::Time& latest_install_time) { … }
void WebApp::SetGeneratedIconFix(
std::optional<GeneratedIconFix> generated_icon_fix) { … }
WebApp::ClientData::ClientData() = default;
WebApp::ClientData::~ClientData() = default;
WebApp::ClientData::ClientData(const ClientData& client_data) = default;
base::Value WebApp::ClientData::AsDebugValue() const { … }
WebApp::ExternalManagementConfig::ExternalManagementConfig() = default;
WebApp::ExternalManagementConfig::ExternalManagementConfig(
bool is_placeholder,
const base::flat_set<GURL>& install_urls,
const base::flat_set<std::string>& additional_policy_ids)
: … { … }
WebApp::ExternalManagementConfig::~ExternalManagementConfig() = default;
WebApp::ExternalManagementConfig::ExternalManagementConfig(
const ExternalManagementConfig& external_management_config) = default;
WebApp::ExternalManagementConfig& WebApp::ExternalManagementConfig::operator=(
const ExternalManagementConfig& external_management_config) = default;
WebApp::ExternalManagementConfig& WebApp::ExternalManagementConfig::operator=(
ExternalManagementConfig&& external_management_config) = default;
base::Value::Dict WebApp::ExternalManagementConfig::AsDebugValue() const { … }
WebApp::IsolationData::IsolationData(IsolatedWebAppStorageLocation location,
base::Version version)
: … { … }
WebApp::IsolationData::IsolationData(
IsolatedWebAppStorageLocation location,
base::Version version,
const std::set<std::string>& controlled_frame_partitions,
const std::optional<PendingUpdateInfo>& pending_update_info,
std::optional<IsolatedWebAppIntegrityBlockData> integrity_block_data)
: … { … }
WebApp::IsolationData::~IsolationData() = default;
WebApp::IsolationData::IsolationData(const WebApp::IsolationData&) = default;
WebApp::IsolationData& WebApp::IsolationData::operator=(
const WebApp::IsolationData&) = default;
WebApp::IsolationData::IsolationData(WebApp::IsolationData&&) = default;
WebApp::IsolationData& WebApp::IsolationData::operator=(
WebApp::IsolationData&&) = default;
bool WebApp::IsolationData::operator==(
const WebApp::IsolationData& other) const = default;
bool WebApp::IsolationData::operator!=(
const WebApp::IsolationData& other) const = default;
base::Value WebApp::IsolationData::AsDebugValue() const { … }
WebApp::IsolationData::PendingUpdateInfo::PendingUpdateInfo(
IsolatedWebAppStorageLocation location,
base::Version version,
std::optional<IsolatedWebAppIntegrityBlockData> integrity_block_data)
: … { … }
WebApp::IsolationData::PendingUpdateInfo::~PendingUpdateInfo() = default;
WebApp::IsolationData::PendingUpdateInfo::PendingUpdateInfo(
const PendingUpdateInfo&) = default;
WebApp::IsolationData::PendingUpdateInfo&
WebApp::IsolationData::PendingUpdateInfo::operator=(const PendingUpdateInfo&) =
default;
base::Value WebApp::IsolationData::PendingUpdateInfo::AsDebugValue() const { … }
void WebApp::IsolationData::SetPendingUpdateInfo(
const std::optional<PendingUpdateInfo>& pending_update_info) { … }
const std::optional<GeneratedIconFix>& WebApp::generated_icon_fix() const { … }
bool WebApp::IsolationData::PendingUpdateInfo::operator==(
const WebApp::IsolationData::PendingUpdateInfo& other) const = default;
bool WebApp::IsolationData::PendingUpdateInfo::operator!=(
const WebApp::IsolationData::PendingUpdateInfo& other) const = default;
bool WebApp::operator==(const WebApp& other) const { … }
bool WebApp::operator!=(const WebApp& other) const { … }
base::Value WebApp::AsDebugValueWithOnlyPlatformAgnosticFields() const { … }
base::Value WebApp::AsDebugValue() const { … }
std::ostream& operator<<(std::ostream& out, const WebApp& app) { … }
std::ostream& operator<<(
std::ostream& out,
const WebApp::ExternalManagementConfig& management_config) { … }
bool operator==(const WebApp::ExternalManagementConfig& management_config1,
const WebApp::ExternalManagementConfig& management_config2) { … }
bool operator!=(const WebApp::ExternalManagementConfig& management_config1,
const WebApp::ExternalManagementConfig& management_config2) { … }
namespace proto {
bool operator==(const WebAppOsIntegrationState& os_integration_state1,
const WebAppOsIntegrationState& os_integration_state2) { … }
bool operator!=(const WebAppOsIntegrationState& os_integration_state1,
const WebAppOsIntegrationState& os_integration_state2) { … }
}
std::vector<std::string> GetSerializedAllowedOrigins(
const blink::ParsedPermissionsPolicyDeclaration
permissions_policy_declaration) { … }
}
namespace sync_pb {
bool operator==(const WebAppSpecifics& sync_proto1,
const WebAppSpecifics& sync_proto2) { … }
bool operator!=(const WebAppSpecifics& sync_proto1,
const WebAppSpecifics& sync_proto2) { … }
}