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
|
// 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.
#include "chrome/browser/webapps/installable/installable_utils.h"
#include "build/build_config.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/android/shortcut_helper.h"
#else
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "url/url_constants.h"
#endif
bool DoesOriginContainAnyInstalledWebApp(
content::BrowserContext* browser_context,
const GURL& origin) {
DCHECK_EQ(origin, origin.DeprecatedGetOriginAsURL());
#if BUILDFLAG(IS_ANDROID)
return ShortcutHelper::DoesOriginContainAnyInstalledWebApk(origin);
#else
auto* provider = web_app::WebAppProvider::GetForWebApps(
Profile::FromBrowserContext(browser_context));
// TODO: Change this method to async, or document that the caller must know
// that WebAppProvider is started.
if (!provider || !provider->on_registry_ready().is_signaled())
return false;
// TODO(crbug.com/340952100): Evaluate call sites of DoesScopeContainAnyApp
// for correctness.
return provider->registrar_unsafe().DoesScopeContainAnyApp(
origin, {web_app::proto::InstallState::INSTALLED_WITH_OS_INTEGRATION,
web_app::proto::InstallState::INSTALLED_WITHOUT_OS_INTEGRATION});
#endif
}
std::set<GURL> GetOriginsWithInstalledWebApps(
content::BrowserContext* browser_context) {
#if BUILDFLAG(IS_ANDROID)
return ShortcutHelper::GetOriginsWithInstalledWebApksOrTwas();
#else
auto* provider = web_app::WebAppProvider::GetForWebApps(
Profile::FromBrowserContext(browser_context));
// TODO: Change this method to async, or document that the caller must know
// that WebAppProvider is started.
if (!provider || !provider->on_registry_ready().is_signaled())
return std::set<GURL>();
const web_app::WebAppRegistrar& registrar = provider->registrar_unsafe();
auto app_ids = registrar.GetAppIds();
std::set<GURL> installed_origins;
for (auto& app_id : app_ids) {
GURL origin = registrar.GetAppScope(app_id).DeprecatedGetOriginAsURL();
DCHECK(origin.is_valid());
if (origin.SchemeIs(url::kHttpsScheme)) {
installed_origins.emplace(origin);
}
}
return installed_origins;
#endif
}
|