| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "wtf/Assertions.h" | 41 #include "wtf/Assertions.h" |
| 42 #include "wtf/HashMap.h" | 42 #include "wtf/HashMap.h" |
| 43 #include "wtf/OwnPtr.h" | 43 #include "wtf/OwnPtr.h" |
| 44 #include "wtf/PassRefPtr.h" | 44 #include "wtf/PassRefPtr.h" |
| 45 #include "wtf/RefCounted.h" | 45 #include "wtf/RefCounted.h" |
| 46 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 47 #include "wtf/text/AtomicStringHash.h" | 47 #include "wtf/text/AtomicStringHash.h" |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 class Blob; | 51 class Blob; |
| 52 class ExceptionState; | 52 class ExceptionState; |
| 53 class ScheduledAction; | 53 class ScheduledAction; |
| 54 class WorkerClients; | 54 class WorkerClients; |
| 55 class WorkerConsole; | 55 class WorkerConsole; |
| 56 class WorkerInspectorController; | 56 class WorkerInspectorController; |
| 57 class WorkerLocation; | 57 class WorkerLocation; |
| 58 class WorkerNavigator; | 58 class WorkerNavigator; |
| 59 class WorkerThread; | 59 class WorkerThread; |
| 60 | 60 |
| 61 class WorkerGlobalScope : public RefCountedWillBeGarbageCollectedFinalized<W
orkerGlobalScope>, public SecurityContext, public ExecutionContext, public Execu
tionContextClient, public WillBeHeapSupplementable<WorkerGlobalScope>, public Ev
entTargetWithInlineData, public DOMWindowBase64 { | 61 class WorkerGlobalScope : public RefCountedWillBeGarbageCollectedFinalized<Worke
rGlobalScope>, public SecurityContext, public ExecutionContext, public Execution
ContextClient, public WillBeHeapSupplementable<WorkerGlobalScope>, public EventT
argetWithInlineData, public DOMWindowBase64 { |
| 62 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WorkerGlobalScope); | 62 DEFINE_WRAPPERTYPEINFO(); |
| 63 REFCOUNTED_EVENT_TARGET(WorkerGlobalScope); | 63 REFCOUNTED_EVENT_TARGET(WorkerGlobalScope); |
| 64 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WorkerGlobalScope); |
| 65 public: |
| 66 virtual ~WorkerGlobalScope(); |
| 67 |
| 68 virtual bool isWorkerGlobalScope() const OVERRIDE FINAL { return true; } |
| 69 virtual bool isSharedWorkerGlobalScope() const OVERRIDE { return false; } |
| 70 virtual bool isDedicatedWorkerGlobalScope() const OVERRIDE { return false; } |
| 71 virtual bool isServiceWorkerGlobalScope() const OVERRIDE { return false; } |
| 72 |
| 73 virtual ExecutionContext* executionContext() const OVERRIDE FINAL; |
| 74 |
| 75 virtual void countFeature(UseCounter::Feature) const; |
| 76 virtual void countDeprecation(UseCounter::Feature) const; |
| 77 |
| 78 const KURL& url() const { return m_url; } |
| 79 KURL completeURL(const String&) const; |
| 80 |
| 81 virtual String userAgent(const KURL&) const OVERRIDE FINAL; |
| 82 virtual void disableEval(const String& errorMessage) OVERRIDE FINAL; |
| 83 |
| 84 WorkerScriptController* script() { return m_script.get(); } |
| 85 void clearScript() { m_script.clear(); } |
| 86 void clearInspector(); |
| 87 |
| 88 // FIXME: We can remove this interface when we remove openDatabaseSync. |
| 89 class TerminationObserver { |
| 64 public: | 90 public: |
| 65 virtual ~WorkerGlobalScope(); | 91 virtual ~TerminationObserver() { } |
| 92 // The function is probably called in the main thread. |
| 93 virtual void wasRequestedToTerminate() = 0; |
| 94 }; |
| 95 void registerTerminationObserver(TerminationObserver*); |
| 96 void unregisterTerminationObserver(TerminationObserver*); |
| 97 void wasRequestedToTerminate(); |
| 66 | 98 |
| 67 virtual bool isWorkerGlobalScope() const OVERRIDE FINAL { return true; } | 99 void dispose(); |
| 68 virtual bool isSharedWorkerGlobalScope() const OVERRIDE { return false;
} | |
| 69 virtual bool isDedicatedWorkerGlobalScope() const OVERRIDE { return fals
e; } | |
| 70 virtual bool isServiceWorkerGlobalScope() const OVERRIDE { return false;
} | |
| 71 | 100 |
| 72 virtual ExecutionContext* executionContext() const OVERRIDE FINAL; | 101 WorkerThread* thread() const { return m_thread; } |
| 73 | 102 |
| 74 virtual void countFeature(UseCounter::Feature) const; | 103 virtual void postTask(PassOwnPtr<ExecutionContextTask>) OVERRIDE FINAL; // E
xecutes the task on context's thread asynchronously. |
| 75 virtual void countDeprecation(UseCounter::Feature) const; | |
| 76 | 104 |
| 77 const KURL& url() const { return m_url; } | 105 // WorkerGlobalScope |
| 78 KURL completeURL(const String&) const; | 106 WorkerGlobalScope* self() { return this; } |
| 107 WorkerConsole* console(); |
| 108 WorkerLocation* location() const; |
| 109 void close(); |
| 79 | 110 |
| 80 virtual String userAgent(const KURL&) const OVERRIDE FINAL; | 111 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 81 virtual void disableEval(const String& errorMessage) OVERRIDE FINAL; | |
| 82 | 112 |
| 83 WorkerScriptController* script() { return m_script.get(); } | 113 // WorkerUtils |
| 84 void clearScript() { m_script.clear(); } | 114 virtual void importScripts(const Vector<String>& urls, ExceptionState&); |
| 85 void clearInspector(); | 115 WorkerNavigator* navigator() const; |
| 86 | 116 |
| 87 // FIXME: We can remove this interface when we remove openDatabaseSync. | 117 // ExecutionContextClient |
| 88 class TerminationObserver { | 118 virtual WorkerEventQueue* eventQueue() const OVERRIDE FINAL; |
| 89 public: | 119 virtual SecurityContext& securityContext() OVERRIDE FINAL { return *this; } |
| 90 virtual ~TerminationObserver() { } | |
| 91 // The function is probably called in the main thread. | |
| 92 virtual void wasRequestedToTerminate() = 0; | |
| 93 }; | |
| 94 void registerTerminationObserver(TerminationObserver*); | |
| 95 void unregisterTerminationObserver(TerminationObserver*); | |
| 96 void wasRequestedToTerminate(); | |
| 97 | 120 |
| 98 void dispose(); | 121 virtual bool isContextThread() const OVERRIDE FINAL; |
| 122 virtual bool isJSExecutionForbidden() const OVERRIDE FINAL; |
| 99 | 123 |
| 100 WorkerThread* thread() const { return m_thread; } | 124 virtual double timerAlignmentInterval() const OVERRIDE FINAL; |
| 101 | 125 |
| 102 virtual void postTask(PassOwnPtr<ExecutionContextTask>) OVERRIDE FINAL;
// Executes the task on context's thread asynchronously. | 126 WorkerInspectorController* workerInspectorController() { return m_workerInsp
ectorController.get(); } |
| 103 | 127 |
| 104 // WorkerGlobalScope | 128 bool isClosing() { return m_closing; } |
| 105 WorkerGlobalScope* self() { return this; } | |
| 106 WorkerConsole* console(); | |
| 107 WorkerLocation* location() const; | |
| 108 void close(); | |
| 109 | 129 |
| 110 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 130 virtual void stopFetch() { } |
| 111 | 131 |
| 112 // WorkerUtils | 132 bool idleNotification(); |
| 113 virtual void importScripts(const Vector<String>& urls, ExceptionState&); | |
| 114 WorkerNavigator* navigator() const; | |
| 115 | 133 |
| 116 // ExecutionContextClient | 134 double timeOrigin() const { return m_timeOrigin; } |
| 117 virtual WorkerEventQueue* eventQueue() const OVERRIDE FINAL; | |
| 118 virtual SecurityContext& securityContext() OVERRIDE FINAL { return *this
; } | |
| 119 | 135 |
| 120 virtual bool isContextThread() const OVERRIDE FINAL; | 136 WorkerClients* clients() { return m_workerClients.get(); } |
| 121 virtual bool isJSExecutionForbidden() const OVERRIDE FINAL; | |
| 122 | 137 |
| 123 virtual double timerAlignmentInterval() const OVERRIDE FINAL; | 138 using SecurityContext::securityOrigin; |
| 139 using SecurityContext::contentSecurityPolicy; |
| 124 | 140 |
| 125 WorkerInspectorController* workerInspectorController() { return m_worker
InspectorController.get(); } | 141 virtual void addMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) OVERRIDE FIN
AL; |
| 126 | 142 |
| 127 bool isClosing() { return m_closing; } | 143 virtual void trace(Visitor*) OVERRIDE; |
| 128 | 144 |
| 129 virtual void stopFetch() { } | 145 protected: |
| 146 WorkerGlobalScope(const KURL&, const String& userAgent, WorkerThread*, doubl
e timeOrigin, PassOwnPtrWillBeRawPtr<WorkerClients>); |
| 147 void applyContentSecurityPolicyFromString(const String& contentSecurityPolic
y, ContentSecurityPolicyHeaderType); |
| 130 | 148 |
| 131 bool idleNotification(); | 149 virtual void logExceptionToConsole(const String& errorMessage, const String&
sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallS
tack>) OVERRIDE; |
| 150 void addMessageToWorkerConsole(PassRefPtrWillBeRawPtr<ConsoleMessage>); |
| 132 | 151 |
| 133 double timeOrigin() const { return m_timeOrigin; } | 152 private: |
| 134 | |
| 135 WorkerClients* clients() { return m_workerClients.get(); } | |
| 136 | |
| 137 using SecurityContext::securityOrigin; | |
| 138 using SecurityContext::contentSecurityPolicy; | |
| 139 | |
| 140 virtual void addMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) OVERRIDE
FINAL; | |
| 141 | |
| 142 virtual void trace(Visitor*) OVERRIDE; | |
| 143 | |
| 144 protected: | |
| 145 WorkerGlobalScope(const KURL&, const String& userAgent, WorkerThread*, d
ouble timeOrigin, PassOwnPtrWillBeRawPtr<WorkerClients>); | |
| 146 void applyContentSecurityPolicyFromString(const String& contentSecurityP
olicy, ContentSecurityPolicyHeaderType); | |
| 147 | |
| 148 virtual void logExceptionToConsole(const String& errorMessage, const Str
ing& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptC
allStack>) OVERRIDE; | |
| 149 void addMessageToWorkerConsole(PassRefPtrWillBeRawPtr<ConsoleMessage>); | |
| 150 | |
| 151 private: | |
| 152 #if !ENABLE(OILPAN) | 153 #if !ENABLE(OILPAN) |
| 153 virtual void refExecutionContext() OVERRIDE FINAL { ref(); } | 154 virtual void refExecutionContext() OVERRIDE FINAL { ref(); } |
| 154 virtual void derefExecutionContext() OVERRIDE FINAL { deref(); } | 155 virtual void derefExecutionContext() OVERRIDE FINAL { deref(); } |
| 155 #endif | 156 #endif |
| 156 | 157 |
| 157 virtual const KURL& virtualURL() const OVERRIDE FINAL; | 158 virtual const KURL& virtualURL() const OVERRIDE FINAL; |
| 158 virtual KURL virtualCompleteURL(const String&) const OVERRIDE FINAL; | 159 virtual KURL virtualCompleteURL(const String&) const OVERRIDE FINAL; |
| 159 | 160 |
| 160 virtual void reportBlockedScriptExecutionToInspector(const String& direc
tiveText) OVERRIDE FINAL; | 161 virtual void reportBlockedScriptExecutionToInspector(const String& directive
Text) OVERRIDE FINAL; |
| 161 | 162 |
| 162 virtual EventTarget* errorEventTarget() OVERRIDE FINAL; | 163 virtual EventTarget* errorEventTarget() OVERRIDE FINAL; |
| 163 virtual void didUpdateSecurityOrigin() OVERRIDE FINAL { } | 164 virtual void didUpdateSecurityOrigin() OVERRIDE FINAL { } |
| 164 | 165 |
| 165 KURL m_url; | 166 KURL m_url; |
| 166 String m_userAgent; | 167 String m_userAgent; |
| 167 | 168 |
| 168 mutable RefPtrWillBeMember<WorkerConsole> m_console; | 169 mutable RefPtrWillBeMember<WorkerConsole> m_console; |
| 169 mutable RefPtrWillBeMember<WorkerLocation> m_location; | 170 mutable RefPtrWillBeMember<WorkerLocation> m_location; |
| 170 mutable RefPtrWillBeMember<WorkerNavigator> m_navigator; | 171 mutable RefPtrWillBeMember<WorkerNavigator> m_navigator; |
| 171 | 172 |
| 172 OwnPtr<WorkerScriptController> m_script; | 173 OwnPtr<WorkerScriptController> m_script; |
| 173 WorkerThread* m_thread; | 174 WorkerThread* m_thread; |
| 174 | 175 |
| 175 RefPtrWillBeMember<WorkerInspectorController> m_workerInspectorControlle
r; | 176 RefPtrWillBeMember<WorkerInspectorController> m_workerInspectorController; |
| 176 bool m_closing; | 177 bool m_closing; |
| 177 | 178 |
| 178 OwnPtrWillBeMember<WorkerEventQueue> m_eventQueue; | 179 OwnPtrWillBeMember<WorkerEventQueue> m_eventQueue; |
| 179 | 180 |
| 180 OwnPtrWillBeMember<WorkerClients> m_workerClients; | 181 OwnPtrWillBeMember<WorkerClients> m_workerClients; |
| 181 | 182 |
| 182 double m_timeOrigin; | 183 double m_timeOrigin; |
| 183 TerminationObserver* m_terminationObserver; | 184 TerminationObserver* m_terminationObserver; |
| 184 }; | 185 }; |
| 185 | 186 |
| 186 DEFINE_TYPE_CASTS(WorkerGlobalScope, ExecutionContext, context, context->isWorke
rGlobalScope(), context.isWorkerGlobalScope()); | 187 DEFINE_TYPE_CASTS(WorkerGlobalScope, ExecutionContext, context, context->isWorke
rGlobalScope(), context.isWorkerGlobalScope()); |
| 187 | 188 |
| 188 } // namespace blink | 189 } // namespace blink |
| 189 | 190 |
| 190 #endif // WorkerGlobalScope_h | 191 #endif // WorkerGlobalScope_h |
| OLD | NEW |