Title: [120177] trunk
Revision
120177
Author
[email protected]
Date
2012-06-13 02:52:20 -0700 (Wed, 13 Jun 2012)

Log Message

Implement InspectorFileSystemAgent::readDirectory for FileSystem support.
https://bugs.webkit.org/show_bug.cgi?id=87724

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

Source/WebCore:

Test: http/tests/inspector/filesystem/read-directory.html

* inspector/Inspector.json:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
* inspector/InspectorFileSystemAgent.cpp:
(InspectorFileSystemAgent::FrontendProvider):
(WebCore):
(WebCore::InspectorFileSystemAgent::create):
(WebCore::InspectorFileSystemAgent::readDirectory):
(WebCore::InspectorFileSystemAgent::InspectorFileSystemAgent):
* inspector/InspectorFileSystemAgent.h:
(WebCore):
(InspectorFileSystemAgent):

LayoutTests:

* http/tests/inspector/filesystem/filesystem-test.js: Added.
* http/tests/inspector/filesystem/read-directory-expected.txt: Added.
* http/tests/inspector/filesystem/read-directory.html: Added.
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (120176 => 120177)


--- trunk/LayoutTests/ChangeLog	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/LayoutTests/ChangeLog	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1,3 +1,18 @@
+2012-06-13  Taiju Tsuiki  <[email protected]>
+
+        Implement InspectorFileSystemAgent::readDirectory for FileSystem support.
+        https://bugs.webkit.org/show_bug.cgi?id=87724
+
+        Reviewed by Vsevolod Vlasov.
+
+        * http/tests/inspector/filesystem/filesystem-test.js: Added.
+        * http/tests/inspector/filesystem/read-directory-expected.txt: Added.
+        * http/tests/inspector/filesystem/read-directory.html: Added.
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * platform/wincairo/Skipped:
+
 2012-06-13  Ryosuke Niwa  <[email protected]>
 
         Revert the removal of 2 editing tests in r120173.

Added: trunk/LayoutTests/http/tests/inspector/filesystem/filesystem-test.js (0 => 120177)


--- trunk/LayoutTests/http/tests/inspector/filesystem/filesystem-test.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/filesystem-test.js	2012-06-13 09:52:20 UTC (rev 120177)
@@ -0,0 +1,73 @@
+var initialize_FileSystemTest = function()
+{
+    var nextCallbackId = 0;
+    var callbacks = {};
+
+    InspectorTest.registerCallback = function(callback)
+    {
+        var callbackId = ++nextCallbackId;
+        callbacks[callbackId] = callback;
+        return "dispatchCallback.bind(null, " + callbackId + ")";
+    };
+
+    InspectorTest.dispatchCallback = function(packedArgs)
+    {
+        var args = JSON.parse(packedArgs);
+        var callbackId = args.shift();
+        var callback = callbacks[callbackId];
+        delete callbacks[callbackId];
+        callback.apply(null, args);
+    };
+
+    InspectorTest.createDirectory = function(path, callback)
+    {
+        InspectorTest.evaluateInPage("createDirectory(escape(\"" + escape(path) + "\"), " + InspectorTest.registerCallback(callback) + ")");
+    };
+
+    InspectorTest.createFile = function(path, callback)
+    {
+        InspectorTest.evaluateInPage("createFile(unescape(\"" + escape(path) + "\"), " + InspectorTest.registerCallback(callback) + ")");
+    };
+
+    InspectorTest.dumpReadDirectoryResult = function(requestId, errorCode, entries)
+    {
+        InspectorTest.addResult("requestId: " + requestId);
+        InspectorTest.addResult("errorCode: " + errorCode);
+
+        if (!entries) {
+            InspectorTest.addResult("entries: (null)");
+            return;
+        }
+
+        InspectorTest.addResult("entries:");
+        for (var i = 0; i < entries.length; ++i) {
+          InspectorTest.addResult("  " + i + ":");
+          for (var j in entries[i])
+            InspectorTest.addResult("    " + j + ": " + entries[i][j]);
+        }
+    };
+}
+
+function dispatchCallback()
+{
+    var args = JSON.stringify(Array.prototype.slice.call(arguments));
+    layoutTestController.evaluateInWebInspector(0, "InspectorTest.dispatchCallback(unescape(\"" + escape(args) + "\"))");
+}
+
+function createDirectory(path, callback)
+{
+    webkitRequestFileSystem(TEMPORARY, 1, function(fs) {
+        fs.root.getDirectory(path, {create:true}, function(entry) {
+            callback();
+        });
+    });
+}
+
+function createFile(path, callback)
+{
+    webkitRequestFileSystem(TEMPORARY, 1, function(fs) {
+        fs.root.getFile(path, {create:true}, function(entry) {
+            callback();
+        });
+    });
+}

