Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: storage/StorageAreaImpl.cpp

Issue 155477: Dom Storage (webkit side) (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/WebCore/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 return m_storageMap->getItem(key); 121 return m_storageMap->getItem(key);
122 } 122 }
123 123
124 void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionC ode& ec, Frame* frame) 124 void StorageAreaImpl::setItem(const String& key, const String& value, ExceptionC ode& ec, Frame* frame)
125 { 125 {
126 ASSERT(!m_isShutdown); 126 ASSERT(!m_isShutdown);
127 ASSERT(!value.isNull()); 127 ASSERT(!value.isNull());
128 blockUntilImportComplete(); 128 blockUntilImportComplete();
129 129
130 if (frame->page()->settings()->privateBrowsingEnabled()) { 130 if (frame && frame->page()->settings()->privateBrowsingEnabled()) {
131 ec = QUOTA_EXCEEDED_ERR; 131 ec = QUOTA_EXCEEDED_ERR;
132 return; 132 return;
133 } 133 }
134 134
135 // FIXME: For LocalStorage where a disk quota will be enforced, here is wher e we need to do quota checking. 135 // FIXME: For LocalStorage where a disk quota will be enforced, here is wher e we need to do quota checking.
136 // If we decide to enforce a memory quota for SessionStorage, this is where we'd do that, also. 136 // If we decide to enforce a memory quota for SessionStorage, this is where we'd do that, also.
137 // if (<over quota>) { 137 // if (<over quota>) {
138 // ec = QUOTA_EXCEEDED_ERR; 138 // ec = QUOTA_EXCEEDED_ERR;
139 // return; 139 // return;
140 // } 140 // }
(...skipping 10 matching lines...) Expand all
151 m_storageAreaSync->scheduleItemForSync(key, value); 151 m_storageAreaSync->scheduleItemForSync(key, value);
152 dispatchStorageEvent(key, oldValue, value, frame); 152 dispatchStorageEvent(key, oldValue, value, frame);
153 } 153 }
154 } 154 }
155 155
156 void StorageAreaImpl::removeItem(const String& key, Frame* frame) 156 void StorageAreaImpl::removeItem(const String& key, Frame* frame)
157 { 157 {
158 ASSERT(!m_isShutdown); 158 ASSERT(!m_isShutdown);
159 blockUntilImportComplete(); 159 blockUntilImportComplete();
160 160
161 if (frame->page()->settings()->privateBrowsingEnabled()) 161 if (frame && frame->page()->settings()->privateBrowsingEnabled())
162 return; 162 return;
163 163
164 String oldValue; 164 String oldValue;
165 RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue); 165 RefPtr<StorageMap> newMap = m_storageMap->removeItem(key, oldValue);
166 if (newMap) 166 if (newMap)
167 m_storageMap = newMap.release(); 167 m_storageMap = newMap.release();
168 168
169 // Only notify the client if an item was actually removed 169 // Only notify the client if an item was actually removed
170 if (!oldValue.isNull()) { 170 if (!oldValue.isNull()) {
171 if (m_storageAreaSync) 171 if (m_storageAreaSync)
172 m_storageAreaSync->scheduleItemForSync(key, String()); 172 m_storageAreaSync->scheduleItemForSync(key, String());
173 dispatchStorageEvent(key, oldValue, String(), frame); 173 dispatchStorageEvent(key, oldValue, String(), frame);
174 } 174 }
175 } 175 }
176 176
177 void StorageAreaImpl::clear(Frame* frame) 177 void StorageAreaImpl::clear(Frame* frame)
178 { 178 {
179 ASSERT(!m_isShutdown); 179 ASSERT(!m_isShutdown);
180 blockUntilImportComplete(); 180 blockUntilImportComplete();
181 181
182 if (frame->page()->settings()->privateBrowsingEnabled()) 182 if (frame && frame->page()->settings()->privateBrowsingEnabled())
183 return; 183 return;
184 184
185 m_storageMap = StorageMap::create(); 185 m_storageMap = StorageMap::create();
186 186
187 if (m_storageAreaSync) 187 if (m_storageAreaSync)
188 m_storageAreaSync->scheduleClear(); 188 m_storageAreaSync->scheduleClear();
189 dispatchStorageEvent(String(), String(), String(), frame); 189 dispatchStorageEvent(String(), String(), String(), frame);
190 } 190 }
191 191
192 bool StorageAreaImpl::contains(const String& key) const 192 bool StorageAreaImpl::contains(const String& key) const
(...skipping 30 matching lines...) Expand all
223 if (m_storageAreaSync) 223 if (m_storageAreaSync)
224 m_storageAreaSync->blockUntilImportComplete(); 224 m_storageAreaSync->blockUntilImportComplete();
225 } 225 }
226 226
227 void StorageAreaImpl::dispatchStorageEvent(const String& key, const String& oldV alue, const String& newValue, Frame* sourceFrame) 227 void StorageAreaImpl::dispatchStorageEvent(const String& key, const String& oldV alue, const String& newValue, Frame* sourceFrame)
228 { 228 {
229 // We need to copy all relevant frames from every page to a vector since sen ding the event to one frame might mutate the frame tree 229 // We need to copy all relevant frames from every page to a vector since sen ding the event to one frame might mutate the frame tree
230 // of any given page in the group or mutate the page group itself. 230 // of any given page in the group or mutate the page group itself.
231 Vector<RefPtr<Frame> > frames; 231 Vector<RefPtr<Frame> > frames;
232 232
233 // TODO(jorlow): Make this work!
234 if (!sourceFrame)
235 return;
michaeln 2009/07/14 19:02:05 I realize this is temporary only until you resolve
jorlow 2009/07/14 19:12:50 Sure. Might as well.
236
233 // FIXME: When can this occur? 237 // FIXME: When can this occur?
234 Page* page = sourceFrame->page(); 238 Page* page = sourceFrame->page();
235 if (!page) 239 if (!page)
michaeln 2009/07/14 19:02:05 while your here... ditto for this test
jorlow 2009/07/14 19:12:50 k
236 return; 240 return;
237 241
238 if (m_storageType == SessionStorage) { 242 if (m_storageType == SessionStorage) {
239 // Send events only to our page. 243 // Send events only to our page.
240 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->tra verseNext()) { 244 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->tra verseNext()) {
241 if (frame->document()->securityOrigin()->equal(securityOrigin())) 245 if (frame->document()->securityOrigin()->equal(securityOrigin()))
242 frames.append(frame); 246 frames.append(frame);
243 } 247 }
244 248
245 for (unsigned i = 0; i < frames.size(); ++i) 249 for (unsigned i = 0; i < frames.size(); ++i)
(...skipping 11 matching lines...) Expand all
257 261
258 for (unsigned i = 0; i < frames.size(); ++i) 262 for (unsigned i = 0; i < frames.size(); ++i)
259 frames[i]->document()->dispatchWindowEvent(StorageEvent::create(even tNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->documen tURI(), sourceFrame->domWindow(), frames[i]->domWindow()->localStorage())); 263 frames[i]->document()->dispatchWindowEvent(StorageEvent::create(even tNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->documen tURI(), sourceFrame->domWindow(), frames[i]->domWindow()->localStorage()));
260 } 264 }
261 } 265 }
262 266
263 } 267 }
264 268
265 #endif // ENABLE(DOM_STORAGE) 269 #endif // ENABLE(DOM_STORAGE)
266 270
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698