#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_install_command_helper.h"
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/base64.h"
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/functional/overloaded.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "base/version.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_features.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_install_source.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_integrity_block_data.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_response_reader_factory.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_source.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_storage_location.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_trust_checker.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_validator.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_version.h"
#include "chrome/browser/web_applications/isolated_web_apps/key_distribution/iwa_key_distribution_info_provider.h"
#include "chrome/browser/web_applications/isolated_web_apps/pending_install_info.h"
#include "chrome/browser/web_applications/web_app_icon_operations.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/browser/web_applications/web_contents/web_app_data_retriever.h"
#include "components/base32/base32.h"
#include "components/webapps/browser/installable/installable_logging.h"
#include "components/webapps/browser/installable/installable_manager.h"
#include "components/webapps/browser/web_contents/web_app_url_loader.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/reload_type.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/browser/web_contents.h"
#include "crypto/random.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "url/gurl.h"
namespace web_app {
namespace {
constexpr static char kGeneratedInstallPagePath[] = …;
constexpr unsigned kRandomDirNameOctetsLength = …;
std::string GenerateRandomDirName() { … }
enum class Operation { … };
base::expected<IsolatedWebAppStorageLocation, std::string>
CopyOrMoveSwbnToIwaDir(const base::FilePath& swbn_path,
const base::FilePath& profile_dir,
bool dev_mode,
Operation operation) { … }
void RemoveParentDirectory(const base::FilePath& path) { … }
bool IsUrlLoadingResultSuccess(webapps::WebAppUrlLoaderResult result) { … }
bool IntegrityBlockDataHasRotatedKey(
base::optional_ref<const IsolatedWebAppIntegrityBlockData>
integrity_block_data,
base::span<const uint8_t> rotated_key) { … }
}
void CleanupLocationIfOwned(const base::FilePath& profile_dir,
const IsolatedWebAppStorageLocation& location,
base::OnceClosure closure) { … }
void UpdateBundlePathAndCreateStorageLocation(
const base::FilePath& profile_dir,
const IwaSourceWithModeAndFileOp& source,
base::OnceCallback<void(
base::expected<IsolatedWebAppStorageLocation, std::string>)> callback) { … }
base::expected<std::reference_wrapper<const WebApp>, std::string>
GetIsolatedWebAppById(const WebAppRegistrar& registrar,
const webapps::AppId& iwa_id) { … }
base::flat_map<web_package::SignedWebBundleId,
std::reference_wrapper<const WebApp>>
GetInstalledIwas(const WebAppRegistrar& registrar) { … }
KeyRotationLookupResult LookupRotatedKey(
const web_package::SignedWebBundleId& web_bundle_id,
base::optional_ref<base::Value::Dict> debug_log) { … }
KeyRotationData GetKeyRotationData(
const web_package::SignedWebBundleId& web_bundle_id,
const WebApp::IsolationData& isolation_data) { … }
std::unique_ptr<content::WebContents>
IsolatedWebAppInstallCommandHelper::CreateIsolatedWebAppWebContents(
Profile& profile) { … }
std::unique_ptr<IsolatedWebAppResponseReaderFactory>
IsolatedWebAppInstallCommandHelper::CreateDefaultResponseReaderFactory(
Profile& profile) { … }
IsolatedWebAppInstallCommandHelper::IsolatedWebAppInstallCommandHelper(
IsolatedWebAppUrlInfo url_info,
std::unique_ptr<WebAppDataRetriever> data_retriever,
std::unique_ptr<IsolatedWebAppResponseReaderFactory>
response_reader_factory)
: … { … }
IsolatedWebAppInstallCommandHelper::~IsolatedWebAppInstallCommandHelper() =
default;
void IsolatedWebAppInstallCommandHelper::CheckTrustAndSignatures(
const IwaSourceWithMode& location,
Profile* profile,
base::OnceCallback<
void(base::expected<
std::optional<web_package::SignedWebBundleIntegrityBlock>,
std::string>)> callback) { … }
void IsolatedWebAppInstallCommandHelper::CheckTrustAndSignatures(
const IwaSourceWithMode& location,
Profile* profile,
base::OnceCallback<void(base::expected<void, std::string>)> callback) { … }
void IsolatedWebAppInstallCommandHelper::CheckTrustAndSignaturesOfBundle(
const base::FilePath& path,
bool dev_mode,
base::OnceCallback<
void(base::expected<
std::optional<web_package::SignedWebBundleIntegrityBlock>,
std::string>)> callback) { … }
void IsolatedWebAppInstallCommandHelper::OnTrustAndSignaturesOfBundleChecked(
base::OnceCallback<
void(base::expected<
std::optional<web_package::SignedWebBundleIntegrityBlock>,
std::string>)> callback,
base::expected<std::unique_ptr<IsolatedWebAppResponseReader>,
UnusableSwbnFileError> result) { … }
void IsolatedWebAppInstallCommandHelper::CreateStoragePartitionIfNotPresent(
Profile& profile) { … }
void IsolatedWebAppInstallCommandHelper::LoadInstallUrl(
const IwaSourceWithMode& source,
content::WebContents& web_contents,
webapps::WebAppUrlLoader& url_loader,
base::OnceCallback<void(base::expected<void, std::string>)> callback) { … }
void IsolatedWebAppInstallCommandHelper::OnLoadInstallUrl(
base::OnceCallback<void(base::expected<void, std::string>)> callback,
webapps::WebAppUrlLoaderResult result) { … }
void IsolatedWebAppInstallCommandHelper::CheckInstallabilityAndRetrieveManifest(
content::WebContents& web_contents,
base::OnceCallback<void(
base::expected<blink::mojom::ManifestPtr, std::string>)> callback) { … }
void IsolatedWebAppInstallCommandHelper::
OnCheckInstallabilityAndRetrieveManifest(
base::OnceCallback<void(
base::expected<blink::mojom::ManifestPtr, std::string>)> callback,
blink::mojom::ManifestPtr opt_manifest,
bool valid_manifest_for_web_app,
webapps::InstallableStatusCode error_code) { … }
base::expected<WebAppInstallInfo, std::string>
IsolatedWebAppInstallCommandHelper::ValidateManifestAndCreateInstallInfo(
const std::optional<base::Version>& expected_version,
const blink::mojom::Manifest& manifest) { … }
void IsolatedWebAppInstallCommandHelper::RetrieveIconsAndPopulateInstallInfo(
WebAppInstallInfo install_info,
content::WebContents& web_contents,
base::OnceCallback<void(base::expected<WebAppInstallInfo, std::string>)>
callback) { … }
void IsolatedWebAppInstallCommandHelper::OnRetrieveIcons(
WebAppInstallInfo install_info,
base::OnceCallback<void(base::expected<WebAppInstallInfo, std::string>)>
callback,
IconsDownloadedResult result,
IconsMap icons_map,
DownloadedIconsHttpResults unused_icons_http_results) { … }
}