Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: Source/core/workers/WorkerContext.h

Issue 17648006: Rename WorkerContext to WorkerGlobalScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/workers/Worker.cpp ('k') | Source/core/workers/WorkerContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008, 2009 Apple 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
27 #ifndef WorkerContext_h
28 #define WorkerContext_h
29
30 #include "bindings/v8/ScriptWrappable.h"
31 #include "bindings/v8/WorkerScriptController.h"
32 #include "core/dom/EventListener.h"
33 #include "core/dom/EventNames.h"
34 #include "core/dom/EventTarget.h"
35 #include "core/dom/ScriptExecutionContext.h"
36 #include "core/page/ContentSecurityPolicy.h"
37 #include "core/workers/WorkerEventQueue.h"
38 #include <wtf/Assertions.h>
39 #include <wtf/HashMap.h>
40 #include <wtf/OwnPtr.h>
41 #include <wtf/PassRefPtr.h>
42 #include <wtf/RefCounted.h>
43 #include <wtf/RefPtr.h>
44 #include <wtf/text/AtomicStringHash.h>
45
46 namespace WebCore {
47
48 class Blob;
49 class DOMURL;
50 class ScheduledAction;
51 class WorkerInspectorController;
52 class WorkerLocation;
53 class WorkerNavigator;
54 class WorkerThread;
55
56 class WorkerContext : public RefCounted<WorkerContext>, public ScriptWrappab le, public ScriptExecutionContext, public EventTarget {
57 public:
58 virtual ~WorkerContext();
59
60 virtual bool isWorkerContext() const OVERRIDE { return true; }
61
62 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
63
64 virtual bool isSharedWorkerContext() const { return false; }
65 virtual bool isDedicatedWorkerContext() const { return false; }
66
67 const KURL& url() const { return m_url; }
68 KURL completeURL(const String&) const;
69
70 virtual String userAgent(const KURL&) const;
71
72 virtual void disableEval(const String& errorMessage) OVERRIDE;
73
74 WorkerScriptController* script() { return m_script.get(); }
75 void clearScript() { m_script.clear(); }
76 void clearInspector();
77
78 WorkerThread* thread() const { return m_thread; }
79
80 virtual void postTask(PassOwnPtr<Task>) OVERRIDE; // Executes the task o n context's thread asynchronously.
81
82 // WorkerGlobalScope
83 WorkerContext* self() { return this; }
84 WorkerLocation* location() const;
85 void close();
86
87 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
88
89 // WorkerUtils
90 virtual void importScripts(const Vector<String>& urls, ExceptionCode&);
91 WorkerNavigator* navigator() const;
92
93 // Timers
94 int setTimeout(PassOwnPtr<ScheduledAction>, int timeout);
95 void clearTimeout(int timeoutId);
96 int setInterval(PassOwnPtr<ScheduledAction>, int timeout);
97 void clearInterval(int timeoutId);
98
99 // ScriptExecutionContext
100 virtual WorkerEventQueue* eventQueue() const OVERRIDE;
101
102 virtual bool isContextThread() const OVERRIDE;
103 virtual bool isJSExecutionForbidden() const OVERRIDE;
104
105 WorkerInspectorController* workerInspectorController() { return m_worker InspectorController.get(); }
106 // These methods are used for GC marking. See JSWorkerContext::visitChil drenVirtual(SlotVisitor&) in
107 // JSWorkerContextCustom.cpp.
108 WorkerNavigator* optionalNavigator() const { return m_navigator.get(); }
109 WorkerLocation* optionalLocation() const { return m_location.get(); }
110
111 using RefCounted<WorkerContext>::ref;
112 using RefCounted<WorkerContext>::deref;
113
114 bool isClosing() { return m_closing; }
115
116 // An observer interface to be notified when the worker thread is gettin g stopped.
117 class Observer {
118 WTF_MAKE_NONCOPYABLE(Observer);
119 public:
120 Observer(WorkerContext*);
121 virtual ~Observer();
122 virtual void notifyStop() = 0;
123 void stopObserving();
124 private:
125 WorkerContext* m_context;
126 };
127 friend class Observer;
128 void registerObserver(Observer*);
129 void unregisterObserver(Observer*);
130 void notifyObserversOfStop();
131
132 virtual const SecurityOrigin* topOrigin() const OVERRIDE { return m_topO rigin.get(); }
133
134 double timeOrigin() const { return m_timeOrigin; }
135
136 protected:
137 WorkerContext(const KURL&, const String& userAgent, WorkerThread*, PassR efPtr<SecurityOrigin> topOrigin, double timeOrigin);
138 void applyContentSecurityPolicyFromString(const String& contentSecurityP olicy, ContentSecurityPolicy::HeaderType);
139
140 virtual void logExceptionToConsole(const String& errorMessage, const Str ing& sourceURL, int lineNumber, PassRefPtr<ScriptCallStack>) OVERRIDE;
141 void addMessageToWorkerConsole(MessageSource, MessageLevel, const String & message, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptCallSt ack>, ScriptState* = 0, unsigned long requestIdentifier = 0);
142
143 private:
144 virtual void refScriptExecutionContext() OVERRIDE { ref(); }
145 virtual void derefScriptExecutionContext() OVERRIDE { deref(); }
146
147 virtual void refEventTarget() OVERRIDE { ref(); }
148 virtual void derefEventTarget() OVERRIDE { deref(); }
149 virtual EventTargetData* eventTargetData() OVERRIDE;
150 virtual EventTargetData* ensureEventTargetData() OVERRIDE;
151
152 virtual const KURL& virtualURL() const OVERRIDE;
153 virtual KURL virtualCompleteURL(const String&) const;
154
155 virtual void addMessage(MessageSource, MessageLevel, const String& messa ge, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptCallStack>, S criptState* = 0, unsigned long requestIdentifier = 0) OVERRIDE;
156 virtual void addConsoleMessage(MessageSource, MessageLevel, const String & message, unsigned long requestIdentifier = 0) OVERRIDE;
157
158 virtual EventTarget* errorEventTarget() OVERRIDE;
159
160 KURL m_url;
161 String m_userAgent;
162
163 mutable RefPtr<WorkerLocation> m_location;
164 mutable RefPtr<WorkerNavigator> m_navigator;
165
166 OwnPtr<WorkerScriptController> m_script;
167 WorkerThread* m_thread;
168
169 mutable RefPtr<DOMURL> m_domURL;
170 OwnPtr<WorkerInspectorController> m_workerInspectorController;
171 bool m_closing;
172 EventTargetData m_eventTargetData;
173
174 HashSet<Observer*> m_workerObservers;
175
176 OwnPtr<WorkerEventQueue> m_eventQueue;
177
178 RefPtr<SecurityOrigin> m_topOrigin;
179
180 double m_timeOrigin;
181 };
182
183 } // namespace WebCore
184
185 #endif // WorkerContext_h
OLDNEW
« no previous file with comments | « Source/core/workers/Worker.cpp ('k') | Source/core/workers/WorkerContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698