Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / NetworkPanel.js
index c20edaf..2651e26 100644 (file)
@@ -92,7 +92,7 @@ WebInspector.NetworkLogView = function(filterBar, coulmnsVisibilitySetting)
 WebInspector.NetworkLogView.HTTPSchemas = {"http": true, "https": true, "ws": true, "wss": true};
 WebInspector.NetworkLogView._responseHeaderColumns = ["Cache-Control", "Connection", "Content-Encoding", "Content-Length", "ETag", "Keep-Alive", "Last-Modified", "Server", "Vary"];
 WebInspector.NetworkLogView._defaultColumnsVisibility = {
-    method: true, status: true, scheme: false, domain: false, type: true, initiator: true, cookies: false, setCookies: false, size: true, time: true,
+    method: true, status: true, scheme: false, domain: false, remoteAddress: false, type: true, initiator: true, cookies: false, setCookies: false, size: true, time: true,
     "Cache-Control": false, "Connection": false, "Content-Encoding": false, "Content-Length": false, "ETag": false, "Keep-Alive": false, "Last-Modified": false, "Server": false, "Vary": false
 };
 WebInspector.NetworkLogView._defaultRefreshDelay = 500;
@@ -226,6 +226,14 @@ WebInspector.NetworkLogView.prototype = {
         });
 
         columns.push({
+            id: "remoteAddress",
+            title: WebInspector.UIString("Remote Address"),
+            sortable: true,
+            weight: 10,
+            align: WebInspector.DataGrid.Align.Right
+        });
+
+        columns.push({
             id: "type",
             title: WebInspector.UIString("Type"),
             sortable: true,
@@ -369,6 +377,7 @@ WebInspector.NetworkLogView.prototype = {
         this._sortingFunctions.status = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "statusCode", false);
         this._sortingFunctions.scheme = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "scheme", false);
         this._sortingFunctions.domain = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "domain", false);
+        this._sortingFunctions.remoteAddress = WebInspector.NetworkDataGridNode.RemoteAddressComparator;
         this._sortingFunctions.type = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "mimeType", false);
         this._sortingFunctions.initiator = WebInspector.NetworkDataGridNode.InitiatorComparator;
         this._sortingFunctions.cookies = WebInspector.NetworkDataGridNode.RequestCookiesCountComparator;
@@ -711,7 +720,7 @@ WebInspector.NetworkLogView.prototype = {
             this._dataGrid.scrollToLastRow();
     },
 
