Title: [120702] trunk
Revision
120702
Author
[email protected]
Date
2012-06-19 03:38:32 -0700 (Tue, 19 Jun 2012)

Log Message

Web Inspector: FileSystem tree should hide uninitialized FileSystem
https://bugs.webkit.org/show_bug.cgi?id=88602

Patch by Taiju Tsuiki <[email protected]> on 2012-06-19
Reviewed by Vsevolod Vlasov.

Source/WebCore:

Test: http/tests/inspector/filesystem/get-filesystem-root.html

* inspector/Inspector.json:
* inspector/InspectorFileSystemAgent.cpp:
(WebCore):
(WebCore::InspectorFileSystemAgent::getFileSystemRoot):
* inspector/InspectorFileSystemAgent.h:
(InspectorFileSystemAgent):
* inspector/front-end/FileSystemModel.js:
(WebInspector.FileSystemModel.prototype._originAdded):
(WebInspector.FileSystemModel.prototype.refreshFileSystemList):
(WebInspector.FileSystemModel.prototype._gotFileSystem):
(WebInspector.FileSystemModel.FileSystem):
(WebInspector.FileSystemRequestManager):
(WebInspector.FileSystemRequestManager.prototype.getFileSystemRoot):
(WebInspector.FileSystemRequestManager.prototype._gotFileSystemRoot):
(WebInspector.FileSystemDispatcher.prototype.gotFileSystemRoot):
* inspector/front-end/ResourcesPanel.js:
(WebInspector.FileSystemListTreeElement.prototype._fileSystemRemoved):

LayoutTests:

* http/tests/inspector/filesystem/get-filesystem-root-expected.txt: Added.
* http/tests/inspector/filesystem/get-filesystem-root.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (120701 => 120702)


--- trunk/LayoutTests/ChangeLog	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/LayoutTests/ChangeLog	2012-06-19 10:38:32 UTC (rev 120702)
@@ -1,3 +1,13 @@
+2012-06-19  Taiju Tsuiki  <[email protected]>
+
+        Web Inspector: FileSystem tree should hide uninitialized FileSystem
+        https://bugs.webkit.org/show_bug.cgi?id=88602
+
+        Reviewed by Vsevolod Vlasov.
+
+        * http/tests/inspector/filesystem/get-filesystem-root-expected.txt: Added.
+        * http/tests/inspector/filesystem/get-filesystem-root.html: Added.
+
 2012-06-19  Christophe Dumez  <[email protected]>
 
         [EFL] EFL's LayoutTestController does not support setTextDirection

Added: trunk/LayoutTests/http/tests/inspector/filesystem/get-filesystem-root-expected.txt (0 => 120702)


--- trunk/LayoutTests/http/tests/inspector/filesystem/get-filesystem-root-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/get-filesystem-root-expected.txt	2012-06-19 10:38:32 UTC (rev 120702)
@@ -0,0 +1,4 @@
+Tests getFileSystemRoot.
+
+PASS: filesystem:http://127.0.0.1:8000/temporary/ is found.
+

Added: trunk/LayoutTests/http/tests/inspector/filesystem/get-filesystem-root.html (0 => 120702)


