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

Side by Side Diff: third_party/WebKit/Source/modules/storage/InspectorDOMStorageAgent.cpp

Issue 2463673004: [inspector_protocol] Support fall through. (Closed)
Patch Set: example domain converted Created 4 years, 1 month 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) 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 30 matching lines...) Expand all
41 #include "modules/storage/StorageNamespace.h" 41 #include "modules/storage/StorageNamespace.h"
42 #include "modules/storage/StorageNamespaceController.h" 42 #include "modules/storage/StorageNamespaceController.h"
43 #include "platform/weborigin/SecurityOrigin.h" 43 #include "platform/weborigin/SecurityOrigin.h"
44 44
45 namespace blink { 45 namespace blink {
46 46
47 namespace DOMStorageAgentState { 47 namespace DOMStorageAgentState {
48 static const char domStorageAgentEnabled[] = "domStorageAgentEnabled"; 48 static const char domStorageAgentEnabled[] = "domStorageAgentEnabled";
49 }; 49 };
50 50
51 static bool hadException(ExceptionState& exceptionState, 51 static Response toResponse(ExceptionState& exceptionState) {
52 ErrorString* errorString) {
53 if (!exceptionState.hadException()) 52 if (!exceptionState.hadException())
54 return false; 53 return Response::OK();
55 54 return Response::Error(DOMException::getErrorName(exceptionState.code()) +
56 switch (exceptionState.code()) { 55 " " + exceptionState.message());
57 case SecurityError:
58 *errorString = "Security error";
59 return true;
60 default:
61 *errorString = "Unknown DOM storage error";
62 return true;
63 }
64 } 56 }
65 57
66 InspectorDOMStorageAgent::InspectorDOMStorageAgent(Page* page) 58 InspectorDOMStorageAgent::InspectorDOMStorageAgent(Page* page)
67 : m_page(page), m_isEnabled(false) {} 59 : m_page(page), m_isEnabled(false) {}
68 60
69 InspectorDOMStorageAgent::~InspectorDOMStorageAgent() {} 61 InspectorDOMStorageAgent::~InspectorDOMStorageAgent() {}
70 62
71 DEFINE_TRACE(InspectorDOMStorageAgent) { 63 DEFINE_TRACE(InspectorDOMStorageAgent) {
72 visitor->trace(m_page); 64 visitor->trace(m_page);
73 InspectorBaseAgent::trace(visitor); 65 InspectorBaseAgent::trace(visitor);
74 } 66 }
75 67
76 void InspectorDOMStorageAgent::restore() { 68 void InspectorDOMStorageAgent::restore() {
77 if (m_state->booleanProperty(DOMStorageAgentState::domStorageAgentEnabled, 69 if (m_state->booleanProperty(DOMStorageAgentState::domStorageAgentEnabled,
78 false)) 70 false)) {
79 enable(0); 71 enable();
72 }
80 } 73 }
81 74
82 void InspectorDOMStorageAgent::enable(ErrorString*) { 75 Response InspectorDOMStorageAgent::enable() {
83 if (m_isEnabled) 76 if (m_isEnabled)
84 return; 77 return Response::OK();
85 m_isEnabled = true; 78 m_isEnabled = true;
86 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, true); 79 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, true);
87 if (StorageNamespaceController* controller = 80 if (StorageNamespaceController* controller =
88 StorageNamespaceController::from(m_page)) 81 StorageNamespaceController::from(m_page))
89 controller->setInspectorAgent(this); 82 controller->setInspectorAgent(this);
83 return Response::OK();
90 } 84 }
91 85
92 void InspectorDOMStorageAgent::disable(ErrorString*) { 86 Response InspectorDOMStorageAgent::disable() {
93 if (!m_isEnabled) 87 if (!m_isEnabled)
94 return; 88 return Response::OK();
95 m_isEnabled = false; 89 m_isEnabled = false;
96 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, false); 90 m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, false);
97 if (StorageNamespaceController* controller = 91 if (StorageNamespaceController* controller =
98 StorageNamespaceController::from(m_page)) 92 StorageNamespaceController::from(m_page))
99 controller->setInspectorAgent(nullptr); 93 controller->setInspectorAgent(nullptr);
94 return Response::OK();
100 } 95 }
101 96
102 void InspectorDOMStorageAgent::getDOMStorageItems( 97 Response InspectorDOMStorageAgent::getDOMStorageItems(
103 ErrorString* errorString,
104 std::unique_ptr<protocol::DOMStorage::StorageId> storageId, 98 std::unique_ptr<protocol::DOMStorage::StorageId> storageId,
105 std::unique_ptr<protocol::Array<protocol::Array<String>>>* items) { 99 std::unique_ptr<protocol::Array<protocol::Array<String>>>* items) {
106 LocalFrame* frame; 100 LocalFrame* frame = nullptr;
107 StorageArea* storageArea = 101 StorageArea* storageArea = nullptr;
108 findStorageArea(errorString, std::move(storageId), frame); 102 Response response = findStorageArea(std::move(storageId), frame, storageArea);
109 if (!storageArea) 103 if (!response.isSuccess())
110 return; 104 return response;
111 105
112 std::unique_ptr<protocol::Array<protocol::Array<String>>> storageItems = 106 std::unique_ptr<protocol::Array<protocol::Array<String>>> storageItems =
113 protocol::Array<protocol::Array<String>>::create(); 107 protocol::Array<protocol::Array<String>>::create();
114 108
115 TrackExceptionState exceptionState; 109 TrackExceptionState exceptionState;
116 for (unsigned i = 0; i < storageArea->length(exceptionState, frame); ++i) { 110 for (unsigned i = 0; i < storageArea->length(exceptionState, frame); ++i) {
117 String name(storageArea->key(i, exceptionState, frame)); 111 String name(storageArea->key(i, exceptionState, frame));
118 if (hadException(exceptionState, errorString)) 112 response = toResponse(exceptionState);
119 return; 113 if (!response.isSuccess())
114 return response;
120 String value(storageArea->getItem(name, exceptionState, frame)); 115 String value(storageArea->getItem(name, exceptionState, frame));
121 if (hadException(exceptionState, errorString)) 116 response = toResponse(exceptionState);
122 return; 117 if (!response.isSuccess())
118 return response;
123 std::unique_ptr<protocol::Array<String>> entry = 119 std::unique_ptr<protocol::Array<String>> entry =
124 protocol::Array<String>::create(); 120 protocol::Array<String>::create();
125 entry->addItem(name); 121 entry->addItem(name);
126 entry->addItem(value); 122 entry->addItem(value);
127 storageItems->addItem(std::move(entry)); 123 storageItems->addItem(std::move(entry));
128 } 124 }
129 *items = std::move(storageItems); 125 *items = std::move(storageItems);
126 return Response::OK();
130 } 127 }
131 128
132 static String toErrorString(ExceptionState& exceptionState) { 129 Response InspectorDOMStorageAgent::setDOMStorageItem(
133 if (exceptionState.hadException())
134 return DOMException::getErrorName(exceptionState.code());
135 return "";
136 }
137
138 void InspectorDOMStorageAgent::setDOMStorageItem(
139 ErrorString* errorString,
140 std::unique_ptr<protocol::DOMStorage::StorageId> storageId, 130 std::unique_ptr<protocol::DOMStorage::StorageId> storageId,
141 const String& key, 131 const String& key,
142 const String& value) { 132 const String& value) {
143 LocalFrame* frame; 133 LocalFrame* frame = nullptr;
144 StorageArea* storageArea = findStorageArea(0, std::move(storageId), frame); 134 StorageArea* storageArea = nullptr;
145 if (!storageArea) { 135 Response response = findStorageArea(std::move(storageId), frame, storageArea);
146 *errorString = "Storage not found"; 136 if (!response.isSuccess())
147 return; 137 return response;
148 }
149 138
150 TrackExceptionState exceptionState; 139 TrackExceptionState exceptionState;
151 storageArea->setItem(key, value, exceptionState, frame); 140 storageArea->setItem(key, value, exceptionState, frame);
152 *errorString = toErrorString(exceptionState); 141 return toResponse(exceptionState);
153 } 142 }
154 143
155 void InspectorDOMStorageAgent::removeDOMStorageItem( 144 Response InspectorDOMStorageAgent::removeDOMStorageItem(
156 ErrorString* errorString,
157 std::unique_ptr<protocol::DOMStorage::StorageId> storageId, 145 std::unique_ptr<protocol::DOMStorage::StorageId> storageId,
158 const String& key) { 146 const String& key) {
159 LocalFrame* frame; 147 LocalFrame* frame = nullptr;
160 StorageArea* storageArea = findStorageArea(0, std::move(storageId), frame); 148 StorageArea* storageArea = nullptr;
161 if (!storageArea) { 149 Response response = findStorageArea(std::move(storageId), frame, storageArea);
162 *errorString = "Storage not found"; 150 if (!response.isSuccess())
163 return; 151 return response;
164 }
165 152
166 TrackExceptionState exceptionState; 153 TrackExceptionState exceptionState;
167 storageArea->removeItem(key, exceptionState, frame); 154 storageArea->removeItem(key, exceptionState, frame);
168 *errorString = toErrorString(exceptionState); 155 return toResponse(exceptionState);
169 } 156 }
170 157
171 std::unique_ptr<protocol::DOMStorage::StorageId> 158 std::unique_ptr<protocol::DOMStorage::StorageId>
172 InspectorDOMStorageAgent::storageId(SecurityOrigin* securityOrigin, 159 InspectorDOMStorageAgent::storageId(SecurityOrigin* securityOrigin,
173 bool isLocalStorage) { 160 bool isLocalStorage) {
174 return protocol::DOMStorage::StorageId::create() 161 return protocol::DOMStorage::StorageId::create()
175 .setSecurityOrigin(securityOrigin->toRawString()) 162 .setSecurityOrigin(securityOrigin->toRawString())
176 .setIsLocalStorage(isLocalStorage) 163 .setIsLocalStorage(isLocalStorage)
177 .build(); 164 .build();
178 } 165 }
(...skipping 13 matching lines...) Expand all
192 if (key.isNull()) 179 if (key.isNull())
193 frontend()->domStorageItemsCleared(std::move(id)); 180 frontend()->domStorageItemsCleared(std::move(id));
194 else if (newValue.isNull()) 181 else if (newValue.isNull())
195 frontend()->domStorageItemRemoved(std::move(id), key); 182 frontend()->domStorageItemRemoved(std::move(id), key);
196 else if (oldValue.isNull()) 183 else if (oldValue.isNull())
197 frontend()->domStorageItemAdded(std::move(id), key, newValue); 184 frontend()->domStorageItemAdded(std::move(id), key, newValue);
198 else 185 else
199 frontend()->domStorageItemUpdated(std::move(id), key, oldValue, newValue); 186 frontend()->domStorageItemUpdated(std::move(id), key, oldValue, newValue);
200 } 187 }
201 188
202 StorageArea* InspectorDOMStorageAgent::findStorageArea( 189 Response InspectorDOMStorageAgent::findStorageArea(
203 ErrorString* errorString,
204 std::unique_ptr<protocol::DOMStorage::StorageId> storageId, 190 std::unique_ptr<protocol::DOMStorage::StorageId> storageId,
205 LocalFrame*& targetFrame) { 191 LocalFrame*& frame,
192 StorageArea*& storageArea) {
206 String securityOrigin = storageId->getSecurityOrigin(); 193 String securityOrigin = storageId->getSecurityOrigin();
207 bool isLocalStorage = storageId->getIsLocalStorage(); 194 bool isLocalStorage = storageId->getIsLocalStorage();
208 195
209 if (!m_page->mainFrame()->isLocalFrame()) 196 if (!m_page->mainFrame()->isLocalFrame())
210 return nullptr; 197 return Response::InternalError();
211 198
212 InspectedFrames* inspectedFrames = 199 InspectedFrames* inspectedFrames =
213 InspectedFrames::create(m_page->deprecatedLocalMainFrame()); 200 InspectedFrames::create(m_page->deprecatedLocalMainFrame());
214 LocalFrame* frame = inspectedFrames->frameWithSecurityOrigin(securityOrigin); 201 frame = inspectedFrames->frameWithSecurityOrigin(securityOrigin);
215 if (!frame) { 202 if (!frame)
216 if (errorString) 203 return Response::Error("Frame not found for the given security origin");
217 *errorString = "LocalFrame not found for the given security origin"; 204
218 return nullptr; 205 if (isLocalStorage) {
206 storageArea = StorageNamespace::localStorageArea(
207 frame->document()->getSecurityOrigin());
208 return Response::OK();
219 } 209 }
220 targetFrame = frame;
221
222 if (isLocalStorage)
223 return StorageNamespace::localStorageArea(
224 frame->document()->getSecurityOrigin());
225 StorageNamespace* sessionStorage = 210 StorageNamespace* sessionStorage =
226 StorageNamespaceController::from(m_page)->sessionStorage(); 211 StorageNamespaceController::from(m_page)->sessionStorage();
227 if (!sessionStorage) { 212 if (!sessionStorage)
228 if (errorString) 213 return Response::Error("SessionStorage is not supported");
229 *errorString = "SessionStorage is not supported"; 214 storageArea =
230 return nullptr; 215 sessionStorage->storageArea(frame->document()->getSecurityOrigin());
231 } 216 return Response::OK();
232 return sessionStorage->storageArea(frame->document()->getSecurityOrigin());
233 } 217 }
234 218
235 } // namespace blink 219 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/storage/InspectorDOMStorageAgent.h ('k') | third_party/inspector_protocol/CodeGenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698