Title: [101890] trunk/Source
Revision
101890
Author
[email protected]
Date
2011-12-02 18:20:10 -0800 (Fri, 02 Dec 2011)

Log Message

Grant workers experimental access to IndexedDB.
https://bugs.webkit.org/show_bug.cgi?id=73609

Reviewed by Nate Chapin.

Source/WebCore:

No new tests - there will be chromium ui tests that depend on
webkit.org/b/73297.

* storage/IDBFactory.cpp:
(WebCore::IDBFactory::open): Call new function,
IDBFactoryBackendInterface::openFromWorker.
* storage/IDBFactoryBackendImpl.cpp:
(WebCore::IDBFactoryBackendImpl::open):
(WebCore::IDBFactoryBackendImpl::openFromWorker):
(WebCore::IDBFactoryBackendImpl::openInternal):
* storage/IDBFactoryBackendImpl.h:
* storage/IDBFactoryBackendInterface.h:
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::webkitIndexedDB): Stores
IDBFactoryBackendInterface, implemented by IDBFactoryBackendProxy in
chromium, in the WorkerContext.  For the Document case it is stored in
the PageGroup.  Storing it in the WorkerContext causes more memory
churn, but that should be trivial.  I don't know of any better
alternatives.
* workers/WorkerContext.h:
* workers/WorkerContext.idl:

Source/WebKit/chromium:

* src/IDBFactoryBackendProxy.cpp:
(WebKit::IDBFactoryBackendProxy::allowIDBFromWorkerThread): Return
true while behind a runtime flag, and while we figure out how to check
permission in a thread-safe manner.
(WebKit::IDBFactoryBackendProxy::openFromWorker): Using the webFrame
from the worker seems to satisfy the weak condition in chromium that
neither it nor it's associated RenderView is NULL.
* src/IDBFactoryBackendProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101889 => 101890)


--- trunk/Source/WebCore/ChangeLog	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/ChangeLog	2011-12-03 02:20:10 UTC (rev 101890)
@@ -1,3 +1,32 @@
+2011-12-02  David Grogan  <[email protected]>
+
+        Grant workers experimental access to IndexedDB.
+        https://bugs.webkit.org/show_bug.cgi?id=73609
+
+        Reviewed by Nate Chapin.
+
+        No new tests - there will be chromium ui tests that depend on
+        webkit.org/b/73297.
+
+        * storage/IDBFactory.cpp:
+        (WebCore::IDBFactory::open): Call new function,
+        IDBFactoryBackendInterface::openFromWorker.
+        * storage/IDBFactoryBackendImpl.cpp:
+        (WebCore::IDBFactoryBackendImpl::open):
+        (WebCore::IDBFactoryBackendImpl::openFromWorker):
+        (WebCore::IDBFactoryBackendImpl::openInternal):
+        * storage/IDBFactoryBackendImpl.h:
+        * storage/IDBFactoryBackendInterface.h:
+        * workers/WorkerContext.cpp:
+        (WebCore::WorkerContext::webkitIndexedDB): Stores
+        IDBFactoryBackendInterface, implemented by IDBFactoryBackendProxy in
+        chromium, in the WorkerContext.  For the Document case it is stored in
+        the PageGroup.  Storing it in the WorkerContext causes more memory
+        churn, but that should be trivial.  I don't know of any better
+        alternatives.
+        * workers/WorkerContext.h:
+        * workers/WorkerContext.idl:
+
 2011-12-02  Aaron Colwell  <[email protected]>
 
         Fix mixed content handling for video in Chromium by having

Modified: trunk/Source/WebCore/page/DOMWindow.idl (101889 => 101890)


--- trunk/Source/WebCore/page/DOMWindow.idl	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/page/DOMWindow.idl	2011-12-03 02:20:10 UTC (rev 101890)
@@ -177,18 +177,18 @@
         readonly attribute [EnabledAtRuntime] NotificationCenter webkitNotifications;
 #endif
 #if defined(ENABLE_INDEXED_DATABASE) && ENABLE_INDEXED_DATABASE
-        readonly attribute [EnabledAtRuntime] IDBFactory webkitIndexedDB;
+        readonly attribute IDBFactory webkitIndexedDB;
 
