2011-01-21 Pavel Podivilov <podivilov@chromium.org>
authorpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jan 2011 16:08:45 +0000 (16:08 +0000)
committerpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jan 2011 16:08:45 +0000 (16:08 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: move sticky breakpoints management from InspectorController to InspectorBrowserDebuggerAgent.
        https://bugs.webkit.org/show_bug.cgi?id=52874

        This is the first step of debugger api refactoring (see bug 52879).
        JavaScript breakpoints are still in the same list as native breakpoints and are restored by InspectorBrowserDebuggerAgent.
        The second step will be to move sticky JavaScript breakpoints to InspectorDebuggerAgent.

        * inspector/Inspector.idl:
        * inspector/InspectorBrowserDebuggerAgent.cpp:
        (WebCore::InspectorBrowserDebuggerAgent::setAllBrowserBreakpoints):
        (WebCore::InspectorBrowserDebuggerAgent::inspectedURLChanged):
        (WebCore::InspectorBrowserDebuggerAgent::restoreStickyBreakpoint):
        (WebCore::InspectorBrowserDebuggerAgent::discardBindings):
        (WebCore::InspectorBrowserDebuggerAgent::didInsertDOMNode):
        (WebCore::InspectorBrowserDebuggerAgent::didRemoveDOMNode):
        (WebCore::InspectorBrowserDebuggerAgent::setDOMBreakpoint):
        (WebCore::InspectorBrowserDebuggerAgent::removeDOMBreakpoint):
        (WebCore::InspectorBrowserDebuggerAgent::descriptionForDOMEvent):
        (WebCore::InspectorBrowserDebuggerAgent::hasBreakpoint):
        (WebCore::InspectorBrowserDebuggerAgent::updateSubtreeBreakpoints):
        * inspector/InspectorBrowserDebuggerAgent.h:
        * inspector/InspectorController.cpp:
        (WebCore::InspectorController::restoreInspectorStateFromCookie):
        (WebCore::InspectorController::connectFrontend):
        (WebCore::InspectorController::didCommitLoad):
        (WebCore::InspectorController::enableDebugger):
        (WebCore::InspectorController::resume):
        (WebCore::InspectorController::inspectedURL):
        * inspector/InspectorController.h:
        * inspector/InspectorState.cpp:
        (WebCore::InspectorState::InspectorState):
        * inspector/InspectorState.h:
        * inspector/front-end/BreakpointManager.js:
        (WebInspector.BreakpointManager):
        (WebInspector.BreakpointManager.prototype._saveBreakpoints):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@76348 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.idl
Source/WebCore/inspector/InspectorBrowserDebuggerAgent.cpp
Source/WebCore/inspector/InspectorBrowserDebuggerAgent.h
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorController.h
Source/WebCore/inspector/InspectorState.cpp
Source/WebCore/inspector/InspectorState.h
Source/WebCore/inspector/front-end/BreakpointManager.js

index 97ad274..4316806 100644 (file)
@@ -1,3 +1,43 @@
+2011-01-21  Pavel Podivilov  <podivilov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: move sticky breakpoints management from InspectorController to InspectorBrowserDebuggerAgent.
+        https://bugs.webkit.org/show_bug.cgi?id=52874
+
+        This is the first step of debugger api refactoring (see bug 52879).
+        JavaScript breakpoints are still in the same list as native breakpoints and are restored by InspectorBrowserDebuggerAgent.
+        The second step will be to move sticky JavaScript breakpoints to InspectorDebuggerAgent.
+
+        * inspector/Inspector.idl:
+        * inspector/InspectorBrowserDebuggerAgent.cpp:
+        (WebCore::InspectorBrowserDebuggerAgent::setAllBrowserBreakpoints):
+        (WebCore::InspectorBrowserDebuggerAgent::inspectedURLChanged):
+        (WebCore::InspectorBrowserDebuggerAgent::restoreStickyBreakpoint):
+        (WebCore::InspectorBrowserDebuggerAgent::discardBindings):
+        (WebCore::InspectorBrowserDebuggerAgent::didInsertDOMNode):
+        (WebCore::InspectorBrowserDebuggerAgent::didRemoveDOMNode):
+        (WebCore::InspectorBrowserDebuggerAgent::setDOMBreakpoint):
+        (WebCore::InspectorBrowserDebuggerAgent::removeDOMBreakpoint):
+        (WebCore::InspectorBrowserDebuggerAgent::descriptionForDOMEvent):
+        (WebCore::InspectorBrowserDebuggerAgent::hasBreakpoint):
+        (WebCore::InspectorBrowserDebuggerAgent::updateSubtreeBreakpoints):
+        * inspector/InspectorBrowserDebuggerAgent.h:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::restoreInspectorStateFromCookie):
+        (WebCore::InspectorController::connectFrontend):
+        (WebCore::InspectorController::didCommitLoad):
+        (WebCore::InspectorController::enableDebugger):
+        (WebCore::InspectorController::resume):
+        (WebCore::InspectorController::inspectedURL):
+        * inspector/InspectorController.h:
+        * inspector/InspectorState.cpp:
+        (WebCore::InspectorState::InspectorState):
+        * inspector/InspectorState.h:
+        * inspector/front-end/BreakpointManager.js:
+        (WebInspector.BreakpointManager):
+        (WebInspector.BreakpointManager.prototype._saveBreakpoints):
+
 2011-01-21  John Knottenbelt  <jknotten@chromium.org>
 
         Reviewed by Jeremy Orlow.
