OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2012 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 */ | 26 */ |
27 | 27 |
28 #ifndef ExecutionContext_h | 28 #ifndef ExecutionContext_h |
29 #define ExecutionContext_h | 29 #define ExecutionContext_h |
30 | 30 |
31 #include "core/dom/ActiveDOMObject.h" | 31 #include "core/dom/ActiveDOMObject.h" |
32 #include "core/dom/ExecutionContextClient.h" | |
33 #include "core/dom/SandboxFlags.h" | 32 #include "core/dom/SandboxFlags.h" |
34 #include "core/dom/SecurityContext.h" | 33 #include "core/dom/SecurityContext.h" |
35 #include "core/fetch/CrossOriginAccessControl.h" | 34 #include "core/fetch/CrossOriginAccessControl.h" |
36 #include "core/frame/ConsoleTypes.h" | 35 #include "core/frame/ConsoleTypes.h" |
37 #include "core/frame/DOMTimer.h" | 36 #include "core/frame/DOMTimer.h" |
38 #include "core/inspector/ConsoleMessage.h" | 37 #include "core/inspector/ConsoleMessage.h" |
39 #include "platform/LifecycleContext.h" | 38 #include "platform/LifecycleContext.h" |
40 #include "platform/Supplementable.h" | 39 #include "platform/Supplementable.h" |
41 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
42 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
(...skipping 12 matching lines...) Expand all Loading... |
55 class PublicURLManager; | 54 class PublicURLManager; |
56 class SecurityOrigin; | 55 class SecurityOrigin; |
57 class ScriptCallStack; | 56 class ScriptCallStack; |
58 | 57 |
59 class ExecutionContext | 58 class ExecutionContext |
60 : public LifecycleContext<ExecutionContext> | 59 : public LifecycleContext<ExecutionContext> |
61 , public WillBeHeapSupplementable<ExecutionContext> { | 60 , public WillBeHeapSupplementable<ExecutionContext> { |
62 public: | 61 public: |
63 virtual void trace(Visitor*) OVERRIDE; | 62 virtual void trace(Visitor*) OVERRIDE; |
64 | 63 |
65 // Delegating to ExecutionContextClient | 64 virtual bool isDocument() const { return false; } |
66 bool isDocument() const { return m_client && m_client->isDocument(); } | 65 virtual bool isWorkerGlobalScope() const { return false; } |
67 bool isWorkerGlobalScope() const { return m_client && m_client->isWorkerGlob
alScope(); } | 66 virtual bool isDedicatedWorkerGlobalScope() const { return false; } |
68 bool isDedicatedWorkerGlobalScope() const { return m_client && m_client->isD
edicatedWorkerGlobalScope(); } | 67 virtual bool isSharedWorkerGlobalScope() const { return false; } |
69 bool isSharedWorkerGlobalScope() const { return m_client && m_client->isShar
edWorkerGlobalScope(); } | 68 virtual bool isServiceWorkerGlobalScope() const { return false; } |
70 bool isServiceWorkerGlobalScope() const { return m_client && m_client->isSer
viceWorkerGlobalScope(); } | 69 virtual bool isJSExecutionForbidden() const { return false; } |
71 bool isJSExecutionForbidden() { return m_client && m_client->isJSExecutionFo
rbidden(); } | 70 SecurityOrigin* securityOrigin(); |
72 SecurityOrigin* securityOrigin() const; | 71 ContentSecurityPolicy* contentSecurityPolicy(); |
73 ContentSecurityPolicy* contentSecurityPolicy() const; | 72 virtual void didUpdateSecurityOrigin() = 0; |
74 const KURL& url() const; | 73 const KURL& url() const; |
75 KURL completeURL(const String& url) const; | 74 KURL completeURL(const String& url) const; |
76 void disableEval(const String& errorMessage); | 75 virtual void disableEval(const String& errorMessage) = 0; |
77 LocalDOMWindow* executingWindow() const; | 76 virtual LocalDOMWindow* executingWindow() { return 0; } |
78 String userAgent(const KURL&) const; | 77 virtual String userAgent(const KURL&) const = 0; |
79 void postTask(PassOwnPtr<ExecutionContextTask>); | 78 virtual void postTask(PassOwnPtr<ExecutionContextTask>) = 0; // Executes the
task on context's thread asynchronously. |
80 double timerAlignmentInterval() const; | 79 virtual double timerAlignmentInterval() const = 0; |
81 | 80 |
82 virtual void reportBlockedScriptExecutionToInspector(const String& directive
Text) = 0; | 81 virtual void reportBlockedScriptExecutionToInspector(const String& directive
Text) = 0; |
83 | 82 |
84 virtual SecurityContext& securityContext() = 0; | 83 virtual SecurityContext& securityContext() = 0; |
85 KURL contextURL() const { return virtualURL(); } | 84 KURL contextURL() const { return virtualURL(); } |
86 KURL contextCompleteURL(const String& url) const { return virtualCompleteURL
(url); } | 85 KURL contextCompleteURL(const String& url) const { return virtualCompleteURL
(url); } |
87 | 86 |
88 bool shouldSanitizeScriptError(const String& sourceURL, AccessControlStatus)
; | 87 bool shouldSanitizeScriptError(const String& sourceURL, AccessControlStatus)
; |
89 void reportException(PassRefPtrWillBeRawPtr<ErrorEvent>, int scriptId, PassR
efPtrWillBeRawPtr<ScriptCallStack>, AccessControlStatus); | 88 void reportException(PassRefPtrWillBeRawPtr<ErrorEvent>, int scriptId, PassR
efPtrWillBeRawPtr<ScriptCallStack>, AccessControlStatus); |
90 | 89 |
91 void addConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>); | 90 virtual void addConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) = 0; |
| 91 virtual void logExceptionToConsole(const String& errorMessage, int scriptId,
const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawP
tr<ScriptCallStack>) = 0; |
92 | 92 |
93 PublicURLManager& publicURLManager(); | 93 PublicURLManager& publicURLManager(); |
94 | 94 |
95 // Active objects are not garbage collected even if inaccessible, e.g. becau
se their activity may result in callbacks being invoked. | 95 // Active objects are not garbage collected even if inaccessible, e.g. becau
se their activity may result in callbacks being invoked. |
96 bool hasPendingActivity(); | 96 bool hasPendingActivity(); |
97 | 97 |
98 void suspendActiveDOMObjects(); | 98 void suspendActiveDOMObjects(); |
99 void resumeActiveDOMObjects(); | 99 void resumeActiveDOMObjects(); |
100 void stopActiveDOMObjects(); | 100 void stopActiveDOMObjects(); |
101 unsigned activeDOMObjectCount(); | 101 unsigned activeDOMObjectCount(); |
102 | 102 |
103 virtual void suspendScheduledTasks(); | 103 virtual void suspendScheduledTasks(); |
104 virtual void resumeScheduledTasks(); | 104 virtual void resumeScheduledTasks(); |
105 virtual bool tasksNeedSuspension() { return false; } | 105 virtual bool tasksNeedSuspension() { return false; } |
| 106 virtual void tasksWereSuspended() { } |
| 107 virtual void tasksWereResumed() { } |
106 | 108 |
107 bool activeDOMObjectsAreSuspended() const { return m_activeDOMObjectsAreSusp
ended; } | 109 bool activeDOMObjectsAreSuspended() const { return m_activeDOMObjectsAreSusp
ended; } |
108 bool activeDOMObjectsAreStopped() const { return m_activeDOMObjectsAreStoppe
d; } | 110 bool activeDOMObjectsAreStopped() const { return m_activeDOMObjectsAreStoppe
d; } |
109 bool isIteratingOverObservers() const; | 111 bool isIteratingOverObservers() const; |
110 | 112 |
111 // Called after the construction of an ActiveDOMObject to synchronize suspen
d state. | 113 // Called after the construction of an ActiveDOMObject to synchronize suspen
d state. |
112 void suspendActiveDOMObjectIfNeeded(ActiveDOMObject*); | 114 void suspendActiveDOMObjectIfNeeded(ActiveDOMObject*); |
113 #if !ENABLE(OILPAN) | 115 #if !ENABLE(OILPAN) |
114 void ref() { refExecutionContext(); } | 116 void ref() { refExecutionContext(); } |
115 void deref() { derefExecutionContext(); } | 117 void deref() { derefExecutionContext(); } |
116 #endif | 118 #endif |
117 | 119 |
118 // Gets the next id in a circular sequence from 1 to 2^31-1. | 120 // Gets the next id in a circular sequence from 1 to 2^31-1. |
119 int circularSequentialID(); | 121 int circularSequentialID(); |
120 | 122 |
121 void didChangeTimerAlignmentInterval(); | 123 void didChangeTimerAlignmentInterval(); |
122 | 124 |
123 SandboxFlags sandboxFlags() const { return m_sandboxFlags; } | 125 SandboxFlags sandboxFlags() const { return m_sandboxFlags; } |
124 bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; } | 126 bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; } |
125 void enforceSandboxFlags(SandboxFlags mask); | 127 void enforceSandboxFlags(SandboxFlags mask); |
126 | 128 |
127 PassOwnPtr<LifecycleNotifier<ExecutionContext> > createLifecycleNotifier(); | 129 PassOwnPtr<LifecycleNotifier<ExecutionContext> > createLifecycleNotifier(); |
128 | 130 |
| 131 virtual EventTarget* errorEventTarget() = 0; |
129 virtual EventQueue* eventQueue() const = 0; | 132 virtual EventQueue* eventQueue() const = 0; |
130 | 133 |
131 protected: | 134 protected: |
132 ExecutionContext(); | 135 ExecutionContext(); |
133 virtual ~ExecutionContext(); | 136 virtual ~ExecutionContext(); |
134 | 137 |
135 void setClient(ExecutionContextClient* client) { m_client = client; } | |
136 | |
137 virtual const KURL& virtualURL() const = 0; | 138 virtual const KURL& virtualURL() const = 0; |
138 virtual KURL virtualCompleteURL(const String&) const = 0; | 139 virtual KURL virtualCompleteURL(const String&) const = 0; |
139 | 140 |
140 ContextLifecycleNotifier& lifecycleNotifier(); | 141 ContextLifecycleNotifier& lifecycleNotifier(); |
141 | 142 |
142 private: | 143 private: |
143 friend class DOMTimer; // For installNewTimeout() and removeTimeoutByID() be
low. | 144 friend class DOMTimer; // For installNewTimeout() and removeTimeoutByID() be
low. |
144 | 145 |
145 bool dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent>, AccessControlSta
tus); | 146 bool dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent>, AccessControlSta
tus); |
146 | 147 |
147 #if !ENABLE(OILPAN) | 148 #if !ENABLE(OILPAN) |
148 virtual void refExecutionContext() = 0; | 149 virtual void refExecutionContext() = 0; |
149 virtual void derefExecutionContext() = 0; | 150 virtual void derefExecutionContext() = 0; |
150 #endif | 151 #endif |
151 // LifecycleContext implementation. | 152 // LifecycleContext implementation. |
152 | 153 |
153 // Implementation details for DOMTimer. No other classes should call these f
unctions. | 154 // Implementation details for DOMTimer. No other classes should call these f
unctions. |
154 int installNewTimeout(PassOwnPtr<ScheduledAction>, int timeout, bool singleS
hot); | 155 int installNewTimeout(PassOwnPtr<ScheduledAction>, int timeout, bool singleS
hot); |
155 void removeTimeoutByID(int timeoutID); // This makes underlying DOMTimer ins
tance destructed. | 156 void removeTimeoutByID(int timeoutID); // This makes underlying DOMTimer ins
tance destructed. |
156 | 157 |
157 ExecutionContextClient* m_client; | |
158 SandboxFlags m_sandboxFlags; | 158 SandboxFlags m_sandboxFlags; |
159 | 159 |
160 int m_circularSequentialID; | 160 int m_circularSequentialID; |
161 typedef HashMap<int, OwnPtr<DOMTimer> > TimeoutMap; | 161 typedef HashMap<int, OwnPtr<DOMTimer> > TimeoutMap; |
162 TimeoutMap m_timeouts; | 162 TimeoutMap m_timeouts; |
163 | 163 |
164 bool m_inDispatchErrorEvent; | 164 bool m_inDispatchErrorEvent; |
165 class PendingException; | 165 class PendingException; |
166 OwnPtrWillBeMember<WillBeHeapVector<OwnPtrWillBeMember<PendingException> > >
m_pendingExceptions; | 166 OwnPtrWillBeMember<WillBeHeapVector<OwnPtrWillBeMember<PendingException> > >
m_pendingExceptions; |
167 | 167 |
168 bool m_activeDOMObjectsAreSuspended; | 168 bool m_activeDOMObjectsAreSuspended; |
169 bool m_activeDOMObjectsAreStopped; | 169 bool m_activeDOMObjectsAreStopped; |
170 | 170 |
171 OwnPtr<PublicURLManager> m_publicURLManager; | 171 OwnPtr<PublicURLManager> m_publicURLManager; |
172 | 172 |
173 // The location of this member is important; to make sure contextDestroyed()
notification on | 173 // The location of this member is important; to make sure contextDestroyed()
notification on |
174 // ExecutionContext's members (notably m_timeouts) is called before they are
destructed, | 174 // ExecutionContext's members (notably m_timeouts) is called before they are
destructed, |
175 // m_lifecycleNotifer should be placed *after* such members. | 175 // m_lifecycleNotifer should be placed *after* such members. |
176 OwnPtr<ContextLifecycleNotifier> m_lifecycleNotifier; | 176 OwnPtr<ContextLifecycleNotifier> m_lifecycleNotifier; |
177 }; | 177 }; |
178 | 178 |
179 } // namespace blink | 179 } // namespace blink |
180 | 180 |
181 #endif // ExecutionContext_h | 181 #endif // ExecutionContext_h |
OLD | NEW |