Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / workers / WorkerGlobalScope.h
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 WorkerGlobalScope_h
28 #define WorkerGlobalScope_h
29
30 #include "bindings/core/v8/WorkerScriptController.h"
31 #include "core/dom/ExecutionContext.h"
32 #include "core/events/EventListener.h"
33 #include "core/events/EventTarget.h"
34 #include "core/frame/DOMWindowBase64.h"
35 #include "core/frame/UseCounter.h"
36 #include "core/frame/csp/ContentSecurityPolicy.h"
37 #include "core/workers/WorkerEventQueue.h"
38 #include "platform/heap/Handle.h"
39 #include "platform/network/ContentSecurityPolicyParsers.h"
40 #include "wtf/Assertions.h"
41 #include "wtf/HashMap.h"
42 #include "wtf/OwnPtr.h"
43 #include "wtf/PassRefPtr.h"
44 #include "wtf/RefCounted.h"
45 #include "wtf/RefPtr.h"
46 #include "wtf/text/AtomicStringHash.h"
47
48 namespace blink {
49
50 class Blob;
51 class ConsoleMessage;
52 class ConsoleMessageStorage;
53 class ExceptionState;
54 class ScheduledAction;
55 class WorkerClients;
56 class WorkerConsole;
57 class WorkerInspectorController;
58 class WorkerLocation;
59 class WorkerNavigator;
60 class WorkerThread;
61
62 class WorkerGlobalScope : public RefCountedWillBeGarbageCollectedFinalized<WorkerGlobalScope>, public SecurityContext, public ExecutionContext, public WillBeHeapSupplementable<WorkerGlobalScope>, public EventTargetWithInlineData, public DOMWindowBase64 {
63     DEFINE_WRAPPERTYPEINFO();
64     REFCOUNTED_EVENT_TARGET(WorkerGlobalScope);
65     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WorkerGlobalScope);
66 public:
67     virtual ~WorkerGlobalScope();
68
69     virtual bool isWorkerGlobalScope() const override final { return true; }
70
71     virtual ExecutionContext* executionContext() const override final;
72
73     virtual void countFeature(UseCounter::Feature) const;
74     virtual void countDeprecation(UseCounter::Feature) const;
75
76     const KURL& url() const { return m_url; }
77     KURL completeURL(const String&) const;
78
79     virtual String userAgent(const KURL&) const override final;
80     virtual void disableEval(const String& errorMessage) override final;
81
82     WorkerScriptController* script() { return m_script.get(); }
83     void clearScript() { m_script.clear(); }
84     void clearInspector();
85
86     virtual void didEvaluateWorkerScript();
87     void dispose();
88
89     WorkerThread* thread() const { return m_thread; }
90
91     virtual void postTask(PassOwnPtr<ExecutionContextTask>) override final; // Executes the task on context's thread asynchronously.
92
93     // WorkerGlobalScope
94     WorkerGlobalScope* self() { return this; }
95     WorkerConsole* console();
96     WorkerLocation* location() const;
97     void close();
98
99     DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
100
101     // WorkerUtils
102     virtual void importScripts(const Vector<String>& urls, ExceptionState&);
103     WorkerNavigator* navigator() const;
104
105     // ExecutionContextClient
106     virtual WorkerEventQueue* eventQueue() const override final;
107     virtual SecurityContext& securityContext() override final { return *this; }
108
109     virtual bool isContextThread() const override final;
110     virtual bool isJSExecutionForbidden() const override final;
111
112     virtual double timerAlignmentInterval() const override final;
113
114     WorkerInspectorController* workerInspectorController() { return m_workerInspectorController.get(); }
115
116     bool isClosing() { return m_closing; }
117
118     virtual void stopFetch() { }
119
120     bool idleNotification();
121
122     double timeOrigin() const { return m_timeOrigin; }
123
124     WorkerClients* clients() { return m_workerClients.get(); }
125
126     using SecurityContext::securityOrigin;
127     using SecurityContext::contentSecurityPolicy;
128
129     virtual void addConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override final;
130     ConsoleMessageStorage* messageStorage();
131
132     virtual void trace(Visitor*) override;
133
134 protected:
135     WorkerGlobalScope(const KURL&, const String& userAgent, WorkerThread*, double timeOrigin, const SecurityOrigin*, PassOwnPtrWillBeRawPtr<WorkerClients>);
136     void applyContentSecurityPolicyFromString(const String& contentSecurityPolicy, ContentSecurityPolicyHeaderType);
137
138     virtual void logExceptionToConsole(const String& errorMessage, int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack>) override;
139     void addMessageToWorkerConsole(PassRefPtrWillBeRawPtr<ConsoleMessage>);
140
141 private:
142 #if !ENABLE(OILPAN)
143     virtual void refExecutionContext() override final { ref(); }
144     virtual void derefExecutionContext() override final { deref(); }
145 #endif
146
147     virtual const KURL& virtualURL() const override final;
148     virtual KURL virtualCompleteURL(const String&) const override final;
149
150     virtual void reportBlockedScriptExecutionToInspector(const String& directiveText) override final;
151
152     virtual EventTarget* errorEventTarget() override final;
153     virtual void didUpdateSecurityOrigin() override final { }
154
155     KURL m_url;
156     String m_userAgent;
157
158     mutable RefPtrWillBeMember<WorkerConsole> m_console;
159     mutable RefPtrWillBeMember<WorkerLocation> m_location;
160     mutable RefPtrWillBeMember<WorkerNavigator> m_navigator;
161
162     OwnPtr<WorkerScriptController> m_script;
163     WorkerThread* m_thread;
164
165     RefPtrWillBeMember<WorkerInspectorController> m_workerInspectorController;
166     bool m_closing;
167
168     OwnPtrWillBeMember<WorkerEventQueue> m_eventQueue;
169
170     OwnPtrWillBeMember<WorkerClients> m_workerClients;
171
172     double m_timeOrigin;
173
174     OwnPtrWillBeMember<ConsoleMessageStorage> m_messageStorage;
175 };
176
177 DEFINE_TYPE_CASTS(WorkerGlobalScope, ExecutionContext, context, context->isWorkerGlobalScope(), context.isWorkerGlobalScope());
178
179 } // namespace blink
180
181 #endif // WorkerGlobalScope_h