Changeset 81640 in webkit


Ignore:
Timestamp:
Mar 21, 2011 8:35:06 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-03-21 Adam Klein <adamk@chromium.org>

Reviewed by David Levin.

[fileapi] Add URI resolution support to WorkerContext
https://bugs.webkit.org/show_bug.cgi?id=55644

Note that these tests do not run as part of new-run-webkit-tests,
but rather in Chromium's ui_test. I've run them locally and confirmed
they pass; a subsequent Chromium change will be submitted to run them
on the Chromium build bots.

  • http/tests/filesystem/resources/fs-worker-common.js: Added.
  • http/tests/filesystem/resources/fs-worker-test-util.js: Added. Copied from fast/filesystem/resources for use by HTTP tests.
  • http/tests/filesystem/script-tests/resolve-uri.js: Updated to be used either in window or worker context.
  • http/tests/filesystem/workers/resolve-url-expected.txt: Added.
  • http/tests/filesystem/workers/resolve-url-sync-expected.txt: Added.
  • http/tests/filesystem/workers/resolve-url-sync.html: Added.
  • http/tests/filesystem/workers/resolve-url.html: Added.
  • http/tests/filesystem/workers/script-tests/TEMPLATE.html: Added.
  • http/tests/filesystem/workers/script-tests/resolve-url-sync.js: Added.

2011-03-21 Adam Klein <adamk@chromium.org>

Reviewed by David Levin.

[fileapi] Add URI resolution support to WorkerContext
https://bugs.webkit.org/show_bug.cgi?id=55644

Tests: http/tests/filesystem/workers/resolve-url-sync.html

http/tests/filesystem/workers/resolve-url.html

  • fileapi/LocalFileSystem.cpp: (WebCore::LocalFileSystem::readFileSystem): Add support for workers.
  • fileapi/LocalFileSystem.h:
  • workers/WorkerContext.cpp: (WebCore::WorkerContext::resolveLocalFileSystemURL): (WebCore::WorkerContext::resolveLocalFileSystemSyncURL):
  • workers/WorkerContext.h:
  • workers/WorkerContext.idl:

2011-03-21 Adam Klein <adamk@chromium.org>

Reviewed by David Levin.

[fileapi] Add URI resolution support to WorkerContext
https://bugs.webkit.org/show_bug.cgi?id=55644

