Web Inspector: move canonical mime type calculation to Resource
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2012 16:48:42 +0000 (16:48 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2012 16:48:42 +0000 (16:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=85507

Reviewed by Yury Semikhatsky.

Drive-by: small refactoring that prepares code for formatter extraction.
* inspector/front-end/BreakpointsSidebarPane.js:
* inspector/front-end/DebuggerModel.js:
(WebInspector.DebuggerModel.prototype.createLiveLocation):
(WebInspector.DebuggerModel.prototype.rawLocationToUILocation):
* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.DebuggerPresentationModelResourceBinding.prototype._uiSourceCodeForResource):
* inspector/front-end/NetworkManager.js:
(WebInspector.NetworkDispatcher.prototype._createNetworkRequest):
(get WebInspector):
* inspector/front-end/Resource.js:
(WebInspector.Resource.prototype.requestContent):
(WebInspector.Resource.prototype.canonicalMimeType):
(WebInspector.Resource.prototype._innerRequestContent.callback):
(WebInspector.Resource.prototype._innerRequestContent):
* inspector/front-end/ResourceView.js:
(WebInspector.ResourceSourceFrame.prototype.requestContent):
(WebInspector.ResourceSourceFrame.prototype._contentChanged):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/BreakpointsSidebarPane.js
Source/WebCore/inspector/front-end/DebuggerModel.js
Source/WebCore/inspector/front-end/DebuggerPresentationModel.js
Source/WebCore/inspector/front-end/NetworkManager.js
Source/WebCore/inspector/front-end/Resource.js
Source/WebCore/inspector/front-end/ResourceView.js

index 433e9da..31ac734 100644 (file)
@@ -1,3 +1,30 @@
+2012-05-03  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: move canonical mime type calculation to Resource
+        https://bugs.webkit.org/show_bug.cgi?id=85507
+
+        Reviewed by Yury Semikhatsky.
+
+        Drive-by: small refactoring that prepares code for formatter extraction.
+
+        * inspector/front-end/BreakpointsSidebarPane.js:
+        * inspector/front-end/DebuggerModel.js:
+        (WebInspector.DebuggerModel.prototype.createLiveLocation):
+        (WebInspector.DebuggerModel.prototype.rawLocationToUILocation):
+        * inspector/front-end/DebuggerPresentationModel.js:
+        (WebInspector.DebuggerPresentationModelResourceBinding.prototype._uiSourceCodeForResource):
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkDispatcher.prototype._createNetworkRequest):
+        (get WebInspector):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.prototype.requestContent):
+        (WebInspector.Resource.prototype.canonicalMimeType):
+        (WebInspector.Resource.prototype._innerRequestContent.callback):
+        (WebInspector.Resource.prototype._innerRequestContent):
+        * inspector/front-end/ResourceView.js:
+        (WebInspector.ResourceSourceFrame.prototype.requestContent):
+        (WebInspector.ResourceSourceFrame.prototype._contentChanged):
+
 2012-05-03  Yury Semikhatsky  <yurys@chromium.org>
 
         Web Inspector: 'expires' value is incorrect for cookies
index 69ec6fe..e53ef5e 100644 (file)
@@ -147,16 +147,6 @@ WebInspector.JavaScriptBreakpointsSidebarPane.prototype = {
         }
     },
 