index b8d1250..79b33f6 100644 (file)
@@ -242,7 +242,7 @@ module core {
         [domain=Inspector] void enableDebugger(in boolean always);
         [domain=Inspector] void disableDebugger(in boolean always);
 
-        [domain=Inspector] void setStickyBreakpoints(in Object breakpoints);
+        [domain=Inspector] void setAllBrowserBreakpoints(in Object breakpoints);
 
         [notify, domain=Debugger] void debuggerWasEnabled();
         [notify, domain=Debugger] void debuggerWasDisabled();
index 906181e..023dc49 100644 (file)
@@ -71,9 +71,71 @@ InspectorBrowserDebuggerAgent::~InspectorBrowserDebuggerAgent()
 {
 }
 
+void InspectorBrowserDebuggerAgent::inspectedURLChanged(const KURL& url)
+{
+    m_eventListenerBreakpoints.clear();
+    m_XHRBreakpoints.clear();
+    m_hasXHRBreakpointWithEmptyURL = false;
+
+    RefPtr<InspectorObject> allBreakpoints = m_inspectorController->state()->getObject(InspectorState::browserBreakpoints);
+    KURL urlCopy = url;
+    urlCopy.removeFragmentIdentifier();
+    RefPtr<InspectorArray> breakpoints = allBreakpoints->getArray(urlCopy);
+    if (!breakpoints)
+        return;
+    for (unsigned i = 0; i < breakpoints->length(); ++i)
+        restoreStickyBreakpoint(breakpoints->get(i)->asObject());
+}
+
+void InspectorBrowserDebuggerAgent::restoreStickyBreakpoint(PassRefPtr<InspectorObject> breakpoint)
+{
+    DEFINE_STATIC_LOCAL(String, eventListenerBreakpointType, ("EventListener"));
+    DEFINE_STATIC_LOCAL(String, javaScriptBreakpointType, ("JS"));
+    DEFINE_STATIC_LOCAL(String, xhrBreakpointType, ("XHR"));
+
+    if (!breakpoint)
+        return;
+    String type;
+    if (!breakpoint->getString("type", &type))
+        return;
+    bool enabled;
+    if (!breakpoint->getBoolean("enabled", &enabled))
+        return;
+    RefPtr<InspectorObject> condition = breakpoint->getObject("condition");
+    if (!condition)
+        return;
+
+    if (type == eventListenerBreakpointType) {
+        if (!enabled)
+            return;
+        String eventName;
+        if (!condition->getString("eventName", &eventName))
+            return;
+        setEventListenerBreakpoint(eventName);
+    } else if (type == javaScriptBreakpointType && m_inspectorController->debuggerAgent()) {
+        String url;
+        if (!condition->getString("url", &url))
+            return;
+        double lineNumber;
+        if (!condition->getNumber("lineNumber", &lineNumber))
+            return;
+        String javaScriptCondition;
+        if (!condition->getString("condition", &javaScriptCondition))
+            return;
+        m_inspectorController->debuggerAgent()->setStickyBreakpoint(url, static_cast<unsigned>(lineNumber), javaScriptCondition, enabled);
+    } else if (type == xhrBreakpointType) {
+        if (!enabled)
+            return;
+        String url;
+        if (!condition->getString("url", &url))
+            return;
+        setXHRBreakpoint(url);
+    }
+}
+
 void InspectorBrowserDebuggerAgent::discardBindings()
 {
-    m_breakpoints.clear();
+    m_domBreakpoints.clear();
 }
 
 void InspectorBrowserDebuggerAgent::setEventListenerBreakpoint(const String& eventName)
@@ -88,8 +150,8 @@ void InspectorBrowserDebuggerAgent::removeEventListenerBreakpoint(const String&
 
 void InspectorBrowserDebuggerAgent::didInsertDOMNode(Node* node)
 {
-    if (m_breakpoints.size()) {
-        uint32_t mask = m_breakpoints.get(InspectorDOMAgent::innerParentNode(node));
+    if (m_domBreakpoints.size()) {
+        uint32_t mask = m_domBreakpoints.get(InspectorDOMAgent::innerParentNode(node));
         uint32_t inheritableTypesMask = (mask | (mask >> domBreakpointDerivedTypeShift)) & inheritableDOMBreakpointTypesMask;
         if (inheritableTypesMask)
             updateSubtreeBreakpoints(node, inheritableTypesMask, true);
@@ -98,16 +160,16 @@ void InspectorBrowserDebuggerAgent::didInsertDOMNode(Node* node)
 
 void InspectorBrowserDebuggerAgent::didRemoveDOMNode(Node* node)
 {
-    if (m_breakpoints.size()) {
+    if (m_domBreakpoints.size()) {
         // Remove subtree breakpoints.
-        m_breakpoints.remove(node);
+        m_domBreakpoints.remove(node);
         Vector<Node*> stack(1, InspectorDOMAgent::innerFirstChild(node));
         do {
             Node* node = stack.last();
             stack.removeLast();
             if (!node)
                 continue;
-            m_breakpoints.remove(node);
+            m_domBreakpoints.remove(node);
             stack.append(InspectorDOMAgent::innerFirstChild(node));
             stack.append(InspectorDOMAgent::innerNextSibling(node));
         } while (!stack.isEmpty());
@@ -121,7 +183,7 @@ void InspectorBrowserDebuggerAgent::setDOMBreakpoint(long nodeId, long type)
         return;
 
     uint32_t rootBit = 1 << type;
-    m_breakpoints.set(node, m_breakpoints.get(node) | rootBit);
+    m_domBreakpoints.set(node, m_domBreakpoints.get(node) | rootBit);
     if (rootBit & inheritableDOMBreakpointTypesMask) {
         for (Node* child = InspectorDOMAgent::innerFirstChild(node); child; child = InspectorDOMAgent::innerNextSibling(child))
             updateSubtreeBreakpoints(child, rootBit, true);
@@ -135,11 +197,11 @@ void InspectorBrowserDebuggerAgent::removeDOMBreakpoint(long nodeId, long type)
         return;
 
     uint32_t rootBit = 1 << type;
-    uint32_t mask = m_breakpoints.get(node) & ~rootBit;
+    uint32_t mask = m_domBreakpoints.get(node) & ~rootBit;
     if (mask)
-        m_breakpoints.set(node, mask);
+        m_domBreakpoints.set(node, mask);
     else
-        m_breakpoints.remove(node);
+        m_domBreakpoints.remove(node);
 
     if ((rootBit & inheritableDOMBreakpointTypesMask) && !(mask & (rootBit << domBreakpointDerivedTypeShift))) {
         for (Node* child = InspectorDOMAgent::innerFirstChild(node); child; child = InspectorDOMAgent::innerNextSibling(child))
@@ -210,7 +272,7 @@ void InspectorBrowserDebuggerAgent::descriptionForDOMEvent(Node* target, long br
         if (!insertion)
             breakpointOwner = InspectorDOMAgent::innerParentNode(target);
         ASSERT(breakpointOwner);
-        while (!(m_breakpoints.get(breakpointOwner) & (1 << breakpointType))) {
+        while (!(m_domBreakpoints.get(breakpointOwner) & (1 << breakpointType))) {
             breakpointOwner = InspectorDOMAgent::innerParentNode(breakpointOwner);
             ASSERT(breakpointOwner);
         }
@@ -229,18 +291,18 @@ bool InspectorBrowserDebuggerAgent::hasBreakpoint(Node* node, long type)
 {
     uint32_t rootBit = 1 << type;
     uint32_t derivedBit = rootBit << domBreakpointDerivedTypeShift;
-    return m_breakpoints.get(node) & (rootBit | derivedBit);
+    return m_domBreakpoints.get(node) & (rootBit | derivedBit);
 }
 
 void InspectorBrowserDebuggerAgent::updateSubtreeBreakpoints(Node* node, uint32_t rootMask, bool set)
 {
-    uint32_t oldMask = m_breakpoints.get(node);
+    uint32_t oldMask = m_domBreakpoints.get(node);
     uint32_t derivedMask = rootMask << domBreakpointDerivedTypeShift;
     uint32_t newMask = set ? oldMask | derivedMask : oldMask & ~derivedMask;
     if (newMask)
-        m_breakpoints.set(node, newMask);
+        m_domBreakpoints.set(node, newMask);
     else
-        m_breakpoints.remove(node);
+        m_domBreakpoints.remove(node);
 
     uint32_t newRootMask = rootMask & ~newMask;
     if (!newRootMask)
@@ -313,13 +375,6 @@ void InspectorBrowserDebuggerAgent::willSendXMLHttpRequest(const String& url)
     debuggerAgent->breakProgram(NativeBreakpointDebuggerEventType, eventData.release());
 }
 
-void InspectorBrowserDebuggerAgent::clearForPageNavigation()
-{
-    m_eventListenerBreakpoints.clear();
-    m_XHRBreakpoints.clear();
-    m_hasXHRBreakpointWithEmptyURL = false;
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR) && ENABLE(JAVASCRIPT_DEBUGGER)
index 6af31e8..0ffa85c 100644 (file)
@@ -46,6 +46,7 @@ namespace WebCore {
 class Element;
 class InspectorController;
 class InspectorObject;
+class KURL;
 class Node;
 
 class InspectorBrowserDebuggerAgent {
@@ -58,6 +59,8 @@ public:
 
     virtual ~InspectorBrowserDebuggerAgent();
 
+    void inspectedURLChanged(const KURL&);
+
     // BrowserDebugger API for InspectorFrontend
     void setXHRBreakpoint(const String& url);
     void removeXHRBreakpoint(const String& url);
@@ -75,17 +78,18 @@ public:
     void willSendXMLHttpRequest(const String& url);
     void pauseOnNativeEventIfNeeded(const String& categoryType, const String& eventName, bool synchronous);
 
-    void clearForPageNavigation();
 private:
     InspectorBrowserDebuggerAgent(InspectorController*);
 
+    void restoreStickyBreakpoint(PassRefPtr<InspectorObject> breakpoint);
+
     void descriptionForDOMEvent(Node* target, long breakpointType, bool insertion, InspectorObject* description);
     void updateSubtreeBreakpoints(Node*, uint32_t rootMask, bool set);
     bool hasBreakpoint(Node*, long type);
     void discardBindings();
 
     InspectorController* m_inspectorController;
-    HashMap<Node*, uint32_t> m_breakpoints;
+    HashMap<Node*, uint32_t> m_domBreakpoints;
     HashSet<String> m_eventListenerBreakpoints;
     HashSet<String> m_XHRBreakpoints;
     bool m_hasXHRBreakpointWithEmptyURL;
index 64b9494..fa747cc 100644 (file)
@@ -222,7 +222,7 @@ void InspectorController::restoreInspectorStateFromCookie(const String& inspecto
     if (!m_frontend) {
         connectFrontend();
         m_frontend->frontendReused();
-        m_frontend->inspectedURLChanged(m_inspectedPage->mainFrame()->loader()->url().string());
+        m_frontend->inspectedURLChanged(inspectedURL().string());
         m_domAgent->setDocument(m_inspectedPage->mainFrame()->document());
         pushDataCollectedOffline();
     }
@@ -399,7 +399,7 @@ void InspectorController::connectFrontend()
     m_consoleAgent->setFrontend(m_frontend.get());
 
     // Initialize Web Inspector title.
-    m_frontend->inspectedURLChanged(m_inspectedPage->mainFrame()->loader()->url().string());
+    m_frontend->inspectedURLChanged(inspectedURL().string());
 
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
     m_applicationCacheAgent = new InspectorApplicationCacheAgent(this, m_frontend.get());
@@ -643,8 +643,7 @@ void InspectorController::didCommitLoad(DocumentLoader* loader)
         if (m_debuggerAgent) {
             m_debuggerAgent->clearForPageNavigation();
             if (m_browserDebuggerAgent)
-                m_browserDebuggerAgent->clearForPageNavigation();
-            restoreStickyBreakpoints();
+                m_browserDebuggerAgent->inspectedURLChanged(inspectedURL());
         }
 #endif
 
@@ -1050,7 +1049,7 @@ void InspectorController::enableDebugger(bool always)
 
     m_debuggerAgent = InspectorDebuggerAgent::create(this, m_frontend.get());
     m_browserDebuggerAgent = InspectorBrowserDebuggerAgent::create(this);
-    restoreStickyBreakpoints();
+    m_browserDebuggerAgent->inspectedURLChanged(inspectedURL());
 
     m_frontend->debuggerWasEnabled();
 }
@@ -1080,67 +1079,9 @@ void InspectorController::resume()
         m_debuggerAgent->resume();
 }
 
-void InspectorController::setStickyBreakpoints(PassRefPtr<InspectorObject> breakpoints)
+void InspectorController::setAllBrowserBreakpoints(PassRefPtr<InspectorObject> breakpoints)
 {
-    m_state->setObject(InspectorState::stickyBreakpoints, breakpoints);
-}
-
-void InspectorController::restoreStickyBreakpoints()
-{
-    RefPtr<InspectorObject> allBreakpoints = m_state->getObject(InspectorState::stickyBreakpoints);
-    KURL url = m_inspectedPage->mainFrame()->loader()->url();
-    url.removeFragmentIdentifier();
-    RefPtr<InspectorArray> breakpoints = allBreakpoints->getArray(url);
-    if (!breakpoints)
-        return;
-    for (unsigned i = 0; i < breakpoints->length(); ++i)
-        restoreStickyBreakpoint(breakpoints->get(i)->asObject());
-}
-
-void InspectorController::restoreStickyBreakpoint(PassRefPtr<InspectorObject> breakpoint)
-{
-    DEFINE_STATIC_LOCAL(String, eventListenerBreakpointType, ("EventListener"));
-    DEFINE_STATIC_LOCAL(String, javaScriptBreakpointType, ("JS"));
-    DEFINE_STATIC_LOCAL(String, xhrBreakpointType, ("XHR"));
-
-    if (!breakpoint)
-        return;
-    String type;
-    if (!breakpoint->getString("type", &type))
-        return;
-    bool enabled;
-    if (!breakpoint->getBoolean("enabled", &enabled))
-        return;
-    RefPtr<InspectorObject> condition = breakpoint->getObject("condition");
-    if (!condition)
-        return;
-
-    if (type == eventListenerBreakpointType && m_browserDebuggerAgent) {
-        if (!enabled)
-            return;
-        String eventName;
-        if (!condition->getString("eventName", &eventName))
-            return;
-        m_browserDebuggerAgent->setEventListenerBreakpoint(eventName);
-    } else if (type == javaScriptBreakpointType && m_debuggerAgent) {
-        String url;
-        if (!condition->getString("url", &url))
-            return;
-        double lineNumber;
-        if (!condition->getNumber("lineNumber", &lineNumber))
-            return;
-        String javaScriptCondition;
-        if (!condition->getString("condition", &javaScriptCondition))
-            return;
-        m_debuggerAgent->setStickyBreakpoint(url, static_cast<unsigned>(lineNumber), javaScriptCondition, enabled);
-    } else if (type == xhrBreakpointType && m_browserDebuggerAgent) {
-        if (!enabled)
-            return;
-        String url;
-        if (!condition->getString("url", &url))
-            return;
-        m_browserDebuggerAgent->setXHRBreakpoint(url);
-    }
+    m_state->setObject(InspectorState::browserBreakpoints, breakpoints);
 }
 #endif
 
@@ -1441,6 +1382,11 @@ void InspectorController::setInspectorExtensionAPI(const String& source)
     m_inspectorExtensionAPI = source;
 }
 
+KURL InspectorController::inspectedURL() const
+{
+    return m_inspectedPage->mainFrame()->loader()->url();
+}
+
 void InspectorController::reloadPage()
 {
     // FIXME: Why do we set the user gesture indicator here?
index eaaa1e5..90a0300 100644 (file)
@@ -125,6 +125,7 @@ public:
     bool enabled() const;
 
     Page* inspectedPage() const { return m_inspectedPage; }
+    KURL inspectedURL() const;
     void reloadPage();
 
     void restoreInspectorStateFromCookie(const String& inspectorCookie);
@@ -242,7 +243,7 @@ public:
     bool debuggerEnabled() const { return m_debuggerAgent; }
     void resume();
 
-    void setStickyBreakpoints(PassRefPtr<InspectorObject> breakpoints);
+    void setAllBrowserBreakpoints(PassRefPtr<InspectorObject>);
 #endif
 
     // Generic code called from custom implementations.
@@ -287,8 +288,6 @@ private:
 
 #if ENABLE(JAVASCRIPT_DEBUGGER)
     void toggleRecordButton(bool);
-    void restoreStickyBreakpoints();
-    void restoreStickyBreakpoint(PassRefPtr<InspectorObject> breakpoint);
 #endif
 
     PassRefPtr<InspectorObject> buildObjectForCookie(const Cookie&);
index 22294a0..dba9e4d 100644 (file)
@@ -42,7 +42,7 @@ InspectorState::InspectorState(InspectorClient* client)
     registerBoolean(userInitiatedProfiling, false);
     registerBoolean(timelineProfilerEnabled, false);
     registerBoolean(searchingForNode, false);
-    registerObject(stickyBreakpoints);
+    registerObject(browserBreakpoints);
     registerBoolean(consoleMessagesEnabled, false);
     registerBoolean(monitoringXHR, false);
     registerBoolean(resourceAgentEnabled, false);
index b62f8de..6e12673 100644 (file)
@@ -49,7 +49,7 @@ public:
         searchingForNode,
         consoleMessagesEnabled,
         userInitiatedProfiling,
-        stickyBreakpoints,
+        browserBreakpoints,
         resourceAgentEnabled,
         lastPropertyId
     };
index 67ef112..d943d5b 100644 (file)
@@ -34,7 +34,7 @@ WebInspector.BreakpointManager = function()
     var breakpoints = WebInspector.settings.findSettingForAllProjects("nativeBreakpoints");
     for (var projectId in breakpoints)
         this._stickyBreakpoints[projectId] = this._validateBreakpoints(breakpoints[projectId]);
-    InspectorBackend.setStickyBreakpoints(this._stickyBreakpoints);
+    InspectorBackend.setAllBrowserBreakpoints(this._stickyBreakpoints);
 
     this._breakpoints = {};
     this._domBreakpointsRestored = false;
@@ -303,7 +303,7 @@ WebInspector.BreakpointManager.prototype = {
         WebInspector.settings.nativeBreakpoints = breakpoints;
 
         this._stickyBreakpoints[WebInspector.settings.projectId] = breakpoints;
-        InspectorBackend.setStickyBreakpoints(this._stickyBreakpoints);
+        InspectorBackend.setAllBrowserBreakpoints(this._stickyBreakpoints);
     },
 
     _validateBreakpoints: function(persistentBreakpoints)