OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010-2011 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 InspectorDebuggerAgent_h |
| 31 #define InspectorDebuggerAgent_h |
| 32 |
| 33 #include "bindings/core/v8/ScriptState.h" |
| 34 #include "core/InspectorFrontend.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" |
| 48 |
| 49 namespace blink { |
| 50 |
| 51 class ConsoleMessage; |
| 52 class Document; |
| 53 class Event; |
| 54 class EventListener; |
| 55 class EventTarget; |
| 56 class FormData; |
| 57 class HTTPHeaderMap; |
| 58 class InjectedScriptManager; |
| 59 class InspectorFrontend; |
| 60 class InstrumentingAgents; |
| 61 class JavaScriptCallFrame; |
| 62 class JSONObject; |
| 63 class KURL; |
| 64 class MutationObserver; |
| 65 class ScriptArguments; |
| 66 class ScriptAsyncCallStack; |
| 67 class ScriptCallStack; |
| 68 class ScriptDebugServer; |
| 69 class ScriptRegexp; |
| 70 class ScriptSourceCode; |
| 71 class ScriptValue; |
| 72 class ThreadableLoaderClient; |
| 73 class XMLHttpRequest; |
| 74 |
| 75 typedef String ErrorString; |
| 76 |
| 77 class InspectorDebuggerAgent : public InspectorBaseAgent<InspectorDebuggerAgent>
, public ScriptDebugListener, public InspectorBackendDispatcher::DebuggerCommand
Handler { |
| 78 WTF_MAKE_NONCOPYABLE(InspectorDebuggerAgent); |
| 79 WTF_MAKE_FAST_ALLOCATED; |
| 80 public: |
| 81 enum BreakpointSource { |
| 82 UserBreakpointSource, |
| 83 DebugCommandBreakpointSource, |
| 84 MonitorCommandBreakpointSource |
| 85 }; |
| 86 |
| 87 static const char backtraceObjectGroup[]; |
| 88 |
| 89 virtual ~InspectorDebuggerAgent(); |
| 90 |
| 91 virtual void canSetScriptSource(ErrorString*, bool* result) override final {
*result = true; } |
| 92 |
| 93 virtual void virtualInit() override final; |
| 94 virtual void setFrontend(InspectorFrontend*) override final; |
| 95 virtual void clearFrontend() override final; |
| 96 virtual void restore() override final; |
| 97 |
| 98 bool isPaused(); |
| 99 bool runningNestedMessageLoop(); |
| 100 void addMessageToConsole(ConsoleMessage*); |
| 101 |
| 102 String preprocessEventListener(LocalFrame*, const String& source, const Stri
ng& url, const String& functionName); |
| 103 PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&
); |
| 104 |
| 105 // Part of the protocol. |
| 106 virtual void enable(ErrorString*) override final; |
| 107 virtual void disable(ErrorString*) override final; |
| 108 virtual void setBreakpointsActive(ErrorString*, bool active) override final; |
| 109 virtual void setSkipAllPauses(ErrorString*, bool skipped, const bool* untilR
eload) override final; |
| 110 |
| 111 virtual void setBreakpointByUrl(ErrorString*, int lineNumber, const String*
optionalURL, const String* optionalURLRegex, const int* optionalColumnNumber, co
nst String* optionalCondition, const bool* isAntiBreakpoint, TypeBuilder::Debugg
er::BreakpointId*, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::Location> >&
locations) override final; |
| 112 virtual void setBreakpoint(ErrorString*, const RefPtr<JSONObject>& location,
const String* optionalCondition, TypeBuilder::Debugger::BreakpointId*, RefPtr<T
ypeBuilder::Debugger::Location>& actualLocation) override final; |
| 113 virtual void removeBreakpoint(ErrorString*, const String& breakpointId) over
ride final; |
| 114 virtual void continueToLocation(ErrorString*, const RefPtr<JSONObject>& loca
tion, const bool* interstateLocationOpt) override final; |
| 115 virtual void getStepInPositions(ErrorString*, const String& callFrameId, Ref
Ptr<TypeBuilder::Array<TypeBuilder::Debugger::Location> >& positions) override f
inal; |
| 116 virtual void getBacktrace(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilde
r::Debugger::CallFrame> >&, RefPtr<TypeBuilder::Debugger::StackTrace>&) override
final; |
| 117 |
| 118 virtual void searchInContent(ErrorString*, const String& scriptId, const Str
ing& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefP
tr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> >&) override final; |
| 119 virtual void setScriptSource(ErrorString*, RefPtr<TypeBuilder::Debugger::Set
ScriptSourceError>&, const String& scriptId, const String& newContent, const boo
l* preview, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCa
llFrames, RefPtr<JSONObject>& result, RefPtr<TypeBuilder::Debugger::StackTrace>&
asyncStackTrace) override final; |
| 120 virtual void restartFrame(ErrorString*, const String& callFrameId, RefPtr<Ty
peBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<JSON
Object>& result, RefPtr<TypeBuilder::Debugger::StackTrace>& asyncStackTrace) ove
rride final; |
| 121 virtual void getScriptSource(ErrorString*, const String& scriptId, String* s
criptSource) override final; |
| 122 virtual void getFunctionDetails(ErrorString*, const String& functionId, RefP
tr<TypeBuilder::Debugger::FunctionDetails>&) override final; |
| 123 virtual void getCollectionEntries(ErrorString*, const String& objectId, RefP
tr<TypeBuilder::Array<TypeBuilder::Debugger::CollectionEntry> >&) override final
; |
| 124 virtual void pause(ErrorString*) override final; |
| 125 virtual void resume(ErrorString*) override final; |
| 126 virtual void stepOver(ErrorString*) override final; |
| 127 virtual void stepInto(ErrorString*) override final; |
| 128 virtual void stepOut(ErrorString*) override final; |
| 129 virtual void setPauseOnExceptions(ErrorString*, const String& pauseState) ov
erride final; |
| 130 virtual void evaluateOnCallFrame(ErrorString*, |
| 131 const String& callFrameId, |
| 132 const String& expression, |
| 133 const String* objectGroup, |
| 134 const bool* includeCommandLineAPI, |
| 135 const bool* doNotPauseOnExceptionsAndMuteConsole, |
| 136 const bool* returnByValue, |
| 137 const bool* generatePreview, |
| 138 RefPtr<TypeBuilder::Runtime::RemoteObject>& result, |
| 139 TypeBuilder::OptOutput<bool>* wasThrown, |
| 140 RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) override final; |
| 141 virtual void compileScript(ErrorString*, const String& expression, const Str
ing& sourceURL, const int* executionContextId, TypeBuilder::OptOutput<TypeBuilde
r::Debugger::ScriptId>*, RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) overr
ide; |
| 142 virtual void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&,
const int* executionContextId, const String* objectGroup, const bool* doNotPaus
eOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result,
RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) override; |
| 143 virtual void setOverlayMessage(ErrorString*, const String*) override; |
| 144 virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String
& in_variableName, const RefPtr<JSONObject>& in_newValue, const String* in_callF
rame, const String* in_functionObjectId) override final; |
| 145 virtual void skipStackFrames(ErrorString*, const String* pattern) override f
inal; |
| 146 virtual void setAsyncCallStackDepth(ErrorString*, int depth) override final; |
| 147 |
| 148 void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum
breakReason, PassRefPtr<JSONObject> data); |
| 149 void didInstallTimer(ExecutionContext*, int timerId, int timeout, bool singl
eShot); |
| 150 void didRemoveTimer(ExecutionContext*, int timerId); |
| 151 bool willFireTimer(ExecutionContext*, int timerId); |
| 152 void didFireTimer(); |
| 153 void didRequestAnimationFrame(Document*, int callbackId); |
| 154 void didCancelAnimationFrame(Document*, int callbackId); |
| 155 bool willFireAnimationFrame(Document*, int callbackId); |
| 156 void didFireAnimationFrame(); |
| 157 void didEnqueueEvent(EventTarget*, Event*); |
| 158 void didRemoveEvent(EventTarget*, Event*); |
| 159 void willHandleEvent(EventTarget*, Event*, EventListener*, bool useCapture); |
| 160 void didHandleEvent(); |
| 161 void didEnqueueMutationRecord(ExecutionContext*, MutationObserver*); |
| 162 void didClearAllMutationRecords(ExecutionContext*, MutationObserver*); |
| 163 void willDeliverMutationRecords(ExecutionContext*, MutationObserver*); |
| 164 void didDeliverMutationRecords(); |
| 165 // void didPostExecutionContextTask(ExecutionContext*, ExecutionContextTask*
); |
| 166 // void didKillAllExecutionContextTasks(ExecutionContext*); |
| 167 // void willPerformExecutionContextTask(ExecutionContext*, ExecutionContextT
ask*); |
| 168 // void didPerformExecutionContextTask(); |
| 169 int traceAsyncOperationStarting(ExecutionContext*, const String& operationNa
me, int prevOperationId = 0); |
| 170 void traceAsyncOperationCompleted(ExecutionContext*, int operationId); |
| 171 void traceAsyncOperationCompletedCallbackStarting(ExecutionContext*, int ope
rationId); |
| 172 void traceAsyncCallbackStarting(ExecutionContext*, int operationId); |
| 173 void traceAsyncCallbackCompleted(); |
| 174 bool canBreakProgram(); |
| 175 void breakProgram(InspectorFrontend::Debugger::Reason::Enum breakReason, Pas
sRefPtr<JSONObject> data); |
| 176 void scriptExecutionBlockedByCSP(const String& directiveText); |
| 177 |
| 178 class Listener { |
| 179 public: |
| 180 virtual ~Listener() { } |
| 181 virtual void debuggerWasEnabled() = 0; |
| 182 virtual void debuggerWasDisabled() = 0; |
| 183 virtual void stepInto() = 0; |
| 184 virtual void didPause() = 0; |
| 185 }; |
| 186 void setListener(Listener* listener) { m_listener = listener; } |
| 187 |
| 188 bool enabled(); |
| 189 |
| 190 virtual ScriptDebugServer& scriptDebugServer() = 0; |
| 191 |
| 192 void setBreakpoint(const String& scriptId, int lineNumber, int columnNumber,
BreakpointSource, const String& condition = String()); |
| 193 void removeBreakpoint(const String& scriptId, int lineNumber, int columnNumb
er, BreakpointSource); |
| 194 |
| 195 PassRefPtr<ScriptAsyncCallStack> currentAsyncStackTraceForConsole(); |
| 196 |
| 197 protected: |
| 198 explicit InspectorDebuggerAgent(InjectedScriptManager*); |
| 199 |
| 200 virtual void startListeningScriptDebugServer() = 0; |
| 201 virtual void stopListeningScriptDebugServer() = 0; |
| 202 virtual void muteConsole() = 0; |
| 203 virtual void unmuteConsole() = 0; |
| 204 InjectedScriptManager* injectedScriptManager() { return m_injectedScriptMana
ger; } |
| 205 virtual InjectedScript injectedScriptForEval(ErrorString*, const int* execut
ionContextId) = 0; |
| 206 |
| 207 virtual void enable(); |
| 208 virtual void disable(); |
| 209 virtual SkipPauseRequest didPause(ScriptState*, const ScriptValue& callFrame
s, const ScriptValue& exception, const Vector<String>& hitBreakpoints) override
final; |
| 210 virtual void didContinue() override final; |
| 211 void reset(); |
| 212 void pageDidCommitLoad(); |
| 213 |
| 214 private: |
| 215 bool shouldSkipInspectorInternals(); |
| 216 SkipPauseRequest shouldSkipExceptionPause(); |
| 217 SkipPauseRequest shouldSkipStepPause(); |
| 218 bool isTopCallFrameInFramework(); |
| 219 |
| 220 void cancelPauseOnNextStatement(); |
| 221 void addMessageToConsole(MessageSource, MessageType); |
| 222 |
| 223 PassRefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> > currentCal
lFrames(); |
| 224 PassRefPtr<TypeBuilder::Debugger::StackTrace> currentAsyncStackTrace(); |
| 225 |
| 226 virtual void didParseSource(const String& scriptId, const Script&, CompileRe
sult) override final; |
| 227 virtual void didReceiveV8AsyncTaskEvent(ExecutionContext*, const String& eve
ntType, const String& eventName, int id) override final; |
| 228 virtual void didReceiveV8PromiseEvent(ScriptState*, v8::Handle<v8::Object> p
romise, v8::Handle<v8::Value> parentPromise, int status) override final; |
| 229 |
| 230 void setPauseOnExceptionsImpl(ErrorString*, int); |
| 231 |
| 232 PassRefPtr<TypeBuilder::Debugger::Location> resolveBreakpoint(const String&
breakpointId, const String& scriptId, const ScriptBreakpoint&, BreakpointSource)
; |
| 233 void removeBreakpoint(const String& breakpointId); |
| 234 void clear(); |
| 235 bool assertPaused(ErrorString*); |
| 236 void clearBreakDetails(); |
| 237 |
| 238 String sourceMapURLForScript(const Script&, CompileResult); |
| 239 |
| 240 PassRefPtr<JavaScriptCallFrame> topCallFrameSkipUnknownSources(); |
| 241 String scriptURL(JavaScriptCallFrame*); |
| 242 AsyncCallStackTracker& asyncCallStackTracker() { return *m_asyncCallStackTra
cker; }; |
| 243 |
| 244 typedef HashMap<String, Script> ScriptsMap; |
| 245 typedef HashMap<String, Vector<String> > BreakpointIdToDebugServerBreakpoint
IdsMap; |
| 246 typedef HashMap<String, std::pair<String, BreakpointSource> > DebugServerBre
akpointToBreakpointIdAndSourceMap; |
| 247 |
| 248 RawPtr<InjectedScriptManager> m_injectedScriptManager; |
| 249 InspectorFrontend::Debugger* m_frontend; |
| 250 RefPtr<ScriptState> m_pausedScriptState; |
| 251 ScriptValue m_currentCallStack; |
| 252 ScriptsMap m_scripts; |
| 253 BreakpointIdToDebugServerBreakpointIdsMap m_breakpointIdToDebugServerBreakpo
intIds; |
| 254 DebugServerBreakpointToBreakpointIdAndSourceMap m_serverBreakpoints; |
| 255 String m_continueToLocationBreakpointId; |
| 256 InspectorFrontend::Debugger::Reason::Enum m_breakReason; |
| 257 RefPtr<JSONObject> m_breakAuxData; |
| 258 bool m_javaScriptPauseScheduled; |
| 259 bool m_debuggerStepScheduled; |
| 260 bool m_steppingFromFramework; |
| 261 bool m_pausingOnNativeEvent; |
| 262 RawPtr<Listener> m_listener; |
| 263 |
| 264 int m_skippedStepInCount; |
| 265 int m_minFrameCountForSkip; |
| 266 bool m_skipAllPauses; |
| 267 OwnPtr<ScriptRegexp> m_cachedSkipStackRegExp; |
| 268 OwnPtr<AsyncCallStackTracker> m_asyncCallStackTracker; |
| 269 PromiseTracker m_promiseTracker; |
| 270 }; |
| 271 |
| 272 } // namespace blink |
| 273 |
| 274 |
| 275 #endif // !defined(InspectorDebuggerAgent_h) |
OLD | NEW |