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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_WEBAPPS_BROWSER_WEBAPPS_CLIENT_H_
#define COMPONENTS_WEBAPPS_BROWSER_WEBAPPS_CLIENT_H_
#include <memory>
#include "base/auto_reset.h"
#include "build/build_config.h"
#include "components/security_state/core/security_state.h"
#include "components/webapps/common/web_app_id.h"
class GURL;
namespace blink::mojom {
class Manifest;
}
namespace content {
class BrowserContext;
class WebContents;
} // namespace content
namespace infobars {
class ContentInfoBarManager;
} // namespace infobars
namespace segmentation_platform {
class SegmentationPlatformService;
} // namespace segmentation_platform
namespace url {
class Origin;
} // namespace url
namespace webapps {
class AppBannerManager;
enum class InstallTrigger;
enum class WebappInstallSource;
struct AddToHomescreenParams;
// Interface to be implemented by the embedder (such as Chrome or WebLayer) to
// expose embedder specific logic.
class WebappsClient {
public:
WebappsClient();
WebappsClient(const WebappsClient&) = delete;
WebappsClient& operator=(const WebappsClient&) = delete;
virtual ~WebappsClient();
// Return the webapps client.
static WebappsClient* Get();
// Returns true if the given Origin should be considered secure enough to
// host an app. Returning false signals that other checks should be
// performed, not that the app is insecure.
virtual bool IsOriginConsideredSecure(const url::Origin& url) = 0;
virtual security_state::SecurityLevel GetSecurityLevelForWebContents(
content::WebContents* web_contents) = 0;
virtual infobars::ContentInfoBarManager* GetInfoBarManagerForWebContents(
content::WebContents* web_contents) = 0;
virtual WebappInstallSource GetInstallSource(
content::WebContents* web_contents,
InstallTrigger trigger) = 0;
virtual AppBannerManager* GetAppBannerManager(
content::WebContents* web_contents) = 0;
using WebAppInstallationConflictCallback = base::OnceCallback<void(bool)>;
// Returns if any current installations conflict with a new web app with the
// given start_url and manifest_id using callback. See the implementing class
// for more details on their behavior. Returning true here signifies that an
// app is already installed here.
// Note: The callback is executed synchonously within the function call on
// desktop.
virtual void DoesNewWebAppConflictWithExistingInstallation(
content::BrowserContext* browser_context,
const GURL& start_url,
const ManifestId& manifest_id,
WebAppInstallationConflictCallback callback) const = 0;
// Returns if the web contents this manager is on is inside of an app context.
virtual bool IsInAppBrowsingContext(
content::WebContents* web_contents) const = 0;
// Tracks whether the current site URL obtained from the web_contents is not
// locally installed.
virtual bool IsAppPartiallyInstalledForSiteUrl(
content::BrowserContext* browsing_context,
const GURL& site_url) const = 0;
// Tracks whether the current site URL obtained from the web_contents is fully
// installed. The only difference from
// DoesNewWebAppConflictWithExistingInstallation() is that the former
// considers the scope obtained from a manifest as check for if an app is
// already installed.
virtual bool IsAppFullyInstalledForSiteUrl(
content::BrowserContext* browsing_context,
const GURL& site_url) const = 0;
virtual bool IsUrlControlledBySeenManifest(
content::BrowserContext* browsing_context,
const GURL& site_url) const = 0;
// Called when a manifest is seen by the AppBannerManager. This manifest
// must be non-empty. Note that this may be the 'default' manifest.
virtual void OnManifestSeen(content::BrowserContext* browsing_context,
const blink::mojom::Manifest& manifest) const = 0;
// The user has ignored the installation dialog and it went away due to
// another interaction (e.g. the tab was changed, page navigated, etc).
virtual void SaveInstallationIgnoredForMl(
content::BrowserContext* browsing_context,
const GURL& manifest_id) const = 0;
// The user has taken active action on the dialog to make it go away.
virtual void SaveInstallationDismissedForMl(
content::BrowserContext* browsing_context,
const GURL& manifest_id) const = 0;
virtual void SaveInstallationAcceptedForMl(
content::BrowserContext* browsing_context,
const GURL& manifest_id) const = 0;
virtual bool IsMlPromotionBlockedByHistoryGuardrail(
content::BrowserContext* browsing_context,
const GURL& manifest_id) const = 0;
virtual segmentation_platform::SegmentationPlatformService*
GetSegmentationPlatformService(
content::BrowserContext* browsing_context) const = 0;
using ScopedSegmentationServiceOverride = base::AutoReset<
std::unique_ptr<segmentation_platform::SegmentationPlatformService>>;
ScopedSegmentationServiceOverride OverrideSegmentationServiceForTesting(
std::unique_ptr<segmentation_platform::SegmentationPlatformService>
service);
#if BUILDFLAG(IS_ANDROID)
virtual bool IsInstallationInProgress(content::WebContents* web_contents,
const GURL& manifest_id) = 0;
virtual bool CanShowAppBanners(const content::WebContents* web_contents) = 0;
virtual void OnWebApkInstallInitiatedFromAppMenu(
content::WebContents* web_contents) = 0;
virtual void InstallWebApk(content::WebContents* web_contents,
const AddToHomescreenParams& params) = 0;
virtual void InstallShortcut(content::WebContents* web_contents,
const AddToHomescreenParams& params) = 0;
#endif
// Returns the id of the app that controls the last committed url of the given
// `web_contents`.
// Note: On Android this always returns `std::nullopt`.
virtual std::optional<webapps::AppId> GetAppIdForWebContents(
content::WebContents* web_contents) = 0;
protected:
segmentation_platform::SegmentationPlatformService*
segmentation_platform_for_testing() const {
return segmentation_platform_for_testing_.get();
}
private:
std::unique_ptr<segmentation_platform::SegmentationPlatformService>
segmentation_platform_for_testing_;
};
} // namespace webapps
#endif // COMPONENTS_WEBAPPS_BROWSER_WEBAPPS_CLIENT_H_
|