--- trunk/LayoutTests/http/tests/inspector/filesystem/get-filesystem-root.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/get-filesystem-root.html	2012-06-19 10:38:32 UTC (rev 120702)
@@ -0,0 +1,41 @@
+<!DOCTYPE html><meta charset="UTF-8">
+<script src=""
+<script src=""
+<script>
+document.addEventListener("DOMContentLoaded", runTest);
+function test()
+{
+    var fileSystemRequestManager = new WebInspector.FileSystemRequestManager();
+
+    InspectorTest.clearFileSystem(step1);
+
+    function step1()
+    {
+        // FIXME: Add API to delete a FileSystem completely and test getFileSystemRoot for
+        // uninitialized FileSystem.
+        InspectorTest.createFile("/hoge", step2);
+    }
+
+    function step2()
+    {
+        fileSystemRequestManager.getFileSystemRoot("http://127.0.0.1:8000", "temporary", step3);
+    }
+
+    function step3(errorCode, backendRootEntry)
+    {
+        if (errorCode === 0 && backendRootEntry)
+            InspectorTest.addResult("PASS: " + backendRootEntry.url + " is found.");
+        else
+            InspectorTest.addResult("FAIL: errorCode = " + errorCode);
+
+        InspectorTest.clearFileSystem(step4);
+    }
+
+    function step4(errorCode, fileSystem)
+    {
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+<p>Tests getFileSystemRoot.</p>

Modified: trunk/Source/WebCore/ChangeLog (120701 => 120702)


--- trunk/Source/WebCore/ChangeLog	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/Source/WebCore/ChangeLog	2012-06-19 10:38:32 UTC (rev 120702)
@@ -1,3 +1,30 @@
+2012-06-19  Taiju Tsuiki  <[email protected]>
+
+        Web Inspector: FileSystem tree should hide uninitialized FileSystem
+        https://bugs.webkit.org/show_bug.cgi?id=88602
+
+        Reviewed by Vsevolod Vlasov.
+
+        Test: http/tests/inspector/filesystem/get-filesystem-root.html
+
+        * inspector/Inspector.json:
+        * inspector/InspectorFileSystemAgent.cpp:
+        (WebCore):
+        (WebCore::InspectorFileSystemAgent::getFileSystemRoot):
+        * inspector/InspectorFileSystemAgent.h:
+        (InspectorFileSystemAgent):
+        * inspector/front-end/FileSystemModel.js:
+        (WebInspector.FileSystemModel.prototype._originAdded):
+        (WebInspector.FileSystemModel.prototype.refreshFileSystemList):
+        (WebInspector.FileSystemModel.prototype._gotFileSystem):
+        (WebInspector.FileSystemModel.FileSystem):
+        (WebInspector.FileSystemRequestManager):
+        (WebInspector.FileSystemRequestManager.prototype.getFileSystemRoot):
+        (WebInspector.FileSystemRequestManager.prototype._gotFileSystemRoot):
+        (WebInspector.FileSystemDispatcher.prototype.gotFileSystemRoot):
+        * inspector/front-end/ResourcesPanel.js:
+        (WebInspector.FileSystemListTreeElement.prototype._fileSystemRemoved):
+
 2012-06-19  Mike West  <[email protected]>
 
         Introduce ENABLE_CSP_NEXT configuration flag.

Modified: trunk/Source/WebCore/inspector/Inspector.json (120701 => 120702)


--- trunk/Source/WebCore/inspector/Inspector.json	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/Source/WebCore/inspector/Inspector.json	2012-06-19 10:38:32 UTC (rev 120702)
@@ -1409,11 +1409,12 @@
                 "type": "object",
                 "properties": [
                     { "name": "url", "type": "string", "description": "filesystem: URL for the entry." },
-                    { "name": "name", "type": "string" },
+                    { "name": "name", "type": "string", "description": "The name of the file or directory." },
                     { "name": "isDirectory", "type": "boolean", "description": "True if the entry is a directory." },
                     { "name": "mimeType", "type": "string", "optional": true, "description": "MIME type of the entry, available for a file only." },
                     { "name": "resourceType", "$ref": "Page.ResourceType", "optional": true, "description": "ResourceType of the entry, available for a file only." }
-                ]
+                ],
+                "description": "Represents a browser side file or directory."
             }
         ],
         "commands": [
@@ -1426,22 +1427,41 @@
                 "description": "Disables events from backend."
             },
             {
+                "name": "getFileSystemRoot",
+                "parameters": [
+                    { "name": "requestId", "type": "integer", "description": "Request Identifier of the command. The backend should pass back this value on corresponding gotFileSystemRoot event." },
+                    { "name": "origin", "type": "string", "description": "Security origin of requesting FileSystem. One of frames in current page needs to have this security origin." },
+                    { "name": "type", "type": "string", "enum": ["temporary", "persistent"], "description": "FileSystem type of requesting FileSystem." }
+                ],
+                "description": "Returns root directory of the FileSystem if exists."
+            },
+            {
                 "name": "readDirectory",
-                "description": "Requests to read the directory content. Result should return on didReadDirectory event with request id.",
                 "parameters": [
-                    { "name": "requestId", "type": "integer" },
-                    { "name": "url", "type": "string" }
-                ]
+                    { "name": "requestId", "type": "integer", "description": "Request Identifier of the command. The backend should pass back this value on corresponding didReadDirectory event." },
+                    { "name": "url", "type": "string", "description": "URL of the directory that the frontend is requesting to read from." }
+                ],
+                "description": "Requests to read the directory content. Result should return on didReadDirectory event with request id."
             }
         ],
         "events": [
             {
+                "name": "gotFileSystemRoot",
+                "parameters": [
+                    { "name": "requestId", "type": "integer", "description": "Request Identifier that was passed to corresponding getFileSystemRoot command." },
+                    { "name": "errorCode", "type": "integer", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value." },
+                    { "name": "root", "$ref": "FileSystem.Entry", "optional": true, "description": "Contains root of the requested FileSystem if the command completed successfully." }
+                ],
+                "description": "Completion event of getFileSystemRoot command."
+            },
+            {
                 "name": "didReadDirectory",
                 "parameters": [
-                    { "name": "requestId", "type": "integer" },
-                    { "name": "errorCode", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value.", "type": "integer" },
-                    { "name": "entries", "type": "array", "items": { "$ref": "FileSystem.Entry" }, "optional": true, "description": "Entries of the directory." }
-                ]
+                    { "name": "requestId", "type": "integer", "description": "Request Identifier that was passed to corresponding readDirectory request." },
+                    { "name": "errorCode", "type": "integer", "description": "0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value." },
+                    { "name": "entries", "type": "array", "items": { "$ref": "FileSystem.Entry" }, "optional": true, "description": "Contains all entries on directory if the command completed successfully." }
+                ],
+                "description": "Completion event of readDirectory command."
             }
         ]
     },

Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp (120701 => 120702)


