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

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

Issue 2669133003: Update AddToHomescreenDataFetcher to accept badge icon for WebAPK. (Closed)
Patch Set: Format Created 3 years, 10 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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 25 matching lines...) Expand all
36 namespace { 36 namespace {
37 37
38 // Looks up the original, online URL of the site requested. The URL from the 38 // Looks up the original, online URL of the site requested. The URL from the
39 // WebContents may be a distilled article which is not appropriate for a home 39 // WebContents may be a distilled article which is not appropriate for a home
40 // screen shortcut. 40 // screen shortcut.
41 GURL GetShortcutUrl(content::BrowserContext* browser_context, 41 GURL GetShortcutUrl(content::BrowserContext* browser_context,
42 const GURL& actual_url) { 42 const GURL& actual_url) {
43 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 43 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
44 } 44 }
45 45
46 InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_px, 46 InstallableParams ParamsToPerformInstallableCheck(
47 int minimum_icon_size_in_px, 47 int ideal_icon_size_in_px,
48 bool check_installable) { 48 int minimum_icon_size_in_px,
49 bool check_webapk_compatibility,
dominickn 2017/02/02 19:16:50 It's weird to me to see the bool in the middle of
F 2017/02/02 21:05:51 Done.
50 int ideal_badge_size_in_px,
51 int minimum_badge_size_in_px) {
49 InstallableParams params; 52 InstallableParams params;
50 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; 53 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px;
51 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px; 54 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px;
52 params.check_installable = check_installable; 55 params.check_installable = check_webapk_compatibility;
53 params.fetch_valid_primary_icon = true; 56 params.fetch_valid_primary_icon = true;
57 if (check_webapk_compatibility) {
58 params.ideal_badge_icon_size_in_px = ideal_badge_size_in_px;
59 params.minimum_badge_icon_size_in_px = minimum_badge_size_in_px;
60 params.fetch_valid_badge_icon = true;
61 }
54 return params; 62 return params;
55 } 63 }
56 64
57 } // namespace 65 } // namespace
58 66
59 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 67 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
60 content::WebContents* web_contents, 68 content::WebContents* web_contents,
61 int ideal_icon_size_in_px, 69 int ideal_icon_size_in_px,
62 int minimum_icon_size_in_px, 70 int minimum_icon_size_in_px,
63 int ideal_splash_image_size_in_px, 71 int ideal_splash_image_size_in_px,
64 int minimum_splash_image_size_in_px, 72 int minimum_splash_image_size_in_px,
73 int ideal_badge_size_in_px,
74 int minimum_badge_size_in_px,
65 bool check_webapk_compatibility, 75 bool check_webapk_compatibility,
66 Observer* observer) 76 Observer* observer)
67 : WebContentsObserver(web_contents), 77 : WebContentsObserver(web_contents),
68 weak_observer_(observer), 78 weak_observer_(observer),
69 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 79 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
70 web_contents->GetLastCommittedURL())), 80 web_contents->GetLastCommittedURL())),
71 data_timeout_timer_(false, false), 81 data_timeout_timer_(false, false),
72 ideal_icon_size_in_px_(ideal_icon_size_in_px), 82 ideal_icon_size_in_px_(ideal_icon_size_in_px),
73 minimum_icon_size_in_px_(minimum_icon_size_in_px), 83 minimum_icon_size_in_px_(minimum_icon_size_in_px),
74 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), 84 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
75 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), 85 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
86 ideal_badge_size_in_px_(ideal_badge_size_in_px),
87 minimum_badge_size_in_px_(minimum_badge_size_in_px),
76 check_webapk_compatibility_(check_webapk_compatibility), 88 check_webapk_compatibility_(check_webapk_compatibility),
77 is_waiting_for_web_application_info_(true), 89 is_waiting_for_web_application_info_(true),
78 is_installable_check_complete_(false), 90 is_installable_check_complete_(false),
79 is_icon_saved_(false), 91 is_icon_saved_(false),
80 is_ready_(false) { 92 is_ready_(false) {
81 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); 93 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px);
82 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); 94 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px);
95 DCHECK(minimum_badge_size_in_px <= ideal_badge_size_in_px);
83 96
84 // Send a message to the renderer to retrieve information about the page. 97 // Send a message to the renderer to retrieve information about the page.
85 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 98 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
86 } 99 }
87 100
88 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( 101 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback(
89 const std::string& webapp_id) { 102 const std::string& webapp_id) {
90 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), 103 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(),
91 splash_screen_url_, ideal_splash_image_size_in_px_, 104 splash_screen_url_, ideal_splash_image_size_in_px_,
92 minimum_splash_image_size_in_px_, webapp_id); 105 minimum_splash_image_size_in_px_, webapp_id);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 151
139 // Kick off a timeout for downloading data. If we haven't finished within the 152 // Kick off a timeout for downloading data. If we haven't finished within the
140 // timeout, fall back to using a dynamically-generated launcher icon. 153 // timeout, fall back to using a dynamically-generated launcher icon.
141 data_timeout_timer_.Start( 154 data_timeout_timer_.Start(
142 FROM_HERE, base::TimeDelta::FromMilliseconds(4000), 155 FROM_HERE, base::TimeDelta::FromMilliseconds(4000),
143 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); 156 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
144 157
145 manager->GetData( 158 manager->GetData(
146 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, 159 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_,
147 minimum_icon_size_in_px_, 160 minimum_icon_size_in_px_,
148 check_webapk_compatibility_), 161 check_webapk_compatibility_,
162 ideal_badge_size_in_px_,
163 minimum_badge_size_in_px_),
149 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, 164 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
150 this)); 165 this));
151 } 166 }
152 167
153 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { 168 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
154 DCHECK(!weak_observer_); 169 DCHECK(!weak_observer_);
155 } 170 }
156 171
157 bool AddToHomescreenDataFetcher::OnMessageReceived( 172 bool AddToHomescreenDataFetcher::OnMessageReceived(
158 const IPC::Message& message) { 173 const IPC::Message& message) {
(...skipping 15 matching lines...) Expand all
174 if (!web_contents() || !weak_observer_) 189 if (!web_contents() || !weak_observer_)
175 return; 190 return;
176 191
177 if (!is_installable_check_complete_) { 192 if (!is_installable_check_complete_) {
178 is_installable_check_complete_ = true; 193 is_installable_check_complete_ = true;
179 if (check_webapk_compatibility_) 194 if (check_webapk_compatibility_)
180 weak_observer_->OnDidDetermineWebApkCompatibility(false); 195 weak_observer_->OnDidDetermineWebApkCompatibility(false);
181 weak_observer_->OnUserTitleAvailable(base::string16()); 196 weak_observer_->OnUserTitleAvailable(base::string16());
182 } 197 }
183 198
184 if (!is_icon_saved_) 199 if (!is_icon_saved_) {
200 shortcut_badge_.reset();
185 CreateLauncherIcon(SkBitmap()); 201 CreateLauncherIcon(SkBitmap());
202 }
186 } 203 }
187 204
188 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( 205 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck(
189 const InstallableData& data) { 206 const InstallableData& data) {
207 shortcut_badge_.reset();
208
190 if (!web_contents() || !weak_observer_) 209 if (!web_contents() || !weak_observer_)
191 return; 210 return;
192 211
193 is_installable_check_complete_ = true; 212 is_installable_check_complete_ = true;
194 213
195 if (check_webapk_compatibility_) { 214 if (check_webapk_compatibility_) {
196 bool webapk_compatible = 215 bool webapk_compatible =
197 (data.error_code == NO_ERROR_DETECTED && 216 (data.error_code == NO_ERROR_DETECTED &&
198 AreWebManifestUrlsWebApkCompatible(data.manifest)); 217 AreWebManifestUrlsWebApkCompatible(data.manifest));
199 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); 218 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible);
200 219
201 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag 220 if (webapk_compatible) {
202 // data received in OnDidGetWebApplicationInfo(). 221 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag
203 if (webapk_compatible) 222 // data received in OnDidGetWebApplicationInfo().
204 shortcut_info_ = ShortcutInfo(GURL()); 223 shortcut_info_ = ShortcutInfo(GURL());
224
225 if (data.badge_icon && !data.badge_icon->drawsNothing()) {
226 shortcut_info_.best_badge_url = data.badge_icon_url;
227
228 data.badge_icon->deepCopyTo(&shortcut_badge_);
dominickn 2017/02/02 19:16:50 Why does this need to be a deep copy as opposed to
F 2017/02/02 21:05:51 My bad. I wasn't sure of the life span of SkBitmap
dominickn 2017/02/02 21:17:11 We use the copy constructor for the primary icon h
F 2017/02/02 22:30:42 Thanks for the info :)
229 }
230 }
205 } 231 }
206 232
207 if (!data.manifest.IsEmpty()) { 233 if (!data.manifest.IsEmpty()) {
208 content::RecordAction( 234 content::RecordAction(
209 base::UserMetricsAction("webapps.AddShortcut.Manifest")); 235 base::UserMetricsAction("webapps.AddShortcut.Manifest"));
210 shortcut_info_.UpdateFromManifest(data.manifest); 236 shortcut_info_.UpdateFromManifest(data.manifest);
211 shortcut_info_.manifest_url = data.manifest_url; 237 shortcut_info_.manifest_url = data.manifest_url;
212 } 238 }
213 239
214 // Save the splash screen URL for the later download. 240 // Save the splash screen URL for the later download.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 337 }
312 338
313 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { 339 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) {
314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
315 if (!web_contents() || !weak_observer_ || is_icon_saved_) 341 if (!web_contents() || !weak_observer_ || is_icon_saved_)
316 return; 342 return;
317 343
318 is_icon_saved_ = true; 344 is_icon_saved_ = true;
319 shortcut_icon_ = icon; 345 shortcut_icon_ = icon;
320 is_ready_ = true; 346 is_ready_ = true;
321 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); 347 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_,
348 shortcut_badge_);
322 } 349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698