Index: webkit/glue/webworker_impl.cc |
=================================================================== |
--- webkit/glue/webworker_impl.cc (revision 18410) |
+++ webkit/glue/webworker_impl.cc (working copy) |
@@ -10,6 +10,7 @@ |
#include "KURL.h" |
#include "ScriptExecutionContext.h" |
#include "SecurityOrigin.h" |
+#include "SubstituteData.h" |
#include "WorkerContext.h" |
#include "WorkerThread.h" |
#include <wtf/MainThread.h> |
@@ -18,10 +19,16 @@ |
#undef LOG |
#include "base/logging.h" |
+#include "webkit/api/public/WebScreenInfo.h" |
#include "webkit/api/public/WebString.h" |
#include "webkit/api/public/WebURL.h" |
#include "webkit/api/public/WebWorkerClient.h" |
#include "webkit/glue/glue_util.h" |
+#include "webkit/glue/webdatasource_impl.h" |
+#include "webkit/glue/webframe_impl.h" |
+#include "webkit/glue/webpreferences.h" |
+#include "webkit/glue/webview.h" |
+#include "webkit/glue/webview_delegate.h" |
#include "webkit/glue/webworker_impl.h" |
using WebKit::WebWorker; |
@@ -31,6 +38,58 @@ |
#if ENABLE(WORKERS) |
+// Dummy WebViewDelegate - we only need it in Worker process to load a |
+// 'shadow page' which will initialize WebCore loader. |
+class WorkerWebViewDelegate : public WebViewDelegate { |
+ public: |
+ WorkerWebViewDelegate() {} |
+ virtual void AddRef() { } |
+ virtual void Release() { } |
+ virtual void Blur(WebWidget *webwidget) { } |
+ virtual void CloseWidgetSoon(WebWidget *webwidget) { } |
+ virtual void DidInvalidateRect(WebWidget *webwidget, |
+ const WebKit::WebRect &rect) { } |
+ virtual void DidMove(WebWidget *webwidget, const WebPluginGeometry &move) { } |
+ virtual void DidScrollRect(WebWidget *webwidget, int dx, int dy, |
+ const WebKit::WebRect &clip_rect) { } |
+ virtual void Focus(WebWidget *webwidget) { } |
+ virtual gfx::NativeViewId GetContainingView(WebWidget *webwidget) { |
+ return gfx::NativeViewId(); |
+ } |
+ virtual void GetRootWindowRect(WebWidget *webwidget, |
+ WebKit::WebRect *rect) { } |
+ virtual void GetRootWindowResizerRect(WebWidget *webwidget, |
+ WebKit::WebRect *rect) { } |
+ virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget *webwidget) { |
+ WebKit::WebScreenInfo info; |
+ return info; |
+ } |
+ virtual void GetWindowRect(WebWidget *webwidget, WebKit::WebRect *rect) { } |
+ virtual bool IsHidden(WebWidget *webwidget) { return true; } |
+ virtual void RunModal(WebWidget *webwidget) { } |
+ virtual void SetCursor(WebWidget *webwidget, const WebCursor &cursor) { } |
+ virtual void SetWindowRect(WebWidget *webwidget, |
+ const WebKit::WebRect &rect) { } |
+ virtual void Show(WebWidget *webwidget, WindowOpenDisposition disposition) { } |
+ virtual void ShowAsPopupWithItems(WebWidget *webwidget, |
+ const WebKit::WebRect &bounds, |
+ int item_height, |
+ int selected_index, |
+ const std::vector<WebMenuItem> &items) { } |
+ // Tell the loader to load the data into the 'shadow page' synchronously, |
+ // so we can grab the resulting Document right after load. |
+ virtual void DidCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
+ static_cast<WebDataSourceImpl*>(ds)->setDeferMainResourceDataLoad(false); |
+ } |
+ // Lazy allocate and leak this instance. |
+ static WorkerWebViewDelegate* worker_delegate() { |
+ static WorkerWebViewDelegate* worker_delegate = new WorkerWebViewDelegate(); |
+ return worker_delegate; |
+ } |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WorkerWebViewDelegate); |
+}; |
+ |
namespace WebKit { |
WebWorker* WebWorker::create(WebWorkerClient* client) { |
@@ -56,11 +115,14 @@ |
} |
} |
-WebWorkerImpl::WebWorkerImpl(WebWorkerClient* client) : client_(client) { |
+WebWorkerImpl::WebWorkerImpl(WebWorkerClient* client) |
+ : client_(client), |
+ web_view_(NULL) { |
InitializeWebKitStaticValues(); |
} |
WebWorkerImpl::~WebWorkerImpl() { |
+ web_view_->Close(); |
} |
void WebWorkerImpl::PostMessageToWorkerContextTask( |
@@ -81,6 +143,33 @@ |
void WebWorkerImpl::startWorkerContext(const WebURL& script_url, |
const WebString& user_agent, |
const WebString& source_code) { |
+ // Create 'shadow page'. This page is never displayed, it is used to proxy the |
+ // loading requests from the worker context to the rest of WebKit and Chromium |
+ // infrastructure. |
+ DCHECK(!web_view_); |
+ web_view_ = WebView::Create(WorkerWebViewDelegate::worker_delegate(), |
+ WebPreferences()); |
+ |
+ WebFrameImpl* web_frame = |
+ static_cast<WebFrameImpl*>(web_view_->GetMainFrame()); |
+ |
+ // Construct substitute data source for the 'shadow page'. We only need it |
+ // to have same origin as the worker so the loading checks work correctly. |
+ WebCore::CString content("Shadow page"); |
+ int len = static_cast<int>(content.length()); |
+ RefPtr<WebCore::SharedBuffer> buf( |
+ WebCore::SharedBuffer::create(content.data(), len)); |
+ WebCore::SubstituteData subst_data(buf, |
+ WebCore::String("text/html"), |
+ WebCore::String("UTF-8"), |
+ WebCore::KURL()); |
+ WebCore::ResourceRequest request(webkit_glue::GURLToKURL(script_url), |
+ WebCore::CString()); |
+ web_frame->frame()->loader()->load(request, subst_data, false); |
+ |
+ // This document will be used as 'loading context' for the worker. |
+ loading_document_ = web_frame->frame()->document(); |
+ |
worker_thread_ = WebCore::WorkerThread::create( |
webkit_glue::WebURLToKURL(script_url), |
webkit_glue::WebStringToString(user_agent), |
@@ -235,13 +324,14 @@ |
void WebWorkerImpl::postTaskToLoader( |
PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { |
- NOTIMPLEMENTED(); |
+ ASSERT(loading_document_->isDocument()); |
+ loading_document_->postTask(task); |
} |
void WebWorkerImpl::postTaskForModeToWorkerContext( |
PassRefPtr<WebCore::ScriptExecutionContext::Task> task, |
const WebCore::String& mode) { |
- NOTIMPLEMENTED(); |
+ worker_thread_->runLoop().postTaskForMode(task, mode); |
} |
void WebWorkerImpl::WorkerContextDestroyedTask( |