NetworkPanel.js 89 KB

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