]>
git.saurik.com Git - iphone-api.git/blob - WebCore/ScriptExecutionContext.h
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef ScriptExecutionContext_h
28 #define ScriptExecutionContext_h
32 #include <wtf/HashMap.h>
33 #include <wtf/HashSet.h>
34 #include <wtf/PassRefPtr.h>
35 #include <wtf/Threading.h>
39 class ActiveDOMObject
;
45 enum MessageDestination
{
49 class ScriptExecutionContext
{
51 ScriptExecutionContext();
52 virtual ~ScriptExecutionContext();
54 virtual bool isDocument() const { return false; }
55 virtual bool isWorkerContext() const { return false; }
57 const KURL
& url() const { return virtualURL(); }
58 KURL
completeURL(const String
& url
) const { return virtualCompleteURL(url
); }
60 SecurityOrigin
* securityOrigin() const { return m_securityOrigin
.get(); }
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;
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
; }
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
; }
85 void ref() { refScriptExecutionContext(); }
86 void deref() { derefScriptExecutionContext(); }
88 class Task
: public ThreadSafeShared
<Task
> {
91 virtual void performTask(ScriptExecutionContext
*) = 0;
94 virtual void postTask(PassRefPtr
<Task
>) = 0; // Executes the task on context's thread asynchronously.
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
>);
103 virtual const KURL
& virtualURL() const = 0;
104 virtual KURL
virtualCompleteURL(const String
&) const = 0;
106 RefPtr
<SecurityOrigin
> m_securityOrigin
;
108 HashSet
<MessagePort
*> m_messagePorts
;
110 HashMap
<ActiveDOMObject
*, void*> m_activeDOMObjects
;
112 virtual void refScriptExecutionContext() = 0;
113 virtual void derefScriptExecutionContext() = 0;
116 } // namespace WebCore
119 #endif // ScriptExecutionContext_h