Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/network_log/HAREntry.js

Issue 2758673002: [DevTools] Extract NetworkLog and HAREntry to a separate network_log module (Closed)
Patch Set: rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 18 matching lines...) Expand all
29 */ 29 */
30 // See http://www.softwareishard.com/blog/har-12-spec/ 30 // See http://www.softwareishard.com/blog/har-12-spec/
31 // for HAR specification. 31 // for HAR specification.
32 32
33 // FIXME: Some fields are not yet supported due to back-end limitations. 33 // FIXME: Some fields are not yet supported due to back-end limitations.
34 // See https://bugs.webkit.org/show_bug.cgi?id=58127 for details. 34 // See https://bugs.webkit.org/show_bug.cgi?id=58127 for details.
35 35
36 /** 36 /**
37 * @unrestricted 37 * @unrestricted
38 */ 38 */
39 SDK.HAREntry = class { 39 NetworkLog.HAREntry = class {
40 /** 40 /**
41 * @param {!SDK.NetworkRequest} request 41 * @param {!SDK.NetworkRequest} request
42 */ 42 */
43 constructor(request) { 43 constructor(request) {
44 this._request = request; 44 this._request = request;
45 } 45 }
46 46
47 /** 47 /**
48 * @param {number} time 48 * @param {number} time
49 * @return {number} 49 * @return {number}
50 */ 50 */
51 static _toMilliseconds(time) { 51 static _toMilliseconds(time) {
52 return time === -1 ? -1 : time * 1000; 52 return time === -1 ? -1 : time * 1000;
53 } 53 }
54 54
55 /** 55 /**
56 * @return {!Object} 56 * @return {!Object}
57 */ 57 */
58 build() { 58 build() {
59 var ipAddress = this._request.remoteAddress(); 59 var ipAddress = this._request.remoteAddress();
60 var portPositionInString = ipAddress.lastIndexOf(':'); 60 var portPositionInString = ipAddress.lastIndexOf(':');
61 if (portPositionInString !== -1) 61 if (portPositionInString !== -1)
62 ipAddress = ipAddress.substr(0, portPositionInString); 62 ipAddress = ipAddress.substr(0, portPositionInString);
63 63
64 var entry = { 64 var entry = {
65 startedDateTime: SDK.HARLog.pseudoWallTime(this._request, this._request.st artTime), 65 startedDateTime: NetworkLog.HARLog.pseudoWallTime(this._request, this._req uest.startTime),
66 time: this._request.timing ? SDK.HAREntry._toMilliseconds(this._request.du ration) : 0, 66 time: this._request.timing ? NetworkLog.HAREntry._toMilliseconds(this._req uest.duration) : 0,
67 request: this._buildRequest(), 67 request: this._buildRequest(),
68 response: this._buildResponse(), 68 response: this._buildResponse(),
69 cache: {}, // Not supported yet. 69 cache: {}, // Not supported yet.
70 timings: this._buildTimings(), 70 timings: this._buildTimings(),
71 serverIPAddress: ipAddress 71 serverIPAddress: ipAddress
72 }; 72 };
73 73
74 if (this._request.connectionId !== '0') 74 if (this._request.connectionId !== '0')
75 entry.connection = this._request.connectionId; 75 entry.connection = this._request.connectionId;
76 var page = SDK.networkLog.pageLoadForRequest(this._request); 76 var page = NetworkLog.networkLog.pageLoadForRequest(this._request);
77 if (page) 77 if (page)
78 entry.pageref = 'page_' + page.id; 78 entry.pageref = 'page_' + page.id;
79 return entry; 79 return entry;
80 } 80 }
81 81
82 /** 82 /**
83 * @return {!Object} 83 * @return {!Object}
84 */ 84 */
85 _buildRequest() { 85 _buildRequest() {
86 var headersText = this._request.requestHeadersText(); 86 var headersText = this._request.requestHeadersText();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 var dns = -1; 159 var dns = -1;
160 if (timing.dnsStart >= 0) 160 if (timing.dnsStart >= 0)
161 dns = firstNonNegative([timing.connectStart, timing.sendStart]) - timing.d nsStart; 161 dns = firstNonNegative([timing.connectStart, timing.sendStart]) - timing.d nsStart;
162 162
163 var connect = -1; 163 var connect = -1;
164 if (timing.connectStart >= 0) 164 if (timing.connectStart >= 0)
165 connect = timing.sendStart - timing.connectStart; 165 connect = timing.sendStart - timing.connectStart;
166 166
167 var send = timing.sendEnd - timing.sendStart; 167 var send = timing.sendEnd - timing.sendStart;
168 var wait = timing.receiveHeadersEnd - timing.sendEnd; 168 var wait = timing.receiveHeadersEnd - timing.sendEnd;
169 var receive = SDK.HAREntry._toMilliseconds(this._request.duration) - timing. receiveHeadersEnd; 169 var receive = NetworkLog.HAREntry._toMilliseconds(this._request.duration) - timing.receiveHeadersEnd;
170 170
171 var ssl = -1; 171 var ssl = -1;
172 if (timing.sslStart >= 0 && timing.sslEnd >= 0) 172 if (timing.sslStart >= 0 && timing.sslEnd >= 0)
173 ssl = timing.sslEnd - timing.sslStart; 173 ssl = timing.sslEnd - timing.sslStart;
174 174
175 return {blocked: blocked, dns: dns, connect: connect, send: send, wait: wait , receive: receive, ssl: ssl}; 175 return {blocked: blocked, dns: dns, connect: connect, send: send, wait: wait , receive: receive, ssl: ssl};
176 } 176 }
177 177
178 /** 178 /**
179 * @return {!Object} 179 * @return {!Object}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 /** 212 /**
213 * @param {!SDK.Cookie} cookie 213 * @param {!SDK.Cookie} cookie
214 * @return {!Object} 214 * @return {!Object}
215 */ 215 */
216 _buildCookie(cookie) { 216 _buildCookie(cookie) {
217 var c = { 217 var c = {
218 name: cookie.name(), 218 name: cookie.name(),
219 value: cookie.value(), 219 value: cookie.value(),
220 path: cookie.path(), 220 path: cookie.path(),
221 domain: cookie.domain(), 221 domain: cookie.domain(),
222 expires: cookie.expiresDate(SDK.HARLog.pseudoWallTime(this._request, this. _request.startTime)), 222 expires: cookie.expiresDate(NetworkLog.HARLog.pseudoWallTime(this._request , this._request.startTime)),
223 httpOnly: cookie.httpOnly(), 223 httpOnly: cookie.httpOnly(),
224 secure: cookie.secure() 224 secure: cookie.secure()
225 }; 225 };
226 if (cookie.sameSite()) 226 if (cookie.sameSite())
227 c.sameSite = cookie.sameSite(); 227 c.sameSite = cookie.sameSite();
228 return c; 228 return c;
229 } 229 }
230 230
231 /** 231 /**
232 * @return {number} 232 * @return {number}
(...skipping 22 matching lines...) Expand all
255 if (!this._request.responseHeadersText) 255 if (!this._request.responseHeadersText)
256 return; 256 return;
257 return this._request.resourceSize - this.responseBodySize; 257 return this._request.resourceSize - this.responseBodySize;
258 } 258 }
259 }; 259 };
260 260
261 261
262 /** 262 /**
263 * @unrestricted 263 * @unrestricted
264 */ 264 */
265 SDK.HARLog = class { 265 NetworkLog.HARLog = class {
266 /** 266 /**
267 * @param {!Array.<!SDK.NetworkRequest>} requests 267 * @param {!Array.<!SDK.NetworkRequest>} requests
268 */ 268 */
269 constructor(requests) { 269 constructor(requests) {
270 this._requests = requests; 270 this._requests = requests;
271 } 271 }
272 272
273 /** 273 /**
274 * @param {!SDK.NetworkRequest} request 274 * @param {!SDK.NetworkRequest} request
275 * @param {number} monotonicTime 275 * @param {number} monotonicTime
(...skipping 22 matching lines...) Expand all
298 } 298 }
299 299
300 /** 300 /**
301 * @return {!Array.<!Object>} 301 * @return {!Array.<!Object>}
302 */ 302 */
303 _buildPages() { 303 _buildPages() {
304 var seenIdentifiers = {}; 304 var seenIdentifiers = {};
305 var pages = []; 305 var pages = [];
306 for (var i = 0; i < this._requests.length; ++i) { 306 for (var i = 0; i < this._requests.length; ++i) {
307 var request = this._requests[i]; 307 var request = this._requests[i];
308 var page = SDK.networkLog.pageLoadForRequest(request); 308 var page = NetworkLog.networkLog.pageLoadForRequest(request);
309 if (!page || seenIdentifiers[page.id]) 309 if (!page || seenIdentifiers[page.id])
310 continue; 310 continue;
311 seenIdentifiers[page.id] = true; 311 seenIdentifiers[page.id] = true;
312 pages.push(this._convertPage(page, request)); 312 pages.push(this._convertPage(page, request));
313 } 313 }
314 return pages; 314 return pages;
315 } 315 }
316 316
317 /** 317 /**
318 * @param {!SDK.PageLoad} page 318 * @param {!NetworkLog.PageLoad} page
319 * @param {!SDK.NetworkRequest} request 319 * @param {!SDK.NetworkRequest} request
320 * @return {!Object} 320 * @return {!Object}
321 */ 321 */
322 _convertPage(page, request) { 322 _convertPage(page, request) {
323 return { 323 return {
324 startedDateTime: SDK.HARLog.pseudoWallTime(request, page.startTime), 324 startedDateTime: NetworkLog.HARLog.pseudoWallTime(request, page.startTime) ,
325 id: 'page_' + page.id, 325 id: 'page_' + page.id,
326 title: page.url, // We don't have actual page title here. URL is probably better than nothing. 326 title: page.url, // We don't have actual page title here. URL is probably better than nothing.
327 pageTimings: { 327 pageTimings: {
328 onContentLoad: this._pageEventTime(page, page.contentLoadTime), 328 onContentLoad: this._pageEventTime(page, page.contentLoadTime),
329 onLoad: this._pageEventTime(page, page.loadTime) 329 onLoad: this._pageEventTime(page, page.loadTime)
330 } 330 }
331 }; 331 };
332 } 332 }
333 333
334 /** 334 /**
335 * @param {!SDK.NetworkRequest} request 335 * @param {!SDK.NetworkRequest} request
336 * @return {!Object} 336 * @return {!Object}
337 */ 337 */
338 _convertResource(request) { 338 _convertResource(request) {
339 return (new SDK.HAREntry(request)).build(); 339 return (new NetworkLog.HAREntry(request)).build();
340 } 340 }
341 341
342 /** 342 /**
343 * @param {!SDK.PageLoad} page 343 * @param {!NetworkLog.PageLoad} page
344 * @param {number} time 344 * @param {number} time
345 * @return {number} 345 * @return {number}
346 */ 346 */
347 _pageEventTime(page, time) { 347 _pageEventTime(page, time) {
348 var startTime = page.startTime; 348 var startTime = page.startTime;
349 if (time === -1 || startTime === -1) 349 if (time === -1 || startTime === -1)
350 return -1; 350 return -1;
351 return SDK.HAREntry._toMilliseconds(time - startTime); 351 return NetworkLog.HAREntry._toMilliseconds(time - startTime);
352 } 352 }
353 }; 353 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698