Commit 87f9483f authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

WebApps: Ignore manifest updating for not-locally-installed web apps

Web apps that sync across devices are not considered locally installed for
non-Chrome OS devices. This CL ensures we don't accidentally install them
as part of manifest updating.

Bug: 926083
Change-Id: I34ba3610b04a3cf62e6c7bd362bed2fd770d7b55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831737
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Auto-Submit: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701440}
parent b89960f8
...@@ -36,6 +36,10 @@ class AppRegistryController { ...@@ -36,6 +36,10 @@ class AppRegistryController {
virtual void SetAppLaunchContainer(const AppId& app_id, virtual void SetAppLaunchContainer(const AppId& app_id,
LaunchContainer launch_container) = 0; LaunchContainer launch_container) = 0;
virtual void SetAppIsLocallyInstalledForTesting(
const AppId& app_id,
bool is_locally_installed) = 0;
// Safe downcast: // Safe downcast:
virtual WebAppSyncBridge* AsWebAppSyncBridge() = 0; virtual WebAppSyncBridge* AsWebAppSyncBridge() = 0;
......
...@@ -36,7 +36,7 @@ void ManifestUpdateManager::MaybeUpdate(const GURL& url, ...@@ -36,7 +36,7 @@ void ManifestUpdateManager::MaybeUpdate(const GURL& url,
if (!base::FeatureList::IsEnabled(features::kDesktopPWAsLocalUpdating)) if (!base::FeatureList::IsEnabled(features::kDesktopPWAsLocalUpdating))
return; return;
if (app_id.empty()) { if (app_id.empty() || !registrar_->IsLocallyInstalled(app_id)) {
NotifyResult(url, ManifestUpdateResult::kNoAppInScope); NotifyResult(url, ManifestUpdateResult::kNoAppInScope);
return; return;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/installable/installable_metrics.h" #include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/web_applications/components/app_registry_controller.h"
#include "chrome/browser/web_applications/components/install_finalizer.h" #include "chrome/browser/web_applications/components/install_finalizer.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_provider_base.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h"
...@@ -138,8 +139,6 @@ class ManifestUpdateManagerBrowserTest : public InProcessBrowserTest { ...@@ -138,8 +139,6 @@ class ManifestUpdateManagerBrowserTest : public InProcessBrowserTest {
GURL app_url = GetAppURL(); GURL app_url = GetAppURL();
ui_test_utils::NavigateToURL(browser(), app_url); ui_test_utils::NavigateToURL(browser(), app_url);
auto* provider = WebAppProviderBase::GetProviderBase(browser()->profile());
AppId app_id; AppId app_id;
base::RunLoop run_loop; base::RunLoop run_loop;
InstallManager::InstallParams params; InstallManager::InstallParams params;
...@@ -148,7 +147,7 @@ class ManifestUpdateManagerBrowserTest : public InProcessBrowserTest { ...@@ -148,7 +147,7 @@ class ManifestUpdateManagerBrowserTest : public InProcessBrowserTest {
params.add_to_quick_launch_bar = false; params.add_to_quick_launch_bar = false;
params.bypass_service_worker_check = true; params.bypass_service_worker_check = true;
params.require_manifest = false; params.require_manifest = false;
provider->install_manager().InstallWebAppWithParams( GetProvider().install_manager().InstallWebAppWithParams(
browser()->tab_strip_model()->GetActiveWebContents(), params, browser()->tab_strip_model()->GetActiveWebContents(), params,
WebappInstallSource::OMNIBOX_INSTALL_ICON, WebappInstallSource::OMNIBOX_INSTALL_ICON,
base::BindLambdaForTesting( base::BindLambdaForTesting(
...@@ -173,6 +172,10 @@ class ManifestUpdateManagerBrowserTest : public InProcessBrowserTest { ...@@ -173,6 +172,10 @@ class ManifestUpdateManagerBrowserTest : public InProcessBrowserTest {
return std::move(awaiter).AwaitNextResult(); return std::move(awaiter).AwaitNextResult();
} }
WebAppProviderBase& GetProvider() {
return *WebAppProviderBase::GetProviderBase(browser()->profile());
}
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -245,9 +248,7 @@ IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest, ...@@ -245,9 +248,7 @@ IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest,
GURL url = GetAppURL(); GURL url = GetAppURL();
UpdateCheckResultAwaiter awaiter(browser(), url); UpdateCheckResultAwaiter awaiter(browser(), url);
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
WebAppProviderBase::GetProviderBase(browser()->profile()) GetProvider().install_finalizer().UninstallWebApp(app_id, base::DoNothing());
->install_finalizer()
.UninstallWebApp(app_id, base::DoNothing());
EXPECT_EQ(std::move(awaiter).AwaitNextResult(), EXPECT_EQ(std::move(awaiter).AwaitNextResult(),
ManifestUpdateResult::kAppUninstalled); ManifestUpdateResult::kAppUninstalled);
} }
...@@ -370,6 +371,30 @@ IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest, ...@@ -370,6 +371,30 @@ IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest,
ManifestUpdateResult::kAppDataInvalid); ManifestUpdateResult::kAppDataInvalid);
} }
IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest,
CheckIgnoresNonLocalApps) {
const char* manifest_template = R"(
{
"name": "Test app name",
"start_url": ".",
"scope": "/",
"display": "standalone",
"icons": $1,
"theme_color": "$2"
}
)";
OverrideManifest(manifest_template, {kInstallableIconList, "blue"});
AppId app_id = InstallWebApp();
GetProvider().registry_controller().SetAppIsLocallyInstalledForTesting(app_id,
false);
EXPECT_FALSE(GetProvider().registrar().IsLocallyInstalled(app_id));
OverrideManifest(manifest_template, {kInstallableIconList, "red"});
EXPECT_EQ(GetResultAfterPageLoad(GetAppURL(), &app_id),
ManifestUpdateResult::kNoAppInScope);
}
IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest, IN_PROC_BROWSER_TEST_F(ManifestUpdateManagerBrowserTest,
CheckFindsThemeColorChange) { CheckFindsThemeColorChange) {
const char* manifest_template = R"( const char* manifest_template = R"(
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/one_shot_event.h" #include "base/one_shot_event.h"
#include "chrome/browser/extensions/launch_util.h" #include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.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"
...@@ -55,6 +56,13 @@ void BookmarkAppRegistryController::SetAppLaunchContainer( ...@@ -55,6 +56,13 @@ void BookmarkAppRegistryController::SetAppLaunchContainer(
} }
} }
void BookmarkAppRegistryController::SetAppIsLocallyInstalledForTesting(
const web_app::AppId& app_id,
bool is_locally_installed) {
SetBookmarkAppIsLocallyInstalled(profile(), GetExtension(app_id),
is_locally_installed);
}
web_app::WebAppSyncBridge* BookmarkAppRegistryController::AsWebAppSyncBridge() { web_app::WebAppSyncBridge* BookmarkAppRegistryController::AsWebAppSyncBridge() {
return nullptr; return nullptr;
} }
......
...@@ -23,6 +23,8 @@ class BookmarkAppRegistryController : public web_app::AppRegistryController { ...@@ -23,6 +23,8 @@ class BookmarkAppRegistryController : public web_app::AppRegistryController {
void SetAppLaunchContainer( void SetAppLaunchContainer(
const web_app::AppId& app_id, const web_app::AppId& app_id,
web_app::LaunchContainer launch_container) override; web_app::LaunchContainer launch_container) override;
void SetAppIsLocallyInstalledForTesting(const web_app::AppId& app_id,
bool is_locally_installed) override;
web_app::WebAppSyncBridge* AsWebAppSyncBridge() override; web_app::WebAppSyncBridge* AsWebAppSyncBridge() override;
private: private:
......
...@@ -132,6 +132,15 @@ void WebAppSyncBridge::SetAppLaunchContainer(const AppId& app_id, ...@@ -132,6 +132,15 @@ void WebAppSyncBridge::SetAppLaunchContainer(const AppId& app_id,
web_app->SetLaunchContainer(launch_container); web_app->SetLaunchContainer(launch_container);
} }
void WebAppSyncBridge::SetAppIsLocallyInstalledForTesting(
const AppId& app_id,
bool is_locally_installed) {
ScopedRegistryUpdate update(this);
WebApp* web_app = update->UpdateApp(app_id);
if (web_app)
web_app->SetIsLocallyInstalled(is_locally_installed);
}
WebAppSyncBridge* WebAppSyncBridge::AsWebAppSyncBridge() { WebAppSyncBridge* WebAppSyncBridge::AsWebAppSyncBridge() {
return this; return this;
} }
......
...@@ -58,6 +58,8 @@ class WebAppSyncBridge : public AppRegistryController, ...@@ -58,6 +58,8 @@ class WebAppSyncBridge : public AppRegistryController,
void Init(base::OnceClosure callback) override; void Init(base::OnceClosure callback) override;
void SetAppLaunchContainer(const AppId& app_id, void SetAppLaunchContainer(const AppId& app_id,
LaunchContainer launch_container) override; LaunchContainer launch_container) override;
void SetAppIsLocallyInstalledForTesting(const AppId& app_id,
bool is_locally_installed) override;
WebAppSyncBridge* AsWebAppSyncBridge() override; WebAppSyncBridge* AsWebAppSyncBridge() override;
private: private:
......
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