Chromium Code Reviews| 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 "chrome/browser/content_settings/cookie_settings.h" | 10 #include "chrome/browser/content_settings/cookie_settings.h" |
| 11 #include "chrome/common/content_settings.h" | 11 #include "chrome/common/content_settings.h" |
| 12 #include "chrome/common/content_settings_types.h" | 12 #include "chrome/common/content_settings_types.h" |
| 13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "webkit/glue/web_intent_service_data.h" | |
| 16 | 17 |
| 17 using content::BrowserThread; | 18 using content::BrowserThread; |
| 18 using extensions::APIPermission; | 19 using extensions::APIPermission; |
| 19 | 20 |
| 20 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( | 21 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( |
| 21 CookieSettings* cookie_settings) | 22 CookieSettings* cookie_settings) |
| 22 : cookie_settings_(cookie_settings) {} | 23 : cookie_settings_(cookie_settings) {} |
| 23 | 24 |
| 24 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 25 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
| 25 | 26 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 52 for (size_t i = 0; i < entries.size(); ++i) { | 53 for (size_t i = 0; i < entries.size(); ++i) { |
| 53 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) | 54 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) |
| 54 return true; | 55 return true; |
| 55 } | 56 } |
| 56 return false; | 57 return false; |
| 57 } | 58 } |
| 58 | 59 |
| 59 bool ExtensionSpecialStoragePolicy::IsFileHandler( | 60 bool ExtensionSpecialStoragePolicy::IsFileHandler( |
| 60 const std::string& extension_id) { | 61 const std::string& extension_id) { |
| 61 base::AutoLock locker(lock_); | 62 base::AutoLock locker(lock_); |
| 62 return file_handler_extensions_.ContainsExtension(extension_id); | 63 return web_intent_extensions_.ContainsExtension(extension_id) || |
| 64 file_handler_extensions_.ContainsExtension(extension_id); | |
| 63 } | 65 } |
| 64 | 66 |
| 65 bool ExtensionSpecialStoragePolicy::NeedsProtection( | 67 bool ExtensionSpecialStoragePolicy::NeedsProtection( |
| 66 const extensions::Extension* extension) { | 68 const extensions::Extension* extension) { |
| 67 return extension->is_hosted_app() && !extension->from_bookmark(); | 69 return extension->is_hosted_app() && !extension->from_bookmark(); |
| 68 } | 70 } |
| 69 | 71 |
| 70 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 72 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| 71 const GURL& origin) { | 73 const GURL& origin) { |
| 72 base::AutoLock locker(lock_); | 74 base::AutoLock locker(lock_); |
| 73 return protected_apps_.ExtensionsContaining(origin); | 75 return protected_apps_.ExtensionsContaining(origin); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( | 78 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
| 77 const extensions::Extension* extension) { | 79 const extensions::Extension* extension) { |
| 78 DCHECK(extension); | 80 DCHECK(extension); |
| 79 if (!NeedsProtection(extension) && | 81 if (!NeedsProtection(extension) && |
| 80 !extension->HasAPIPermission( | 82 !extension->HasAPIPermission( |
| 81 APIPermission::kUnlimitedStorage) && | 83 APIPermission::kUnlimitedStorage) && |
| 82 !extension->HasAPIPermission( | 84 !extension->HasAPIPermission( |
| 83 APIPermission::kFileBrowserHandler)) { | 85 APIPermission::kFileBrowserHandler) && |
| 86 extension->intents_services().empty()) { | |
|
benwells
2012/08/27 08:02:59
We need to do this only if the service is for the
thorogood
2012/08/29 06:34:46
Done.
| |
| 84 return; | 87 return; |
| 85 } | 88 } |
| 86 { | 89 { |
| 87 base::AutoLock locker(lock_); | 90 base::AutoLock locker(lock_); |
| 88 if (NeedsProtection(extension)) | 91 if (NeedsProtection(extension)) |
| 89 protected_apps_.Add(extension); | 92 protected_apps_.Add(extension); |
| 90 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) | 93 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) |
| 91 unlimited_extensions_.Add(extension); | 94 unlimited_extensions_.Add(extension); |
| 92 if (extension->HasAPIPermission( | 95 if (extension->HasAPIPermission( |
| 93 APIPermission::kFileBrowserHandler)) { | 96 APIPermission::kFileBrowserHandler)) |
| 94 file_handler_extensions_.Add(extension); | 97 file_handler_extensions_.Add(extension); |
| 95 } | 98 if (!extension->intents_services().empty()) |
| 99 web_intent_extensions_.Add(extension); | |
| 96 } | 100 } |
| 97 NotifyChanged(); | 101 NotifyChanged(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( | 104 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( |
| 101 const extensions::Extension* extension) { | 105 const extensions::Extension* extension) { |
| 102 DCHECK(extension); | 106 DCHECK(extension); |
| 103 if (!NeedsProtection(extension) && | 107 if (!NeedsProtection(extension) && |
| 104 !extension->HasAPIPermission( | 108 !extension->HasAPIPermission( |
| 105 APIPermission::kUnlimitedStorage) && | 109 APIPermission::kUnlimitedStorage) && |
| 106 !extension->HasAPIPermission( | 110 !extension->HasAPIPermission( |
| 107 APIPermission::kFileBrowserHandler)) { | 111 APIPermission::kFileBrowserHandler) && |
| 112 extension->intents_services().empty()) { | |
| 108 return; | 113 return; |
| 109 } | 114 } |
| 110 { | 115 { |
| 111 base::AutoLock locker(lock_); | 116 base::AutoLock locker(lock_); |
| 112 if (NeedsProtection(extension)) | 117 if (NeedsProtection(extension)) |
| 113 protected_apps_.Remove(extension); | 118 protected_apps_.Remove(extension); |
| 114 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) | 119 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) |
| 115 unlimited_extensions_.Remove(extension); | 120 unlimited_extensions_.Remove(extension); |
| 116 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler)) | 121 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler)) |
| 117 file_handler_extensions_.Remove(extension); | 122 file_handler_extensions_.Remove(extension); |
| 123 if (!extension->intents_services().empty()) | |
| 124 web_intent_extensions_.Add(extension); | |
| 118 } | 125 } |
| 119 NotifyChanged(); | 126 NotifyChanged(); |
| 120 } | 127 } |
| 121 | 128 |
| 122 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { | 129 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { |
| 123 { | 130 { |
| 124 base::AutoLock locker(lock_); | 131 base::AutoLock locker(lock_); |
| 125 protected_apps_.Clear(); | 132 protected_apps_.Clear(); |
| 126 unlimited_extensions_.Clear(); | 133 unlimited_extensions_.Clear(); |
| 127 file_handler_extensions_.Clear(); | 134 file_handler_extensions_.Clear(); |
| 135 web_intent_extensions_.Clear(); | |
| 128 } | 136 } |
| 129 NotifyChanged(); | 137 NotifyChanged(); |
| 130 } | 138 } |
| 131 | 139 |
| 132 void ExtensionSpecialStoragePolicy::NotifyChanged() { | 140 void ExtensionSpecialStoragePolicy::NotifyChanged() { |
| 133 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 141 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 134 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 142 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 135 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); | 143 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); |
| 136 return; | 144 return; |
| 137 } | 145 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 197 |
| 190 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 198 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| 191 ClearCache(); | 199 ClearCache(); |
| 192 extensions_.Clear(); | 200 extensions_.Clear(); |
| 193 } | 201 } |
| 194 | 202 |
| 195 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 203 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
| 196 STLDeleteValues(&cached_results_); | 204 STLDeleteValues(&cached_results_); |
| 197 cached_results_.clear(); | 205 cached_results_.clear(); |
| 198 } | 206 } |
| OLD | NEW |