kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/public/common/origin_util.h" |
| 6 | |
| 7 | #include "base/lazy_instance.h" |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 8 | #include "base/macros.h" |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 9 | #include "base/stl_util.h" |
Emily Stark | fcadace | 2018-05-24 00:00:53 | [diff] [blame] | 10 | #include "base/strings/pattern.h" |
jam | e0dcd98 | 2017-01-11 03:13:45 | [diff] [blame] | 11 | #include "content/common/url_schemes.h" |
Lukasz Anforowicz | a7b5a153 | 2019-03-13 19:56:36 | [diff] [blame] | 12 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 13 | #include "url/gurl.h" |
jam | 0901535 | 2017-01-19 01:49:02 | [diff] [blame] | 14 | #include "url/url_util.h" |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 15 | |
| 16 | namespace content { |
| 17 | |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 18 | bool IsOriginSecure(const GURL& url) { |
Lukasz Anforowicz | 0e9ad4e | 2019-03-14 20:03:47 | [diff] [blame] | 19 | // TODO(lukasza): data: URLs (and opaque origins associated with them) should |
| 20 | // be considered insecure according to |
| 21 | // https://www.w3.org/TR/powerful-features/#is-url-trustworthy. |
| 22 | // Unfortunately, changing this behavior of content::IsOriginSecure breaks |
| 23 | // quite a few tests for now (e.g. considering data: insecure makes us think |
| 24 | // that https + data = mixed content), so fixing this is postponed to a |
| 25 | // follow-up CL. WIP CL @ https://crrev.com/c/1505897. |
| 26 | if (url.SchemeIs(url::kDataScheme)) |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 27 | return true; |
| 28 | |
Lukasz Anforowicz | 0e9ad4e | 2019-03-14 20:03:47 | [diff] [blame] | 29 | return network::IsUrlPotentiallyTrustworthy(url); |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 30 | } |
| 31 | |
annekao | 1db36fd | 2015-07-29 17:09:16 | [diff] [blame] | 32 | bool OriginCanAccessServiceWorkers(const GURL& url) { |
| 33 | if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url)) |
| 34 | return true; |
| 35 | |
Jan Wilken Dörrie | 531be7ca | 2019-06-07 10:05:57 | [diff] [blame] | 36 | if (base::Contains(GetServiceWorkerSchemes(), url.scheme())) { |
annekao | 1db36fd | 2015-07-29 17:09:16 | [diff] [blame] | 37 | return true; |
| 38 | } |
| 39 | |
| 40 | return false; |
| 41 | } |
| 42 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 43 | bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) { |
Lukasz Anforowicz | 0e9ad4e | 2019-03-14 20:03:47 | [diff] [blame] | 44 | return network::IsOriginPotentiallyTrustworthy(origin); |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 45 | } |
| 46 | |
kinuko | 8cbea05 | 2015-04-25 13:35:43 | [diff] [blame] | 47 | } // namespace content |