NetworkPanel.js 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563
  1. /*
  2. * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
  3. * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org>
  4. * Copyright (C) 2011 Google Inc. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  16. * its contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. importScript("RequestView.js");
  31. importScript("NetworkItemView.js");
  32. importScript("RequestCookiesView.js");
  33. importScript("RequestHeadersView.js");
  34. importScript("RequestHTMLView.js");
  35. importScript("RequestJSONView.js");
  36. importScript("RequestPreviewView.js");
  37. importScript("RequestResponseView.js");
  38. importScript("RequestTimingView.js");
  39. importScript("ResourceWebSocketFrameView.js");
  40. /**
  41. * @constructor
  42. * @extends {WebInspector.View}
  43. * @param {WebInspector.Setting} coulmnsVisibilitySetting
  44. */
  45. WebInspector.NetworkLogView = function(coulmnsVisibilitySetting)
  46. {
  47. WebInspector.View.call(this);
  48. this.registerRequiredCSS("networkLogView.css");
  49. this._coulmnsVisibilitySetting = coulmnsVisibilitySetting;
  50. this._allowRequestSelection = false;
  51. this._requests = [];
  52. this._requestsById = {};
  53. this._requestsByURL = {};
  54. this._staleRequests = {};
  55. this._requestGridNodes = {};
  56. this._lastRequestGridNodeId = 0;
  57. this._mainRequestLoadTime = -1;
  58. this._mainRequestDOMContentLoadedTime = -1;
  59. this._typeFilterElements = {};
  60. this._typeFilter = WebInspector.NetworkLogView._trivialTypeFilter;
  61. this._matchedRequests = [];
  62. this._highlightedSubstringChanges = [];
  63. this._filteredOutRequests = new Map();
  64. this._matchedRequestsMap = {};
  65. this._currentMatchedRequestIndex = -1;
  66. this._createStatusbarButtons();
  67. this._createStatusBarItems();
  68. this._linkifier = new WebInspector.Linkifier();
  69. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestStarted, this._onRequestStarted, this);
  70. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdated, this._onRequestUpdated, this);
  71. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, this._onRequestUpdated, this);
  72. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
  73. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.Load, this._loadEventFired, this);
  74. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._domContentLoadedEventFired, this);
  75. this._initializeView();
  76. WebInspector.networkLog.requests.forEach(this._appendRequest.bind(this));
  77. }
  78. WebInspector.NetworkLogView.HTTPSchemas = {"http": true, "https": true, "ws": true, "wss": true};
  79. WebInspector.NetworkLogView._responseHeaderColumns = ["Cache-Control", "Connection", "Content-Encoding", "Content-Length", "ETag", "Keep-Alive", "Last-Modified", "Server", "Vary"];
  80. WebInspector.NetworkLogView._defaultColumnsVisibility = {
  81. method: true, status: true, scheme: false, domain: false, type: true, initiator: true, cookies: false, setCookies: false, size: true, time: true,
  82. "Cache-Control": false, "Connection": false, "Content-Encoding": false, "Content-Length": false, "ETag": false, "Keep-Alive": false, "Last-Modified": false, "Server": false, "Vary": false
  83. };
  84. WebInspector.NetworkLogView._defaultRefreshDelay = 500;
  85. WebInspector.NetworkLogView.ALL_TYPES = "all";
  86. WebInspector.NetworkLogView.prototype = {
  87. _initializeView: function()
  88. {
  89. this.element.id = "network-container";
  90. this._createSortingFunctions();
  91. this._createTable();
  92. this._createTimelineGrid();
  93. this._createSummaryBar();
  94. if (!this.useLargeRows)
  95. this._setLargerRequests(this.useLargeRows);
  96. this._allowPopover = true;
  97. this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._onHidePopover.bind(this));
  98. // Enable faster hint.
  99. this._popoverHelper.setTimeout(100);
  100. this.calculator = new WebInspector.NetworkTransferTimeCalculator();
  101. this._toggleTypeFilter(WebInspector.NetworkLogView.ALL_TYPES, false);
  102. this.switchToDetailedView();
  103. },
  104. get statusBarItems()
  105. {
  106. return [this._largerRequestsButton.element, this._preserveLogToggle.element, this._clearButton.element, this._filterBarElement, this._progressBarContainer];
  107. },
  108. get useLargeRows()
  109. {
  110. return WebInspector.settings.resourcesLargeRows.get();
  111. },
  112. set allowPopover(flag)
  113. {
  114. this._allowPopover = flag;
  115. },
  116. elementsToRestoreScrollPositionsFor: function()
  117. {
  118. if (!this._dataGrid) // Not initialized yet.
  119. return [];
  120. return [this._dataGrid.scrollContainer];
  121. },
  122. onResize: function()
  123. {
  124. this._updateOffscreenRows();
  125. },
  126. _createTimelineGrid: function()
  127. {
  128. this._timelineGrid = new WebInspector.TimelineGrid();
  129. this._timelineGrid.element.addStyleClass("network-timeline-grid");
  130. this._dataGrid.element.appendChild(this._timelineGrid.element);
  131. },
  132. _createTable: function()
  133. {
  134. var columns = [];
  135. columns.push({
  136. id: "name",
  137. titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Name"), WebInspector.UIString("Path")),
  138. title: WebInspector.UIString("Name"),
  139. sortable: true,
  140. weight: 20,
  141. disclosure: true
  142. });
  143. columns.push({
  144. id: "method",
  145. title: WebInspector.UIString("Method"),
  146. sortable: true,
  147. weight: 6
  148. });
  149. columns.push({
  150. id: "status",
  151. titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Status"), WebInspector.UIString("Text")),
  152. title: WebInspector.UIString("Status"),
  153. sortable: true,
  154. weight: 6
  155. });
  156. columns.push({
  157. id: "scheme",
  158. title: WebInspector.UIString("Scheme"),
  159. sortable: true,
  160. weight: 6
  161. });
  162. columns.push({
  163. id: "domain",
  164. title: WebInspector.UIString("Domain"),
  165. sortable: true,
  166. weight: 6
  167. });
  168. columns.push({
  169. id: "type",
  170. title: WebInspector.UIString("Type"),
  171. sortable: true,
  172. weight: 6
  173. });
  174. columns.push({
  175. id: "initiator",
  176. title: WebInspector.UIString("Initiator"),
  177. sortable: true,
  178. weight: 10
  179. });
  180. columns.push({
  181. id: "cookies",
  182. title: WebInspector.UIString("Cookies"),
  183. sortable: true,
  184. weight: 6,
  185. align: WebInspector.DataGrid.Align.Right
  186. });
  187. columns.push({
  188. id: "setCookies",
  189. title: WebInspector.UIString("Set-Cookies"),
  190. sortable: true,
  191. weight: 6,
  192. align: WebInspector.DataGrid.Align.Right
  193. });
  194. columns.push({
  195. id: "size",
  196. titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Size"), WebInspector.UIString("Content")),
  197. title: WebInspector.UIString("Size"),
  198. sortable: true,
  199. weight: 6,
  200. align: WebInspector.DataGrid.Align.Right
  201. });
  202. columns.push({
  203. id: "time",
  204. titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Time"), WebInspector.UIString("Latency")),
  205. title: WebInspector.UIString("Time"),
  206. sortable: true,
  207. weight: 6,
  208. align: WebInspector.DataGrid.Align.Right
  209. });
  210. var responseHeaderColumns = WebInspector.NetworkLogView._responseHeaderColumns;
  211. for (var i = 0; i < responseHeaderColumns.length; ++i) {
  212. var headerName = responseHeaderColumns[i];
  213. var descriptor = {
  214. id: headerName,
  215. title: WebInspector.UIString(headerName),
  216. weight: 6
  217. }
  218. if (headerName === "Content-Length")
  219. descriptor.align = WebInspector.DataGrid.Align.Right;
  220. columns.push(descriptor);
  221. }
  222. columns.push({
  223. id: "timeline",
  224. titleDOMFragment: document.createDocumentFragment(),
  225. title: WebInspector.UIString("Timeline"),
  226. sortable: false,
  227. weight: 40,
  228. sort: WebInspector.DataGrid.Order.Ascending
  229. });
  230. this._dataGrid = new WebInspector.DataGrid(columns);
  231. this._dataGrid.setName("networkLog");
  232. this._dataGrid.resizeMethod = WebInspector.DataGrid.ResizeMethod.Last;
  233. this._dataGrid.element.addStyleClass("network-log-grid");
  234. this._dataGrid.element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
  235. this._dataGrid.show(this.element);
  236. // Event listeners need to be added _after_ we attach to the document, so that owner document is properly update.
  237. this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._sortItems, this);
  238. this._dataGrid.addEventListener(WebInspector.DataGrid.Events.ColumnsResized, this._updateDividersIfNeeded, this);
  239. this._dataGrid.scrollContainer.addEventListener("scroll", this._updateOffscreenRows.bind(this));
  240. this._patchTimelineHeader();
  241. },
  242. _makeHeaderFragment: function(title, subtitle)
  243. {
  244. var fragment = document.createDocumentFragment();
  245. fragment.createTextChild(title);
  246. var subtitleDiv = fragment.createChild("div", "network-header-subtitle");
  247. subtitleDiv.createTextChild(subtitle);
  248. return fragment;
  249. },
  250. _patchTimelineHeader: function()
  251. {
  252. var timelineSorting = document.createElement("select");
  253. var option = document.createElement("option");
  254. option.value = "startTime";
  255. option.label = WebInspector.UIString("Timeline");
  256. timelineSorting.appendChild(option);
  257. option = document.createElement("option");
  258. option.value = "startTime";
  259. option.label = WebInspector.UIString("Start Time");
  260. timelineSorting.appendChild(option);
  261. option = document.createElement("option");
  262. option.value = "responseTime";
  263. option.label = WebInspector.UIString("Response Time");
  264. timelineSorting.appendChild(option);
  265. option = document.createElement("option");
  266. option.value = "endTime";
  267. option.label = WebInspector.UIString("End Time");
  268. timelineSorting.appendChild(option);
  269. option = document.createElement("option");
  270. option.value = "duration";
  271. option.label = WebInspector.UIString("Duration");
  272. timelineSorting.appendChild(option);
  273. option = document.createElement("option");
  274. option.value = "latency";
  275. option.label = WebInspector.UIString("Latency");
  276. timelineSorting.appendChild(option);
  277. var header = this._dataGrid.headerTableHeader("timeline");
  278. header.replaceChild(timelineSorting, header.firstChild);
  279. timelineSorting.addEventListener("click", function(event) { event.consume() }, false);
  280. timelineSorting.addEventListener("change", this._sortByTimeline.bind(this), false);
  281. this._timelineSortSelector = timelineSorting;
  282. },
  283. _createSortingFunctions: function()
  284. {
  285. this._sortingFunctions = {};
  286. this._sortingFunctions.name = WebInspector.NetworkDataGridNode.NameComparator;
  287. this._sortingFunctions.method = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "method", false);
  288. this._sortingFunctions.status = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "statusCode", false);
  289. this._sortingFunctions.scheme = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "scheme", false);
  290. this._sortingFunctions.domain = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "domain", false);
  291. this._sortingFunctions.type = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "mimeType", false);
  292. this._sortingFunctions.initiator = WebInspector.NetworkDataGridNode.InitiatorComparator;
  293. this._sortingFunctions.cookies = WebInspector.NetworkDataGridNode.RequestCookiesCountComparator;
  294. this._sortingFunctions.setCookies = WebInspector.NetworkDataGridNode.ResponseCookiesCountComparator;
  295. this._sortingFunctions.size = WebInspector.NetworkDataGridNode.SizeComparator;
  296. this._sortingFunctions.time = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "duration", false);
  297. this._sortingFunctions.timeline = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "startTime", false);
  298. this._sortingFunctions.startTime = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "startTime", false);
  299. this._sortingFunctions.endTime = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "endTime", false);
  300. this._sortingFunctions.responseTime = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "responseReceivedTime", false);
  301. this._sortingFunctions.duration = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "duration", true);
  302. this._sortingFunctions.latency = WebInspector.NetworkDataGridNode.RequestPropertyComparator.bind(null, "latency", true);
  303. var timeCalculator = new WebInspector.NetworkTransferTimeCalculator();
  304. var durationCalculator = new WebInspector.NetworkTransferDurationCalculator();
  305. this._calculators = {};
  306. this._calculators.timeline = timeCalculator;
  307. this._calculators.startTime = timeCalculator;
  308. this._calculators.endTime = timeCalculator;
  309. this._calculators.responseTime = timeCalculator;
  310. this._calculators.duration = durationCalculator;
  311. this._calculators.latency = durationCalculator;
  312. },
  313. _sortItems: function()
  314. {
  315. this._removeAllNodeHighlights();
  316. var columnIdentifier = this._dataGrid.sortColumnIdentifier();
  317. if (columnIdentifier === "timeline") {
  318. this._sortByTimeline();
  319. return;
  320. }
  321. var sortingFunction = this._sortingFunctions[columnIdentifier];
  322. if (!sortingFunction)
  323. return;
  324. this._dataGrid.sortNodes(sortingFunction, !this._dataGrid.isSortOrderAscending());
  325. this._timelineSortSelector.selectedIndex = 0;
  326. this._updateOffscreenRows();
  327. this.searchCanceled();
  328. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  329. action: WebInspector.UserMetrics.UserActionNames.NetworkSort,
  330. column: columnIdentifier,
  331. sortOrder: this._dataGrid.sortOrder()
  332. });
  333. },
  334. _sortByTimeline: function()
  335. {
  336. this._removeAllNodeHighlights();
  337. var selectedIndex = this._timelineSortSelector.selectedIndex;
  338. if (!selectedIndex)
  339. selectedIndex = 1; // Sort by start time by default.
  340. var selectedOption = this._timelineSortSelector[selectedIndex];
  341. var value = selectedOption.value;
  342. var sortingFunction = this._sortingFunctions[value];
  343. this._dataGrid.sortNodes(sortingFunction);
  344. this.calculator = this._calculators[value];
  345. if (this.calculator.startAtZero)
  346. this._timelineGrid.hideEventDividers();
  347. else
  348. this._timelineGrid.showEventDividers();
  349. this._dataGrid.markColumnAsSortedBy("timeline", WebInspector.DataGrid.Order.Ascending);
  350. this._updateOffscreenRows();
  351. },
  352. /**
  353. * @param {string} typeName
  354. * @param {string} label
  355. */
  356. _addTypeFilter: function(typeName, label)
  357. {
  358. var typeFilterElement = this._filterBarElement.createChild("li", typeName);
  359. typeFilterElement.typeName = typeName;
  360. typeFilterElement.createTextChild(label);
  361. typeFilterElement.addEventListener("click", this._onTypeFilterClicked.bind(this), false);
  362. this._typeFilterElements[typeName] = typeFilterElement;
  363. },
  364. _createStatusBarItems: function()
  365. {
  366. var filterBarElement = document.createElement("div");
  367. filterBarElement.className = "scope-bar status-bar-item";
  368. filterBarElement.title = WebInspector.UIString("Use %s Click to select multiple types.", WebInspector.KeyboardShortcut.shortcutToString("", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta));
  369. this._filterBarElement = filterBarElement;
  370. this._addTypeFilter(WebInspector.NetworkLogView.ALL_TYPES, WebInspector.UIString("All"));
  371. filterBarElement.createChild("div", "scope-bar-divider");
  372. for (var typeId in WebInspector.resourceTypes) {
  373. var type = WebInspector.resourceTypes[typeId];
  374. this._addTypeFilter(type.name(), type.categoryTitle());
  375. }
  376. this._progressBarContainer = document.createElement("div");
  377. this._progressBarContainer.className = "status-bar-item";
  378. },
  379. _createSummaryBar: function()
  380. {
  381. var tbody = this._dataGrid.dataTableBody;
  382. var tfoot = document.createElement("tfoot");
  383. var tr = tfoot.createChild("tr", "revealed network-summary-bar");
  384. var td = tr.createChild("td");
  385. td.setAttribute("colspan", 7);
  386. tbody.parentNode.insertBefore(tfoot, tbody);
  387. this._summaryBarElement = td;
  388. },
  389. _updateSummaryBar: function()
  390. {
  391. var requestsNumber = this._requests.length;
  392. if (!requestsNumber) {
  393. if (this._summaryBarElement._isDisplayingWarning)
  394. return;
  395. this._summaryBarElement._isDisplayingWarning = true;
  396. this._summaryBarElement.removeChildren();
  397. this._summaryBarElement.createChild("div", "warning-icon-small");
  398. this._summaryBarElement.appendChild(document.createTextNode(
  399. WebInspector.UIString("No requests captured. Reload the page to see detailed information on the network activity.")));
  400. return;
  401. }
  402. delete this._summaryBarElement._isDisplayingWarning;
  403. var transferSize = 0;
  404. var selectedRequestsNumber = 0;
  405. var selectedTransferSize = 0;
  406. var baseTime = -1;
  407. var maxTime = -1;
  408. for (var i = 0; i < this._requests.length; ++i) {
  409. var request = this._requests[i];
  410. var requestTransferSize = request.transferSize;
  411. transferSize += requestTransferSize;
  412. if (!this._filteredOutRequests.get(request)) {
  413. selectedRequestsNumber++;
  414. selectedTransferSize += requestTransferSize;
  415. }
  416. if (request.url === WebInspector.inspectedPageURL)
  417. baseTime = request.startTime;
  418. if (request.endTime > maxTime)
  419. maxTime = request.endTime;
  420. }
  421. var text = "";
  422. if (selectedRequestsNumber !== requestsNumber) {
  423. text += String.sprintf(WebInspector.UIString("%d / %d requests"), selectedRequestsNumber, requestsNumber);
  424. text += " \u2758 " + String.sprintf(WebInspector.UIString("%s / %s transferred"), Number.bytesToString(selectedTransferSize), Number.bytesToString(transferSize));
  425. } else {
  426. text += String.sprintf(WebInspector.UIString("%d requests"), requestsNumber);
  427. text += " \u2758 " + String.sprintf(WebInspector.UIString("%s transferred"), Number.bytesToString(transferSize));
  428. }
  429. if (baseTime !== -1 && this._mainRequestLoadTime !== -1 && this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
  430. text += " \u2758 " + String.sprintf(WebInspector.UIString("%s (load: %s, DOMContentLoaded: %s)"),
  431. Number.secondsToString(maxTime - baseTime),
  432. Number.secondsToString(this._mainRequestLoadTime - baseTime),
  433. Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime));
  434. }
  435. this._summaryBarElement.textContent = text;
  436. },
  437. /**
  438. * @param {!Event} e
  439. */
  440. _onTypeFilterClicked: function(e)
  441. {
  442. var toggle;
  443. if (WebInspector.isMac())
  444. toggle = e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey;
  445. else
  446. toggle = e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
  447. this._toggleTypeFilter(e.target.typeName, toggle);
  448. this._removeAllNodeHighlights();
  449. this.searchCanceled();
  450. this._filterRequests();
  451. },
  452. /**
  453. * @param {string} typeName
  454. * @param {boolean} allowMultiSelect
  455. */
  456. _toggleTypeFilter: function(typeName, allowMultiSelect)
  457. {
  458. if (allowMultiSelect && typeName !== WebInspector.NetworkLogView.ALL_TYPES)
  459. this._typeFilterElements[WebInspector.NetworkLogView.ALL_TYPES].removeStyleClass("selected");
  460. else {
  461. for (var key in this._typeFilterElements)
  462. this._typeFilterElements[key].removeStyleClass("selected");
  463. }
  464. var filterElement = this._typeFilterElements[typeName];
  465. filterElement.enableStyleClass("selected", !filterElement.hasStyleClass("selected"));
  466. var allowedTypes = {};
  467. for (var key in this._typeFilterElements) {
  468. if (this._typeFilterElements[key].hasStyleClass("selected"))
  469. allowedTypes[key] = true;
  470. }
  471. if (typeName === WebInspector.NetworkLogView.ALL_TYPES)
  472. this._typeFilter = WebInspector.NetworkLogView._trivialTypeFilter;
  473. else
  474. this._typeFilter = WebInspector.NetworkLogView._typeFilter.bind(null, allowedTypes);
  475. },
  476. _scheduleRefresh: function()
  477. {
  478. if (this._needsRefresh)
  479. return;
  480. this._needsRefresh = true;
  481. if (this.isShowing() && !this._refreshTimeout)
  482. this._refreshTimeout = setTimeout(this.refresh.bind(this), WebInspector.NetworkLogView._defaultRefreshDelay);
  483. },
  484. _updateDividersIfNeeded: function()
  485. {
  486. if (!this._dataGrid)
  487. return;
  488. var timelineColumn = this._dataGrid.columns.timeline;
  489. for (var i = 0; i < this._dataGrid.resizers.length; ++i) {
  490. if (timelineColumn.ordinal === this._dataGrid.resizers[i].rightNeighboringColumnIndex) {
  491. // Position timline grid location.
  492. this._timelineGrid.element.style.left = this._dataGrid.resizers[i].style.left;
  493. }
  494. }
  495. var proceed = true;
  496. if (!this.isShowing()) {
  497. this._scheduleRefresh();
  498. proceed = false;
  499. } else {
  500. this.calculator.setDisplayWindow(this._timelineGrid.dividersElement.clientWidth);
  501. proceed = this._timelineGrid.updateDividers(this.calculator);
  502. }
  503. if (!proceed)
  504. return;
  505. if (this.calculator.startAtZero || !this.calculator.computePercentageFromEventTime) {
  506. // If our current sorting method starts at zero, that means it shows all
  507. // requests starting at the same point, and so onLoad event and DOMContent
  508. // event lines really wouldn't make much sense here, so don't render them.
  509. // Additionally, if the calculator doesn't have the computePercentageFromEventTime
  510. // function defined, we are probably sorting by size, and event times aren't relevant
  511. // in this case.
  512. return;
  513. }
  514. this._timelineGrid.removeEventDividers();
  515. if (this._mainRequestLoadTime !== -1) {
  516. var percent = this.calculator.computePercentageFromEventTime(this._mainRequestLoadTime);
  517. var loadDivider = document.createElement("div");
  518. loadDivider.className = "network-event-divider network-red-divider";
  519. var loadDividerPadding = document.createElement("div");
  520. loadDividerPadding.className = "network-event-divider-padding";
  521. loadDividerPadding.title = WebInspector.UIString("Load event fired");
  522. loadDividerPadding.appendChild(loadDivider);
  523. loadDividerPadding.style.left = percent + "%";
  524. this._timelineGrid.addEventDivider(loadDividerPadding);
  525. }
  526. if (this._mainRequestDOMContentLoadedTime !== -1) {
  527. var percent = this.calculator.computePercentageFromEventTime(this._mainRequestDOMContentLoadedTime);
  528. var domContentLoadedDivider = document.createElement("div");
  529. domContentLoadedDivider.className = "network-event-divider network-blue-divider";
  530. var domContentLoadedDividerPadding = document.createElement("div");
  531. domContentLoadedDividerPadding.className = "network-event-divider-padding";
  532. domContentLoadedDividerPadding.title = WebInspector.UIString("DOMContentLoaded event fired");
  533. domContentLoadedDividerPadding.appendChild(domContentLoadedDivider);
  534. domContentLoadedDividerPadding.style.left = percent + "%";
  535. this._timelineGrid.addEventDivider(domContentLoadedDividerPadding);
  536. }
  537. },
  538. _refreshIfNeeded: function()
  539. {
  540. if (this._needsRefresh)
  541. this.refresh();
  542. },
  543. _invalidateAllItems: function()
  544. {
  545. for (var i = 0; i < this._requests.length; ++i) {
  546. var request = this._requests[i];
  547. this._staleRequests[request.requestId] = request;
  548. }
  549. },
  550. get calculator()
  551. {
  552. return this._calculator;
  553. },
  554. set calculator(x)
  555. {
  556. if (!x || this._calculator === x)
  557. return;
  558. this._calculator = x;
  559. this._calculator.reset();
  560. this._invalidateAllItems();
  561. this.refresh();
  562. },
  563. _requestGridNode: function(request)
  564. {
  565. return this._requestGridNodes[request.__gridNodeId];
  566. },
  567. _createRequestGridNode: function(request)
  568. {
  569. var node = new WebInspector.NetworkDataGridNode(this, request);
  570. request.__gridNodeId = this._lastRequestGridNodeId++;
  571. this._requestGridNodes[request.__gridNodeId] = node;
  572. return node;
  573. },
  574. _createStatusbarButtons: function()
  575. {
  576. this._preserveLogToggle = new WebInspector.StatusBarButton(WebInspector.UIString("Preserve Log upon Navigation"), "record-profile-status-bar-item");
  577. this._preserveLogToggle.addEventListener("click", this._onPreserveLogClicked, this);
  578. this._clearButton = new WebInspector.StatusBarButton(WebInspector.UIString("Clear"), "clear-status-bar-item");
  579. this._clearButton.addEventListener("click", this._reset, this);
  580. this._largerRequestsButton = new WebInspector.StatusBarButton(WebInspector.UIString("Use small resource rows."), "network-larger-resources-status-bar-item");
  581. this._largerRequestsButton.toggled = WebInspector.settings.resourcesLargeRows.get();
  582. this._largerRequestsButton.addEventListener("click", this._toggleLargerRequests, this);
  583. },
  584. _loadEventFired: function(event)
  585. {
  586. this._mainRequestLoadTime = event.data || -1;
  587. // Schedule refresh to update boundaries and draw the new line.
  588. this._scheduleRefresh();
  589. },
  590. _domContentLoadedEventFired: function(event)
  591. {
  592. this._mainRequestDOMContentLoadedTime = event.data || -1;
  593. // Schedule refresh to update boundaries and draw the new line.
  594. this._scheduleRefresh();
  595. },
  596. wasShown: function()
  597. {
  598. this._refreshIfNeeded();
  599. },
  600. willHide: function()
  601. {
  602. this._popoverHelper.hidePopover();
  603. },
  604. refresh: function()
  605. {
  606. this._needsRefresh = false;
  607. if (this._refreshTimeout) {
  608. clearTimeout(this._refreshTimeout);
  609. delete this._refreshTimeout;
  610. }
  611. this._removeAllNodeHighlights();
  612. var wasScrolledToLastRow = this._dataGrid.isScrolledToLastRow();
  613. var boundariesChanged = false;
  614. if (this.calculator.updateBoundariesForEventTime) {
  615. boundariesChanged = this.calculator.updateBoundariesForEventTime(this._mainRequestLoadTime) || boundariesChanged;
  616. boundariesChanged = this.calculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime) || boundariesChanged;
  617. }
  618. for (var requestId in this._staleRequests) {
  619. var request = this._staleRequests[requestId];
  620. var node = this._requestGridNode(request);
  621. if (!node) {
  622. // Create the timeline tree element and graph.
  623. node = this._createRequestGridNode(request);
  624. this._dataGrid.rootNode().appendChild(node);
  625. }
  626. node.refreshRequest();
  627. this._applyFilter(node);
  628. if (this.calculator.updateBoundaries(request))
  629. boundariesChanged = true;
  630. if (!node.isFilteredOut())
  631. this._updateHighlightIfMatched(request);
  632. }
  633. if (boundariesChanged) {
  634. // The boundaries changed, so all item graphs are stale.
  635. this._invalidateAllItems();
  636. }
  637. for (var requestId in this._staleRequests)
  638. this._requestGridNode(this._staleRequests[requestId]).refreshGraph(this.calculator);
  639. this._staleRequests = {};
  640. this._sortItems();
  641. this._updateSummaryBar();
  642. this._dataGrid.updateWidths();
  643. // FIXME: evaluate performance impact of moving this before a call to sortItems()
  644. if (wasScrolledToLastRow)
  645. this._dataGrid.scrollToLastRow();
  646. },
  647. _onPreserveLogClicked: function(e)
  648. {
  649. this._preserveLogToggle.toggled = !this._preserveLogToggle.toggled;
  650. },
  651. _reset: function()
  652. {
  653. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.ViewCleared);
  654. this._clearSearchMatchedList();
  655. if (this._popoverHelper)
  656. this._popoverHelper.hidePopover();
  657. if (this._calculator)
  658. this._calculator.reset();
  659. this._requests = [];
  660. this._requestsById = {};
  661. this._requestsByURL = {};
  662. this._staleRequests = {};
  663. this._requestGridNodes = {};
  664. if (this._dataGrid) {
  665. this._dataGrid.rootNode().removeChildren();
  666. this._updateDividersIfNeeded();
  667. this._updateSummaryBar();
  668. }
  669. this._mainRequestLoadTime = -1;
  670. this._mainRequestDOMContentLoadedTime = -1;
  671. },
  672. get requests()
  673. {
  674. return this._requests;
  675. },
  676. requestById: function(id)
  677. {
  678. return this._requestsById[id];
  679. },
  680. _onRequestStarted: function(event)
  681. {
  682. this._appendRequest(event.data);
  683. },
  684. _appendRequest: function(request)
  685. {
  686. this._requests.push(request);
  687. // In case of redirect request id is reassigned to a redirected
  688. // request and we need to update _requestsById and search results.
  689. if (this._requestsById[request.requestId]) {
  690. var oldRequest = request.redirects[request.redirects.length - 1];
  691. this._requestsById[oldRequest.requestId] = oldRequest;
  692. this._updateSearchMatchedListAfterRequestIdChanged(request.requestId, oldRequest.requestId);
  693. }
  694. this._requestsById[request.requestId] = request;
  695. this._requestsByURL[request.url] = request;
  696. // Pull all the redirects of the main request upon commit load.
  697. if (request.redirects) {
  698. for (var i = 0; i < request.redirects.length; ++i)
  699. this._refreshRequest(request.redirects[i]);
  700. }
  701. this._refreshRequest(request);
  702. },
  703. /**
  704. * @param {WebInspector.Event} event
  705. */
  706. _onRequestUpdated: function(event)
  707. {
  708. var request = /** @type {WebInspector.NetworkRequest} */ (event.data);
  709. this._refreshRequest(request);
  710. },
  711. /**
  712. * @param {WebInspector.NetworkRequest} request
  713. */
  714. _refreshRequest: function(request)
  715. {
  716. this._staleRequests[request.requestId] = request;
  717. this._scheduleRefresh();
  718. },
  719. clear: function()
  720. {
  721. if (this._preserveLogToggle.toggled)
  722. return;
  723. this._reset();
  724. },
  725. _mainFrameNavigated: function(event)
  726. {
  727. if (this._preserveLogToggle.toggled)
  728. return;
  729. var frame = /** @type {WebInspector.ResourceTreeFrame} */ (event.data);
  730. var loaderId = frame.loaderId;
  731. // Preserve provisional load requests.
  732. var requestsToPreserve = [];
  733. for (var i = 0; i < this._requests.length; ++i) {
  734. var request = this._requests[i];
  735. if (request.loaderId === loaderId)
  736. requestsToPreserve.push(request);
  737. }
  738. this._reset();
  739. // Restore preserved items.
  740. for (var i = 0; i < requestsToPreserve.length; ++i)
  741. this._appendRequest(requestsToPreserve[i]);
  742. },
  743. switchToDetailedView: function()
  744. {
  745. if (!this._dataGrid)
  746. return;
  747. if (this._dataGrid.selectedNode)
  748. this._dataGrid.selectedNode.selected = false;
  749. this.element.removeStyleClass("brief-mode");
  750. this._detailedMode = true;
  751. this._updateColumns();
  752. },
  753. switchToBriefView: function()
  754. {
  755. this.element.addStyleClass("brief-mode");
  756. this._removeAllNodeHighlights();
  757. this._detailedMode = false;
  758. this._updateColumns();
  759. this._popoverHelper.hidePopover();
  760. },
  761. _toggleLargerRequests: function()
  762. {
  763. WebInspector.settings.resourcesLargeRows.set(!WebInspector.settings.resourcesLargeRows.get());
  764. this._setLargerRequests(WebInspector.settings.resourcesLargeRows.get());
  765. },
  766. _setLargerRequests: function(enabled)
  767. {
  768. this._largerRequestsButton.toggled = enabled;
  769. if (!enabled) {
  770. this._largerRequestsButton.title = WebInspector.UIString("Use large resource rows.");
  771. this._dataGrid.element.addStyleClass("small");
  772. this._timelineGrid.element.addStyleClass("small");
  773. } else {
  774. this._largerRequestsButton.title = WebInspector.UIString("Use small resource rows.");
  775. this._dataGrid.element.removeStyleClass("small");
  776. this._timelineGrid.element.removeStyleClass("small");
  777. }
  778. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.RowSizeChanged, { largeRows: enabled });
  779. this._updateOffscreenRows();
  780. },
  781. _getPopoverAnchor: function(element)
  782. {
  783. if (!this._allowPopover)
  784. return;
  785. var anchor = element.enclosingNodeOrSelfWithClass("network-graph-bar") || element.enclosingNodeOrSelfWithClass("network-graph-label");
  786. if (anchor && anchor.parentElement.request && anchor.parentElement.request.timing)
  787. return anchor;
  788. anchor = element.enclosingNodeOrSelfWithClass("network-script-initiated");
  789. if (anchor && anchor.request && anchor.request.initiator)
  790. return anchor;
  791. return null;
  792. },
  793. /**
  794. * @param {Element} anchor
  795. * @param {WebInspector.Popover} popover
  796. */
  797. _showPopover: function(anchor, popover)
  798. {
  799. var content;
  800. if (anchor.hasStyleClass("network-script-initiated"))
  801. content = this._generateScriptInitiatedPopoverContent(anchor.request);
  802. else
  803. content = WebInspector.RequestTimingView.createTimingTable(anchor.parentElement.request);
  804. popover.show(content, anchor);
  805. },
  806. _onHidePopover: function()
  807. {
  808. this._linkifier.reset();
  809. },
  810. /**
  811. * @param {!WebInspector.NetworkRequest} request
  812. * @return {!Element}
  813. */
  814. _generateScriptInitiatedPopoverContent: function(request)
  815. {
  816. var stackTrace = request.initiator.stackTrace;
  817. var framesTable = document.createElement("table");
  818. for (var i = 0; i < stackTrace.length; ++i) {
  819. var stackFrame = stackTrace[i];
  820. var row = document.createElement("tr");
  821. row.createChild("td").textContent = stackFrame.functionName ? stackFrame.functionName : WebInspector.UIString("(anonymous function)");
  822. row.createChild("td").textContent = " @ ";
  823. row.createChild("td").appendChild(this._linkifier.linkifyLocation(stackFrame.url, stackFrame.lineNumber - 1, stackFrame.columnNumber - 1));
  824. framesTable.appendChild(row);
  825. }
  826. return framesTable;
  827. },
  828. _updateColumns: function()
  829. {
  830. var columnsVisibility = this._coulmnsVisibilitySetting.get();
  831. var detailedMode = !!this._detailedMode;
  832. for (var columnIdentifier in columnsVisibility) {
  833. var visible = detailedMode && columnsVisibility[columnIdentifier];
  834. this._dataGrid.setColumnVisible(columnIdentifier, visible);
  835. }
  836. this._dataGrid.setColumnVisible("timeline", detailedMode);
  837. this._dataGrid.applyColumnWeights();
  838. },
  839. /**
  840. * @param {string} columnIdentifier
  841. */
  842. _toggleColumnVisibility: function(columnIdentifier)
  843. {
  844. var columnsVisibility = this._coulmnsVisibilitySetting.get();
  845. columnsVisibility[columnIdentifier] = !columnsVisibility[columnIdentifier];
  846. this._coulmnsVisibilitySetting.set(columnsVisibility);
  847. this._updateColumns();
  848. },
  849. /**
  850. * @return {!Array.<string>}
  851. */
  852. _getConfigurableColumnIDs: function()
  853. {
  854. if (this._configurableColumnIDs)
  855. return this._configurableColumnIDs;
  856. var columns = this._dataGrid.columns;
  857. function compare(id1, id2)
  858. {
  859. return columns[id1].title.compareTo(columns[id2].title);
  860. }
  861. var columnIDs = Object.keys(this._coulmnsVisibilitySetting.get());
  862. this._configurableColumnIDs = columnIDs.sort(compare);
  863. return this._configurableColumnIDs;
  864. },
  865. _contextMenu: function(event)
  866. {
  867. var contextMenu = new WebInspector.ContextMenu(event);
  868. if (this._detailedMode && event.target.isSelfOrDescendant(this._dataGrid.headerTableBody)) {
  869. var columnsVisibility = this._coulmnsVisibilitySetting.get();
  870. var columnIDs = this._getConfigurableColumnIDs();
  871. for (var i = 0; i < columnIDs.length; ++i) {
  872. var columnIdentifier = columnIDs[i];
  873. var column = this._dataGrid.columns[columnIdentifier];
  874. contextMenu.appendCheckboxItem(column.title, this._toggleColumnVisibility.bind(this, columnIdentifier), !!columnsVisibility[columnIdentifier]);
  875. }
  876. contextMenu.show();
  877. return;
  878. }
  879. var gridNode = this._dataGrid.dataGridNodeFromNode(event.target);
  880. var request = gridNode && gridNode._request;
  881. if (request) {
  882. contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), WebInspector.openResource.bind(WebInspector, request.url, false));
  883. contextMenu.appendSeparator();
  884. contextMenu.appendItem(WebInspector.copyLinkAddressLabel(), this._copyLocation.bind(this, request));
  885. if (request.requestHeadersText)
  886. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy request headers" : "Copy Request Headers"), this._copyRequestHeaders.bind(this, request));
  887. if (request.responseHeadersText)
  888. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy response headers" : "Copy Response Headers"), this._copyResponseHeaders.bind(this, request));
  889. contextMenu.appendItem(WebInspector.UIString("Copy as cURL"), this._copyCurlCommand.bind(this, request));
  890. }
  891. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy all as HAR" : "Copy All as HAR"), this._copyAll.bind(this));
  892. contextMenu.appendSeparator();
  893. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Save as HAR with content" : "Save as HAR with Content"), this._exportAll.bind(this));
  894. contextMenu.appendSeparator();
  895. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear browser cache" : "Clear Browser Cache"), this._clearBrowserCache.bind(this));
  896. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear browser cookies" : "Clear Browser Cookies"), this._clearBrowserCookies.bind(this));
  897. if (request && request.type === WebInspector.resourceTypes.XHR) {
  898. contextMenu.appendSeparator();
  899. contextMenu.appendItem(WebInspector.UIString("Replay XHR"), this._replayXHR.bind(this, request.requestId));
  900. contextMenu.appendSeparator();
  901. }
  902. contextMenu.show();
  903. },
  904. _replayXHR: function(requestId)
  905. {
  906. NetworkAgent.replayXHR(requestId);
  907. },
  908. _copyAll: function()
  909. {
  910. var harArchive = {
  911. log: (new WebInspector.HARLog(this._requests.filter(WebInspector.NetworkLogView.HTTPRequestsFilter))).build()
  912. };
  913. InspectorFrontendHost.copyText(JSON.stringify(harArchive, null, 2));
  914. },
  915. _copyLocation: function(request)
  916. {
  917. InspectorFrontendHost.copyText(request.url);
  918. },
  919. _copyRequestHeaders: function(request)
  920. {
  921. InspectorFrontendHost.copyText(request.requestHeadersText);
  922. },
  923. _copyResponseHeaders: function(request)
  924. {
  925. InspectorFrontendHost.copyText(request.responseHeadersText);
  926. },
  927. /**
  928. * @param {WebInspector.NetworkRequest} request
  929. */
  930. _copyCurlCommand: function(request)
  931. {
  932. InspectorFrontendHost.copyText(this._generateCurlCommand(request));
  933. },
  934. _exportAll: function()
  935. {
  936. var filename = WebInspector.inspectedPageDomain + ".har";
  937. var stream = new WebInspector.FileOutputStream();
  938. stream.open(filename, openCallback.bind(this));
  939. function openCallback()
  940. {
  941. var progressIndicator = new WebInspector.ProgressIndicator();
  942. this._progressBarContainer.appendChild(progressIndicator.element);
  943. var harWriter = new WebInspector.HARWriter();
  944. harWriter.write(stream, this._requests.filter(WebInspector.NetworkLogView.HTTPRequestsFilter), progressIndicator);
  945. }
  946. },
  947. _clearBrowserCache: function()
  948. {
  949. if (confirm(WebInspector.UIString("Are you sure you want to clear browser cache?")))
  950. NetworkAgent.clearBrowserCache();
  951. },
  952. _clearBrowserCookies: function()
  953. {
  954. if (confirm(WebInspector.UIString("Are you sure you want to clear browser cookies?")))
  955. NetworkAgent.clearBrowserCookies();
  956. },
  957. _updateOffscreenRows: function()
  958. {
  959. var dataTableBody = this._dataGrid.dataTableBody;
  960. var rows = dataTableBody.children;
  961. var recordsCount = rows.length;
  962. if (recordsCount < 2)
  963. return; // Filler row only.
  964. var visibleTop = this._dataGrid.scrollContainer.scrollTop;
  965. var visibleBottom = visibleTop + this._dataGrid.scrollContainer.offsetHeight;
  966. var rowHeight = 0;
  967. // Filler is at recordsCount - 1.
  968. var unfilteredRowIndex = 0;
  969. for (var i = 0; i < recordsCount - 1; ++i) {
  970. var row = rows[i];
  971. var dataGridNode = this._dataGrid.dataGridNodeFromNode(row);
  972. if (dataGridNode.isFilteredOut()) {
  973. row.removeStyleClass("offscreen");
  974. continue;
  975. }
  976. if (!rowHeight)
  977. rowHeight = row.offsetHeight;
  978. var rowIsVisible = unfilteredRowIndex * rowHeight < visibleBottom && (unfilteredRowIndex + 1) * rowHeight > visibleTop;
  979. if (rowIsVisible !== row.rowIsVisible) {
  980. row.enableStyleClass("offscreen", !rowIsVisible);
  981. row.rowIsVisible = rowIsVisible;
  982. }
  983. unfilteredRowIndex++;
  984. }
  985. },
  986. _matchRequest: function(request)
  987. {
  988. if (!this._searchRegExp)
  989. return -1;
  990. if (!request.name().match(this._searchRegExp) && !request.path().match(this._searchRegExp))
  991. return -1;
  992. if (request.requestId in this._matchedRequestsMap)
  993. return this._matchedRequestsMap[request.requestId];
  994. var matchedRequestIndex = this._matchedRequests.length;
  995. this._matchedRequestsMap[request.requestId] = matchedRequestIndex;
  996. this._matchedRequests.push(request.requestId);
  997. return matchedRequestIndex;
  998. },
  999. _clearSearchMatchedList: function()
  1000. {
  1001. delete this._searchRegExp;
  1002. this._matchedRequests = [];
  1003. this._matchedRequestsMap = {};
  1004. this._removeAllHighlights();
  1005. },
  1006. _updateSearchMatchedListAfterRequestIdChanged: function(oldRequestId, newRequestId)
  1007. {
  1008. var requestIndex = this._matchedRequestsMap[oldRequestId];
  1009. if (requestIndex) {
  1010. delete this._matchedRequestsMap[oldRequestId];
  1011. this._matchedRequestsMap[newRequestId] = requestIndex;
  1012. this._matchedRequests[requestIndex] = newRequestId;
  1013. }
  1014. },
  1015. _updateHighlightIfMatched: function(request)
  1016. {
  1017. var matchedRequestIndex = this._matchRequest(request);
  1018. if (matchedRequestIndex === -1)
  1019. return;
  1020. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, this._matchedRequests.length);
  1021. if (this._currentMatchedRequestIndex !== -1 && this._currentMatchedRequestIndex !== matchedRequestIndex)
  1022. return;
  1023. this._highlightNthMatchedRequestForSearch(matchedRequestIndex, false);
  1024. },
  1025. _removeAllHighlights: function()
  1026. {
  1027. this._removeAllNodeHighlights();
  1028. for (var i = 0; i < this._highlightedSubstringChanges.length; ++i)
  1029. WebInspector.revertDomChanges(this._highlightedSubstringChanges[i]);
  1030. this._highlightedSubstringChanges = [];
  1031. },
  1032. /**
  1033. * @param {WebInspector.NetworkRequest} request
  1034. * @param {boolean} reveal
  1035. * @param {RegExp=} regExp
  1036. */
  1037. _highlightMatchedRequest: function(request, reveal, regExp)
  1038. {
  1039. var node = this._requestGridNode(request);
  1040. if (!node)
  1041. return;
  1042. var nameMatched = request.name().match(regExp);
  1043. var pathMatched = request.path().match(regExp);
  1044. if (!nameMatched && pathMatched && !this._largerRequestsButton.toggled)
  1045. this._toggleLargerRequests();
  1046. var highlightedSubstringChanges = node._highlightMatchedSubstring(regExp);
  1047. this._highlightedSubstringChanges.push(highlightedSubstringChanges);
  1048. if (reveal) {
  1049. node.reveal();
  1050. this._highlightNode(node);
  1051. }
  1052. },
  1053. /**
  1054. * @param {number} matchedRequestIndex
  1055. * @param {boolean} reveal
  1056. */
  1057. _highlightNthMatchedRequestForSearch: function(matchedRequestIndex, reveal)
  1058. {
  1059. var request = this.requestById(this._matchedRequests[matchedRequestIndex]);
  1060. if (!request)
  1061. return;
  1062. this._removeAllHighlights();
  1063. this._highlightMatchedRequest(request, reveal, this._searchRegExp);
  1064. var node = this._requestGridNode(request);
  1065. if (node)
  1066. this._currentMatchedRequestIndex = matchedRequestIndex;
  1067. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchIndexUpdated, this._currentMatchedRequestIndex);
  1068. },
  1069. /**
  1070. * @param {string} query
  1071. * @param {boolean} shouldJump
  1072. */
  1073. performSearch: function(query, shouldJump)
  1074. {
  1075. var newMatchedRequestIndex = 0;
  1076. var currentMatchedRequestId;
  1077. if (this._currentMatchedRequestIndex !== -1)
  1078. currentMatchedRequestId = this._matchedRequests[this._currentMatchedRequestIndex];
  1079. this._clearSearchMatchedList();
  1080. this._searchRegExp = createPlainTextSearchRegex(query, "i");
  1081. var childNodes = this._dataGrid.dataTableBody.childNodes;
  1082. var requestNodes = Array.prototype.slice.call(childNodes, 0, childNodes.length - 1); // drop the filler row.
  1083. for (var i = 0; i < requestNodes.length; ++i) {
  1084. var dataGridNode = this._dataGrid.dataGridNodeFromNode(requestNodes[i]);
  1085. if (dataGridNode.isFilteredOut())
  1086. continue;
  1087. if (this._matchRequest(dataGridNode._request) !== -1 && dataGridNode._request.requestId === currentMatchedRequestId)
  1088. newMatchedRequestIndex = this._matchedRequests.length - 1;
  1089. }
  1090. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, this._matchedRequests.length);
  1091. if (shouldJump)
  1092. this._highlightNthMatchedRequestForSearch(newMatchedRequestIndex, true);
  1093. },
  1094. /**
  1095. * @param {!WebInspector.NetworkDataGridNode} node
  1096. */
  1097. _applyFilter: function(node)
  1098. {
  1099. var filter = this._filterRegExp;
  1100. var request = node._request;
  1101. var matches = false;
  1102. if (this._typeFilter(request)) {
  1103. matches = !filter || filter.test(request.name()) || filter.test(request.path());
  1104. if (filter && matches)
  1105. this._highlightMatchedRequest(request, false, filter);
  1106. }
  1107. node.element.enableStyleClass("filtered-out", !matches);
  1108. if (matches)
  1109. this._filteredOutRequests.remove(request);
  1110. else
  1111. this._filteredOutRequests.put(request, true);
  1112. },
  1113. /**
  1114. * @param {string} query
  1115. */
  1116. performFilter: function(query)
  1117. {
  1118. delete this._filterRegExp;
  1119. if (query)
  1120. this._filterRegExp = createPlainTextSearchRegex(query, "i");
  1121. this._filterRequests();
  1122. },
  1123. _filterRequests: function()
  1124. {
  1125. this._removeAllHighlights();
  1126. this._filteredOutRequests.clear();
  1127. var nodes = this._dataGrid.rootNode().children;
  1128. for (var i = 0; i < nodes.length; ++i)
  1129. this._applyFilter(nodes[i]);
  1130. this._updateSummaryBar();
  1131. this._updateOffscreenRows();
  1132. },
  1133. jumpToPreviousSearchResult: function()
  1134. {
  1135. if (!this._matchedRequests.length)
  1136. return;
  1137. this._highlightNthMatchedRequestForSearch((this._currentMatchedRequestIndex + this._matchedRequests.length - 1) % this._matchedRequests.length, true);
  1138. },
  1139. jumpToNextSearchResult: function()
  1140. {
  1141. if (!this._matchedRequests.length)
  1142. return;
  1143. this._highlightNthMatchedRequestForSearch((this._currentMatchedRequestIndex + 1) % this._matchedRequests.length, true);
  1144. },
  1145. searchCanceled: function()
  1146. {
  1147. this._clearSearchMatchedList();
  1148. this.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, 0);
  1149. },
  1150. revealAndHighlightRequest: function(request)
  1151. {
  1152. this._removeAllNodeHighlights();
  1153. var node = this._requestGridNode(request);
  1154. if (node) {
  1155. this._dataGrid.element.focus();
  1156. node.reveal();
  1157. this._highlightNode(node);
  1158. }
  1159. },
  1160. _removeAllNodeHighlights: function()
  1161. {
  1162. if (this._highlightedNode) {
  1163. this._highlightedNode.element.removeStyleClass("highlighted-row");
  1164. delete this._highlightedNode;
  1165. }
  1166. },
  1167. _highlightNode: function(node)
  1168. {
  1169. node.element.addStyleClass("highlighted-row");
  1170. this._highlightedNode = node;
  1171. },
  1172. /**
  1173. * @param {WebInspector.NetworkRequest} request
  1174. * @return {string}
  1175. */
  1176. _generateCurlCommand: function(request)
  1177. {
  1178. var command = ["curl"];
  1179. var ignoredHeaders = {};
  1180. function escapeCharacter(x)
  1181. {
  1182. var code = x.charCodeAt(0);
  1183. if (code < 256) {
  1184. // Add leading zero when needed to not care about the next character.
  1185. return code < 16 ? "\\x0" + code.toString(16) : "\\x" + code.toString(16);
  1186. }
  1187. code = code.toString(16);
  1188. return "\\u" + ("0000" + code).substr(code.length, 4);
  1189. }
  1190. function escape(str)
  1191. {
  1192. if (/[^\x20-\x7E]|\'/.test(str)) {
  1193. // Use ANSI-C quoting syntax.
  1194. return "$\'" + str.replace(/\\/g, "\\\\")
  1195. .replace(/\'/g, "\\\'")
  1196. .replace(/\n/g, "\\n")
  1197. .replace(/\r/g, "\\r")
  1198. .replace(/[^\x20-\x7E]/g, escapeCharacter) + "'";
  1199. } else {
  1200. // Use single quote syntax.
  1201. return "'" + str + "'";
  1202. }
  1203. }
  1204. command.push(escape(request.url).replace(/[[{}\]]/g, "\\$&"));
  1205. var inferredMethod = "GET";
  1206. var data = [];
  1207. var requestContentType = request.requestContentType();
  1208. if (requestContentType && requestContentType.startsWith("application/x-www-form-urlencoded") && request.requestFormData) {
  1209. data.push("--data");
  1210. data.push(escape(request.requestFormData));
  1211. ignoredHeaders["Content-Length"] = true;
  1212. inferredMethod = "POST";
  1213. } else if (request.requestFormData) {
  1214. data.push("--data-binary");
  1215. data.push(escape(request.requestFormData));
  1216. ignoredHeaders["Content-Length"] = true;
  1217. inferredMethod = "POST";
  1218. }
  1219. if (request.requestMethod !== inferredMethod) {
  1220. command.push("-X");
  1221. command.push(request.requestMethod);
  1222. }
  1223. for (var i = 0; i < request.requestHeaders.length; i++) {
  1224. var header = request.requestHeaders[i];
  1225. if (header.name in ignoredHeaders)
  1226. continue;
  1227. command.push("-H");
  1228. command.push(escape(header.name + ": " + header.value));
  1229. }
  1230. command = command.concat(data);
  1231. command.push("--compressed");
  1232. return command.join(" ");
  1233. },
  1234. __proto__: WebInspector.View.prototype
  1235. }
  1236. /**
  1237. * @param {!WebInspector.NetworkRequest} request
  1238. * @return {boolean}
  1239. */
  1240. WebInspector.NetworkLogView.HTTPRequestsFilter = function(request)
  1241. {
  1242. return request.parsedURL.isValid && (request.scheme in WebInspector.NetworkLogView.HTTPSchemas);
  1243. }
  1244. WebInspector.NetworkLogView.EventTypes = {
  1245. ViewCleared: "ViewCleared",
  1246. RowSizeChanged: "RowSizeChanged",
  1247. RequestSelected: "RequestSelected",
  1248. SearchCountUpdated: "SearchCountUpdated",
  1249. SearchIndexUpdated: "SearchIndexUpdated"
  1250. };
  1251. /**
  1252. * @constructor
  1253. * @extends {WebInspector.Panel}
  1254. * @implements {WebInspector.ContextMenu.Provider}
  1255. */
  1256. WebInspector.NetworkPanel = function()
  1257. {
  1258. WebInspector.Panel.call(this, "network");
  1259. this.registerRequiredCSS("networkPanel.css");
  1260. this._injectStyles();
  1261. this.createSidebarView();
  1262. this.splitView.hideMainElement();
  1263. var defaultColumnsVisibility = WebInspector.NetworkLogView._defaultColumnsVisibility;
  1264. var networkLogColumnsVisibilitySetting = WebInspector.settings.createSetting("networkLogColumnsVisibility", defaultColumnsVisibility);
  1265. var savedColumnsVisibility = networkLogColumnsVisibilitySetting.get();
  1266. var columnsVisibility = {};
  1267. for (var columnId in defaultColumnsVisibility)
  1268. columnsVisibility[columnId] = savedColumnsVisibility.hasOwnProperty(columnId) ? savedColumnsVisibility[columnId] : defaultColumnsVisibility[columnId];
  1269. networkLogColumnsVisibilitySetting.set(columnsVisibility);
  1270. this._networkLogView = new WebInspector.NetworkLogView(networkLogColumnsVisibilitySetting);
  1271. this._networkLogView.show(this.sidebarElement);
  1272. this._viewsContainerElement = this.splitView.mainElement;
  1273. this._viewsContainerElement.id = "network-views";
  1274. this._viewsContainerElement.addStyleClass("hidden");
  1275. if (!this._networkLogView.useLargeRows)
  1276. this._viewsContainerElement.addStyleClass("small");
  1277. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.ViewCleared, this._onViewCleared, this);
  1278. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.RowSizeChanged, this._onRowSizeChanged, this);
  1279. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.RequestSelected, this._onRequestSelected, this);
  1280. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.SearchCountUpdated, this._onSearchCountUpdated, this);
  1281. this._networkLogView.addEventListener(WebInspector.NetworkLogView.EventTypes.SearchIndexUpdated, this._onSearchIndexUpdated, this);
  1282. this._closeButtonElement = this._viewsContainerElement.createChild("div", "close-button");
  1283. this._closeButtonElement.id = "network-close-button";
  1284. this._closeButtonElement.addEventListener("click", this._toggleGridMode.bind(this), false);
  1285. this._viewsContainerElement.appendChild(this._closeButtonElement);
  1286. function viewGetter()
  1287. {
  1288. return this.visibleView;
  1289. }
  1290. WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
  1291. }
  1292. WebInspector.NetworkPanel.prototype = {
  1293. get statusBarItems()
  1294. {
  1295. return this._networkLogView.statusBarItems;
  1296. },
  1297. elementsToRestoreScrollPositionsFor: function()
  1298. {
  1299. return this._networkLogView.elementsToRestoreScrollPositionsFor();
  1300. },
  1301. // FIXME: only used by the layout tests, should not be exposed.
  1302. _reset: function()
  1303. {
  1304. this._networkLogView._reset();
  1305. },
  1306. handleShortcut: function(event)
  1307. {
  1308. if (this._viewingRequestMode && event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  1309. this._toggleGridMode();
  1310. event.handled = true;
  1311. return;
  1312. }
  1313. WebInspector.Panel.prototype.handleShortcut.call(this, event);
  1314. },
  1315. wasShown: function()
  1316. {
  1317. WebInspector.Panel.prototype.wasShown.call(this);
  1318. },
  1319. get requests()
  1320. {
  1321. return this._networkLogView.requests;
  1322. },
  1323. requestById: function(id)
  1324. {
  1325. return this._networkLogView.requestById(id);
  1326. },
  1327. _requestByAnchor: function(anchor)
  1328. {
  1329. return anchor.requestId ? this.requestById(anchor.requestId) : this._networkLogView._requestsByURL[anchor.href];
  1330. },
  1331. canShowAnchorLocation: function(anchor)
  1332. {
  1333. return !!this._requestByAnchor(anchor);
  1334. },
  1335. showAnchorLocation: function(anchor)
  1336. {
  1337. var request = this._requestByAnchor(anchor);
  1338. this.revealAndHighlightRequest(request)
  1339. },
  1340. revealAndHighlightRequest: function(request)
  1341. {
  1342. this._toggleGridMode();
  1343. if (request)
  1344. this._networkLogView.revealAndHighlightRequest(request);
  1345. },
  1346. _onViewCleared: function(event)
  1347. {
  1348. this._closeVisibleRequest();
  1349. this._toggleGridMode();
  1350. this._viewsContainerElement.removeChildren();
  1351. this._viewsContainerElement.appendChild(this._closeButtonElement);
  1352. },
  1353. _onRowSizeChanged: function(event)
  1354. {
  1355. this._viewsContainerElement.enableStyleClass("small", !event.data.largeRows);
  1356. },
  1357. _onSearchCountUpdated: function(event)
  1358. {
  1359. WebInspector.searchController.updateSearchMatchesCount(event.data, this);
  1360. },
  1361. _onSearchIndexUpdated: function(event)
  1362. {
  1363. WebInspector.searchController.updateCurrentMatchIndex(event.data, this);
  1364. },
  1365. _onRequestSelected: function(event)
  1366. {
  1367. this._showRequest(event.data);
  1368. },
  1369. _showRequest: function(request)
  1370. {
  1371. if (!request)
  1372. return;
  1373. this._toggleViewingRequestMode();
  1374. if (this.visibleView) {
  1375. this.visibleView.detach();
  1376. delete this.visibleView;
  1377. }
  1378. var view = new WebInspector.NetworkItemView(request);
  1379. view.show(this._viewsContainerElement);
  1380. this.visibleView = view;
  1381. },
  1382. _closeVisibleRequest: function()
  1383. {
  1384. this.element.removeStyleClass("viewing-resource");
  1385. if (this.visibleView) {
  1386. this.visibleView.detach();
  1387. delete this.visibleView;
  1388. }
  1389. },
  1390. _toggleGridMode: function()
  1391. {
  1392. if (this._viewingRequestMode) {
  1393. this._viewingRequestMode = false;
  1394. this.element.removeStyleClass("viewing-resource");
  1395. this.splitView.hideMainElement();
  1396. }
  1397. this._networkLogView.switchToDetailedView();
  1398. this._networkLogView.allowPopover = true;
  1399. this._networkLogView._allowRequestSelection = false;
  1400. },
  1401. _toggleViewingRequestMode: function()
  1402. {
  1403. if (this._viewingRequestMode)
  1404. return;
  1405. this._viewingRequestMode = true;
  1406. this.element.addStyleClass("viewing-resource");
  1407. this.splitView.showMainElement();
  1408. this._networkLogView.allowPopover = false;
  1409. this._networkLogView._allowRequestSelection = true;
  1410. this._networkLogView.switchToBriefView();
  1411. },
  1412. /**
  1413. * @param {string} query
  1414. * @param {boolean} shouldJump
  1415. */
  1416. performSearch: function(query, shouldJump)
  1417. {
  1418. this._networkLogView.performSearch(query, shouldJump);
  1419. },
  1420. /**
  1421. * @return {boolean}
  1422. */
  1423. canFilter: function()
  1424. {
  1425. return true;
  1426. },
  1427. /**
  1428. * @param {string} query
  1429. */
  1430. performFilter: function(query)
  1431. {
  1432. this._networkLogView.performFilter(query);
  1433. },
  1434. jumpToPreviousSearchResult: function()
  1435. {
  1436. this._networkLogView.jumpToPreviousSearchResult();
  1437. },
  1438. jumpToNextSearchResult: function()
  1439. {
  1440. this._networkLogView.jumpToNextSearchResult();
  1441. },
  1442. searchCanceled: function()
  1443. {
  1444. this._networkLogView.searchCanceled();
  1445. },
  1446. /**
  1447. * @param {WebInspector.ContextMenu} contextMenu
  1448. * @param {Object} target
  1449. */
  1450. appendApplicableItems: function(event, contextMenu, target)
  1451. {
  1452. function reveal(request)
  1453. {
  1454. WebInspector.inspectorView.setCurrentPanel(this);
  1455. this.revealAndHighlightRequest(request);
  1456. }
  1457. function appendRevealItem(request)
  1458. {
  1459. var revealText = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Reveal in Network panel" : "Reveal in Network Panel");
  1460. contextMenu.appendItem(revealText, reveal.bind(this, request));
  1461. }
  1462. if (target instanceof WebInspector.Resource) {
  1463. var resource = /** @type {WebInspector.Resource} */ (target);
  1464. if (resource.request)
  1465. appendRevealItem.call(this, resource.request);
  1466. return;
  1467. }
  1468. if (target instanceof WebInspector.UISourceCode) {
  1469. var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (target);
  1470. var resource = WebInspector.resourceForURL(uiSourceCode.url);
  1471. if (resource && resource.request)
  1472. appendRevealItem.call(this, resource.request);
  1473. return;
  1474. }
  1475. if (!(target instanceof WebInspector.NetworkRequest))
  1476. return;
  1477. var request = /** @type {WebInspector.NetworkRequest} */ (target);
  1478. if (this.visibleView && this.visibleView.isShowing() && this.visibleView.request() === request)
  1479. return;
  1480. appendRevealItem.call(this, request);
  1481. },
  1482. _injectStyles: function()
  1483. {
  1484. var style = document.createElement("style");
  1485. var rules = [];
  1486. var columns = WebInspector.NetworkLogView._defaultColumnsVisibility;
  1487. var hideSelectors = [];
  1488. var bgSelectors = [];
  1489. for (var columnId in columns) {
  1490. hideSelectors.push("#network-container .hide-" + columnId + "-column ." + columnId + "-column");
  1491. bgSelectors.push(".network-log-grid.data-grid td." + columnId + "-column");
  1492. }
  1493. rules.push(hideSelectors.join(", ") + "{border-left: 0 none transparent;}");
  1494. rules.push(bgSelectors.join(", ") + "{background-color: rgba(0, 0, 0, 0.07);}");
  1495. style.textContent = rules.join("\n");
  1496. document.head.appendChild(style);
  1497. },
  1498. __proto__: WebInspector.Panel.prototype
  1499. }
  1500. /**
  1501. * @constructor
  1502. * @implements {WebInspector.TimelineGrid.Calculator}
  1503. */
  1504. WebInspector.NetworkBaseCalculator = function()
  1505. {
  1506. }
  1507. WebInspector.NetworkBaseCalculator.prototype = {
  1508. computePosition: function(time)
  1509. {
  1510. return (time - this._minimumBoundary) / this.boundarySpan() * this._workingArea;
  1511. },
  1512. computeBarGraphPercentages: function(item)
  1513. {
  1514. return {start: 0, middle: 0, end: (this._value(item) / this.boundarySpan()) * 100};
  1515. },
  1516. computeBarGraphLabels: function(item)
  1517. {
  1518. const label = this.formatTime(this._value(item));
  1519. return {left: label, right: label, tooltip: label};
  1520. },
  1521. boundarySpan: function()
  1522. {
  1523. return this._maximumBoundary - this._minimumBoundary;
  1524. },
  1525. updateBoundaries: function(item)
  1526. {
  1527. this._minimumBoundary = 0;
  1528. var value = this._value(item);
  1529. if (typeof this._maximumBoundary === "undefined" || value > this._maximumBoundary) {
  1530. this._maximumBoundary = value;
  1531. return true;
  1532. }
  1533. return false;
  1534. },
  1535. reset: function()
  1536. {
  1537. delete this._minimumBoundary;
  1538. delete this._maximumBoundary;
  1539. },
  1540. maximumBoundary: function()
  1541. {
  1542. return this._maximumBoundary;
  1543. },
  1544. minimumBoundary: function()
  1545. {
  1546. return this._minimumBoundary;
  1547. },
  1548. zeroTime: function()
  1549. {
  1550. return this._minimumBoundary;
  1551. },
  1552. _value: function(item)
  1553. {
  1554. return 0;
  1555. },
  1556. formatTime: function(value)
  1557. {
  1558. return value.toString();
  1559. },
  1560. setDisplayWindow: function(clientWidth)
  1561. {
  1562. this._workingArea = clientWidth;
  1563. this.paddingLeft = 0;
  1564. }
  1565. }
  1566. /**
  1567. * @constructor
  1568. * @extends {WebInspector.NetworkBaseCalculator}
  1569. */
  1570. WebInspector.NetworkTimeCalculator = function(startAtZero)
  1571. {
  1572. WebInspector.NetworkBaseCalculator.call(this);
  1573. this.startAtZero = startAtZero;
  1574. }
  1575. WebInspector.NetworkTimeCalculator.prototype = {
  1576. computeBarGraphPercentages: function(request)
  1577. {
  1578. if (request.startTime !== -1)
  1579. var start = ((request.startTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  1580. else
  1581. var start = 0;
  1582. if (request.responseReceivedTime !== -1)
  1583. var middle = ((request.responseReceivedTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  1584. else
  1585. var middle = (this.startAtZero ? start : 100);
  1586. if (request.endTime !== -1)
  1587. var end = ((request.endTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  1588. else
  1589. var end = (this.startAtZero ? middle : 100);
  1590. if (this.startAtZero) {
  1591. end -= start;
  1592. middle -= start;
  1593. start = 0;
  1594. }
  1595. return {start: start, middle: middle, end: end};
  1596. },
  1597. computePercentageFromEventTime: function(eventTime)
  1598. {
  1599. // This function computes a percentage in terms of the total loading time
  1600. // of a specific event. If startAtZero is set, then this is useless, and we
  1601. // want to return 0.
  1602. if (eventTime !== -1 && !this.startAtZero)
  1603. return ((eventTime - this._minimumBoundary) / this.boundarySpan()) * 100;
  1604. return 0;
  1605. },
  1606. updateBoundariesForEventTime: function(eventTime)
  1607. {
  1608. if (eventTime === -1 || this.startAtZero)
  1609. return false;
  1610. if (typeof this._maximumBoundary === "undefined" || eventTime > this._maximumBoundary) {
  1611. this._maximumBoundary = eventTime;
  1612. return true;
  1613. }
  1614. return false;
  1615. },
  1616. computeBarGraphLabels: function(request)
  1617. {
  1618. var rightLabel = "";
  1619. if (request.responseReceivedTime !== -1 && request.endTime !== -1)
  1620. rightLabel = this.formatTime(request.endTime - request.responseReceivedTime);
  1621. var hasLatency = request.latency > 0;
  1622. if (hasLatency)
  1623. var leftLabel = this.formatTime(request.latency);
  1624. else
  1625. var leftLabel = rightLabel;
  1626. if (request.timing)
  1627. return {left: leftLabel, right: rightLabel};
  1628. if (hasLatency && rightLabel) {
  1629. var total = this.formatTime(request.duration);
  1630. var tooltip = WebInspector.UIString("%s latency, %s download (%s total)", leftLabel, rightLabel, total);
  1631. } else if (hasLatency)
  1632. var tooltip = WebInspector.UIString("%s latency", leftLabel);
  1633. else if (rightLabel)
  1634. var tooltip = WebInspector.UIString("%s download", rightLabel);
  1635. if (request.cached)
  1636. tooltip = WebInspector.UIString("%s (from cache)", tooltip);
  1637. return {left: leftLabel, right: rightLabel, tooltip: tooltip};
  1638. },
  1639. updateBoundaries: function(request)
  1640. {
  1641. var didChange = false;
  1642. var lowerBound;
  1643. if (this.startAtZero)
  1644. lowerBound = 0;
  1645. else
  1646. lowerBound = this._lowerBound(request);
  1647. if (lowerBound !== -1 && (typeof this._minimumBoundary === "undefined" || lowerBound < this._minimumBoundary)) {
  1648. this._minimumBoundary = lowerBound;
  1649. didChange = true;
  1650. }
  1651. var upperBound = this._upperBound(request);
  1652. if (upperBound !== -1 && (typeof this._maximumBoundary === "undefined" || upperBound > this._maximumBoundary)) {
  1653. this._maximumBoundary = upperBound;
  1654. didChange = true;
  1655. }
  1656. return didChange;
  1657. },
  1658. formatTime: function(value)
  1659. {
  1660. return Number.secondsToString(value);
  1661. },
  1662. _lowerBound: function(request)
  1663. {
  1664. return 0;
  1665. },
  1666. _upperBound: function(request)
  1667. {
  1668. return 0;
  1669. },
  1670. __proto__: WebInspector.NetworkBaseCalculator.prototype
  1671. }
  1672. /**
  1673. * @constructor
  1674. * @extends {WebInspector.NetworkTimeCalculator}
  1675. */
  1676. WebInspector.NetworkTransferTimeCalculator = function()
  1677. {
  1678. WebInspector.NetworkTimeCalculator.call(this, false);
  1679. }
  1680. WebInspector.NetworkTransferTimeCalculator.prototype = {
  1681. formatTime: function(value)
  1682. {
  1683. return Number.secondsToString(value);
  1684. },
  1685. _lowerBound: function(request)
  1686. {
  1687. return request.startTime;
  1688. },
  1689. _upperBound: function(request)
  1690. {
  1691. return request.endTime;
  1692. },
  1693. __proto__: WebInspector.NetworkTimeCalculator.prototype
  1694. }
  1695. /**
  1696. * @constructor
  1697. * @extends {WebInspector.NetworkTimeCalculator}
  1698. */
  1699. WebInspector.NetworkTransferDurationCalculator = function()
  1700. {
  1701. WebInspector.NetworkTimeCalculator.call(this, true);
  1702. }
  1703. WebInspector.NetworkTransferDurationCalculator.prototype = {
  1704. formatTime: function(value)
  1705. {
  1706. return Number.secondsToString(value);
  1707. },
  1708. _upperBound: function(request)
  1709. {
  1710. return request.duration;
  1711. },
  1712. __proto__: WebInspector.NetworkTimeCalculator.prototype
  1713. }
  1714. /**
  1715. * @constructor
  1716. * @extends {WebInspector.DataGridNode}
  1717. * @param {!WebInspector.NetworkLogView} parentView
  1718. * @param {!WebInspector.NetworkRequest} request
  1719. */
  1720. WebInspector.NetworkDataGridNode = function(parentView, request)
  1721. {
  1722. WebInspector.DataGridNode.call(this, {});
  1723. this._parentView = parentView;
  1724. this._request = request;
  1725. this._linkifier = new WebInspector.Linkifier();
  1726. }
  1727. WebInspector.NetworkDataGridNode.prototype = {
  1728. /** override */
  1729. createCells: function()
  1730. {
  1731. // Out of sight, out of mind: create nodes offscreen to save on render tree update times when running updateOffscreenRows()
  1732. this._element.addStyleClass("offscreen");
  1733. this._nameCell = this._createDivInTD("name");
  1734. this._methodCell = this._createDivInTD("method");
  1735. this._statusCell = this._createDivInTD("status");
  1736. this._schemeCell = this._createDivInTD("scheme");
  1737. this._domainCell = this._createDivInTD("domain");
  1738. this._typeCell = this._createDivInTD("type");
  1739. this._initiatorCell = this._createDivInTD("initiator");
  1740. this._cookiesCell = this._createDivInTD("cookies");
  1741. this._setCookiesCell = this._createDivInTD("setCookies");
  1742. this._sizeCell = this._createDivInTD("size");
  1743. this._timeCell = this._createDivInTD("time");
  1744. this._responseHeaderCells = {};
  1745. var responseHeaderColumns = WebInspector.NetworkLogView._responseHeaderColumns;
  1746. for (var i = 0; i < responseHeaderColumns.length; ++i)
  1747. this._responseHeaderCells[responseHeaderColumns[i]] = this._createDivInTD(responseHeaderColumns[i]);
  1748. this._timelineCell = this._createDivInTD("timeline");
  1749. this._createTimelineBar(this._timelineCell);
  1750. this._nameCell.addEventListener("click", this._onClick.bind(this), false);
  1751. this._nameCell.addEventListener("dblclick", this._openInNewTab.bind(this), false);
  1752. },
  1753. wasDetached: function()
  1754. {
  1755. this._linkifier.reset();
  1756. },
  1757. isFilteredOut: function()
  1758. {
  1759. if (this._parentView._filteredOutRequests.get(this._request))
  1760. return true;
  1761. return !this._parentView._typeFilter(this._request);
  1762. },
  1763. _onClick: function()
  1764. {
  1765. if (!this._parentView._allowRequestSelection)
  1766. this.select();
  1767. },
  1768. select: function()
  1769. {
  1770. this._parentView.dispatchEventToListeners(WebInspector.NetworkLogView.EventTypes.RequestSelected, this._request);
  1771. WebInspector.DataGridNode.prototype.select.apply(this, arguments);
  1772. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  1773. action: WebInspector.UserMetrics.UserActionNames.NetworkRequestSelected,
  1774. url: this._request.url
  1775. });
  1776. },
  1777. _highlightMatchedSubstring: function(regexp)
  1778. {
  1779. var domChanges = [];
  1780. var matchInfo = this._element.textContent.match(regexp);
  1781. if (matchInfo)
  1782. WebInspector.highlightSearchResult(this._nameCell, matchInfo.index, matchInfo[0].length, domChanges);
  1783. return domChanges;
  1784. },
  1785. _openInNewTab: function()
  1786. {
  1787. InspectorFrontendHost.openInNewTab(this._request.url);
  1788. },
  1789. get selectable()
  1790. {
  1791. return this._parentView._allowRequestSelection && !this.isFilteredOut();
  1792. },
  1793. _createDivInTD: function(columnIdentifier)
  1794. {
  1795. var td = this.createTD(columnIdentifier);
  1796. var div = td.createChild("div");
  1797. this._element.appendChild(td);
  1798. return div;
  1799. },
  1800. /**
  1801. * @param {!Element} cell
  1802. */
  1803. _createTimelineBar: function(cell)
  1804. {
  1805. cell.className = "network-graph-side";
  1806. this._barAreaElement = document.createElement("div");
  1807. // this._barAreaElement.className = "network-graph-bar-area hidden";
  1808. this._barAreaElement.className = "network-graph-bar-area";
  1809. this._barAreaElement.request = this._request;
  1810. cell.appendChild(this._barAreaElement);
  1811. this._barLeftElement = document.createElement("div");
  1812. this._barLeftElement.className = "network-graph-bar waiting";
  1813. this._barAreaElement.appendChild(this._barLeftElement);
  1814. this._barRightElement = document.createElement("div");
  1815. this._barRightElement.className = "network-graph-bar";
  1816. this._barAreaElement.appendChild(this._barRightElement);
  1817. this._labelLeftElement = document.createElement("div");
  1818. this._labelLeftElement.className = "network-graph-label waiting";
  1819. this._barAreaElement.appendChild(this._labelLeftElement);
  1820. this._labelRightElement = document.createElement("div");
  1821. this._labelRightElement.className = "network-graph-label";
  1822. this._barAreaElement.appendChild(this._labelRightElement);
  1823. cell.addEventListener("mouseover", this._refreshLabelPositions.bind(this), false);
  1824. },
  1825. refreshRequest: function()
  1826. {
  1827. this._refreshNameCell();
  1828. this._refreshMethodCell();
  1829. this._refreshStatusCell();
  1830. this._refreshSchemeCell();
  1831. this._refreshDomainCell();
  1832. this._refreshTypeCell();
  1833. this._refreshInitiatorCell();
  1834. this._refreshCookiesCell();
  1835. this._refreshSetCookiesCell();
  1836. this._refreshSizeCell();
  1837. this._refreshTimeCell();
  1838. var responseHeaderColumns = WebInspector.NetworkLogView._responseHeaderColumns;
  1839. for (var i = 0; i < responseHeaderColumns.length; ++i)
  1840. this._refreshResponseHeaderCell(responseHeaderColumns[i]);
  1841. if (this._request.cached)
  1842. this._timelineCell.addStyleClass("resource-cached");
  1843. this._element.addStyleClass("network-item");
  1844. this._element.enableStyleClass("network-error-row", this._request.failed || (this._request.statusCode >= 400));
  1845. this._updateElementStyleClasses(this._element);
  1846. },
  1847. /**
  1848. * @param {!Element} element
  1849. */
  1850. _updateElementStyleClasses: function(element)
  1851. {
  1852. var typeClassName = "network-type-" + this._request.type.name();
  1853. if (!element.hasStyleClass(typeClassName)) {
  1854. element.removeMatchingStyleClasses("network-type-\\w+");
  1855. element.addStyleClass(typeClassName);
  1856. }
  1857. },
  1858. _refreshResponseHeaderCell: function(headerName)
  1859. {
  1860. var cell = this._responseHeaderCells[headerName];
  1861. var value = this._request.responseHeaderValue(headerName);
  1862. cell.setTextAndTitle(value ? value : "");
  1863. },
  1864. _refreshNameCell: function()
  1865. {
  1866. this._nameCell.removeChildren();
  1867. if (this._request.type === WebInspector.resourceTypes.Image) {
  1868. var previewImage = document.createElement("img");
  1869. previewImage.className = "image-network-icon-preview";
  1870. this._request.populateImageSource(previewImage);
  1871. var iconElement = document.createElement("div");
  1872. iconElement.className = "icon";
  1873. iconElement.appendChild(previewImage);
  1874. } else {
  1875. var iconElement = document.createElement("img");
  1876. iconElement.className = "icon";
  1877. }
  1878. this._nameCell.appendChild(iconElement);
  1879. this._nameCell.appendChild(document.createTextNode(this._request.name()));
  1880. this._appendSubtitle(this._nameCell, this._request.path());
  1881. this._nameCell.title = this._request.url;
  1882. },
  1883. _refreshMethodCell: function()
  1884. {
  1885. this._methodCell.setTextAndTitle(this._request.requestMethod);
  1886. },
  1887. _refreshStatusCell: function()
  1888. {
  1889. this._statusCell.removeChildren();
  1890. if (this._request.failed) {
  1891. var failText = this._request.canceled ? WebInspector.UIString("(canceled)") : WebInspector.UIString("(failed)");
  1892. if (this._request.localizedFailDescription) {
  1893. this._statusCell.appendChild(document.createTextNode(failText));
  1894. this._appendSubtitle(this._statusCell, this._request.localizedFailDescription);
  1895. this._statusCell.title = failText + " " + this._request.localizedFailDescription;
  1896. } else
  1897. this._statusCell.setTextAndTitle(failText);
  1898. this._statusCell.addStyleClass("network-dim-cell");
  1899. return;
  1900. }
  1901. this._statusCell.removeStyleClass("network-dim-cell");
  1902. if (this._request.statusCode) {
  1903. this._statusCell.appendChild(document.createTextNode("" + this._request.statusCode));
  1904. this._appendSubtitle(this._statusCell, this._request.statusText);
  1905. this._statusCell.title = this._request.statusCode + " " + this._request.statusText;
  1906. if (this._request.cached)
  1907. this._statusCell.addStyleClass("network-dim-cell");
  1908. } else {
  1909. if (!this._request.isHttpFamily() && this._request.finished)
  1910. this._statusCell.setTextAndTitle(WebInspector.UIString("Success"));
  1911. else if (this._request.isPingRequest())
  1912. this._statusCell.setTextAndTitle(WebInspector.UIString("(ping)"));
  1913. else
  1914. this._statusCell.setTextAndTitle(WebInspector.UIString("(pending)"));
  1915. this._statusCell.addStyleClass("network-dim-cell");
  1916. }
  1917. },
  1918. _refreshSchemeCell: function()
  1919. {
  1920. this._schemeCell.setTextAndTitle(this._request.scheme);
  1921. },
  1922. _refreshDomainCell: function()
  1923. {
  1924. this._typeCell.setTextAndTitle(this._request.domain);
  1925. },
  1926. _refreshTypeCell: function()
  1927. {
  1928. if (this._request.mimeType) {
  1929. this._typeCell.removeStyleClass("network-dim-cell");
  1930. this._typeCell.setTextAndTitle(this._request.mimeType);
  1931. } else if (this._request.isPingRequest()) {
  1932. this._typeCell.removeStyleClass("network-dim-cell");
  1933. this._typeCell.setTextAndTitle(this._request.requestContentType() || "");
  1934. } else {
  1935. this._typeCell.addStyleClass("network-dim-cell");
  1936. this._typeCell.setTextAndTitle(WebInspector.UIString("Pending"));
  1937. }
  1938. },
  1939. _refreshInitiatorCell: function()
  1940. {
  1941. this._initiatorCell.removeChildren();
  1942. this._initiatorCell.removeStyleClass("network-dim-cell");
  1943. this._initiatorCell.removeStyleClass("network-script-initiated");
  1944. delete this._initiatorCell.request;
  1945. var request = this._request;
  1946. var initiator = request.initiatorInfo();
  1947. switch (initiator.type) {
  1948. case WebInspector.NetworkRequest.InitiatorType.Parser:
  1949. this._initiatorCell.title = initiator.url + ":" + initiator.lineNumber;
  1950. this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(initiator.url, initiator.lineNumber - 1));
  1951. this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Parser"));
  1952. break;
  1953. case WebInspector.NetworkRequest.InitiatorType.Redirect:
  1954. this._initiatorCell.title = initiator.url;
  1955. this._initiatorCell.appendChild(WebInspector.linkifyRequestAsNode(request.redirectSource));
  1956. this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Redirect"));
  1957. break;
  1958. case WebInspector.NetworkRequest.InitiatorType.Script:
  1959. var urlElement = this._linkifier.linkifyLocation(initiator.url, initiator.lineNumber - 1, initiator.columnNumber - 1);
  1960. urlElement.title = "";
  1961. this._initiatorCell.appendChild(urlElement);
  1962. this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Script"));
  1963. this._initiatorCell.addStyleClass("network-script-initiated");
  1964. this._initiatorCell.request = request;
  1965. break;
  1966. default:
  1967. this._initiatorCell.title = "";
  1968. this._initiatorCell.addStyleClass("network-dim-cell");
  1969. this._initiatorCell.setTextAndTitle(WebInspector.UIString("Other"));
  1970. }
  1971. },
  1972. _refreshCookiesCell: function()
  1973. {
  1974. var requestCookies = this._request.requestCookies;
  1975. this._cookiesCell.setTextAndTitle(requestCookies ? "" + requestCookies.length : "");
  1976. },
  1977. _refreshSetCookiesCell: function()
  1978. {
  1979. var responseCookies = this._request.responseCookies;
  1980. this._setCookiesCell.setTextAndTitle(responseCookies ? "" + responseCookies.length : "");
  1981. },
  1982. _refreshSizeCell: function()
  1983. {
  1984. if (this._request.cached) {
  1985. this._sizeCell.setTextAndTitle(WebInspector.UIString("(from cache)"));
  1986. this._sizeCell.addStyleClass("network-dim-cell");
  1987. } else {
  1988. var resourceSize = Number.bytesToString(this._request.resourceSize);
  1989. var transferSize = Number.bytesToString(this._request.transferSize);
  1990. this._sizeCell.setTextAndTitle(transferSize);
  1991. this._sizeCell.removeStyleClass("network-dim-cell");
  1992. this._appendSubtitle(this._sizeCell, resourceSize);
  1993. }
  1994. },
  1995. _refreshTimeCell: function()
  1996. {
  1997. if (this._request.duration > 0) {
  1998. this._timeCell.removeStyleClass("network-dim-cell");
  1999. this._timeCell.setTextAndTitle(Number.secondsToString(this._request.duration));
  2000. this._appendSubtitle(this._timeCell, Number.secondsToString(this._request.latency));
  2001. } else {
  2002. this._timeCell.addStyleClass("network-dim-cell");
  2003. this._timeCell.setTextAndTitle(WebInspector.UIString("Pending"));
  2004. }
  2005. },
  2006. _appendSubtitle: function(cellElement, subtitleText)
  2007. {
  2008. var subtitleElement = document.createElement("div");
  2009. subtitleElement.className = "network-cell-subtitle";
  2010. subtitleElement.textContent = subtitleText;
  2011. cellElement.appendChild(subtitleElement);
  2012. },
  2013. refreshGraph: function(calculator)
  2014. {
  2015. var percentages = calculator.computeBarGraphPercentages(this._request);
  2016. this._percentages = percentages;
  2017. this._barAreaElement.removeStyleClass("hidden");
  2018. this._updateElementStyleClasses(this._timelineCell);
  2019. this._barLeftElement.style.setProperty("left", percentages.start + "%");
  2020. this._barRightElement.style.setProperty("right", (100 - percentages.end) + "%");
  2021. this._barLeftElement.style.setProperty("right", (100 - percentages.end) + "%");
  2022. this._barRightElement.style.setProperty("left", percentages.middle + "%");
  2023. var labels = calculator.computeBarGraphLabels(this._request);
  2024. this._labelLeftElement.textContent = labels.left;
  2025. this._labelRightElement.textContent = labels.right;
  2026. var tooltip = (labels.tooltip || "");
  2027. this._barLeftElement.title = tooltip;
  2028. this._labelLeftElement.title = tooltip;
  2029. this._labelRightElement.title = tooltip;
  2030. this._barRightElement.title = tooltip;
  2031. },
  2032. _refreshLabelPositions: function()
  2033. {
  2034. if (!this._percentages)
  2035. return;
  2036. this._labelLeftElement.style.removeProperty("left");
  2037. this._labelLeftElement.style.removeProperty("right");
  2038. this._labelLeftElement.removeStyleClass("before");
  2039. this._labelLeftElement.removeStyleClass("hidden");
  2040. this._labelRightElement.style.removeProperty("left");
  2041. this._labelRightElement.style.removeProperty("right");
  2042. this._labelRightElement.removeStyleClass("after");
  2043. this._labelRightElement.removeStyleClass("hidden");
  2044. const labelPadding = 10;
  2045. const barRightElementOffsetWidth = this._barRightElement.offsetWidth;
  2046. const barLeftElementOffsetWidth = this._barLeftElement.offsetWidth;
  2047. if (this._barLeftElement) {
  2048. var leftBarWidth = barLeftElementOffsetWidth - labelPadding;
  2049. var rightBarWidth = (barRightElementOffsetWidth - barLeftElementOffsetWidth) - labelPadding;
  2050. } else {
  2051. var leftBarWidth = (barLeftElementOffsetWidth - barRightElementOffsetWidth) - labelPadding;
  2052. var rightBarWidth = barRightElementOffsetWidth - labelPadding;
  2053. }
  2054. const labelLeftElementOffsetWidth = this._labelLeftElement.offsetWidth;
  2055. const labelRightElementOffsetWidth = this._labelRightElement.offsetWidth;
  2056. const labelBefore = (labelLeftElementOffsetWidth > leftBarWidth);
  2057. const labelAfter = (labelRightElementOffsetWidth > rightBarWidth);
  2058. const graphElementOffsetWidth = this._timelineCell.offsetWidth;
  2059. if (labelBefore && (graphElementOffsetWidth * (this._percentages.start / 100)) < (labelLeftElementOffsetWidth + 10))
  2060. var leftHidden = true;
  2061. if (labelAfter && (graphElementOffsetWidth * ((100 - this._percentages.end) / 100)) < (labelRightElementOffsetWidth + 10))
  2062. var rightHidden = true;
  2063. if (barLeftElementOffsetWidth == barRightElementOffsetWidth) {
  2064. // The left/right label data are the same, so a before/after label can be replaced by an on-bar label.
  2065. if (labelBefore && !labelAfter)
  2066. leftHidden = true;
  2067. else if (labelAfter && !labelBefore)
  2068. rightHidden = true;
  2069. }
  2070. if (labelBefore) {
  2071. if (leftHidden)
  2072. this._labelLeftElement.addStyleClass("hidden");
  2073. this._labelLeftElement.style.setProperty("right", (100 - this._percentages.start) + "%");
  2074. this._labelLeftElement.addStyleClass("before");
  2075. } else {
  2076. this._labelLeftElement.style.setProperty("left", this._percentages.start + "%");
  2077. this._labelLeftElement.style.setProperty("right", (100 - this._percentages.middle) + "%");
  2078. }
  2079. if (labelAfter) {
  2080. if (rightHidden)
  2081. this._labelRightElement.addStyleClass("hidden");
  2082. this._labelRightElement.style.setProperty("left", this._percentages.end + "%");
  2083. this._labelRightElement.addStyleClass("after");
  2084. } else {
  2085. this._labelRightElement.style.setProperty("left", this._percentages.middle + "%");
  2086. this._labelRightElement.style.setProperty("right", (100 - this._percentages.end) + "%");
  2087. }
  2088. },
  2089. __proto__: WebInspector.DataGridNode.prototype
  2090. }
  2091. /**
  2092. * @param {WebInspector.NetworkRequest} request
  2093. * @return {boolean}
  2094. */
  2095. WebInspector.NetworkLogView._trivialTypeFilter = function(request)
  2096. {
  2097. return true;
  2098. }
  2099. /**
  2100. * @param {!Object.<string, boolean>} allowedTypes
  2101. * @param {WebInspector.NetworkRequest} request
  2102. * @return {boolean}
  2103. */
  2104. WebInspector.NetworkLogView._typeFilter = function(allowedTypes, request)
  2105. {
  2106. return request.type.name() in allowedTypes;
  2107. }
  2108. WebInspector.NetworkDataGridNode.NameComparator = function(a, b)
  2109. {
  2110. var aFileName = a._request.name();
  2111. var bFileName = b._request.name();
  2112. if (aFileName > bFileName)
  2113. return 1;
  2114. if (bFileName > aFileName)
  2115. return -1;
  2116. return 0;
  2117. }
  2118. WebInspector.NetworkDataGridNode.SizeComparator = function(a, b)
  2119. {
  2120. if (b._request.cached && !a._request.cached)
  2121. return 1;
  2122. if (a._request.cached && !b._request.cached)
  2123. return -1;
  2124. return a._request.transferSize - b._request.transferSize;
  2125. }
  2126. WebInspector.NetworkDataGridNode.InitiatorComparator = function(a, b)
  2127. {
  2128. var aInitiator = a._request.initiatorInfo();
  2129. var bInitiator = b._request.initiatorInfo();
  2130. if (aInitiator.type < bInitiator.type)
  2131. return -1;
  2132. if (aInitiator.type > bInitiator.type)
  2133. return 1;
  2134. if (aInitiator.source < bInitiator.source)
  2135. return -1;
  2136. if (aInitiator.source > bInitiator.source)
  2137. return 1;
  2138. if (aInitiator.lineNumber < bInitiator.lineNumber)
  2139. return -1;
  2140. if (aInitiator.lineNumber > bInitiator.lineNumber)
  2141. return 1;
  2142. if (aInitiator.columnNumber < bInitiator.columnNumber)
  2143. return -1;
  2144. if (aInitiator.columnNumber > bInitiator.columnNumber)
  2145. return 1;
  2146. return 0;
  2147. }
  2148. WebInspector.NetworkDataGridNode.RequestCookiesCountComparator = function(a, b)
  2149. {
  2150. var aScore = a._request.requestCookies ? a._request.requestCookies.length : 0;
  2151. var bScore = b._request.requestCookies ? b._request.requestCookies.length : 0;
  2152. return aScore - bScore;
  2153. }
  2154. WebInspector.NetworkDataGridNode.ResponseCookiesCountComparator = function(a, b)
  2155. {
  2156. var aScore = a._request.responseCookies ? a._request.responseCookies.length : 0;
  2157. var bScore = b._request.responseCookies ? b._request.responseCookies.length : 0;
  2158. return aScore - bScore;
  2159. }
  2160. WebInspector.NetworkDataGridNode.RequestPropertyComparator = function(propertyName, revert, a, b)
  2161. {
  2162. var aValue = a._request[propertyName];
  2163. var bValue = b._request[propertyName];
  2164. if (aValue > bValue)
  2165. return revert ? -1 : 1;
  2166. if (bValue > aValue)
  2167. return revert ? 1 : -1;
  2168. return 0;
  2169. }