Pass "create" bool through to allow opening
a filesystem without allowing creation.

  • src/LocalFileSystemChromium.cpp: (WebCore::LocalFileSystem::readFileSystem): (WebCore::LocalFileSystem::requestFileSystem):
  • src/WebWorkerBase.cpp: (WebKit::WebWorkerBase::openFileSystemForWorker):
  • src/WebWorkerBase.h:
  • src/WorkerFileSystemCallbacksBridge.cpp: (WebKit::WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread): (WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
  • src/WorkerFileSystemCallbacksBridge.h:
Location:
trunk
Files:
10 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r81639 r81640  
     12011-03-21  Adam Klein  <adamk@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        [fileapi] Add URI resolution support to WorkerContext
     6        https://bugs.webkit.org/show_bug.cgi?id=55644
     7
     8        Note that these tests do not run as part of new-run-webkit-tests,
     9        but rather in Chromium's ui_test. I've run them locally and confirmed
     10        they pass; a subsequent Chromium change will be submitted to run them
     11        on the Chromium build bots.
     12
     13        * http/tests/filesystem/resources/fs-worker-common.js: Added.
     14        * http/tests/filesystem/resources/fs-worker-test-util.js: Added.
     15        Copied from fast/filesystem/resources for use by HTTP tests.
     16        * http/tests/filesystem/script-tests/resolve-uri.js:
     17        Updated to be used either in window or worker context.
     18        * http/tests/filesystem/workers/resolve-url-expected.txt: Added.
     19        * http/tests/filesystem/workers/resolve-url-sync-expected.txt: Added.
     20        * http/tests/filesystem/workers/resolve-url-sync.html: Added.
     21        * http/tests/filesystem/workers/resolve-url.html: Added.
     22        * http/tests/filesystem/workers/script-tests/TEMPLATE.html: Added.
     23        * http/tests/filesystem/workers/script-tests/resolve-url-sync.js: Added.
     24
    1252011-03-21  David Levin  <levin@chromium.org>
    226
  • trunk/LayoutTests/http/tests/filesystem/script-tests/resolve-uri.js

    r81438 r81640  
     1if (this.importScripts) {
     2    importScripts('../resources/fs-worker-common.js');
     3    importScripts('../resources/fs-test-util.js');
     4}
     5
    16description("Tests using resolveLocalFileSystemURL to obtain an Entry from a URL");
    27
     
    164169}
    165170
    166 if (window.requestFileSystem) {
    167     window.jsTestIsAsync = true;
    168     requestFileSystem(window.TEMPORARY, 100, fileSystemCallback, errorCallback);
     171if (this.requestFileSystem) {
     172    jsTestIsAsync = true;
     173    requestFileSystem(this.TEMPORARY, 100, fileSystemCallback, errorCallback);
    169174} else
    170175    debug("This test requires FileSystem API support.");
    171176
    172 window.successfullyParsed = true;
     177var successfullyParsed = true;
  • trunk/Source/WebCore/ChangeLog

    r81639 r81640  
     12011-03-21  Adam Klein  <adamk@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        [fileapi] Add URI resolution support to WorkerContext
     6        https://bugs.webkit.org/show_bug.cgi?id=55644
     7
     8        Tests: http/tests/filesystem/workers/resolve-url-sync.html
     9               http/tests/filesystem/workers/resolve-url.html
     10
     11        * fileapi/LocalFileSystem.cpp:
     12        (WebCore::LocalFileSystem::readFileSystem):
     13        Add support for workers.
     14        * fileapi/LocalFileSystem.h:
     15        * workers/WorkerContext.cpp:
     16        (WebCore::WorkerContext::resolveLocalFileSystemURL):
     17        (WebCore::WorkerContext::resolveLocalFileSystemSyncURL):
     18        * workers/WorkerContext.h:
     19        * workers/WorkerContext.idl:
     20
    1212011-03-21  David Levin  <levin@chromium.org>
    222
  • trunk/Source/WebCore/fileapi/LocalFileSystem.cpp

    r79917 r81640  
    8282}
    8383
    84 void LocalFileSystem::readFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
     84void LocalFileSystem::readFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool)
    8585{
    8686    // AsyncFileSystem::openFileSystem calls callbacks synchronously, so the method needs to be called asynchronously.
  • trunk/Source/WebCore/fileapi/LocalFileSystem.h

    r79917 r81640  
    5555
    5656    // Does not create the root path for file system, just reads it if available.
    57     void readFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, PassOwnPtr<AsyncFileSystemCallbacks>);
     57    void readFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, PassOwnPtr<AsyncFileSystemCallbacks>, bool synchronous = false);
    5858
    5959    void requestFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, long long size, PassOwnPtr<AsyncFileSystemCallbacks>, bool synchronous = false);
  • trunk/Source/WebCore/workers/WorkerContext.cpp

    r77563 r81640  
    6868#if ENABLE(FILE_SYSTEM)
    6969#include "AsyncFileSystem.h"
     70#include "DirectoryEntrySync.h"
    7071#include "DOMFileSystem.h"
     72#include "DOMFileSystemBase.h"
    7173#include "DOMFileSystemSync.h"
    7274#include "ErrorCallback.h"
     75#include "FileEntrySync.h"
    7376#include "FileError.h"
    7477#include "FileException.h"
     
    378381}
    379382
     383void WorkerContext::resolveLocalFileSystemURL(const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
     384{
     385    KURL completedURL = completeURL(url);
     386    if (!AsyncFileSystem::isAvailable() || !securityOrigin()->canAccessFileSystem() || !securityOrigin()->canRequest(completedURL)) {
     387        DOMFileSystem::scheduleCallback(this, errorCallback, FileError::create(FileError::SECURITY_ERR));
     388        return;
     389    }
     390
     391    AsyncFileSystem::Type type;
     392    String filePath;
     393    if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(completedURL, type, filePath)) {
     394        DOMFileSystem::scheduleCallback(this, errorCallback, FileError::create(FileError::SYNTAX_ERR));
     395        return;
     396    }
     397
     398    LocalFileSystem::localFileSystem().readFileSystem(this, type, ResolveURICallbacks::create(successCallback, errorCallback, this, filePath));
     399}
     400
     401PassRefPtr<EntrySync> WorkerContext::resolveLocalFileSystemSyncURL(const String& url, ExceptionCode& ec)
     402{
     403    ec = 0;
     404    KURL completedURL = completeURL(url);
     405    if (!AsyncFileSystem::isAvailable() || !securityOrigin()->canAccessFileSystem() || !securityOrigin()->canRequest(completedURL)) {
     406        ec = FileException::SECURITY_ERR;
     407        return 0;
     408    }
     409
     410    AsyncFileSystem::Type type;
     411    String filePath;
     412    if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(completedURL, type, filePath)) {
     413        ec = FileException::SYNTAX_ERR;
     414        return 0;
     415    }
     416
     417    FileSystemSyncCallbackHelper readFileSystemHelper;
     418    LocalFileSystem::localFileSystem().readFileSystem(this, type, FileSystemCallbacks::create(readFileSystemHelper.successCallback(), readFileSystemHelper.errorCallback(), this), true);
     419    RefPtr<DOMFileSystemSync> fileSystem = readFileSystemHelper.getResult(ec);
     420    if (!fileSystem)
     421        return 0;
     422
     423    RefPtr<EntrySync> entry = fileSystem->root()->getDirectory(filePath, 0, ec);
     424    if (ec == FileException::TYPE_MISMATCH_ERR)
     425        return fileSystem->root()->getFile(filePath, 0, ec);
     426
     427    return entry.release();
     428}
     429
    380430COMPILE_ASSERT(static_cast<int>(WorkerContext::TEMPORARY) == static_cast<int>(AsyncFileSystem::Temporary), enum_mismatch);
    381431COMPILE_ASSERT(static_cast<int>(WorkerContext::PERSISTENT) == static_cast<int>(AsyncFileSystem::Persistent), enum_mismatch);
  • trunk/Source/WebCore/workers/WorkerContext.h

    r76248 r81640  
    5151    class DatabaseCallback;
    5252    class DatabaseSync;
     53    class EntryCallback;
     54    class EntrySync;
    5355    class ErrorCallback;
    5456    class FileSystemCallback;
     
    130132            PERSISTENT,
    131133        };
    132         void requestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>);
     134        void requestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback>);
    133135        PassRefPtr<DOMFileSystemSync> requestFileSystemSync(int type, long long size, ExceptionCode&);
     136        void resolveLocalFileSystemURL(const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback>);
     137        PassRefPtr<EntrySync> resolveLocalFileSystemSyncURL(const String& url, ExceptionCode&);
    134138#endif
    135139
  • trunk/Source/WebCore/workers/WorkerContext.idl

    r78407 r81640  
    111111        [EnabledAtRuntime=FileSystem] void requestFileSystem(in unsigned short type, in long long size, in [Callback, Optional] FileSystemCallback successCallback, in [Callback, Optional] ErrorCallback errorCallback);
    112112        [EnabledAtRuntime=FileSystem] DOMFileSystemSync requestFileSystemSync(in unsigned short type, in long long size) raises (FileException);
     113        [EnabledAtRuntime=FileSystem] void resolveLocalFileSystemURL(in DOMString url, in [Callback, Optional] EntryCallback successCallback, in [Callback, Optional] ErrorCallback errorCallback);
     114        [EnabledAtRuntime=FileSystem] EntrySync resolveLocalFileSystemSyncURL(in DOMString url) raises (FileException);
    113115
    114116                 attribute [EnabledAtRuntime=FileSystem] FlagsConstructor Flags;
  • trunk/Source/WebKit/chromium/ChangeLog

    r81637 r81640  
     12011-03-21  Adam Klein  <adamk@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        [fileapi] Add URI resolution support to WorkerContext
     6        https://bugs.webkit.org/show_bug.cgi?id=55644
     7
     8        Pass "create" bool through to allow opening
     9        a filesystem without allowing creation.
     10
     11        * src/LocalFileSystemChromium.cpp:
     12        (WebCore::LocalFileSystem::readFileSystem):
     13        (WebCore::LocalFileSystem::requestFileSystem):
     14        * src/WebWorkerBase.cpp:
     15        (WebKit::WebWorkerBase::openFileSystemForWorker):
     16        * src/WebWorkerBase.h:
     17        * src/WorkerFileSystemCallbacksBridge.cpp:
     18        (WebKit::WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread):
     19        (WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread):
     20        * src/WorkerFileSystemCallbacksBridge.h:
     21
    1222011-03-21  Ilya Sherman  <isherman@chromium.org>
    223
  • trunk/Source/WebKit/chromium/src/LocalFileSystemChromium.cpp

    r79917 r81640  
    5858}
    5959
    60 void LocalFileSystem::readFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
    61 {
    62     ASSERT(context && context->isDocument());
    63     Document* document = static_cast<Document*>(context);
    64     WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
    65     webFrame->client()->openFileSystem(webFrame, static_cast<WebFileSystem::Type>(type), 0, false, new WebFileSystemCallbacksImpl(callbacks, type));
    66 }
     60namespace {
    6761
    68 void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool synchronous)
     62enum CreationFlag {
     63    OpenExisting,
     64    CreateIfNotPresent
     65};
     66
     67} // namespace
     68
     69static void openFileSystemHelper(ScriptExecutionContext* context, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool synchronous, long long size, CreationFlag create)
    6970{
    7071    ASSERT(context);
     
    7273        Document* document = static_cast<Document*>(context);
    7374        WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
    74         webFrame->client()->openFileSystem(webFrame, static_cast<WebFileSystem::Type>(type), size, true, new WebFileSystemCallbacksImpl(callbacks, type));
     75        webFrame->client()->openFileSystem(webFrame, static_cast<WebFileSystem::Type>(type), size, create == CreateIfNotPresent, new WebFileSystemCallbacksImpl(callbacks, type));
    7576    } else {
    7677        WorkerContext* workerContext = static_cast<WorkerContext*>(context);
    7778        WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
    7879        WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy);
    79         webWorker->openFileSystemForWorker(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks, type, context, synchronous), synchronous);
     80        webWorker->openFileSystemForWorker(static_cast<WebFileSystem::Type>(type), size, create == CreateIfNotPresent, new WebFileSystemCallbacksImpl(callbacks, type, context, synchronous), synchronous);
    8081    }
     82}
     83
     84void LocalFileSystem::readFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool synchronous)
     85{
     86    openFileSystemHelper(context, type, callbacks, synchronous, 0, OpenExisting);
     87}
     88
     89void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks, bool synchronous)
     90{
     91    openFileSystemHelper(context, type, callbacks, synchronous, size, CreateIfNotPresent);
    8192}
    8293
  • trunk/Source/WebKit/chromium/src/WebWorkerBase.cpp

    r81567 r81640  
    238238
    239239#if ENABLE(FILE_SYSTEM)
    240 void WebWorkerBase::openFileSystemForWorker(WebFileSystem::Type type, long long size, WebFileSystemCallbacks* callbacks, bool synchronous)
     240void WebWorkerBase::openFileSystemForWorker(WebFileSystem::Type type, long long size, bool create, WebFileSystemCallbacks* callbacks, bool synchronous)
    241241{
    242242    WorkerRunLoop& runLoop = m_workerThread->runLoop();
     
    249249
    250250    RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, workerContext, callbacks);
    251     bridge->postOpenFileSystemToMainThread(commonClient(), type, size, mode);
     251    bridge->postOpenFileSystemToMainThread(commonClient(), type, size, create, mode);
    252252
    253253    if (synchronous) {
  • trunk/Source/WebKit/chromium/src/WebWorkerBase.h

    r79354 r81640  
    9393
    9494#if ENABLE(FILE_SYSTEM)
    95     void openFileSystemForWorker(WebFileSystem::Type, long long size, WebFileSystemCallbacks*, bool synchronous);
     95    void openFileSystemForWorker(WebFileSystem::Type, long long size, bool create, WebFileSystemCallbacks*, bool synchronous);
    9696#endif
    9797
  • trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp

    r81599 r81640  
    152152}
    153153
    154 void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, const String& mode)
    155 {
    156     dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode));
     154void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, const String& mode)
     155{
     156    dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, create, this, mode));
    157157}
    158158
     
    214214}
    215215
    216 void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
     216void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, bool create, WorkerFileSystemCallbacksBridge* bridge, const String& mode)
    217217{
    218218    if (!commonClient)
    219219        bridge->didFailOnMainThread(WebFileErrorAbort, mode);
    220220    else {
    221         commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
     221        commonClient->openFileSystem(type, size, create, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode));
    222222    }
    223223}
  • trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h

    r81567 r81640  
    8585
    8686    // Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread.
    87     void postOpenFileSystemToMainThread(WebCommonWorkerClient*, WebFileSystem::Type, long long size, const String& mode);
     87    void postOpenFileSystemToMainThread(WebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, const String& mode);
    8888    void postMoveToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode);
    8989    void postCopyToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode);
     
    108108
    109109    // Methods that are to be called on the main thread.
    110     static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, WorkerFileSystemCallbacksBridge*, const String& mode);
     110    static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, bool create, WorkerFileSystemCallbacksBridge*, const String& mode);
    111111    static void moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
    112112    static void copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode);
Note: See TracChangeset for help on using the changeset viewer.