-        attribute [EnabledAtRuntime] IDBCursorConstructor webkitIDBCursor;
-        attribute [EnabledAtRuntime] IDBDatabaseConstructor webkitIDBDatabase;
-        attribute [EnabledAtRuntime] IDBDatabaseErrorConstructor webkitIDBDatabaseError;
-        attribute [EnabledAtRuntime] IDBDatabaseExceptionConstructor webkitIDBDatabaseException;
-        attribute [EnabledAtRuntime] IDBFactoryConstructor webkitIDBFactory;
-        attribute [EnabledAtRuntime] IDBIndexConstructor webkitIDBIndex;
-        attribute [EnabledAtRuntime] IDBKeyRangeConstructor webkitIDBKeyRange;
-        attribute [EnabledAtRuntime] IDBObjectStoreConstructor webkitIDBObjectStore;
-        attribute [EnabledAtRuntime] IDBRequestConstructor webkitIDBRequest;
-        attribute [EnabledAtRuntime] IDBTransactionConstructor webkitIDBTransaction;
+        attribute IDBCursorConstructor webkitIDBCursor;
+        attribute IDBDatabaseConstructor webkitIDBDatabase;
+        attribute IDBDatabaseErrorConstructor webkitIDBDatabaseError;
+        attribute IDBDatabaseExceptionConstructor webkitIDBDatabaseException;
+        attribute IDBFactoryConstructor webkitIDBFactory;
+        attribute IDBIndexConstructor webkitIDBIndex;
+        attribute IDBKeyRangeConstructor webkitIDBKeyRange;
+        attribute IDBObjectStoreConstructor webkitIDBObjectStore;
+        attribute IDBRequestConstructor webkitIDBRequest;
+        attribute IDBTransactionConstructor webkitIDBTransaction;
 #endif
 #if defined(ENABLE_FILE_SYSTEM) && ENABLE_FILE_SYSTEM
         const unsigned short TEMPORARY = 0;

Modified: trunk/Source/WebCore/storage/IDBFactory.cpp (101889 => 101890)


--- trunk/Source/WebCore/storage/IDBFactory.cpp	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/storage/IDBFactory.cpp	2011-12-03 02:20:10 UTC (rev 101890)
@@ -46,6 +46,9 @@
 #include "Page.h"
 #include "PageGroup.h"
 #include "SecurityOrigin.h"
+#include "WorkerContext.h"
+#include "WorkerLoaderProxy.h"
+#include "WorkerThread.h"
 
 namespace WebCore {
 
@@ -79,23 +82,23 @@
 
 PassRefPtr<IDBRequest> IDBFactory::open(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
 {
-    if (!context->isDocument()) {
-        // FIXME: make this work with workers.
-        return 0;
-    }
+    ASSERT(context->isDocument() || context->isWorkerContext());
 
-    Document* document = static_cast<Document*>(context);
-    if (!document->frame() || !document->page())
-        return 0;
-
     if (name.isNull()) {
         ec = IDBDatabaseException::NON_TRANSIENT_ERR;
         return 0;
     }
-
-    RefPtr<IDBRequest> request = IDBRequest::create(document, IDBAny::create(this), 0);
-    GroupSettings* groupSettings = document->page()->group().groupSettings();
-    m_backend->open(name, request, document->securityOrigin(), document->frame(), groupSettings->indexedDBDatabasePath());
+    if (context->isDocument()) {
+        Document* document = static_cast<Document*>(context);
+        if (!document->frame() || !document->page())
+            return 0;
+        Frame* frame = document->frame();
+        RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), 0);
+        m_backend->open(name, request.get(), context->securityOrigin(), frame, String());
+        return request;
+    }
+    RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), 0);
+    m_backend->openFromWorker(name, request.get(), context->securityOrigin(), static_cast<WorkerContext*>(context), String());
     return request;
 }
 

Modified: trunk/Source/WebCore/storage/IDBFactoryBackendImpl.cpp (101889 => 101890)


--- trunk/Source/WebCore/storage/IDBFactoryBackendImpl.cpp	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/storage/IDBFactoryBackendImpl.cpp	2011-12-03 02:20:10 UTC (rev 101890)
@@ -80,9 +80,9 @@
     m_backingStoreMap.remove(fileIdentifier);
 }
 
