Add service worker registration options for default web app config
This CL adds two fields to the default web app config JSON:
- load_and_await_service_worker_registration: bool
- service_worker_install_url: URL string
These allow default apps to control their service worker registration
behaviour during the install flow.
Bug: 1123435
Change-Id: Id389c347066a8dbcaa2c2350b884cdb5872e5721
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409057
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Reviewed-by: Glen Robertson <glenrob@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807358}
diff --git a/chrome/browser/web_applications/components/external_install_options.cc b/chrome/browser/web_applications/components/external_install_options.cc
index 6777c57..3adde60 100644
--- a/chrome/browser/web_applications/components/external_install_options.cc
+++ b/chrome/browser/web_applications/components/external_install_options.cc
@@ -40,7 +40,9 @@
is_disabled, override_previous_user_uninstall,
bypass_service_worker_check, require_manifest,
force_reinstall, wait_for_windows_closed, install_placeholder,
- reinstall_placeholder, uninstall_and_replace,
+ reinstall_placeholder,
+ load_and_await_service_worker_registration,
+ service_worker_registration_url, uninstall_and_replace,
additional_search_terms) ==
std::tie(other.install_url, other.user_display_mode,
other.install_source, other.add_to_applications_menu,
@@ -50,6 +52,8 @@
other.bypass_service_worker_check, other.require_manifest,
other.force_reinstall, other.wait_for_windows_closed,
other.install_placeholder, other.reinstall_placeholder,
+ other.load_and_await_service_worker_registration,
+ other.service_worker_registration_url,
other.uninstall_and_replace, other.additional_search_terms);
}
@@ -80,6 +84,10 @@
<< install_options.install_placeholder
<< "\n reinstall_placeholder: "
<< install_options.reinstall_placeholder
+ << "\n load_and_await_service_worker_registration: "
+ << install_options.load_and_await_service_worker_registration
+ << "\n service_worker_registration_url: "
+ << install_options.service_worker_registration_url.value_or(GURL())
<< "\n uninstall_and_replace:\n "
<< base::JoinString(install_options.uninstall_and_replace, "\n ")
<< "\n additional_search_terms:\n "
diff --git a/chrome/browser/web_applications/components/external_install_options.h b/chrome/browser/web_applications/components/external_install_options.h
index 97172ac..b8ddf2ee 100644
--- a/chrome/browser/web_applications/components/external_install_options.h
+++ b/chrome/browser/web_applications/components/external_install_options.h
@@ -103,6 +103,17 @@
// it.
bool reinstall_placeholder = false;
+ // Whether we should load |service_worker_registration_url| after successful
+ // installation to allow the site to install its service worker and set up
+ // offline caching.
+ bool load_and_await_service_worker_registration = true;
+
+ // The URL to use for service worker registration. This is
+ // configurable by sites that wish to be able to track install metrics of the
+ // install_url separate from the service worker registration step. Defaults to
+ // install_url if unset.
+ base::Optional<GURL> service_worker_registration_url;
+
// A list of app_ids that the Web App System should attempt to uninstall and
// replace with this app (e.g maintain shelf pins, app list positions).
std::vector<AppId> uninstall_and_replace;
diff --git a/chrome/browser/web_applications/components/pending_app_manager.cc b/chrome/browser/web_applications/components/pending_app_manager.cc
index 4434e50..d90b2a0 100644
--- a/chrome/browser/web_applications/components/pending_app_manager.cc
+++ b/chrome/browser/web_applications/components/pending_app_manager.cc
@@ -113,6 +113,11 @@
registration_callback_ = RegistrationCallback();
}
+void PendingAppManager::SetRegistrationsCompleteCallbackForTesting(
+ base::OnceClosure callback) {
+ registrations_complete_callback_ = std::move(callback);
+}
+
void PendingAppManager::OnRegistrationFinished(const GURL& install_url,
RegistrationResultCode result) {
if (registration_callback_)
diff --git a/chrome/browser/web_applications/components/pending_app_manager.h b/chrome/browser/web_applications/components/pending_app_manager.h
index d8e724dc..accdc57 100644
--- a/chrome/browser/web_applications/components/pending_app_manager.h
+++ b/chrome/browser/web_applications/components/pending_app_manager.h
@@ -112,6 +112,7 @@
void SetRegistrationCallbackForTesting(RegistrationCallback callback);
void ClearRegistrationCallbackForTesting();
+ void SetRegistrationsCompleteCallbackForTesting(base::OnceClosure callback);
void ClearSynchronizeRequestsForTesting();
virtual void Shutdown() = 0;
@@ -128,6 +129,8 @@
virtual void OnRegistrationFinished(const GURL& launch_url,
RegistrationResultCode result);
+ base::OnceClosure registrations_complete_callback_;
+
private:
struct SynchronizeRequest {
SynchronizeRequest(SynchronizeCallback callback, int remaining_requests);