File: ExecutionContext.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (214 lines) | stat: -rw-r--r-- 8,294 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 * Copyright (C) 2012 Google Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef ExecutionContext_h
#define ExecutionContext_h

#include "core/CoreExport.h"
#include "core/dom/ContextLifecycleNotifier.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/dom/SecurityContext.h"
#include "core/fetch/AccessControlStatus.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/ReferrerPolicy.h"
#include "public/platform/WebTraceLocation.h"
#include "wtf/Noncopyable.h"
#include <memory>

namespace blink {

class SuspendableObject;
class ConsoleMessage;
class DOMTimerCoordinator;
class ErrorEvent;
class EventQueue;
class EventTarget;
class ExecutionContextTask;
class LocalDOMWindow;
class PublicURLManager;
class SecurityOrigin;
enum class TaskType : unsigned;

class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier,
                                     public Supplementable<ExecutionContext> {
  WTF_MAKE_NONCOPYABLE(ExecutionContext);

 public:
  DECLARE_VIRTUAL_TRACE();

  // Used to specify whether |isSecureContext| should walk the
  // ancestor tree to decide whether to restrict usage of a powerful
  // feature.
  enum SecureContextCheck {
    StandardSecureContextCheck,
    WebCryptoSecureContextCheck
  };

  virtual bool isDocument() const { return false; }
  virtual bool isWorkerOrWorkletGlobalScope() const { return false; }
  virtual bool isWorkerGlobalScope() const { return false; }
  virtual bool isWorkletGlobalScope() const { return false; }
  virtual bool isMainThreadWorkletGlobalScope() const { return false; }
  virtual bool isDedicatedWorkerGlobalScope() const { return false; }
  virtual bool isSharedWorkerGlobalScope() const { return false; }
  virtual bool isServiceWorkerGlobalScope() const { return false; }
  virtual bool isCompositorWorkerGlobalScope() const { return false; }
  virtual bool isAnimationWorkletGlobalScope() const { return false; }
  virtual bool isAudioWorkletGlobalScope() const { return false; }
  virtual bool isPaintWorkletGlobalScope() const { return false; }
  virtual bool isThreadedWorkletGlobalScope() const { return false; }
  virtual bool isJSExecutionForbidden() const { return false; }

  virtual bool isContextThread() const { return true; }

  SecurityOrigin* getSecurityOrigin();
  ContentSecurityPolicy* contentSecurityPolicy();
  const KURL& url() const;
  KURL completeURL(const String& url) const;
  virtual void disableEval(const String& errorMessage) = 0;
  virtual LocalDOMWindow* executingWindow() const { return 0; }
  virtual String userAgent() const = 0;
  // Executes the task on context's thread asynchronously.
  virtual void postTask(
      TaskType,
      const WebTraceLocation&,
      std::unique_ptr<ExecutionContextTask>,
      const String& taskNameForInstrumentation = emptyString()) = 0;

  // Gets the DOMTimerCoordinator which maintains the "active timer
  // list" of tasks created by setTimeout and setInterval. The
  // DOMTimerCoordinator is owned by the ExecutionContext and should
  // not be used after the ExecutionContext is destroyed.
  virtual DOMTimerCoordinator* timers() = 0;

  virtual SecurityContext& securityContext() = 0;
  KURL contextURL() const { return virtualURL(); }
  KURL contextCompleteURL(const String& url) const {
    return virtualCompleteURL(url);
  }

  bool shouldSanitizeScriptError(const String& sourceURL, AccessControlStatus);
  void dispatchErrorEvent(ErrorEvent*, AccessControlStatus);

  virtual void addConsoleMessage(ConsoleMessage*) = 0;
  virtual void exceptionThrown(ErrorEvent*) = 0;

  PublicURLManager& publicURLManager();

  virtual void removeURLFromMemoryCache(const KURL&);

  void suspendSuspendableObjects();
  void resumeSuspendableObjects();
  void stopSuspendableObjects();
  void notifyContextDestroyed() override;

  void suspendScheduledTasks();
  void resumeScheduledTasks();

  // TODO(haraken): Remove these methods by making the customers inherit from
  // SuspendableObject. SuspendableObject is a standard way to observe context
  // suspension/resumption.
  virtual bool tasksNeedSuspension() { return false; }
  virtual void tasksWereSuspended() {}
  virtual void tasksWereResumed() {}

  bool isContextSuspended() const { return m_isContextSuspended; }
  bool isContextDestroyed() const { return m_isContextDestroyed; }

  // Called after the construction of an SuspendableObject to synchronize
  // suspend
  // state.
  void suspendSuspendableObjectIfNeeded(SuspendableObject*);

  // Gets the next id in a circular sequence from 1 to 2^31-1.
  int circularSequentialID();

  virtual EventTarget* errorEventTarget() = 0;
  virtual EventQueue* getEventQueue() const = 0;

  // Methods related to window interaction. It should be used to manage window
  // focusing and window creation permission for an ExecutionContext.
  void allowWindowInteraction();
  void consumeWindowInteraction();
  bool isWindowInteractionAllowed() const;

  // Decides whether this context is privileged, as described in
  // https://w3c.github.io/webappsec/specs/powerfulfeatures/#settings-privileged.
  virtual bool isSecureContext(
      String& errorMessage,
      const SecureContextCheck = StandardSecureContextCheck) const = 0;
  virtual bool isSecureContext(
      const SecureContextCheck = StandardSecureContextCheck) const;

  virtual String outgoingReferrer() const;
  // Parses a comma-separated list of referrer policy tokens, and sets
  // the context's referrer policy to the last one that is a valid
  // policy. Logs a message to the console if none of the policy
  // tokens are valid policies.
  //
  // If |supportLegacyKeywords| is true, then the legacy keywords
  // "never", "default", "always", and "origin-when-crossorigin" are
  // parsed as valid policies.
  void parseAndSetReferrerPolicy(const String& policies,
                                 bool supportLegacyKeywords = false);
  void setReferrerPolicy(ReferrerPolicy);
  virtual ReferrerPolicy getReferrerPolicy() const { return m_referrerPolicy; }

 protected:
  ExecutionContext();
  virtual ~ExecutionContext();

  virtual const KURL& virtualURL() const = 0;
  virtual KURL virtualCompleteURL(const String&) const = 0;

 private:
  bool dispatchErrorEventInternal(ErrorEvent*, AccessControlStatus);

  unsigned m_circularSequentialID;

  bool m_inDispatchErrorEvent;
  HeapVector<Member<ErrorEvent>> m_pendingExceptions;

  bool m_isContextSuspended;
  bool m_isContextDestroyed;

  Member<PublicURLManager> m_publicURLManager;

  // Counter that keeps track of how many window interaction calls are allowed
  // for this ExecutionContext. Callers are expected to call
  // |allowWindowInteraction()| and |consumeWindowInteraction()| in order to
  // increment and decrement the counter.
  int m_windowInteractionTokens;

  ReferrerPolicy m_referrerPolicy;
};

}  // namespace blink

#endif  // ExecutionContext_h