--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp	2012-06-19 10:38:32 UTC (rev 120702)
@@ -96,6 +96,105 @@
 
 namespace {
 
+class GetFileSystemRootTask : public RefCounted<GetFileSystemRootTask> {
+    WTF_MAKE_NONCOPYABLE(GetFileSystemRootTask);
+public:
+    static PassRefPtr<GetFileSystemRootTask> create(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& type)
+    {
+        return adoptRef(new GetFileSystemRootTask(frontendProvider, requestId, type));
+    }
+
+    void start(ScriptExecutionContext*);
+
+private:
+    class ErrorCallback;
+    class GetEntryCallback;
+
+    void gotEntry(Entry*);
+
+    void reportResult(FileError::ErrorCode errorCode, PassRefPtr<TypeBuilder::FileSystem::Entry> entry)
+    {
+        if (!m_frontendProvider || !m_frontendProvider->frontend())
+            return;
+        m_frontendProvider->frontend()->gotFileSystemRoot(m_requestId, static_cast<int>(errorCode), entry);
+        m_frontendProvider = 0;
+    }
+
+    GetFileSystemRootTask(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& type)
+        : m_frontendProvider(frontendProvider)
+        , m_requestId(requestId)
+        , m_type(type) { }
+
+    RefPtr<FrontendProvider> m_frontendProvider;
+    int m_requestId;
+    String m_type;
+};
+
+class GetFileSystemRootTask::ErrorCallback : public WebCore::ErrorCallback {
+    WTF_MAKE_NONCOPYABLE(ErrorCallback);
+public:
+    static PassRefPtr<GetFileSystemRootTask::ErrorCallback> create(PassRefPtr<GetFileSystemRootTask> getFileSystemRootTask)
+    {
+        return adoptRef(new GetFileSystemRootTask::ErrorCallback(getFileSystemRootTask));
+    }
+
+    virtual bool handleEvent(FileError* error) OVERRIDE
+    {
+        m_getFileSystemRootTask->reportResult(error->code(), 0);
+        return true;
+    }
+
+private:
+    ErrorCallback(PassRefPtr<GetFileSystemRootTask> getFileSystemRootTask)
+        : m_getFileSystemRootTask(getFileSystemRootTask) { }
+    RefPtr<GetFileSystemRootTask> m_getFileSystemRootTask;
+};
+
+class GetFileSystemRootTask::GetEntryCallback : public WebCore::EntryCallback {
+    WTF_MAKE_NONCOPYABLE(GetEntryCallback);
+public:
+    static PassRefPtr<GetFileSystemRootTask::GetEntryCallback> create(PassRefPtr<GetFileSystemRootTask> getFileSystemRootTask)
+    {
+        return adoptRef(new GetFileSystemRootTask::GetEntryCallback(getFileSystemRootTask));
+    }
+
+    virtual bool handleEvent(Entry* entry) OVERRIDE
+    {
+        m_getFileSystemRootTask->gotEntry(entry);
+        return true;
+    }
+
+private:
+    GetEntryCallback(PassRefPtr<GetFileSystemRootTask> getFileSystemRootTask)
+        : m_getFileSystemRootTask(getFileSystemRootTask) { }
+    RefPtr<GetFileSystemRootTask> m_getFileSystemRootTask;
+};
+
+void GetFileSystemRootTask::start(ScriptExecutionContext* scriptExecutionContext)
+{
+    FileSystemType type;
+    if (m_type == DOMFileSystemBase::persistentPathPrefix)
+        type = FileSystemTypePersistent;
+    else if (m_type == DOMFileSystemBase::temporaryPathPrefix)
+        type = FileSystemTypeTemporary;
+    else {
+        reportResult(FileError::SYNTAX_ERR, 0);
+        return;
+    }
+
+    RefPtr<EntryCallback> successCallback = GetFileSystemRootTask::GetEntryCallback::create(this);
+    RefPtr<ErrorCallback> errorCallback = GetFileSystemRootTask::ErrorCallback::create(this);
+    OwnPtr<ResolveURICallbacks> fileSystemCallbacks = ResolveURICallbacks::create(successCallback, errorCallback, scriptExecutionContext, type, "/");
+
+    LocalFileSystem::localFileSystem().readFileSystem(scriptExecutionContext, type, fileSystemCallbacks.release());
+}
+
+void GetFileSystemRootTask::gotEntry(Entry* entry)
+{
+    RefPtr<TypeBuilder::FileSystem::Entry> result(TypeBuilder::FileSystem::Entry::create().setUrl(entry->toURL()).setName("/").setIsDirectory(true));
+    reportResult(static_cast<FileError::ErrorCode>(0), result);
+}
+
 class ReadDirectoryTask : public RefCounted<ReadDirectoryTask> {
     WTF_MAKE_NONCOPYABLE(ReadDirectoryTask);
 public:
@@ -309,6 +408,18 @@
     m_state->setBoolean(FileSystemAgentState::fileSystemAgentEnabled, m_enabled);
 }
 
+void InspectorFileSystemAgent::getFileSystemRoot(ErrorString*, int requestId, const String& origin, const String& type)
+{
+    if (!m_enabled || !m_frontendProvider)
+        return;
+    ASSERT(m_frontendProvider->frontend());
+
+    if (ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextForOrigin(SecurityOrigin::createFromString(origin).get()))
+        GetFileSystemRootTask::create(m_frontendProvider, requestId, type)->start(scriptExecutionContext);
+    else
+        m_frontendProvider->frontend()->gotFileSystemRoot(requestId, static_cast<int>(FileError::ABORT_ERR), 0);
+}
+
 void InspectorFileSystemAgent::readDirectory(ErrorString*, int requestId, const String& url)
 {
     if (!m_enabled || !m_frontendProvider)

Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h (120701 => 120702)


--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h	2012-06-19 10:38:32 UTC (rev 120702)
@@ -59,6 +59,7 @@
     virtual void enable(ErrorString*) OVERRIDE;
     virtual void disable(ErrorString*) OVERRIDE;
 
+    virtual void getFileSystemRoot(ErrorString*, int requestId, const String& origin, const String& type) OVERRIDE;
     virtual void readDirectory(ErrorString*, int requestId, const String& url) OVERRIDE;
 
     virtual void setFrontend(InspectorFrontend*) OVERRIDE;

Modified: trunk/Source/WebCore/inspector/front-end/FileSystemModel.js (120701 => 120702)


--- trunk/Source/WebCore/inspector/front-end/FileSystemModel.js	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/Source/WebCore/inspector/front-end/FileSystemModel.js	2012-06-19 10:38:32 UTC (rev 120702)
@@ -147,12 +147,8 @@
         this._fileSystemsForOrigin[origin] = {};
 
         var types = ["persistent", "temporary"];
-        for (var i = 0; i < types.length; ++i) {
-            // FIXME(88602): Check if the filesystem is initialized, and show it only if it was.
-            var fileSystem = new WebInspector.FileSystemModel.FileSystem(this, origin, types[i]);
-            this._fileSystemsForOrigin[origin][types[i]] = fileSystem;
-            this._fileSystemAdded(fileSystem);
-        }
+        for (var i = 0; i < types.length; ++i)
+            this._agentWrapper.getFileSystemRoot(origin, types[i], this._gotFileSystem.bind(this, origin, types[i], this._fileSystemsForOrigin[origin]));
     },
 
     /**
@@ -186,13 +182,26 @@
 
     refreshFileSystemList: function()
     {
-        for (var origin in this._fileSystemsForOrigin)
-            for (var type in this._fileSystemsForOrigin[origin])
-                this._fileSystemRemoved(this._fileSystemsForOrigin[origin][type]);
+        if (WebInspector.resourceTreeModel.mainFrame) {
+            this._detachFrameRecursively(WebInspector.resourceTreeModel.mainFrame);
+            this._attachFrameRecursively(WebInspector.resourceTreeModel.mainFrame);
+        }
+    },
 
-        for (var origin in this._fileSystemsForOrigin)
-            for (var type in this._fileSystemsForOrigin[origin])
-                this._fileSystemAdded(this._fileSystemsForOrigin[origin][type]);
+    /**
+     * @param {string} origin
+     * @param {string} type
+     * @param {Object.<WebInspector.FileSystemModel.FileSystem>} store
+     * @param {number} errorCode
+     * @param {FileSystemAgent.Entry=} backendRootEntry
+     */
+    _gotFileSystem: function(origin, type, store, errorCode, backendRootEntry)
+    {
+        if (errorCode === 0 && backendRootEntry && this._fileSystemsForOrigin[origin] === store) {
+            var fileSystem = new WebInspector.FileSystemModel.FileSystem(this, origin, type, backendRootEntry);
+            store[type] = fileSystem;
+            this._fileSystemAdded(fileSystem);
+        }
     }
 }
 
