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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
48 PassOwnPtrWillBeRawPtr<StorageArea> StorageArea::create(PassOwnPtr<WebStorageAre
a> storageArea, StorageType storageType) | 48 PassOwnPtrWillBeRawPtr<StorageArea> StorageArea::create(PassOwnPtr<WebStorageAre
a> storageArea, StorageType storageType) |
49 { | 49 { |
50 return adoptPtrWillBeNoop(new StorageArea(storageArea, storageType)); | 50 return adoptPtrWillBeNoop(new StorageArea(storageArea, storageType)); |
51 } | 51 } |
52 | 52 |
53 StorageArea::StorageArea(PassOwnPtr<WebStorageArea> storageArea, StorageType sto
rageType) | 53 StorageArea::StorageArea(PassOwnPtr<WebStorageArea> storageArea, StorageType sto
rageType) |
54 : m_storageArea(storageArea) | 54 : FrameDestructionObserver(nullptr) |
| 55 , m_storageArea(storageArea) |
55 , m_storageType(storageType) | 56 , m_storageType(storageType) |
56 , m_canAccessStorageCachedFrame(nullptr) | |
57 , m_canAccessStorageCachedResult(false) | 57 , m_canAccessStorageCachedResult(false) |
58 { | 58 { |
59 } | 59 } |
60 | 60 |
61 StorageArea::~StorageArea() | 61 StorageArea::~StorageArea() |
62 { | 62 { |
63 } | 63 } |
64 | 64 |
65 void StorageArea::trace(Visitor* visitor) | 65 void StorageArea::trace(Visitor* visitor) |
66 { | 66 { |
67 visitor->trace(m_canAccessStorageCachedFrame); | 67 FrameDestructionObserver::trace(visitor); |
68 } | 68 } |
69 | 69 |
70 unsigned StorageArea::length(ExceptionState& exceptionState, LocalFrame* frame) | 70 unsigned StorageArea::length(ExceptionState& exceptionState, LocalFrame* frame) |
71 { | 71 { |
72 if (!canAccessStorage(frame)) { | 72 if (!canAccessStorage(frame)) { |
73 exceptionState.throwSecurityError("access is denied for this document.")
; | 73 exceptionState.throwSecurityError("access is denied for this document.")
; |
74 return 0; | 74 return 0; |
75 } | 75 } |
76 return m_storageArea->length(); | 76 return m_storageArea->length(); |
77 } | 77 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 exceptionState.throwSecurityError("access is denied for this document.")
; | 130 exceptionState.throwSecurityError("access is denied for this document.")
; |
131 return false; | 131 return false; |
132 } | 132 } |
133 return !getItem(key, exceptionState, frame).isNull(); | 133 return !getItem(key, exceptionState, frame).isNull(); |
134 } | 134 } |
135 | 135 |
136 bool StorageArea::canAccessStorage(LocalFrame* frame) | 136 bool StorageArea::canAccessStorage(LocalFrame* frame) |
137 { | 137 { |
138 if (!frame || !frame->page()) | 138 if (!frame || !frame->page()) |
139 return false; | 139 return false; |
140 if (m_canAccessStorageCachedFrame == frame) | 140 |
| 141 // FrameDestructionObserver is used to safely keep the cached |
| 142 // reference to the LocalFrame. Should the LocalFrame die before |
| 143 // this StorageArea does, that cached reference will be cleared. |
| 144 if (m_frame == frame) |
141 return m_canAccessStorageCachedResult; | 145 return m_canAccessStorageCachedResult; |
142 bool result = frame->page()->storageClient().canAccessStorage(frame, m_stora
geType); | 146 bool result = frame->page()->storageClient().canAccessStorage(frame, m_stora
geType); |
143 m_canAccessStorageCachedFrame = frame; | 147 // Move attention to the new LocalFrame. |
| 148 observeFrame(frame); |
144 m_canAccessStorageCachedResult = result; | 149 m_canAccessStorageCachedResult = result; |
145 return result; | 150 return result; |
146 } | 151 } |
147 | 152 |
148 size_t StorageArea::memoryBytesUsedByCache() | 153 size_t StorageArea::memoryBytesUsedByCache() |
149 { | 154 { |
150 return m_storageArea->memoryBytesUsedByCache(); | 155 return m_storageArea->memoryBytesUsedByCache(); |
151 } | 156 } |
152 | 157 |
153 void StorageArea::dispatchLocalStorageEvent(const String& key, const String& old
Value, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pageU
RL, WebStorageArea* sourceAreaInstance, bool originatedInProcess) | 158 void StorageArea::dispatchLocalStorageEvent(const String& key, const String& old
Value, const String& newValue, SecurityOrigin* securityOrigin, const KURL& pageU
RL, WebStorageArea* sourceAreaInstance, bool originatedInProcess) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 203 } |
199 | 204 |
200 bool StorageArea::isEventSource(Storage* storage, WebStorageArea* sourceAreaInst
ance) | 205 bool StorageArea::isEventSource(Storage* storage, WebStorageArea* sourceAreaInst
ance) |
201 { | 206 { |
202 ASSERT(storage); | 207 ASSERT(storage); |
203 StorageArea* area = storage->area(); | 208 StorageArea* area = storage->area(); |
204 return area->m_storageArea == sourceAreaInstance; | 209 return area->m_storageArea == sourceAreaInstance; |
205 } | 210 } |
206 | 211 |
207 } // namespace blink | 212 } // namespace blink |
OLD | NEW |