~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/inspector/InspectorDOMAgent.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Apple Inc. All rights reserved.
 
3
 * Copyright (C) 2009 Google Inc. All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
9
 * 1.  Redistributions of source code must retain the above copyright
 
10
 *     notice, this list of conditions and the following disclaimer.
 
11
 * 2.  Redistributions in binary form must reproduce the above copyright
 
12
 *     notice, this list of conditions and the following disclaimer in the
 
13
 *     documentation and/or other materials provided with the distribution.
 
14
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 
15
 *     its contributors may be used to endorse or promote products derived
 
16
 *     from this software without specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
#ifndef InspectorDOMAgent_h
 
31
#define InspectorDOMAgent_h
 
32
 
 
33
#include "AtomicString.h"
 
34
#include "EventListener.h"
 
35
#include "EventTarget.h"
 
36
#include "ScriptArray.h"
 
37
#include "ScriptObject.h"
 
38
#include "ScriptState.h"
 
39
 
 
40
#include <wtf/ListHashSet.h>
 
41
#include <wtf/HashMap.h>
 
42
#include <wtf/HashSet.h>
 
43
#include <wtf/PassRefPtr.h>
 
44
#include <wtf/RefPtr.h>
 
45
 
 
46
namespace WebCore {
 
47
    class ContainerNode;
 
48
    class Element;
 
49
    class Event;
 
50
    class Document;
 
51
    class InspectorFrontend;
 
52
    class NameNodeMap;
 
53
    class Node;
 
54
    class Page;
 
55
 
 
56
    struct Cookie;
 
57
 
 
58
    struct EventListenerInfo {
 
59
        EventListenerInfo(Node* node, const AtomicString& eventType, const EventListenerVector& eventListenerVector)
 
60
            : node(node)
 
61
            , eventType(eventType)
 
62
            , eventListenerVector(eventListenerVector)
 
63
        {
 
64
        }
 
65
 
 
66
        Node* node;
 
67
        const AtomicString eventType;
 
68
        const EventListenerVector eventListenerVector;
 
69
    };
 
70
 
 
71
    class InspectorDOMAgent : public EventListener {
 
72
    public:
 
73
        static const InspectorDOMAgent* cast(const EventListener* listener)
 
74
        {
 
75
            return listener->type() == InspectorDOMAgentType
 
76
                ? static_cast<const InspectorDOMAgent*>(listener)
 
77
                : 0;
 
78
        }
 
79
 
 
80
        InspectorDOMAgent(InspectorFrontend* frontend);
 
81
        ~InspectorDOMAgent();
 
82
 
 
83
        virtual bool operator==(const EventListener& other);
 
84
 
 
85
        // Methods called from the frontend.
 
86
        void getChildNodes(long callId, long nodeId);
 
87
        void setAttribute(long callId, long elementId, const String& name, const String& value);
 
88
        void removeAttribute(long callId, long elementId, const String& name);
 
89
        void setTextNodeValue(long callId, long nodeId, const String& value);
 
90
        void getEventListenersForNode(long callId, long nodeId);
 
91
        void getCookies(long callId);
 
92
 
 
93
        // Methods called from the InspectorController.
 
94
        void setDocument(Document* document);
 
95
        void releaseDanglingNodes();
 
96
 
 
97
        Node* nodeForId(long nodeId);
 
98
        long pushNodePathToFrontend(Node* node);
 
99
 
 
100
   private:
 
101
        void startListening(Document* document);
 
102
        void stopListening(Document* document);
 
103
 
 
104
        virtual void handleEvent(ScriptExecutionContext*, Event* event);
 
105
 
 
106
        typedef HashMap<RefPtr<Node>, long> NodeToIdMap;
 
107
        long bind(Node* node, NodeToIdMap* nodesMap);
 
108
        void unbind(Node* node, NodeToIdMap* nodesMap);
 
109
 
 
110
        void pushDocumentToFrontend();
 
111
        void pushChildNodesToFrontend(long nodeId);
 
112
 
 
113
        ScriptObject buildObjectForNode(Node* node, int depth, NodeToIdMap* nodesMap);
 
114
        ScriptArray buildArrayForElementAttributes(Element* element);
 
115
        ScriptArray buildArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap);
 
116
 
 
117
        ScriptObject buildObjectForEventListener(const RegisteredEventListener& registeredEventListener, const AtomicString& eventType, Node* node);
 
118
 
 
119
        ScriptObject buildObjectForCookie(const Cookie& cookie);
 
120
        ScriptArray buildArrayForCookies(const Vector<Cookie>& cookiesList);
 
121
 
 
122
        // We represent embedded doms as a part of the same hierarchy. Hence we treat children of frame owners differently.
 
123
        // We also skip whitespace text nodes conditionally. Following methods encapsulate these specifics.
 
124
        Node* innerFirstChild(Node* node);
 
125
        Node* innerNextSibling(Node* node);
 
126
        Node* innerPreviousSibling(Node* node);
 
127
        int innerChildNodeCount(Node* node);
 
128
        Node* innerParentNode(Node* node);
 
129
        bool isWhitespace(Node* node);
 
130
 
 
131
        Document* mainFrameDocument() const;
 
132
        void discardBindings();
 
133
 
 
134
        InspectorFrontend* m_frontend;
 
135
        NodeToIdMap m_documentNodeToIdMap;
 
136
        // Owns node mappings for dangling nodes.
 
137
        Vector<NodeToIdMap*> m_danglingNodeToIdMaps;
 
138
        HashMap<long, Node*> m_idToNode;
 
139
        HashMap<long, NodeToIdMap*> m_idToNodesMap;
 
140
        HashSet<long> m_childrenRequested;
 
141
        long m_lastNodeId;
 
142
        ListHashSet<RefPtr<Document> > m_documents;
 
143
    };
 
144
 
 
145
 
 
146
} // namespace WebCore
 
147
 
 
148
#endif // !defined(InspectorDOMAgent_h)