OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
11 #include "storage/browser/quota/special_storage_policy.h" | |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 #include "url/url_util.h" | 13 #include "url/url_util.h" |
14 | 14 |
15 // Static | 15 // Static |
16 bool BrowsingDataHelper::IsWebScheme(const std::string& scheme) { | 16 bool BrowsingDataHelper::IsWebScheme(const std::string& scheme) { |
17 const std::vector<std::string>& schemes = url::GetWebStorageSchemes(); | 17 const std::vector<std::string>& schemes = url::GetWebStorageSchemes(); |
18 return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end(); | 18 return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end(); |
19 } | 19 } |
20 | 20 |
21 // Static | 21 // Static |
22 bool BrowsingDataHelper::HasWebScheme(const GURL& origin) { | 22 bool BrowsingDataHelper::HasWebScheme(const GURL& origin) { |
23 return BrowsingDataHelper::IsWebScheme(origin.scheme()); | 23 return BrowsingDataHelper::IsWebScheme(origin.scheme()); |
24 } | 24 } |
25 | 25 |
26 // Static | 26 // Static |
27 bool BrowsingDataHelper::IsExtensionScheme(const std::string& scheme) { | 27 bool BrowsingDataHelper::IsExtensionScheme(const std::string& scheme) { |
28 return scheme == extensions::kExtensionScheme; | 28 return scheme == extensions::kExtensionScheme; |
29 } | 29 } |
30 | 30 |
31 // Static | 31 // Static |
32 bool BrowsingDataHelper::HasExtensionScheme(const GURL& origin) { | 32 bool BrowsingDataHelper::HasExtensionScheme(const GURL& origin) { |
33 return BrowsingDataHelper::IsExtensionScheme(origin.scheme()); | 33 return BrowsingDataHelper::IsExtensionScheme(origin.scheme()); |
34 } | 34 } |
35 | |
36 // Static | |
37 bool BrowsingDataHelper::DoesOriginMatchMask( | |
38 const GURL& origin, | |
39 int origin_type_mask, | |
40 storage::SpecialStoragePolicy* policy) { | |
41 // Packaged apps and extensions match iff EXTENSION. | |
42 if (BrowsingDataHelper::HasExtensionScheme(origin.GetOrigin()) && | |
43 origin_type_mask & EXTENSION) | |
44 return true; | |
45 | |
46 // If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB. | |
47 if ((!policy || !policy->IsStorageProtected(origin.GetOrigin())) && | |
48 BrowsingDataHelper::HasWebScheme(origin.GetOrigin()) && | |
49 origin_type_mask & UNPROTECTED_WEB) | |
50 return true; | |
51 | |
52 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB. | |
53 if (policy && | |
54 policy->IsStorageProtected(origin.GetOrigin()) && | |
55 BrowsingDataHelper::HasWebScheme(origin.GetOrigin()) && | |
56 origin_type_mask & PROTECTED_WEB) | |
57 return true; | |
58 | |
59 return false; | |
60 } | |
OLD | NEW |