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
|
// Copyright 2021 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_WEB_APPLICATIONS_SUB_APPS_SERVICE_IMPL_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_SUB_APPS_SERVICE_IMPL_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/document_service.h"
#include "third_party/blink/public/mojom/subapps/sub_apps_service.mojom.h"
namespace content {
class RenderFrameHost;
}
namespace web_app {
namespace {
struct SubAppInstallParams {
webapps::ManifestId manifest_id;
GURL install_url;
};
struct SubAppInstallResult {
webapps::ManifestId manifest_id;
webapps::AppId app_id;
webapps::InstallResultCode install_result_code;
};
} // namespace
class SubAppsInstallDialogController;
class SubAppsServiceImpl
: public content::DocumentService<blink::mojom::SubAppsService> {
public:
using AddResultsMojo = std::vector<blink::mojom::SubAppsServiceAddResultPtr>;
static constexpr char kSubAppsUninstallNotificationId[] =
"sub_apps_uninstall_notification";
SubAppsServiceImpl(const SubAppsServiceImpl&) = delete;
SubAppsServiceImpl& operator=(const SubAppsServiceImpl&) = delete;
~SubAppsServiceImpl() override;
// We only want to create this object when the Browser* associated with the
// WebContents is an Isolated Web App and when the RFH is the main frame.
static void CreateIfAllowed(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::SubAppsService> receiver);
// blink::mojom::SubAppsService
void Add(
std::vector<blink::mojom::SubAppsServiceAddParametersPtr> sub_apps_to_add,
AddCallback result_callback) override;
void List(ListCallback result_callback) override;
void Remove(const std::vector<std::string>& manifest_id_paths,
RemoveCallback result_callback) override;
private:
struct AddCallInfo {
AddCallInfo();
~AddCallInfo();
AddCallback mojo_callback;
std::vector<std::unique_ptr<WebAppInstallInfo>> install_infos;
std::unique_ptr<SubAppsInstallDialogController> install_dialog;
AddResultsMojo results;
};
void CollectInstallData(int add_call_id,
std::vector<SubAppInstallParams> requested_installs,
webapps::ManifestId parent_manifest_id);
void ProcessInstallData(
int add_call_id,
std::vector<std::pair<webapps::ManifestId,
std::unique_ptr<WebAppInstallInfo>>> install_data);
void ScheduleSubAppInstalls(int add_call_id);
void ProcessDialogResponse(int add_call_id, bool dialog_accepted);
void FinishAddCallOrShowInstallDialog(int add_call_id);
void FinishAddCall(int add_call_id,
std::vector<SubAppInstallResult> install_results);
void RemoveSubApp(
const std::string& manifest_id_path,
base::OnceCallback<void(blink::mojom::SubAppsServiceRemoveResultPtr)>
remove_barrier_callback,
const webapps::AppId* calling_app_id);
void NotifyUninstall(
RemoveCallback result_callback,
std::vector<blink::mojom::SubAppsServiceRemoveResultPtr> remove_results);
SubAppsServiceImpl(
content::RenderFrameHost& render_frame_host,
mojo::PendingReceiver<blink::mojom::SubAppsService> receiver);
int next_add_call_id_ = 0;
std::map<int, AddCallInfo> add_call_info_;
base::WeakPtrFactory<SubAppsServiceImpl> weak_ptr_factory_{this};
};
} // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_SUB_APPS_SERVICE_IMPL_H_
|