InspectorDebuggerAgent.h revision 81bc750723a18f21cd17d1b173cd2a4dda9cea6e
1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2010 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#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR) 34#include "InjectedScript.h" 35#include "InspectorFrontend.h" 36#include "ScriptBreakpoint.h" 37#include "ScriptDebugListener.h" 38#include "ScriptState.h" 39#include <wtf/Forward.h> 40#include <wtf/HashMap.h> 41#include <wtf/PassOwnPtr.h> 42#include <wtf/Vector.h> 43#include <wtf/text/StringHash.h> 44 45namespace WebCore { 46 47class InjectedScriptHost; 48class InspectorFrontend; 49class InspectorObject; 50class InspectorState; 51class InspectorValue; 52class InstrumentingAgents; 53class Page; 54 55typedef String ErrorString; 56 57enum DebuggerEventType { 58 JavaScriptPauseEventType, 59 JavaScriptBreakpointEventType, 60 NativeBreakpointDebuggerEventType 61}; 62 63class InspectorDebuggerAgent : public ScriptDebugListener { 64 WTF_MAKE_NONCOPYABLE(InspectorDebuggerAgent); WTF_MAKE_FAST_ALLOCATED; 65public: 66 static PassOwnPtr<InspectorDebuggerAgent> create(InstrumentingAgents*, InspectorState*, Page*, InjectedScriptHost*); 67 virtual ~InspectorDebuggerAgent(); 68 69 void startUserInitiatedDebugging(); 70 void enable(ErrorString*) { enable(false); } 71 void disable(ErrorString*) { disable(); } 72 void disable(); 73 bool enabled(); 74 void restore(); 75 void setFrontend(InspectorFrontend*); 76 void enableDebuggerAfterShown(); 77 void clearFrontend(); 78 79 void inspectedURLChanged(const String& url); 80 81 // Part of the protocol. 82 void activateBreakpoints(ErrorString* error); 83 void deactivateBreakpoints(ErrorString* error); 84 85 void setJavaScriptBreakpoint(ErrorString* error, const String& url, int lineNumber, int columnNumber, const String& condition, bool enabled, String* breakpointId, RefPtr<InspectorArray>* locations); 86 void setJavaScriptBreakpointBySourceId(ErrorString* error, const String& sourceId, int lineNumber, int columnNumber, const String& condition, bool enabled, String* breakpointId, int* actualLineNumber, int* actualColumnNumber); 87 void removeJavaScriptBreakpoint(ErrorString* error, const String& breakpointId); 88 void continueToLocation(ErrorString* error, const String& sourceId, int lineNumber, int columnNumber); 89 90 void editScriptSource(ErrorString* error, const String& sourceID, const String& newContent, bool* success, String* result, RefPtr<InspectorValue>* newCallFrames); 91 void getScriptSource(ErrorString* error, const String& sourceID, String* scriptSource); 92 void schedulePauseOnNextStatement(DebuggerEventType type, PassRefPtr<InspectorValue> data); 93 void cancelPauseOnNextStatement(); 94 void breakProgram(DebuggerEventType type, PassRefPtr<InspectorValue> data); 95 void pause(ErrorString* error); 96 void resume(ErrorString* error); 97 void stepOver(ErrorString* error); 98 void stepInto(ErrorString* error); 99 void stepOut(ErrorString* error); 100 void setPauseOnExceptionsState(ErrorString* error, long pauseState, long* newState); 101 void evaluateOnCallFrame(ErrorString* error, PassRefPtr<InspectorObject> callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, RefPtr<InspectorValue>* result); 102 103 class Listener { 104 public: 105 virtual ~Listener() { } 106 virtual void debuggerWasEnabled() = 0; 107 virtual void debuggerWasDisabled() = 0; 108 }; 109 void setListener(Listener* listener) { m_listener = listener; } 110 111private: 112 InspectorDebuggerAgent(InstrumentingAgents*, InspectorState*, Page*, InjectedScriptHost*); 113 114 void enable(bool restoringFromState); 115 116 PassRefPtr<InspectorValue> currentCallFrames(); 117 118 virtual void didParseSource(const String& sourceID, const String& url, const String& data, int lineOffset, int columnOffset, ScriptWorldType); 119 virtual void failedToParseSource(const String& url, const String& data, int firstLine, int errorLine, const String& errorMessage); 120 virtual void didPause(ScriptState*); 121 virtual void didContinue(); 122 123 bool resolveBreakpoint(const String& breakpointId, const String& sourceId, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber); 124 void clear(); 125 126 class Script { 127 public: 128 Script() 129 : lineOffset(0) 130 , columnOffset(0) 131 , linesCount(0) 132 { 133 } 134 135 Script(const String& url, const String& data, int lineOffset, int columnOffset) 136 : url(url) 137 , data(data) 138 , lineOffset(lineOffset) 139 , columnOffset(columnOffset) 140 , linesCount(0) 141 { 142 } 143 144 String url; 145 String data; 146 int lineOffset; 147 int columnOffset; 148 int linesCount; 149 }; 150 151 typedef HashMap<String, Script> ScriptsMap; 152 typedef HashMap<String, Vector<String> > BreakpointIdToDebugServerBreakpointIdsMap; 153 154 InstrumentingAgents* m_instrumentingAgents; 155 InspectorState* m_inspectorState; 156 Page* m_inspectedPage; 157 InjectedScriptHost* m_injectedScriptHost; 158 InspectorFrontend::Debugger* m_frontend; 159 ScriptState* m_pausedScriptState; 160 ScriptsMap m_scripts; 161 BreakpointIdToDebugServerBreakpointIdsMap m_breakpointIdToDebugServerBreakpointIds; 162 String m_continueToLocationBreakpointId; 163 RefPtr<InspectorObject> m_breakProgramDetails; 164 bool m_javaScriptPauseScheduled; 165 Listener* m_listener; 166}; 167 168} // namespace WebCore 169 170#endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR) 171 172#endif // !defined(InspectorDebuggerAgent_h) 173