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

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 2064943002: Pass in extra parameters to WebApkBuilder#buildWebApkAsync() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_manifest000 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 content::RecordAction( 99 content::RecordAction(
100 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); 100 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
101 break; 101 break;
102 } 102 }
103 103
104 web_contents()->GetManifest( 104 web_contents()->GetManifest(
105 base::Bind(&AddToHomescreenDataFetcher::OnDidGetManifest, this)); 105 base::Bind(&AddToHomescreenDataFetcher::OnDidGetManifest, this));
106 } 106 }
107 107
108 void AddToHomescreenDataFetcher::OnDidGetManifest( 108 void AddToHomescreenDataFetcher::OnDidGetManifest(
109 const GURL& manifest_url,
109 const content::Manifest& manifest) { 110 const content::Manifest& manifest) {
110 if (!web_contents() || !weak_observer_) return; 111 if (!web_contents() || !weak_observer_) return;
111 112
112 if (!manifest.IsEmpty()) { 113 if (!manifest.IsEmpty()) {
113 content::RecordAction( 114 content::RecordAction(
114 base::UserMetricsAction("webapps.AddShortcut.Manifest")); 115 base::UserMetricsAction("webapps.AddShortcut.Manifest"));
115 shortcut_info_.UpdateFromManifest(manifest); 116 shortcut_info_.UpdateFromManifest(manifest);
117 shortcut_info_.manifest_url = manifest_url;
116 } 118 }
117 119
118 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( 120 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon(
119 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); 121 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_);
120 122
121 // If fetching the Manifest icon fails, fallback to the best favicon 123 // If fetching the Manifest icon fails, fallback to the best favicon
122 // for the page. 124 // for the page.
123 if (!ManifestIconDownloader::Download( 125 if (!ManifestIconDownloader::Download(
124 web_contents(), 126 web_contents(),
125 icon_src, 127 icon_src,
126 ideal_icon_size_in_dp_, 128 ideal_icon_size_in_dp_,
127 minimum_icon_size_in_dp_, 129 minimum_icon_size_in_dp_,
128 base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched, 130 base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched,
129 this))) { 131 this, icon_src))) {
130 FetchFavicon(); 132 FetchFavicon();
131 } 133 }
132 134
133 // Save the splash screen URL for the later download. 135 // Save the splash screen URL for the later download.
134 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( 136 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon(
135 manifest.icons, ideal_splash_image_size_in_dp_, 137 manifest.icons, ideal_splash_image_size_in_dp_,
136 minimum_splash_image_size_in_dp_); 138 minimum_splash_image_size_in_dp_);
137 139
138 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); 140 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title);
139 141
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 &icon_bitmap); 231 &icon_bitmap);
230 } 232 }
231 233
232 bool is_generated = false; 234 bool is_generated = false;
233 if (weak_observer_) { 235 if (weak_observer_) {
234 icon_bitmap = weak_observer_->FinalizeLauncherIcon(icon_bitmap, 236 icon_bitmap = weak_observer_->FinalizeLauncherIcon(icon_bitmap,
235 shortcut_info_.url, 237 shortcut_info_.url,
236 &is_generated); 238 &is_generated);
237 } 239 }
238 240
241 shortcut_info_.icon_url = is_generated ? GURL() : bitmap_result.icon_url;
239 content::BrowserThread::PostTask( 242 content::BrowserThread::PostTask(
240 content::BrowserThread::UI, 243 content::BrowserThread::UI, FROM_HERE,
241 FROM_HERE, 244 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this,
242 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, 245 icon_bitmap));
243 this,
244 icon_bitmap,
245 is_generated));
246 } 246 }
247 247
248 void AddToHomescreenDataFetcher::OnManifestIconFetched(const SkBitmap& icon) { 248 void AddToHomescreenDataFetcher::OnManifestIconFetched(const GURL& icon_url,
249 const SkBitmap& icon) {
249 if (icon.drawsNothing()) { 250 if (icon.drawsNothing()) {
250 FetchFavicon(); 251 FetchFavicon();
251 return; 252 return;
252 } 253 }
253 NotifyObserver(icon, false); 254 shortcut_info_.icon_url = icon_url;
255 NotifyObserver(icon);
254 } 256 }
255 257
256 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& bitmap, 258 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& bitmap) {
257 bool is_generated) {
258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
259 if (!web_contents() || !weak_observer_ || is_icon_saved_) 260 if (!web_contents() || !weak_observer_ || is_icon_saved_)
260 return; 261 return;
261 262
262 is_icon_saved_ = true; 263 is_icon_saved_ = true;
263 shortcut_icon_ = bitmap; 264 shortcut_icon_ = bitmap;
264 shortcut_info_.is_icon_generated = is_generated;
265 is_ready_ = true; 265 is_ready_ = true;
266 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); 266 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_);
267 } 267 }
268 268
269 GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) { 269 GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) {
270 GURL original_url = 270 GURL original_url =
271 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 271 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
272 272
273 // If URL points to an offline content, get original URL. 273 // If URL points to an offline content, get original URL.
274 GURL online_url = 274 GURL online_url =
275 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 275 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
276 web_contents()->GetBrowserContext(), original_url); 276 web_contents()->GetBrowserContext(), original_url);
277 if (online_url.is_valid()) 277 if (online_url.is_valid())
278 return online_url; 278 return online_url;
279 279
280 return original_url; 280 return original_url;
281 } 281 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | chrome/browser/banners/app_banner_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698