-void IDBFactoryBackendImpl::getDatabaseNames(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir)
+void IDBFactoryBackendImpl::getDatabaseNames(PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDirectory)
 {
-    RefPtr<IDBBackingStore> backingStore = openBackingStore(securityOrigin, dataDir);
+    RefPtr<IDBBackingStore> backingStore = openBackingStore(securityOrigin, dataDirectory);
     if (!backingStore) {
         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
         return;
@@ -98,31 +98,17 @@
     callbacks->onSuccess(databaseNames.release());
 }
 
-void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir)
+void IDBFactoryBackendImpl::open(const String& name, IDBCallbacks* callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDirectory)
 {
-    const String uniqueIdentifier = computeUniqueIdentifier(name, securityOrigin.get());
+    openInternal(name, callbacks, securityOrigin, dataDirectory);
+}
 
-    IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
-    if (it != m_databaseBackendMap.end()) {
-        // If it's already been opened, we have to wait for any pending
-        // setVersion calls to complete.
-        it->second->openConnection(callbacks);
-        return;
-    }
-
-    // FIXME: Everything from now on should be done on another thread.
-    RefPtr<IDBBackingStore> backingStore = openBackingStore(securityOrigin, dataDir);
-    if (!backingStore) {
-        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
-        return;
-    }
-
-    RefPtr<IDBDatabaseBackendImpl> databaseBackend = IDBDatabaseBackendImpl::create(name, backingStore.get(), m_transactionCoordinator.get(), this, uniqueIdentifier);
-    callbacks->onSuccess(databaseBackend.get());
-    m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
+void IDBFactoryBackendImpl::openFromWorker(const String& name, IDBCallbacks* callbacks, PassRefPtr<SecurityOrigin> securityOrigin, WorkerContext*, const String& dataDirectory)
+{
+    openInternal(name, callbacks, securityOrigin, dataDirectory);
 }
 
-void IDBFactoryBackendImpl::deleteDatabase(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir)
+void IDBFactoryBackendImpl::deleteDatabase(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDirectory)
 {
     const String uniqueIdentifier = computeUniqueIdentifier(name, securityOrigin.get());
 
@@ -135,7 +121,7 @@
     }
 
     // FIXME: Everything from now on should be done on another thread.
-    RefPtr<IDBBackingStore> backingStore = openBackingStore(securityOrigin, dataDir);
+    RefPtr<IDBBackingStore> backingStore = openBackingStore(securityOrigin, dataDirectory);
     if (!backingStore) {
         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
         return;
@@ -146,7 +132,7 @@
     databaseBackend->deleteDatabase(callbacks);
 }
 
-PassRefPtr<IDBBackingStore> IDBFactoryBackendImpl::openBackingStore(PassRefPtr<SecurityOrigin> securityOrigin, const String& dataDir)
+PassRefPtr<IDBBackingStore> IDBFactoryBackendImpl::openBackingStore(PassRefPtr<SecurityOrigin> securityOrigin, const String& dataDirectory)
 {
     const String fileIdentifier = computeFileIdentifier(securityOrigin.get());
 
@@ -156,7 +142,7 @@
         backingStore = it2->second;
     else {
 #if USE(LEVELDB)
-        backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDir, fileIdentifier, this);
+        backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDirectory, fileIdentifier, this);
 #else
         ASSERT_NOT_REACHED();
 #endif
@@ -168,6 +154,31 @@
     return 0;
 }
 
+void IDBFactoryBackendImpl::openInternal(const String& name, IDBCallbacks* callbacks, PassRefPtr<SecurityOrigin> prpSecurityOrigin, const String& dataDirectory)
+{
+    RefPtr<SecurityOrigin> securityOrigin = prpSecurityOrigin;
+    const String uniqueIdentifier = computeUniqueIdentifier(name, securityOrigin.get());
+
+    IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
+    if (it != m_databaseBackendMap.end()) {
+        // If it's already been opened, we have to wait for any pending
+        // setVersion calls to complete.
+        it->second->openConnection(callbacks);
+        return;
+    }
+
+    // FIXME: Everything from now on should be done on another thread.
+    RefPtr<IDBBackingStore> backingStore = openBackingStore(securityOrigin, dataDirectory);
+    if (!backingStore) {
+        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
+        return;
+    }
+
+    RefPtr<IDBDatabaseBackendImpl> databaseBackend = IDBDatabaseBackendImpl::create(name, backingStore.get(), m_transactionCoordinator.get(), this, uniqueIdentifier);
+    callbacks->onSuccess(RefPtr<IDBDatabaseBackendInterface>(databaseBackend.get()).release());
+    m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)

