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

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

Issue 2589503002: Use exact pixel sizes instead of dip in webapp/WebAPK installability code (Closed)
Patch Set: Merge branch 'master' into dp_px Created 4 years 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 11 matching lines...) Expand all
22 #include "chrome/common/web_application_info.h" 22 #include "chrome/common/web_application_info.h"
23 #include "components/dom_distiller/core/url_utils.h" 23 #include "components/dom_distiller/core/url_utils.h"
24 #include "components/favicon/core/favicon_service.h" 24 #include "components/favicon/core/favicon_service.h"
25 #include "components/favicon_base/favicon_types.h" 25 #include "components/favicon_base/favicon_types.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/user_metrics.h" 27 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_observer.h" 29 #include "content/public/browser/web_contents_observer.h"
30 #include "content/public/common/manifest.h" 30 #include "content/public/common/manifest.h"
31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
32 #include "ui/display/display.h"
33 #include "ui/display/screen.h"
34 #include "ui/gfx/codec/png_codec.h" 32 #include "ui/gfx/codec/png_codec.h"
35 #include "ui/gfx/favicon_size.h" 33 #include "ui/gfx/favicon_size.h"
36 #include "url/gurl.h" 34 #include "url/gurl.h"
37 35
38 namespace { 36 namespace {
39 37
40 // 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
41 // 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
42 // screen shortcut. 40 // screen shortcut.
43 GURL GetShortcutUrl(content::BrowserContext* browser_context, 41 GURL GetShortcutUrl(content::BrowserContext* browser_context,
44 const GURL& actual_url) { 42 const GURL& actual_url) {
45 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 43 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
46 } 44 }
47 45
48 InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_dp, 46 InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_px,
49 int minimum_icon_size_in_dp, 47 int minimum_icon_size_in_px,
50 bool check_installable) { 48 bool check_installable) {
51 InstallableParams params; 49 InstallableParams params;
52 params.ideal_icon_size_in_dp = ideal_icon_size_in_dp; 50 params.ideal_icon_size_in_px = ideal_icon_size_in_px;
53 params.minimum_icon_size_in_dp = minimum_icon_size_in_dp; 51 params.minimum_icon_size_in_px = minimum_icon_size_in_px;
54 params.check_installable = check_installable; 52 params.check_installable = check_installable;
55 params.fetch_valid_icon = true; 53 params.fetch_valid_icon = true;
56 return params; 54 return params;
57 } 55 }
58 56
59 } // namespace 57 } // namespace
60 58
61 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 59 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
62 content::WebContents* web_contents, 60 content::WebContents* web_contents,
63 int ideal_icon_size_in_dp, 61 int ideal_icon_size_in_px,
64 int minimum_icon_size_in_dp, 62 int minimum_icon_size_in_px,
65 int ideal_splash_image_size_in_dp, 63 int ideal_splash_image_size_in_px,
66 int minimum_splash_image_size_in_dp, 64 int minimum_splash_image_size_in_px,
67 bool check_webapk_compatibility, 65 bool check_webapk_compatibility,
68 Observer* observer) 66 Observer* observer)
69 : WebContentsObserver(web_contents), 67 : WebContentsObserver(web_contents),
70 weak_observer_(observer), 68 weak_observer_(observer),
71 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 69 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
72 web_contents->GetLastCommittedURL())), 70 web_contents->GetLastCommittedURL())),
73 data_timeout_timer_(false, false), 71 data_timeout_timer_(false, false),
74 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), 72 ideal_icon_size_in_px_(ideal_icon_size_in_px),
75 minimum_icon_size_in_dp_(minimum_icon_size_in_dp), 73 minimum_icon_size_in_px_(minimum_icon_size_in_px),
76 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), 74 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
77 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp), 75 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
78 check_webapk_compatibility_(check_webapk_compatibility), 76 check_webapk_compatibility_(check_webapk_compatibility),
79 is_waiting_for_web_application_info_(true), 77 is_waiting_for_web_application_info_(true),
80 is_installable_check_complete_(false), 78 is_installable_check_complete_(false),
81 is_icon_saved_(false), 79 is_icon_saved_(false),
82 is_ready_(false) { 80 is_ready_(false) {
83 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); 81 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px);
84 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); 82 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px);
85 83
86 // Send a message to the renderer to retrieve information about the page. 84 // Send a message to the renderer to retrieve information about the page.
87 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 85 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
88 } 86 }
89 87
90 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( 88 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback(
91 const std::string& webapp_id) { 89 const std::string& webapp_id) {
92 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), 90 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(),
93 splash_screen_url_, ideal_splash_image_size_in_dp_, 91 splash_screen_url_, ideal_splash_image_size_in_px_,
94 minimum_splash_image_size_in_dp_, webapp_id); 92 minimum_splash_image_size_in_px_, webapp_id);
95 } 93 }
96 94
97 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( 95 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo(
98 const WebApplicationInfo& received_web_app_info) { 96 const WebApplicationInfo& received_web_app_info) {
99 is_waiting_for_web_application_info_ = false; 97 is_waiting_for_web_application_info_ = false;
100 if (!web_contents() || !weak_observer_) 98 if (!web_contents() || !weak_observer_)
101 return; 99 return;
102 100
103 // Sanitize received_web_app_info. 101 // Sanitize received_web_app_info.
104 WebApplicationInfo web_app_info = received_web_app_info; 102 WebApplicationInfo web_app_info = received_web_app_info;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 InstallableManager::FromWebContents(web_contents()); 138 InstallableManager::FromWebContents(web_contents());
141 DCHECK(manager); 139 DCHECK(manager);
142 140
143 // Kick off a timeout for downloading data. If we haven't finished within the 141 // 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. 142 // timeout, fall back to using a dynamically-generated launcher icon.
145 data_timeout_timer_.Start( 143 data_timeout_timer_.Start(
146 FROM_HERE, base::TimeDelta::FromMilliseconds(4000), 144 FROM_HERE, base::TimeDelta::FromMilliseconds(4000),
147 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); 145 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
148 146
149 manager->GetData( 147 manager->GetData(
150 ParamsToPerformInstallableCheck(ideal_icon_size_in_dp_, 148 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_,
151 minimum_icon_size_in_dp_, 149 minimum_icon_size_in_px_,
152 check_webapk_compatibility_), 150 check_webapk_compatibility_),
153 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, 151 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
154 this)); 152 this));
155 } 153 }
156 154
157 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { 155 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
158 DCHECK(!weak_observer_); 156 DCHECK(!weak_observer_);
159 } 157 }
160 158
161 bool AddToHomescreenDataFetcher::OnMessageReceived( 159 bool AddToHomescreenDataFetcher::OnMessageReceived(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 203
206 if (!data.manifest.IsEmpty()) { 204 if (!data.manifest.IsEmpty()) {
207 content::RecordAction( 205 content::RecordAction(
208 base::UserMetricsAction("webapps.AddShortcut.Manifest")); 206 base::UserMetricsAction("webapps.AddShortcut.Manifest"));
209 shortcut_info_.UpdateFromManifest(data.manifest); 207 shortcut_info_.UpdateFromManifest(data.manifest);
210 shortcut_info_.manifest_url = data.manifest_url; 208 shortcut_info_.manifest_url = data.manifest_url;
211 } 209 }
212 210
213 // Save the splash screen URL for the later download. 211 // Save the splash screen URL for the later download.
214 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( 212 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon(
215 data.manifest.icons, ideal_splash_image_size_in_dp_, 213 data.manifest.icons, ideal_splash_image_size_in_px_,
216 minimum_splash_image_size_in_dp_); 214 minimum_splash_image_size_in_px_);
217 215
218 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); 216 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title);
219 217
220 if (data.icon) { 218 if (data.icon) {
221 shortcut_info_.best_icon_url = data.icon_url; 219 shortcut_info_.best_icon_url = data.icon_url;
222 220
223 CreateLauncherIcon(*(data.icon)); 221 CreateLauncherIcon(*(data.icon));
224 return; 222 return;
225 } 223 }
226 224
(...skipping 11 matching lines...) Expand all
238 favicon_base::FAVICON, 236 favicon_base::FAVICON,
239 favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON}; 237 favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON};
240 238
241 favicon::FaviconService* favicon_service = 239 favicon::FaviconService* favicon_service =
242 FaviconServiceFactory::GetForProfile( 240 FaviconServiceFactory::GetForProfile(
243 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), 241 Profile::FromBrowserContext(web_contents()->GetBrowserContext()),
244 ServiceAccessType::EXPLICIT_ACCESS); 242 ServiceAccessType::EXPLICIT_ACCESS);
245 243
246 // Using favicon if its size is not smaller than platform required size, 244 // Using favicon if its size is not smaller than platform required size,
247 // otherwise using the largest icon among all avaliable icons. 245 // otherwise using the largest icon among all avaliable icons.
248 int ideal_icon_size_in_px = 246 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px_ - 1;
249 ideal_icon_size_in_dp_ *
250 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
251 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px - 1;
252 favicon_service->GetLargestRawFaviconForPageURL( 247 favicon_service->GetLargestRawFaviconForPageURL(
253 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon, 248 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon,
254 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), 249 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this),
255 &favicon_task_tracker_); 250 &favicon_task_tracker_);
256 } 251 }
257 252
258 void AddToHomescreenDataFetcher::OnFaviconFetched( 253 void AddToHomescreenDataFetcher::OnFaviconFetched(
259 const favicon_base::FaviconRawBitmapResult& bitmap_result) { 254 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
260 if (!web_contents() || !weak_observer_ || is_icon_saved_) 255 if (!web_contents() || !weak_observer_ || is_icon_saved_)
261 return; 256 return;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { 309 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) {
315 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 310 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
316 if (!web_contents() || !weak_observer_ || is_icon_saved_) 311 if (!web_contents() || !weak_observer_ || is_icon_saved_)
317 return; 312 return;
318 313
319 is_icon_saved_ = true; 314 is_icon_saved_ = true;
320 shortcut_icon_ = icon; 315 shortcut_icon_ = icon;
321 is_ready_ = true; 316 is_ready_ = true;
322 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); 317 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_);
323 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698