[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da

podivilov at chromium.org podivilov at chromium.org
Wed Dec 22 18:10:13 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 19ede04bb76aec0242bbbdf0a7b3fe444fb3b1c4
Author: podivilov at chromium.org <podivilov at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Dec 8 10:44:20 2010 +0000

    2010-12-08  Pavel Podivilov  <podivilov at chromium.org>
    
            Reviewed by Pavel Feldman.
    
            Web Inspector: SourceFrame refactoring.
            https://bugs.webkit.org/show_bug.cgi?id=50223
    
            * inspector/debugger-breakpoints-not-activated-on-reload.html:
            * inspector/debugger-pause-on-breakpoint.html:
    2010-12-08  Pavel Podivilov  <podivilov at chromium.org>
    
            Reviewed by Pavel Feldman.
    
            Web Inspector: SourceFrame refactoring.
            https://bugs.webkit.org/show_bug.cgi?id=50223
    
            SourceFrame should ask BreakpointManager about existing breakpoints instead of maintaining
            it's own storages. Move common code from ScriptView and SourceView to SourceFrame.
    
            * inspector/front-end/BreakpointManager.js:
            (WebInspector.BreakpointManager.prototype.findBreakpoints):
            (WebInspector.BreakpointManager.prototype.findBreakpoint):
            * inspector/front-end/Script.js:
            (WebInspector.Script):
            (WebInspector.Script.prototype.get linesCount):
            (WebInspector.Script.prototype.get source):
            (WebInspector.Script.prototype.set source):
            * inspector/front-end/ScriptView.js:
            (WebInspector.ScriptView):
            (WebInspector.ScriptView.prototype._scriptSourceChanged):
            (WebInspector.ScriptFrameDelegateImpl):
            (WebInspector.ScriptFrameDelegateImpl.prototype.canEditScripts):
            (WebInspector.ScriptFrameDelegateImpl.prototype.editLineComplete):
            (WebInspector.ScriptFrameDelegateImpl.prototype.scripts):
            * inspector/front-end/ScriptsPanel.js:
            (WebInspector.ScriptsPanel):
            * inspector/front-end/SourceFrame.js:
            (WebInspector.SourceFrame): Add common methods of ScriptView and SourceView.
            (WebInspector.SourceFrameDelegate):
            (WebInspector.SourceFrameDelegate.prototype.canEditScripts):
            (WebInspector.SourceFrameDelegate.prototype.editLineComplete):
            (WebInspector.SourceFrameDelegate.prototype.scripts):
            * inspector/front-end/SourceView.js:
            (WebInspector.SourceView):
            (WebInspector.SourceView.prototype._contentLoaded):
            (WebInspector.ResourceFrameDelegateImpl):
            (WebInspector.ResourceFrameDelegateImpl.prototype.canEditScripts):
            (WebInspector.ResourceFrameDelegateImpl.prototype.editLineComplete):
            (WebInspector.ResourceFrameDelegateImpl.prototype.scripts):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73499 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index e52c0d3..a207d07 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
+2010-12-08  Pavel Podivilov  <podivilov at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: SourceFrame refactoring.
+        https://bugs.webkit.org/show_bug.cgi?id=50223
+
+        * inspector/debugger-breakpoints-not-activated-on-reload.html:
+        * inspector/debugger-pause-on-breakpoint.html:
+
 2010-12-08  Philippe Normand  <pnormand at igalia.com>
 
         Unreviewed, unskipping media/video-controls-rendering.html on GTK.
diff --git a/LayoutTests/inspector/debugger-breakpoints-not-activated-on-reload.html b/LayoutTests/inspector/debugger-breakpoints-not-activated-on-reload.html
index c06664d..fc2c926 100644
--- a/LayoutTests/inspector/debugger-breakpoints-not-activated-on-reload.html
+++ b/LayoutTests/inspector/debugger-breakpoints-not-activated-on-reload.html
@@ -24,7 +24,7 @@ var test = function()
     function step2()
     {
         InspectorTest.addResult("Main resource was shown.");
-        WebInspector.panels.scripts.visibleView._addBreakpoint(8);
+        WebInspector.panels.scripts.visibleView.sourceFrame._setBreakpoint(8);
         WebInspector.panels.scripts.toggleBreakpointsButton.element.click();
         InspectorTest.reloadPage(step3);
     }
diff --git a/LayoutTests/inspector/debugger-pause-on-breakpoint.html b/LayoutTests/inspector/debugger-pause-on-breakpoint.html
index 8398d59..4831d42 100644
--- a/LayoutTests/inspector/debugger-pause-on-breakpoint.html
+++ b/LayoutTests/inspector/debugger-pause-on-breakpoint.html
@@ -22,7 +22,7 @@ var test = function()
     function step2()
     {
         InspectorTest.addResult("Script source was shown.");
-        WebInspector.panels.scripts.visibleView._addBreakpoint(9);
+        WebInspector.panels.scripts.visibleView.sourceFrame._setBreakpoint(9);
         InspectorTest.runTestFunctionAndWaitUntilPaused(step3);
     }
 
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 8cec9aa..d0247d1 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,44 @@
+2010-12-08  Pavel Podivilov  <podivilov at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: SourceFrame refactoring.
+        https://bugs.webkit.org/show_bug.cgi?id=50223
+
+        SourceFrame should ask BreakpointManager about existing breakpoints instead of maintaining
+        it's own storages. Move common code from ScriptView and SourceView to SourceFrame.
+
+        * inspector/front-end/BreakpointManager.js:
+        (WebInspector.BreakpointManager.prototype.findBreakpoints):
+        (WebInspector.BreakpointManager.prototype.findBreakpoint):
+        * inspector/front-end/Script.js:
+        (WebInspector.Script):
+        (WebInspector.Script.prototype.get linesCount):
+        (WebInspector.Script.prototype.get source):
+        (WebInspector.Script.prototype.set source):
+        * inspector/front-end/ScriptView.js:
+        (WebInspector.ScriptView):
+        (WebInspector.ScriptView.prototype._scriptSourceChanged):
+        (WebInspector.ScriptFrameDelegateImpl):
+        (WebInspector.ScriptFrameDelegateImpl.prototype.canEditScripts):
+        (WebInspector.ScriptFrameDelegateImpl.prototype.editLineComplete):
+        (WebInspector.ScriptFrameDelegateImpl.prototype.scripts):
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame): Add common methods of ScriptView and SourceView.
+        (WebInspector.SourceFrameDelegate):
+        (WebInspector.SourceFrameDelegate.prototype.canEditScripts):
+        (WebInspector.SourceFrameDelegate.prototype.editLineComplete):
+        (WebInspector.SourceFrameDelegate.prototype.scripts):
+        * inspector/front-end/SourceView.js:
+        (WebInspector.SourceView):
+        (WebInspector.SourceView.prototype._contentLoaded):
+        (WebInspector.ResourceFrameDelegateImpl):
+        (WebInspector.ResourceFrameDelegateImpl.prototype.canEditScripts):
+        (WebInspector.ResourceFrameDelegateImpl.prototype.editLineComplete):
+        (WebInspector.ResourceFrameDelegateImpl.prototype.scripts):
+
 2010-12-08  Yuta Kitamura  <yutak at chromium.org>
 
         Unreviewed, rolling out r73492.
