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

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

Issue 2642233002: Require WebApp & WebAPK primary icons to have IconPurpose::ANY (Closed)
Patch Set: rebase 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 <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h"
8 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
9 #include "chrome/browser/manifest/manifest_icon_downloader.h" 12 #include "chrome/browser/manifest/manifest_icon_downloader.h"
10 #include "chrome/browser/manifest/manifest_icon_selector.h" 13 #include "chrome/browser/manifest/manifest_icon_selector.h"
11 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ssl/security_state_tab_helper.h" 15 #include "chrome/browser/ssl/security_state_tab_helper.h"
13 #include "components/security_state/core/security_state.h" 16 #include "components/security_state/core/security_state.h"
14 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/navigation_handle.h" 19 #include "content/public/browser/navigation_handle.h"
17 #include "content/public/browser/service_worker_context.h" 20 #include "content/public/browser/service_worker_context.h"
18 #include "content/public/browser/storage_partition.h" 21 #include "content/public/browser/storage_partition.h"
19 #include "net/base/url_util.h" 22 #include "net/base/url_util.h"
20 #include "third_party/WebKit/public/platform/WebDisplayMode.h" 23 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
21 24
25 using IconPurpose = content::Manifest::Icon::IconPurpose;
26
22 namespace { 27 namespace {
23 28
24 const char kPngExtension[] = ".png"; 29 const char kPngExtension[] = ".png";
25 30
26 // This constant is the icon size on Android (48dp) multiplied by the scale 31 // 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 32 // 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 33 // icon is an approximate, appropriate lower bound. It is the currently
29 // advertised minimum icon size for triggering banners. 34 // advertised minimum icon size for triggering banners.
30 // TODO(dominickn): consolidate with minimum_icon_size_in_px across platforms. 35 // TODO(dominickn): consolidate with minimum_icon_size_in_px across platforms.
31 const int kIconMinimumSizeInPx = 144; 36 const int kIconMinimumSizeInPx = 144;
32 37
33 // Returns true if |manifest| specifies a PNG icon >= 144x144px (or size "any"). 38 // Returns true if |manifest| specifies a PNG icon >= 144x144px (or size "any"),
39 // and of icon purpose IconPurpose::ANY.
34 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { 40 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) {
35 for (const auto& icon : manifest.icons) { 41 for (const auto& icon : manifest.icons) {
36 // The type field is optional. If it isn't present, fall back on checking 42 // 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. 43 // the src extension, and allow the icon if the extension ends with png.
38 if (!base::EqualsASCII(icon.type, "image/png") && 44 if (!base::EqualsASCII(icon.type, "image/png") &&
39 !(icon.type.empty() && base::EndsWith( 45 !(icon.type.empty() && base::EndsWith(
40 icon.src.ExtractFileName(), kPngExtension, 46 icon.src.ExtractFileName(), kPngExtension,
41 base::CompareCase::INSENSITIVE_ASCII))) 47 base::CompareCase::INSENSITIVE_ASCII)))
42 continue; 48 continue;
43 49
50 if (!base::ContainsValue(icon.purpose, IconPurpose::ANY))
51 continue;
52
44 for (const auto& size : icon.sizes) { 53 for (const auto& size : icon.sizes) {
45 if (size.IsEmpty()) // "any" 54 if (size.IsEmpty()) // "any"
46 return true; 55 return true;
47 if (size.width() >= kIconMinimumSizeInPx && 56 if (size.width() >= kIconMinimumSizeInPx &&
48 size.height() >= kIconMinimumSizeInPx) { 57 size.height() >= kIconMinimumSizeInPx) {
49 return true; 58 return true;
50 } 59 }
51 } 60 }
52 } 61 }
53 62
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 return manifest_->url; 466 return manifest_->url;
458 } 467 }
459 468
460 const content::Manifest& InstallableManager::manifest() const { 469 const content::Manifest& InstallableManager::manifest() const {
461 return manifest_->manifest; 470 return manifest_->manifest;
462 } 471 }
463 472
464 bool InstallableManager::is_installable() const { 473 bool InstallableManager::is_installable() const {
465 return installable_->installable; 474 return installable_->installable;
466 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/installable/installable_logging.cc ('k') | chrome/browser/installable/installable_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698