1/*
2 * Copyright (C) 2011 Google 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 are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef InspectorDOMDebuggerAgent_h
32#define InspectorDOMDebuggerAgent_h
33
34#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
35
36#include "InspectorBaseAgent.h"
37#include "InspectorDebuggerAgent.h"
38#include <wtf/HashMap.h>
39#include <wtf/PassOwnPtr.h>
40#include <wtf/RefCounted.h>
41#include <wtf/text/WTFString.h>
42
43namespace WebCore {
44
45class Element;
46class InspectorAgent;
47class InspectorDOMAgent;
48class InspectorDebuggerAgent;
49class InspectorFrontend;
50class InspectorObject;
51class InspectorState;
52class InstrumentingAgents;
53class Node;
54
55typedef String ErrorString;
56
57class InspectorDOMDebuggerAgent : public InspectorBaseAgent<InspectorDOMDebuggerAgent>, public InspectorDebuggerAgent::Listener, public InspectorBackendDispatcher::DOMDebuggerCommandHandler {
58    WTF_MAKE_NONCOPYABLE(InspectorDOMDebuggerAgent);
59public:
60    static PassOwnPtr<InspectorDOMDebuggerAgent> create(InstrumentingAgents*, InspectorCompositeState*, InspectorDOMAgent*, InspectorDebuggerAgent*, InspectorAgent*);
61
62    virtual ~InspectorDOMDebuggerAgent();
63
64    // DOMDebugger API for InspectorFrontend
65    virtual void setXHRBreakpoint(ErrorString*, const String& url);
66    virtual void removeXHRBreakpoint(ErrorString*, const String& url);
67    virtual void setEventListenerBreakpoint(ErrorString*, const String& eventName);
68    virtual void removeEventListenerBreakpoint(ErrorString*, const String& eventName);
69    virtual void setInstrumentationBreakpoint(ErrorString*, const String& eventName);
70    virtual void removeInstrumentationBreakpoint(ErrorString*, const String& eventName);
71    virtual void setDOMBreakpoint(ErrorString*, int nodeId, const String& type);
72    virtual void removeDOMBreakpoint(ErrorString*, int nodeId, const String& type);
73
74    // InspectorInstrumentation API
75    void willInsertDOMNode(Node* parent);
76    void didInvalidateStyleAttr(Node*);
77    void didInsertDOMNode(Node*);
78    void willRemoveDOMNode(Node*);
79    void didRemoveDOMNode(Node*);
80    void willModifyDOMAttr(Element*);
81    void willSendXMLHttpRequest(const String& url);
82    void pauseOnNativeEventIfNeeded(bool isDOMEvent, const String& eventName, bool synchronous);
83
84    void didProcessTask();
85
86    virtual void clearFrontend();
87    virtual void discardAgent();
88
89private:
90    InspectorDOMDebuggerAgent(InstrumentingAgents*, InspectorCompositeState*, InspectorDOMAgent*, InspectorDebuggerAgent*, InspectorAgent*);
91
92    // InspectorDebuggerAgent::Listener implementation.
93    virtual void debuggerWasEnabled();
94    virtual void debuggerWasDisabled();
95    virtual void stepInto();
96    virtual void didPause();
97    void disable();
98
99    void descriptionForDOMEvent(Node* target, int breakpointType, bool insertion, InspectorObject* description);
100    void updateSubtreeBreakpoints(Node*, uint32_t rootMask, bool set);
101    bool hasBreakpoint(Node*, int type);
102    void discardBindings();
103    void setBreakpoint(ErrorString*, const String& eventName);
104    void removeBreakpoint(ErrorString*, const String& eventName);
105
106    void clear();
107
108    InspectorDOMAgent* m_domAgent;
109    InspectorDebuggerAgent* m_debuggerAgent;
110    HashMap<Node*, uint32_t> m_domBreakpoints;
111    bool m_pauseInNextEventListener;
112};
113
114} // namespace WebCore
115
116#endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
117
118#endif // !defined(InspectorDOMDebuggerAgent_h)
119