Added: trunk/LayoutTests/http/tests/inspector/filesystem/read-directory-expected.txt (0 => 120177)


--- trunk/LayoutTests/http/tests/inspector/filesystem/read-directory-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/read-directory-expected.txt	2012-06-13 09:52:20 UTC (rev 120177)
@@ -0,0 +1,19 @@
+Tests readDirectory.
+
+requestId: 1
+errorCode: 0
+entries:
+  0:
+    url: filesystem:http://127.0.0.1:8000/temporary/hoge/piyo.html
+    name: piyo.html
+    isDirectory: false
+    mimeType: text/html
+    resourceType: Document
+  1:
+    url: filesystem:http://127.0.0.1:8000/temporary/hoge/fuga
+    name: fuga
+    isDirectory: true
+requestId: 1
+errorCode: 1
+entries: (null)
+

Added: trunk/LayoutTests/http/tests/inspector/filesystem/read-directory.html (0 => 120177)


--- trunk/LayoutTests/http/tests/inspector/filesystem/read-directory.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/filesystem/read-directory.html	2012-06-13 09:52:20 UTC (rev 120177)
@@ -0,0 +1,60 @@
+<!DOCTYPE html><meta charset="UTF-8">
+<script src=""
+<script src=""
+<script>
+document.addEventListener("DOMContentLoaded", runTest);
+function test()
+{
+    // FIXME: Replace FileSystemDispatcher with FileSystemDispatcher implementation after it landed.
+    function FileSystemDispatcher() {}
+    FileSystemDispatcher.prototype = {
+        didReadDirectory: function(requestId, errorCode, entries)
+        {
+        }
+    };
+
+    InspectorBackend.registerFileSystemDispatcher(new FileSystemDispatcher());
+    FileSystemAgent.enable();
+
+    step1();
+
+    function step1()
+    {
+        InspectorTest.createDirectory("/hoge", step2);
+    }
+
+    function step2()
+    {
+        InspectorTest.createDirectory("/hoge/fuga", step3);
+    }
+
+    function step3()
+    {
+        InspectorTest.createFile("/hoge/piyo.html", step4);
+    }
+
+    function step4()
+    {
+        InspectorTest.addSniffer(FileSystemDispatcher.prototype, "didReadDirectory", step5, false);
+        // FIXME: Call FileSystemDispatcher through FileSystemDispatcher implementation after it landed.
+        FileSystemAgent.readDirectory(1, WebInspector.resourceTreeModel.mainFrame.id, "filesystem:http://127.0.0.1/temporary/hoge");
+    }
+
+    function step5(requestId, errorCode, entries)
+    {
+        InspectorTest.dumpReadDirectoryResult(requestId, errorCode, entries);
+
+        InspectorTest.addSniffer(FileSystemDispatcher.prototype, "didReadDirectory", step6, false);
+        // FIXME: Call FileSystemDispatcher through FileSystemDispatcher implementation after it landed.
+        FileSystemAgent.readDirectory(1, WebInspector.resourceTreeModel.mainFrame.id, "filesystem:http://127.0.0.1/temporary/foo");
+    }
+
+    function step6(requestId, errorCode, entries) {
+        InspectorTest.dumpReadDirectoryResult(requestId, errorCode, entries);
+
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+<p>Tests readDirectory.</p>

Modified: trunk/LayoutTests/platform/mac/Skipped (120176 => 120177)


--- trunk/LayoutTests/platform/mac/Skipped	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/LayoutTests/platform/mac/Skipped	2012-06-13 09:52:20 UTC (rev 120177)
@@ -325,6 +325,7 @@
 # FileSystem API is not supported.
 fast/filesystem
 http/tests/filesystem
+http/tests/inspector/filesystem
 http/tests/security/filesystem-iframe-from-remote.html
 http/tests/security/mixedContent/filesystem-url-in-iframe.html
 http/tests/websocket/tests/hybi/send-file-blob.html

Modified: trunk/LayoutTests/platform/qt/Skipped (120176 => 120177)


--- trunk/LayoutTests/platform/qt/Skipped	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/LayoutTests/platform/qt/Skipped	2012-06-13 09:52:20 UTC (rev 120177)
@@ -117,6 +117,7 @@
 # ENABLE(FILE_SYSTEM) is disabled.
 fast/filesystem
 http/tests/filesystem
+http/tests/inspector/filesystem
 http/tests/security/filesystem-iframe-from-remote.html
 http/tests/security/mixedContent/filesystem-url-in-iframe.html
 http/tests/websocket/tests/hybi/send-file-blob.html

Modified: trunk/LayoutTests/platform/win/Skipped (120176 => 120177)


--- trunk/LayoutTests/platform/win/Skipped	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/LayoutTests/platform/win/Skipped	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1304,6 +1304,7 @@
 # FileSystem API is not supported.
 fast/filesystem
 http/tests/filesystem
+http/tests/inspector/filesystem
 http/tests/security/filesystem-iframe-from-remote.html
 http/tests/websocket/tests/hybi/send-file-blob.html
 http/tests/websocket/tests/hybi/send-file-blob-fail.html

Modified: trunk/LayoutTests/platform/wincairo/Skipped (120176 => 120177)


--- trunk/LayoutTests/platform/wincairo/Skipped	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/LayoutTests/platform/wincairo/Skipped	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1803,6 +1803,7 @@
 # FileSystem API is not supported.
 fast/filesystem
 http/tests/filesystem
+http/tests/inspector/filesystem
 http/tests/security/filesystem-iframe-from-remote.html
 http/tests/websocket/tests/hybi/send-file-blob.html
 http/tests/websocket/tests/hybi/send-file-blob-fail.html

Modified: trunk/Source/WebCore/ChangeLog (120176 => 120177)


--- trunk/Source/WebCore/ChangeLog	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/Source/WebCore/ChangeLog	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1,3 +1,25 @@
+2012-06-13  Taiju Tsuiki  <[email protected]>
+
+        Implement InspectorFileSystemAgent::readDirectory for FileSystem support.
+        https://bugs.webkit.org/show_bug.cgi?id=87724
+
+        Reviewed by Vsevolod Vlasov.
+
+        Test: http/tests/inspector/filesystem/read-directory.html
+
+        * inspector/Inspector.json:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        * inspector/InspectorFileSystemAgent.cpp:
+        (InspectorFileSystemAgent::FrontendProvider):
+        (WebCore):
+        (WebCore::InspectorFileSystemAgent::create):
+        (WebCore::InspectorFileSystemAgent::readDirectory):
+        (WebCore::InspectorFileSystemAgent::InspectorFileSystemAgent):
+        * inspector/InspectorFileSystemAgent.h:
+        (WebCore):
+        (InspectorFileSystemAgent):
+
 2012-06-13  Silvia Pfeiffer  <[email protected]>
 
         Change the styling of the Chromium video controls.

Modified: trunk/Source/WebCore/inspector/Inspector.json (120176 => 120177)


--- trunk/Source/WebCore/inspector/Inspector.json	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/Source/WebCore/inspector/Inspector.json	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1403,6 +1403,19 @@
     {
         "domain": "FileSystem",
         "hidden": true,
+        "types": [
+            {
+                "id": "Entry",
+                "type": "object",
+                "properties": [
+                    { "name": "url", "type": "string", "description": "filesystem: URL for the entry." },
+                    { "name": "name", "type": "string" },
+                    { "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." }
+                ]
+            }
+        ],
         "commands": [
             {
                 "name": "enable",
@@ -1410,10 +1423,27 @@
             },
             {
                 "name": "disable",
-                "description": "Disables events from backend.."
+                "description": "Disables events from backend."
+            },
+            {
+                "name": "readDirectory",
+                "description": "Requests to read the directory content. Result should return on didReadDirectory event with request id.",
+                "parameters": [
+                    { "name": "requestId", "type": "integer" },
+                    { "name": "frameId", "type": "string" },
+                    { "name": "url", "type": "string" }
+                ]
             }
         ],
         "events": [
+            {
+                "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." }
+                ]
+            }
         ]
     },
     {

Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (120176 => 120177)


--- trunk/Source/WebCore/inspector/InspectorController.cpp	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp	2012-06-13 09:52:20 UTC (rev 120177)
@@ -107,7 +107,7 @@
 #endif
 
 #if ENABLE(FILE_SYSTEM)
-    m_agents.append(InspectorFileSystemAgent::create(m_instrumentingAgents.get(), m_state.get()));
+    m_agents.append(InspectorFileSystemAgent::create(m_instrumentingAgents.get(), pageAgent, m_state.get()));
 #endif
     OwnPtr<InspectorDOMStorageAgent> domStorageAgentPtr(InspectorDOMStorageAgent::create(m_instrumentingAgents.get(), m_state.get()));
     InspectorDOMStorageAgent* domStorageAgent = domStorageAgentPtr.get();

Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp (120176 => 120177)


--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.cpp	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -35,9 +35,26 @@
 #include "InspectorFileSystemAgent.h"
 
 #include "DOMFileSystem.h"
+#include "DirectoryEntry.h"
+#include "DirectoryReader.h"
+#include "Document.h"
+#include "EntriesCallback.h"
+#include "EntryArray.h"
+#include "EntryCallback.h"
+#include "ErrorCallback.h"
+#include "FileError.h"
+#include "FileSystemCallback.h"
+#include "FileSystemCallbacks.h"
+#include "Frame.h"
+#include "InspectorPageAgent.h"
 #include "InspectorState.h"
 #include "InstrumentingAgents.h"
+#include "KURL.h"
+#include "LocalFileSystem.h"
+#include "MIMETypeRegistry.h"
 
+using WebCore::TypeBuilder::Array;
+
 namespace WebCore {
 
 namespace FileSystemAgentState {
@@ -45,7 +62,8 @@
 }
 
 class InspectorFileSystemAgent::FrontendProvider : public RefCounted<FrontendProvider> {
-  public:
+    WTF_MAKE_NONCOPYABLE(FrontendProvider);
+public:
     static PassRefPtr<FrontendProvider> create(InspectorFileSystemAgent* agent, InspectorFrontend::FileSystem* frontend)
     {
         return adoptRef(new FrontendProvider(agent, frontend));
@@ -64,7 +82,7 @@
         m_frontend = 0;
     }
 
-  private:
+private:
     FrontendProvider(InspectorFileSystemAgent* agent, InspectorFrontend::FileSystem* frontend)
         : m_agent(agent)
         , m_frontend(frontend) { }
@@ -73,10 +91,198 @@
     InspectorFrontend::FileSystem* m_frontend;
 };
 
+typedef InspectorFileSystemAgent::FrontendProvider FrontendProvider;
+
+namespace {
+
+class ReadDirectoryTask : public RefCounted<ReadDirectoryTask> {
+    WTF_MAKE_NONCOPYABLE(ReadDirectoryTask);
+public:
+    static PassRefPtr<ReadDirectoryTask> create(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url)
+    {
+        return adoptRef(new ReadDirectoryTask(frontendProvider, requestId, url));
+    }
+
+    virtual ~ReadDirectoryTask()
+    {
+        reportResult(FileError::ABORT_ERR, 0);
+    }
+
+    void start(ScriptExecutionContext*);
+
+private:
+    class ErrorCallback;
+    class GetEntryCallback;
+    class ReadDirectoryEntriesCallback;
+
+    void gotEntry(Entry*);
+    void didReadDirectoryEntries(EntryArray*);
+
+    void reportResult(FileError::ErrorCode errorCode, PassRefPtr<Array<TypeBuilder::FileSystem::Entry> > entries)
+    {
+        if (!m_frontendProvider || !m_frontendProvider->frontend())
+            return;
+        m_frontendProvider->frontend()->didReadDirectory(m_requestId, static_cast<int>(errorCode), entries);
+        m_frontendProvider = 0;
+    }
+
+    ReadDirectoryTask(PassRefPtr<FrontendProvider> frontendProvider, int requestId, const String& url)
+        : m_frontendProvider(frontendProvider)
+        , m_requestId(requestId)
+        , m_url(ParsedURLString, url) { }
+
+    void readDirectoryEntries();
+
+    RefPtr<FrontendProvider> m_frontendProvider;
+    int m_requestId;
+    KURL m_url;
+    RefPtr<Array<TypeBuilder::FileSystem::Entry> > m_entries;
+    RefPtr<DirectoryReader> m_directoryReader;
+};
+
+class ReadDirectoryTask::ErrorCallback : public WebCore::ErrorCallback {
+    WTF_MAKE_NONCOPYABLE(ErrorCallback);
+public:
+    static PassRefPtr<ReadDirectoryTask::ErrorCallback> create(PassRefPtr<ReadDirectoryTask> readDirectoryTask)
+    {
+        return adoptRef(new ReadDirectoryTask::ErrorCallback(readDirectoryTask));
+    }
+
+    virtual bool handleEvent(FileError* error) OVERRIDE
+    {
+        if (m_readDirectoryTask)
+            m_readDirectoryTask->reportResult(error->code(), 0);
+        return true;
+    }
+
+private:
+    ErrorCallback(PassRefPtr<ReadDirectoryTask> readDirectoryTask)
+        : m_readDirectoryTask(readDirectoryTask) { }
+    RefPtr<ReadDirectoryTask> m_readDirectoryTask;
+};
+
+class ReadDirectoryTask::GetEntryCallback : public EntryCallback {
+    WTF_MAKE_NONCOPYABLE(GetEntryCallback);
+public:
+    static PassRefPtr<ReadDirectoryTask::GetEntryCallback> create(PassRefPtr<ReadDirectoryTask> readDirectoryTask)
+    {
+        return adoptRef(new ReadDirectoryTask::GetEntryCallback(readDirectoryTask));
+    }
+
+    virtual bool handleEvent(Entry* fileSystem) OVERRIDE
+    {
+        m_readDirectoryTask->gotEntry(fileSystem);
+        return true;
+    }
+
+private:
+    GetEntryCallback(PassRefPtr<ReadDirectoryTask> readDirectoryTask)
+        : m_readDirectoryTask(readDirectoryTask) { }
+    RefPtr<ReadDirectoryTask> m_readDirectoryTask;
+};
+
+class ReadDirectoryTask::ReadDirectoryEntriesCallback : public EntriesCallback {
+    WTF_MAKE_NONCOPYABLE(ReadDirectoryEntriesCallback);
+public:
+    static PassRefPtr<ReadDirectoryTask::ReadDirectoryEntriesCallback> create(PassRefPtr<ReadDirectoryTask> readDirectoryTask)
+    {
+        return adoptRef(new ReadDirectoryTask::ReadDirectoryEntriesCallback(readDirectoryTask));
+    }
+
+    virtual bool handleEvent(EntryArray* entries) OVERRIDE
+    {
+        ASSERT(entries);
+        m_readDirectoryTask->didReadDirectoryEntries(entries);
+        return true;
+    }
+
+private:
+    ReadDirectoryEntriesCallback(PassRefPtr<ReadDirectoryTask> readDirectoryTask)
+        : m_readDirectoryTask(readDirectoryTask) { }
+    RefPtr<ReadDirectoryTask> m_readDirectoryTask;
+};
+
+void ReadDirectoryTask::start(ScriptExecutionContext* scriptExecutionContext)
+{
+    ASSERT(scriptExecutionContext);
+
+    FileSystemType type;
+    String path;
+    if (!DOMFileSystemBase::crackFileSystemURL(m_url, type, path)) {
+        reportResult(FileError::SYNTAX_ERR, 0);
+        return;
+    }
+
+    RefPtr<EntryCallback> successCallback = ReadDirectoryTask::GetEntryCallback::create(this);
+    RefPtr<ErrorCallback> errorCallback = ReadDirectoryTask::ErrorCallback::create(this);
+    OwnPtr<ResolveURICallbacks> fileSystemCallbacks = ResolveURICallbacks::create(successCallback, errorCallback, scriptExecutionContext, type, path);
+
+    LocalFileSystem::localFileSystem().readFileSystem(scriptExecutionContext, type, fileSystemCallbacks.release());
+}
+
+void ReadDirectoryTask::gotEntry(Entry* entry)
+{
+    if (!entry->isDirectory()) {
+        reportResult(FileError::TYPE_MISMATCH_ERR, 0);
+        return;
+    }
+
+    m_directoryReader = static_cast<DirectoryEntry*>(entry)->createReader();
+    m_entries = Array<TypeBuilder::FileSystem::Entry>::create();
+    readDirectoryEntries();
+}
+
+void ReadDirectoryTask::readDirectoryEntries()
+{
+    if (!m_directoryReader->filesystem()->scriptExecutionContext()) {
+        reportResult(FileError::ABORT_ERR, 0);
+        return;
+    }
+
+    RefPtr<EntriesCallback> successCallback = ReadDirectoryTask::ReadDirectoryEntriesCallback::create(this);
+    RefPtr<ErrorCallback> errorCallback = ReadDirectoryTask::ErrorCallback::create(this);
+    m_directoryReader->readEntries(successCallback, errorCallback);
+}
+
+void ReadDirectoryTask::didReadDirectoryEntries(EntryArray* entries)
+{
+    if (!entries->length()) {
+        reportResult(static_cast<FileError::ErrorCode>(0), m_entries);
+        return;
+    }
+
+    for (unsigned i = 0; i < entries->length(); ++i) {
+        Entry* entry = entries->item(i);
+        RefPtr<TypeBuilder::FileSystem::Entry> entryForFrontend = TypeBuilder::FileSystem::Entry::create().setUrl(entry->toURL()).setName(entry->name()).setIsDirectory(entry->isDirectory());
+
+        using TypeBuilder::Page::ResourceType;
+        if (!entry->isDirectory()) {
+            String mimeType = MIMETypeRegistry::getMIMETypeForPath(entry->name());
+            ResourceType::Enum resourceType;
+            if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
+                resourceType = ResourceType::Image;
+            else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType))
+                resourceType = ResourceType::Script;
+            else if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
+                resourceType = ResourceType::Document;
+            else
+                resourceType = ResourceType::Other;
+
+            entryForFrontend->setMimeType(mimeType);
+            entryForFrontend->setResourceType(resourceType);
+        }
+
+        m_entries->addItem(entryForFrontend);
+    }
+    readDirectoryEntries();
+}
+
+}
+
 // static
