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/extensions/extension_special_storage_policy.h" | 5 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/content_settings/cookie_settings.h" | 9 #include "chrome/browser/content_settings/cookie_settings.h" |
10 #include "chrome/common/content_settings.h" | 10 #include "chrome/common/content_settings.h" |
11 #include "chrome/common/content_settings_types.h" | 11 #include "chrome/common/content_settings_types.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 | 15 |
16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 using extensions::APIPermission; |
17 | 18 |
18 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( | 19 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( |
19 CookieSettings* cookie_settings) | 20 CookieSettings* cookie_settings) |
20 : cookie_settings_(cookie_settings) {} | 21 : cookie_settings_(cookie_settings) {} |
21 | 22 |
22 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 23 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
23 | 24 |
24 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { | 25 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { |
25 if (origin.SchemeIs(chrome::kExtensionScheme)) | 26 if (origin.SchemeIs(chrome::kExtensionScheme)) |
26 return true; | 27 return true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 bool ExtensionSpecialStoragePolicy::NeedsProtection( | 64 bool ExtensionSpecialStoragePolicy::NeedsProtection( |
64 const extensions::Extension* extension) { | 65 const extensions::Extension* extension) { |
65 return extension->is_hosted_app() && !extension->from_bookmark(); | 66 return extension->is_hosted_app() && !extension->from_bookmark(); |
66 } | 67 } |
67 | 68 |
68 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( | 69 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
69 const extensions::Extension* extension) { | 70 const extensions::Extension* extension) { |
70 DCHECK(extension); | 71 DCHECK(extension); |
71 if (!extension->is_hosted_app() && | 72 if (!extension->is_hosted_app() && |
72 !extension->HasAPIPermission( | 73 !extension->HasAPIPermission( |
73 ExtensionAPIPermission::kUnlimitedStorage) && | 74 APIPermission::kUnlimitedStorage) && |
74 !extension->HasAPIPermission( | 75 !extension->HasAPIPermission( |
75 ExtensionAPIPermission::kFileBrowserHandler)) { | 76 APIPermission::kFileBrowserHandler)) { |
76 return; | 77 return; |
77 } | 78 } |
78 { | 79 { |
79 base::AutoLock locker(lock_); | 80 base::AutoLock locker(lock_); |
80 if (NeedsProtection(extension)) | 81 if (NeedsProtection(extension)) |
81 protected_apps_.Add(extension); | 82 protected_apps_.Add(extension); |
82 if (extension->HasAPIPermission(ExtensionAPIPermission::kUnlimitedStorage)) | 83 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) |
83 unlimited_extensions_.Add(extension); | 84 unlimited_extensions_.Add(extension); |
84 if (extension->HasAPIPermission( | 85 if (extension->HasAPIPermission( |
85 ExtensionAPIPermission::kFileBrowserHandler)) { | 86 APIPermission::kFileBrowserHandler)) { |
86 file_handler_extensions_.Add(extension); | 87 file_handler_extensions_.Add(extension); |
87 } | 88 } |
88 } | 89 } |
89 NotifyChanged(); | 90 NotifyChanged(); |
90 } | 91 } |
91 | 92 |
92 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( | 93 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( |
93 const extensions::Extension* extension) { | 94 const extensions::Extension* extension) { |
94 DCHECK(extension); | 95 DCHECK(extension); |
95 if (!extension->is_hosted_app() && | 96 if (!extension->is_hosted_app() && |
96 !extension->HasAPIPermission( | 97 !extension->HasAPIPermission( |
97 ExtensionAPIPermission::kUnlimitedStorage) && | 98 APIPermission::kUnlimitedStorage) && |
98 !extension->HasAPIPermission( | 99 !extension->HasAPIPermission( |
99 ExtensionAPIPermission::kFileBrowserHandler)) { | 100 APIPermission::kFileBrowserHandler)) { |
100 return; | 101 return; |
101 } | 102 } |
102 { | 103 { |
103 base::AutoLock locker(lock_); | 104 base::AutoLock locker(lock_); |
104 if (extension->is_hosted_app() && !extension->from_bookmark()) | 105 if (extension->is_hosted_app() && !extension->from_bookmark()) |
105 protected_apps_.Remove(extension); | 106 protected_apps_.Remove(extension); |
106 if (extension->HasAPIPermission(ExtensionAPIPermission::kUnlimitedStorage)) | 107 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) |
107 unlimited_extensions_.Remove(extension); | 108 unlimited_extensions_.Remove(extension); |
108 if (extension->HasAPIPermission( | 109 if (extension->HasAPIPermission( |
109 ExtensionAPIPermission::kFileBrowserHandler)) { | 110 APIPermission::kFileBrowserHandler)) { |
110 file_handler_extensions_.Remove(extension); | 111 file_handler_extensions_.Remove(extension); |
111 } | 112 } |
112 } | 113 } |
113 NotifyChanged(); | 114 NotifyChanged(); |
114 } | 115 } |
115 | 116 |
116 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { | 117 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { |
117 { | 118 { |
118 base::AutoLock locker(lock_); | 119 base::AutoLock locker(lock_); |
119 protected_apps_.Clear(); | 120 protected_apps_.Clear(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 void ExtensionSpecialStoragePolicy::SpecialCollection::Remove( | 172 void ExtensionSpecialStoragePolicy::SpecialCollection::Remove( |
172 const extensions::Extension* extension) { | 173 const extensions::Extension* extension) { |
173 cached_results_.clear(); | 174 cached_results_.clear(); |
174 extensions_.erase(extension->id()); | 175 extensions_.erase(extension->id()); |
175 } | 176 } |
176 | 177 |
177 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 178 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
178 cached_results_.clear(); | 179 cached_results_.clear(); |
179 extensions_.clear(); | 180 extensions_.clear(); |
180 } | 181 } |
OLD | NEW |