]>
Commit | Line | Data |
---|---|---|
a90939db JF |
1 | /* |
2 | * Copyright (C) 2008 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 ScriptExecutionContext_h | |
28 | #define ScriptExecutionContext_h | |
29 | ||
30 | #include "Console.h" | |
31 | #include "KURL.h" | |
32 | #include <wtf/HashMap.h> | |
33 | #include <wtf/HashSet.h> | |
34 | #include <wtf/PassRefPtr.h> | |
35 | #include <wtf/Threading.h> | |
36 | ||
37 | namespace WebCore { | |
38 | ||
39 | class ActiveDOMObject; | |
40 | class MessagePort; | |
41 | class SecurityOrigin; | |
42 | class ScriptString; | |
43 | class String; | |
44 | ||
45 | enum MessageDestination { | |
46 | ConsoleDestination, | |
47 | }; | |
48 | ||
49 | class ScriptExecutionContext { | |
50 | public: | |
51 | ScriptExecutionContext(); | |
52 | virtual ~ScriptExecutionContext(); | |
53 | ||
54 | virtual bool isDocument() const { return false; } | |
55 | virtual bool isWorkerContext() const { return false; } | |
56 | ||
57 | const KURL& url() const { return virtualURL(); } | |
58 | KURL completeURL(const String& url) const { return virtualCompleteURL(url); } | |
59 | ||
60 | SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } | |
61 | ||
62 | virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL) = 0; | |
63 | virtual void addMessage(MessageDestination, MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL) = 0; | |
64 | virtual void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const ScriptString& sourceString) = 0; | |
65 | ||
66 | // Active objects are not garbage collected even if inaccessible, e.g. because their activity may result in callbacks being invoked. | |
67 | bool canSuspendActiveDOMObjects(); | |
68 | // Active objects can be asked to suspend even if canSuspendActiveDOMObjects() returns 'false' - | |
69 | // step-by-step JS debugging is one example. | |
70 | void suspendActiveDOMObjects(); | |
71 | void resumeActiveDOMObjects(); | |
72 | void stopActiveDOMObjects(); | |
73 | void createdActiveDOMObject(ActiveDOMObject*, void* upcastPointer); | |
74 | void destroyedActiveDOMObject(ActiveDOMObject*); | |
75 | typedef const HashMap<ActiveDOMObject*, void*> ActiveDOMObjectsMap; | |
76 | ActiveDOMObjectsMap& activeDOMObjects() const { return m_activeDOMObjects; } | |
77 | ||
78 | // MessagePort is conceptually a kind of ActiveDOMObject, but it needs to be tracked separately for message dispatch. | |
79 | void processMessagePortMessagesSoon(); | |
80 | void dispatchMessagePortEvents(); | |
81 | void createdMessagePort(MessagePort*); | |
82 | void destroyedMessagePort(MessagePort*); | |
83 | const HashSet<MessagePort*>& messagePorts() const { return m_messagePorts; } | |
84 | ||
85 | void ref() { refScriptExecutionContext(); } | |
86 | void deref() { derefScriptExecutionContext(); } | |
87 | ||
88 | class Task : public ThreadSafeShared<Task> { | |
89 | public: | |
90 | virtual ~Task(); | |
91 | virtual void performTask(ScriptExecutionContext*) = 0; | |
92 | }; | |
93 | ||
94 | virtual void postTask(PassRefPtr<Task>) = 0; // Executes the task on context's thread asynchronously. | |
95 | ||
96 | protected: | |
97 | // Explicitly override the security origin for this script context. | |
98 | // Note: It is dangerous to change the security origin of a script context | |
99 | // that already contains content. | |
100 | void setSecurityOrigin(PassRefPtr<SecurityOrigin>); | |
101 | ||
102 | private: | |
103 | virtual const KURL& virtualURL() const = 0; | |
104 | virtual KURL virtualCompleteURL(const String&) const = 0; | |
105 | ||
106 | RefPtr<SecurityOrigin> m_securityOrigin; | |
107 | ||
108 | HashSet<MessagePort*> m_messagePorts; | |
109 | ||
110 | HashMap<ActiveDOMObject*, void*> m_activeDOMObjects; | |
111 | ||
112 | virtual void refScriptExecutionContext() = 0; | |
113 | virtual void derefScriptExecutionContext() = 0; | |
114 | }; | |
115 | ||
116 | } // namespace WebCore | |
117 | ||
118 | ||
119 | #endif // ScriptExecutionContext_h |