Changeset 55823 in webkit


Ignore:
Timestamp:
Mar 10, 2010 6:18:41 PM (14 years ago)
Author:
dumi@chromium.org
Message:

WebCore: Adding support for the optional creation callback that could be
passed to openDatabase().

Reviewed by Adam Barth.

Tests: storage/open-database-creation-callback.html

storage/open-database-creation-callback-isolated-world.html

https://bugs.webkit.org/show_bug.cgi?id=34726

  • Android.jscbindings.mk
  • Android.v8bindings.mk
  • GNUmakefile.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::JSDOMWindow::openDatabase):

  • bindings/js/JSDatabaseCallback.cpp: Added.

(WebCore::JSDatabaseCallback::JSDatabaseCallback):
(WebCore::JSDatabaseCallback::~JSDatabaseCallback):
(WebCore::JSDatabaseCallback::handleEvent):

  • bindings/js/JSDatabaseCallback.h: Added.

(WebCore::JSDatabaseCallback::create):

  • bindings/v8/custom/V8DOMWindowCustom.cpp:

(WebCore::V8DOMWindow::openDatabaseCallback):

  • bindings/v8/custom/V8DatabaseCallback.cpp: Added.

(WebCore::V8DatabaseCallback::V8DatabaseCallback):
(WebCore::V8DatabaseCallback::~V8DatabaseCallback):
(WebCore::V8DatabaseCallback::handleEvent):

  • bindings/v8/custom/V8DatabaseCallback.h: Added.

(WebCore::V8DatabaseCallback::create):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::openDatabase):

  • page/DOMWindow.h:
  • page/DOMWindow.idl:
  • storage/Database.cpp:

(WebCore::DatabaseCreationCallbackTask::create):
(WebCore::DatabaseCreationCallbackTask::performTask):
(WebCore::DatabaseCreationCallbackTask::DatabaseCreationCallbackTask):
(WebCore::Database::openDatabase):
(WebCore::Database::Database):
(WebCore::Database::performOpenAndVerify):
(WebCore::Database::performCreationCallback):

  • storage/Database.h:

(WebCore::Database::isNew):

  • storage/DatabaseCallback.h: Added.

(WebCore::DatabaseCallback::~DatabaseCallback):

  • workers/WorkerContext.cpp:

(WebCore::WorkerContext::openDatabase):

  • workers/WorkerContext.h:

LayoutTests: Adding a test to test the creation callback passed to
openDatabase() and another one to make sure it is executed in the
correct world.

Reviewed by Adam Barth.

Also, fixing fast/frames/sandboxed-iframe-storage.html: calling
openDatabase() without at least 4 parameters should always fail,
because the database name, version, description and estimated size
are not optional according to the spec.

https://bugs.webkit.org/show_bug.cgi?id=34726

  • fast/frames/resources/sandboxed-iframe-storage-allowed.html:
  • fast/frames/resources/sandboxed-iframe-storage-disallowed.html:
  • fast/frames/sandboxed-iframe-storage-expected.txt:
  • platform/qt/Skipped:
  • storage/open-database-creation-callback-expected.txt: Added.
  • storage/open-database-creation-callback.html: Added.
  • storage/open-database-creation-callback-isolated-world-expected.txt: Added.
  • storage/open-database-creation-callback-isolated-world.html: Added.
