Changeset 56834 in webkit


Ignore:
Timestamp:
Mar 31, 2010 3:35:32 AM (14 years ago)
Author:
jorlow@chromium.org
Message:

2010-03-30 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Nate Chapin.

IndexedDB: Finish hooking up bindings for IndexedDatabaseRequest
https://bugs.webkit.org/show_bug.cgi?id=36830

Still not enough hooked up to test. Soon!

  • WebCore.gypi:
  • bindings/v8/custom/V8CustomIDBCallback.h: Removed.
  • bindings/v8/custom/V8CustomIDBCallbacks.h: Added. (WebCore::V8CustomIDBCallbacks::create): (WebCore::V8CustomIDBCallbacks::~V8CustomIDBCallbacks): (WebCore::V8CustomIDBCallbacks::onSuccess): (WebCore::V8CustomIDBCallbacks::onError): (WebCore::V8CustomIDBCallbacks::V8CustomIDBCallbacks):
  • bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp: (WebCore::V8IndexedDatabaseRequest::openCallback):
  • storage/IDBDatabaseRequest.cpp: Added. (WebCore::IDBDatabaseRequest::IDBDatabaseRequest): (WebCore::IDBDatabaseRequest::~IDBDatabaseRequest):
  • storage/IDBDatabaseRequest.h: (WebCore::IDBDatabaseRequest::create):
  • storage/IndexedDatabaseRequest.cpp: (WebCore::IndexedDatabaseRequest::open):
  • storage/IndexedDatabaseRequest.h:
