2
* Copyright (C) 2009 Apple Inc. All rights reserved.
3
* Copyright (C) 2009 Google Inc. All rights reserved.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
30
#ifndef InspectorDOMAgent_h
31
#define InspectorDOMAgent_h
33
#include "AtomicString.h"
34
#include "EventListener.h"
35
#include "EventTarget.h"
36
#include "ScriptArray.h"
37
#include "ScriptObject.h"
38
#include "ScriptState.h"
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>
51
class InspectorFrontend;
58
struct EventListenerInfo {
59
EventListenerInfo(Node* node, const AtomicString& eventType, const EventListenerVector& eventListenerVector)
61
, eventType(eventType)
62
, eventListenerVector(eventListenerVector)
67
const AtomicString eventType;
68
const EventListenerVector eventListenerVector;
71
class InspectorDOMAgent : public EventListener {
73
static const InspectorDOMAgent* cast(const EventListener* listener)
75
return listener->type() == InspectorDOMAgentType
76
? static_cast<const InspectorDOMAgent*>(listener)
80
InspectorDOMAgent(InspectorFrontend* frontend);
83
virtual bool operator==(const EventListener& other);
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);
93
// Methods called from the InspectorController.
94
void setDocument(Document* document);
95
void releaseDanglingNodes();
97
Node* nodeForId(long nodeId);
98
long pushNodePathToFrontend(Node* node);
101
void startListening(Document* document);
102
void stopListening(Document* document);
104
virtual void handleEvent(ScriptExecutionContext*, Event* event);
106
typedef HashMap<RefPtr<Node>, long> NodeToIdMap;
107
long bind(Node* node, NodeToIdMap* nodesMap);
108
void unbind(Node* node, NodeToIdMap* nodesMap);
110
void pushDocumentToFrontend();
111
void pushChildNodesToFrontend(long nodeId);
113
ScriptObject buildObjectForNode(Node* node, int depth, NodeToIdMap* nodesMap);
114
ScriptArray buildArrayForElementAttributes(Element* element);
115
ScriptArray buildArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap);
117
ScriptObject buildObjectForEventListener(const RegisteredEventListener& registeredEventListener, const AtomicString& eventType, Node* node);
119
ScriptObject buildObjectForCookie(const Cookie& cookie);
120
ScriptArray buildArrayForCookies(const Vector<Cookie>& cookiesList);
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);
131
Document* mainFrameDocument() const;
132
void discardBindings();
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;
142
ListHashSet<RefPtr<Document> > m_documents;
146
} // namespace WebCore
148
#endif // !defined(InspectorDOMAgent_h)