Location:
trunk
Files:
9 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r55822 r55823  
     12010-03-08  Dumitru Daniliuc  <dumi@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Adding a test to test the creation callback passed to
     6        openDatabase() and another one to make sure it is executed in the
     7        correct world.
     8
     9        Also, fixing fast/frames/sandboxed-iframe-storage.html: calling
     10        openDatabase() without at least 4 parameters should always fail,
     11        because the database name, version, description and estimated size
     12        are not optional according to the spec.
     13
     14        https://bugs.webkit.org/show_bug.cgi?id=34726
     15
     16        * fast/frames/resources/sandboxed-iframe-storage-allowed.html:
     17        * fast/frames/resources/sandboxed-iframe-storage-disallowed.html:
     18        * fast/frames/sandboxed-iframe-storage-expected.txt:
     19        * platform/qt/Skipped:
     20        * storage/open-database-creation-callback-expected.txt: Added.
     21        * storage/open-database-creation-callback.html: Added.
     22        * storage/open-database-creation-callback-isolated-world-expected.txt: Added.
     23        * storage/open-database-creation-callback-isolated-world.html: Added.
     24 
    1252010-03-10  Justin Schuh  <jschuh@chromium.org>
    226
  • trunk/LayoutTests/fast/frames/resources/sandboxed-iframe-storage-allowed.html

    r55635 r55823  
    77
    88window.onload = function() {
    9     shouldBeTrue("window.openDatabase() != null");
     9    shouldBeTrue("window.openDatabase('SandboxedIframeStorageAllowed', '1.0', '', 1) != null");
    1010    shouldBeTrue("window.localStorage != null");
    1111    shouldBeTrue("window.sessionStorage != null");
  • trunk/LayoutTests/fast/frames/resources/sandboxed-iframe-storage-disallowed.html

    r55635 r55823  
    77
    88window.onload = function() {
    9     shouldBeTrue("window.openDatabase() == null");
     9    shouldBeTrue("window.openDatabase('SandboxedIframeStorageDisallowed', '1.0', '', 1) == null");
    1010    shouldBeTrue("window.localStorage == null");
    1111    shouldBeTrue("window.sessionStorage == null");
  • trunk/LayoutTests/fast/frames/sandboxed-iframe-storage-expected.txt

    r55635 r55823  
    1515Frame: '<!--framePath //<!--frame0-->-->'
    1616--------
    17 PASS window.openDatabase() == null is true
     17PASS window.openDatabase('SandboxedIframeStorageDisallowed', '1.0', '', 1) == null is true
    1818PASS window.localStorage == null is true
    1919PASS window.sessionStorage == null is true
     
    2323Frame: '<!--framePath //<!--frame1-->-->'
    2424--------
    25 PASS window.openDatabase() != null is true
     25PASS window.openDatabase('SandboxedIframeStorageAllowed', '1.0', '', 1) != null is true
    2626PASS window.localStorage != null is true
    2727PASS window.sessionStorage != null is true
  • trunk/WebCore/Android.jscbindings.mk

    r55635 r55823  
    8181        bindings/js/JSCustomSQLTransactionErrorCallback.cpp \
    8282        bindings/js/JSCustomVoidCallback.cpp \
     83        bindings/js/JSDatabaseCallback.cpp \
    8384        bindings/js/JSDesktopNotificationsCustom.cpp \
    8485        bindings/js/JSDOMApplicationCacheCustom.cpp \
  • trunk/WebCore/Android.v8bindings.mk

    r55798 r55823  
    108108        bindings/v8/custom/V8DOMWindowCustom.cpp \
    109109        bindings/v8/custom/V8DataGridColumnListCustom.cpp \
     110        bindings/v8/custom/V8DatabaseCallback.cpp \
    110111        bindings/v8/custom/V8DatabaseCustom.cpp \
    111112        bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp \
  • trunk/WebCore/ChangeLog

    r55822 r55823  
     12010-03-08  Dumitru Daniliuc  <dumi@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Adding support for the optional creation callback that could be
     6        passed to openDatabase().
     7
     8        Tests: storage/open-database-creation-callback.html
     9               storage/open-database-creation-callback-isolated-world.html
     10
     11        https://bugs.webkit.org/show_bug.cgi?id=34726
     12
     13        * Android.jscbindings.mk
     14        * Android.v8bindings.mk
     15        * GNUmakefile.am:
     16        * WebCore.gypi:
     17        * WebCore.pro:
     18        * WebCore.vcproj/WebCore.vcproj:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * bindings/js/JSDOMWindowCustom.cpp:
     21        (WebCore::JSDOMWindow::openDatabase):
     22        * bindings/js/JSDatabaseCallback.cpp: Added.
     23        (WebCore::JSDatabaseCallback::JSDatabaseCallback):
     24        (WebCore::JSDatabaseCallback::~JSDatabaseCallback):
     25        (WebCore::JSDatabaseCallback::handleEvent):
     26        * bindings/js/JSDatabaseCallback.h: Added.
     27        (WebCore::JSDatabaseCallback::create):
     28        * bindings/v8/custom/V8DOMWindowCustom.cpp:
     29        (WebCore::V8DOMWindow::openDatabaseCallback):
     30        * bindings/v8/custom/V8DatabaseCallback.cpp: Added.
     31        (WebCore::V8DatabaseCallback::V8DatabaseCallback):
     32        (WebCore::V8DatabaseCallback::~V8DatabaseCallback):
     33        (WebCore::V8DatabaseCallback::handleEvent):
     34        * bindings/v8/custom/V8DatabaseCallback.h: Added.
     35        (WebCore::V8DatabaseCallback::create):
     36        * page/DOMWindow.cpp:
     37        (WebCore::DOMWindow::openDatabase):
     38        * page/DOMWindow.h:
     39        * page/DOMWindow.idl:
     40        * storage/Database.cpp:
     41        (WebCore::DatabaseCreationCallbackTask::create):
     42        (WebCore::DatabaseCreationCallbackTask::performTask):
     43        (WebCore::DatabaseCreationCallbackTask::DatabaseCreationCallbackTask):
     44        (WebCore::Database::openDatabase):
     45        (WebCore::Database::Database):
     46        (WebCore::Database::performOpenAndVerify):
     47        (WebCore::Database::performCreationCallback):
     48        * storage/Database.h:
     49        (WebCore::Database::isNew):
     50        * storage/DatabaseCallback.h: Added.
     51        (WebCore::DatabaseCallback::~DatabaseCallback):
     52        * workers/WorkerContext.cpp:
     53        (WebCore::WorkerContext::openDatabase):
     54        * workers/WorkerContext.h:
     55
    1562010-03-10  Justin Schuh  <jschuh@chromium.org>
    257
  • trunk/WebCore/GNUmakefile.am

    r55821 r55823  
    22422242        WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp \
    22432243        WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h \
     2244        WebCore/bindings/js/JSDatabaseCallback.cpp \
     2245        WebCore/bindings/js/JSDatabaseCallback.h \
    22442246        WebCore/bindings/js/JSDatabaseCustom.cpp \
    22452247        WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp \
     
    22622264        WebCore/storage/DatabaseAuthorizer.cpp \
    22632265        WebCore/storage/DatabaseAuthorizer.h \
     2266        WebCore/storage/DatabaseCallback.h \
    22642267        WebCore/storage/DatabaseDetails.h \
    22652268        WebCore/storage/DatabaseTask.cpp \
  • trunk/WebCore/WebCore.gypi

    r55821 r55823  
    714714            'bindings/v8/custom/V8CustomXPathNSResolver.cpp',
    715715            'bindings/v8/custom/V8CustomXPathNSResolver.h',
     716            'bindings/v8/custom/V8DatabaseCallback.cpp',
     717            'bindings/v8/custom/V8DatabaseCallback.h',
    716718            'bindings/v8/custom/V8DatabaseCustom.cpp',
    717719            'bindings/v8/custom/V8DataGridColumnListCustom.cpp',
     
    32423244            'storage/DatabaseAuthorizer.cpp',
    32433245            'storage/DatabaseAuthorizer.h',
     3246            'storage/DatabaseCallback.h',
    32443247            'storage/DatabaseDetails.h',
    32453248            'storage/DatabaseTask.cpp',
  • trunk/WebCore/WebCore.pro

    r55821 r55823  
    10201020    bindings/js/JSCustomVoidCallback.h \
    10211021    bindings/js/JSCustomXPathNSResolver.h \
     1022    bindings/js/JSDatabaseCallback.h \
    10221023    bindings/js/JSDataGridDataSource.h \
    10231024    bindings/js/JSDebugWrapperSet.h \
     
    22322233        bindings/js/JSCustomSQLTransactionCallback.cpp \
    22332234        bindings/js/JSCustomSQLTransactionErrorCallback.cpp \
     2235        bindings/js/JSDatabaseCallback.cpp \
    22342236        bindings/js/JSDatabaseCustom.cpp \
    22352237        bindings/js/JSSQLResultSetRowListCustom.cpp \
     
    22422244        storage/DatabaseAuthorizer.h \
    22432245        storage/Database.h \
     2246        storage/DatabaseCallback.h \
    22442247        storage/DatabaseTask.h \
    22452248        storage/DatabaseThread.h \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r55821 r55823  
    3539335393                                </File>
    3539435394                                <File
     35395                                        RelativePath="..\bindings\js\JSDatabaseCallback.cpp"
     35396                                        >
     35397                                </File>
     35398                                <File
     35399                                        RelativePath="..\bindings\js\JSDatabaseCallback.h"
     35400                                        >
     35401                                </File>
     35402                                <File
    3539535403                                        RelativePath="..\bindings\js\JSDatabaseCustom.cpp"
    3539635404                                        >
     
    4233042338                        </File>
    4233142339                        <File
     42340                                RelativePath="..\storage\DatabaseCallback.h"
     42341                                >
     42342                        </File>
     42343                        <File
    4233242344                                RelativePath="..\storage\DatabaseTask.cpp"
    4233342345                                >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r55821 r55823  
    41244124                B5C1123B102B6C4600096578 /* SQLTransactionCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5C11239102B6C4600096578 /* SQLTransactionCoordinator.cpp */; };
    41254125                B5C1123C102B6C4600096578 /* SQLTransactionCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = B5C1123A102B6C4600096578 /* SQLTransactionCoordinator.h */; };
     4126                B5D3601A112F8B560048DEA8 /* DatabaseCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = B5D36019112F8B560048DEA8 /* DatabaseCallback.h */; };
     4127                B5D3601D112F8BA00048DEA8 /* JSDatabaseCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = B5D3601C112F8BA00048DEA8 /* JSDatabaseCallback.h */; };
     4128                B5D3601F112F8BA80048DEA8 /* JSDatabaseCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5D3601E112F8BA80048DEA8 /* JSDatabaseCallback.cpp */; };
    41264129                B71FE6DF11091CB300DAEF77 /* PrintContext.h in Headers */ = {isa = PBXBuildFile; fileRef = B776D43A1104525D00BEB0EC /* PrintContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
    41274130                B776D43D1104527500BEB0EC /* PrintContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B776D43C1104527500BEB0EC /* PrintContext.cpp */; };
     
    94069409                B5C11239102B6C4600096578 /* SQLTransactionCoordinator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SQLTransactionCoordinator.cpp; sourceTree = "<group>"; };
    94079410                B5C1123A102B6C4600096578 /* SQLTransactionCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLTransactionCoordinator.h; sourceTree = "<group>"; };
     9411                B5D36019112F8B560048DEA8 /* DatabaseCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DatabaseCallback.h; sourceTree = "<group>"; };
     9412                B5D3601C112F8BA00048DEA8 /* JSDatabaseCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDatabaseCallback.h; sourceTree = "<group>"; };
     9413                B5D3601E112F8BA80048DEA8 /* JSDatabaseCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDatabaseCallback.cpp; sourceTree = "<group>"; };
    94089414                B776D43A1104525D00BEB0EC /* PrintContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrintContext.h; sourceTree = "<group>"; };
    94099415                B776D43C1104527500BEB0EC /* PrintContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintContext.cpp; sourceTree = "<group>"; };
     
    1061310619                                51A45B550CAD7FD7000D2BE9 /* DatabaseAuthorizer.cpp */,
    1061410620                                51A45B540CAD7FD7000D2BE9 /* DatabaseAuthorizer.h */,
     10621                                B5D36019112F8B560048DEA8 /* DatabaseCallback.h */,
    1061510622                                5116D9750CF177BD00C2B84D /* DatabaseDetails.h */,
    1061610623                                519611E90CAC749C0010A80C /* DatabaseTask.cpp */,
     
    1470614713                                1432E8480C51493F00B1500F /* GCController.cpp */,
    1470714714                                1432E8460C51493800B1500F /* GCController.h */,
     14715                                B5D3601E112F8BA80048DEA8 /* JSDatabaseCallback.cpp */,
     14716                                B5D3601C112F8BA00048DEA8 /* JSDatabaseCallback.h */,
    1470814717                                BC53DAC411432FD9000D817E /* JSDebugWrapperSet.cpp */,
    1470914718                                BC53DAC111432EEE000D817E /* JSDebugWrapperSet.h */,
     
    1867618685                                BC53DAC211432EEE000D817E /* JSDebugWrapperSet.h in Headers */,
    1867718686                                2ED609BD1145B07100C8684E /* DOMFormData.h in Headers */,
     18687                                B5D3601A112F8B560048DEA8 /* DatabaseCallback.h in Headers */,
     18688                                B5D3601D112F8BA00048DEA8 /* JSDatabaseCallback.h in Headers */,
    1867818689                        );
    1867918690                        runOnlyForDeploymentPostprocessing = 0;
     
    2087620887                                BC53DAC711433064000D817E /* JSDOMWrapper.cpp in Sources */,
    2087720888                                2ED609BC1145B07100C8684E /* DOMFormData.cpp in Sources */,
     20889                                B5D3601F112F8BA80048DEA8 /* JSDatabaseCallback.cpp in Sources */,
    2087820890                        );
    2087920891                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp

    r55637 r55823  
    2323#include "AtomicString.h"
    2424#include "Chrome.h"
     25#include "Database.h"
    2526#include "DOMWindow.h"
    2627#include "Document.h"
     
    3637#include "History.h"
    3738#include "JSAudioConstructor.h"
     39#include "JSDatabase.h"
     40#include "JSDatabaseCallback.h"
    3841#include "JSDOMWindowShell.h"
    3942#include "JSEvent.h"
     
    966969}
    967970
     971JSValue JSDOMWindow::openDatabase(ExecState* exec, const ArgList& args)
     972{
     973    if (!allowsAccessFrom(exec) || (args.size() < 4))
     974        return jsUndefined();
     975    ExceptionCode ec = 0;
     976    const UString& name = args.at(0).toString(exec);
     977    const UString& version = args.at(1).toString(exec);
     978    const UString& displayName = args.at(2).toString(exec);
     979    unsigned long estimatedSize = args.at(3).toInt32(exec);
     980    RefPtr<DatabaseCallback> creationCallback;
     981    if ((args.size() >= 5) && args.at(4).isObject())
     982        creationCallback = JSDatabaseCallback::create(asObject(args.at(4)), globalObject());
     983
     984    JSValue result = toJS(exec, globalObject(), WTF::getPtr(impl()->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)));
     985    setDOMException(exec, ec);
     986    return result;
     987}
     988
    968989DOMWindow* toDOMWindow(JSValue value)
    969990{
  • trunk/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp

    r55798 r55823  
    5555#include "V8BindingState.h"
    5656#include "V8CustomEventListener.h"
     57#include "V8Database.h"
     58#include "V8DatabaseCallback.h"
    5759#include "V8GCForContextDispose.h"
    5860#include "V8HTMLAudioElementConstructor.h"
     
    774776}
    775777
     778v8::Handle<v8::Value> V8DOMWindow::openDatabaseCallback(const v8::Arguments& args)
     779{
     780    INC_STATS("DOM.DOMWindow.openDatabase");
     781    if (args.Length() < 4)
     782        return v8::Undefined();
     783
     784    DOMWindow* imp = V8DOMWindow::toNative(args.Holder());
     785    if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true))
     786        return v8::Undefined();
     787
     788    ExceptionCode ec = 0;
     789    String name = toWebCoreString(args[0]);
     790    String version = toWebCoreString(args[1]);
     791    String displayName = toWebCoreString(args[2]);
     792    unsigned long estimatedSize = args[3]->IntegerValue();
     793    RefPtr<DatabaseCallback> creationCallback;
     794    if ((args.Length() >= 5) && args[4]->IsObject())
     795        creationCallback = V8DatabaseCallback::create(args[4], imp->frame());
     796
     797    v8::Handle<v8::Value> result = toV8(imp->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec));
     798    V8Proxy::setDOMException(ec);
     799    return result;
     800}
     801
    776802bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data)
    777803{
  • trunk/WebCore/page/DOMWindow.cpp

    r55637 r55823  
    3737#include "Console.h"
    3838#include "Database.h"
     39#include "DatabaseCallback.h"
    3940#include "DOMApplicationCache.h"
    4041#include "DOMSelection.h"
     
    11781179
    11791180#if ENABLE(DATABASE)
    1180 PassRefPtr<Database> DOMWindow::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode& ec)
     1181PassRefPtr<Database> DOMWindow::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
    11811182{
    11821183    if (!m_frame)
     
    11901191        return 0;
    11911192
    1192     return Database::openDatabase(document, name, version, displayName, estimatedSize, ec);
     1193    return Database::openDatabase(document, name, version, displayName, estimatedSize, creationCallback, ec);
    11931194}
    11941195#endif
  • trunk/WebCore/page/DOMWindow.h

    r55635 r55823  
    4646    class DOMSelection;
    4747    class Database;
     48    class DatabaseCallback;
    4849    class Document;
    4950    class Element;
     
    201202#if ENABLE(DATABASE)
    202203        // HTML 5 client-side database
    203         PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode&);
     204        PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode&);
    204205#endif
    205206
  • trunk/WebCore/page/DOMWindow.idl

    r55637 r55823  
    161161#endif   
    162162#if defined(ENABLE_DATABASE) && ENABLE_DATABASE
    163         [EnabledAtRuntime] Database openDatabase(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize)
     163        [EnabledAtRuntime, Custom] Database openDatabase(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in DatabaseCallback creationCallback)
    164164            raises(DOMException);
    165165#endif
  • trunk/WebCore/storage/Database.cpp

    r55635 r55823  
    3636#include "CString.h"
    3737#include "DatabaseAuthorizer.h"
     38#include "DatabaseCallback.h"
    3839#include "DatabaseTask.h"
    3940#include "DatabaseThread.h"
     
    133134static int guidForOriginAndName(const String& origin, const String& name);
    134135
    135 PassRefPtr<Database> Database::openDatabase(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, ExceptionCode& e)
     136class DatabaseCreationCallbackTask : public ScriptExecutionContext::Task {
     137public:
     138    static PassOwnPtr<DatabaseCreationCallbackTask> create(PassRefPtr<Database> database)
     139    {
     140        return new DatabaseCreationCallbackTask(database);
     141    }
     142
     143    virtual void performTask(ScriptExecutionContext*)
     144    {
     145        m_database->performCreationCallback();
     146    }
     147
     148private:
     149    DatabaseCreationCallbackTask(PassRefPtr<Database> database)
     150        : m_database(database)
     151    {
     152    }
     153
     154    RefPtr<Database> m_database;
     155};
     156
     157PassRefPtr<Database> Database::openDatabase(ScriptExecutionContext* context, const String& name,
     158                                            const String& expectedVersion, const String& displayName,
     159                                            unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback,
     160                                            ExceptionCode& e)
    136161{
    137162    if (!DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize)) {
     
    141166    }
    142167
    143     RefPtr<Database> database = adoptRef(new Database(context, name, expectedVersion, displayName, estimatedSize));
     168    RefPtr<Database> database = adoptRef(new Database(context, name, expectedVersion, displayName, estimatedSize, creationCallback));
    144169
    145170    if (!database->openAndVerifyVersion(e)) {
     
    161186#endif
    162187
     188    // If it's a new database and a creation callback was provided, reset the expected
     189    // version to "" and schedule the creation callback. Because of some subtle String
     190    // implementation issues, we have to reset m_expectedVersion here instead of doing
     191    // it inside performOpenAndVerify() which is run on the DB thread.
     192    if (database->isNew() && database->m_creationCallback.get()) {
     193        database->m_expectedVersion = "";
     194        LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for database %p\n", database.get());
     195        database->m_scriptExecutionContext->postTask(DatabaseCreationCallbackTask::create(database));
     196    }
     197
    163198    return database;
    164199}
    165200
    166 Database::Database(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize)
     201Database::Database(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback)
    167202    : m_transactionInProgress(false)
    168203    , m_isTransactionQueueEnabled(true)
     
    176211    , m_stopped(false)
    177212    , m_opened(false)
     213    , m_new(false)
     214    , m_creationCallback(creationCallback)
    178215{
    179216    ASSERT(m_scriptExecutionContext.get());
     
    521558
    522559            if (!m_sqliteDatabase.tableExists(databaseInfoTableName())) {
     560                m_new = true;
     561
    523562                if (!m_sqliteDatabase.executeCommand("CREATE TABLE " + databaseInfoTableName() + " (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL);")) {
    524563                    LOG_ERROR("Unable to create table %s in database %s", databaseInfoTableName().ascii().data(), databaseDebugName().ascii().data());
     
    539578            if (currentVersion.length()) {
    540579                LOG(StorageAPI, "Retrieved current version %s from database %s", currentVersion.ascii().data(), databaseDebugName().ascii().data());
    541             } else {
     580            } else if (!m_new || !m_creationCallback) {
    542581                LOG(StorageAPI, "Setting version %s in database %s that was just created", m_expectedVersion.ascii().data(), databaseDebugName().ascii().data());
    543582                if (!setVersionInDatabase(m_expectedVersion)) {
     
    562601    // If the expected version isn't the empty string, ensure that the current database version we have matches that version. Otherwise, set an exception.
    563602    // If the expected version is the empty string, then we always return with whatever version of the database we have.
    564     if (m_expectedVersion.length() && m_expectedVersion != currentVersion) {
     603    if ((!m_new || !m_creationCallback) && m_expectedVersion.length() && m_expectedVersion != currentVersion) {
    565604        LOG(StorageAPI, "page expects version %s from database %s, which actually has version name %s - openDatabase() call will fail", m_expectedVersion.ascii().data(),
    566605            databaseDebugName().ascii().data(), currentVersion.ascii().data());
     
    686725}
    687726
     727void Database::performCreationCallback()
     728{
     729    m_creationCallback->handleEvent(m_scriptExecutionContext.get(), this);
     730}
     731
    688732SQLTransactionClient* Database::transactionClient() const
    689733{
  • trunk/WebCore/storage/Database.h

    r55635 r55823  
    5252
    5353class DatabaseAuthorizer;
     54class DatabaseCallback;
    5455class DatabaseThread;
    5556class ScriptExecutionContext;
     
    7475
    7576// Direct support for the DOM API
    76     static PassRefPtr<Database> openDatabase(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, ExceptionCode&);
     77    static PassRefPtr<Database> openDatabase(ScriptExecutionContext* context, const String& name,
     78                                             const String& expectedVersion, const String& displayName,
     79                                             unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback,
     80                                             ExceptionCode&);
    7781    String version() const;
    7882    void changeVersion(const String& oldVersion, const String& newVersion,
     
    112116    bool stopped() const { return m_stopped; }
    113117
     118    bool isNew() const { return m_new; }
     119
    114120    unsigned long long databaseSize() const;
    115121    unsigned long long maximumSize() const;
     
    122128
    123129    Vector<String> performGetTableNames();
     130    void performCreationCallback();
    124131
    125132    SQLTransactionClient* transactionClient() const;
     
    129136    Database(ScriptExecutionContext* context, const String& name,
    130137             const String& expectedVersion, const String& displayName,
    131              unsigned long estimatedSize);
     138             unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback);
    132139
    133140    bool openAndVerifyVersion(ExceptionCode&);
     
    160167    bool m_opened;
    161168
     169    bool m_new;
     170
    162171    SQLiteDatabase m_sqliteDatabase;
    163172    RefPtr<DatabaseAuthorizer> m_databaseAuthorizer;
     173
     174    RefPtr<DatabaseCallback> m_creationCallback;
    164175
    165176#ifndef NDEBUG
  • trunk/WebCore/workers/WorkerContext.cpp

    r55635 r55823  
    257257
    258258#if ENABLE(DATABASE)
    259 PassRefPtr<Database> WorkerContext::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode& ec)
     259PassRefPtr<Database> WorkerContext::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
    260260{
    261261    if (!securityOrigin()->canAccessDatabase()) {
     
    268268        return 0;
    269269
    270     return Database::openDatabase(this, name, version, displayName, estimatedSize, ec);
     270    return Database::openDatabase(this, name, version, displayName, estimatedSize, creationCallback, ec);
    271271}
    272272#endif
  • trunk/WebCore/workers/WorkerContext.h

    r55635 r55823  
    3232#include "AtomicStringHash.h"
    3333#include "Database.h"
     34#include "DatabaseCallback.h"
    3435#include "EventListener.h"
    3536#include "EventNames.h"
     
    107108#if ENABLE(DATABASE)
    108109        // HTML 5 client-side database
    109         PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode&);
     110        PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode&);
    110111        // Not implemented yet.
    111112        virtual bool isDatabaseReadOnly() const { return false; }
Note: See TracChangeset for help on using the changeset viewer.