Location:
trunk/WebCore
Files:
6 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56833 r56834  
     12010-03-30  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Nate Chapin.
     4
     5        IndexedDB: Finish hooking up bindings for IndexedDatabaseRequest
     6        https://bugs.webkit.org/show_bug.cgi?id=36830
     7
     8        Still not enough hooked up to test.  Soon!
     9
     10        * WebCore.gypi:
     11        * bindings/v8/custom/V8CustomIDBCallback.h: Removed.
     12        * bindings/v8/custom/V8CustomIDBCallbacks.h: Added.
     13        (WebCore::V8CustomIDBCallbacks::create):
     14        (WebCore::V8CustomIDBCallbacks::~V8CustomIDBCallbacks):
     15        (WebCore::V8CustomIDBCallbacks::onSuccess):
     16        (WebCore::V8CustomIDBCallbacks::onError):
     17        (WebCore::V8CustomIDBCallbacks::V8CustomIDBCallbacks):
     18        * bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp:
     19        (WebCore::V8IndexedDatabaseRequest::openCallback):
     20        * storage/IDBDatabaseRequest.cpp: Added.
     21        (WebCore::IDBDatabaseRequest::IDBDatabaseRequest):
     22        (WebCore::IDBDatabaseRequest::~IDBDatabaseRequest):
     23        * storage/IDBDatabaseRequest.h:
     24        (WebCore::IDBDatabaseRequest::create):
     25        * storage/IndexedDatabaseRequest.cpp:
     26        (WebCore::IndexedDatabaseRequest::open):
     27        * storage/IndexedDatabaseRequest.h:
     28
    1292010-03-31  Zhenyao Mo  <zmo@google.com>
    230
  • trunk/WebCore/WebCore.gypi

    r56825 r56834  
    697697            'bindings/v8/custom/V8CSSStyleSheetCustom.cpp',
    698698            'bindings/v8/custom/V8CSSValueCustom.cpp',
    699             'bindings/v8/custom/V8CustomCallback.h',
     699            'bindings/v8/custom/V8CustomIDBCallbacks.h',
    700700            'bindings/v8/custom/V8CustomEventListener.cpp',
    701701            'bindings/v8/custom/V8CustomEventListener.h',
     
    32693269            'storage/IDBDatabaseError.h',
    32703270            'storage/IDBDatabaseException.h',
     3271            'storage/IDBDatabaseRequest.cpp',
    32713272            'storage/IDBDatabaseRequest.h',
    32723273            'storage/IndexedDatabase.cpp',
  • trunk/WebCore/bindings/v8/custom/V8CustomIDBCallbacks.h

    r56833 r56834  
    2929 */
    3030
    31 #ifndef V8CustomIDBCallback_h
    32 #define V8CustomIDBCallback_h
     31#ifndef V8CustomIDBCallbacks_h
     32#define V8CustomIDBCallbacks_h
    3333
    3434#include "Frame.h"
     35#include "IDBDatabaseError.h"
    3536#include "V8CustomVoidCallback.h"
     37#include "V8IDBDatabaseError.h"
    3638#include <v8.h>
    3739#include <wtf/PassRefPtr.h>
     
    4446
    4547// FIXME: Maybe split common parts into a base class.
    46 template <typename CallbackType>
    47 class V8CustomIDBCallback : public RefCounted<V8CustomIDBCallback<CallbackType> > {
     48template <typename ResultType, typename ResultWrapperType>
     49class V8CustomIDBCallbacks : public IDBCallbacks<ResultType> {
    4850public:
    49     static PassRefPtr<V8CustomIDBCallback> create(v8::Local<v8::Value> value, Frame* frame)
     51    static PassRefPtr<V8CustomIDBCallbacks> create(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, Frame* frame)
    5052    {
    51         ASSERT(value->IsObject());
    52         return adoptRef(new V8CustomIDBCallback(value->ToObject(), frame));
     53        return adoptRef(new V8CustomIDBCallbacks(onSuccess, onError, frame));
    5354    }
    5455
    55     virtual ~V8CustomIDBCallback()
     56    virtual ~V8CustomIDBCallbacks()
    5657    {
    57         m_callback.Dispose();
     58        m_onSuccess.Dispose();
     59        m_onError.Dispose();
    5860    }
    5961
    60     virtual void handleEvent(CallbackType* result)
     62    virtual void onSuccess(PassRefPtr<ResultType> result)
    6163    {
     64        if (m_onSuccessNull)
     65            return;
    6266        v8::HandleScope handleScope;
    6367        v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get());
     
    6771        v8::Context::Scope scope(context);
    6872        v8::Handle<v8::Value> argv[] = {
    69             toV8(result)
     73            toV8(ResultWrapperType::create(result))
    7074        };
    7175        RefPtr<Frame> protector(m_frame);
    7276        bool callbackReturnValue = false;
    7377        // FIXME: Do we care if this thing returns true (i.e. it raised an exception)?
    74         invokeCallback(m_callback, 1, argv, callbackReturnValue);
     78        invokeCallback(m_onSuccess, 1, argv, callbackReturnValue);
     79    }
     80
     81    virtual void onError(PassRefPtr<IDBDatabaseError> error)
     82    {
     83        if (m_onErrorNull)
     84            return;
     85        v8::HandleScope handleScope;
     86        v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get());
     87        if (context.IsEmpty())
     88            return;
     89
     90        v8::Context::Scope scope(context);
     91        v8::Handle<v8::Value> argv[] = {
     92            toV8(error)
     93        };
     94        RefPtr<Frame> protector(m_frame);
     95        bool callbackReturnValue = false;
     96        // FIXME: Do we care if this thing returns true (i.e. it raised an exception)?
     97        invokeCallback(m_onError, 1, argv, callbackReturnValue);
    7598    }
    7699
    77100private:
    78     V8CustomIDBCallback(v8::Local<v8::Object>callback, Frame* frame)
    79         : m_callback(v8::Persistent<v8::Object>::New(callback)),
    80           m_frame(frame)
     101    V8CustomIDBCallbacks(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, Frame* frame)
     102        : m_onSuccessNull(!onSuccess->IsObject())
     103        , m_onSuccess(v8::Persistent<v8::Object>::New(onSuccess->ToObject()))
     104        , m_onErrorNull(!onError->IsObject())
     105        , m_onError(v8::Persistent<v8::Object>::New(onError->ToObject()))
     106        , m_frame(frame)
    81107    {
    82108    }
    83109
    84     v8::Persistent<v8::Object> m_callback;
     110    // FIXME: Should these be v8::Functions?  For some reason, VoidCallback (which this copied) uses v8::Objects.
     111    bool m_onSuccessNull;
     112    v8::Persistent<v8::Object> m_onSuccess;
     113    bool m_onErrorNull;
     114    v8::Persistent<v8::Object> m_onError;
    85115    RefPtr<Frame> m_frame;
    86116};
     
    90120#endif
    91121
    92 #endif // V8CustomIDBCallback_h
     122#endif // V8CustomIDBCallbacks_h
  • trunk/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp

    r55778 r56834  
    3737#include "IDBDatabaseRequest.h"
    3838#include "V8Binding.h"
    39 #include "V8CustomIDBCallback.h"
     39#include "V8CustomIDBCallbacks.h"
    4040#include "V8IDBDatabaseError.h"
    4141#include "V8IDBDatabaseRequest.h"
     
    5656        modifyDatabase = args[2]->BooleanValue();
    5757
    58     Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
    59 
    60     RefPtr<V8CustomIDBCallback<IDBDatabaseError> > onerror;
     58    v8::Local<v8::Value> onError;
     59    v8::Local<v8::Value> onSuccess;
    6160    if (args.Length() > 3 && !args[3]->IsUndefined() && !args[3]->IsNull()) {
    6261        if (!args[3]->IsObject())
    6362            return throwError("onerror callback was not the proper type");
    64         if (frame)
    65             onerror = V8CustomIDBCallback<IDBDatabaseError>::create(args[3], frame);
     63        onError = args[3];
    6664    }
    67 
    68     RefPtr<V8CustomIDBCallback<IDBDatabaseRequest> > onsuccess;
    6965    if (args.Length() > 4 && !args[4]->IsUndefined() && !args[4]->IsNull()) {
    7066        if (!args[4]->IsObject())
    7167            return throwError("onsuccess callback was not the proper type");
    72         if (frame)
    73             onsuccess = V8CustomIDBCallback<IDBDatabaseRequest>::create(args[4], frame);
     68        onSuccess = args[4];
    7469    }
    75 
    76     if (!onerror && !onsuccess)
     70    if (!onError->IsObject() && !onSuccess->IsObject())
    7771        return throwError("Neither the onerror nor the onsuccess callbacks were set.");
    7872
     73    Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
     74    RefPtr<V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest> > callbacks =
     75        V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest>::create(onSuccess, onError, frame);
     76
    7977    ExceptionCode ec = 0;
    80     imp->open(name, description, modifyDatabase, ec);
     78    imp->open(name, description, modifyDatabase, ec, callbacks);
    8179    if (ec)
    8280        return throwError(ec);
  • trunk/WebCore/storage/IDBDatabaseRequest.cpp

    r56833 r56834  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 #ifndef IDBDatabaseRequest_h
    29 #define IDBDatabaseRequest_h
    3028
    31 #include <wtf/RefCounted.h>
     29#include "config.h"
     30#include "IDBDatabaseRequest.h"
     31
     32#include "IndexedDatabase.h"
    3233
    3334#if ENABLE(INDEXED_DATABASE)
     
    3536namespace WebCore {
    3637
    37 class IDBRequest;
     38IDBDatabaseRequest::IDBDatabaseRequest(PassRefPtr<IDBDatabase> idbDatabase)
     39    : m_idbDatabase(idbDatabase)
     40{
     41}
    3842
    39 class IDBDatabaseRequest : public RefCounted<IDBDatabaseRequest> {
    40 public:
    41     // FIXME: Write.
    42     IDBRequest* request() const { return 0; }
    43     void createObjectStore(const String& name, const String& keyPath, bool autoIncrement) { }
    44 };
     43IDBDatabaseRequest::~IDBDatabaseRequest()
     44{
     45}
    4546
    4647} // namespace WebCore
    4748
    48 #endif
     49#endif // ENABLE(INDEXED_DATABASE)
    4950
    50 #endif // IDBDatabaseRequest_h
    51 
  • trunk/WebCore/storage/IDBDatabaseRequest.h

    r56777 r56834  
    2929#define IDBDatabaseRequest_h
    3030
     31#include "IDBDatabase.h"
     32#include "PlatformString.h"
     33#include <wtf/PassRefPtr.h>
    3134#include <wtf/RefCounted.h>
     35#include <wtf/RefPtr.h>
    3236
    3337#if ENABLE(INDEXED_DATABASE)
     
    3539namespace WebCore {
    3640
    37 class IDBRequest;
    38 
    3941class IDBDatabaseRequest : public RefCounted<IDBDatabaseRequest> {
    4042public:
     43    static PassRefPtr<IDBDatabaseRequest> create(PassRefPtr<IDBDatabase> idbDatabase)
     44    {
     45        return adoptRef(new IDBDatabaseRequest(idbDatabase));
     46    }
     47    ~IDBDatabaseRequest();
     48
    4149    // FIXME: Write.
    42     IDBRequest* request() const { return 0; }
    4350    void createObjectStore(const String& name, const String& keyPath, bool autoIncrement) { }
     51
     52private:
     53    IDBDatabaseRequest(PassRefPtr<IDBDatabase>);
     54
     55    RefPtr<IDBDatabase> m_idbDatabase;
    4456};
    4557
  • trunk/WebCore/storage/IndexedDatabaseRequest.cpp

    r56777 r56834  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829#include "config.h"
    2930#include "IndexedDatabaseRequest.h"
     
    4647}
    4748
    48 void IndexedDatabaseRequest::open(const String& name, const String& description, bool modifyDatabase, ExceptionCode& exception)
     49void IndexedDatabaseRequest::open(const String& name, const String& description, bool modifyDatabase, ExceptionCode& exception, PassRefPtr<IDBDatabaseCallbacks> callbacks)
    4950{
    50     // FIXME: This should initiate a request.
     51    m_indexedDatabase->open(name, description, modifyDatabase, exception, callbacks);
    5152}
    5253
  • trunk/WebCore/storage/IndexedDatabaseRequest.h

    r56777 r56834  
    3030
    3131#include "ExceptionCode.h"
     32#include "IndexedDatabase.h"
    3233#include "PlatformString.h"
    3334#include <wtf/PassRefPtr.h>
     
    5051    ~IndexedDatabaseRequest();
    5152
    52     void open(const String& name, const String& description, bool modifyDatabase, ExceptionCode&);
     53    void open(const String& name, const String& description, bool modifyDatabase, ExceptionCode&, PassRefPtr<IDBDatabaseCallbacks> callbacks);
    5354
    5455    void disconnectFrame() { m_frame = 0; }
Note: See TracChangeset for help on using the changeset viewer.