Web Inspector: do not map scripts generated with document.write to the document resou...
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Nov 2011 16:28:29 +0000 (16:28 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Nov 2011 16:28:29 +0000 (16:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71114

Reviewed by Yury Semikhatsky.

* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.DebuggerPresentationModel):
(WebInspector.DebuggerPresentationModel.prototype._addScript):
(WebInspector.DebuggerPresentationModel.prototype._bindScriptToRawSourceCode):
(WebInspector.DebuggerPresentationModel.prototype.uiSourceCodes):
(WebInspector.DebuggerPresentationModel.prototype.setFormatSource):
(WebInspector.DebuggerPresentationModel.prototype._consoleCleared):
(WebInspector.DebuggerPresentationModel.prototype._rawSourceCodeForScriptWithURL):
(WebInspector.DebuggerPresentationModel.prototype._rawSourceCodeForScript):
(WebInspector.DebuggerPresentationModel.prototype._scriptForRawSourceCode):
(WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
(WebInspector.DebuggerPresentationModel.Linkifier.prototype.reset):
* inspector/front-end/RawSourceCode.js:
(WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent.didFormatContent):
(WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
(WebInspector.RawSourceCode.prototype._createSourceMapping):
* inspector/front-end/Script.js:
(WebInspector.Script.prototype.editSource):
(WebInspector.Script.prototype.isInlineScript):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/DebuggerPresentationModel.js
Source/WebCore/inspector/front-end/RawSourceCode.js
Source/WebCore/inspector/front-end/Script.js

index 1cc398f..d618516 100644 (file)
@@ -1,3 +1,30 @@
+2011-11-03  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: do not map scripts generated with document.write to the document resources.
+        https://bugs.webkit.org/show_bug.cgi?id=71114
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/front-end/DebuggerPresentationModel.js:
+        (WebInspector.DebuggerPresentationModel):
+        (WebInspector.DebuggerPresentationModel.prototype._addScript):
+        (WebInspector.DebuggerPresentationModel.prototype._bindScriptToRawSourceCode):
+        (WebInspector.DebuggerPresentationModel.prototype.uiSourceCodes):
+        (WebInspector.DebuggerPresentationModel.prototype.setFormatSource):
+        (WebInspector.DebuggerPresentationModel.prototype._consoleCleared):
+        (WebInspector.DebuggerPresentationModel.prototype._rawSourceCodeForScriptWithURL):
+        (WebInspector.DebuggerPresentationModel.prototype._rawSourceCodeForScript):
+        (WebInspector.DebuggerPresentationModel.prototype._scriptForRawSourceCode):
+        (WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
+        (WebInspector.DebuggerPresentationModel.Linkifier.prototype.reset):
+        * inspector/front-end/RawSourceCode.js:
+        (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent.didFormatContent):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping):
+        * inspector/front-end/Script.js:
+        (WebInspector.Script.prototype.editSource):
+        (WebInspector.Script.prototype.isInlineScript):
+
 2011-11-03  Simon Hausmann  <simon.hausmann@nokia.com>
 
         [Qt] Remove Maemo specific code paths
index 78a9535..a8fa0a0 100644 (file)
@@ -36,7 +36,9 @@ WebInspector.DebuggerPresentationModel = function()
 {
     // FIXME: apply formatter from outside as a generic mapping.
     this._formatter = new WebInspector.ScriptFormatter();
-    this._rawSourceCode = {};
+    this._rawSourceCodeForScriptId = {};
+    this._rawSourceCodeForURL = {};
+    this._rawSourceCodeForDocumentURL = {};
     this._presentationCallFrames = [];
 
     this._breakpointManager = new WebInspector.BreakpointManager(WebInspector.settings.breakpoints, this._breakpointAdded.bind(this), this._breakpointRemoved.bind(this), WebInspector.debuggerModel);
@@ -109,24 +111,43 @@ WebInspector.DebuggerPresentationModel.prototype = {
      */
     _addScript: function(script)
     {
-        var rawSourceCodeId = this._createRawSourceCodeId(script);
-        var rawSourceCode = this._rawSourceCode[rawSourceCodeId];
-        if (rawSourceCode) {
-            rawSourceCode.addScript(script);
-            return;
-        }
-
         var resource;
-        if (script.sourceURL)
+        var isInlineScript = false;
+        if (script.isInlineScript()) {
             resource = WebInspector.networkManager.inflightResourceForURL(script.sourceURL) || WebInspector.resourceForURL(script.sourceURL);
-        rawSourceCode = new WebInspector.RawSourceCode(rawSourceCodeId, script, resource, this._formatter, this._formatSource);
-        this._rawSourceCode[rawSourceCodeId] = rawSourceCode;
+            if (resource && resource.type === WebInspector.Resource.Type.Document) {
+                isInlineScript = true;
+                var rawSourceCode = this._rawSourceCodeForDocumentURL[script.sourceURL];
+                if (rawSourceCode) {
+                    rawSourceCode.addScript(script);
+                    this._bindScriptToRawSourceCode(script, rawSourceCode);
+                    return;
+                }
+            }
+        }
+
+        rawSourceCode = new WebInspector.RawSourceCode(script.scriptId, script, resource, this._formatter, this._formatSource);
+        this._bindScriptToRawSourceCode(script, rawSourceCode);
+
+        if (isInlineScript)
+            this._rawSourceCodeForDocumentURL[script.sourceURL] = rawSourceCode;
+
         if (rawSourceCode.sourceMapping)
             this._updateSourceMapping(rawSourceCode, null);
         rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._sourceMappingUpdated, this);
     },
 
     /**
+     * @param {WebInspector.Script} script
+     * @param {WebInspector.RawSourceCode} rawSourceCode
+     */
+    _bindScriptToRawSourceCode: function(script, rawSourceCode)
+    {
+        this._rawSourceCodeForScriptId[script.scriptId] = rawSourceCode;
+        this._rawSourceCodeForURL[script.sourceURL] = rawSourceCode; 
+    },
+
+    /**
      * @param {WebInspector.Event} event
      */
     _sourceMappingUpdated: function(event)
@@ -142,8 +163,8 @@ WebInspector.DebuggerPresentationModel.prototype = {
     uiSourceCodes: function()
     {
         var result = [];
-        for (var id in this._rawSourceCode) {
-            var uiSourceCodeList = this._rawSourceCode[id].sourceMapping.uiSourceCodeList();
+        for (var id in this._rawSourceCodeForScriptId) {
+            var uiSourceCodeList = this._rawSourceCodeForScriptId[id].sourceMapping.uiSourceCodeList();
             for (var i = 0; i < uiSourceCodeList.length; ++i)
                 result.push(uiSourceCodeList[i]);
         }
@@ -297,8 +318,8 @@ WebInspector.DebuggerPresentationModel.prototype = {
 
         this._formatSource = formatSource;
         this._breakpointManager.reset();
-        for (var id in this._rawSourceCode)
-            this._rawSourceCode[id].setFormatted(this._formatSource);
+        for (var id in this._rawSourceCodeForScriptId)
+            this._rawSourceCodeForScriptId[id].setFormatted(this._formatSource);
     },
 
     /**
@@ -338,8 +359,8 @@ WebInspector.DebuggerPresentationModel.prototype = {
 
     _consoleCleared: function()
     {
-        for (var id in this._rawSourceCode)
-            this._rawSourceCode[id].messages = [];
+        for (var id in this._rawSourceCodeForScriptId)
+            this._rawSourceCodeForScriptId[id].messages = [];
         this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.ConsoleMessagesCleared);
     },
 
@@ -580,7 +601,7 @@ WebInspector.DebuggerPresentationModel.prototype = {
      */
     _rawSourceCodeForScriptWithURL: function(sourceURL)
     {
-        return this._rawSourceCode[sourceURL];
+        return this._rawSourceCodeForURL[sourceURL];
     },
 
     /**
@@ -588,7 +609,7 @@ WebInspector.DebuggerPresentationModel.prototype = {
      */
     _rawSourceCodeForScript: function(script)
     {
-        return this._rawSourceCode[this._createRawSourceCodeId(script)];
+        return this._rawSourceCodeForScriptId[script.scriptId];
     },
 
     /**
@@ -603,23 +624,15 @@ WebInspector.DebuggerPresentationModel.prototype = {
          */
         function filter(script)
         {
-            return this._createRawSourceCodeId(script) === rawSourceCode.id;
+            return script.scriptId === rawSourceCode.id;
         }
         return WebInspector.debuggerModel.queryScripts(filter.bind(this))[0];
     },
 
-    /**
-     * @param {WebInspector.Script} script
-     */
-    _createRawSourceCodeId: function(script)
-    {
-        return script.sourceURL || script.scriptId;
-    },
-
     _debuggerReset: function()
     {
-        for (var id in this._rawSourceCode) {
-            var rawSourceCode = this._rawSourceCode[id];
+        for (var id in this._rawSourceCodeForScriptId) {
+            var rawSourceCode = this._rawSourceCodeForScriptId[id];
             if (rawSourceCode.sourceMapping) {
                 var uiSourceCodeList = rawSourceCode.sourceMapping.uiSourceCodeList();
                 for (var i = 0; i < uiSourceCodeList.length; ++i)
@@ -627,7 +640,9 @@ WebInspector.DebuggerPresentationModel.prototype = {
             }
             rawSourceCode.removeAllListeners();
         }
-        this._rawSourceCode = {};
+        this._rawSourceCodeForScriptId = {};
+        this._rawSourceCodeForURL = {};
+        this._rawSourceCodeForDocumentURL = {};
         this._presentationCallFrames = [];
         this._selectedCallFrame = null;
         this._breakpointManager.debuggerReset();
@@ -960,8 +975,8 @@ WebInspector.DebuggerPresentationModel.Linkifier.prototype = {
     reset: function()
     {
         for (var id in this._anchorsForRawSourceCode) {
-            if (this._model._rawSourceCode[id]) // In case of navigation the list of rawSourceCodes is empty.
-                this._model._rawSourceCode[id].removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._updateSourceAnchors, this);
+            if (this._model._rawSourceCodeForScriptId[id]) // In case of navigation the list of rawSourceCodes is empty.
+                this._model._rawSourceCodeForScriptId[id].removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._updateSourceAnchors, this);
         }
         this._anchorsForRawSourceCode = {};
     },
index e91d9a9..02e5df0 100644 (file)
@@ -211,7 +211,7 @@ WebInspector.RawSourceCode.prototype = {
 
         var originalContentProvider = this._createContentProvider();
         if (!this._formatted) {
-            var uiSourceCode = new WebInspector.UISourceCode(this.id, this.url, this.isContentScript, this, originalContentProvider);
+            var uiSourceCode = new WebInspector.UISourceCode(this.url, this.url, this.isContentScript, this, originalContentProvider);
             var sourceMapping = new WebInspector.RawSourceCode.PlainSourceMapping(this, uiSourceCode);
             callback(sourceMapping);
             return;
@@ -232,7 +232,7 @@ WebInspector.RawSourceCode.prototype = {
             function didFormatContent(formattedContent, mapping)
             {
                 var contentProvider = new WebInspector.StaticContentProvider(mimeType, formattedContent)
-                var uiSourceCode = new WebInspector.UISourceCode("deobfuscated:" + this.id, this.url, this.isContentScript, this, contentProvider);
+                var uiSourceCode = new WebInspector.UISourceCode("deobfuscated:" + this.url, this.url, this.isContentScript, this, contentProvider);
                 var sourceMapping = new WebInspector.RawSourceCode.FormattedSourceMapping(this, uiSourceCode, mapping);
                 callback(sourceMapping);
             }
index 0b27cb2..bd2a77b 100644 (file)
@@ -126,5 +126,10 @@ WebInspector.Script.prototype = {
             DebuggerAgent.setScriptSource(this.scriptId, newSource, undefined, didEditScriptSource.bind(this));
         } else
             callback("Script failed to parse");
+    },
+
+    isInlineScript: function()
+    {
+        return this.sourceURL && this.lineOffset !== 0 && this.columnOffset !== 0;
     }
 }