WebCore/bindings/v8/ScriptDebugServer.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (c) 2010, Google Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #ifndef ScriptDebugServer_h
       
    32 #define ScriptDebugServer_h
       
    33 
       
    34 #if ENABLE(JAVASCRIPT_DEBUGGER)
       
    35 
       
    36 #include "JavaScriptCallFrame.h"
       
    37 #include "PlatformString.h"
       
    38 #include "ScriptBreakpoint.h"
       
    39 #include "StringHash.h"
       
    40 #include "Timer.h"
       
    41 #include <v8-debug.h>
       
    42 #include <wtf/HashMap.h>
       
    43 #include <wtf/Noncopyable.h>
       
    44 #include <wtf/PassOwnPtr.h>
       
    45 
       
    46 namespace WebCore {
       
    47 
       
    48 class Page;
       
    49 class ScriptDebugListener;
       
    50 
       
    51 class ScriptDebugServer : public Noncopyable {
       
    52 public:
       
    53     static ScriptDebugServer& shared();
       
    54 
       
    55     void addListener(ScriptDebugListener*, Page*);
       
    56     void removeListener(ScriptDebugListener*, Page*);
       
    57 
       
    58     bool setBreakpoint(const String& sourceID, ScriptBreakpoint breakpoint, unsigned lineNumber, unsigned* actualLineNumber);
       
    59     void removeBreakpoint(const String& sourceID, unsigned lineNumber);
       
    60     void clearBreakpoints();
       
    61     void setBreakpointsActivated(bool activated);
       
    62     void activateBreakpoints() { setBreakpointsActivated(true); }
       
    63     void deactivateBreakpoints() { setBreakpointsActivated(false); }
       
    64 
       
    65     enum PauseOnExceptionsState {
       
    66         DontPauseOnExceptions,
       
    67         PauseOnAllExceptions,
       
    68         PauseOnUncaughtExceptions
       
    69     };
       
    70     PauseOnExceptionsState pauseOnExceptionsState();
       
    71     void setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExceptionsState);
       
    72 
       
    73     void pause() { }
       
    74     void continueProgram();
       
    75     void stepIntoStatement();
       
    76     void stepOverStatement();
       
    77     void stepOutOfFunction();
       
    78 
       
    79     bool editScriptSource(const String& sourceID, const String& newContent, String& newSourceOrErrorMessage);
       
    80 
       
    81     void recompileAllJSFunctionsSoon() { }
       
    82     void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) { }
       
    83 
       
    84     void pageCreated(Page*) { }
       
    85 
       
    86     // v8-specific methods.
       
    87     void setDebuggerScriptSource(const String& scriptSource);
       
    88 
       
    89     class ClientMessageLoop {
       
    90     public:
       
    91         virtual ~ClientMessageLoop() { }
       
    92         virtual void run(Page*) = 0;
       
    93         virtual void quitNow() = 0;
       
    94     };
       
    95     void setClientMessageLoop(PassOwnPtr<ClientMessageLoop> clientMessageLoop) { m_clientMessageLoop = clientMessageLoop; }
       
    96 
       
    97     PassRefPtr<JavaScriptCallFrame> currentCallFrame();
       
    98 
       
    99     void setEnabled(bool);
       
   100     bool isDebuggerAlwaysEnabled();
       
   101 
       
   102 private:
       
   103     ScriptDebugServer();
       
   104     ~ScriptDebugServer() { }
       
   105 
       
   106     static void v8DebugEventCallback(const v8::Debug::EventDetails& eventDetails);
       
   107     void handleV8DebugEvent(const v8::Debug::EventDetails& eventDetails);
       
   108 
       
   109     void dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> sourceObject);
       
   110 
       
   111     void ensureDebuggerScriptCompiled();
       
   112     void didResume();
       
   113 
       
   114     typedef HashMap<Page*, ScriptDebugListener*> ListenersMap;
       
   115     ListenersMap m_listenersMap;
       
   116     String m_debuggerScriptSource;
       
   117     PauseOnExceptionsState m_pauseOnExceptionsState;
       
   118     OwnHandle<v8::Object> m_debuggerScript;
       
   119     RefPtr<JavaScriptCallFrame> m_currentCallFrame;
       
   120     OwnHandle<v8::Object> m_executionState;
       
   121     OwnPtr<ClientMessageLoop> m_clientMessageLoop;
       
   122     Page* m_pausedPage;
       
   123     bool m_enabled;
       
   124 };
       
   125 
       
   126 } // namespace WebCore
       
   127 
       
   128 #endif // ENABLE(JAVASCRIPT_DEBUGGER)
       
   129 
       
   130 #endif // ScriptDebugServer_h