2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebWorkerClientImpl_h
32 #define WebWorkerClientImpl_h
36 #include "ScriptExecutionContext.h"
37 #include "WorkerContextProxy.h"
38 #include "WorkerLoaderProxy.h"
39 #include "WorkerMessagingProxy.h"
40 #include "WorkerObjectProxy.h"
42 #include "WebFileSystem.h"
43 #include "WebWorkerBase.h"
44 #include "WebWorkerClient.h"
45 #include <wtf/OwnPtr.h>
46 #include <wtf/PassOwnPtr.h>
47 #include <wtf/RefPtr.h>
54 // This class provides chromium implementation for WorkerContextProxt, WorkerObjectProxy amd WorkerLoaderProxy
55 // for in-proc dedicated workers. It also acts as a bridge for workers to chromium implementation of file systems,
56 // databases and other related functionality.
58 // In essence, this class wraps WorkerMessagingProxy.
59 class WebWorkerClientImpl : public WebCore::WorkerContextProxy
60 , public WebCore::WorkerObjectProxy
61 , public NewWebWorkerBase
62 , public NewWebCommonWorkerClient {
64 // WebCore::WorkerContextProxy Factory.
65 static WebCore::WorkerContextProxy* createWorkerContextProxy(WebCore::Worker*);
67 // WebCore::WorkerContextProxy methods:
68 // These are called on the thread that created the worker. In the renderer
69 // process, this will be the main WebKit thread.
70 virtual void startWorkerContext(const WebCore::KURL&,
73 virtual void terminateWorkerContext();
74 virtual void postMessageToWorkerContext(
75 PassRefPtr<WebCore::SerializedScriptValue> message,
76 PassOwnPtr<WebCore::MessagePortChannelArray> channels);
77 virtual bool hasPendingActivity() const;
78 virtual void workerObjectDestroyed();
81 virtual void connectToInspector(WebCore::WorkerContextProxy::PageInspector*);
82 virtual void disconnectFromInspector();
83 virtual void sendMessageToInspector(const String&);
84 virtual void postMessageToPageInspector(const String&);
86 // WebCore::WorkerLoaderProxy methods:
87 virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
88 virtual void postTaskForModeToWorkerContext(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const String& mode);
90 // WebCore::WorkerObjectProxy methods:
91 virtual void postMessageToWorkerObject(PassRefPtr<WebCore::SerializedScriptValue>, PassOwnPtr<WebCore::MessagePortChannelArray>);
92 virtual void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, const String& sourceURL);
94 virtual void postConsoleMessageToWorkerObject(WebCore::MessageSource, WebCore::MessageType, WebCore::MessageLevel,
95 const String& message, int lineNumber, const String& sourceURL);
96 virtual void confirmMessageFromWorkerObject(bool);
97 virtual void reportPendingActivity(bool);
98 virtual void workerContextClosed();
99 virtual void workerContextDestroyed();
101 // WebWorkerClientBase methods:
102 virtual bool allowDatabase(WebFrame*, const WebString& name, const WebString& displayName, unsigned long estimatedSize);
103 virtual bool allowFileSystem();
104 virtual void openFileSystem(WebFileSystem::Type, long long size, bool create,
105 WebFileSystemCallbacks*);
107 virtual void dispatchDevToolsMessage(const WebString&);
109 // WebCommentWorkerBase methods:
110 virtual NewWebCommonWorkerClient* newCommonClient() { return this; }
111 virtual WebView* view() const;
114 WebWorkerClientImpl(WebCore::Worker*, WebFrameImpl*);
115 virtual ~WebWorkerClientImpl();
117 WebCore::WorkerMessagingProxy* m_proxy;
118 // Guard against context from being destroyed before a worker exits.
119 RefPtr<WebCore::ScriptExecutionContext> m_scriptExecutionContext;
120 WebFrameImpl* m_webFrame;
121 WebCore::WorkerContextProxy::PageInspector* m_pageInspector;
124 } // namespace WebKit;
126 #endif // ENABLE(WORKERS)