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 WebSharedWorkerImpl_h
32
#define WebSharedWorkerImpl_h
34
#include "WebSharedWorker.h"
36
#if ENABLE(SHARED_WORKERS)
37
#include "ScriptExecutionContext.h"
38
#include "WebCommonWorkerClient.h"
39
#include "WebContentSecurityPolicy.h"
40
#include "WebFrameClient.h"
41
#include "WebSharedWorkerClient.h"
42
#include "WebWorkerBase.h"
43
#include "WorkerLoaderProxy.h"
44
#include "WorkerObjectProxy.h"
45
#include "WorkerThread.h"
46
#include <wtf/PassOwnPtr.h>
47
#include <wtf/RefPtr.h>
51
class WebApplicationCacheHost;
52
class WebApplicationCacheHostClient;
53
class WebWorkerClient;
54
class WebSecurityOrigin;
59
class WebSharedWorkerClient;
60
// This class is used by the worker process code to talk to the WebCore::SharedWorker implementation.
61
// It can't use it directly since it uses WebKit types, so this class converts the data types.
62
// When the WebCore::SharedWorker object wants to call WebCore::WorkerReportingProxy, this class will
63
// convert to Chrome data types first and then call the supplied WebCommonWorkerClient.
64
class WebSharedWorkerImpl : public WebCore::WorkerObjectProxy
65
, public WebWorkerBase
66
, public WebFrameClient
67
, public WebSharedWorker {
69
explicit WebSharedWorkerImpl(WebSharedWorkerClient*);
71
virtual void postMessageToWorkerObject(
72
PassRefPtr<WebCore::SerializedScriptValue>,
73
PassOwnPtr<WebCore::MessagePortChannelArray>);
74
virtual void postExceptionToWorkerObject(
75
const WTF::String&, int, const WTF::String&);
76
virtual void postConsoleMessageToWorkerObject(
77
WebCore::MessageSource, WebCore::MessageType,
78
WebCore::MessageLevel, const WTF::String&, int, const WTF::String&);
79
virtual void postMessageToPageInspector(const WTF::String&);
80
virtual void updateInspectorStateCookie(const WTF::String&);
81
virtual void confirmMessageFromWorkerObject(bool);
82
virtual void reportPendingActivity(bool);
83
virtual void workerContextClosed();
84
virtual void workerContextDestroyed();
85
virtual WebView* view() const { return m_webView; }
87
// WebCore::WorkerLoaderProxy methods:
88
virtual void postTaskToLoader(PassOwnPtr<WebCore::ScriptExecutionContext::Task>);
89
virtual bool postTaskForModeToWorkerContext(
90
PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const WTF::String& mode);
92
// WebFrameClient methods to support resource loading thru the 'shadow page'.
93
virtual void didCreateDataSource(WebFrame*, WebDataSource*);
94
virtual WebApplicationCacheHost* createApplicationCacheHost(WebFrame*, WebApplicationCacheHostClient*);
97
// WebSharedWorker methods:
98
virtual bool isStarted();
100
virtual void startWorkerContext(const WebURL&, const WebString& name, const WebString& userAgent, const WebString& sourceCode, const WebString& contentSecurityPolicy, WebContentSecurityPolicyType, long long cacheId);
102
virtual void connect(WebMessagePortChannel*, ConnectListener*);
103
virtual void terminateWorkerContext();
104
virtual void clientDestroyed();
106
virtual void pauseWorkerContextOnStart();
107
virtual void resumeWorkerContext();
108
virtual void attachDevTools();
109
virtual void reattachDevTools(const WebString& savedState);
110
virtual void detachDevTools();
111
virtual void dispatchDevToolsMessage(const WebString&);
114
// NewWebWorkerBase methods:
115
WebCommonWorkerClient* commonClient() { return m_client; }
118
virtual ~WebSharedWorkerImpl();
120
WebSharedWorkerClient* client() { return m_client; }
122
void setWorkerThread(PassRefPtr<WebCore::WorkerThread> thread) { m_workerThread = thread; }
123
WebCore::WorkerThread* workerThread() { return m_workerThread.get(); }
125
// Shuts down the worker thread.
126
void stopWorkerThread();
128
// Creates the shadow loader used for worker network requests.
129
void initializeLoader(const WebURL&);
132
static void connectTask(WebCore::ScriptExecutionContext*, PassOwnPtr<WebCore::MessagePortChannel>);
133
// Tasks that are run on the main thread.
134
static void postMessageTask(
135
WebCore::ScriptExecutionContext*,
136
WebSharedWorkerImpl* thisPtr,
138
PassOwnPtr<WebCore::MessagePortChannelArray> channels);
139
static void postExceptionTask(
140
WebCore::ScriptExecutionContext*,
141
WebSharedWorkerImpl* thisPtr,
142
const WTF::String& message,
144
const WTF::String& sourceURL);
145
static void postConsoleMessageTask(
146
WebCore::ScriptExecutionContext*,
147
WebSharedWorkerImpl* thisPtr,
151
const WTF::String& message,
153
const WTF::String& sourceURL);
154
static void postMessageToPageInspectorTask(WebCore::ScriptExecutionContext*, WebSharedWorkerImpl*, const WTF::String&);
155
static void updateInspectorStateCookieTask(WebCore::ScriptExecutionContext*, WebSharedWorkerImpl* thisPtr, const WTF::String& cookie);
156
static void confirmMessageTask(
157
WebCore::ScriptExecutionContext*,
158
WebSharedWorkerImpl* thisPtr,
159
bool hasPendingActivity);
160
static void reportPendingActivityTask(
161
WebCore::ScriptExecutionContext*,
162
WebSharedWorkerImpl* thisPtr,
163
bool hasPendingActivity);
164
static void workerContextClosedTask(
165
WebCore::ScriptExecutionContext*,
166
WebSharedWorkerImpl* thisPtr);
167
static void workerContextDestroyedTask(
168
WebCore::ScriptExecutionContext*,
169
WebSharedWorkerImpl* thisPtr);
171
// 'shadow page' - created to proxy loading requests from the worker.
172
RefPtr<WebCore::ScriptExecutionContext> m_loadingDocument;
174
bool m_askedToTerminate;
176
RefPtr<WebCore::WorkerThread> m_workerThread;
178
WebSharedWorkerClient* m_client;
179
bool m_pauseWorkerContextOnStart;
182
} // namespace WebKit
184
#endif // ENABLE(SHARED_WORKERS)