Web Inspector: Refactor InspectorDOMStorageAgent::getDOMStorageEntries to report...
authorvivek.vg@samsung.com <vivek.vg@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 12:54:34 +0000 (12:54 +0000)
committervivek.vg@samsung.com <vivek.vg@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 12:54:34 +0000 (12:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108611

Reviewed by Pavel Feldman.

Added reporting of various error messages. Moved the modification of output
parameter at a later stage when there are no errors reported.

No new tests as code refactoring.

* inspector/InspectorDOMStorageAgent.cpp:
(WebCore::hadException):
(WebCore):
(WebCore::InspectorDOMStorageAgent::getDOMStorageEntries):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141690 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorDOMStorageAgent.cpp

index 2a7381e..31eda65 100644 (file)
@@ -1,3 +1,20 @@
+2013-02-02  Vivek Galatage  <vivek.vg@samsung.com>
+
+        Web Inspector: Refactor InspectorDOMStorageAgent::getDOMStorageEntries to report the error messages
+        https://bugs.webkit.org/show_bug.cgi?id=108611
+
+        Reviewed by Pavel Feldman.
+
+        Added reporting of various error messages. Moved the modification of output
+        parameter at a later stage when there are no errors reported.
+
+        No new tests as code refactoring.
+
+        * inspector/InspectorDOMStorageAgent.cpp:
+        (WebCore::hadException):
+        (WebCore):
+        (WebCore::InspectorDOMStorageAgent::getDOMStorageEntries):
+
 2013-02-02  Andrey Lushnikov  <lushnikov@chromium.org>
 
         Web Inspector: fix bug in highlighting single chars via highlightRange API of DTE
index 8433a6d..9cf8875 100644 (file)
@@ -56,6 +56,20 @@ namespace DOMStorageAgentState {
 static const char domStorageAgentEnabled[] = "domStorageAgentEnabled";
 };
 
+static bool hadException(ExceptionCode ec, ErrorString* errorString)
+{
+    switch (ec) {
+    case 0:
+        return false;
+    case SECURITY_ERR:
+        *errorString = "Security error";
+        return true;
+    default:
+        *errorString = "Unknown DOM storage error";
+        return true;
+    }
+}
+
 InspectorDOMStorageAgent::InspectorDOMStorageAgent(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state)
     : InspectorBaseAgent<InspectorDOMStorageAgent>("DOMStorage", instrumentingAgents, state)
     , m_frontend(0)
@@ -109,33 +123,36 @@ void InspectorDOMStorageAgent::disable(ErrorString*)
     m_state->setBoolean(DOMStorageAgentState::domStorageAgentEnabled, m_enabled);
 }
 
-void InspectorDOMStorageAgent::getDOMStorageEntries(ErrorString*, const String& storageId, RefPtr<TypeBuilder::Array<TypeBuilder::Array<String> > >& entries)
+void InspectorDOMStorageAgent::getDOMStorageEntries(ErrorString* errorString, const String& storageId, RefPtr<TypeBuilder::Array<TypeBuilder::Array<String> > >& entries)
 {
-    // FIXME: consider initializing this array after 2 checks below. The checks should return error messages in this case.
-    entries = TypeBuilder::Array<TypeBuilder::Array<String> >::create();
-
     InspectorDOMStorageResource* storageResource = getDOMStorageResourceForId(storageId);
-    if (!storageResource)
+    if (!storageResource) {
+        *errorString = "Storage resource not found for the given storage identifier";
         return;
+    }
     Frame* frame = storageResource->frame();
-    if (!frame)
+    if (!frame) {
+        *errorString = "Frame not found";
         return;
+    }
+
+    RefPtr<TypeBuilder::Array<TypeBuilder::Array<String> > > storageEntries = TypeBuilder::Array<TypeBuilder::Array<String> >::create();
 
-    // FIXME: Exceptions are not reported here.
     ExceptionCode ec = 0;
     StorageArea* storageArea = storageResource->storageArea();
     for (unsigned i = 0; i < storageArea->length(ec, frame); ++i) {
         String name(storageArea->key(i, ec, frame));
-        if (ec)
+        if (hadException(ec, errorString))
             return;
         String value(storageArea->getItem(name, ec, frame));
-        if (ec)
+        if (hadException(ec, errorString))
             return;
         RefPtr<TypeBuilder::Array<String> > entry = TypeBuilder::Array<String>::create();
         entry->addItem(name);
         entry->addItem(value);
-        entries->addItem(entry);
+        storageEntries->addItem(entry);
     }
+    entries = storageEntries.release();
 }
 
 void InspectorDOMStorageAgent::setDOMStorageItem(ErrorString*, const String& storageId, const String& key, const String& value, bool* success)