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

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

Issue 2773353002: Make minimum PWA icon size the same accross all device densities
Patch Set: Merge branch 'master' into min_size Created 3 years, 8 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/location.h" 10 #include "base/location.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Looks up the original, online URL of the site requested. The URL from the 42 // Looks up the original, online URL of the site requested. The URL from the
43 // WebContents may be a distilled article which is not appropriate for a home 43 // WebContents may be a distilled article which is not appropriate for a home
44 // screen shortcut. 44 // screen shortcut.
45 GURL GetShortcutUrl(content::BrowserContext* browser_context, 45 GURL GetShortcutUrl(content::BrowserContext* browser_context,
46 const GURL& actual_url) { 46 const GURL& actual_url) {
47 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 47 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
48 } 48 }
49 49
50 InstallableParams ParamsToPerformInstallableCheck( 50 InstallableParams ParamsToPerformInstallableCheck(
51 int ideal_icon_size_in_px, 51 int ideal_icon_size_in_px,
52 int minimum_icon_size_in_px,
53 int badge_size_in_px, 52 int badge_size_in_px,
54 bool check_webapk_compatibility) { 53 bool check_webapk_compatibility) {
55 InstallableParams params; 54 InstallableParams params;
56 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; 55 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px;
57 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px;
58 params.check_installable = check_webapk_compatibility; 56 params.check_installable = check_webapk_compatibility;
59 params.fetch_valid_primary_icon = true; 57 params.fetch_valid_primary_icon = true;
60 if (check_webapk_compatibility) { 58 if (check_webapk_compatibility) {
61 params.ideal_badge_icon_size_in_px = badge_size_in_px; 59 params.ideal_badge_icon_size_in_px = badge_size_in_px;
62 params.minimum_badge_icon_size_in_px = badge_size_in_px;
63 params.fetch_valid_badge_icon = true; 60 params.fetch_valid_badge_icon = true;
64 } 61 }
65 return params; 62 return params;
66 } 63 }
67 64
68 } // namespace 65 } // namespace
69 66
70 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 67 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
71 content::WebContents* web_contents, 68 content::WebContents* web_contents,
72 int ideal_icon_size_in_px, 69 int ideal_icon_size_in_px,
73 int minimum_icon_size_in_px,
74 int ideal_splash_image_size_in_px, 70 int ideal_splash_image_size_in_px,
75 int minimum_splash_image_size_in_px,
76 int badge_size_in_px, 71 int badge_size_in_px,
77 bool check_webapk_compatibility, 72 bool check_webapk_compatibility,
78 Observer* observer) 73 Observer* observer)
79 : WebContentsObserver(web_contents), 74 : WebContentsObserver(web_contents),
80 background_task_runner_( 75 background_task_runner_(
81 content::BrowserThread::GetBlockingPool() 76 content::BrowserThread::GetBlockingPool()
82 ->GetTaskRunnerWithShutdownBehavior( 77 ->GetTaskRunnerWithShutdownBehavior(
83 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), 78 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
84 weak_observer_(observer), 79 weak_observer_(observer),
85 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 80 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
86 web_contents->GetLastCommittedURL())), 81 web_contents->GetLastCommittedURL())),
87 ideal_icon_size_in_px_(ideal_icon_size_in_px), 82 ideal_icon_size_in_px_(ideal_icon_size_in_px),
88 minimum_icon_size_in_px_(minimum_icon_size_in_px),
89 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), 83 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
90 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
91 badge_size_in_px_(badge_size_in_px), 84 badge_size_in_px_(badge_size_in_px),
92 check_webapk_compatibility_(check_webapk_compatibility), 85 check_webapk_compatibility_(check_webapk_compatibility),
93 is_waiting_for_web_application_info_(true), 86 is_waiting_for_web_application_info_(true),
94 is_installable_check_complete_(false), 87 is_installable_check_complete_(false),
95 is_icon_saved_(false), 88 is_icon_saved_(false),
96 is_ready_(false) { 89 is_ready_(false) {
97 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px);
98 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px);
99
100 // Send a message to the renderer to retrieve information about the page. 90 // Send a message to the renderer to retrieve information about the page.
101 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 91 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
102 } 92 }
103 93
104 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( 94 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo(
105 const WebApplicationInfo& received_web_app_info) { 95 const WebApplicationInfo& received_web_app_info) {
106 is_waiting_for_web_application_info_ = false; 96 is_waiting_for_web_application_info_ = false;
107 if (!web_contents() || !weak_observer_) 97 if (!web_contents() || !weak_observer_)
108 return; 98 return;
109 99
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 DCHECK(manager); 138 DCHECK(manager);
149 139
150 // Kick off a timeout for downloading data. If we haven't finished within the 140 // Kick off a timeout for downloading data. If we haven't finished within the
151 // timeout, fall back to using a dynamically-generated launcher icon. 141 // timeout, fall back to using a dynamically-generated launcher icon.
152 data_timeout_timer_.Start( 142 data_timeout_timer_.Start(
153 FROM_HERE, base::TimeDelta::FromMilliseconds(kDataTimeoutInMilliseconds), 143 FROM_HERE, base::TimeDelta::FromMilliseconds(kDataTimeoutInMilliseconds),
154 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); 144 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
155 145
156 manager->GetData( 146 manager->GetData(
157 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, 147 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_,
158 minimum_icon_size_in_px_,
159 badge_size_in_px_, 148 badge_size_in_px_,
160 check_webapk_compatibility_), 149 check_webapk_compatibility_),
161 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, 150 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
162 this)); 151 this));
163 } 152 }
164 153
165 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { 154 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
166 DCHECK(!weak_observer_); 155 DCHECK(!weak_observer_);
167 } 156 }
168 157
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (data.badge_icon && !data.badge_icon->drawsNothing()) { 220 if (data.badge_icon && !data.badge_icon->drawsNothing()) {
232 shortcut_info_.best_badge_icon_url = data.badge_icon_url; 221 shortcut_info_.best_badge_icon_url = data.badge_icon_url;
233 badge_icon_ = *data.badge_icon; 222 badge_icon_ = *data.badge_icon;
234 } 223 }
235 } 224 }
236 } 225 }
237 226
238 // Save the splash screen URL for the later download. 227 // Save the splash screen URL for the later download.
239 shortcut_info_.splash_image_url = ManifestIconSelector::FindBestMatchingIcon( 228 shortcut_info_.splash_image_url = ManifestIconSelector::FindBestMatchingIcon(
240 data.manifest.icons, ideal_splash_image_size_in_px_, 229 data.manifest.icons, ideal_splash_image_size_in_px_,
241 minimum_splash_image_size_in_px_, 230 InstallableManager::GetMinimumIconSizeInPx(),
242 content::Manifest::Icon::IconPurpose::ANY); 231 content::Manifest::Icon::IconPurpose::ANY);
243 shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_; 232 shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_;
244 shortcut_info_.minimum_splash_image_size_in_px =
245 minimum_splash_image_size_in_px_;
246 233
247 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); 234 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title);
248 235
249 if (data.primary_icon) { 236 if (data.primary_icon) {
250 shortcut_info_.best_primary_icon_url = data.primary_icon_url; 237 shortcut_info_.best_primary_icon_url = data.primary_icon_url;
251 238
252 CreateLauncherIcon(*(data.primary_icon)); 239 CreateLauncherIcon(*(data.primary_icon));
253 return; 240 return;
254 } 241 }
255 242
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { 326 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) {
340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 327 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
341 if (!web_contents() || !weak_observer_ || is_icon_saved_) 328 if (!web_contents() || !weak_observer_ || is_icon_saved_)
342 return; 329 return;
343 330
344 is_icon_saved_ = true; 331 is_icon_saved_ = true;
345 primary_icon_ = primary_icon; 332 primary_icon_ = primary_icon;
346 is_ready_ = true; 333 is_ready_ = true;
347 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); 334 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_);
348 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698