-PassOwnPtr<InspectorFileSystemAgent> InspectorFileSystemAgent::create(InstrumentingAgents* instrumentingAgents, InspectorState* state)
+PassOwnPtr<InspectorFileSystemAgent> InspectorFileSystemAgent::create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorState* state)
 {
-    return adoptPtr(new InspectorFileSystemAgent(instrumentingAgents, state));
+    return adoptPtr(new InspectorFileSystemAgent(instrumentingAgents, pageAgent, state));
 }
 
 InspectorFileSystemAgent::~InspectorFileSystemAgent()
@@ -102,6 +308,21 @@
     m_state->setBoolean(FileSystemAgentState::fileSystemAgentEnabled, m_enabled);
 }
 
+void InspectorFileSystemAgent::readDirectory(ErrorString*, int requestId, const String& frameId, const String& url)
+{
+    if (!m_enabled || !m_frontendProvider)
+        return;
+    ASSERT(m_frontendProvider->frontend());
+
+    Frame* frame = m_pageAgent->frameForId(frameId);
+    if (!frame) {
+        m_frontendProvider->frontend()->didReadDirectory(requestId, static_cast<int>(FileError::ABORT_ERR), 0);
+        return;
+    }
+
+    ReadDirectoryTask::create(m_frontendProvider, requestId, url)->start(frame->document());
+}
+
 void InspectorFileSystemAgent::setFrontend(InspectorFrontend* frontend)
 {
     ASSERT(frontend);
@@ -123,8 +344,9 @@
     m_enabled = m_state->getBoolean(FileSystemAgentState::fileSystemAgentEnabled);
 }
 
