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" |
11 #include "net/base/url_util.h" | 11 #include "net/base/url_util.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "url/url_util.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 bool IsOriginSecure(const GURL& url) { | 17 bool IsOriginSecure(const GURL& url) { |
17 if (url.SchemeIsCryptographic() || url.SchemeIsFile()) | 18 if (url.SchemeIsCryptographic() || url.SchemeIsFile()) |
18 return true; | 19 return true; |
19 | 20 |
20 if (url.SchemeIsFileSystem() && url.inner_url() && | 21 if (url.SchemeIsFileSystem() && url.inner_url() && |
21 IsOriginSecure(*url.inner_url())) { | 22 IsOriginSecure(*url.inner_url())) { |
22 return true; | 23 return true; |
23 } | 24 } |
24 | 25 |
25 std::string hostname = url.HostNoBrackets(); | 26 std::string hostname = url.HostNoBrackets(); |
26 if (net::IsLocalhost(hostname)) | 27 if (net::IsLocalhost(hostname)) |
27 return true; | 28 return true; |
28 | 29 |
29 if (base::ContainsValue(GetSecureSchemes(), url.scheme())) | 30 if (base::ContainsValue(url::GetSecureSchemes(), url.scheme())) |
30 return true; | 31 return true; |
31 | 32 |
32 if (base::ContainsValue(GetSecureOrigins(), url.GetOrigin())) { | 33 if (base::ContainsValue(GetSecureOrigins(), url.GetOrigin())) { |
33 return true; | 34 return true; |
34 } | 35 } |
35 | 36 |
36 return false; | 37 return false; |
37 } | 38 } |
38 | 39 |
39 bool OriginCanAccessServiceWorkers(const GURL& url) { | 40 bool OriginCanAccessServiceWorkers(const GURL& url) { |
40 if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url)) | 41 if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url)) |
41 return true; | 42 return true; |
42 | 43 |
43 if (base::ContainsValue(GetServiceWorkerSchemes(), url.scheme())) { | 44 if (base::ContainsValue(GetServiceWorkerSchemes(), url.scheme())) { |
44 return true; | 45 return true; |
45 } | 46 } |
46 | 47 |
47 return false; | 48 return false; |
48 } | 49 } |
49 | 50 |
50 void ResetSchemesAndOriginsWhitelistForTesting() { | |
51 RefreshSecuritySchemesForTesting(); | |
52 } | |
53 | |
54 } // namespace content | 51 } // namespace content |
OLD | NEW |