Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_helper.cc
bloba40de7afb2c8e23f22f2be117abdb51b9bf92a92
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"
12 #include "url/gurl.h"
14 // Static
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);
25 // Static
26 bool BrowsingDataHelper::HasWebScheme(const GURL& origin) {
27 return BrowsingDataHelper::IsWebScheme(origin.scheme());
30 // Static
31 bool BrowsingDataHelper::IsExtensionScheme(const std::string& scheme) {
32 return scheme == extensions::kExtensionScheme;
35 // Static
36 bool BrowsingDataHelper::HasExtensionScheme(const GURL& origin) {
37 return BrowsingDataHelper::IsExtensionScheme(origin.scheme());
40 // Static
41 bool BrowsingDataHelper::DoesOriginMatchMask(
42 const GURL& origin,
43 int origin_type_mask,
44 storage::SpecialStoragePolicy* policy) {
45 // Packaged apps and extensions match iff EXTENSION.
46 if (BrowsingDataHelper::HasExtensionScheme(origin.GetOrigin()) &&
47 origin_type_mask & EXTENSION)
48 return true;
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)
54 return true;
56 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB.
57 if (policy &&
58 policy->IsStorageProtected(origin.GetOrigin()) &&
59 BrowsingDataHelper::HasWebScheme(origin.GetOrigin()) &&
60 origin_type_mask & PROTECTED_WEB)
61 return true;
63 return false;