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.
5 #include "content/public/common/origin_util.h"
7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h"
9 #include "content/public/common/content_client.h"
10 #include "net/base/net_util.h"
17 class SecureSchemeAndOriginSet
{
19 SecureSchemeAndOriginSet() { Reset(); }
20 ~SecureSchemeAndOriginSet() {}
23 GetContentClient()->AddSecureSchemesAndOrigins(&schemes_
, &origins_
);
26 const std::set
<std::string
>& schemes() const { return schemes_
; }
27 const std::set
<GURL
>& origins() const { return origins_
; }
30 std::set
<std::string
> schemes_
;
31 std::set
<GURL
> origins_
;
32 DISALLOW_COPY_AND_ASSIGN(SecureSchemeAndOriginSet
);
35 base::LazyInstance
<SecureSchemeAndOriginSet
>::Leaky g_trustworthy_whitelist
=
36 LAZY_INSTANCE_INITIALIZER
;
40 bool IsOriginSecure(const GURL
& url
) {
41 if (url
.SchemeIsCryptographic() || url
.SchemeIsFile())
44 if (url
.SchemeIsFileSystem() && url
.inner_url() &&
45 IsOriginSecure(*url
.inner_url())) {
49 std::string hostname
= url
.HostNoBrackets();
50 if (net::IsLocalhost(hostname
))
53 if (ContainsKey(g_trustworthy_whitelist
.Get().schemes(), url
.scheme()))
56 if (ContainsKey(g_trustworthy_whitelist
.Get().origins(), url
.GetOrigin()))
62 void ResetSecureSchemesAndOriginsForTesting() {
63 g_trustworthy_whitelist
.Get().Reset();
66 } // namespace content