1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_WEB_APP_INTERNALS_IWA_INTERNALS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_WEB_APP_INTERNALS_IWA_INTERNALS_HANDLER_H_
#include <cstdint>
#include <optional>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/types/expected.h"
#include "base/types/optional_ref.h"
#include "base/version.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/web_app_internals/web_app_internals.mojom.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/web_ui.h"
#include "url/gurl.h"
namespace web_app {
class IwaSourceDevModeWithFileOp;
class ScopedTempWebBundleFile;
class WebAppInternalsIwaInstallationBrowserTest;
struct InstallIsolatedWebAppCommandSuccess;
// Handles API requests from chrome://web-app-internals related to IWAs.
// This class is supposed to be used by WebAppInternalsHandler.
class IwaInternalsHandler {
public:
using Handler = ::mojom::WebAppInternalsHandler;
IwaInternalsHandler(content::WebUI& web_ui, Profile& profile);
~IwaInternalsHandler();
IwaInternalsHandler(const IwaInternalsHandler&) = delete;
IwaInternalsHandler& operator=(const IwaInternalsHandler&) = delete;
void InstallIsolatedWebAppFromDevProxy(
const GURL& url,
Handler::InstallIsolatedWebAppFromDevProxyCallback callback);
void ParseUpdateManifestFromUrl(
const GURL& update_manifest_url,
Handler::ParseUpdateManifestFromUrlCallback callback);
void InstallIsolatedWebAppFromBundleUrl(
::mojom::InstallFromBundleUrlParamsPtr params,
Handler::InstallIsolatedWebAppFromBundleUrlCallback callback);
void SelectFileAndInstallIsolatedWebAppFromDevBundle(
Handler::SelectFileAndInstallIsolatedWebAppFromDevBundleCallback
callback);
void SelectFileAndUpdateIsolatedWebAppFromDevBundle(
const webapps::AppId& app_id,
Handler::SelectFileAndUpdateIsolatedWebAppFromDevBundleCallback callback);
void SearchForIsolatedWebAppUpdates(
Handler::SearchForIsolatedWebAppUpdatesCallback callback);
void GetIsolatedWebAppDevModeAppInfo(
Handler::GetIsolatedWebAppDevModeAppInfoCallback callback);
void UpdateDevProxyIsolatedWebApp(
const webapps::AppId& app_id,
Handler::UpdateDevProxyIsolatedWebAppCallback callback);
void RotateKey(const std::string& web_bundle_id,
const std::optional<std::vector<uint8_t>>& public_key);
void UpdateManifestInstalledIsolatedWebApp(
const webapps::AppId& app_id,
Handler::UpdateManifestInstalledIsolatedWebAppCallback callback);
void SetUpdateChannelForIsolatedWebApp(
const webapps::AppId& app_id,
const std::string& update_channel,
Handler::SetUpdateChannelForIsolatedWebAppCallback callback);
void SetPinnedVersionForIsolatedWebApp(
const webapps::AppId& app_id,
const std::string pinned_version,
Handler::SetPinnedVersionForIsolatedWebAppCallback callback);
void ResetPinnedVersionForIsolatedWebApp(const webapps::AppId& app_id);
void SetAllowDowngradesForIsolatedWebApp(bool allow_downgrades,
const webapps::AppId& app_id);
private:
class IsolatedWebAppDevBundleSelectListener;
class IwaManifestInstallUpdateHandler;
friend class web_app::WebAppInternalsIwaInstallationBrowserTest;
Profile* profile() { return &profile_.get(); }
void DownloadWebBundleToFile(
const GURL& web_bundle_url,
::mojom::UpdateInfoPtr update_info,
Handler::InstallIsolatedWebAppFromBundleUrlCallback callback,
web_app::ScopedTempWebBundleFile file);
void OnWebBundleDownloaded(
::mojom::UpdateInfoPtr update_info,
Handler::InstallIsolatedWebAppFromBundleUrlCallback callback,
web_app::ScopedTempWebBundleFile bundle,
int32_t result);
void OnIsolatedWebAppDevModeBundleSelected(
Handler::SelectFileAndInstallIsolatedWebAppFromDevBundleCallback callback,
std::optional<base::FilePath> path);
void OnIsolatedWebAppDevModeBundleSelectedForUpdate(
const webapps::AppId& app_id,
Handler::SelectFileAndUpdateIsolatedWebAppFromDevBundleCallback callback,
std::optional<base::FilePath> path);
void OnInstallIsolatedWebAppInDevMode(
base::OnceCallback<void(::mojom::InstallIsolatedWebAppResultPtr)>
callback,
base::expected<InstallIsolatedWebAppCommandSuccess, std::string> result);
void OnInstalledIsolatedWebAppInDevModeFromWebBundle(
::mojom::UpdateInfoPtr update_info,
base::OnceCallback<void(::mojom::InstallIsolatedWebAppResultPtr)>
callback,
base::expected<InstallIsolatedWebAppCommandSuccess, std::string> result);
// Discovers and applies an update for a dev mode Isolated Web App identified
// by its app id. If `location` is set, then the update will be read from the
// provided location, otherwise the existing location will be used.
void ApplyDevModeUpdate(
const webapps::AppId& app_id,
base::optional_ref<const web_app::IwaSourceDevModeWithFileOp> location,
base::OnceCallback<void(const std::string&)> callback);
const raw_ref<content::WebUI> web_ui_;
const raw_ref<Profile> profile_;
base::flat_map<webapps::AppId, base::Version> pinned_versions_;
base::flat_set<webapps::AppId> app_ids_allowing_downgrades_;
// Runs updates for manifest-installed dev-mode apps.
// Will be nullptr if WebAppProvider is not available for the current
// `profile_`.
std::unique_ptr<IwaManifestInstallUpdateHandler> update_handler_;
base::WeakPtrFactory<IwaInternalsHandler> weak_ptr_factory_{this};
};
} // namespace web_app
#endif // CHROME_BROWSER_UI_WEBUI_WEB_APP_INTERNALS_IWA_INTERNALS_HANDLER_H_
|