Modified: trunk/Source/WebCore/storage/IDBFactoryBackendImpl.h (101889 => 101890)


--- trunk/Source/WebCore/storage/IDBFactoryBackendImpl.h	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/storage/IDBFactoryBackendImpl.h	2011-12-03 02:20:10 UTC (rev 101890)
@@ -56,12 +56,15 @@
     void removeIDBBackingStore(const String& fileIdentifier);
 
     virtual void getDatabaseNames(PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir);
-    virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir);
+
+    virtual void open(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir);
+    virtual void openFromWorker(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, WorkerContext*, const String& dataDir);
     virtual void deleteDatabase(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir);
 
 private:
     IDBFactoryBackendImpl();
     PassRefPtr<IDBBackingStore> openBackingStore(PassRefPtr<SecurityOrigin>, const String& dataDir);
+    void openInternal(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, const String& dataDir);
 
     typedef HashMap<String, IDBDatabaseBackendImpl*> IDBDatabaseBackendMap;
     IDBDatabaseBackendMap m_databaseBackendMap;

Modified: trunk/Source/WebCore/storage/IDBFactoryBackendInterface.h (101889 => 101890)


--- trunk/Source/WebCore/storage/IDBFactoryBackendInterface.h	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/storage/IDBFactoryBackendInterface.h	2011-12-03 02:20:10 UTC (rev 101890)
@@ -40,6 +40,7 @@
 class Frame;
 class IDBDatabase;
 class SecurityOrigin;
+class WorkerContext;
 
 typedef int ExceptionCode;
 
@@ -53,7 +54,9 @@
     virtual ~IDBFactoryBackendInterface() { }
 
     virtual void getDatabaseNames(PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir) = 0;
-    virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir) = 0;
+
+    virtual void open(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir) = 0;
+    virtual void openFromWorker(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, WorkerContext*, const String& dataDir) = 0;
     virtual void deleteDatabase(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir) = 0;
 };
 

Modified: trunk/Source/WebCore/workers/WorkerContext.cpp (101889 => 101890)


--- trunk/Source/WebCore/workers/WorkerContext.cpp	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/workers/WorkerContext.cpp	2011-12-03 02:20:10 UTC (rev 101890)
@@ -86,6 +86,8 @@
 #include "ExceptionCode.h"
 #endif
 
+#include "IDBFactory.h"
+
 namespace WebCore {
 
 class CloseWorkerContextTask : public ScriptExecutionContext::Task {
@@ -521,6 +523,19 @@
     }
 }
 
+#if ENABLE(INDEXED_DATABASE)
+IDBFactory* WorkerContext::webkitIndexedDB() const
+{
+    if (!securityOrigin()->canAccessDatabase())
+        return 0;
+    if (!m_idbFactoryBackendInterface)
+        m_idbFactoryBackendInterface = IDBFactoryBackendInterface::create();
+    if (!m_idbFactory)
+        m_idbFactory = IDBFactory::create(m_idbFactoryBackendInterface.get());
+    return m_idbFactory.get();
+}
+#endif
+
 WorkerEventQueue* WorkerContext::eventQueue() const
 {
     return m_eventQueue.get();

Modified: trunk/Source/WebCore/workers/WorkerContext.h (101889 => 101890)


--- trunk/Source/WebCore/workers/WorkerContext.h	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/workers/WorkerContext.h	2011-12-03 02:20:10 UTC (rev 101890)
@@ -55,6 +55,7 @@
     class EntrySync;
     class ErrorCallback;
     class FileSystemCallback;
+    class IDBFactory;
     class NotificationCenter;
     class ScheduledAction;
     class WorkerInspectorController;
@@ -173,6 +174,9 @@
         void registerObserver(Observer*);
         void unregisterObserver(Observer*);
         void notifyObserversOfStop();
+#if ENABLE(INDEXED_DATABASE)
+        IDBFactory* webkitIndexedDB() const;
+#endif
 
     protected:
         WorkerContext(const KURL&, const String&, WorkerThread*);
@@ -218,6 +222,12 @@
         HashSet<Observer*> m_workerObservers;
 
         OwnPtr<WorkerEventQueue> m_eventQueue;
+
+#if ENABLE(INDEXED_DATABASE)
+        mutable RefPtr<IDBFactory> m_idbFactory;
+        mutable RefPtr<IDBFactoryBackendInterface> m_idbFactoryBackendInterface;
+#endif
+
     };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerContext.idl (101889 => 101890)


