Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 if (size.width() >= kIconMinimumSizeInPx && | 43 if (size.width() >= kIconMinimumSizeInPx && |
| 44 size.height() >= kIconMinimumSizeInPx) { | 44 size.height() >= kIconMinimumSizeInPx) { |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool UrlHasUsernameOrPassword(const GURL& url) { | |
| 54 return url.has_username() || url.has_password(); | |
| 55 } | |
| 56 | |
| 57 // Returns whether any of the URLs in |manifest| has a username or password. | |
| 58 bool DoesManifestHaveUrlWithUsernameOrPassword( | |
| 59 const content::Manifest& manifest) { | |
| 60 for (const content::Manifest::Icon& icon : manifest.icons) { | |
| 61 if (UrlHasUsernameOrPassword(icon.src)) | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 for (const content::Manifest::RelatedApplication& related_application : | |
| 66 manifest.related_applications) { | |
| 67 if (UrlHasUsernameOrPassword(related_application.url)) { | |
| 68 return true; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 return UrlHasUsernameOrPassword(manifest.start_url) || | |
| 73 UrlHasUsernameOrPassword(manifest.scope); | |
| 74 } | |
| 75 | |
| 53 } // namespace | 76 } // namespace |
| 54 | 77 |
| 55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); | 78 DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); |
| 56 | 79 |
| 57 struct InstallableManager::ManifestProperty { | 80 struct InstallableManager::ManifestProperty { |
| 58 InstallableStatusCode error = NO_ERROR_DETECTED; | 81 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 59 GURL url; | 82 GURL url; |
| 60 content::Manifest manifest; | 83 content::Manifest manifest; |
| 61 bool fetched = false; | 84 bool fetched = false; |
| 62 }; | 85 }; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 87 InstallableManager::InstallableManager(content::WebContents* web_contents) | 110 InstallableManager::InstallableManager(content::WebContents* web_contents) |
| 88 : content::WebContentsObserver(web_contents), | 111 : content::WebContentsObserver(web_contents), |
| 89 manifest_(new ManifestProperty()), | 112 manifest_(new ManifestProperty()), |
| 90 installable_(new InstallableProperty()), | 113 installable_(new InstallableProperty()), |
| 91 is_active_(false), | 114 is_active_(false), |
| 92 weak_factory_(this) { } | 115 weak_factory_(this) { } |
| 93 | 116 |
| 94 InstallableManager::~InstallableManager() = default; | 117 InstallableManager::~InstallableManager() = default; |
| 95 | 118 |
| 96 bool InstallableManager::IsManifestValidForWebApp( | 119 bool InstallableManager::IsManifestValidForWebApp( |
| 120 const GURL& manifest_url, | |
| 97 const content::Manifest& manifest) { | 121 const content::Manifest& manifest) { |
| 98 if (manifest.IsEmpty()) { | 122 if (manifest.IsEmpty()) { |
| 99 installable_->error = MANIFEST_EMPTY; | 123 installable_->error = MANIFEST_EMPTY; |
| 100 return false; | 124 return false; |
| 101 } | 125 } |
| 102 | 126 |
| 103 if (!manifest.start_url.is_valid()) { | 127 if (!manifest.start_url.is_valid()) { |
| 104 installable_->error = START_URL_NOT_VALID; | 128 installable_->error = START_URL_NOT_VALID; |
| 105 return false; | 129 return false; |
| 106 } | 130 } |
| 107 | 131 |
| 108 if ((manifest.name.is_null() || manifest.name.string().empty()) && | 132 if ((manifest.name.is_null() || manifest.name.string().empty()) && |
| 109 (manifest.short_name.is_null() || manifest.short_name.string().empty())) { | 133 (manifest.short_name.is_null() || manifest.short_name.string().empty())) { |
| 110 installable_->error = MANIFEST_MISSING_NAME_OR_SHORT_NAME; | 134 installable_->error = MANIFEST_MISSING_NAME_OR_SHORT_NAME; |
| 111 return false; | 135 return false; |
| 112 } | 136 } |
| 113 | 137 |
| 138 // WebAPK web manifests are stored on the Chrome WebAPK server. Classify | |
| 139 // web manifests with a user name or password as not-installable to avoid | |
| 140 // storing user names and passwords on the WebAPK server. | |
| 141 if (DoesManifestHaveUrlWithUsernameOrPassword(manifest) || | |
|
dominickn
2016/08/17 22:54:43
I think this check should belong in WebAPK-specifi
pkotwicz
2016/08/18 01:11:41
The reason I put this code here is that there are
dominickn
2016/08/18 01:19:16
I think a separate WebApkManifestValidator is the
| |
| 142 UrlHasUsernameOrPassword(manifest_url)) { | |
| 143 installable_->error = URL_USERNAME_AND_PASSWORD_NOT_SUPPORTED; | |
| 144 return false; | |
| 145 } | |
| 146 | |
| 114 // TODO(dominickn,mlamouri): when Chrome supports "minimal-ui", it should be | 147 // TODO(dominickn,mlamouri): when Chrome supports "minimal-ui", it should be |
| 115 // accepted. If we accept it today, it would fallback to "browser" and make | 148 // accepted. If we accept it today, it would fallback to "browser" and make |
| 116 // this check moot. See https://crbug.com/604390. | 149 // this check moot. See https://crbug.com/604390. |
| 117 if (manifest.display != blink::WebDisplayModeStandalone && | 150 if (manifest.display != blink::WebDisplayModeStandalone && |
| 118 manifest.display != blink::WebDisplayModeFullscreen) { | 151 manifest.display != blink::WebDisplayModeFullscreen) { |
| 119 installable_->error = MANIFEST_DISPLAY_NOT_SUPPORTED; | 152 installable_->error = MANIFEST_DISPLAY_NOT_SUPPORTED; |
| 120 return false; | 153 return false; |
| 121 } | 154 } |
| 122 | 155 |
| 123 if (!DoesManifestContainRequiredIcon(manifest)) { | 156 if (!DoesManifestContainRequiredIcon(manifest)) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 manifest_->url = manifest_url; | 347 manifest_->url = manifest_url; |
| 315 manifest_->manifest = manifest; | 348 manifest_->manifest = manifest; |
| 316 manifest_->fetched = true; | 349 manifest_->fetched = true; |
| 317 WorkOnTask(); | 350 WorkOnTask(); |
| 318 } | 351 } |
| 319 | 352 |
| 320 void InstallableManager::CheckInstallable() { | 353 void InstallableManager::CheckInstallable() { |
| 321 DCHECK(!installable_->fetched); | 354 DCHECK(!installable_->fetched); |
| 322 DCHECK(!manifest().IsEmpty()); | 355 DCHECK(!manifest().IsEmpty()); |
| 323 | 356 |
| 324 if (IsManifestValidForWebApp(manifest())) { | 357 if (IsManifestValidForWebApp(manifest_url(), manifest())) { |
| 325 CheckServiceWorker(); | 358 CheckServiceWorker(); |
| 326 } else { | 359 } else { |
| 327 installable_->installable = false; | 360 installable_->installable = false; |
| 328 installable_->fetched = true; | 361 installable_->fetched = true; |
| 329 WorkOnTask(); | 362 WorkOnTask(); |
| 330 } | 363 } |
| 331 } | 364 } |
| 332 | 365 |
| 333 void InstallableManager::CheckServiceWorker() { | 366 void InstallableManager::CheckServiceWorker() { |
| 334 DCHECK(!installable_->fetched); | 367 DCHECK(!installable_->fetched); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 } | 468 } |
| 436 | 469 |
| 437 bool InstallableManager::is_installable() const { | 470 bool InstallableManager::is_installable() const { |
| 438 return installable_->installable; | 471 return installable_->installable; |
| 439 } | 472 } |
| 440 | 473 |
| 441 // static | 474 // static |
| 442 int InstallableManager::GetMinimumIconSizeInPx() { | 475 int InstallableManager::GetMinimumIconSizeInPx() { |
| 443 return kIconMinimumSizeInPx; | 476 return kIconMinimumSizeInPx; |
| 444 } | 477 } |
| OLD | NEW |