Skip to content

Commit

Permalink
core(lantern): use securityOrigin on record (GoogleChrome#5071)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and kdzwinel committed Aug 16, 2018
1 parent 591a739 commit 2926aff
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
7 changes: 0 additions & 7 deletions lighthouse-core/lib/dependency-graph/network-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ class NetworkNode extends Node {
* @return {LH.WebInspector.NetworkRequest}
*/
get record() {
// Ensure that the record has an origin value
if (this._record.origin === undefined) {
this._record.origin = this._record.parsedURL
? `${this._record.parsedURL.scheme}://${this._record.parsedURL.host}`
: null;
}

return this._record;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = class ConnectionPool {
return this._connectionsByRecord.get(record);
}

const origin = String(record.origin);
const origin = String(record.parsedURL.securityOrigin());
/** @type {TcpConnection[]} */
const connections = this._connectionsByOrigin.get(origin) || [];
const wasConnectionWarm = !!this._connectionReusedByRequestId.get(record.requestId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NetworkAnalyzer {
static groupByOrigin(records) {
const grouped = new Map();
records.forEach(item => {
const key = item.origin;
const key = item.parsedURL.securityOrigin();
const group = grouped.get(key) || [];
group.push(item);
grouped.set(key, group);
Expand Down Expand Up @@ -179,7 +179,7 @@ class NetworkAnalyzer {
if (!Number.isFinite(timing.sendEnd) || timing.sendEnd < 0) return;

const ttfb = timing.receiveHeadersEnd - timing.sendEnd;
const origin = record.origin;
const origin = record.parsedURL.securityOrigin();
const rtt = rttByOrigin.get(origin) || rttByOrigin.get(NetworkAnalyzer.SUMMARY) || 0;
return Math.max(ttfb - rtt, 0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Byte efficiency base audit', () => {
const networkRecord = {
requestId: 1,
url: 'http://example.com/',
parsedURL: {scheme: 'http'},
parsedURL: {scheme: 'http', securityOrigin: () => 'http://example.com'},
_transferSize: 400000,
_timing: {receiveHeadersEnd: 0},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('Render blocking resources audit', () => {
beforeEach(() => {
requestId = 1;
record = props => {
const ret = Object.assign({parsedURL: {}, requestId: requestId++}, props);
const parsedURL = {securityOrigin: () => 'http://example.com'};
const ret = Object.assign({parsedURL, requestId: requestId++}, props);
Object.defineProperty(ret, 'transferSize', {
get() {
return ret._transferSize;
Expand All @@ -62,7 +63,7 @@ describe('Render blocking resources audit', () => {
});

it('computes savings from deferring', () => {
const serverResponseTimeByOrigin = new Map([['undefined://undefined', 100]]);
const serverResponseTimeByOrigin = new Map([['http://example.com', 100]]);
const simulator = new Simulator({rtt: 1000, serverResponseTimeByOrigin});
const documentNode = new NetworkNode(record({_transferSize: 4000}));
const styleNode = new NetworkNode(record({_transferSize: 3000}));
Expand All @@ -81,7 +82,7 @@ describe('Render blocking resources audit', () => {
});

it('computes savings from inlining', () => {
const serverResponseTimeByOrigin = new Map([['undefined://undefined', 100]]);
const serverResponseTimeByOrigin = new Map([['http://example.com', 100]]);
const simulator = new Simulator({rtt: 1000, serverResponseTimeByOrigin});
const documentNode = new NetworkNode(record({_transferSize: 10 * 1000}));
const styleNode = new NetworkNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {

function addOriginToRecord(record) {
const parsed = record.parsedURL || {};
record.origin = `${parsed.scheme}://${parsed.host}`;
parsed.securityOrigin = () => `${parsed.scheme}://${parsed.host}`;
if (!record.parsedURL) record.parsedURL = parsed;
}

function createRecord(opts) {
const url = opts.url || 'https://example.com';
return Object.assign(
{
url,
origin: url.match(/.*\.com/)[0],
requestId: recordId++,
connectionId: 0,
connectionReused: false,
startTime: 0.01,
endTime: 0.01,
transferSize: 0,
protocol: 'http/1.1',
parsedURL: {scheme: url.match(/https?/)[0]},
parsedURL: {scheme: url.match(/https?/)[0], securityOrigin: () => url.match(/.*\.com/)[0]},
_timing: opts.timing || null,
},
opts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ function request(opts) {
return Object.assign({
requestId: opts.requestId || nextRequestId++,
url,
origin: url,
transferSize: opts.transferSize || 1000,
parsedURL: {scheme},
parsedURL: {scheme, securityOrigin: () => url},
_timing: opts.timing,
}, opts);
}
Expand Down
2 changes: 1 addition & 1 deletion typings/web-inspector.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ declare global {
url: string;
_url: string;
protocol: string;
origin: string | null;
parsedURL: ParsedURL;

startTime: number;
Expand Down Expand Up @@ -54,6 +53,7 @@ declare global {
export interface ParsedURL {
scheme: string;
host: string;
securityOrigin(): string;
}

export interface ResourceType {
Expand Down

0 comments on commit 2926aff

Please sign in to comment.