| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 ASSERT(m_securityOrigin); | 102 ASSERT(m_securityOrigin); |
| 103 ASSERT(m_storageMap); | 103 ASSERT(m_storageMap); |
| 104 ASSERT(!m_isShutdown); | 104 ASSERT(!m_isShutdown); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool StorageAreaImpl::canAccessStorage(Frame* frame) | 107 bool StorageAreaImpl::canAccessStorage(Frame* frame) |
| 108 { | 108 { |
| 109 return frame && frame->page(); | 109 return frame && frame->page(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* frame) const | |
| 113 { | |
| 114 if (!frame->page()->settings()->privateBrowsingEnabled()) | |
| 115 return false; | |
| 116 if (m_storageType != LocalStorage) | |
| 117 return true; | |
| 118 return !SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(frame->doc
ument()->securityOrigin()->protocol()); | |
| 119 } | |
| 120 | |
| 121 unsigned StorageAreaImpl::length(ExceptionCode& ec, Frame* frame) | 112 unsigned StorageAreaImpl::length(ExceptionCode& ec, Frame* frame) |
| 122 { | 113 { |
| 123 ec = 0; | 114 ec = 0; |
| 124 if (!canAccessStorage(frame)) { | 115 if (!canAccessStorage(frame)) { |
| 125 ec = SECURITY_ERR; | 116 ec = SECURITY_ERR; |
| 126 return 0; | 117 return 0; |
| 127 } | 118 } |
| 128 if (disabledByPrivateBrowsingInFrame(frame)) | |
| 129 return 0; | |
| 130 | 119 |
| 131 ASSERT(!m_isShutdown); | 120 ASSERT(!m_isShutdown); |
| 132 blockUntilImportComplete(); | 121 blockUntilImportComplete(); |
| 133 | 122 |
| 134 return m_storageMap->length(); | 123 return m_storageMap->length(); |
| 135 } | 124 } |
| 136 | 125 |
| 137 String StorageAreaImpl::key(unsigned index, ExceptionCode& ec, Frame* frame) | 126 String StorageAreaImpl::key(unsigned index, ExceptionCode& ec, Frame* frame) |
| 138 { | 127 { |
| 139 ec = 0; | 128 ec = 0; |
| 140 if (!canAccessStorage(frame)) { | 129 if (!canAccessStorage(frame)) { |
| 141 ec = SECURITY_ERR; | 130 ec = SECURITY_ERR; |
| 142 return String(); | 131 return String(); |
| 143 } | 132 } |
| 144 if (disabledByPrivateBrowsingInFrame(frame)) | |
| 145 return String(); | |
| 146 | 133 |
| 147 ASSERT(!m_isShutdown); | 134 ASSERT(!m_isShutdown); |
| 148 blockUntilImportComplete(); | 135 blockUntilImportComplete(); |
| 149 | 136 |
| 150 return m_storageMap->key(index); | 137 return m_storageMap->key(index); |
| 151 } | 138 } |
| 152 | 139 |
| 153 String StorageAreaImpl::getItem(const String& key, ExceptionCode& ec, Frame* fra
me) | 140 String StorageAreaImpl::getItem(const String& key, ExceptionCode& ec, Frame* fra
me) |
| 154 { | 141 { |
| 155 ec = 0; | 142 ec = 0; |
| 156 if (!canAccessStorage(frame)) { | 143 if (!canAccessStorage(frame)) { |
| 157 ec = SECURITY_ERR; | 144 ec = SECURITY_ERR; |
| 158 return String(); | 145 return String(); |
| 159 } | 146 } |
| 160 if (disabledByPrivateBrowsingInFrame(frame)) | |
| 161 return String(); | |
| 162 | 147 |
| 163 ASSERT(!m_isShutdown); | 148 ASSERT(!m_isShutdown); |
| 164 blockUntilImportComplete(); | 149 blockUntilImportComplete(); |
| 165 | 150 |
| 166 return m_storageMap->getItem(key); | 151 return m_storageMap->getItem(key); |
| 167 } | 152 } |
| 168 | 153 |
| 169 void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionC
ode& ec, Frame* frame) | 154 void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionC
ode& ec, Frame* frame) |
| 170 { | 155 { |
| 171 ec = 0; | 156 ec = 0; |
| 172 if (!canAccessStorage(frame)) { | 157 if (!canAccessStorage(frame)) { |
| 173 ec = SECURITY_ERR; | 158 ec = SECURITY_ERR; |
| 174 return; | 159 return; |
| 175 } | 160 } |
| 176 | 161 |
| 177 ASSERT(!m_isShutdown); | 162 ASSERT(!m_isShutdown); |
| 178 ASSERT(!value.isNull()); | 163 ASSERT(!value.isNull()); |
| 179 blockUntilImportComplete(); | 164 blockUntilImportComplete(); |
| 180 | 165 |
| 181 if (disabledByPrivateBrowsingInFrame(frame)) { | |
| 182 ec = QUOTA_EXCEEDED_ERR; | |
| 183 return; | |
| 184 } | |
| 185 | |
| 186 String oldValue; | 166 String oldValue; |
| 187 bool quotaException; | 167 bool quotaException; |
| 188 RefPtr<StorageMap> newMap = m_storageMap->setItem(key, value, oldValue, quot
aException); | 168 RefPtr<StorageMap> newMap = m_storageMap->setItem(key, value, oldValue, quot
aException); |
| 189 if (newMap) | 169 if (newMap) |
| 190 m_storageMap = newMap.release(); | 170 m_storageMap = newMap.release(); |
| 191 | 171 |
| 192 if (quotaException) { | 172 if (quotaException) { |
| 193 ec = QUOTA_EXCEEDED_ERR; | 173 ec = QUOTA_EXCEEDED_ERR; |
| 194 return; | 174 return; |
| 195 } | 175 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 207 { | 187 { |
| 208 ec = 0; | 188 ec = 0; |
| 209 if (!canAccessStorage(frame)) { | 189 if (!canAccessStorage(frame)) { |
| 210 ec = SECURITY_ERR; | 190 ec = SECURITY_ERR; |
| 211 return; | 191 return; |
| 212 } | 192 } |
| 213 | 193 |
| 214 ASSERT(!m_isShutdown); | 194 ASSERT(!m_isShutdown); |
| 215 blockUntilImportComplete(); | 195 blockUntilImportComplete(); |
| 216 | 196 |
| 217 if (disabledByPrivateBrowsingInFrame(frame)) | |
| 218 return; | |
| 219 | |
| 220 String oldValue; | 197 String oldValue; |
| 221 RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue); | 198 RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue); |
| 222 if (newMap) | 199 if (newMap) |
| 223 m_storageMap = newMap.release(); | 200 m_storageMap = newMap.release(); |
| 224 | 201 |
| 225 if (oldValue.isNull()) | 202 if (oldValue.isNull()) |
| 226 return; | 203 return; |
| 227 | 204 |
| 228 if (m_storageAreaSync) | 205 if (m_storageAreaSync) |
| 229 m_storageAreaSync->scheduleItemForSync(key, String()); | 206 m_storageAreaSync->scheduleItemForSync(key, String()); |
| 230 dispatchStorageEvent(key, oldValue, String(), frame); | 207 dispatchStorageEvent(key, oldValue, String(), frame); |
| 231 } | 208 } |
| 232 | 209 |
| 233 void StorageAreaImpl::clear(ExceptionCode& ec, Frame* frame) | 210 void StorageAreaImpl::clear(ExceptionCode& ec, Frame* frame) |
| 234 { | 211 { |
| 235 ec = 0; | 212 ec = 0; |
| 236 if (!canAccessStorage(frame)) { | 213 if (!canAccessStorage(frame)) { |
| 237 ec = SECURITY_ERR; | 214 ec = SECURITY_ERR; |
| 238 return; | 215 return; |
| 239 } | 216 } |
| 240 | 217 |
| 241 ASSERT(!m_isShutdown); | 218 ASSERT(!m_isShutdown); |
| 242 blockUntilImportComplete(); | 219 blockUntilImportComplete(); |
| 243 | 220 |
| 244 if (disabledByPrivateBrowsingInFrame(frame)) | |
| 245 return; | |
| 246 | |
| 247 if (!m_storageMap->length()) | 221 if (!m_storageMap->length()) |
| 248 return; | 222 return; |
| 249 | 223 |
| 250 unsigned quota = m_storageMap->quota(); | 224 unsigned quota = m_storageMap->quota(); |
| 251 m_storageMap = StorageMap::create(quota); | 225 m_storageMap = StorageMap::create(quota); |
| 252 | 226 |
| 253 if (m_storageAreaSync) | 227 if (m_storageAreaSync) |
| 254 m_storageAreaSync->scheduleClear(); | 228 m_storageAreaSync->scheduleClear(); |
| 255 dispatchStorageEvent(String(), String(), String(), frame); | 229 dispatchStorageEvent(String(), String(), String(), frame); |
| 256 } | 230 } |
| 257 | 231 |
| 258 bool StorageAreaImpl::contains(const String& key, ExceptionCode& ec, Frame* fram
e) | 232 bool StorageAreaImpl::contains(const String& key, ExceptionCode& ec, Frame* fram
e) |
| 259 { | 233 { |
| 260 ec = 0; | 234 ec = 0; |
| 261 if (!canAccessStorage(frame)) { | 235 if (!canAccessStorage(frame)) { |
| 262 ec = SECURITY_ERR; | 236 ec = SECURITY_ERR; |
| 263 return false; | 237 return false; |
| 264 } | 238 } |
| 265 if (disabledByPrivateBrowsingInFrame(frame)) | |
| 266 return false; | |
| 267 | 239 |
| 268 ASSERT(!m_isShutdown); | 240 ASSERT(!m_isShutdown); |
| 269 blockUntilImportComplete(); | 241 blockUntilImportComplete(); |
| 270 | 242 |
| 271 return m_storageMap->contains(key); | 243 return m_storageMap->contains(key); |
| 272 } | 244 } |
| 273 | 245 |
| 274 void StorageAreaImpl::importItems(const HashMap<String, String>& items) | 246 void StorageAreaImpl::importItems(const HashMap<String, String>& items) |
| 275 { | 247 { |
| 276 ASSERT(!m_isShutdown); | 248 ASSERT(!m_isShutdown); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 335 |
| 364 void StorageAreaImpl::dispatchStorageEvent(const String& key, const String& oldV
alue, const String& newValue, Frame* sourceFrame) | 336 void StorageAreaImpl::dispatchStorageEvent(const String& key, const String& oldV
alue, const String& newValue, Frame* sourceFrame) |
| 365 { | 337 { |
| 366 if (m_storageType == LocalStorage) | 338 if (m_storageType == LocalStorage) |
| 367 StorageEventDispatcher::dispatchLocalStorageEvents(key, oldValue, newVal
ue, m_securityOrigin.get(), sourceFrame); | 339 StorageEventDispatcher::dispatchLocalStorageEvents(key, oldValue, newVal
ue, m_securityOrigin.get(), sourceFrame); |
| 368 else | 340 else |
| 369 StorageEventDispatcher::dispatchSessionStorageEvents(key, oldValue, newV
alue, m_securityOrigin.get(), sourceFrame); | 341 StorageEventDispatcher::dispatchSessionStorageEvents(key, oldValue, newV
alue, m_securityOrigin.get(), sourceFrame); |
| 370 } | 342 } |
| 371 | 343 |
| 372 } // namespace WebCore | 344 } // namespace WebCore |
| OLD | NEW |