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

Side by Side Diff: chrome/browser/installable/installable_manager.cc

Issue 2611623003: Use exact pixel sizes instead of dip in webapp/WebAPK installability code (Closed)
Patch Set: Rebased version of pkotwicz@'s original patch Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "chrome/browser/manifest/manifest_icon_downloader.h" 9 #include "chrome/browser/manifest/manifest_icon_downloader.h"
10 #include "chrome/browser/manifest/manifest_icon_selector.h" 10 #include "chrome/browser/manifest/manifest_icon_selector.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/navigation_handle.h" 14 #include "content/public/browser/navigation_handle.h"
15 #include "content/public/browser/service_worker_context.h" 15 #include "content/public/browser/service_worker_context.h"
16 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
17 #include "third_party/WebKit/public/platform/WebDisplayMode.h" 17 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
18 18
19 namespace { 19 namespace {
20 20
21 const char kPngExtension[] = ".png"; 21 const char kPngExtension[] = ".png";
22 22
23 // This constant is the icon size on Android (48dp) multiplied by the scale 23 // This constant is the icon size on Android (48dp) multiplied by the scale
24 // factor of a Nexus 5 device (3x). For mobile and desktop platforms, a 144px 24 // factor of a Nexus 5 device (3x). For mobile and desktop platforms, a 144px
25 // icon is an approximate, appropriate lower bound. It is the currently 25 // icon is an approximate, appropriate lower bound. It is the currently
26 // advertised minimum icon size for triggering banners. 26 // advertised minimum icon size for triggering banners.
27 // TODO(dominickn): consolidate with minimum_icon_size_in_dp across platforms. 27 // TODO(dominickn): consolidate with minimum_icon_size_in_px across platforms.
28 const int kIconMinimumSizeInPx = 144; 28 const int kIconMinimumSizeInPx = 144;
29 29
30 // Returns true if |manifest| specifies a PNG icon >= 144x144px (or size "any"). 30 // Returns true if |manifest| specifies a PNG icon >= 144x144px (or size "any").
31 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { 31 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) {
32 for (const auto& icon : manifest.icons) { 32 for (const auto& icon : manifest.icons) {
33 // The type field is optional. If it isn't present, fall back on checking 33 // The type field is optional. If it isn't present, fall back on checking
34 // the src extension, and allow the icon if the extension ends with png. 34 // the src extension, and allow the icon if the extension ends with png.
35 if (!base::EqualsASCII(icon.type, "image/png") && 35 if (!base::EqualsASCII(icon.type, "image/png") &&
36 !(icon.type.empty() && base::EndsWith( 36 !(icon.type.empty() && base::EndsWith(
37 icon.src.ExtractFileName(), kPngExtension, 37 icon.src.ExtractFileName(), kPngExtension,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 tasks_.push_back({params, callback}); 108 tasks_.push_back({params, callback});
109 if (is_active_) 109 if (is_active_)
110 return; 110 return;
111 111
112 is_active_ = true; 112 is_active_ = true;
113 StartNextTask(); 113 StartNextTask();
114 } 114 }
115 115
116 InstallableManager::IconProperty& InstallableManager::GetIcon( 116 InstallableManager::IconProperty& InstallableManager::GetIcon(
117 const InstallableParams& params) { 117 const InstallableParams& params) {
118 return icons_[{params.ideal_icon_size_in_dp, params.minimum_icon_size_in_dp}]; 118 return icons_[{params.ideal_icon_size_in_px, params.minimum_icon_size_in_px}];
119 } 119 }
120 120
121 bool InstallableManager::IsIconFetched(const InstallableParams& params) const { 121 bool InstallableManager::IsIconFetched(const InstallableParams& params) const {
122 const auto it = icons_.find( 122 const auto it = icons_.find(
123 {params.ideal_icon_size_in_dp, params.minimum_icon_size_in_dp}); 123 {params.ideal_icon_size_in_px, params.minimum_icon_size_in_px});
124 return it != icons_.end() && it->second.fetched; 124 return it != icons_.end() && it->second.fetched;
125 } 125 }
126 126
127 void InstallableManager::SetIconFetched(const InstallableParams& params) { 127 void InstallableManager::SetIconFetched(const InstallableParams& params) {
128 GetIcon(params).fetched = true; 128 GetIcon(params).fetched = true;
129 } 129 }
130 130
131 InstallableStatusCode InstallableManager::GetErrorCode( 131 InstallableStatusCode InstallableManager::GetErrorCode(
132 const InstallableParams& params) { 132 const InstallableParams& params) {
133 if (manifest_->error != NO_ERROR_DETECTED) 133 if (manifest_->error != NO_ERROR_DETECTED)
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 void InstallableManager::CheckAndFetchBestIcon() { 375 void InstallableManager::CheckAndFetchBestIcon() {
376 DCHECK(!manifest().IsEmpty()); 376 DCHECK(!manifest().IsEmpty());
377 DCHECK(!tasks_.empty()); 377 DCHECK(!tasks_.empty());
378 378
379 const InstallableParams& params = tasks_[0].first; 379 const InstallableParams& params = tasks_[0].first;
380 IconProperty& icon = GetIcon(params); 380 IconProperty& icon = GetIcon(params);
381 icon.fetched = true; 381 icon.fetched = true;
382 382
383 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( 383 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon(
384 manifest().icons, params.ideal_icon_size_in_dp, 384 manifest().icons, params.ideal_icon_size_in_px,
385 params.minimum_icon_size_in_dp); 385 params.minimum_icon_size_in_px);
386 386
387 if (icon_url.is_empty()) { 387 if (icon_url.is_empty()) {
388 icon.error = NO_ACCEPTABLE_ICON; 388 icon.error = NO_ACCEPTABLE_ICON;
389 } else { 389 } else {
390 bool can_download_icon = ManifestIconDownloader::Download( 390 bool can_download_icon = ManifestIconDownloader::Download(
391 GetWebContents(), icon_url, params.ideal_icon_size_in_dp, 391 GetWebContents(), icon_url, params.ideal_icon_size_in_px,
392 params.minimum_icon_size_in_dp, 392 params.minimum_icon_size_in_px,
393 base::Bind(&InstallableManager::OnAppIconFetched, 393 base::Bind(&InstallableManager::OnAppIconFetched,
394 weak_factory_.GetWeakPtr(), icon_url)); 394 weak_factory_.GetWeakPtr(), icon_url));
395 if (can_download_icon) 395 if (can_download_icon)
396 return; 396 return;
397 icon.error = CANNOT_DOWNLOAD_ICON; 397 icon.error = CANNOT_DOWNLOAD_ICON;
398 } 398 }
399 399
400 WorkOnTask(); 400 WorkOnTask();
401 } 401 }
402 402
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return manifest_->url; 436 return manifest_->url;
437 } 437 }
438 438
439 const content::Manifest& InstallableManager::manifest() const { 439 const content::Manifest& InstallableManager::manifest() const {
440 return manifest_->manifest; 440 return manifest_->manifest;
441 } 441 }
442 442
443 bool InstallableManager::is_installable() const { 443 bool InstallableManager::is_installable() const {
444 return installable_->installable; 444 return installable_->installable;
445 } 445 }
OLDNEW
« no previous file with comments | « chrome/browser/installable/installable_manager.h ('k') | chrome/browser/installable/installable_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698