| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
| 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 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void InspectorDOMStorageAgent::disable(ErrorString*) | 100 void InspectorDOMStorageAgent::disable(ErrorString*) |
| 101 { | 101 { |
| 102 if (!m_isEnabled) | 102 if (!m_isEnabled) |
| 103 return; | 103 return; |
| 104 m_isEnabled = false; | 104 m_isEnabled = false; |
| 105 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, false); | 105 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, false); |
| 106 if (StorageNamespaceController* controller = StorageNamespaceController::fro
m(m_page)) | 106 if (StorageNamespaceController* controller = StorageNamespaceController::fro
m(m_page)) |
| 107 controller->setInspectorAgent(nullptr); | 107 controller->setInspectorAgent(nullptr); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void InspectorDOMStorageAgent::getDOMStorageItems(ErrorString* errorString, cons
t RefPtr<JSONObject>& storageId, RefPtr<protocol::TypeBuilder::Array<protocol::T
ypeBuilder::Array<String>>>& items) | 110 void InspectorDOMStorageAgent::getDOMStorageItems(ErrorString* errorString, Pass
OwnPtr<protocol::DOMStorage::StorageId> storageId, OwnPtr<protocol::Array<protoc
ol::Array<String>>>* items) |
| 111 { | 111 { |
| 112 LocalFrame* frame; | 112 LocalFrame* frame; |
| 113 StorageArea* storageArea = findStorageArea(errorString, storageId, frame); | 113 StorageArea* storageArea = findStorageArea(errorString, storageId, frame); |
| 114 if (!storageArea) | 114 if (!storageArea) |
| 115 return; | 115 return; |
| 116 | 116 |
| 117 RefPtr<protocol::TypeBuilder::Array<protocol::TypeBuilder::Array<String>>> s
torageItems = protocol::TypeBuilder::Array<protocol::TypeBuilder::Array<String>>
::create(); | 117 OwnPtr<protocol::Array<protocol::Array<String>>> storageItems = protocol::Ar
ray<protocol::Array<String>>::create(); |
| 118 | 118 |
| 119 TrackExceptionState exceptionState; | 119 TrackExceptionState exceptionState; |
| 120 for (unsigned i = 0; i < storageArea->length(exceptionState, frame); ++i) { | 120 for (unsigned i = 0; i < storageArea->length(exceptionState, frame); ++i) { |
| 121 String name(storageArea->key(i, exceptionState, frame)); | 121 String name(storageArea->key(i, exceptionState, frame)); |
| 122 if (hadException(exceptionState, errorString)) | 122 if (hadException(exceptionState, errorString)) |
| 123 return; | 123 return; |
| 124 String value(storageArea->getItem(name, exceptionState, frame)); | 124 String value(storageArea->getItem(name, exceptionState, frame)); |
| 125 if (hadException(exceptionState, errorString)) | 125 if (hadException(exceptionState, errorString)) |
| 126 return; | 126 return; |
| 127 RefPtr<protocol::TypeBuilder::Array<String>> entry = protocol::TypeBuild
er::Array<String>::create(); | 127 OwnPtr<protocol::Array<String>> entry = protocol::Array<String>::create(
); |
| 128 entry->addItem(name); | 128 entry->addItem(name); |
| 129 entry->addItem(value); | 129 entry->addItem(value); |
| 130 storageItems->addItem(entry); | 130 storageItems->addItem(entry.release()); |
| 131 } | 131 } |
| 132 items = storageItems.release(); | 132 *items = storageItems.release(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 static String toErrorString(ExceptionState& exceptionState) | 135 static String toErrorString(ExceptionState& exceptionState) |
| 136 { | 136 { |
| 137 if (exceptionState.hadException()) | 137 if (exceptionState.hadException()) |
| 138 return DOMException::getErrorName(exceptionState.code()); | 138 return DOMException::getErrorName(exceptionState.code()); |
| 139 return ""; | 139 return ""; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString* errorString, const
RefPtr<JSONObject>& storageId, const String& key, const String& value) | 142 void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString* errorString, PassO
wnPtr<protocol::DOMStorage::StorageId> storageId, const String& key, const Strin
g& value) |
| 143 { | 143 { |
| 144 LocalFrame* frame; | 144 LocalFrame* frame; |
| 145 StorageArea* storageArea = findStorageArea(0, storageId, frame); | 145 StorageArea* storageArea = findStorageArea(0, storageId, frame); |
| 146 if (!storageArea) { | 146 if (!storageArea) { |
| 147 *errorString = "Storage not found"; | 147 *errorString = "Storage not found"; |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 TrackExceptionState exceptionState; | 151 TrackExceptionState exceptionState; |
| 152 storageArea->setItem(key, value, exceptionState, frame); | 152 storageArea->setItem(key, value, exceptionState, frame); |
| 153 *errorString = toErrorString(exceptionState); | 153 *errorString = toErrorString(exceptionState); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void InspectorDOMStorageAgent::removeDOMStorageItem(ErrorString* errorString, co
nst RefPtr<JSONObject>& storageId, const String& key) | 156 void InspectorDOMStorageAgent::removeDOMStorageItem(ErrorString* errorString, Pa
ssOwnPtr<protocol::DOMStorage::StorageId> storageId, const String& key) |
| 157 { | 157 { |
| 158 LocalFrame* frame; | 158 LocalFrame* frame; |
| 159 StorageArea* storageArea = findStorageArea(0, storageId, frame); | 159 StorageArea* storageArea = findStorageArea(0, storageId, frame); |
| 160 if (!storageArea) { | 160 if (!storageArea) { |
| 161 *errorString = "Storage not found"; | 161 *errorString = "Storage not found"; |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 TrackExceptionState exceptionState; | 165 TrackExceptionState exceptionState; |
| 166 storageArea->removeItem(key, exceptionState, frame); | 166 storageArea->removeItem(key, exceptionState, frame); |
| 167 *errorString = toErrorString(exceptionState); | 167 *errorString = toErrorString(exceptionState); |
| 168 } | 168 } |
| 169 | 169 |
| 170 PassRefPtr<protocol::TypeBuilder::DOMStorage::StorageId> InspectorDOMStorageAgen
t::storageId(SecurityOrigin* securityOrigin, bool isLocalStorage) | 170 PassOwnPtr<protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::storageId(
SecurityOrigin* securityOrigin, bool isLocalStorage) |
| 171 { | 171 { |
| 172 return protocol::TypeBuilder::DOMStorage::StorageId::create() | 172 return protocol::DOMStorage::StorageId::create() |
| 173 .setSecurityOrigin(securityOrigin->toRawString()) | 173 .setSecurityOrigin(securityOrigin->toRawString()) |
| 174 .setIsLocalStorage(isLocalStorage).release(); | 174 .setIsLocalStorage(isLocalStorage).build(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, con
st String& oldValue, const String& newValue, StorageType storageType, SecurityOr
igin* securityOrigin) | 177 void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, con
st String& oldValue, const String& newValue, StorageType storageType, SecurityOr
igin* securityOrigin) |
| 178 { | 178 { |
| 179 if (!frontend()) | 179 if (!frontend()) |
| 180 return; | 180 return; |
| 181 | 181 |
| 182 RefPtr<protocol::TypeBuilder::DOMStorage::StorageId> id = storageId(security
Origin, storageType == LocalStorage); | 182 OwnPtr<protocol::DOMStorage::StorageId> id = storageId(securityOrigin, stora
geType == LocalStorage); |
| 183 | 183 |
| 184 if (key.isNull()) | 184 if (key.isNull()) |
| 185 frontend()->domStorageItemsCleared(id); | 185 frontend()->domStorageItemsCleared(id.release()); |
| 186 else if (newValue.isNull()) | 186 else if (newValue.isNull()) |
| 187 frontend()->domStorageItemRemoved(id, key); | 187 frontend()->domStorageItemRemoved(id.release(), key); |
| 188 else if (oldValue.isNull()) | 188 else if (oldValue.isNull()) |
| 189 frontend()->domStorageItemAdded(id, key, newValue); | 189 frontend()->domStorageItemAdded(id.release(), key, newValue); |
| 190 else | 190 else |
| 191 frontend()->domStorageItemUpdated(id, key, oldValue, newValue); | 191 frontend()->domStorageItemUpdated(id.release(), key, oldValue, newValue)
; |
| 192 } | 192 } |
| 193 | 193 |
| 194 StorageArea* InspectorDOMStorageAgent::findStorageArea(ErrorString* errorString,
const RefPtr<JSONObject>& storageId, LocalFrame*& targetFrame) | 194 StorageArea* InspectorDOMStorageAgent::findStorageArea(ErrorString* errorString,
PassOwnPtr<protocol::DOMStorage::StorageId> storageId, LocalFrame*& targetFrame
) |
| 195 { | 195 { |
| 196 String securityOrigin; | 196 if (!storageId->hasSecurityOrigin() || !storageId->hasIsLocalStorage()) { |
| 197 bool isLocalStorage = false; | |
| 198 bool success = storageId->getString("securityOrigin", &securityOrigin); | |
| 199 if (success) | |
| 200 success = storageId->getBoolean("isLocalStorage", &isLocalStorage); | |
| 201 if (!success) { | |
| 202 if (errorString) | 197 if (errorString) |
| 203 *errorString = "Invalid storageId format"; | 198 *errorString = "Invalid storageId format"; |
| 204 return nullptr; | 199 return nullptr; |
| 205 } | 200 } |
| 206 | 201 |
| 202 String securityOrigin = storageId->getSecurityOrigin(); |
| 203 bool isLocalStorage = storageId->getIsLocalStorage(); |
| 204 |
| 207 if (!m_page->mainFrame()->isLocalFrame()) | 205 if (!m_page->mainFrame()->isLocalFrame()) |
| 208 return nullptr; | 206 return nullptr; |
| 209 | 207 |
| 210 OwnPtrWillBeRawPtr<InspectedFrames> inspectedFrames = InspectedFrames::creat
e(m_page->deprecatedLocalMainFrame()); | 208 OwnPtrWillBeRawPtr<InspectedFrames> inspectedFrames = InspectedFrames::creat
e(m_page->deprecatedLocalMainFrame()); |
| 211 LocalFrame* frame = inspectedFrames->frameWithSecurityOrigin(securityOrigin)
; | 209 LocalFrame* frame = inspectedFrames->frameWithSecurityOrigin(securityOrigin)
; |
| 212 if (!frame) { | 210 if (!frame) { |
| 213 if (errorString) | 211 if (errorString) |
| 214 *errorString = "LocalFrame not found for the given security origin"; | 212 *errorString = "LocalFrame not found for the given security origin"; |
| 215 return nullptr; | 213 return nullptr; |
| 216 } | 214 } |
| 217 targetFrame = frame; | 215 targetFrame = frame; |
| 218 | 216 |
| 219 if (isLocalStorage) | 217 if (isLocalStorage) |
| 220 return StorageNamespace::localStorageArea(frame->document()->securityOri
gin()); | 218 return StorageNamespace::localStorageArea(frame->document()->securityOri
gin()); |
| 221 StorageNamespace* sessionStorage = StorageNamespaceController::from(m_page)-
>sessionStorage(); | 219 StorageNamespace* sessionStorage = StorageNamespaceController::from(m_page)-
>sessionStorage(); |
| 222 if (!sessionStorage) { | 220 if (!sessionStorage) { |
| 223 if (errorString) | 221 if (errorString) |
| 224 *errorString = "SessionStorage is not supported"; | 222 *errorString = "SessionStorage is not supported"; |
| 225 return nullptr; | 223 return nullptr; |
| 226 } | 224 } |
| 227 return sessionStorage->storageArea(frame->document()->securityOrigin()); | 225 return sessionStorage->storageArea(frame->document()->securityOrigin()); |
| 228 } | 226 } |
| 229 | 227 |
| 230 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |