Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1390)

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 2124513002: Introduce ManifestUpgradeDetector for WebAPK to detect web manifest changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce manifest upgrade detector. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..022248dea93b621a9552db0be5d782e1548d9d3f 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
@@ -41,6 +41,7 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
int minimum_icon_size_in_dp,
int ideal_splash_image_size_in_dp,
int minimum_splash_image_size_in_dp,
+ bool stop_fetch_when_no_manifest,
Observer* observer)
: WebContentsObserver(web_contents),
weak_observer_(observer),
@@ -52,7 +53,8 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
ideal_icon_size_in_dp_(ideal_icon_size_in_dp),
minimum_icon_size_in_dp_(minimum_icon_size_in_dp),
ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp),
- minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {
+ minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp),
+ stop_fetch_when_no_manifest_(stop_fetch_when_no_manifest) {
DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp);
DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp);
@@ -101,6 +103,19 @@ void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo(
break;
}
+ if (stop_fetch_when_no_manifest_) {
+ web_contents()->HasManifest(
+ base::Bind(&AddToHomescreenDataFetcher::OnDidHasManifest, this));
+ } else {
+ web_contents()->GetManifest(
+ base::Bind(&AddToHomescreenDataFetcher::OnDidGetManifest, this));
+ }
+}
+
+void AddToHomescreenDataFetcher::OnDidHasManifest(bool has_manifest) {
+ if (!has_manifest)
+ return;
+
web_contents()->GetManifest(
base::Bind(&AddToHomescreenDataFetcher::OnDidGetManifest, this));
}
@@ -110,11 +125,17 @@ void AddToHomescreenDataFetcher::OnDidGetManifest(
const content::Manifest& manifest) {
if (!web_contents() || !weak_observer_) return;
+ if (stop_fetch_when_no_manifest_ && manifest.IsEmpty()) return;
+
+ weak_observer_->OnDidHasManifest(true);
if (!manifest.IsEmpty()) {
content::RecordAction(
base::UserMetricsAction("webapps.AddShortcut.Manifest"));
shortcut_info_.UpdateFromManifest(manifest);
shortcut_info_.manifest_url = manifest_url;
+ icon_urls_.clear();
+ for (const auto& icon : manifest.icons)
+ icon_urls_.push_back(icon.src.spec());
}
GURL icon_src = ManifestIconSelector::FindBestMatchingIcon(
@@ -164,6 +185,11 @@ bool AddToHomescreenDataFetcher::OnMessageReceived(
return handled;
}
+void AddToHomescreenDataFetcher::ReplaceWebContents(
+ content::WebContents* web_contents) {
+ Observe(web_contents);
+}
+
AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
DCHECK(!weak_observer_);
}
@@ -263,7 +289,7 @@ void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& bitmap) {
is_icon_saved_ = true;
shortcut_icon_ = bitmap;
is_ready_ = true;
- weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_);
+ weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_, icon_urls_);
}
GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) {

Powered by Google App Engine
This is Rietveld 408576698