2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010-2011 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 InspectorDebuggerAgent_h
31 #define InspectorDebuggerAgent_h
33 #include "InspectorFrontend.h"
34 #include "bindings/v8/ScriptState.h"
35 #include "core/frame/ConsoleTypes.h"
36 #include "core/inspector/AsyncCallStackTracker.h"
37 #include "core/inspector/ConsoleAPITypes.h"
38 #include "core/inspector/InjectedScript.h"
39 #include "core/inspector/InspectorBaseAgent.h"
40 #include "core/inspector/PromiseTracker.h"
41 #include "core/inspector/ScriptBreakpoint.h"
42 #include "core/inspector/ScriptDebugListener.h"
43 #include "wtf/Forward.h"
44 #include "wtf/HashMap.h"
45 #include "wtf/PassRefPtr.h"
46 #include "wtf/Vector.h"
47 #include "wtf/text/StringHash.h"
54 class ExecutionContextTask;
57 class InjectedScriptManager;
58 class InspectorFrontend;
59 class InstrumentingAgents;
62 class MutationObserver;
63 class ScriptArguments;
64 class ScriptCallStack;
65 class ScriptDebugServer;
67 class ScriptSourceCode;
69 class ThreadableLoaderClient;
72 typedef String ErrorString;
74 class InspectorDebuggerAgent : public InspectorBaseAgent<InspectorDebuggerAgent>, public ScriptDebugListener, public InspectorBackendDispatcher::DebuggerCommandHandler {
75 WTF_MAKE_NONCOPYABLE(InspectorDebuggerAgent); WTF_MAKE_FAST_ALLOCATED;
77 enum BreakpointSource {
79 DebugCommandBreakpointSource,
80 MonitorCommandBreakpointSource
83 static const char backtraceObjectGroup[];
85 virtual ~InspectorDebuggerAgent();
87 virtual void canSetScriptSource(ErrorString*, bool* result) OVERRIDE FINAL { *result = true; }
89 virtual void init() OVERRIDE FINAL;
90 virtual void setFrontend(InspectorFrontend*) OVERRIDE FINAL;
91 virtual void clearFrontend() OVERRIDE FINAL;
92 virtual void restore() OVERRIDE FINAL;
95 bool runningNestedMessageLoop();
96 void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String&, ScriptCallStack*, unsigned long);
97 void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String&, ScriptState*, ScriptArguments*, unsigned long);
99 String preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName);
100 PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&);
102 // Part of the protocol.
103 virtual void enable(ErrorString*) OVERRIDE FINAL;
104 virtual void disable(ErrorString*) OVERRIDE FINAL;
105 virtual void setBreakpointsActive(ErrorString*, bool active) OVERRIDE FINAL;
106 virtual void setSkipAllPauses(ErrorString*, bool skipped, const bool* untilReload) OVERRIDE FINAL;
108 virtual void setBreakpointByUrl(ErrorString*, int lineNumber, const String* optionalURL, const String* optionalURLRegex, const int* optionalColumnNumber, const String* optionalCondition, const bool* isAntiBreakpoint, TypeBuilder::Debugger::BreakpointId*, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::Location> >& locations) OVERRIDE FINAL;
109 virtual void setBreakpoint(ErrorString*, const RefPtr<JSONObject>& location, const String* optionalCondition, TypeBuilder::Debugger::BreakpointId*, RefPtr<TypeBuilder::Debugger::Location>& actualLocation) OVERRIDE FINAL;
110 virtual void removeBreakpoint(ErrorString*, const String& breakpointId) OVERRIDE FINAL;
111 virtual void continueToLocation(ErrorString*, const RefPtr<JSONObject>& location, const bool* interstateLocationOpt) OVERRIDE FINAL;
112 virtual void getStepInPositions(ErrorString*, const String& callFrameId, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::Location> >& positions) OVERRIDE FINAL;
113 virtual void getBacktrace(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >&, RefPtr<TypeBuilder::Debugger::StackTrace>&) OVERRIDE FINAL;
115 virtual void searchInContent(ErrorString*, const String& scriptId, const String& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> >&) OVERRIDE FINAL;
116 virtual void setScriptSource(ErrorString*, RefPtr<TypeBuilder::Debugger::SetScriptSourceError>&, const String& scriptId, const String& newContent, const bool* preview, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<JSONObject>& result, RefPtr<TypeBuilder::Debugger::StackTrace>& asyncStackTrace) OVERRIDE FINAL;
117 virtual void restartFrame(ErrorString*, const String& callFrameId, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<JSONObject>& result, RefPtr<TypeBuilder::Debugger::StackTrace>& asyncStackTrace) OVERRIDE FINAL;
118 virtual void getScriptSource(ErrorString*, const String& scriptId, String* scriptSource) OVERRIDE FINAL;
119 virtual void getFunctionDetails(ErrorString*, const String& functionId, RefPtr<TypeBuilder::Debugger::FunctionDetails>&) OVERRIDE FINAL;
120 virtual void pause(ErrorString*) OVERRIDE FINAL;
121 virtual void resume(ErrorString*) OVERRIDE FINAL;
122 virtual void stepOver(ErrorString*, const String* callFrameId) OVERRIDE FINAL;
123 virtual void stepInto(ErrorString*) OVERRIDE FINAL;
124 virtual void stepOut(ErrorString*, const String* callFrameId) OVERRIDE FINAL;
125 virtual void setPauseOnExceptions(ErrorString*, const String& pauseState) OVERRIDE FINAL;
126 virtual void evaluateOnCallFrame(ErrorString*,
127 const String& callFrameId,
128 const String& expression,
129 const String* objectGroup,
130 const bool* includeCommandLineAPI,
131 const bool* doNotPauseOnExceptionsAndMuteConsole,
132 const bool* returnByValue,
133 const bool* generatePreview,
134 RefPtr<TypeBuilder::Runtime::RemoteObject>& result,
135 TypeBuilder::OptOutput<bool>* wasThrown) OVERRIDE FINAL;
136 virtual void compileScript(ErrorString*, const String& expression, const String& sourceURL, const int* executionContextId, TypeBuilder::OptOutput<TypeBuilder::Debugger::ScriptId>*, TypeBuilder::OptOutput<String>* syntaxErrorMessage) OVERRIDE;
137 virtual void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&, const int* executionContextId, const String* objectGroup, const bool* doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) OVERRIDE;
138 virtual void setOverlayMessage(ErrorString*, const String*) OVERRIDE;
139 virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String& in_variableName, const RefPtr<JSONObject>& in_newValue, const String* in_callFrame, const String* in_functionObjectId) OVERRIDE FINAL;
140 virtual void skipStackFrames(ErrorString*, const String* pattern) OVERRIDE FINAL;
141 virtual void setAsyncCallStackDepth(ErrorString*, int depth) OVERRIDE FINAL;
143 void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data);
144 void didInstallTimer(ExecutionContext*, int timerId, int timeout, bool singleShot);
145 void didRemoveTimer(ExecutionContext*, int timerId);
146 bool willFireTimer(ExecutionContext*, int timerId);
148 void didRequestAnimationFrame(Document*, int callbackId);
149 void didCancelAnimationFrame(Document*, int callbackId);
150 bool willFireAnimationFrame(Document*, int callbackId);
151 void didFireAnimationFrame();
152 void didAddEventListener(EventTarget*, const AtomicString& eventType, EventListener*, bool useCapture);
153 void didRemoveEventListener(EventTarget*, const AtomicString& eventType, EventListener*, bool useCapture);
154 void didRemoveAllEventListeners(EventTarget*);
155 void willHandleEvent(EventTarget*, const AtomicString& eventType, EventListener*, bool useCapture);
156 void didHandleEvent();
157 void willLoadXHR(XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString& method, const KURL&, bool async, FormData* body, const HTTPHeaderMap& headers, bool includeCrendentials);
158 void didEnqueueMutationRecord(ExecutionContext*, MutationObserver*);
159 void didClearAllMutationRecords(ExecutionContext*, MutationObserver*);
160 void willDeliverMutationRecords(ExecutionContext*, MutationObserver*);
161 void didDeliverMutationRecords();
162 void didPostPromiseTask(ExecutionContext*, ExecutionContextTask*, bool isResolved);
163 void willPerformPromiseTask(ExecutionContext*, ExecutionContextTask*);
164 void didPerformPromiseTask();
165 bool isPromiseTrackerEnabled();
166 void didCreatePromise(const ScriptObject& promise);
167 void didUpdatePromiseParent(const ScriptObject& promise, const ScriptObject& parentPromise);
168 void didUpdatePromiseState(const ScriptObject& promise, V8PromiseCustom::PromiseState, const ScriptValue& result);
169 bool canBreakProgram();
170 void breakProgram(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data);
171 void scriptExecutionBlockedByCSP(const String& directiveText);
175 virtual ~Listener() { }
176 virtual void debuggerWasEnabled() = 0;
177 virtual void debuggerWasDisabled() = 0;
178 virtual void stepInto() = 0;
179 virtual void didPause() = 0;
181 void setListener(Listener* listener) { m_listener = listener; }
183 virtual ScriptDebugServer& scriptDebugServer() = 0;
185 void setBreakpoint(const String& scriptId, int lineNumber, int columnNumber, BreakpointSource, const String& condition = String());
186 void removeBreakpoint(const String& scriptId, int lineNumber, int columnNumber, BreakpointSource);
188 virtual SkipPauseRequest shouldSkipExceptionPause(RefPtr<JavaScriptCallFrame>& topFrame) OVERRIDE FINAL;
189 virtual SkipPauseRequest shouldSkipBreakpointPause(RefPtr<JavaScriptCallFrame>& topFrame) OVERRIDE FINAL;
190 virtual SkipPauseRequest shouldSkipStepPause(RefPtr<JavaScriptCallFrame>& topFrame) OVERRIDE FINAL;
193 explicit InspectorDebuggerAgent(InjectedScriptManager*);
195 virtual void startListeningScriptDebugServer() = 0;
196 virtual void stopListeningScriptDebugServer() = 0;
197 virtual void muteConsole() = 0;
198 virtual void unmuteConsole() = 0;
199 InjectedScriptManager* injectedScriptManager() { return m_injectedScriptManager; }
200 virtual InjectedScript injectedScriptForEval(ErrorString*, const int* executionContextId) = 0;
202 virtual void enable();
203 virtual void disable();
204 virtual void didPause(ScriptState*, const ScriptValue& callFrames, const ScriptValue& exception, const Vector<String>& hitBreakpoints) OVERRIDE FINAL;
205 virtual void didContinue() OVERRIDE FINAL;
207 void pageDidCommitLoad();
210 void cancelPauseOnNextStatement();
211 void addMessageToConsole(MessageSource, MessageType);
215 PassRefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> > currentCallFrames();
216 PassRefPtr<TypeBuilder::Debugger::StackTrace> currentAsyncStackTrace();
218 virtual void didParseSource(const String& scriptId, const Script&) OVERRIDE FINAL;
219 virtual void failedToParseSource(const String& url, const String& data, int firstLine, int errorLine, const String& errorMessage) OVERRIDE FINAL;
221 void setPauseOnExceptionsImpl(ErrorString*, int);
223 PassRefPtr<TypeBuilder::Debugger::Location> resolveBreakpoint(const String& breakpointId, const String& scriptId, const ScriptBreakpoint&, BreakpointSource);
224 void removeBreakpoint(const String& breakpointId);
226 bool assertPaused(ErrorString*);
227 void clearBreakDetails();
229 String sourceMapURLForScript(const Script&);
231 String scriptURL(JavaScriptCallFrame*);
233 ScriptValue resolveCallFrame(ErrorString*, const String* callFrameId);
235 typedef HashMap<String, Script> ScriptsMap;
236 typedef HashMap<String, Vector<String> > BreakpointIdToDebugServerBreakpointIdsMap;
237 typedef HashMap<String, std::pair<String, BreakpointSource> > DebugServerBreakpointToBreakpointIdAndSourceMap;
239 InjectedScriptManager* m_injectedScriptManager;
240 InspectorFrontend::Debugger* m_frontend;
241 RefPtr<ScriptState> m_pausedScriptState;
242 ScriptValue m_currentCallStack;
243 ScriptsMap m_scripts;
244 BreakpointIdToDebugServerBreakpointIdsMap m_breakpointIdToDebugServerBreakpointIds;
245 DebugServerBreakpointToBreakpointIdAndSourceMap m_serverBreakpoints;
246 String m_continueToLocationBreakpointId;
247 InspectorFrontend::Debugger::Reason::Enum m_breakReason;
248 RefPtr<JSONObject> m_breakAuxData;
249 bool m_javaScriptPauseScheduled;
250 Listener* m_listener;
252 int m_skipStepInCount;
253 bool m_skipAllPauses;
254 OwnPtr<ScriptRegexp> m_cachedSkipStackRegExp;
255 AsyncCallStackTracker m_asyncCallStackTracker;
256 PromiseTracker m_promiseTracker;
259 } // namespace WebCore
262 #endif // !defined(InspectorDebuggerAgent_h)