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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 #endif | 95 #endif |
96 { | 96 { |
97 ASSERT(isMainThread()); | 97 ASSERT(isMainThread()); |
98 ASSERT(m_securityOrigin); | 98 ASSERT(m_securityOrigin); |
99 ASSERT(m_storageMap); | 99 ASSERT(m_storageMap); |
100 ASSERT(!m_isShutdown); | 100 ASSERT(!m_isShutdown); |
101 } | 101 } |
102 | 102 |
103 bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* frame) const | 103 bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* frame) const |
104 { | 104 { |
| 105 #if PLATFORM(CHROMIUM) |
| 106 // The frame pointer can be NULL in Chromium since this call is made in a di
fferent |
| 107 // process from where the Frame object exists. Luckily, private browseing i
s |
| 108 // implemented differently in Chromium, so it'd never return true anyway. |
| 109 ASSERT(!frame); |
| 110 return false; |
| 111 #else |
105 if (!frame->page()) | 112 if (!frame->page()) |
106 return true; | 113 return true; |
107 if (!frame->page()->settings()->privateBrowsingEnabled()) | 114 if (!frame->page()->settings()->privateBrowsingEnabled()) |
108 return false; | 115 return false; |
109 if (m_storageType != LocalStorage) | 116 if (m_storageType != LocalStorage) |
110 return true; | 117 return true; |
111 return !SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(frame->doc
ument()->securityOrigin()->protocol()); | 118 return !SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(frame->doc
ument()->securityOrigin()->protocol()); |
| 119 #endif |
112 } | 120 } |
113 | 121 |
114 unsigned StorageAreaImpl::length(Frame*) const | 122 unsigned StorageAreaImpl::length(Frame*) const |
115 { | 123 { |
116 ASSERT(!m_isShutdown); | 124 ASSERT(!m_isShutdown); |
117 blockUntilImportComplete(); | 125 blockUntilImportComplete(); |
118 | 126 |
119 return m_storageMap->length(); | 127 return m_storageMap->length(); |
120 } | 128 } |
121 | 129 |
122 String StorageAreaImpl::key(unsigned index, Frame*) const | 130 String StorageAreaImpl::key(unsigned index, Frame*) const |
123 { | 131 { |
124 ASSERT(!m_isShutdown); | 132 ASSERT(!m_isShutdown); |
125 blockUntilImportComplete(); | 133 blockUntilImportComplete(); |
126 | 134 |
127 return m_storageMap->key(index); | 135 return m_storageMap->key(index); |
128 } | 136 } |
129 | 137 |
130 String StorageAreaImpl::getItem(const String& key, Frame*) const | 138 String StorageAreaImpl::getItem(const String& key, Frame*) const |
131 { | 139 { |
132 ASSERT(!m_isShutdown); | 140 ASSERT(!m_isShutdown); |
133 blockUntilImportComplete(); | 141 blockUntilImportComplete(); |
134 | 142 |
135 return m_storageMap->getItem(key); | 143 return m_storageMap->getItem(key); |
136 } | 144 } |
137 | 145 |
138 void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionC
ode& ec, Frame* frame) | 146 String StorageAreaImpl::setItem(const String& key, const String& value, Exceptio
nCode& ec, Frame* frame) |
139 { | 147 { |
140 ASSERT(!m_isShutdown); | 148 ASSERT(!m_isShutdown); |
141 ASSERT(!value.isNull()); | 149 ASSERT(!value.isNull()); |
142 blockUntilImportComplete(); | 150 blockUntilImportComplete(); |
143 | 151 |
144 if (disabledByPrivateBrowsingInFrame(frame)) { | 152 if (disabledByPrivateBrowsingInFrame(frame)) { |
145 ec = QUOTA_EXCEEDED_ERR; | 153 ec = QUOTA_EXCEEDED_ERR; |
146 return; | 154 return String(); |
147 } | 155 } |
148 | 156 |
149 String oldValue; | 157 String oldValue; |
150 bool quotaException; | 158 bool quotaException; |
151 RefPtr<StorageMap> newMap = m_storageMap->setItem(key, value, oldValue, quot
aException); | 159 RefPtr<StorageMap> newMap = m_storageMap->setItem(key, value, oldValue, quot
aException); |
152 if (newMap) | 160 if (newMap) |
153 m_storageMap = newMap.release(); | 161 m_storageMap = newMap.release(); |
154 | 162 |
155 if (quotaException) { | 163 if (quotaException) { |
156 ec = QUOTA_EXCEEDED_ERR; | 164 ec = QUOTA_EXCEEDED_ERR; |
157 return; | 165 return oldValue; |
158 } | 166 } |
159 | 167 |
160 if (oldValue == value) | 168 if (oldValue == value) |
161 return; | 169 return oldValue; |
162 | 170 |
163 if (m_storageAreaSync) | 171 if (m_storageAreaSync) |
164 m_storageAreaSync->scheduleItemForSync(key, value); | 172 m_storageAreaSync->scheduleItemForSync(key, value); |
165 StorageEventDispatcher::dispatch(key, oldValue, value, m_storageType, m_secu
rityOrigin.get(), frame); | 173 StorageEventDispatcher::dispatch(key, oldValue, value, m_storageType, m_secu
rityOrigin.get(), frame); |
| 174 return oldValue; |
166 } | 175 } |
167 | 176 |
168 void StorageAreaImpl::removeItem(const String& key, Frame* frame) | 177 String StorageAreaImpl::removeItem(const String& key, Frame* frame) |
169 { | 178 { |
170 ASSERT(!m_isShutdown); | 179 ASSERT(!m_isShutdown); |
171 blockUntilImportComplete(); | 180 blockUntilImportComplete(); |
172 | 181 |
173 if (disabledByPrivateBrowsingInFrame(frame)) | 182 if (disabledByPrivateBrowsingInFrame(frame)) |
174 return; | 183 return String(); |
175 | 184 |
176 String oldValue; | 185 String oldValue; |
177 RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue); | 186 RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue); |
178 if (newMap) | 187 if (newMap) |
179 m_storageMap = newMap.release(); | 188 m_storageMap = newMap.release(); |
180 | 189 |
181 if (oldValue.isNull()) | 190 if (oldValue.isNull()) |
182 return; | 191 return oldValue; |
183 | 192 |
184 if (m_storageAreaSync) | 193 if (m_storageAreaSync) |
185 m_storageAreaSync->scheduleItemForSync(key, String()); | 194 m_storageAreaSync->scheduleItemForSync(key, String()); |
186 StorageEventDispatcher::dispatch(key, oldValue, String(), m_storageType, m_s
ecurityOrigin.get(), frame); | 195 StorageEventDispatcher::dispatch(key, oldValue, String(), m_storageType, m_s
ecurityOrigin.get(), frame); |
| 196 return oldValue; |
187 } | 197 } |
188 | 198 |
189 void StorageAreaImpl::clear(Frame* frame) | 199 bool StorageAreaImpl::clear(Frame* frame) |
190 { | 200 { |
191 ASSERT(!m_isShutdown); | 201 ASSERT(!m_isShutdown); |
192 blockUntilImportComplete(); | 202 blockUntilImportComplete(); |
193 | 203 |
194 if (disabledByPrivateBrowsingInFrame(frame)) | 204 if (disabledByPrivateBrowsingInFrame(frame)) |
195 return; | 205 return false; |
196 | 206 |
197 if (!m_storageMap->length()) | 207 if (!m_storageMap->length()) |
198 return; | 208 return false; |
199 | 209 |
200 unsigned quota = m_storageMap->quota(); | 210 unsigned quota = m_storageMap->quota(); |
201 m_storageMap = StorageMap::create(quota); | 211 m_storageMap = StorageMap::create(quota); |
202 | 212 |
203 if (m_storageAreaSync) | 213 if (m_storageAreaSync) |
204 m_storageAreaSync->scheduleClear(); | 214 m_storageAreaSync->scheduleClear(); |
205 StorageEventDispatcher::dispatch(String(), String(), String(), m_storageType
, m_securityOrigin.get(), frame); | 215 StorageEventDispatcher::dispatch(String(), String(), String(), m_storageType
, m_securityOrigin.get(), frame); |
| 216 return true; |
206 } | 217 } |
207 | 218 |
208 bool StorageAreaImpl::contains(const String& key, Frame*) const | 219 bool StorageAreaImpl::contains(const String& key, Frame*) const |
209 { | 220 { |
210 ASSERT(!m_isShutdown); | 221 ASSERT(!m_isShutdown); |
211 blockUntilImportComplete(); | 222 blockUntilImportComplete(); |
212 | 223 |
213 return m_storageMap->contains(key); | 224 return m_storageMap->contains(key); |
214 } | 225 } |
215 | 226 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 m_storageAreaSync->scheduleSync(); | 265 m_storageAreaSync->scheduleSync(); |
255 } | 266 } |
256 | 267 |
257 void StorageAreaImpl::blockUntilImportComplete() const | 268 void StorageAreaImpl::blockUntilImportComplete() const |
258 { | 269 { |
259 if (m_storageAreaSync) | 270 if (m_storageAreaSync) |
260 m_storageAreaSync->blockUntilImportComplete(); | 271 m_storageAreaSync->blockUntilImportComplete(); |
261 } | 272 } |
262 | 273 |
263 } | 274 } |
OLD | NEW |