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

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

Issue 2642233002: Require WebApp & WebAPK primary icons to have IconPurpose::ANY (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | chrome/browser/installable/installable_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ssl/security_state_tab_helper.h" 12 #include "chrome/browser/ssl/security_state_tab_helper.h"
13 #include "components/security_state/core/security_state.h" 13 #include "components/security_state/core/security_state.h"
14 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/navigation_handle.h" 16 #include "content/public/browser/navigation_handle.h"
17 #include "content/public/browser/service_worker_context.h" 17 #include "content/public/browser/service_worker_context.h"
18 #include "content/public/browser/storage_partition.h" 18 #include "content/public/browser/storage_partition.h"
19 #include "net/base/url_util.h" 19 #include "net/base/url_util.h"
20 #include "third_party/WebKit/public/platform/WebDisplayMode.h" 20 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
21 21
22 using IconPurpose = content::Manifest::Icon::IconPurpose;
23
22 namespace { 24 namespace {
23 25
24 const char kPngExtension[] = ".png"; 26 const char kPngExtension[] = ".png";
25 27
26 // This constant is the icon size on Android (48dp) multiplied by the scale 28 // This constant is the icon size on Android (48dp) multiplied by the scale
27 // factor of a Nexus 5 device (3x). For mobile and desktop platforms, a 144px 29 // factor of a Nexus 5 device (3x). For mobile and desktop platforms, a 144px
28 // icon is an approximate, appropriate lower bound. It is the currently 30 // icon is an approximate, appropriate lower bound. It is the currently
29 // advertised minimum icon size for triggering banners. 31 // advertised minimum icon size for triggering banners.
30 // TODO(dominickn): consolidate with minimum_icon_size_in_px across platforms. 32 // TODO(dominickn): consolidate with minimum_icon_size_in_px across platforms.
31 const int kIconMinimumSizeInPx = 144; 33 const int kIconMinimumSizeInPx = 144;
32 34
35 // Returns true if |icon| has icon purpose |purpose|.
36 bool HasIconPurpose(const content::Manifest::Icon& icon, IconPurpose purpose) {
37 for (IconPurpose icon_purpose : icon.purpose) {
dominickn 2017/01/19 23:29:20 return std::find(icon.purpose.begin(), icon.purpos
F 2017/01/20 00:36:01 Done.
38 if (icon_purpose == purpose)
39 return true;
40 }
41 return false;
42 }
43
33 // Returns true if |manifest| specifies a PNG icon >= 144x144px (or size "any"). 44 // Returns true if |manifest| specifies a PNG icon >= 144x144px (or size "any").
34 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { 45 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) {
35 for (const auto& icon : manifest.icons) { 46 for (const auto& icon : manifest.icons) {
36 // The type field is optional. If it isn't present, fall back on checking 47 // The type field is optional. If it isn't present, fall back on checking
37 // the src extension, and allow the icon if the extension ends with png. 48 // the src extension, and allow the icon if the extension ends with png.
38 if (!base::EqualsASCII(icon.type, "image/png") && 49 if (!base::EqualsASCII(icon.type, "image/png") &&
39 !(icon.type.empty() && base::EndsWith( 50 !(icon.type.empty() && base::EndsWith(
40 icon.src.ExtractFileName(), kPngExtension, 51 icon.src.ExtractFileName(), kPngExtension,
41 base::CompareCase::INSENSITIVE_ASCII))) 52 base::CompareCase::INSENSITIVE_ASCII)))
42 continue; 53 continue;
43 54
55 if (!HasIconPurpose(icon, IconPurpose::ANY))
dominickn 2017/01/19 23:29:20 Nit: newline after continue
F 2017/01/20 00:36:01 Done.
56 continue;
44 for (const auto& size : icon.sizes) { 57 for (const auto& size : icon.sizes) {
45 if (size.IsEmpty()) // "any" 58 if (size.IsEmpty()) // "any"
46 return true; 59 return true;
47 if (size.width() >= kIconMinimumSizeInPx && 60 if (size.width() >= kIconMinimumSizeInPx &&
48 size.height() >= kIconMinimumSizeInPx) { 61 size.height() >= kIconMinimumSizeInPx) {
49 return true; 62 return true;
50 } 63 }
51 } 64 }
52 } 65 }
53 66
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 return manifest_->url; 470 return manifest_->url;
458 } 471 }
459 472
460 const content::Manifest& InstallableManager::manifest() const { 473 const content::Manifest& InstallableManager::manifest() const {
461 return manifest_->manifest; 474 return manifest_->manifest;
462 } 475 }
463 476
464 bool InstallableManager::is_installable() const { 477 bool InstallableManager::is_installable() const {
465 return installable_->installable; 478 return installable_->installable;
466 } 479 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/installable/installable_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698