summaryrefslogtreecommitdiffstats
path: root/WebKit/chromium/src/WebWorkerBase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/chromium/src/WebWorkerBase.cpp')
-rw-r--r--WebKit/chromium/src/WebWorkerBase.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/WebKit/chromium/src/WebWorkerBase.cpp b/WebKit/chromium/src/WebWorkerBase.cpp
index 8e26560..1fedeb2 100644
--- a/WebKit/chromium/src/WebWorkerBase.cpp
+++ b/WebKit/chromium/src/WebWorkerBase.cpp
@@ -31,6 +31,7 @@
#include "config.h"
#include "WebWorkerBase.h"
+#include "DatabaseTask.h"
#include "GenericWorkerTask.h"
#include "MessagePortChannel.h"
#include "PlatformMessagePortChannel.h"
@@ -39,9 +40,12 @@
#include "WebFrameClient.h"
#include "WebFrameImpl.h"
#include "WebMessagePortChannel.h"
+#include "WebRuntimeFeatures.h"
+#include "WebSettings.h"
#include "WebView.h"
#include "WebWorkerClient.h"
+#include "WorkerScriptController.h"
#include "WorkerThread.h"
#include <wtf/MainThread.h>
@@ -51,6 +55,67 @@ namespace WebKit {
#if ENABLE(WORKERS)
+static const char allowDatabaseMode[] = "allowDatabaseMode";
+
+namespace {
+
+// This class is used to route the result of the WebWorkerBase::allowDatabase
+// call back to the worker context.
+class AllowDatabaseMainThreadBridge : public ThreadSafeShared<AllowDatabaseMainThreadBridge> {
+public:
+ static PassRefPtr<AllowDatabaseMainThreadBridge> create(WebWorkerBase* worker, const WebCore::String& mode, WebCommonWorkerClient* commonClient, WebFrame* frame, const WebCore::String& name, const WebCore::String& displayName, unsigned long estimatedSize)
+ {
+ return adoptRef(new AllowDatabaseMainThreadBridge(worker, mode, commonClient, frame, name, displayName, estimatedSize));
+ }
+
+ // These methods are invoked on the worker context.
+ void cancel()
+ {
+ MutexLocker locker(m_mutex);
+ m_worker = 0;
+ }
+
+ bool result()
+ {
+ return m_result;
+ }
+
+ // This method is invoked on the main thread.
+ void signalCompleted(bool result)
+ {
+ MutexLocker locker(m_mutex);
+ if (m_worker)
+ m_worker->postTaskForModeToWorkerContext(createCallbackTask(&didComplete, this, result), m_mode);
+ }
+
+private:
+ AllowDatabaseMainThreadBridge(WebWorkerBase* worker, const WebCore::String& mode, WebCommonWorkerClient* commonClient, WebFrame* frame, const WebCore::String& name, const WebCore::String& displayName, unsigned long estimatedSize)
+ : m_worker(worker)
+ , m_mode(mode)
+ {
+ worker->dispatchTaskToMainThread(createCallbackTask(&allowDatabaseTask, commonClient, frame, String(name), String(displayName), estimatedSize, this));
+ }
+
+ static void allowDatabaseTask(WebCore::ScriptExecutionContext* context, WebCommonWorkerClient* commonClient, WebFrame* frame, const WebCore::String name, const WebCore::String displayName, unsigned long estimatedSize, PassRefPtr<AllowDatabaseMainThreadBridge> bridge)
+ {
+ if (!commonClient)
+ bridge->signalCompleted(false);
+ else
+ bridge->signalCompleted(commonClient->allowDatabase(frame, name, displayName, estimatedSize));
+ }
+
+ static void didComplete(WebCore::ScriptExecutionContext* context, PassRefPtr<AllowDatabaseMainThreadBridge> bridge, bool result)
+ {
+ bridge->m_result = result;
+ }
+
+ bool m_result;
+ Mutex m_mutex;
+ WebWorkerBase* m_worker;
+ WebCore::String m_mode;
+};
+}
+
// This function is called on the main thread to force to initialize some static
// values used in WebKit before any worker thread is started. This is because in
// our worker processs, we do not run any WebKit code in main thread and thus
@@ -101,6 +166,7 @@ void WebWorkerBase::initializeLoader(const WebURL& url)
// infrastructure.
ASSERT(!m_webView);
m_webView = WebView::create(0);
+ m_webView->settings()->setOfflineWebApplicationCacheEnabled(WebRuntimeFeatures::isApplicationCacheEnabled());
m_webView->initializeMainFrame(this);
WebFrameImpl* webFrame = static_cast<WebFrameImpl*>(m_webView->mainFrame());
@@ -144,6 +210,27 @@ WebApplicationCacheHost* WebWorkerBase::createApplicationCacheHost(WebFrame*, We
return 0;
}
+bool WebWorkerBase::allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize)
+{
+ WorkerRunLoop& runLoop = m_workerThread->runLoop();
+ WorkerScriptController* controller = WorkerScriptController::controllerForContext();
+ WorkerContext* workerContext = controller->workerContext();
+
+ // Create a unique mode just for this synchronous call.
+ String mode = allowDatabaseMode;
+ mode.append(String::number(runLoop.createUniqueId()));
+
+ RefPtr<AllowDatabaseMainThreadBridge> bridge = AllowDatabaseMainThreadBridge::create(this, mode, commonClient(), m_webView->mainFrame(), String(name), String(displayName), estimatedSize);
+
+ // Either the bridge returns, or the queue gets terminated.
+ if (runLoop.runInMode(workerContext, mode) == MessageQueueTerminated) {
+ bridge->cancel();
+ return false;
+ }
+
+ return bridge->result();
+}
+
// WorkerObjectProxy -----------------------------------------------------------
void WebWorkerBase::postMessageToWorkerObject(PassRefPtr<SerializedScriptValue> message,