OLD | NEW |
---|---|
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/location.h" | 10 #include "base/location.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/manifest.h" | 27 #include "content/public/common/manifest.h" |
28 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" | 28 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" |
29 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
30 #include "ui/gfx/favicon_size.h" | 30 #include "ui/gfx/favicon_size.h" |
31 #include "url/gurl.h" | 31 #include "url/gurl.h" |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // The default number of milliseconds to wait for the data download to complete. | |
36 const int kDataTimeoutInMilliseconds = 4000; | |
37 | |
38 // Looks up the original, online URL of the site requested. The URL from the | 35 // 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 | 36 // WebContents may be a distilled article which is not appropriate for a home |
40 // screen shortcut. | 37 // screen shortcut. |
41 GURL GetShortcutUrl(content::BrowserContext* browser_context, | 38 GURL GetShortcutUrl(content::BrowserContext* browser_context, |
42 const GURL& actual_url) { | 39 const GURL& actual_url) { |
43 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); | 40 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); |
44 } | 41 } |
45 | 42 |
46 InstallableParams ParamsToPerformInstallableCheck( | 43 InstallableParams ParamsToPerformManifestAndIconFetch( |
47 int ideal_icon_size_in_px, | 44 int ideal_icon_size_in_px, |
48 int minimum_icon_size_in_px, | 45 int minimum_icon_size_in_px, |
49 int badge_size_in_px, | 46 int badge_size_in_px, |
50 bool check_webapk_compatibility) { | 47 bool check_webapk_compatibility) { |
51 InstallableParams params; | 48 InstallableParams params; |
52 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; | 49 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; |
53 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px; | 50 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px; |
54 params.check_installable = check_webapk_compatibility; | |
55 params.fetch_valid_primary_icon = true; | 51 params.fetch_valid_primary_icon = true; |
56 if (check_webapk_compatibility) { | 52 if (check_webapk_compatibility) { |
53 params.fetch_valid_badge_icon = true; | |
57 params.ideal_badge_icon_size_in_px = badge_size_in_px; | 54 params.ideal_badge_icon_size_in_px = badge_size_in_px; |
58 params.minimum_badge_icon_size_in_px = badge_size_in_px; | 55 params.minimum_badge_icon_size_in_px = badge_size_in_px; |
59 params.fetch_valid_badge_icon = true; | |
60 } | 56 } |
61 return params; | 57 return params; |
62 } | 58 } |
63 | 59 |
60 InstallableParams ParamsToPerformInstallableCheck( | |
61 bool check_webapk_compatibility) { | |
62 InstallableParams params; | |
63 params.check_installable = check_webapk_compatibility; | |
64 return params; | |
65 } | |
66 | |
64 } // namespace | 67 } // namespace |
65 | 68 |
66 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( | 69 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
67 content::WebContents* web_contents, | 70 content::WebContents* web_contents, |
68 int ideal_icon_size_in_px, | 71 int ideal_icon_size_in_px, |
69 int minimum_icon_size_in_px, | 72 int minimum_icon_size_in_px, |
70 int ideal_splash_image_size_in_px, | 73 int ideal_splash_image_size_in_px, |
71 int minimum_splash_image_size_in_px, | 74 int minimum_splash_image_size_in_px, |
72 int badge_size_in_px, | 75 int badge_size_in_px, |
76 int data_timeout_ms, | |
73 bool check_webapk_compatibility, | 77 bool check_webapk_compatibility, |
74 Observer* observer) | 78 Observer* observer) |
75 : content::WebContentsObserver(web_contents), | 79 : content::WebContentsObserver(web_contents), |
80 installable_manager_(InstallableManager::FromWebContents(web_contents)), | |
76 weak_observer_(observer), | 81 weak_observer_(observer), |
77 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), | 82 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), |
78 web_contents->GetLastCommittedURL())), | 83 web_contents->GetLastCommittedURL())), |
79 ideal_icon_size_in_px_(ideal_icon_size_in_px), | 84 ideal_icon_size_in_px_(ideal_icon_size_in_px), |
80 minimum_icon_size_in_px_(minimum_icon_size_in_px), | 85 minimum_icon_size_in_px_(minimum_icon_size_in_px), |
81 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), | 86 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), |
82 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), | 87 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), |
83 badge_size_in_px_(badge_size_in_px), | 88 badge_size_in_px_(badge_size_in_px), |
89 data_timeout_ms_(data_timeout_ms), | |
84 check_webapk_compatibility_(check_webapk_compatibility), | 90 check_webapk_compatibility_(check_webapk_compatibility), |
85 is_waiting_for_web_application_info_(true), | 91 is_waiting_for_web_application_info_(true), |
86 is_installable_check_complete_(false), | 92 is_installable_check_complete_(false), |
87 is_icon_saved_(false) { | 93 is_icon_saved_(false) { |
88 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); | 94 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); |
89 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); | 95 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); |
90 | 96 |
91 // 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. |
92 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 98 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
93 main_frame->Send( | 99 main_frame->Send( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: | 134 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: |
129 base::RecordAction( | 135 base::RecordAction( |
130 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); | 136 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); |
131 break; | 137 break; |
132 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED: | 138 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED: |
133 base::RecordAction( | 139 base::RecordAction( |
134 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); | 140 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); |
135 break; | 141 break; |
136 } | 142 } |
137 | 143 |
138 InstallableManager::CreateForWebContents(web_contents()); | |
139 InstallableManager* manager = | |
140 InstallableManager::FromWebContents(web_contents()); | |
141 DCHECK(manager); | |
142 | |
143 // Kick off a timeout for downloading data. If we haven't finished within the | 144 // Kick off a timeout for downloading data. If we haven't finished within the |
144 // timeout, fall back to using a dynamically-generated launcher icon. | 145 // timeout, fall back to using a dynamically-generated launcher icon. |
145 data_timeout_timer_.Start( | 146 data_timeout_timer_.Start( |
146 FROM_HERE, base::TimeDelta::FromMilliseconds(kDataTimeoutInMilliseconds), | 147 FROM_HERE, base::TimeDelta::FromMilliseconds(data_timeout_ms_), |
147 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); | 148 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); |
148 | 149 |
149 manager->GetData( | 150 installable_manager_->GetData( |
150 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, | 151 ParamsToPerformManifestAndIconFetch( |
151 minimum_icon_size_in_px_, | 152 ideal_icon_size_in_px_, minimum_icon_size_in_px_, badge_size_in_px_, |
152 badge_size_in_px_, | 153 check_webapk_compatibility_), |
153 check_webapk_compatibility_), | 154 base::Bind(&AddToHomescreenDataFetcher::OnDidGetManifestAndIcons, this)); |
154 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, | |
155 this)); | |
156 } | 155 } |
157 | 156 |
158 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { | 157 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { |
159 DCHECK(!weak_observer_); | 158 DCHECK(!weak_observer_); |
160 } | 159 } |
161 | 160 |
162 bool AddToHomescreenDataFetcher::OnMessageReceived( | 161 bool AddToHomescreenDataFetcher::OnMessageReceived( |
163 const IPC::Message& message, | 162 const IPC::Message& message, |
164 content::RenderFrameHost* sender) { | 163 content::RenderFrameHost* sender) { |
165 if (!is_waiting_for_web_application_info_) | 164 if (!is_waiting_for_web_application_info_) |
166 return false; | 165 return false; |
167 | 166 |
168 bool handled = true; | 167 bool handled = true; |
169 | 168 |
170 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) | 169 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) |
171 IPC_MESSAGE_HANDLER(ChromeFrameHostMsg_DidGetWebApplicationInfo, | 170 IPC_MESSAGE_HANDLER(ChromeFrameHostMsg_DidGetWebApplicationInfo, |
172 OnDidGetWebApplicationInfo) | 171 OnDidGetWebApplicationInfo) |
173 IPC_MESSAGE_UNHANDLED(handled = false) | 172 IPC_MESSAGE_UNHANDLED(handled = false) |
174 IPC_END_MESSAGE_MAP() | 173 IPC_END_MESSAGE_MAP() |
175 | 174 |
176 return handled; | 175 return handled; |
177 } | 176 } |
178 | 177 |
179 void AddToHomescreenDataFetcher::OnDataTimedout() { | 178 void AddToHomescreenDataFetcher::OnDataTimedout() { |
180 if (!web_contents() || !weak_observer_) | 179 if (!web_contents() || !weak_observer_) |
181 return; | 180 return; |
182 | 181 |
183 if (!is_installable_check_complete_) { | 182 if (!is_installable_check_complete_) { |
184 is_installable_check_complete_ = true; | 183 is_installable_check_complete_ = true; |
184 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | |
185 if (check_webapk_compatibility_) | 185 if (check_webapk_compatibility_) |
186 weak_observer_->OnDidDetermineWebApkCompatibility(false); | 186 weak_observer_->OnDidDetermineWebApkCompatibility(false); |
187 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | |
188 } | 187 } |
189 | 188 |
190 badge_icon_.reset(); | 189 badge_icon_.reset(); |
pkotwicz
2017/06/27 01:09:32
We should probably delete line 189
dominickn
2017/06/27 01:37:24
Well, we're always non-WebAPK compatible in here,
pkotwicz
2017/06/27 15:48:19
It doesn't do any harm, but clearing the badge her
dominickn
2017/06/28 01:38:05
Done.
| |
191 CreateLauncherIcon(SkBitmap()); | 190 CreateLauncherIcon(raw_primary_icon_); |
192 } | 191 } |
193 | 192 |
194 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( | 193 void AddToHomescreenDataFetcher::OnDidGetManifestAndIcons( |
195 const InstallableData& data) { | 194 const InstallableData& data) { |
196 data_timeout_timer_.Stop(); | |
197 badge_icon_.reset(); | |
198 | |
199 if (!web_contents() || !weak_observer_ || is_installable_check_complete_) | 195 if (!web_contents() || !weak_observer_ || is_installable_check_complete_) |
200 return; | 196 return; |
201 | 197 |
202 is_installable_check_complete_ = true; | |
203 | |
204 bool webapk_compatible = false; | |
205 if (check_webapk_compatibility_) { | |
206 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && | |
207 AreWebManifestUrlsWebApkCompatible(data.manifest)); | |
208 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); | |
209 | |
210 if (webapk_compatible) { | |
211 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag | |
212 // data received in OnDidGetWebApplicationInfo(). | |
213 shortcut_info_ = ShortcutInfo(GURL()); | |
214 } | |
215 } | |
216 | |
217 if (!data.manifest.IsEmpty()) { | 198 if (!data.manifest.IsEmpty()) { |
218 base::RecordAction(base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 199 base::RecordAction(base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
219 shortcut_info_.UpdateFromManifest(data.manifest); | 200 shortcut_info_.UpdateFromManifest(data.manifest); |
220 shortcut_info_.manifest_url = data.manifest_url; | 201 shortcut_info_.manifest_url = data.manifest_url; |
202 } | |
221 | 203 |
222 if (webapk_compatible) { | 204 // Do this after updating from the manifest for the case where a site has |
223 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA); | 205 // a manifest with name and standalone specified, but no icons. |
206 if (data.manifest.IsEmpty() || !data.primary_icon) { | |
pkotwicz
2017/06/27 01:09:32
Nit: It would be clearer if you stopped the timer
dominickn
2017/06/27 01:37:24
Done.
| |
207 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | |
208 if (check_webapk_compatibility_) | |
209 weak_observer_->OnDidDetermineWebApkCompatibility(false); | |
210 FetchFavicon(); | |
211 return; | |
212 } | |
224 | 213 |
225 if (data.badge_icon && !data.badge_icon->drawsNothing()) { | 214 raw_primary_icon_ = *data.primary_icon; |
226 shortcut_info_.best_badge_icon_url = data.badge_icon_url; | 215 shortcut_info_.best_primary_icon_url = data.primary_icon_url; |
227 badge_icon_ = *data.badge_icon; | |
228 } | |
229 } | |
230 } | |
231 | 216 |
232 // Save the splash screen URL for the later download. | 217 // Save the splash screen URL for the later download. |
233 shortcut_info_.splash_image_url = | 218 shortcut_info_.splash_image_url = |
234 content::ManifestIconSelector::FindBestMatchingIcon( | 219 content::ManifestIconSelector::FindBestMatchingIcon( |
235 data.manifest.icons, ideal_splash_image_size_in_px_, | 220 data.manifest.icons, ideal_splash_image_size_in_px_, |
236 minimum_splash_image_size_in_px_, | 221 minimum_splash_image_size_in_px_, |
237 content::Manifest::Icon::IconPurpose::ANY); | 222 content::Manifest::Icon::IconPurpose::ANY); |
238 shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_; | 223 shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_; |
239 shortcut_info_.minimum_splash_image_size_in_px = | 224 shortcut_info_.minimum_splash_image_size_in_px = |
240 minimum_splash_image_size_in_px_; | 225 minimum_splash_image_size_in_px_; |
226 if (data.badge_icon) { | |
227 shortcut_info_.best_badge_icon_url = data.badge_icon_url; | |
228 badge_icon_ = *data.badge_icon; | |
229 } | |
230 | |
231 installable_manager_->GetData( | |
232 ParamsToPerformInstallableCheck(check_webapk_compatibility_), | |
233 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, | |
234 this)); | |
235 } | |
236 | |
237 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( | |
238 const InstallableData& data) { | |
239 data_timeout_timer_.Stop(); | |
240 | |
241 if (!web_contents() || !weak_observer_ || is_installable_check_complete_) | |
242 return; | |
241 | 243 |
242 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 244 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
245 is_installable_check_complete_ = true; | |
243 | 246 |
244 if (data.primary_icon) { | 247 bool webapk_compatible = false; |
245 shortcut_info_.best_primary_icon_url = data.primary_icon_url; | 248 if (check_webapk_compatibility_) { |
246 | 249 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && |
247 if (webapk_compatible) | 250 AreWebManifestUrlsWebApkCompatible(data.manifest)); |
248 NotifyObserver(*data.primary_icon); | 251 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
249 else | |
250 CreateLauncherIcon(*(data.primary_icon)); | |
251 return; | |
252 } | 252 } |
253 | 253 |
254 FetchFavicon(); | 254 if (webapk_compatible) { |
255 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA); | |
256 NotifyObserver(raw_primary_icon_); | |
257 } else { | |
258 CreateLauncherIcon(raw_primary_icon_); | |
259 } | |
255 } | 260 } |
256 | 261 |
257 void AddToHomescreenDataFetcher::FetchFavicon() { | 262 void AddToHomescreenDataFetcher::FetchFavicon() { |
258 if (!web_contents() || !weak_observer_) | 263 if (!web_contents() || !weak_observer_) |
259 return; | 264 return; |
260 | 265 |
261 // Grab the best, largest icon we can find to represent this bookmark. | 266 // Grab the best, largest icon we can find to represent this bookmark. |
262 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its | 267 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its |
263 // rewrite is further along. | 268 // rewrite is further along. |
264 std::vector<int> icon_types{ | 269 std::vector<int> icon_types{ |
(...skipping 10 matching lines...) Expand all Loading... | |
275 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px_ - 1; | 280 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px_ - 1; |
276 favicon_service->GetLargestRawFaviconForPageURL( | 281 favicon_service->GetLargestRawFaviconForPageURL( |
277 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon, | 282 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon, |
278 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), | 283 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), |
279 &favicon_task_tracker_); | 284 &favicon_task_tracker_); |
280 } | 285 } |
281 | 286 |
282 void AddToHomescreenDataFetcher::OnFaviconFetched( | 287 void AddToHomescreenDataFetcher::OnFaviconFetched( |
283 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 288 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
284 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 289 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
290 data_timeout_timer_.Stop(); | |
285 | 291 |
286 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 292 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
287 return; | 293 return; |
288 | 294 |
289 // The user is waiting for the icon to be processed before they can proceed | 295 // The user is waiting for the icon to be processed before they can proceed |
290 // with add to homescreen. But if we shut down, there's no point starting the | 296 // with add to homescreen. But if we shut down, there's no point starting the |
291 // image processing. Use USER_VISIBLE with MayBlock and SKIP_ON_SHUTDOWN. | 297 // image processing. Use USER_VISIBLE with MayBlock and SKIP_ON_SHUTDOWN. |
292 base::PostTaskWithTraitsAndReplyWithResult( | 298 base::PostTaskWithTraitsAndReplyWithResult( |
293 FROM_HERE, | 299 FROM_HERE, |
294 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, | 300 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
295 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, | 301 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, |
296 base::BindOnce(&AddToHomescreenDataFetcher:: | 302 base::BindOnce(&AddToHomescreenDataFetcher:: |
297 CreateLauncherIconFromFaviconInBackground, | 303 CreateLauncherIconFromFaviconInBackground, |
298 base::Unretained(this), bitmap_result), | 304 base::Unretained(this), bitmap_result), |
299 base::BindOnce(&AddToHomescreenDataFetcher::NotifyObserver, | 305 base::BindOnce(&AddToHomescreenDataFetcher::NotifyObserver, |
300 base::RetainedRef(this))); | 306 base::RetainedRef(this))); |
301 } | 307 } |
302 | 308 |
303 SkBitmap AddToHomescreenDataFetcher::CreateLauncherIconFromFaviconInBackground( | 309 SkBitmap AddToHomescreenDataFetcher::CreateLauncherIconFromFaviconInBackground( |
304 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 310 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
305 base::ThreadRestrictions::AssertIOAllowed(); | 311 base::ThreadRestrictions::AssertIOAllowed(); |
306 | 312 |
307 SkBitmap raw_icon; | |
308 if (bitmap_result.is_valid()) { | 313 if (bitmap_result.is_valid()) { |
309 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), | 314 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), |
310 bitmap_result.bitmap_data->size(), &raw_icon); | 315 bitmap_result.bitmap_data->size(), |
316 &raw_primary_icon_); | |
311 } | 317 } |
312 | 318 |
313 shortcut_info_.best_primary_icon_url = bitmap_result.icon_url; | 319 shortcut_info_.best_primary_icon_url = bitmap_result.icon_url; |
314 return CreateLauncherIconInBackground(raw_icon); | 320 return CreateLauncherIconInBackground(raw_primary_icon_); |
315 } | 321 } |
316 | 322 |
317 void AddToHomescreenDataFetcher::CreateLauncherIcon(const SkBitmap& raw_icon) { | 323 void AddToHomescreenDataFetcher::CreateLauncherIcon(const SkBitmap& icon) { |
318 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 324 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
319 | 325 |
320 // The user is waiting for the icon to be processed before they can proceed | 326 // The user is waiting for the icon to be processed before they can proceed |
321 // with add to homescreen. But if we shut down, there's no point starting the | 327 // with add to homescreen. But if we shut down, there's no point starting the |
322 // image processing. Use USER_VISIBLE with MayBlock and SKIP_ON_SHUTDOWN. | 328 // image processing. Use USER_VISIBLE with MayBlock and SKIP_ON_SHUTDOWN. |
323 base::PostTaskWithTraitsAndReplyWithResult( | 329 base::PostTaskWithTraitsAndReplyWithResult( |
324 FROM_HERE, | 330 FROM_HERE, |
325 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, | 331 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
326 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, | 332 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, |
327 base::BindOnce( | 333 base::BindOnce( |
328 &AddToHomescreenDataFetcher::CreateLauncherIconInBackground, | 334 &AddToHomescreenDataFetcher::CreateLauncherIconInBackground, |
329 base::Unretained(this), raw_icon), | 335 base::Unretained(this), raw_primary_icon_), |
330 base::BindOnce(&AddToHomescreenDataFetcher::NotifyObserver, | 336 base::BindOnce(&AddToHomescreenDataFetcher::NotifyObserver, |
331 base::RetainedRef(this))); | 337 base::RetainedRef(this))); |
332 } | 338 } |
333 | 339 |
334 SkBitmap AddToHomescreenDataFetcher::CreateLauncherIconInBackground( | 340 SkBitmap AddToHomescreenDataFetcher::CreateLauncherIconInBackground( |
335 const SkBitmap& raw_icon) { | 341 const SkBitmap& icon) { |
336 base::ThreadRestrictions::AssertIOAllowed(); | 342 base::ThreadRestrictions::AssertIOAllowed(); |
337 | 343 |
338 SkBitmap primary_icon; | 344 SkBitmap primary_icon; |
339 bool is_generated = false; | 345 bool is_generated = false; |
340 if (weak_observer_) { | 346 if (weak_observer_) { |
341 primary_icon = weak_observer_->FinalizeLauncherIconInBackground( | 347 primary_icon = weak_observer_->FinalizeLauncherIconInBackground( |
342 raw_icon, shortcut_info_.url, &is_generated); | 348 icon, shortcut_info_.url, &is_generated); |
343 } | 349 } |
344 | 350 |
345 if (is_generated) | 351 if (is_generated) |
346 shortcut_info_.best_primary_icon_url = GURL(); | 352 shortcut_info_.best_primary_icon_url = GURL(); |
347 | 353 |
348 return primary_icon; | 354 return primary_icon; |
349 } | 355 } |
350 | 356 |
351 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { | 357 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { |
352 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 358 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
353 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 359 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
354 return; | 360 return; |
355 | 361 |
356 is_icon_saved_ = true; | 362 is_icon_saved_ = true; |
357 primary_icon_ = primary_icon; | 363 primary_icon_ = primary_icon; |
358 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); | 364 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); |
359 } | 365 } |
OLD | NEW |