-    /**
-     * @param {WebInspector.BreakpointManager.Breakpoint} breakpoint
-     * @param {WebInspector.UILocation} uiLocation
-     */
-    _createBreakpointItemId: function(breakpoint, uiLocation)
-    {
-        var primaryLocation = breakpoint.primaryUILocation();
-        return primaryLocation.uiSourceCode.id + ":" + primaryLocation.lineNumber + "@" + uiLocation.uiSourceCode.id + ":" + uiLocation.lineNumber;
-    },
-
     _breakpointClicked: function(uiLocation, event)
     {
         this._showSourceLineDelegate(uiLocation.uiSourceCode, uiLocation.lineNumber);
index f68fbc6..a240d05 100644 (file)
@@ -501,6 +501,18 @@ WebInspector.DebuggerModel.prototype = {
     {
         var script = this._scripts[location.scriptId];
         return script.createLiveLocation(location, updateDelegate);
+    },
+
+    /**
+     * @param {DebuggerAgent.Location} rawLocation
+     * @return {?WebInspector.UILocation}
+     */
+    rawLocationToUILocation: function(rawLocation)
+    {
+        var script = this._scripts[rawLocation.scriptId];
+        if (!script)
+            return null;
+        return script.rawLocationToUILocation(rawLocation);
     }
 }
 
index 3216dfa..b189f16 100644 (file)
@@ -364,11 +364,12 @@ WebInspector.DebuggerPresentationModelResourceBinding.prototype = {
      */
     _uiSourceCodeForResource: function(resource)
     {
-        var rawLocation = WebInspector.debuggerModel.createRawLocationByURL(resource.url, 0, 0);
-        if (!rawLocation)
-            return null;
-        var uiLocation = this._presentationModel.rawLocationToUILocation(rawLocation);
-        return uiLocation ? uiLocation.uiSourceCode : null;
+        var uiSourceCodes = this._presentationModel.uiSourceCodes();
+        for (var i = 0; i < uiSourceCodes.length; ++i) {
+            if (uiSourceCodes[i].url === resource.url)
+                return uiSourceCodes[i];
+        }
+        return null;
     },
 
     /**
index 40d3b9b..4c3915f 100644 (file)
@@ -584,9 +584,8 @@ WebInspector.NetworkDispatcher.prototype = {
      * @param {string} url
      * @param {string} documentURL
      * @param {NetworkAgent.Initiator} initiator
-     * @param {ConsoleAgent.StackTrace=} stackTrace
      */
-    _createNetworkRequest: function(requestId, frameId, loaderId, url, documentURL, initiator, stackTrace)
+    _createNetworkRequest: function(requestId, frameId, loaderId, url, documentURL, initiator)
     {
         var networkRequest = new WebInspector.NetworkRequest(requestId, url, documentURL, frameId, loaderId);
         networkRequest.initiator = initiator;
index 056cada..2a9d9ca 100644 (file)
@@ -373,7 +373,7 @@ WebInspector.Resource.prototype = {
     requestContent: function(callback)
     {
         if (typeof this._content !== "undefined") {
-            callback(this._content, !!this._contentEncoded, this.mimeType);
+            callback(this._content, !!this._contentEncoded, this.canonicalMimeType());
             return;
         }
 
@@ -381,6 +381,17 @@ WebInspector.Resource.prototype = {
         this._innerRequestContent();
     },
 
+    canonicalMimeType: function()
+    {
+        if (this.type === WebInspector.resourceTypes.Document)
+            return "text/html";
+        if (this.type === WebInspector.resourceTypes.Script)
+            return "text/javascript";
+        if (this.type === WebInspector.resourceTypes.Stylesheet)
+            return "text/css";
+        return this.mimeType;
+    },
+
     /**
      * @param {string} query
      * @param {boolean} caseSensitive
@@ -448,7 +459,7 @@ WebInspector.Resource.prototype = {
             this._originalContent = content;
             var callbacks = this._pendingContentCallbacks.slice();
             for (var i = 0; i < callbacks.length; ++i)
-                callbacks[i](this._content, this._contentEncoded, this.mimeType);
+                callbacks[i](this._content, this._contentEncoded, this.canonicalMimeType());
             this._pendingContentCallbacks.length = 0;
             delete this._contentRequested;
         }
index 305dff8..07ecc54 100644 (file)
@@ -87,22 +87,6 @@ WebInspector.ResourceSourceFrame = function(resource)
     this._resource.addEventListener(WebInspector.Resource.Events.RevisionAdded, this._contentChanged, this);
 }
 
-WebInspector.ResourceSourceFrame._canonicalMIMEType = function(resource)
-{
-    var type = resource.type;
-    if (type === WebInspector.resourceTypes.Document)
-        return "text/html";
-    if (type === WebInspector.resourceTypes.Stylesheet)
-        return "text/css";
-    if (type === WebInspector.resourceTypes.Script)
-        return "text/javascript";
-}
-
-WebInspector.ResourceSourceFrame._mimeTypeForResource = function(resource)
-{
-    return WebInspector.ResourceSourceFrame._canonicalMIMEType(resource) || resource.mimeType;
-}
-
 WebInspector.ResourceSourceFrame.prototype = {
     get resource()
     {
@@ -121,15 +105,14 @@ WebInspector.ResourceSourceFrame.prototype = {
          */
         function callbackWrapper(content, contentEncoded, mimeType)
         {
-            // Canonicalize mimeType.
-            callback(content, contentEncoded, WebInspector.ResourceSourceFrame._mimeTypeForResource(this._resource));
+            callback(content, contentEncoded, mimeType);
         }
         this.resource.requestContent(callbackWrapper.bind(this));
     },
 
     _contentChanged: function(event)
     {
-        this.setContent(this._resource.content, false, WebInspector.ResourceSourceFrame._mimeTypeForResource(this._resource));
+        this.setContent(this._resource.content, false, this._resource.canonicalMimeType());
     }
 }