@@ -208,8 +217,9 @@
  * @param {WebInspector.FileSystemModel} fileSystemModel
  * @param {string} origin
  * @param {string} type
+ * @param {FileSystemAgent.Entry} backendRootEntry
  */
-WebInspector.FileSystemModel.FileSystem = function(fileSystemModel, origin, type)
+WebInspector.FileSystemModel.FileSystem = function(fileSystemModel, origin, type, backendRootEntry)
 {
     this.origin = origin;
     this.type = type;
@@ -227,6 +237,7 @@
  */
 WebInspector.FileSystemRequestManager = function()
 {
+    this._pendingGetFileSystemRootRequests = {};
     this._pendingReadDirectoryRequests = {};
 
     InspectorBackend.registerFileSystemDispatcher(new WebInspector.FileSystemDispatcher(this));
@@ -245,6 +256,32 @@
     },
 
     /**
+     * @param {string} origin
+     * @param {string} type
+     * @param {function(number, FileSystemAgent.Entry)} callback
+     */
+    getFileSystemRoot: function(origin, type, callback)
+    {
+        var requestId = this._requestId();
+        this._pendingGetFileSystemRootRequests[requestId] = callback;
+        FileSystemAgent.getFileSystemRoot(requestId, origin, type);
+    },
+
+    /**
+     * @param {number} requestId
+     * @param {number} errorCode
+     * @param {FileSystemAgent.Entry=} backendRootEntry
+     */
+    _gotFileSystemRoot: function(requestId, errorCode, backendRootEntry)
+    {
+        var callback = this._pendingGetFileSystemRootRequests[requestId];
+        if (!callback)
+            return;
+        delete this._pendingGetFileSystemRootRequests[requestId];
+        callback(errorCode, backendRootEntry);
+    },
+
+    /**
      * @param {string} url
      * @param {function(number, Array.<FileSystemAgent.Entry>=)} callback
      */
@@ -284,6 +321,16 @@
     /**
      * @param {number} requestId
      * @param {number} errorCode
+     * @param {FileSystemAgent.Entry=} backendRootEntry
+     */
+    gotFileSystemRoot: function(requestId, errorCode, backendRootEntry)
+    {
+        this._agentWrapper._gotFileSystemRoot(requestId, errorCode, backendRootEntry);
+    },
+
+    /**
+     * @param {number} requestId
+     * @param {number} errorCode
      * @param {Array.<FileSystemAgent.Entry>=} backendEntries
      */
     didReadDirectory: function(requestId, errorCode, backendEntries)

Modified: trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js (120701 => 120702)


--- trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js	2012-06-19 10:27:45 UTC (rev 120701)
+++ trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js	2012-06-19 10:38:32 UTC (rev 120702)
@@ -1525,7 +1525,6 @@
         var fileSystemTreeElement = this._fileSystemTreeElementByName(fileSystem.name);
         if (!fileSystemTreeElement)
             return;
-        fileSystemTreeElement.clear();
         this.removeChild(fileSystemTreeElement);
     },
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to