-InspectorFileSystemAgent::InspectorFileSystemAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state)
+InspectorFileSystemAgent::InspectorFileSystemAgent(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorState* state)
     : InspectorBaseAgent<InspectorFileSystemAgent>("FileSystem", instrumentingAgents, state)
+    , m_pageAgent(pageAgent)
     , m_enabled(false)
 {
     ASSERT(instrumentingAgents);

Modified: trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h (120176 => 120177)


--- trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h	2012-06-13 09:49:50 UTC (rev 120176)
+++ trunk/Source/WebCore/inspector/InspectorFileSystemAgent.h	2012-06-13 09:52:20 UTC (rev 120177)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -40,8 +40,10 @@
 #include <wtf/PassRefPtr.h>
 
 namespace WebCore {
+
 class DOMFileSystem;
 class InspectorFrontend;
+class InspectorPageAgent;
 class InspectorState;
 class InstrumentingAgents;
 
@@ -49,18 +51,21 @@
 public:
     class FrontendProvider;
 
-    static PassOwnPtr<InspectorFileSystemAgent> create(InstrumentingAgents*, InspectorState*);
+    static PassOwnPtr<InspectorFileSystemAgent> create(InstrumentingAgents*, InspectorPageAgent*, InspectorState*);
     virtual ~InspectorFileSystemAgent();
 
-    virtual void enable(ErrorString*);
-    virtual void disable(ErrorString*);
+    virtual void enable(ErrorString*) OVERRIDE;
+    virtual void disable(ErrorString*) OVERRIDE;
 
-    virtual void setFrontend(InspectorFrontend*);
-    virtual void clearFrontend();
-    virtual void restore();
+    virtual void readDirectory(ErrorString*, int requestId, const String& frameId, const String& url) OVERRIDE;
+
+    virtual void setFrontend(InspectorFrontend*) OVERRIDE;
+    virtual void clearFrontend() OVERRIDE;
+    virtual void restore() OVERRIDE;
 private:
-    InspectorFileSystemAgent(InstrumentingAgents*, InspectorState*);
+    InspectorFileSystemAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorState*);
 
+    InspectorPageAgent* m_pageAgent;
     RefPtr<FrontendProvider> m_frontendProvider;
     bool m_enabled;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to