| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2009 Google Inc. All Rights Reserved. |
| 3 * (C) 2008 Apple Inc. | 3 * (C) 2008 Apple Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "core/storage/Storage.h" | 38 #include "core/storage/Storage.h" |
| 39 #include "core/storage/StorageEvent.h" | 39 #include "core/storage/StorageEvent.h" |
| 40 #include "core/storage/StorageNamespace.h" | 40 #include "core/storage/StorageNamespace.h" |
| 41 #include "platform/weborigin/SecurityOrigin.h" | 41 #include "platform/weborigin/SecurityOrigin.h" |
| 42 #include "public/platform/WebStorageArea.h" | 42 #include "public/platform/WebStorageArea.h" |
| 43 #include "public/platform/WebString.h" | 43 #include "public/platform/WebString.h" |
| 44 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 StorageArea::StorageArea(PassOwnPtr<blink::WebStorageArea> storageArea, StorageT
ype storageType) | 48 PassOwnPtrWillBeRawPtr<StorageArea> StorageArea::create(PassOwnPtr<WebStorageAre
a> storageArea, StorageType storageType) |
| 49 { |
| 50 return adoptPtrWillBeNoop(new StorageArea(storageArea, storageType)); |
| 51 } |
| 52 |
| 53 StorageArea::StorageArea(PassOwnPtr<WebStorageArea> storageArea, StorageType sto
rageType) |
| 49 : m_storageArea(storageArea) | 54 : m_storageArea(storageArea) |
| 50 , m_storageType(storageType) | 55 , m_storageType(storageType) |
| 56 , m_canAccessStorageCachedFrame(nullptr) |
| 51 , m_canAccessStorageCachedResult(false) | 57 , m_canAccessStorageCachedResult(false) |
| 52 , m_canAccessStorageCachedFrame(0) | |
| 53 { | 58 { |
| 54 } | 59 } |
| 55 | 60 |
| 56 StorageArea::~StorageArea() | 61 StorageArea::~StorageArea() |
| 57 { | 62 { |
| 58 } | 63 } |
| 59 | 64 |
| 65 void StorageArea::trace(Visitor* visitor) |
| 66 { |
| 67 visitor->trace(m_canAccessStorageCachedFrame); |
| 68 } |
| 69 |
| 60 unsigned StorageArea::length(ExceptionState& exceptionState, LocalFrame* frame) | 70 unsigned StorageArea::length(ExceptionState& exceptionState, LocalFrame* frame) |
| 61 { | 71 { |
| 62 if (!canAccessStorage(frame)) { | 72 if (!canAccessStorage(frame)) { |
| 63 exceptionState.throwSecurityError("access is denied for this document.")
; | 73 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 64 return 0; | 74 return 0; |
| 65 } | 75 } |
| 66 return m_storageArea->length(); | 76 return m_storageArea->length(); |
| 67 } | 77 } |
| 68 | 78 |
| 69 String StorageArea::key(unsigned index, ExceptionState& exceptionState, LocalFra
me* frame) | 79 String StorageArea::key(unsigned index, ExceptionState& exceptionState, LocalFra
me* frame) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 } | 93 } |
| 84 return m_storageArea->getItem(key); | 94 return m_storageArea->getItem(key); |
| 85 } | 95 } |
| 86 | 96 |
| 87 void StorageArea::setItem(const String& key, const String& value, ExceptionState
& exceptionState, LocalFrame* frame) | 97 void StorageArea::setItem(const String& key, const String& value, ExceptionState
& exceptionState, LocalFrame* frame) |
| 88 { | 98 { |
| 89 if (!canAccessStorage(frame)) { | 99 if (!canAccessStorage(frame)) { |
| 90 exceptionState.throwSecurityError("access is denied for this document.")
; | 100 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 91 return; | 101 return; |
| 92 } | 102 } |
| 93 blink::WebStorageArea::Result result = blink::WebStorageArea::ResultOK; | 103 WebStorageArea::Result result = WebStorageArea::ResultOK; |
| 94 m_storageArea->setItem(key, value, frame->document()->url(), result); | 104 m_storageArea->setItem(key, value, frame->document()->url(), result); |
| 95 if (result != blink::WebStorageArea::ResultOK) | 105 if (result != WebStorageArea::ResultOK) |
| 96 exceptionState.throwDOMException(QuotaExceededError, "Setting the value
of '" + key + "' exceeded the quota."); | 106 exceptionState.throwDOMException(QuotaExceededError, "Setting the value
of '" + key + "' exceeded the quota."); |
| 97 } | 107 } |
| 98 | 108 |
| 99 void StorageArea::removeItem(const String& key, ExceptionState& exceptionState,
LocalFrame* frame) | 109 void StorageArea::removeItem(const String& key, ExceptionState& exceptionState,
LocalFrame* frame) |
| 100 { | 110 { |
| 101 if (!canAccessStorage(frame)) { | 111 if (!canAccessStorage(frame)) { |
| 102 exceptionState.throwSecurityError("access is denied for this document.")
; | 112 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 103 return; | 113 return; |
| 104 } | 114 } |
| 105 m_storageArea->removeItem(key, frame->document()->url()); | 115 m_storageArea->removeItem(key, frame->document()->url()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 133 m_canAccessStorageCachedFrame = frame; | 143 m_canAccessStorageCachedFrame = frame; |
| 134 m_canAccessStorageCachedResult = result; | 144 m_canAccessStorageCachedResult = result; |
| 135 return result; | 145 return result; |
| 136 } | 146 } |
| 137 | 147 |
| 138 size_t StorageArea::memoryBytesUsedByCache() | 148 size_t StorageArea::memoryBytesUsedByCache() |
| 139 { | 149 { |
| 140 return m_storageArea->memoryBytesUsedByCache(); | 150 return m_storageArea->memoryBytesUsedByCache(); |
| 141 } | 151 } |
| 142 | 152 |
| 143 void StorageArea::dispatchLocalStorageEvent(const String& key, const String& old
Value, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pageU
RL, blink::WebStorageArea* sourceAreaInstance, bool originatedInProcess) | 153 void StorageArea::dispatchLocalStorageEvent(const String& key, const String& old
Value, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pageU
RL, WebStorageArea* sourceAreaInstance, bool originatedInProcess) |
| 144 { | 154 { |
| 145 // FIXME: This looks suspicious. Why doesn't this use allPages instead? | 155 // FIXME: This looks suspicious. Why doesn't this use allPages instead? |
| 146 const HashSet<Page*>& pages = Page::ordinaryPages(); | 156 const HashSet<Page*>& pages = Page::ordinaryPages(); |
| 147 for (HashSet<Page*>::const_iterator it = pages.begin(); it != pages.end(); +
+it) { | 157 for (HashSet<Page*>::const_iterator it = pages.begin(); it != pages.end(); +
+it) { |
| 148 for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree().tra
verseNext()) { | 158 for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree().tra
verseNext()) { |
| 149 // FIXME: We do not yet have a way to dispatch events to out-of-proc
ess frames. | 159 // FIXME: We do not yet have a way to dispatch events to out-of-proc
ess frames. |
| 150 if (!frame->isLocalFrame()) | 160 if (!frame->isLocalFrame()) |
| 151 continue; | 161 continue; |
| 152 Storage* storage = frame->domWindow()->optionalLocalStorage(); | 162 Storage* storage = frame->domWindow()->optionalLocalStorage(); |
| 153 if (storage && toLocalFrame(frame)->document()->securityOrigin()->ca
nAccess(securityOrigin) && !isEventSource(storage, sourceAreaInstance)) | 163 if (storage && toLocalFrame(frame)->document()->securityOrigin()->ca
nAccess(securityOrigin) && !isEventSource(storage, sourceAreaInstance)) |
| 154 frame->domWindow()->enqueueWindowEvent(StorageEvent::create(Even
tTypeNames::storage, key, oldValue, newValue, pageURL, storage)); | 164 frame->domWindow()->enqueueWindowEvent(StorageEvent::create(Even
tTypeNames::storage, key, oldValue, newValue, pageURL, storage)); |
| 155 } | 165 } |
| 156 InspectorInstrumentation::didDispatchDOMStorageEvent(*it, key, oldValue,
newValue, LocalStorage, securityOrigin); | 166 InspectorInstrumentation::didDispatchDOMStorageEvent(*it, key, oldValue,
newValue, LocalStorage, securityOrigin); |
| 157 } | 167 } |
| 158 } | 168 } |
| 159 | 169 |
| 160 static Page* findPageWithSessionStorageNamespace(const blink::WebStorageNamespac
e& sessionNamespace) | 170 static Page* findPageWithSessionStorageNamespace(const WebStorageNamespace& sess
ionNamespace) |
| 161 { | 171 { |
| 162 // FIXME: This looks suspicious. Why doesn't this use allPages instead? | 172 // FIXME: This looks suspicious. Why doesn't this use allPages instead? |
| 163 const HashSet<Page*>& pages = Page::ordinaryPages(); | 173 const HashSet<Page*>& pages = Page::ordinaryPages(); |
| 164 for (HashSet<Page*>::const_iterator it = pages.begin(); it != pages.end(); +
+it) { | 174 for (HashSet<Page*>::const_iterator it = pages.begin(); it != pages.end(); +
+it) { |
| 165 const bool dontCreateIfMissing = false; | 175 const bool dontCreateIfMissing = false; |
| 166 StorageNamespace* storageNamespace = (*it)->sessionStorage(dontCreateIfM
issing); | 176 StorageNamespace* storageNamespace = (*it)->sessionStorage(dontCreateIfM
issing); |
| 167 if (storageNamespace && storageNamespace->isSameNamespace(sessionNamespa
ce)) | 177 if (storageNamespace && storageNamespace->isSameNamespace(sessionNamespa
ce)) |
| 168 return *it; | 178 return *it; |
| 169 } | 179 } |
| 170 return 0; | 180 return 0; |
| 171 } | 181 } |
| 172 | 182 |
| 173 void StorageArea::dispatchSessionStorageEvent(const String& key, const String& o
ldValue, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pag
eURL, const blink::WebStorageNamespace& sessionNamespace, blink::WebStorageArea*
sourceAreaInstance, bool originatedInProcess) | 183 void StorageArea::dispatchSessionStorageEvent(const String& key, const String& o
ldValue, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pag
eURL, const WebStorageNamespace& sessionNamespace, WebStorageArea* sourceAreaIns
tance, bool originatedInProcess) |
| 174 { | 184 { |
| 175 Page* page = findPageWithSessionStorageNamespace(sessionNamespace); | 185 Page* page = findPageWithSessionStorageNamespace(sessionNamespace); |
| 176 if (!page) | 186 if (!page) |
| 177 return; | 187 return; |
| 178 | 188 |
| 179 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverse
Next()) { | 189 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverse
Next()) { |
| 180 // FIXME: We do not yet have a way to dispatch events to out-of-process
frames. | 190 // FIXME: We do not yet have a way to dispatch events to out-of-process
frames. |
| 181 if (!frame->isLocalFrame()) | 191 if (!frame->isLocalFrame()) |
| 182 continue; | 192 continue; |
| 183 Storage* storage = frame->domWindow()->optionalSessionStorage(); | 193 Storage* storage = frame->domWindow()->optionalSessionStorage(); |
| 184 if (storage && toLocalFrame(frame)->document()->securityOrigin()->canAcc
ess(securityOrigin) && !isEventSource(storage, sourceAreaInstance)) | 194 if (storage && toLocalFrame(frame)->document()->securityOrigin()->canAcc
ess(securityOrigin) && !isEventSource(storage, sourceAreaInstance)) |
| 185 frame->domWindow()->enqueueWindowEvent(StorageEvent::create(EventTyp
eNames::storage, key, oldValue, newValue, pageURL, storage)); | 195 frame->domWindow()->enqueueWindowEvent(StorageEvent::create(EventTyp
eNames::storage, key, oldValue, newValue, pageURL, storage)); |
| 186 } | 196 } |
| 187 InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, ne
wValue, SessionStorage, securityOrigin); | 197 InspectorInstrumentation::didDispatchDOMStorageEvent(page, key, oldValue, ne
wValue, SessionStorage, securityOrigin); |
| 188 } | 198 } |
| 189 | 199 |
| 190 bool StorageArea::isEventSource(Storage* storage, blink::WebStorageArea* sourceA
reaInstance) | 200 bool StorageArea::isEventSource(Storage* storage, WebStorageArea* sourceAreaInst
ance) |
| 191 { | 201 { |
| 192 ASSERT(storage); | 202 ASSERT(storage); |
| 193 StorageArea* area = storage->area(); | 203 StorageArea* area = storage->area(); |
| 194 return area->m_storageArea == sourceAreaInstance; | 204 return area->m_storageArea == sourceAreaInstance; |
| 195 } | 205 } |
| 196 | 206 |
| 197 } // namespace blink | 207 } // namespace blink |
| OLD | NEW |