| OLD | NEW |
| 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 "content/public/common/origin_util.h" | 5 #include "content/public/common/origin_util.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "content/common/url_schemes.h" | 10 #include "content/common/url_schemes.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 return true; | 22 return true; |
| 23 } | 23 } |
| 24 | 24 |
| 25 std::string hostname = url.HostNoBrackets(); | 25 std::string hostname = url.HostNoBrackets(); |
| 26 if (net::IsLocalhost(hostname)) | 26 if (net::IsLocalhost(hostname)) |
| 27 return true; | 27 return true; |
| 28 | 28 |
| 29 if (base::ContainsValue(GetSecureSchemes(), url.scheme())) | 29 if (base::ContainsValue(GetSecureSchemes(), url.scheme())) |
| 30 return true; | 30 return true; |
| 31 | 31 |
| 32 if (base::ContainsValue(GetSecureOrigins(), url.GetOrigin())) { | 32 if (IsOriginWhiteListedTrustworthy(url)) |
| 33 return true; | 33 return true; |
| 34 } | |
| 35 | 34 |
| 36 return false; | 35 return false; |
| 37 } | 36 } |
| 38 | 37 |
| 39 bool OriginCanAccessServiceWorkers(const GURL& url) { | 38 bool OriginCanAccessServiceWorkers(const GURL& url) { |
| 40 if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url)) | 39 if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url)) |
| 41 return true; | 40 return true; |
| 42 | 41 |
| 43 if (base::ContainsValue(GetServiceWorkerSchemes(), url.scheme())) { | 42 if (base::ContainsValue(GetServiceWorkerSchemes(), url.scheme())) { |
| 44 return true; | 43 return true; |
| 45 } | 44 } |
| 46 | 45 |
| 47 return false; | 46 return false; |
| 48 } | 47 } |
| 49 | 48 |
| 49 bool IsOriginWhiteListedTrustworthy(const GURL& url) { |
| 50 return base::ContainsValue(GetSecureOrigins(), url.GetOrigin()); |
| 51 } |
| 52 |
| 50 void ResetSchemesAndOriginsWhitelistForTesting() { | 53 void ResetSchemesAndOriginsWhitelistForTesting() { |
| 51 RefreshSecuritySchemesForTesting(); | 54 RefreshSecuritySchemesForTesting(); |
| 52 } | 55 } |
| 53 | 56 |
| 54 } // namespace content | 57 } // namespace content |
| OLD | NEW |