| 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 "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/content_settings/cookie_settings.h" | 11 #include "chrome/browser/content_settings/cookie_settings.h" |
| 12 #include "chrome/browser/intents/web_intents_util.h" | |
| 13 #include "chrome/common/content_settings.h" | 12 #include "chrome/common/content_settings.h" |
| 14 #include "chrome/common/content_settings_types.h" | 13 #include "chrome/common/content_settings_types.h" |
| 15 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/web_intents_handler.h" | |
| 17 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 18 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 19 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
| 20 #include "webkit/glue/web_intent_service_data.h" | |
| 21 | 18 |
| 22 using content::BrowserThread; | 19 using content::BrowserThread; |
| 23 using extensions::APIPermission; | 20 using extensions::APIPermission; |
| 24 | 21 |
| 25 namespace { | |
| 26 | |
| 27 // Does the specified extension support the passed Web Intent, |action|? | |
| 28 bool ExtensionSupportsIntentAction( | |
| 29 const extensions::Extension* extension, | |
| 30 const std::string& action) { | |
| 31 #if defined(ENABLE_WEB_INTENTS) | |
| 32 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator i = | |
| 33 extensions::WebIntentsInfo::GetIntentsServices(extension).begin(); | |
| 34 i != extensions::WebIntentsInfo::GetIntentsServices(extension).end(); | |
| 35 ++i) { | |
| 36 if (UTF16ToUTF8(i->action) == action) | |
| 37 return true; | |
| 38 } | |
| 39 #endif | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( | 22 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( |
| 46 CookieSettings* cookie_settings) | 23 CookieSettings* cookie_settings) |
| 47 : cookie_settings_(cookie_settings) {} | 24 : cookie_settings_(cookie_settings) {} |
| 48 | 25 |
| 49 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 26 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
| 50 | 27 |
| 51 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { | 28 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { |
| 52 if (origin.SchemeIs(extensions::kExtensionScheme)) | 29 if (origin.SchemeIs(extensions::kExtensionScheme)) |
| 53 return true; | 30 return true; |
| 54 base::AutoLock locker(lock_); | 31 base::AutoLock locker(lock_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 81 for (size_t i = 0; i < entries.size(); ++i) { | 58 for (size_t i = 0; i < entries.size(); ++i) { |
| 82 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) | 59 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) |
| 83 return true; | 60 return true; |
| 84 } | 61 } |
| 85 return false; | 62 return false; |
| 86 } | 63 } |
| 87 | 64 |
| 88 bool ExtensionSpecialStoragePolicy::IsFileHandler( | 65 bool ExtensionSpecialStoragePolicy::IsFileHandler( |
| 89 const std::string& extension_id) { | 66 const std::string& extension_id) { |
| 90 base::AutoLock locker(lock_); | 67 base::AutoLock locker(lock_); |
| 91 return web_intent_extensions_.ContainsExtension(extension_id) || | 68 return file_handler_extensions_.ContainsExtension(extension_id); |
| 92 file_handler_extensions_.ContainsExtension(extension_id); | |
| 93 } | 69 } |
| 94 | 70 |
| 95 bool ExtensionSpecialStoragePolicy::NeedsProtection( | 71 bool ExtensionSpecialStoragePolicy::NeedsProtection( |
| 96 const extensions::Extension* extension) { | 72 const extensions::Extension* extension) { |
| 97 return extension->is_hosted_app() && !extension->from_bookmark(); | 73 return extension->is_hosted_app() && !extension->from_bookmark(); |
| 98 } | 74 } |
| 99 | 75 |
| 100 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 76 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| 101 const GURL& origin) { | 77 const GURL& origin) { |
| 102 base::AutoLock locker(lock_); | 78 base::AutoLock locker(lock_); |
| 103 return protected_apps_.ExtensionsContaining(origin); | 79 return protected_apps_.ExtensionsContaining(origin); |
| 104 } | 80 } |
| 105 | 81 |
| 106 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( | 82 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
| 107 const extensions::Extension* extension) { | 83 const extensions::Extension* extension) { |
| 108 DCHECK(extension); | 84 DCHECK(extension); |
| 109 const bool supports_intent_view = ExtensionSupportsIntentAction( | |
| 110 extension, web_intents::kActionView); | |
| 111 if (!NeedsProtection(extension) && | 85 if (!NeedsProtection(extension) && |
| 112 !extension->HasAPIPermission( | 86 !extension->HasAPIPermission( |
| 113 APIPermission::kUnlimitedStorage) && | 87 APIPermission::kUnlimitedStorage) && |
| 114 !extension->HasAPIPermission( | 88 !extension->HasAPIPermission( |
| 115 APIPermission::kFileBrowserHandler) && | 89 APIPermission::kFileBrowserHandler)) { |
| 116 !supports_intent_view) { | |
| 117 return; | 90 return; |
| 118 } | 91 } |
| 119 { | 92 { |
| 120 base::AutoLock locker(lock_); | 93 base::AutoLock locker(lock_); |
| 121 if (NeedsProtection(extension)) | 94 if (NeedsProtection(extension)) |
| 122 protected_apps_.Add(extension); | 95 protected_apps_.Add(extension); |
| 123 // FIXME: Does GrantRightsForExtension imply |extension| is installed? | 96 // FIXME: Does GrantRightsForExtension imply |extension| is installed? |
| 124 if (extension->is_app()) | 97 if (extension->is_app()) |
| 125 installed_apps_.Add(extension); | 98 installed_apps_.Add(extension); |
| 126 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) | 99 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) |
| 127 unlimited_extensions_.Add(extension); | 100 unlimited_extensions_.Add(extension); |
| 128 if (extension->HasAPIPermission( | 101 if (extension->HasAPIPermission( |
| 129 APIPermission::kFileBrowserHandler)) | 102 APIPermission::kFileBrowserHandler)) |
| 130 file_handler_extensions_.Add(extension); | 103 file_handler_extensions_.Add(extension); |
| 131 if (supports_intent_view) | |
| 132 web_intent_extensions_.Add(extension); | |
| 133 } | 104 } |
| 134 NotifyChanged(); | 105 NotifyChanged(); |
| 135 } | 106 } |
| 136 | 107 |
| 137 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( | 108 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( |
| 138 const extensions::Extension* extension) { | 109 const extensions::Extension* extension) { |
| 139 DCHECK(extension); | 110 DCHECK(extension); |
| 140 const bool supports_intent_view = ExtensionSupportsIntentAction( | |
| 141 extension, web_intents::kActionView); | |
| 142 if (!NeedsProtection(extension) && | 111 if (!NeedsProtection(extension) && |
| 143 !extension->HasAPIPermission( | 112 !extension->HasAPIPermission( |
| 144 APIPermission::kUnlimitedStorage) && | 113 APIPermission::kUnlimitedStorage) && |
| 145 !extension->HasAPIPermission( | 114 !extension->HasAPIPermission( |
| 146 APIPermission::kFileBrowserHandler) && | 115 APIPermission::kFileBrowserHandler)) { |
| 147 !supports_intent_view) { | |
| 148 return; | 116 return; |
| 149 } | 117 } |
| 150 { | 118 { |
| 151 base::AutoLock locker(lock_); | 119 base::AutoLock locker(lock_); |
| 152 if (NeedsProtection(extension)) | 120 if (NeedsProtection(extension)) |
| 153 protected_apps_.Remove(extension); | 121 protected_apps_.Remove(extension); |
| 154 if (extension->is_app()) | 122 if (extension->is_app()) |
| 155 installed_apps_.Remove(extension); | 123 installed_apps_.Remove(extension); |
| 156 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) | 124 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) |
| 157 unlimited_extensions_.Remove(extension); | 125 unlimited_extensions_.Remove(extension); |
| 158 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler)) | 126 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler)) |
| 159 file_handler_extensions_.Remove(extension); | 127 file_handler_extensions_.Remove(extension); |
| 160 if (supports_intent_view) | |
| 161 web_intent_extensions_.Remove(extension); | |
| 162 } | 128 } |
| 163 NotifyChanged(); | 129 NotifyChanged(); |
| 164 } | 130 } |
| 165 | 131 |
| 166 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { | 132 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { |
| 167 { | 133 { |
| 168 base::AutoLock locker(lock_); | 134 base::AutoLock locker(lock_); |
| 169 protected_apps_.Clear(); | 135 protected_apps_.Clear(); |
| 170 installed_apps_.Clear(); | 136 installed_apps_.Clear(); |
| 171 unlimited_extensions_.Clear(); | 137 unlimited_extensions_.Clear(); |
| 172 file_handler_extensions_.Clear(); | 138 file_handler_extensions_.Clear(); |
| 173 web_intent_extensions_.Clear(); | |
| 174 } | 139 } |
| 175 NotifyChanged(); | 140 NotifyChanged(); |
| 176 } | 141 } |
| 177 | 142 |
| 178 void ExtensionSpecialStoragePolicy::NotifyChanged() { | 143 void ExtensionSpecialStoragePolicy::NotifyChanged() { |
| 179 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 144 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 180 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 145 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 181 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); | 146 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); |
| 182 return; | 147 return; |
| 183 } | 148 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 200 |
| 236 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 201 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| 237 ClearCache(); | 202 ClearCache(); |
| 238 extensions_.Clear(); | 203 extensions_.Clear(); |
| 239 } | 204 } |
| 240 | 205 |
| 241 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 206 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
| 242 STLDeleteValues(&cached_results_); | 207 STLDeleteValues(&cached_results_); |
| 243 cached_results_.clear(); | 208 cached_results_.clear(); |
| 244 } | 209 } |
| OLD | NEW |