1 | /* |
2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
3 | * Copyright (C) 2015 Apple 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 are |
7 | * met: |
8 | * |
9 | * * Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * * Redistributions in binary form must reproduce the above |
12 | * copyright notice, this list of conditions and the following disclaimer |
13 | * in the documentation and/or other materials provided with the |
14 | * distribution. |
15 | * * Neither the name of Google Inc. nor the names of its |
16 | * contributors may be used to endorse or promote products derived from |
17 | * this software without specific prior written permission. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
31 | |
32 | #pragma once |
33 | |
34 | #include "InspectorWebAgentBase.h" |
35 | #include <JavaScriptCore/InspectorBackendDispatchers.h> |
36 | #include <JavaScriptCore/InspectorDebuggerAgent.h> |
37 | #include <wtf/HashMap.h> |
38 | #include <wtf/JSONValues.h> |
39 | #include <wtf/text/WTFString.h> |
40 | |
41 | namespace Inspector { |
42 | class InjectedScriptManager; |
43 | } |
44 | |
45 | namespace WebCore { |
46 | |
47 | class Element; |
48 | class Event; |
49 | class Frame; |
50 | class Node; |
51 | class RegisteredEventListener; |
52 | |
53 | typedef String ErrorString; |
54 | |
55 | class InspectorDOMDebuggerAgent final : public InspectorAgentBase, public Inspector::InspectorDebuggerAgent::Listener, public Inspector::DOMDebuggerBackendDispatcherHandler { |
56 | WTF_MAKE_NONCOPYABLE(InspectorDOMDebuggerAgent); |
57 | WTF_MAKE_FAST_ALLOCATED; |
58 | public: |
59 | InspectorDOMDebuggerAgent(WebAgentContext&, Inspector::InspectorDebuggerAgent*); |
60 | virtual ~InspectorDOMDebuggerAgent(); |
61 | |
62 | // DOMDebugger API |
63 | void setURLBreakpoint(ErrorString&, const String& url, const bool* optionalIsRegex) final; |
64 | void removeURLBreakpoint(ErrorString&, const String& url) final; |
65 | void setEventBreakpoint(ErrorString&, const String& breakpointType, const String& eventName) final; |
66 | void removeEventBreakpoint(ErrorString&, const String& breakpointType, const String& eventName) final; |
67 | void setDOMBreakpoint(ErrorString&, int nodeId, const String& type) final; |
68 | void removeDOMBreakpoint(ErrorString&, int nodeId, const String& type) final; |
69 | |
70 | // InspectorInstrumentation |
71 | void willInsertDOMNode(Node& parent); |
72 | void willInvalidateStyleAttr(Element&); |
73 | void didInsertDOMNode(Node&); |
74 | void willRemoveDOMNode(Node&); |
75 | void didRemoveDOMNode(Node&); |
76 | void willModifyDOMAttr(Element&); |
77 | void willSendXMLHttpRequest(const String& url); |
78 | void willFetch(const String& url); |
79 | void frameDocumentUpdated(Frame&); |
80 | void willHandleEvent(Event&, const RegisteredEventListener&); |
81 | void didHandleEvent(); |
82 | void willFireTimer(bool oneShot); |
83 | void willFireAnimationFrame(); |
84 | void mainFrameDOMContentLoaded(); |
85 | |
86 | void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) final; |
87 | void willDestroyFrontendAndBackend(Inspector::DisconnectReason) final; |
88 | void discardAgent() final; |
89 | |
90 | private: |
91 | // Inspector::InspectorDebuggerAgent::Listener implementation. |
92 | void debuggerWasEnabled() final; |
93 | void debuggerWasDisabled() final; |
94 | void disable(); |
95 | |
96 | enum class URLBreakpointSource { Fetch, XHR }; |
97 | void breakOnURLIfNeeded(const String& url, URLBreakpointSource); |
98 | |
99 | void descriptionForDOMEvent(Node& target, int breakpointType, bool insertion, JSON::Object& description); |
100 | void updateSubtreeBreakpoints(Node*, uint32_t rootMask, bool set); |
101 | bool hasBreakpoint(Node*, int type); |
102 | void discardBindings(); |
103 | |
104 | RefPtr<Inspector::DOMDebuggerBackendDispatcher> m_backendDispatcher; |
105 | Inspector::InjectedScriptManager& m_injectedScriptManager; |
106 | |
107 | Inspector::InspectorDebuggerAgent* m_debuggerAgent { nullptr }; |
108 | |
109 | HashMap<Node*, uint32_t> m_domBreakpoints; |
110 | |
111 | using EventBreakpointType = Inspector::Protocol::DOMDebugger::EventBreakpointType; |
112 | HashSet<std::pair<EventBreakpointType, String>, |
113 | WTF::PairHash<EventBreakpointType, String>, |
114 | WTF::PairHashTraits<WTF::StrongEnumHashTraits<EventBreakpointType>, WTF::HashTraits<String>> |
115 | > m_eventBreakpoints; |
116 | |
117 | enum class URLBreakpointType { RegularExpression, Text }; |
118 | HashMap<String, URLBreakpointType> m_urlBreakpoints; |
119 | bool m_pauseOnAllURLsEnabled { false }; |
120 | }; |
121 | |
122 | } // namespace WebCore |
123 | |