| 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 10 matching lines...) Expand all Loading... |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "StorageAreaProxy.h" | 28 #include "StorageAreaProxy.h" |
| 29 | 29 |
| 30 #include "StorageNamespaceProxy.h" | 30 #include "StorageNamespaceProxy.h" |
| 31 #include "bindings/v8/ExceptionMessages.h" | |
| 32 #include "bindings/v8/ExceptionState.h" | 31 #include "bindings/v8/ExceptionState.h" |
| 33 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 34 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/events/ThreadLocalEventNames.h" | 34 #include "core/events/ThreadLocalEventNames.h" |
| 36 #include "core/inspector/InspectorInstrumentation.h" | 35 #include "core/inspector/InspectorInstrumentation.h" |
| 37 #include "core/frame/DOMWindow.h" | 36 #include "core/frame/DOMWindow.h" |
| 38 #include "core/frame/Frame.h" | 37 #include "core/frame/Frame.h" |
| 39 #include "core/page/Page.h" | 38 #include "core/page/Page.h" |
| 40 #include "core/page/PageGroup.h" | 39 #include "core/page/PageGroup.h" |
| 41 #include "core/storage/Storage.h" | 40 #include "core/storage/Storage.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 { | 58 { |
| 60 } | 59 } |
| 61 | 60 |
| 62 StorageAreaProxy::~StorageAreaProxy() | 61 StorageAreaProxy::~StorageAreaProxy() |
| 63 { | 62 { |
| 64 } | 63 } |
| 65 | 64 |
| 66 unsigned StorageAreaProxy::length(ExceptionState& exceptionState, Frame* frame) | 65 unsigned StorageAreaProxy::length(ExceptionState& exceptionState, Frame* frame) |
| 67 { | 66 { |
| 68 if (!canAccessStorage(frame)) { | 67 if (!canAccessStorage(frame)) { |
| 69 exceptionState.throwSecurityError(ExceptionMessages::failedToGet("length
", "Storage", "access is denied for this document.")); | 68 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 70 return 0; | 69 return 0; |
| 71 } | 70 } |
| 72 return m_storageArea->length(); | 71 return m_storageArea->length(); |
| 73 } | 72 } |
| 74 | 73 |
| 75 String StorageAreaProxy::key(unsigned index, ExceptionState& exceptionState, Fra
me* frame) | 74 String StorageAreaProxy::key(unsigned index, ExceptionState& exceptionState, Fra
me* frame) |
| 76 { | 75 { |
| 77 if (!canAccessStorage(frame)) { | 76 if (!canAccessStorage(frame)) { |
| 78 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("le
ngth", "Storage", "access is denied for this document.")); | 77 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 79 return String(); | 78 return String(); |
| 80 } | 79 } |
| 81 return m_storageArea->key(index); | 80 return m_storageArea->key(index); |
| 82 } | 81 } |
| 83 | 82 |
| 84 String StorageAreaProxy::getItem(const String& key, ExceptionState& exceptionSta
te, Frame* frame) | 83 String StorageAreaProxy::getItem(const String& key, ExceptionState& exceptionSta
te, Frame* frame) |
| 85 { | 84 { |
| 86 if (!canAccessStorage(frame)) { | 85 if (!canAccessStorage(frame)) { |
| 87 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("ge
tItem", "Storage", "access is denied for this document.")); | 86 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 88 return String(); | 87 return String(); |
| 89 } | 88 } |
| 90 return m_storageArea->getItem(key); | 89 return m_storageArea->getItem(key); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void StorageAreaProxy::setItem(const String& key, const String& value, Exception
State& exceptionState, Frame* frame) | 92 void StorageAreaProxy::setItem(const String& key, const String& value, Exception
State& exceptionState, Frame* frame) |
| 94 { | 93 { |
| 95 if (!canAccessStorage(frame)) { | 94 if (!canAccessStorage(frame)) { |
| 96 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("se
tItem", "Storage", "access is denied for this document.")); | 95 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 97 return; | 96 return; |
| 98 } | 97 } |
| 99 blink::WebStorageArea::Result result = blink::WebStorageArea::ResultOK; | 98 blink::WebStorageArea::Result result = blink::WebStorageArea::ResultOK; |
| 100 m_storageArea->setItem(key, value, frame->document()->url(), result); | 99 m_storageArea->setItem(key, value, frame->document()->url(), result); |
| 101 if (result != blink::WebStorageArea::ResultOK) | 100 if (result != blink::WebStorageArea::ResultOK) |
| 102 exceptionState.throwDOMException(QuotaExceededError, ExceptionMessages::
failedToExecute("setItem", "Storage", "Setting the value of '" + key + "' exceed
ed the quota.")); | 101 exceptionState.throwDOMException(QuotaExceededError, "Setting the value
of '" + key + "' exceeded the quota."); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void StorageAreaProxy::removeItem(const String& key, ExceptionState& exceptionSt
ate, Frame* frame) | 104 void StorageAreaProxy::removeItem(const String& key, ExceptionState& exceptionSt
ate, Frame* frame) |
| 106 { | 105 { |
| 107 if (!canAccessStorage(frame)) { | 106 if (!canAccessStorage(frame)) { |
| 108 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("re
moveItem", "Storage", "access is denied for this document.")); | 107 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 109 return; | 108 return; |
| 110 } | 109 } |
| 111 m_storageArea->removeItem(key, frame->document()->url()); | 110 m_storageArea->removeItem(key, frame->document()->url()); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void StorageAreaProxy::clear(ExceptionState& exceptionState, Frame* frame) | 113 void StorageAreaProxy::clear(ExceptionState& exceptionState, Frame* frame) |
| 115 { | 114 { |
| 116 if (!canAccessStorage(frame)) { | 115 if (!canAccessStorage(frame)) { |
| 117 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("cl
ear", "Storage", "access is denied for this document.")); | 116 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 118 return; | 117 return; |
| 119 } | 118 } |
| 120 m_storageArea->clear(frame->document()->url()); | 119 m_storageArea->clear(frame->document()->url()); |
| 121 } | 120 } |
| 122 | 121 |
| 123 bool StorageAreaProxy::contains(const String& key, ExceptionState& exceptionStat
e, Frame* frame) | 122 bool StorageAreaProxy::contains(const String& key, ExceptionState& exceptionStat
e, Frame* frame) |
| 124 { | 123 { |
| 125 if (!canAccessStorage(frame)) { | 124 if (!canAccessStorage(frame)) { |
| 126 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("co
ntains", "Storage", "access is denied for this document.")); | 125 exceptionState.throwSecurityError("access is denied for this document.")
; |
| 127 return false; | 126 return false; |
| 128 } | 127 } |
| 129 return !getItem(key, exceptionState, frame).isNull(); | 128 return !getItem(key, exceptionState, frame).isNull(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 bool StorageAreaProxy::canAccessStorage(Frame* frame) | 131 bool StorageAreaProxy::canAccessStorage(Frame* frame) |
| 133 { | 132 { |
| 134 if (!frame || !frame->page()) | 133 if (!frame || !frame->page()) |
| 135 return false; | 134 return false; |
| 136 if (m_canAccessStorageCachedFrame == frame) | 135 if (m_canAccessStorageCachedFrame == frame) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 192 } |
| 194 | 193 |
| 195 bool StorageAreaProxy::isEventSource(Storage* storage, blink::WebStorageArea* so
urceAreaInstance) | 194 bool StorageAreaProxy::isEventSource(Storage* storage, blink::WebStorageArea* so
urceAreaInstance) |
| 196 { | 195 { |
| 197 ASSERT(storage); | 196 ASSERT(storage); |
| 198 StorageAreaProxy* areaProxy = static_cast<StorageAreaProxy*>(storage->area()
); | 197 StorageAreaProxy* areaProxy = static_cast<StorageAreaProxy*>(storage->area()
); |
| 199 return areaProxy->m_storageArea == sourceAreaInstance; | 198 return areaProxy->m_storageArea == sourceAreaInstance; |
| 200 } | 199 } |
| 201 | 200 |
| 202 } // namespace WebCore | 201 } // namespace WebCore |
| OLD | NEW |