InspectorDebuggerAgent.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #ifndef InspectorDebuggerAgent_h
  30. #define InspectorDebuggerAgent_h
  31. #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
  32. #include "ConsoleAPITypes.h"
  33. #include "ConsoleTypes.h"
  34. #include "InjectedScript.h"
  35. #include "InspectorBaseAgent.h"
  36. #include "InspectorFrontend.h"
  37. #include "ScriptBreakpoint.h"
  38. #include "ScriptDebugListener.h"
  39. #include "ScriptState.h"
  40. #include <wtf/Forward.h>
  41. #include <wtf/HashMap.h>
  42. #include <wtf/PassOwnPtr.h>
  43. #include <wtf/PassRefPtr.h>
  44. #include <wtf/Vector.h>
  45. #include <wtf/text/StringHash.h>
  46. namespace WebCore {
  47. class InjectedScriptManager;
  48. class InspectorFrontend;
  49. class InspectorArray;
  50. class InspectorObject;
  51. class InspectorState;
  52. class InspectorValue;
  53. class InstrumentingAgents;
  54. class ScriptDebugServer;
  55. class ScriptValue;
  56. typedef String ErrorString;
  57. class InspectorDebuggerAgent : public InspectorBaseAgent<InspectorDebuggerAgent>, public ScriptDebugListener, public InspectorBackendDispatcher::DebuggerCommandHandler {
  58. WTF_MAKE_NONCOPYABLE(InspectorDebuggerAgent); WTF_MAKE_FAST_ALLOCATED;
  59. public:
  60. static const char* backtraceObjectGroup;
  61. virtual ~InspectorDebuggerAgent();
  62. virtual void causesRecompilation(ErrorString*, bool*);
  63. virtual void canSetScriptSource(ErrorString*, bool*);
  64. virtual void supportsSeparateScriptCompilationAndExecution(ErrorString*, bool*);
  65. virtual void setFrontend(InspectorFrontend*);
  66. virtual void clearFrontend();
  67. virtual void restore();
  68. bool isPaused();
  69. bool runningNestedMessageLoop();
  70. void addMessageToConsole(MessageSource, MessageType);
  71. // Part of the protocol.
  72. virtual void enable(ErrorString*);
  73. virtual void disable(ErrorString*);
  74. virtual void setBreakpointsActive(ErrorString*, bool active);
  75. virtual void setBreakpointByUrl(ErrorString*, int lineNumber, const String* optionalURL, const String* optionalURLRegex, const int* optionalColumnNumber, const String* optionalCondition, TypeBuilder::Debugger::BreakpointId*, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::Location> >& locations);
  76. virtual void setBreakpoint(ErrorString*, const RefPtr<InspectorObject>& location, const String* optionalCondition, TypeBuilder::Debugger::BreakpointId*, RefPtr<TypeBuilder::Debugger::Location>& actualLocation);
  77. virtual void removeBreakpoint(ErrorString*, const String& breakpointId);
  78. virtual void continueToLocation(ErrorString*, const RefPtr<InspectorObject>& location);
  79. virtual void searchInContent(ErrorString*, const String& scriptId, const String& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> >&);
  80. virtual void setScriptSource(ErrorString*, const String& scriptId, const String& newContent, const bool* preview, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<InspectorObject>& result);
  81. virtual void restartFrame(ErrorString*, const String& callFrameId, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<InspectorObject>& result);
  82. virtual void getScriptSource(ErrorString*, const String& scriptId, String* scriptSource);
  83. virtual void getFunctionDetails(ErrorString*, const String& functionId, RefPtr<TypeBuilder::Debugger::FunctionDetails>&);
  84. virtual void pause(ErrorString*);
  85. virtual void resume(ErrorString*);
  86. virtual void stepOver(ErrorString*);
  87. virtual void stepInto(ErrorString*);
  88. virtual void stepOut(ErrorString*);
  89. virtual void setPauseOnExceptions(ErrorString*, const String& pauseState);
  90. virtual void evaluateOnCallFrame(ErrorString*,
  91. const String& callFrameId,
  92. const String& expression,
  93. const String* objectGroup,
  94. const bool* includeCommandLineAPI,
  95. const bool* doNotPauseOnExceptionsAndMuteConsole,
  96. const bool* returnByValue,
  97. const bool* generatePreview,
  98. RefPtr<TypeBuilder::Runtime::RemoteObject>& result,
  99. TypeBuilder::OptOutput<bool>* wasThrown);
  100. void compileScript(ErrorString*, const String& expression, const String& sourceURL, TypeBuilder::OptOutput<TypeBuilder::Debugger::ScriptId>*, TypeBuilder::OptOutput<String>* syntaxErrorMessage);
  101. 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);
  102. virtual void setOverlayMessage(ErrorString*, const String*);
  103. virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String& in_variableName, const RefPtr<InspectorObject>& in_newValue, const String* in_callFrame, const String* in_functionObjectId);
  104. void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<InspectorObject> data);
  105. void cancelPauseOnNextStatement();
  106. void breakProgram(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<InspectorObject> data);
  107. virtual void scriptExecutionBlockedByCSP(const String& directiveText);
  108. class Listener {
  109. public:
  110. virtual ~Listener() { }
  111. virtual void debuggerWasEnabled() = 0;
  112. virtual void debuggerWasDisabled() = 0;
  113. virtual void stepInto() = 0;
  114. virtual void didPause() = 0;
  115. };
  116. void setListener(Listener* listener) { m_listener = listener; }
  117. virtual ScriptDebugServer& scriptDebugServer() = 0;
  118. protected:
  119. InspectorDebuggerAgent(InstrumentingAgents*, InspectorCompositeState*, InjectedScriptManager*);
  120. virtual void startListeningScriptDebugServer() = 0;
  121. virtual void stopListeningScriptDebugServer() = 0;
  122. virtual void muteConsole() = 0;
  123. virtual void unmuteConsole() = 0;
  124. InjectedScriptManager* injectedScriptManager() { return m_injectedScriptManager; }
  125. virtual InjectedScript injectedScriptForEval(ErrorString*, const int* executionContextId) = 0;
  126. virtual void enable();
  127. virtual void disable();
  128. virtual void didPause(ScriptState*, const ScriptValue& callFrames, const ScriptValue& exception);
  129. virtual void didContinue();
  130. void reset();
  131. private:
  132. bool enabled();
  133. PassRefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> > currentCallFrames();
  134. virtual void didParseSource(const String& scriptId, const Script&);
  135. virtual void failedToParseSource(const String& url, const String& data, int firstLine, int errorLine, const String& errorMessage);
  136. void setPauseOnExceptionsImpl(ErrorString*, int);
  137. PassRefPtr<TypeBuilder::Debugger::Location> resolveBreakpoint(const String& breakpointId, const String& scriptId, const ScriptBreakpoint&);
  138. void clear();
  139. bool assertPaused(ErrorString*);
  140. void clearBreakDetails();
  141. String sourceMapURLForScript(const Script&);
  142. typedef HashMap<String, Script> ScriptsMap;
  143. typedef HashMap<String, Vector<String> > BreakpointIdToDebugServerBreakpointIdsMap;
  144. InjectedScriptManager* m_injectedScriptManager;
  145. InspectorFrontend::Debugger* m_frontend;
  146. ScriptState* m_pausedScriptState;
  147. ScriptValue m_currentCallStack;
  148. ScriptsMap m_scripts;
  149. BreakpointIdToDebugServerBreakpointIdsMap m_breakpointIdToDebugServerBreakpointIds;
  150. String m_continueToLocationBreakpointId;
  151. InspectorFrontend::Debugger::Reason::Enum m_breakReason;
  152. RefPtr<InspectorObject> m_breakAuxData;
  153. bool m_javaScriptPauseScheduled;
  154. Listener* m_listener;
  155. };
  156. } // namespace WebCore
  157. #endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
  158. #endif // !defined(InspectorDebuggerAgent_h)