blob: 5869274d6f2cbc860267decf4d451e2896efa6d8 [file] [log] [blame]
kinuko8cbea052015-04-25 13:35:431// 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"
avia9aa7a82015-12-25 03:06:318#include "base/macros.h"
kinuko8cbea052015-04-25 13:35:439#include "base/stl_util.h"
Emily Starkfcadace2018-05-24 00:00:5310#include "base/strings/pattern.h"
jame0dcd982017-01-11 03:13:4511#include "content/common/url_schemes.h"
Lukasz Anforowicza7b5a1532019-03-13 19:56:3612#include "services/network/public/cpp/is_potentially_trustworthy.h"
kinuko8cbea052015-04-25 13:35:4313#include "url/gurl.h"
jam09015352017-01-19 01:49:0214#include "url/url_util.h"
kinuko8cbea052015-04-25 13:35:4315
kinuko8cbea052015-04-25 13:35:4316namespace content {
17
kinuko8cbea052015-04-25 13:35:4318bool IsOriginSecure(const GURL& url) {
Lukasz Anforowicz0e9ad4e2019-03-14 20:03:4719 // 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))
kinuko8cbea052015-04-25 13:35:4327 return true;
28
Lukasz Anforowicz0e9ad4e2019-03-14 20:03:4729 // TODO(lukasza): trustworthiness of blob: URLs should depend on their inner
30 // origin (just as it does for filesystem: URLs). Changing this behavior of
31 // content::IsOriginSecure breaks some tests, so fixing this is postponed to a
32 // follow-up CL. WIP CL @ https://crrev.com/c/1506941.
33 if (url.SchemeIs(url::kBlobScheme))
34 return false;
kinuko8cbea052015-04-25 13:35:4335
Lukasz Anforowicz0e9ad4e2019-03-14 20:03:4736 return network::IsUrlPotentiallyTrustworthy(url);
kinuko8cbea052015-04-25 13:35:4337}
38
annekao1db36fd2015-07-29 17:09:1639bool OriginCanAccessServiceWorkers(const GURL& url) {
40 if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url))
41 return true;
42
jame0dcd982017-01-11 03:13:4543 if (base::ContainsValue(GetServiceWorkerSchemes(), url.scheme())) {
annekao1db36fd2015-07-29 17:09:1644 return true;
45 }
46
47 return false;
48}
49
carloskd9d97942017-02-16 08:58:0950bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) {
Lukasz Anforowicz0e9ad4e2019-03-14 20:03:4751 return network::IsOriginPotentiallyTrustworthy(origin);
carloskd9d97942017-02-16 08:58:0952}
53
kinuko8cbea052015-04-25 13:35:4354} // namespace content