diff --git a/WebCore/inspector/front-end/BreakpointManager.js b/WebCore/inspector/front-end/BreakpointManager.js
index 3d51092..f712367 100644
--- a/WebCore/inspector/front-end/BreakpointManager.js
+++ b/WebCore/inspector/front-end/BreakpointManager.js
@@ -63,24 +63,21 @@ WebInspector.BreakpointManager.prototype = {
         this._setBreakpoint(sourceID, url, line, enabled, condition);
     },
 
-    breakpointsForSourceID: function(sourceID)
+    findBreakpoints: function(filter)
     {
         var breakpoints = [];
         for (var id in this._breakpoints) {
-            if (this._breakpoints[id].sourceID === sourceID)
-                breakpoints.push(this._breakpoints[id]);
+           var breakpoint = this._breakpoints[id];
+           if (filter(breakpoint))
+               breakpoints.push(breakpoint);
         }
         return breakpoints;
     },
 
-    breakpointsForURL: function(url)
+    findBreakpoint: function(sourceID, lineNumber)
     {
-        var breakpoints = [];
-        for (var id in this._breakpoints) {
-            if (this._breakpoints[id].url === url)
-                breakpoints.push(this._breakpoints[id]);
-        }
-        return breakpoints;
+        var breakpointId = WebInspector.Breakpoint.jsBreakpointId(sourceID, lineNumber);
+        return this._breakpoints[breakpointId];
     },
 
     reset: function()
