1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_helper.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/common/url_constants.h"
9 #include "content/public/browser/child_process_security_policy.h"
10 #include "extensions/common/constants.h"
11 #include "storage/browser/quota/special_storage_policy.h"
15 bool BrowsingDataHelper::IsWebScheme(const std::string
& scheme
) {
16 // All "web safe" schemes are valid, except `chrome-extension://`
17 // and `chrome-devtools://`.
18 content::ChildProcessSecurityPolicy
* policy
=
19 content::ChildProcessSecurityPolicy::GetInstance();
20 return (policy
->IsWebSafeScheme(scheme
) &&
21 !BrowsingDataHelper::IsExtensionScheme(scheme
) &&
22 scheme
!= content::kChromeDevToolsScheme
);
26 bool BrowsingDataHelper::HasWebScheme(const GURL
& origin
) {
27 return BrowsingDataHelper::IsWebScheme(origin
.scheme());
31 bool BrowsingDataHelper::IsExtensionScheme(const std::string
& scheme
) {
32 return scheme
== extensions::kExtensionScheme
;
36 bool BrowsingDataHelper::HasExtensionScheme(const GURL
& origin
) {
37 return BrowsingDataHelper::IsExtensionScheme(origin
.scheme());
41 bool BrowsingDataHelper::DoesOriginMatchMask(
44 storage::SpecialStoragePolicy
* policy
) {
45 // Packaged apps and extensions match iff EXTENSION.
46 if (BrowsingDataHelper::HasExtensionScheme(origin
.GetOrigin()) &&
47 origin_type_mask
& EXTENSION
)
50 // If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB.
51 if ((!policy
|| !policy
->IsStorageProtected(origin
.GetOrigin())) &&
52 BrowsingDataHelper::HasWebScheme(origin
.GetOrigin()) &&
53 origin_type_mask
& UNPROTECTED_WEB
)
56 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB.
58 policy
->IsStorageProtected(origin
.GetOrigin()) &&
59 BrowsingDataHelper::HasWebScheme(origin
.GetOrigin()) &&
60 origin_type_mask
& PROTECTED_WEB
)