Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
index 0ffe0adf17e0b10b6f999a73923cb72753a5f130..fac3877a5f27f562d52451c4c4c24de4cec1f19f 100644 |
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
@@ -6,21 +6,27 @@ |
#include "base/bind.h" |
#include "base/callback.h" |
+#include "base/command_line.h" |
#include "base/location.h" |
#include "base/strings/string16.h" |
#include "base/task/cancelable_task_tracker.h" |
#include "chrome/browser/android/offline_pages/offline_page_utils.h" |
#include "chrome/browser/android/shortcut_helper.h" |
+#include "chrome/browser/banners/app_banner_debug_log.h" |
+#include "chrome/browser/banners/webapp_manifest_validator.h" |
#include "chrome/browser/favicon/favicon_service_factory.h" |
#include "chrome/browser/manifest/manifest_icon_downloader.h" |
#include "chrome/browser/manifest/manifest_icon_selector.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/chrome_constants.h" |
+#include "chrome/common/chrome_switches.h" |
#include "chrome/common/render_messages.h" |
#include "chrome/common/web_application_info.h" |
#include "components/dom_distiller/core/url_utils.h" |
#include "components/favicon/core/favicon_service.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/service_worker_context.h" |
+#include "content/public/browser/storage_partition.h" |
#include "content/public/browser/user_metrics.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_observer.h" |
@@ -55,6 +61,7 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) { |
DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); |
DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); |
+ shortcut_url_ = shortcut_info_.url; |
// Send a message to the renderer to retrieve information about the page. |
is_waiting_for_web_application_info_ = true; |
@@ -117,6 +124,43 @@ void AddToHomescreenDataFetcher::OnDidGetManifest( |
shortcut_info_.manifest_url = manifest_url; |
} |
+ if (!IsManifestWebApkCapable(manifest)) { |
+ banners::OutputDeveloperMessageCode code = |
+ banners::OutputDeveloperMessageCode::kNone; |
+ if (banners::webapp_manifest_validator::IsWebappCapable(manifest, &code)) { |
+ shortcut_info_.type = ShortcutInfo::Type::WEBAPP; |
+ } |
+ OnCheckIsWebApk(manifest, false); |
+ return; |
+ } |
+ |
+ // Check to see if there is a single service worker controlling this page |
+ // and the manifest's start url. |
+ Profile* profile = |
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
+ content::StoragePartition* storage_partition = |
+ content::BrowserContext::GetStoragePartition( |
+ profile, web_contents()->GetSiteInstance()); |
+ DCHECK(storage_partition); |
+ storage_partition->GetServiceWorkerContext()->CheckHasServiceWorker( |
+ shortcut_url_, manifest.start_url, |
+ base::Bind(&AddToHomescreenDataFetcher::OnDidCheckServiceWorkerForWebApk, |
+ this, manifest)); |
+} |
+ |
+void AddToHomescreenDataFetcher::OnDidCheckServiceWorkerForWebApk( |
+ const content::Manifest& manifest, |
+ bool has_service_worker) { |
+ if (!web_contents() || !weak_observer_) return; |
+ OnCheckIsWebApk(manifest, has_service_worker); |
+} |
+ |
+void AddToHomescreenDataFetcher::OnCheckIsWebApk( |
+ const content::Manifest& manifest, |
+ bool is_webapk) { |
+ if (is_webapk) |
+ shortcut_info_.type = ShortcutInfo::Type::WEBAPK; |
+ |
GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( |
manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); |
@@ -279,3 +323,13 @@ GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) { |
return original_url; |
} |
+ |
+bool AddToHomescreenDataFetcher::IsManifestWebApkCapable( |
+ const content::Manifest& manifest) const { |
+ banners::OutputDeveloperMessageCode code = |
+ banners::OutputDeveloperMessageCode::kNone; |
+ return banners::webapp_manifest_validator::IsManifestGoodForWebapp(manifest, |
+ &code) && |
+ base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableWebApk); |
+} |