blob: d6cd385534c3866a5f0a256a40f09120d8a9868b [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
16namespace 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 return network::IsUrlPotentiallyTrustworthy(url);
kinuko8cbea052015-04-25 13:35:4330}
31
annekao1db36fd2015-07-29 17:09:1632bool OriginCanAccessServiceWorkers(const GURL& url) {
33 if (url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url))
34 return true;
35
Jan Wilken Dörrie531be7ca2019-06-07 10:05:5736 if (base::Contains(GetServiceWorkerSchemes(), url.scheme())) {
annekao1db36fd2015-07-29 17:09:1637 return true;
38 }
39
40 return false;
41}
42
carloskd9d97942017-02-16 08:58:0943bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) {
Lukasz Anforowicz0e9ad4e2019-03-14 20:03:4744 return network::IsOriginPotentiallyTrustworthy(origin);
carloskd9d97942017-02-16 08:58:0945}
46
kinuko8cbea052015-04-25 13:35:4347} // namespace content