#include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_deref.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/functional/concurrent_closures.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/syslog_logging.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/external_install_options.h"
#include "chrome/browser/web_applications/isolated_web_apps/policy/isolated_web_app_external_install_options.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/os_integration/os_integration_manager.h"
#include "chrome/browser/web_applications/os_integration/os_integration_sub_manager.h"
#include "chrome/browser/web_applications/policy/pre_redirection_url_observer.h"
#include "chrome/browser/web_applications/policy/web_app_policy_constants.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.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_id_constants.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "url/url_constants.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/system_features_disable_list_policy_handler.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "components/policy/core/common/policy_pref_names.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/web_applications/web_app_system_web_app_delegate_map_utils.h"
#include "components/user_manager/user_manager.h"
#endif
namespace {
bool IconInfosContainIconURL(const std::vector<apps::IconInfo>& icon_infos,
const GURL& url) { … }
bool AreForceInstalledAppsAllowed(Profile* profile) { … }
bool IsForceUnregistrationPolicyEnabled() { … }
}
namespace web_app {
BASE_FEATURE(…);
const char WebAppPolicyManager::kInstallResultHistogramName[];
WebAppPolicyManager::WebAppPolicyManager(Profile* profile)
: … { … }
WebAppPolicyManager::~WebAppPolicyManager() = default;
#if BUILDFLAG(IS_CHROMEOS_ASH)
void WebAppPolicyManager::SetSystemWebAppDelegateMap(
const ash::SystemWebAppDelegateMap* system_web_apps_delegate_map) {
system_web_apps_delegate_map_ = system_web_apps_delegate_map;
}
#endif
void WebAppPolicyManager::SetProvider(base::PassKey<WebAppProvider>,
WebAppProvider& provider) { … }
void WebAppPolicyManager::Start(
base::OnceClosure policy_settings_and_force_installs_applied) { … }
void WebAppPolicyManager::Shutdown() { … }
void WebAppPolicyManager::ReinstallPlaceholderAppIfNecessary(
const GURL& url,
ExternallyManagedAppManager::OnceInstallCallback on_complete) { … }
void WebAppPolicyManager::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
void WebAppPolicyManager::InitChangeRegistrarAndRefreshPolicy(
bool enable_pwa_support) { … }
void WebAppPolicyManager::OnDisableListPolicyChanged() { … }
void WebAppPolicyManager::OnSyncPolicySettingsCommandsComplete() { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
const std::set<ash::SystemWebAppType>&
WebAppPolicyManager::GetDisabledSystemWebApps() const {
return disabled_system_apps_;
}
#endif
const std::set<webapps::AppId>& WebAppPolicyManager::GetDisabledWebAppsIds()
const { … }
bool WebAppPolicyManager::IsWebAppInDisabledList(
const webapps::AppId& app_id) const { … }
bool WebAppPolicyManager::IsDisabledAppsModeHidden() const { … }
void WebAppPolicyManager::RefreshPolicyInstalledApps(
bool allow_close_and_relaunch) { … }
void WebAppPolicyManager::ParsePolicySettings() { … }
void WebAppPolicyManager::RefreshPolicySettings() { … }
void WebAppPolicyManager::ApplyPolicySettings() { … }
void WebAppPolicyManager::ApplyRunOnOsLoginPolicySettings(
base::OnceClosure policy_settings_applied_callback) { … }
void WebAppPolicyManager::ApplyForceOSUnregistrationPolicySettings(
base::OnceClosure policy_settings_applied_callback) { … }
std::optional<ExternalInstallOptions>
WebAppPolicyManager::ParseInstallPolicyEntry(const base::Value::Dict& entry) { … }
RunOnOsLoginPolicy WebAppPolicyManager::GetUrlRunOnOsLoginPolicy(
const webapps::AppId& app_id) const { … }
RunOnOsLoginPolicy WebAppPolicyManager::GetUrlRunOnOsLoginPolicyByManifestId(
const std::string& manifest_id) const { … }
void WebAppPolicyManager::SetOnAppsSynchronizedCompletedCallbackForTesting(
base::OnceClosure callback) { … }
void WebAppPolicyManager::SetRefreshPolicySettingsCompletedCallbackForTesting(
base::OnceClosure callback) { … }
void WebAppPolicyManager::RefreshPolicySettingsForTesting() { … }
void WebAppPolicyManager::OverrideManifest(
const GURL& custom_values_key,
blink::mojom::ManifestPtr& manifest) const { … }
void WebAppPolicyManager::MaybeOverrideManifest(
content::RenderFrameHost* frame_host,
blink::mojom::ManifestPtr& manifest) const { … }
bool WebAppPolicyManager::IsPreventCloseEnabled(
const webapps::AppId& app_id) const { … }
void WebAppPolicyManager::RefreshPolicyInstalledAppsForTesting(
bool allow_close_and_relaunch) { … }
void WebAppPolicyManager::OnAppsSynchronized(
std::map<GURL, ExternallyManagedAppManager::InstallResult> install_results,
std::map<GURL, webapps::UninstallResultCode> uninstall_results) { … }
bool WebAppPolicyManager::WebAppSetting::Parse(const base::Value::Dict& dict,
bool for_default_settings) { … }
WebAppPolicyManager::CustomManifestValues::CustomManifestValues() = default;
WebAppPolicyManager::CustomManifestValues::CustomManifestValues(
const WebAppPolicyManager::CustomManifestValues&) = default;
WebAppPolicyManager::CustomManifestValues::~CustomManifestValues() = default;
void WebAppPolicyManager::CustomManifestValues::SetName(
const std::string& utf8_name) { … }
void WebAppPolicyManager::CustomManifestValues::SetIcon(const GURL& icon_gurl) { … }
void WebAppPolicyManager::ObserveDisabledSystemFeaturesPolicy() { … }
void WebAppPolicyManager::OnDisableModePolicyChanged() { … }
void WebAppPolicyManager::PopulateDisabledWebAppsIdsLists() { … }
void WebAppPolicyManager::OnWebAppForceInstallPolicyParsed() { … }
}