diff --git a/WebCore/inspector/front-end/Script.js b/WebCore/inspector/front-end/Script.js
index be3f020..ce14a59 100644
--- a/WebCore/inspector/front-end/Script.js
+++ b/WebCore/inspector/front-end/Script.js
@@ -27,7 +27,7 @@ WebInspector.Script = function(sourceID, sourceURL, source, startingLine, errorL
 {
     this.sourceID = sourceID;
     this.sourceURL = sourceURL;
-    this.source = source;
+    this._source = source;
     this.startingLine = startingLine;
     this.errorLine = errorLine;
     this.errorMessage = errorMessage;
@@ -57,6 +57,10 @@ WebInspector.Script.WorldType = {
     EXTENSIONS_WORLD: 1
 }
 
+WebInspector.Script.Events = {
+    SourceChanged: "source-changed"
+}
+
 WebInspector.Script.prototype = {
     get linesCount()
     {
@@ -71,5 +75,19 @@ WebInspector.Script.prototype = {
             this._linesCount++;
         }
         return this._linesCount;
+    },
+
+    get source()
+    {
+        return this._source;
+    },
+
+    set source(source)
+    {
+        this._source = source;
+        this.dispatchEventToListeners(WebInspector.Script.Events.SourceChanged);
     }
 }
+
+WebInspector.Script.prototype.__proto__ = WebInspector.Object.prototype;
+
diff --git a/WebCore/inspector/front-end/ScriptView.js b/WebCore/inspector/front-end/ScriptView.js
index d878e9b..1962fdf 100644
--- a/WebCore/inspector/front-end/ScriptView.js
+++ b/WebCore/inspector/front-end/ScriptView.js
@@ -33,8 +33,10 @@ WebInspector.ScriptView = function(script)
 
     this._frameNeedsSetup = true;
     this._sourceFrameSetup = false;
-    var canEditScripts = WebInspector.panels.scripts.canEditScripts();
-    this.sourceFrame = new WebInspector.SourceFrame(this.element, this._addBreakpoint.bind(this), canEditScripts ? this._editLine.bind(this) : null, this._continueToLine.bind(this));
+    var delegate = new WebInspector.ScriptFrameDelegateImpl(this.script);
+    this.sourceFrame = new WebInspector.SourceFrame(this.element, delegate);
+
+    this.script.addEventListener(WebInspector.Script.Events.SourceChanged, this._scriptSourceChanged, this);
 }
 
 WebInspector.ScriptView.prototype = {
@@ -85,29 +87,9 @@ WebInspector.ScriptView.prototype = {
             document.getElementById("script-resource-views").appendChild(this.element);
     },
 
-    _continueToLine: function(line)
-    {
-        var scriptsPanel = WebInspector.panels.scripts;
-        if (scriptsPanel)
-            scriptsPanel.continueToLine(this.script.sourceID, line);
-    },
-
-    _addBreakpoint: function(line)
+    _scriptSourceChanged: function(event)
     {
-        WebInspector.breakpointManager.setBreakpoint(this.script.sourceID, this.script.sourceURL, line, true, "");
-        if (!WebInspector.panels.scripts.breakpointsActivated)
-            WebInspector.panels.scripts.toggleBreakpointsClicked();
-    },
-
-    _editLineComplete: function(newBody)
-    {
-        this.script.source = newBody;
-        this.sourceFrame.updateContent(this._prependWhitespace(newBody));
-    },
-
-    _sourceIDForLine: function(line)
-    {
-        return this.script.sourceID;
+        this.sourceFrame.updateContent(this._prependWhitespace(this.script.source));
     },
 
     // The following methods are pulled from SourceView, since they are
@@ -127,9 +109,32 @@ WebInspector.ScriptView.prototype = {
     showingFirstSearchResult: WebInspector.SourceView.prototype.showingFirstSearchResult,
     showingLastSearchResult: WebInspector.SourceView.prototype.showingLastSearchResult,
     _jumpToSearchResult: WebInspector.SourceView.prototype._jumpToSearchResult,
-    _editLine: WebInspector.SourceView.prototype._editLine,
     resize: WebInspector.SourceView.prototype.resize
 }
 
 WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
 
+WebInspector.ScriptFrameDelegateImpl = function(script)
+{
+    WebInspector.SourceFrameDelegate.call(this);
+    this._script = script;
+}
+
+WebInspector.ScriptFrameDelegateImpl.prototype = {
+    canEditScripts: function()
+    {
+        return WebInspector.panels.scripts.canEditScripts();
+    },
+
+    editLineComplete: function(revertEditLineCallback, newContent)
+    {
+        this._script.source = newContent;
+    },
+
+    scripts: function()
+    {
+        return [this._script];
+    }
+}
+
+WebInspector.ScriptFrameDelegateImpl.prototype.__proto__ = WebInspector.SourceFrameDelegate.prototype;
diff --git a/WebCore/inspector/front-end/ScriptsPanel.js b/WebCore/inspector/front-end/ScriptsPanel.js
index 61a2f28..9465702 100644
--- a/WebCore/inspector/front-end/ScriptsPanel.js
+++ b/WebCore/inspector/front-end/ScriptsPanel.js
@@ -175,8 +175,6 @@ WebInspector.ScriptsPanel = function()
 
     this._debuggerEnabled = Preferences.debuggerAlwaysEnabled;
 
-    WebInspector.breakpointManager.addEventListener("breakpoint-added", this._breakpointAdded, this);
-
     this.reset();
 }
 
@@ -281,26 +279,6 @@ WebInspector.ScriptsPanel.prototype = {
         delete resource._scriptsPendingResourceLoad;
     },
 
-    _breakpointAdded: function(event)
-    {
-        var breakpoint = event.data;
-
-        var sourceFrame;
-        if (breakpoint.url) {
-            var resource = WebInspector.resourceForURL(breakpoint.url);
-            if (resource && resource.finished)
-                sourceFrame = this._sourceFrameForScriptOrResource(resource);
-        }
-
-        if (breakpoint.sourceID && !sourceFrame) {
-            var object = this._sourceIDMap[breakpoint.sourceID]
-            sourceFrame = this._sourceFrameForScriptOrResource(object);
-        }
-
-        if (sourceFrame)
-            sourceFrame.addBreakpoint(breakpoint);
-    },
-
     canEditScripts: function()
     {
         return Preferences.canEditScriptSource;
@@ -312,7 +290,7 @@ WebInspector.ScriptsPanel.prototype = {
             return;
 
         // Need to clear breakpoints and re-create them later when editing source.
-        var breakpoints = WebInspector.breakpointManager.breakpointsForSourceID(sourceID);
+        var breakpoints = WebInspector.breakpointManager.findBreakpoints(function(b) { return b.sourceID === editData.sourceID });
         for (var i = 0; i < breakpoints.length; ++i)
             breakpoints[i].remove();
 
@@ -1092,4 +1070,3 @@ WebInspector.ScriptsPanel.prototype = {
 }
 
 WebInspector.ScriptsPanel.prototype.__proto__ = WebInspector.Panel.prototype;
-
diff --git a/WebCore/inspector/front-end/SourceFrame.js b/WebCore/inspector/front-end/SourceFrame.js
index 8e077cd..29fdc1f 100644
--- a/WebCore/inspector/front-end/SourceFrame.js
+++ b/WebCore/inspector/front-end/SourceFrame.js
@@ -28,9 +28,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.SourceFrame = function(parentElement, addBreakpointDelegate, editDelegate, continueToHereDelegate)
+WebInspector.SourceFrame = function(parentElement, delegate)
 {
     this._parentElement = parentElement;
+    this._delegate = delegate;
 
     this._textModel = new WebInspector.TextEditorModel();
     this._textModel.replaceTabsWithSpaces = true;
@@ -38,13 +39,8 @@ WebInspector.SourceFrame = function(parentElement, addBreakpointDelegate, editDe
     this._messages = [];
     this._rowMessages = {};
     this._messageBubbles = {};
-    this.breakpoints = [];
 
     this._loaded = false;
-
-    this._continueToHereDelegate = continueToHereDelegate;
-    this._addBreakpointDelegate = addBreakpointDelegate;
-    this._editDelegate = editDelegate;
     this._popoverObjectGroup = "popover";
 }
 
@@ -105,23 +101,6 @@ WebInspector.SourceFrame.prototype = {
             this._lineNumberToReveal = lineNumber;
     },
 
-    addBreakpoint: function(breakpoint)
-    {
-        this.breakpoints.push(breakpoint);
-        breakpoint.addEventListener("removed", this._breakpointRemoved, this);
-        if (this._textViewer)
-            this._addBreakpointToSource(breakpoint);
-    },
-
-    _breakpointRemoved: function(event)
-    {
-        var breakpoint = event.target;
-
-        this.breakpoints.remove(breakpoint);
-        if (this._textViewer)
-            this._removeBreakpointFromSource(breakpoint);
-    },
-
     addMessage: function(msg)
     {
         // Don't add the message if there is no message or valid line or if the msg isn't an error or warning.
@@ -211,14 +190,10 @@ WebInspector.SourceFrame.prototype = {
         element.addEventListener("scroll", this._scroll.bind(this), true);
         this._parentElement.appendChild(element);
 
-        this._needsProgramCounterImage = true;
-        this._needsBreakpointImages = true;
-
         this._textViewer.beginUpdates();
 
         this._textViewer.mimeType = this._mimeType;
         this._addExistingMessagesToSource();
-        this._addExistingBreakpointsToSource();
         this._updateExecutionLine();
         this._updateDiffDecorations();
         this._textViewer.resize();
@@ -238,9 +213,16 @@ WebInspector.SourceFrame.prototype = {
             this.highlightLine(this._lineToHighlight);
             delete this._lineToHighlight;
         }
+
+        var breakpoints = this._breakpoints();
+        for (var i = 0; i < breakpoints.length; ++i)
+            this._addBreakpoint(breakpoints[i]);
+        WebInspector.breakpointManager.addEventListener("breakpoint-added", this._breakpointAdded, this);
+
         this._textViewer.endUpdates();
-        if (this._editDelegate)
-            this._textViewer.editCallback = this._editDelegate;
+
+        if (this._delegate.canEditScripts())
+            this._textViewer.editCallback = this._editLine.bind(this);
     },
 
     findSearchMatches: function(query)
@@ -429,23 +411,25 @@ WebInspector.SourceFrame.prototype = {
         msg._resourceMessageLineElement = messageLineElement;
     },
 
-    _addExistingBreakpointsToSource: function()
+    _breakpointAdded: function(event)
     {
-        for (var i = 0; i < this.breakpoints.length; ++i)
-            this._addBreakpointToSource(this.breakpoints[i]);
+        var breakpoint = event.data;
+
+        if (this._shouldDisplayBreakpoint(breakpoint))
+            this._addBreakpoint(breakpoint);
     },
 
-    _addBreakpointToSource: function(breakpoint)
+    _addBreakpoint: function(breakpoint)
     {
-        breakpoint.addEventListener("enable-changed", this._breakpointChanged, this);
-        breakpoint.addEventListener("condition-changed", this._breakpointChanged, this);
-
         var lineNumber = breakpoint.line - 1;
         if (lineNumber >= this._textModel.linesCount)
             return;
 
-        this._textModel.setAttribute(lineNumber, "breakpoint", breakpoint);
-        breakpoint.sourceText = this._textModel.line(breakpoint.line - 1);
+        breakpoint.addEventListener("enable-changed", this._breakpointChanged, this);
+        breakpoint.addEventListener("condition-changed", this._breakpointChanged, this);
+        breakpoint.addEventListener("removed", this._breakpointRemoved, this);
+
+        breakpoint.sourceText = this._textModel.line(lineNumber);
 
         this._textViewer.beginUpdates();
         this._textViewer.addDecoration(lineNumber, "webkit-breakpoint");
@@ -456,14 +440,16 @@ WebInspector.SourceFrame.prototype = {
         this._textViewer.endUpdates();
     },
 
-    _removeBreakpointFromSource: function(breakpoint)
+    _breakpointRemoved: function(event)
     {
+        var breakpoint = event.target;
+
         breakpoint.removeEventListener("enable-changed", null, this);
         breakpoint.removeEventListener("condition-changed", null, this);
+        breakpoint.removeEventListener("removed", null, this);
 
         var lineNumber = breakpoint.line - 1;
         this._textViewer.beginUpdates();
-        this._textModel.removeAttribute(lineNumber, "breakpoint");
         this._textViewer.removeDecoration(lineNumber, "webkit-breakpoint");
         this._textViewer.removeDecoration(lineNumber, "webkit-breakpoint-disabled");
         this._textViewer.removeDecoration(lineNumber, "webkit-breakpoint-conditional");
@@ -472,28 +458,27 @@ WebInspector.SourceFrame.prototype = {
 
     _contextMenu: function(event)
     {
-        var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
-        if (!target)
+        if (!WebInspector.panels.scripts)
             return;
-        var row = target.parentElement;
 
-        if (!WebInspector.panels.scripts)
+        var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
+        if (!target)
             return;
+        var lineNumber = target.parentElement.lineNumber + 1;
 
-        var lineNumber = row.lineNumber;
         var contextMenu = new WebInspector.ContextMenu();
 
-        contextMenu.appendItem(WebInspector.UIString("Continue to Here"), this._continueToHereDelegate.bind(this, lineNumber + 1));
+        contextMenu.appendItem(WebInspector.UIString("Continue to Here"), this._continueToLine.bind(this, lineNumber));
 
-        var breakpoint = this._textModel.getAttribute(lineNumber, "breakpoint");
+        var breakpoint = this._findBreakpoint(lineNumber);
         if (!breakpoint) {
             // This row doesn't have a breakpoint: We want to show Add Breakpoint and Add and Edit Breakpoint.
-            contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._addBreakpointDelegate.bind(this, lineNumber + 1));
+            contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._setBreakpoint.bind(this, lineNumber));
 
             function addConditionalBreakpoint()
             {
-                this._addBreakpointDelegate(lineNumber + 1);
-                var breakpoint = this._textModel.getAttribute(lineNumber, "breakpoint");
+                this._setBreakpoint(lineNumber);
+                var breakpoint = this._findBreakpoint(lineNumber);
                 if (breakpoint)
                     this._editBreakpointCondition(breakpoint);
             }
@@ -525,18 +510,16 @@ WebInspector.SourceFrame.prototype = {
         var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
         if (!target)
             return;
-        var row = target.parentElement;
-
-        var lineNumber = row.lineNumber;
+        var lineNumber = target.parentElement.lineNumber + 1;
 
-        var breakpoint = this._textModel.getAttribute(lineNumber, "breakpoint");
+        var breakpoint = this._findBreakpoint(lineNumber);
         if (breakpoint) {
             if (event.shiftKey)
                 breakpoint.enabled = !breakpoint.enabled;
             else
                 breakpoint.remove();
         } else
-            this._addBreakpointDelegate(lineNumber + 1);
+            this._setBreakpoint(lineNumber);
         event.preventDefault();
     },
 
@@ -773,8 +756,123 @@ WebInspector.SourceFrame.prototype = {
     {
         if (this._textViewer)
             this._textViewer.resize();
+    },
+
+    _continueToLine: function(lineNumber)
+    {
+        var sourceID = this._sourceIDForLine(lineNumber);
+        WebInspector.panels.scripts.continueToLine(sourceID, lineNumber);
+    },
+
+    _editLine: function(lineNumber, newContent, cancelEditingCallback)
+    {
+        lineNumber += 1;
+
+        var lines = [];
+        for (var i = 0; i < this._textModel.linesCount; ++i) {
+            if (i === lineNumber - 1)
+                lines.push(newContent);
+            else
+                lines.push(this._textModel.line(i));
+        }
+
+        var editData = {};
+        editData.sourceID = this._sourceIDForLine(lineNumber);
+        editData.content = lines.join("\n");
+        editData.line = lineNumber;
+        editData.linesCountToShift = newContent.split("\n").length - 1;
+        this._doEditLine(editData, cancelEditingCallback);
+    },
+
+    _revertEditLine: function(editData, contentToRevertTo)
+    {
+        var newEditData = {};
+        newEditData.sourceID = editData.sourceID;
+        newEditData.content = contentToRevertTo;
+        newEditData.line = editData.line;
+        newEditData.linesCountToShift = -editData.linesCountToShift;
+        this._doEditLine(newEditData);
+    },
+
+    _doEditLine: function(editData, cancelEditingCallback)
+    {
+        var revertEditingCallback = this._revertEditLine.bind(this, editData);
+        var commitEditingCallback = this._delegate.editLineComplete.bind(this._delegate, revertEditingCallback);
+        WebInspector.panels.scripts.editScriptSource(editData, commitEditingCallback, cancelEditingCallback);
+    },
+
+    _setBreakpoint: function(lineNumber)
+    {
+        var sourceID = this._sourceIDForLine(lineNumber);
+        WebInspector.breakpointManager.setBreakpoint(sourceID, this._url, lineNumber, true, "");
+        if (!WebInspector.panels.scripts.breakpointsActivated)
+            WebInspector.panels.scripts.toggleBreakpointsClicked();
+    },
+
+    _breakpoints: function()
+    {
+        var sourceIDs = {};
+        var scripts = this._delegate.scripts();
+        for (var i = 0; i < scripts.length; ++i)
+            sourceIDs[scripts[i].sourceID] = true;
+        function filter(breakpoint)
+        {
+            return breakpoint.sourceID in sourceIDs;
+        }
+        return WebInspector.breakpointManager.findBreakpoints(filter);
+    },
+
+    _findBreakpoint: function(lineNumber)
+    {
+        var sourceID = this._sourceIDForLine(lineNumber);
+        return WebInspector.breakpointManager.findBreakpoint(sourceID, lineNumber);
+    },
+
+    _shouldDisplayBreakpoint: function(breakpoint)
+    {
+        var scripts = this._delegate.scripts();
+        for (var i = 0; i < scripts.length; ++i) {
+            if (breakpoint.sourceID === scripts[i].sourceID)
+                return true;
+        }
+        return false;
+    },
+
+    _sourceIDForLine: function(lineNumber)
+    {
+        var sourceID = null;
+        var scripts = this._delegate.scripts();
+        var closestStartingLine = 0;
+        for (var i = 0; i < scripts.length; ++i) {
+            var script = scripts[i];
+            if (script.startingLine <= lineNumber && script.startingLine >= closestStartingLine) {
+                closestStartingLine = script.startingLine;
+                sourceID = script.sourceID;
+            }
+        }
+        return sourceID;
     }
 }
 
-
 WebInspector.SourceFrame.prototype.__proto__ = WebInspector.Object.prototype;
+
+WebInspector.SourceFrameDelegate = function()
+{
+}
+
+WebInspector.SourceFrameDelegate.prototype = {
+    canEditScripts: function()
+    {
+        // Implemented by subclasses.
+    },
+
+    editLineComplete: function(revertEditLineCallback, newContent)
+    {
+        // Implemented by subclasses.
+    },
+
+    scripts: function()
+    {
+        // Implemented by subclasses.
+    }
+}
diff --git a/WebCore/inspector/front-end/SourceView.js b/WebCore/inspector/front-end/SourceView.js
index 9616321..8ccadd3 100644
--- a/WebCore/inspector/front-end/SourceView.js
+++ b/WebCore/inspector/front-end/SourceView.js
@@ -32,8 +32,8 @@ WebInspector.SourceView = function(resource)
 
     this.element.addStyleClass("source");
 
-    var canEditScripts = WebInspector.panels.scripts && WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
-    this.sourceFrame = new WebInspector.SourceFrame(this.element, this._addBreakpoint.bind(this), canEditScripts ? this._editLine.bind(this) : null, this._continueToLine.bind(this));
+    var delegate = new WebInspector.ResourceFrameDelegateImpl(this.resource);
+    this.sourceFrame = new WebInspector.SourceFrame(this.element, delegate);
     resource.addEventListener("finished", this._resourceLoadingFinished, this);
     this._frameNeedsSetup = true;
 }
@@ -100,9 +100,6 @@ WebInspector.SourceView.prototype = {
         var mimeType = this._canonicalMimeType(this.resource);
         this.sourceFrame.setContent(mimeType, content, this.resource.url);
         this._sourceFrameSetupFinished();
-        var breakpoints = WebInspector.breakpointManager.breakpointsForURL(this.resource.url);
-        for (var i = 0; i < breakpoints.length; ++i)
-            this.sourceFrame.addBreakpoint(breakpoints[i]);
     },
 
     _canonicalMimeType: function(resource)
@@ -119,73 +116,6 @@ WebInspector.SourceView.prototype = {
         this.resource.removeEventListener("finished", this._resourceLoadingFinished, this);
     },
 
-    _continueToLine: function(line)
-    {
-        var scriptsPanel = WebInspector.panels.scripts;
-        if (scriptsPanel) {
-            var sourceID = this._sourceIDForLine(line);
-            scriptsPanel.continueToLine(sourceID, line);
-        }
-    },
-
-    _addBreakpoint: function(line)
-    {
-        var sourceID = this._sourceIDForLine(line);
-        WebInspector.breakpointManager.setBreakpoint(sourceID, this.resource.url, line, true, "");
-        if (!WebInspector.panels.scripts.breakpointsActivated)
-            WebInspector.panels.scripts.toggleBreakpointsClicked();
-    },
-
-    _editLine: function(line, newContent, cancelEditingCallback)
-    {
-        var lines = [];
-        var textModel = this.sourceFrame.textModel;
-        for (var i = 0; i < textModel.linesCount; ++i) {
-            if (i === line)
-                lines.push(newContent);
-            else
-                lines.push(textModel.line(i));
-        }
-
-        var editData = {};
-        editData.sourceID = this._sourceIDForLine(line);
-        editData.content = lines.join("\n");
-        editData.line = line;
-        editData.linesCountToShift = newContent.split("\n").length - 1;
-
-        WebInspector.panels.scripts.editScriptSource(editData, this._editLineComplete.bind(this, editData), cancelEditingCallback);
-    },
-
-    _editLineComplete: function(editData, newContent)
-    {
-        this.resource.setContent(newContent, this._revertEditLine.bind(this, editData));
-    },
-
-    _revertEditLine: function(editData, contentToRevertTo)
-    {
-        var newEditData = {};
-        newEditData.sourceID = editData.sourceID;
-        newEditData.content = editData.content;
-        newEditData.line = editData.line;
-        newEditData.linesCountToShift = -editData.linesCountToShift;
-        WebInspector.panels.scripts.editScriptSource(newEditData, this._editLineComplete.bind(this, newEditData));
-    },
-
-    _sourceIDForLine: function(line)
-    {
-        var sourceID = null;
-        var closestStartingLine = 0;
-        var scripts = this.resource.scripts;
-        for (var i = 0; i < scripts.length; ++i) {
-            var script = scripts[i];
-            if (script.startingLine <= line && script.startingLine >= closestStartingLine) {
-                closestStartingLine = script.startingLine;
-                sourceID = script.sourceID;
-            }
-        }
-        return sourceID;
-    },
-
     // The rest of the methods in this prototype need to be generic enough to work with a ScriptView.
     // The ScriptView prototype pulls these methods into it's prototype to avoid duplicate code.
 
@@ -308,3 +238,28 @@ WebInspector.SourceView.prototype = {
 }
 
 WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
+
+WebInspector.ResourceFrameDelegateImpl = function(resource)
+{
+    WebInspector.SourceFrameDelegate.call(this);
+    this._resource = resource;
+}
+
+WebInspector.ResourceFrameDelegateImpl.prototype = {
+    canEditScripts: function()
+    {
+        return WebInspector.panels.scripts.canEditScripts() && this._resource.type === WebInspector.Resource.Type.Script;
+    },
+
+    editLineComplete: function(revertEditLineCallback, newContent)
+    {
+        this._resource.setContent(newContent, revertEditLineCallback);
+    },
+
+    scripts: function()
+    {
+        return this._resource.scripts;
+    }
+}
+
+WebInspector.ResourceFrameDelegateImpl.prototype.__proto__ = WebInspector.SourceFrameDelegate.prototype;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list