~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/chromium/src/WebSharedWorkerImpl.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 *
 
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
 
13
 * distribution.
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
#ifndef WebSharedWorkerImpl_h
 
32
#define WebSharedWorkerImpl_h
 
33
 
 
34
#include "WebSharedWorker.h"
 
35
 
 
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>
 
48
 
 
49
 
 
50
namespace WebKit {
 
51
class WebApplicationCacheHost;
 
52
class WebApplicationCacheHostClient;
 
53
class WebWorkerClient;
 
54
class WebSecurityOrigin;
 
55
class WebString;
 
56
class WebURL;
 
57
class WebView;
 
58
class WebWorker;
 
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 {
 
68
public:
 
69
    explicit WebSharedWorkerImpl(WebSharedWorkerClient*);
 
70
 
 
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; }
 
86
 
 
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);
 
91
 
 
92
    // WebFrameClient methods to support resource loading thru the 'shadow page'.
 
93
    virtual void didCreateDataSource(WebFrame*, WebDataSource*);
 
94
    virtual WebApplicationCacheHost* createApplicationCacheHost(WebFrame*, WebApplicationCacheHostClient*);
 
95
 
 
96
 
 
97
    // WebSharedWorker methods:
 
98
    virtual bool isStarted();
 
99
 
 
100
    virtual void startWorkerContext(const WebURL&, const WebString& name, const WebString& userAgent, const WebString& sourceCode, const WebString& contentSecurityPolicy, WebContentSecurityPolicyType, long long cacheId);
 
101
 
 
102
    virtual void connect(WebMessagePortChannel*, ConnectListener*);
 
103
    virtual void terminateWorkerContext();
 
104
    virtual void clientDestroyed();
 
105
 
 
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&);
 
112
 
 
113
 
 
114
    // NewWebWorkerBase methods:
 
115
    WebCommonWorkerClient* commonClient() { return m_client; }
 
116
 
 
117
private:
 
118
    virtual ~WebSharedWorkerImpl();
 
119
 
 
120
    WebSharedWorkerClient* client() { return m_client; }
 
121
 
 
122
    void setWorkerThread(PassRefPtr<WebCore::WorkerThread> thread) { m_workerThread = thread; }
 
123
    WebCore::WorkerThread* workerThread() { return m_workerThread.get(); }
 
124
 
 
125
    // Shuts down the worker thread.
 
126
    void stopWorkerThread();
 
127
 
 
128
    // Creates the shadow loader used for worker network requests.
 
129
    void initializeLoader(const WebURL&);
 
130
 
 
131
 
 
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,
 
137
        WTF::String message,
 
138
        PassOwnPtr<WebCore::MessagePortChannelArray> channels);
 
139
    static void postExceptionTask(
 
140
        WebCore::ScriptExecutionContext*,
 
141
        WebSharedWorkerImpl* thisPtr,
 
142
        const WTF::String& message,
 
143
        int lineNumber,
 
144
        const WTF::String& sourceURL);
 
145
    static void postConsoleMessageTask(
 
146
        WebCore::ScriptExecutionContext*,
 
147
        WebSharedWorkerImpl* thisPtr,
 
148
        int source,
 
149
        int type,
 
150
        int level,
 
151
        const WTF::String& message,
 
152
        int lineNumber,
 
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);
 
170
 
 
171
    // 'shadow page' - created to proxy loading requests from the worker.
 
172
    RefPtr<WebCore::ScriptExecutionContext> m_loadingDocument;
 
173
    WebView* m_webView;
 
174
    bool m_askedToTerminate;
 
175
 
 
176
    RefPtr<WebCore::WorkerThread> m_workerThread;
 
177
 
 
178
    WebSharedWorkerClient* m_client;
 
179
    bool m_pauseWorkerContextOnStart;
 
180
};
 
181
 
 
182
} // namespace WebKit
 
183
 
 
184
#endif // ENABLE(SHARED_WORKERS)
 
185
 
 
186
#endif