--- trunk/Source/WebCore/workers/WorkerContext.idl	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebCore/workers/WorkerContext.idl	2011-12-03 02:20:10 UTC (rev 101890)
@@ -126,6 +126,20 @@
         attribute Float32ArrayConstructor Float32Array; // Usable with new operator
         attribute Float64ArrayConstructor Float64Array; // Usable with new operator
         attribute DataViewConstructor DataView; // Usable with new operator
+#if defined(ENABLE_INDEXED_DATABASE) && ENABLE_INDEXED_DATABASE
+        readonly attribute [EnabledAtRuntime] IDBFactory webkitIndexedDB;
+
+        attribute [EnabledAtRuntime] IDBCursorConstructor webkitIDBCursor;
+        attribute [EnabledAtRuntime] IDBDatabaseConstructor webkitIDBDatabase;
+        attribute [EnabledAtRuntime] IDBDatabaseErrorConstructor webkitIDBDatabaseError;
+        attribute [EnabledAtRuntime] IDBDatabaseExceptionConstructor webkitIDBDatabaseException;
+        attribute [EnabledAtRuntime] IDBFactoryConstructor webkitIDBFactory;
+        attribute [EnabledAtRuntime] IDBIndexConstructor webkitIDBIndex;
+        attribute [EnabledAtRuntime] IDBKeyRangeConstructor webkitIDBKeyRange;
+        attribute [EnabledAtRuntime] IDBObjectStoreConstructor webkitIDBObjectStore;
+        attribute [EnabledAtRuntime] IDBRequestConstructor webkitIDBRequest;
+        attribute [EnabledAtRuntime] IDBTransactionConstructor webkitIDBTransaction;
+#endif
     };
 
 }

Modified: trunk/Source/WebKit/chromium/ChangeLog (101889 => 101890)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-12-03 02:20:10 UTC (rev 101890)
@@ -1,3 +1,19 @@
+2011-12-02  David Grogan  <[email protected]>
+
+        Grant workers experimental access to IndexedDB.
+        https://bugs.webkit.org/show_bug.cgi?id=73609
+
+        Reviewed by Nate Chapin.
+
+        * src/IDBFactoryBackendProxy.cpp:
+        (WebKit::IDBFactoryBackendProxy::allowIDBFromWorkerThread): Return
+        true while behind a runtime flag, and while we figure out how to check
+        permission in a thread-safe manner.
+        (WebKit::IDBFactoryBackendProxy::openFromWorker): Using the webFrame
+        from the worker seems to satisfy the weak condition in chromium that
+        neither it nor it's associated RenderView is NULL.
+        * src/IDBFactoryBackendProxy.h:
+
 2011-12-01  James Robinson  <[email protected]>
 
         [chromium] Move WebLayer APIs to platform directory

Modified: trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.cpp (101889 => 101890)


--- trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.cpp	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.cpp	2011-12-03 02:20:10 UTC (rev 101890)
@@ -31,6 +31,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "CrossThreadTask.h"
 #include "DOMStringList.h"
 #include "IDBDatabaseBackendProxy.h"
 #include "IDBDatabaseError.h"
@@ -45,7 +46,13 @@
 #include "WebPermissionClient.h"
 #include "WebVector.h"
 #include "WebViewImpl.h"
+#include "WebWorkerBase.h"
+#include "WorkerContext.h"
+#include "WorkerLoaderProxy.h"
+#include "WorkerScriptController.h"
+#include "WorkerThread.h"
 
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -78,9 +85,27 @@
     m_webIDBFactory->getDatabaseNames(new WebIDBCallbacksImpl(callbacks), origin, webFrame, dataDir);
 }
 
