2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / dom / ScriptExecutionContext.h
blob565dbe07c41913602f1f9894467193c6a57624c8
1 /*
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
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.
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
30 #include <wtf/HashMap.h>
31 #include <wtf/HashSet.h>
33 namespace WebCore {
35 class ActiveDOMObject;
36 class MessagePort;
37 class KURL;
38 class SecurityOrigin;
39 class String;
41 class ScriptExecutionContext {
42 public:
43 ScriptExecutionContext();
44 virtual ~ScriptExecutionContext();
46 virtual bool isDocument() const { return false; }
47 virtual bool isWorkerContext() const { return false; }
49 const KURL& url() const { return virtualURL(); }
51 // Active objects are not garbage collected even if inaccessible, e.g. because their activity may result in callbacks being invoked.
52 void stopActiveDOMObjects();
53 void createdActiveDOMObject(ActiveDOMObject*, void* upcastPointer);
54 void destroyedActiveDOMObject(ActiveDOMObject*);
55 const HashMap<ActiveDOMObject*, void*>& activeDOMObjects() const { return m_activeDOMObjects; }
57 // MessagePort is conceptually a kind of ActiveDOMObject, but it needs to be tracked separately for message dispatch, and for cross-heap GC support.
58 void processMessagePortMessagesSoon();
59 void dispatchMessagePortEvents();
60 void createdMessagePort(MessagePort*);
61 void destroyedMessagePort(MessagePort*);
62 const HashSet<MessagePort*>& messagePorts() const { return m_messagePorts; }
64 void ref() { refScriptExecutionContext(); }
65 void deref() { derefScriptExecutionContext(); }
67 private:
68 virtual const KURL& virtualURL() const = 0;
70 bool m_firedMessagePortTimer;
71 HashSet<MessagePort*> m_messagePorts;
73 HashMap<ActiveDOMObject*, void*> m_activeDOMObjects;
75 virtual void refScriptExecutionContext() = 0;
76 virtual void derefScriptExecutionContext() = 0;
79 } // namespace WebCore
82 #endif // ScriptExecutionContext_h