-    _onRecordButtonClicked: function(e)
+    _onRecordButtonClicked: function()
     {
         if (!this._recordButton.toggled)
             this._reset();
@@ -750,14 +759,6 @@ WebInspector.NetworkLogView.prototype = {
         return this._requests;
     },
 
-    /**
-     * @return {!WebInspector.NetworkRequest}
-     */
-    requestById: function(id)
-    {
-        return this._requestsById[id];
-    },
-
     _onRequestStarted: function(event)
     {
         if (this._recordButton.toggled)
@@ -1007,6 +1008,8 @@ WebInspector.NetworkLogView.prototype = {
                 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy request headers" : "Copy Request Headers"), this._copyRequestHeaders.bind(this, request));
             if (request.responseHeadersText)
                 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy response headers" : "Copy Response Headers"), this._copyResponseHeaders.bind(this, request));
+            if (request.finished)
+                contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy response" : "Copy Response"), this._copyResponse.bind(this, request));
             contextMenu.appendItem(WebInspector.UIString("Copy as cURL"), this._copyCurlCommand.bind(this, request));
         }
         contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy all as HAR" : "Copy All as HAR"), this._copyAll.bind(this));
@@ -1032,10 +1035,16 @@ WebInspector.NetworkLogView.prototype = {
         NetworkAgent.replayXHR(requestId);
     },
 
+    _harRequests: function()
+    {
+        var httpRequests = this._requests.filter(WebInspector.NetworkLogView.HTTPRequestsFilter);
+        return httpRequests.filter(WebInspector.NetworkLogView.NonSourceMapRequestsFilter);
+    },
+
     _copyAll: function()
     {
         var harArchive = {
-            log: (new WebInspector.HARLog(this._requests.filter(WebInspector.NetworkLogView.HTTPRequestsFilter))).build()
+            log: (new WebInspector.HARLog(this._harRequests())).build()
         };
         InspectorFrontendHost.copyText(JSON.stringify(harArchive, null, 2));
     },
@@ -1050,6 +1059,17 @@ WebInspector.NetworkLogView.prototype = {
         InspectorFrontendHost.copyText(request.requestHeadersText());
     },
 
+    _copyResponse: function(request)
+    {
+        function callback(content)
+        {
+            if (request.contentEncoded)
+                content = request.asDataURL();
+            InspectorFrontendHost.copyText(content || "");
+        }
+        request.requestContent(callback);
+    },
+
     _copyResponseHeaders: function(request)
     {
         InspectorFrontendHost.copyText(request.responseHeadersText);
@@ -1080,7 +1100,7 @@ WebInspector.NetworkLogView.prototype = {
             var progressIndicator = new WebInspector.ProgressIndicator();
             this._progressBarContainer.appendChild(progressIndicator.element);
             var harWriter = new WebInspector.HARWriter();
-            harWriter.write(stream, this._requests.filter(WebInspector.NetworkLogView.HTTPRequestsFilter), progressIndicator);
+            harWriter.write(stream, this._harRequests(), progressIndicator);
         }
     },
 
@@ -1224,7 +1244,7 @@ WebInspector.NetworkLogView.prototype = {
      */
     _highlightNthMatchedRequestForSearch: function(matchedRequestIndex, reveal)
     {
-        var request = this.requestById(this._matchedRequests[matchedRequestIndex]);
+        var request = this._requestsById[this._matchedRequests[matchedRequestIndex]];
         if (!request)
             return;
         this._removeAllHighlights();
@@ -1347,7 +1367,7 @@ WebInspector.NetworkLogView.prototype = {
 
     _highlightNode: function(node)
     {
-        node.element.classList.add("highlighted-row");
+        WebInspector.runCSSAnimationOnce(node.element, "highlighted-row");
         this._highlightedNode = node;
     },
 
@@ -1461,6 +1481,14 @@ WebInspector.NetworkLogView.HTTPRequestsFilter = function(request)
     return request.parsedURL.isValid && (request.scheme in WebInspector.NetworkLogView.HTTPSchemas);
 }
 
+/**
+ * @param {!WebInspector.NetworkRequest} request
+ * @return {boolean}
+ */
+WebInspector.NetworkLogView.NonSourceMapRequestsFilter = function(request)
+{
+    return !WebInspector.SourceMap.hasSourceMapRequestHeader(request);
+}
 
 WebInspector.NetworkLogView.EventTypes = {
     ViewCleared: "ViewCleared",
@@ -1492,8 +1520,9 @@ WebInspector.NetworkPanel = function()
     this._searchableView.show(this.element);
     this._contentsElement = this._searchableView.element;
 
-    this.createSidebarView(this._contentsElement);
-    this.splitView.hideMainElement();
+    this._splitView = new WebInspector.SplitView(true, false, "networkSidebarWidth");
+    this._splitView.show(this._contentsElement);
+    this._splitView.hideMain();
 
     var defaultColumnsVisibility = WebInspector.NetworkLogView._defaultColumnsVisibility;
     var networkLogColumnsVisibilitySetting = WebInspector.settings.createSetting("networkLogColumnsVisibility", defaultColumnsVisibility);
@@ -1504,13 +1533,14 @@ WebInspector.NetworkPanel = function()
     networkLogColumnsVisibilitySetting.set(columnsVisibility);
 
     this._networkLogView = new WebInspector.NetworkLogView(this._filterBar, networkLogColumnsVisibilitySetting);
-    this.splitView.setSidebarView(this._networkLogView);
+    this._networkLogView.show(this._splitView.sidebarElement());
 
-    this._viewsContainerElement = this.splitView.mainElement();
+    var viewsContainerView = new WebInspector.View();
+    this._viewsContainerElement = viewsContainerView.element;
     this._viewsContainerElement.id = "network-views";
-    this._viewsContainerElement.classList.add("hidden");
     if (!this._networkLogView.useLargeRows)
         this._viewsContainerElement.classList.add("small");
+    viewsContainerView.show(this._splitView.mainElement());
 
     this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.ViewCleared, this._onViewCleared, this);
     this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.RowSizeChanged, this._onRowSizeChanged, this);
@@ -1588,32 +1618,8 @@ WebInspector.NetworkPanel.prototype = {
     },
 
     /**
-     * @return {!WebInspector.NetworkRequest}
-     */
-    requestById: function(id)
-    {
-        return this._networkLogView.requestById(id);
-    },
-
-    _requestByAnchor: function(anchor)
-    {
-        return anchor.requestId ? this.requestById(anchor.requestId) : this._networkLogView._requestsByURL[anchor.href];
-    },
-
-    /**
-     * @param {!Element} anchor
-     * @return {boolean}
+     * @param {!WebInspector.NetworkRequest} request
      */
-    showAnchorLocation: function(anchor)
-    {
-        var request = this._requestByAnchor(anchor);
-        if (!request)
-            return false;
-        this.revealAndHighlightRequest(request)
-        WebInspector.inspectorView.setCurrentPanel(this);
-        return true;
-    },
-
     revealAndHighlightRequest: function(request)
     {
         this._toggleGridMode();
@@ -1681,7 +1687,7 @@ WebInspector.NetworkPanel.prototype = {
         if (this._viewingRequestMode) {
             this._viewingRequestMode = false;
             this.element.classList.remove("viewing-resource");
-            this.splitView.hideMainElement();
+            this._splitView.hideMain();
         }
 
         this._networkLogView.switchToDetailedView();
@@ -1696,7 +1702,7 @@ WebInspector.NetworkPanel.prototype = {
         this._viewingRequestMode = true;
 
         this.element.classList.add("viewing-resource");
-        this.splitView.showMainElement();
+        this._splitView.showBoth();
         this._networkLogView.allowPopover = false;
         this._networkLogView._allowRequestSelection = true;
         this._networkLogView.switchToBriefView();
@@ -1818,6 +1824,25 @@ WebInspector.NetworkPanel.ContextMenuProvider.prototype = {
 
 /**
  * @constructor
+ * @implements {WebInspector.Revealer}
+ */
+WebInspector.NetworkPanel.RequestRevealer = function()
+{
+}
+
+WebInspector.NetworkPanel.RequestRevealer.prototype = {
+    /**
+     * @param {!Object} request
+     */
+    reveal: function(request)
+    {
+        if (request instanceof WebInspector.NetworkRequest)
+            /** @type {!WebInspector.NetworkPanel} */ (WebInspector.showPanel("network")).revealAndHighlightRequest(request);
+    }
+}
+
+/**
+ * @constructor
  * @implements {WebInspector.TimelineGrid.Calculator}
  */
 WebInspector.NetworkBaseCalculator = function()
@@ -2162,6 +2187,7 @@ WebInspector.NetworkDataGridNode.prototype = {
         this._statusCell = this._createDivInTD("status");
         this._schemeCell = this._createDivInTD("scheme");
         this._domainCell = this._createDivInTD("domain");
+        this._remoteAddressCell = this._createDivInTD("remoteAddress");
         this._typeCell = this._createDivInTD("type");
         this._initiatorCell = this._createDivInTD("initiator");
         this._cookiesCell = this._createDivInTD("cookies");
@@ -2277,6 +2303,7 @@ WebInspector.NetworkDataGridNode.prototype = {
         this._refreshStatusCell();
         this._refreshSchemeCell();
         this._refreshDomainCell();
+        this._refreshRemoteAddressCell();
         this._refreshTypeCell();
         this._refreshInitiatorCell();
         this._refreshCookiesCell();
@@ -2292,11 +2319,19 @@ WebInspector.NetworkDataGridNode.prototype = {
             this._timelineCell.classList.add("resource-cached");
 
         this._element.classList.add("network-item");
-        this._element.enableStyleClass("network-error-row", this._request.failed || (this._request.statusCode >= 400));
+        this._element.enableStyleClass("network-error-row", this._isFailed());
         this._updateElementStyleClasses(this._element);
     },
 
     /**
+     * @return {boolean}
+     */
+    _isFailed: function()
+    {
+        return !!this._request.failed || (this._request.statusCode >= 400);
+    },
+
+    /**
      * @param {!Element} element
      */
     _updateElementStyleClasses: function(element)
@@ -2345,37 +2380,30 @@ WebInspector.NetworkDataGridNode.prototype = {
     _refreshStatusCell: function()
     {
         this._statusCell.removeChildren();
+        this._statusCell.enableStyleClass("network-dim-cell", !this._isFailed() && (this._request.cached || !this._request.statusCode));
 
-        if (this._request.failed) {
-            var failText = this._request.canceled ? WebInspector.UIString("(canceled)") : WebInspector.UIString("(failed)");
+        if (this._request.failed && !this._request.canceled) {
+            var failText = WebInspector.UIString("(failed)");
             if (this._request.localizedFailDescription) {
                 this._statusCell.appendChild(document.createTextNode(failText));
                 this._appendSubtitle(this._statusCell, this._request.localizedFailDescription);
                 this._statusCell.title = failText + " " + this._request.localizedFailDescription;
             } else
                 this._statusCell.setTextAndTitle(failText);
-            this._statusCell.classList.add("network-dim-cell");
-            return;
-        }
-
-        this._statusCell.classList.remove("network-dim-cell");
-
-        if (this._request.statusCode) {
+        } else if (this._request.statusCode) {
             this._statusCell.appendChild(document.createTextNode("" + this._request.statusCode));
             this._appendSubtitle(this._statusCell, this._request.statusText);
             this._statusCell.title = this._request.statusCode + " " + this._request.statusText;
-            if (this._request.cached)
-                this._statusCell.classList.add("network-dim-cell");
+        } else if (this._request.parsedURL.isDataURL()) {
+            this._statusCell.setTextAndTitle(WebInspector.UIString("(data)"));
+        } else if (this._request.isPingRequest()) {
+            this._statusCell.setTextAndTitle(WebInspector.UIString("(ping)"));
+        } else if (this._request.canceled) {
+            this._statusCell.setTextAndTitle(WebInspector.UIString("(canceled)"));
+        } else if (this._request.finished) {
+            this._statusCell.setTextAndTitle(WebInspector.UIString("Finished"));
         } else {
-            if (this._request.parsedURL.isDataURL())
-                this._statusCell.setTextAndTitle(WebInspector.UIString("(data)"));
-            else if (this._request.isPingRequest())
-                this._statusCell.setTextAndTitle(WebInspector.UIString("(ping)"));
-            else if (this._request.finished)
-                this._statusCell.setTextAndTitle(WebInspector.UIString("Finished"));
-            else
-                this._statusCell.setTextAndTitle(WebInspector.UIString("(pending)"));
-            this._statusCell.classList.add("network-dim-cell");
+            this._statusCell.setTextAndTitle(WebInspector.UIString("(pending)"));
         }
     },
 
@@ -2389,6 +2417,11 @@ WebInspector.NetworkDataGridNode.prototype = {
         this._domainCell.setTextAndTitle(this._request.domain);
     },
 
+    _refreshRemoteAddressCell: function()
+    {
+        this._remoteAddressCell.setTextAndTitle(this._request.remoteAddress());
+    },
+
     _refreshTypeCell: function()
     {
         if (this._request.mimeType) {
@@ -2594,6 +2627,17 @@ WebInspector.NetworkDataGridNode.NameComparator = function(a, b)
     return 0;
 }
 
+WebInspector.NetworkDataGridNode.RemoteAddressComparator = function(a, b)
+{
+    var aRemoteAddress = a._request.remoteAddress();
+    var bRemoteAddress = b._request.remoteAddress();
+    if (aRemoteAddress > bRemoteAddress)
+        return 1;
+    if (bRemoteAddress > aRemoteAddress)
+        return -1;
+    return 0;
+}
+
 WebInspector.NetworkDataGridNode.SizeComparator = function(a, b)
 {
     if (b._request.cached && !a._request.cached)