-void IDBFactoryBackendProxy::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> prpOrigin, Frame* frame, const String& dataDir)
+bool IDBFactoryBackendProxy::allowIDBFromWorkerThread(WorkerContext*, const String&, const WebSecurityOrigin&)
 {
+    return true;
+}
+
+void IDBFactoryBackendProxy::openFromWorker(const String& name, IDBCallbacks* callbacks, PassRefPtr<SecurityOrigin> prpOrigin, WorkerContext* context, const String& dataDir)
+{
     WebSecurityOrigin origin(prpOrigin);
+    if (!allowIDBFromWorkerThread(context, name, origin)) {
+        callbacks->onError(WebIDBDatabaseError(0, "The user denied permission to access the database."));
+        return;
+    }
+    WorkerLoaderProxy* workerLoaderProxy = &context->thread()->workerLoaderProxy();
+    NewWebWorkerBase* webWorker = static_cast<NewWebWorkerBase*>(workerLoaderProxy);
+    WebFrame* webFrame = webWorker->view()->mainFrame();
+    m_webIDBFactory->open(name, new WebIDBCallbacksImpl(callbacks), origin, webFrame, dataDir);
+}
+
+void IDBFactoryBackendProxy::open(const String& name, IDBCallbacks* callbacks, PassRefPtr<SecurityOrigin> prpOrigin, Frame* frame, const String& dataDir)
+{
+    WebSecurityOrigin origin(prpOrigin);
     WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame);
     WebViewImpl* webView = webFrame->viewImpl();
     if (webView->permissionClient() && !webView->permissionClient()->allowIndexedDB(webFrame, name, origin)) {

Modified: trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.h (101889 => 101890)


--- trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.h	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebKit/chromium/src/IDBFactoryBackendProxy.h	2011-12-03 02:20:10 UTC (rev 101890)
@@ -33,11 +33,14 @@
 
 #include "IDBFactoryBackendInterface.h"
 
-namespace WebCore { class DOMStringList; }
+namespace WebCore {
+class WorkerContext;
+}
 
 namespace WebKit {
 
 class WebIDBFactory;
+class WebSecurityOrigin;
 
 class IDBFactoryBackendProxy : public WebCore::IDBFactoryBackendInterface {
 public:
@@ -45,11 +48,15 @@
     virtual ~IDBFactoryBackendProxy();
 
     virtual void getDatabaseNames(PassRefPtr<WebCore::IDBCallbacks>, PassRefPtr<WebCore::SecurityOrigin>, WebCore::Frame*, const String& dataDir);
-    virtual void open(const String& name, PassRefPtr<WebCore::IDBCallbacks>, PassRefPtr<WebCore::SecurityOrigin>, WebCore::Frame*, const String& dataDir);
+
+    virtual void open(const String& name, WebCore::IDBCallbacks*, PassRefPtr<WebCore::SecurityOrigin>, WebCore::Frame*, const String& dataDir);
+    virtual void openFromWorker(const String& name, WebCore::IDBCallbacks*, PassRefPtr<WebCore::SecurityOrigin>, WebCore::WorkerContext*, const String& dataDir);
+
     virtual void deleteDatabase(const String& name, PassRefPtr<WebCore::IDBCallbacks>, PassRefPtr<WebCore::SecurityOrigin>, WebCore::Frame*, const String& dataDir);
 
 private:
     IDBFactoryBackendProxy();
+    bool allowIDBFromWorkerThread(WebCore::WorkerContext*, const String& name, const WebSecurityOrigin&);
 
     // We don't own this pointer (unlike all the other proxy classes which do).
     WebIDBFactory* m_webIDBFactory;

Modified: trunk/Source/WebKit/chromium/src/WebIDBFactoryImpl.cpp (101889 => 101890)


--- trunk/Source/WebKit/chromium/src/WebIDBFactoryImpl.cpp	2011-12-03 02:12:22 UTC (rev 101889)
+++ trunk/Source/WebKit/chromium/src/WebIDBFactoryImpl.cpp	2011-12-03 02:20:10 UTC (rev 101890)
@@ -66,7 +66,7 @@
 
 void WebIDBFactoryImpl::open(const WebString& name, WebIDBCallbacks* callbacks, const WebSecurityOrigin& origin, WebFrame*, const WebString& dataDir)
 {
-    m_idbFactoryBackend->open(name, IDBCallbacksProxy::create(adoptPtr(callbacks)), origin, 0, dataDir);
+    m_idbFactoryBackend->open(name, IDBCallbacksProxy::create(adoptPtr(callbacks)).get(), origin, 0, dataDir);
 }
 
 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, WebIDBCallbacks* callbacks, const WebSecurityOrigin& origin, WebFrame*, const WebString& dataDir)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to