Commit fdaf0951 authored by Dominick Ng's avatar Dominick Ng Committed by Commit Bot

Migrate extensions::BookmarkOrHostedAppInstalled() to AppRegistrar.

This CL deletes the extensions::BookmarkOrHostedAppInstalled() method,
and adds an abstract IsInstalled(const GURL& start_url) method to the
AppRegistrar to replace it. The new method's concrete implementation
lives in BookmarkAppRegistrar (migrated from its old home).

The existing call sites for the method are migrated as well.

BUG=891172

Change-Id: Ide93d8f6e799ad325ae8b8902b43787c89636601
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585281
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654777}
parent 010beefd
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
#include "chrome/browser/banners/app_banner_settings_helper.h" #include "chrome/browser/banners/app_banner_settings_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h" #include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h" #include "chrome/browser/web_applications/extensions/bookmark_app_util.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
...@@ -93,8 +95,10 @@ bool AppBannerManagerDesktop::IsWebAppConsideredInstalled( ...@@ -93,8 +95,10 @@ bool AppBannerManagerDesktop::IsWebAppConsideredInstalled(
const GURL& validated_url, const GURL& validated_url,
const GURL& start_url, const GURL& start_url,
const GURL& manifest_url) { const GURL& manifest_url) {
return extensions::BookmarkOrHostedAppInstalled( return web_app::WebAppProvider::Get(
web_contents->GetBrowserContext(), start_url); Profile::FromBrowserContext(web_contents->GetBrowserContext()))
->registrar()
.IsInstalled(start_url);
} }
void AppBannerManagerDesktop::ShowBannerUi(WebappInstallSource install_source) { void AppBannerManagerDesktop::ShowBannerUi(WebappInstallSource install_source) {
......
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h" #include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/install_manager.h" #include "chrome/browser/web_applications/components/install_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/components/web_app_utils.h" #include "chrome/browser/web_applications/components/web_app_utils.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h"
#include "chrome/common/extensions/extension_metrics.h" #include "chrome/common/extensions/extension_metrics.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
...@@ -368,7 +368,10 @@ ChromeManagementAPIDelegate::GenerateAppForLinkFunctionDelegate( ...@@ -368,7 +368,10 @@ ChromeManagementAPIDelegate::GenerateAppForLinkFunctionDelegate(
bool ChromeManagementAPIDelegate::IsWebAppInstalled( bool ChromeManagementAPIDelegate::IsWebAppInstalled(
content::BrowserContext* context, content::BrowserContext* context,
const GURL& web_app_url) const { const GURL& web_app_url) const {
return extensions::BookmarkOrHostedAppInstalled(context, web_app_url); auto* provider = web_app::WebAppProviderBase::GetProviderBase(
Profile::FromBrowserContext(context));
DCHECK(provider);
return provider->registrar().IsInstalled(web_app_url);
} }
bool ChromeManagementAPIDelegate::CanContextInstallWebApps( bool ChromeManagementAPIDelegate::CanContextInstallWebApps(
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h" #include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "extensions/browser/api/management/management_api.h" #include "extensions/browser/api/management/management_api.h"
...@@ -258,12 +259,13 @@ IN_PROC_BROWSER_TEST_F(InstallReplacementWebAppApiTest, InstallableWebApp) { ...@@ -258,12 +259,13 @@ IN_PROC_BROWSER_TEST_F(InstallReplacementWebAppApiTest, InstallableWebApp) {
chrome::SetAutoAcceptPWAInstallConfirmationForTesting(true); chrome::SetAutoAcceptPWAInstallConfirmationForTesting(true);
const GURL good_web_app_url = https_test_server_.GetURL(kGoodWebAppURL); const GURL good_web_app_url = https_test_server_.GetURL(kGoodWebAppURL);
EXPECT_FALSE(extensions::BookmarkOrHostedAppInstalled(browser()->profile(),
good_web_app_url)); auto* provider =
web_app::WebAppProviderBase::GetProviderBase(browser()->profile());
EXPECT_FALSE(provider->registrar().IsInstalled(good_web_app_url));
RunTest(kGoodWebAppURL, kBackground, true /* from_webstore */); RunTest(kGoodWebAppURL, kBackground, true /* from_webstore */);
EXPECT_TRUE(extensions::BookmarkOrHostedAppInstalled(browser()->profile(), EXPECT_TRUE(provider->registrar().IsInstalled(good_web_app_url));
good_web_app_url));
chrome::SetAutoAcceptPWAInstallConfirmationForTesting(false); chrome::SetAutoAcceptPWAInstallConfirmationForTesting(false);
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
class GURL;
namespace web_app { namespace web_app {
class AppRegistrar { class AppRegistrar {
...@@ -16,6 +18,12 @@ class AppRegistrar { ...@@ -16,6 +18,12 @@ class AppRegistrar {
virtual void Init(base::OnceClosure callback) = 0; virtual void Init(base::OnceClosure callback) = 0;
// Returns true if the app with the specified |start_url| is currently fully
// locally installed. The provided |start_url| must exactly match the launch
// URL for the app; this method does not consult the app scope or match URLs
// that fall within the scope.
virtual bool IsInstalled(const GURL& start_url) const = 0;
// Returns true if the app with |app_id| is currently installed. // Returns true if the app with |app_id| is currently installed.
virtual bool IsInstalled(const AppId& app_id) const = 0; virtual bool IsInstalled(const AppId& app_id) const = 0;
......
...@@ -9,10 +9,14 @@ ...@@ -9,10 +9,14 @@
#include "base/one_shot_event.h" #include "base/one_shot_event.h"
#include "chrome/browser/extensions/convert_web_app.h" #include "chrome/browser/extensions/convert_web_app.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h"
#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" #include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "url/gurl.h"
namespace extensions { namespace extensions {
...@@ -25,6 +29,27 @@ void BookmarkAppRegistrar::Init(base::OnceClosure callback) { ...@@ -25,6 +29,27 @@ void BookmarkAppRegistrar::Init(base::OnceClosure callback) {
ExtensionSystem::Get(profile_)->ready().Post(FROM_HERE, std::move(callback)); ExtensionSystem::Get(profile_)->ready().Post(FROM_HERE, std::move(callback));
} }
bool BookmarkAppRegistrar::IsInstalled(const GURL& start_url) const {
ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
const ExtensionSet& extensions = registry->enabled_extensions();
// Iterate through the extensions and extract the LaunchWebUrl (bookmark apps)
// or check the web extent (hosted apps).
for (const scoped_refptr<const Extension>& extension : extensions) {
if (!extension->is_hosted_app())
continue;
if (!BookmarkAppIsLocallyInstalled(profile_, extension.get()))
continue;
if (extension->web_extent().MatchesURL(start_url) ||
AppLaunchInfo::GetLaunchWebURL(extension.get()) == start_url) {
return true;
}
}
return false;
}
bool BookmarkAppRegistrar::IsInstalled(const web_app::AppId& app_id) const { bool BookmarkAppRegistrar::IsInstalled(const web_app::AppId& app_id) const {
return GetExtension(app_id) != nullptr; return GetExtension(app_id) != nullptr;
} }
......
...@@ -21,6 +21,7 @@ class BookmarkAppRegistrar : public web_app::AppRegistrar { ...@@ -21,6 +21,7 @@ class BookmarkAppRegistrar : public web_app::AppRegistrar {
// AppRegistrar // AppRegistrar
void Init(base::OnceClosure callback) override; void Init(base::OnceClosure callback) override;
bool IsInstalled(const GURL& start_url) const override;
bool IsInstalled(const web_app::AppId& app_id) const override; bool IsInstalled(const web_app::AppId& app_id) const override;
bool WasExternalAppUninstalledByUser( bool WasExternalAppUninstalledByUser(
const web_app::AppId& app_id) const override; const web_app::AppId& app_id) const override;
......
...@@ -55,28 +55,6 @@ bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs, ...@@ -55,28 +55,6 @@ bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs,
return true; return true;
} }
bool BookmarkOrHostedAppInstalled(content::BrowserContext* browser_context,
const GURL& url) {
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context);
const ExtensionSet& extensions = registry->enabled_extensions();
// Iterate through the extensions and extract the LaunchWebUrl (bookmark apps)
// or check the web extent (hosted apps).
for (const scoped_refptr<const Extension>& extension : extensions) {
if (!extension->is_hosted_app())
continue;
if (!BookmarkAppIsLocallyInstalled(browser_context, extension.get()))
continue;
if (extension->web_extent().MatchesURL(url) ||
AppLaunchInfo::GetLaunchWebURL(extension.get()) == url) {
return true;
}
}
return false;
}
bool IsInNavigationScopeForLaunchUrl(const GURL& launch_url, const GURL& url) { bool IsInNavigationScopeForLaunchUrl(const GURL& launch_url, const GURL& url) {
// Drop any "suffix" components after the path (Resolve "."): // Drop any "suffix" components after the path (Resolve "."):
const GURL nav_scope = launch_url.GetWithoutFilename(); const GURL nav_scope = launch_url.GetWithoutFilename();
......
...@@ -34,11 +34,6 @@ bool BookmarkAppIsLocallyInstalled(content::BrowserContext* context, ...@@ -34,11 +34,6 @@ bool BookmarkAppIsLocallyInstalled(content::BrowserContext* context,
bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs, bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs,
const Extension* extension); const Extension* extension);
// Returns true if a bookmark or hosted app from a given URL is already
// installed and enabled.
bool BookmarkOrHostedAppInstalled(content::BrowserContext* browser_context,
const GURL& url);
// Generates a scope based on |launch_url| and checks if the |url| falls under // Generates a scope based on |launch_url| and checks if the |url| falls under
// it. https://www.w3.org/TR/appmanifest/#navigation-scope // it. https://www.w3.org/TR/appmanifest/#navigation-scope
bool IsInNavigationScopeForLaunchUrl(const GURL& launch_url, const GURL& url); bool IsInNavigationScopeForLaunchUrl(const GURL& launch_url, const GURL& url);
......
...@@ -30,6 +30,11 @@ void TestAppRegistrar::AddAsExternalAppUninstalledByUser(const AppId& app_id) { ...@@ -30,6 +30,11 @@ void TestAppRegistrar::AddAsExternalAppUninstalledByUser(const AppId& app_id) {
void TestAppRegistrar::Init(base::OnceClosure callback) {} void TestAppRegistrar::Init(base::OnceClosure callback) {}
bool TestAppRegistrar::IsInstalled(const GURL& start_url) const {
NOTIMPLEMENTED();
return false;
}
bool TestAppRegistrar::IsInstalled(const AppId& app_id) const { bool TestAppRegistrar::IsInstalled(const AppId& app_id) const {
return base::ContainsKey(installed_apps_, app_id); return base::ContainsKey(installed_apps_, app_id);
} }
......
...@@ -28,6 +28,7 @@ class TestAppRegistrar : public AppRegistrar { ...@@ -28,6 +28,7 @@ class TestAppRegistrar : public AppRegistrar {
// AppRegistrar // AppRegistrar
void Init(base::OnceClosure callback) override; void Init(base::OnceClosure callback) override;
bool IsInstalled(const GURL& start_url) const override;
bool IsInstalled(const AppId& app_id) const override; bool IsInstalled(const AppId& app_id) const override;
bool WasExternalAppUninstalledByUser(const AppId& app_id) const override; bool WasExternalAppUninstalledByUser(const AppId& app_id) const override;
bool HasScopeUrl(const AppId& app_id) const override; bool HasScopeUrl(const AppId& app_id) const override;
......
...@@ -74,6 +74,11 @@ void WebAppRegistrar::OnDatabaseOpened(base::OnceClosure callback, ...@@ -74,6 +74,11 @@ void WebAppRegistrar::OnDatabaseOpened(base::OnceClosure callback,
std::move(callback).Run(); std::move(callback).Run();
} }
bool WebAppRegistrar::IsInstalled(const GURL& start_url) const {
NOTIMPLEMENTED();
return false;
}
bool WebAppRegistrar::IsInstalled(const AppId& app_id) const { bool WebAppRegistrar::IsInstalled(const AppId& app_id) const {
return GetAppById(app_id) != nullptr; return GetAppById(app_id) != nullptr;
} }
......
...@@ -37,6 +37,7 @@ class WebAppRegistrar : public AppRegistrar { ...@@ -37,6 +37,7 @@ class WebAppRegistrar : public AppRegistrar {
// AppRegistrar // AppRegistrar
void Init(base::OnceClosure callback) override; void Init(base::OnceClosure callback) override;
bool IsInstalled(const GURL& start_url) const override;
bool IsInstalled(const AppId& app_id) const override; bool IsInstalled(const AppId& app_id) const override;
bool WasExternalAppUninstalledByUser(const AppId& app_id) const override; bool WasExternalAppUninstalledByUser(const AppId& app_id) const override;
bool HasScopeUrl(const AppId& app_id) const override; bool HasScopeUrl(const AppId& app_id) const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment