зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1690221 - [devtools] Remove unused chrome connector. r=bomsy
Differential Revision: https://phabricator.services.mozilla.com/D103749
This commit is contained in:
Родитель
f3bf06a03a
Коммит
1e919fbc8d
|
@ -1,115 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ACTIVITY_TYPE } = require("devtools/client/netmonitor/src/constants");
|
||||
const {
|
||||
CDPConnector,
|
||||
} = require("devtools/client/netmonitor/src/connector/chrome/events");
|
||||
|
||||
/**
|
||||
* DO NOT DELETE THIS FILE
|
||||
*
|
||||
* The ChromeConnector is currently not used, but is kept in tree to illustrate
|
||||
* the Connector abstraction.
|
||||
*/
|
||||
class ChromeConnector {
|
||||
constructor() {
|
||||
// Internal properties
|
||||
this.payloadQueue = [];
|
||||
this.connector = undefined;
|
||||
|
||||
// Public methods
|
||||
this.connect = this.connect.bind(this);
|
||||
this.disconnect = this.disconnect.bind(this);
|
||||
this.willNavigate = this.willNavigate.bind(this);
|
||||
this.sendHTTPRequest = this.sendHTTPRequest.bind(this);
|
||||
this.setPreferences = this.setPreferences.bind(this);
|
||||
this.triggerActivity = this.triggerActivity.bind(this);
|
||||
this.viewSourceInDebugger = this.viewSourceInDebugger.bind(this);
|
||||
}
|
||||
|
||||
async connect(connection, actions, getState) {
|
||||
const { tabConnection } = connection;
|
||||
this.actions = actions;
|
||||
this.connector = new CDPConnector();
|
||||
this.connector.setup(tabConnection, this.actions);
|
||||
this.connector.willNavigate(this.willNavigate);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.connector.disconnect();
|
||||
}
|
||||
|
||||
pause() {
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
resume() {
|
||||
this.setup();
|
||||
}
|
||||
|
||||
enableActions(enable) {
|
||||
// TODO : implement.
|
||||
}
|
||||
|
||||
/**
|
||||
* currently all events are about "navigation" is not support on CDP
|
||||
*/
|
||||
willNavigate() {
|
||||
this.actions.batchReset();
|
||||
this.actions.clearRequests();
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a specific "activity" to be performed by the frontend.
|
||||
* This can be, for example, triggering reloads or enabling/disabling cache.
|
||||
*
|
||||
* @param {number} type The activity type. See the ACTIVITY_TYPE const.
|
||||
* @return {object} A promise resolved once the activity finishes and the frontend
|
||||
* is back into "standby" mode.
|
||||
*/
|
||||
triggerActivity(type) {
|
||||
switch (type) {
|
||||
case ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED:
|
||||
case ACTIVITY_TYPE.RELOAD.WITH_CACHE_DEFAULT:
|
||||
return this.connector.reset().then(() =>
|
||||
this.connector.Page.reload().then(() => {
|
||||
this.currentActivity = ACTIVITY_TYPE.NONE;
|
||||
})
|
||||
);
|
||||
}
|
||||
this.currentActivity = ACTIVITY_TYPE.NONE;
|
||||
return Promise.reject(new Error("Invalid activity type"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HTTP request data payload
|
||||
*
|
||||
* @param {object} data data payload would like to sent to backend
|
||||
*/
|
||||
sendHTTPRequest(data) {
|
||||
// TODO : not support. currently didn't provide this feature in CDP API.
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the list of block requests
|
||||
*
|
||||
* @param {array} urls An array of URLS which are blocked
|
||||
*/
|
||||
setBlockedUrls(urls) {
|
||||
// TODO : implement.
|
||||
}
|
||||
|
||||
setPreferences() {
|
||||
// TODO : implement.
|
||||
}
|
||||
|
||||
viewSourceInDebugger() {
|
||||
// TODO : implement.
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChromeConnector;
|
|
@ -1,126 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
let bulkLoader = undefined;
|
||||
|
||||
const PriorityLevels = { Critical: 1, Major: 2, Normal: 3, None: 0 };
|
||||
|
||||
class Scheduler {
|
||||
constructor() {
|
||||
this.busy = false;
|
||||
this.queue = [];
|
||||
}
|
||||
|
||||
sync(task) {
|
||||
this.queue.push(task);
|
||||
if (!this.busy) {
|
||||
return this.dequeue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
dequeue() {
|
||||
const self = this;
|
||||
const recursive = resolve => {
|
||||
self.dequeue();
|
||||
};
|
||||
this.busy = true;
|
||||
const next = this.queue.shift();
|
||||
if (next) {
|
||||
next().then(recursive, recursive);
|
||||
} else {
|
||||
this.busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// singleton class
|
||||
const getBulkLoader = () => {
|
||||
const mappingPriority = (priority, options) => {
|
||||
switch (priority) {
|
||||
case PriorityLevels.Critical:
|
||||
return options.Critical;
|
||||
case PriorityLevels.Major:
|
||||
return options.Major;
|
||||
case PriorityLevels.Normal:
|
||||
return options.Normal;
|
||||
case PriorityLevels.None:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return options.None;
|
||||
};
|
||||
|
||||
const getTimeoutMS = priority => {
|
||||
const delay = { Critical: 3000, Major: 1000, Normal: 500, None: 100 };
|
||||
return mappingPriority(priority, delay);
|
||||
};
|
||||
|
||||
const getDelayStartMS = priority => {
|
||||
const delay = { Critical: 1, Major: 50, Normal: 100, None: 500 };
|
||||
return mappingPriority(priority, delay);
|
||||
};
|
||||
|
||||
const LoaderPromise = (priority, callback) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ms = getTimeoutMS(priority);
|
||||
// Set up the real work
|
||||
setTimeout(() => callback(resolve, reject), getDelayStartMS(priority));
|
||||
|
||||
// Set up the timeout
|
||||
setTimeout(() => {
|
||||
reject("Promise timed out after " + ms + " ms");
|
||||
}, ms);
|
||||
});
|
||||
};
|
||||
|
||||
// TODO : recovery thread after all tasks finished.
|
||||
class Thread {
|
||||
constructor() {
|
||||
this.scheduler = new Scheduler();
|
||||
}
|
||||
|
||||
addTask(callback, priority) {
|
||||
this.scheduler.sync(() => {
|
||||
return LoaderPromise(
|
||||
!priority ? PriorityLevels.None : priority,
|
||||
(resolve, reject) => callback(resolve, reject)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class BulkLoader {
|
||||
constructor() {
|
||||
this.threads = new Map();
|
||||
this.tasks = [];
|
||||
}
|
||||
|
||||
add(id, callback, priority) {
|
||||
let thread = this.threads.get(priority);
|
||||
if (!this.threads.has(priority)) {
|
||||
thread = new Thread();
|
||||
this.threads.set(priority, thread);
|
||||
}
|
||||
this.tasks.push({ id, priority, task: callback, isFinished: false });
|
||||
return thread.addTask(callback, priority);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.threads.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!bulkLoader) {
|
||||
bulkLoader = new BulkLoader();
|
||||
}
|
||||
|
||||
return bulkLoader;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getBulkLoader,
|
||||
PriorityLevels,
|
||||
};
|
|
@ -1,244 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
const {
|
||||
EVENTS,
|
||||
TEST_EVENTS,
|
||||
} = require("devtools/client/netmonitor/src/constants");
|
||||
const {
|
||||
Payloads,
|
||||
} = require("devtools/client/netmonitor/src/connector/chrome/utils");
|
||||
const {
|
||||
getBulkLoader,
|
||||
PriorityLevels,
|
||||
} = require("devtools/client/netmonitor/src/connector/chrome/bulk-loader");
|
||||
|
||||
class CDPConnector {
|
||||
constructor() {
|
||||
this.payloads = new Payloads();
|
||||
this.onNetworkUpdate = this.onNetworkUpdate.bind(this);
|
||||
this.onResponseReceived = this.onResponseReceived.bind(this);
|
||||
this.onDataReceived = this.onDataReceived.bind(this);
|
||||
this.onLoadingFinished = this.onLoadingFinished.bind(this);
|
||||
this.onLoadingFailed = this.onLoadingFailed.bind(this);
|
||||
this.update = this.update.bind(this);
|
||||
}
|
||||
|
||||
setup(connection, actions) {
|
||||
const { Network, Page } = connection;
|
||||
this.Network = Network;
|
||||
this.Page = Page;
|
||||
this.actions = actions;
|
||||
Network.requestWillBeSent(this.onNetworkUpdate);
|
||||
Network.responseReceived(this.onResponseReceived);
|
||||
Network.dataReceived(this.onDataReceived);
|
||||
Network.loadingFinished(this.onLoadingFinished);
|
||||
Network.loadingFailed(this.onLoadingFailed);
|
||||
Network.enable();
|
||||
Page.enable();
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.Network.disable();
|
||||
this.Page.disable();
|
||||
this.payloads.clear();
|
||||
}
|
||||
|
||||
async reset() {
|
||||
return Promise.all([
|
||||
this.Network.disable(),
|
||||
this.Page.disable(),
|
||||
this.payloads.clear(),
|
||||
this.Network.enable(),
|
||||
this.Page.enable(),
|
||||
]);
|
||||
}
|
||||
|
||||
willNavigate(event) {
|
||||
// not support
|
||||
}
|
||||
|
||||
onNetworkUpdate(params) {
|
||||
const { requestId } = params;
|
||||
const payload = this.payloads.add(requestId);
|
||||
return payload.update(params).then(([request, header, postData]) => {
|
||||
const bulkloader = getBulkLoader();
|
||||
bulkloader.add(
|
||||
requestId,
|
||||
(resolve, reject) =>
|
||||
this.addRequest(requestId, request).then(() => {
|
||||
this.updateRequestHeader(requestId, header);
|
||||
this.updatePostData(requestId, postData);
|
||||
resolve();
|
||||
}),
|
||||
PriorityLevels.Critical
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
onResponseReceived(params) {
|
||||
const { requestId } = params;
|
||||
const payload = this.payloads.get(requestId);
|
||||
return payload
|
||||
.update(params)
|
||||
.then(([request, header, postData, state, timings]) => {
|
||||
const loader = getBulkLoader();
|
||||
loader.add(
|
||||
requestId,
|
||||
resolve => {
|
||||
this.updateResponseHeader(requestId, header);
|
||||
this.updateResponseState(requestId, state);
|
||||
this.updateResponseTiming(requestId, timings);
|
||||
this.getResponseContent(params);
|
||||
resolve();
|
||||
},
|
||||
PriorityLevels.Major
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
onDataReceived(params) {
|
||||
const { requestId } = params;
|
||||
const payload = this.payloads.get(requestId);
|
||||
payload.update(params);
|
||||
}
|
||||
|
||||
onLoadingFinished(params) {
|
||||
const { requestId } = params;
|
||||
const payload = this.payloads.get(requestId);
|
||||
if (payload) {
|
||||
payload.log("LoadingFinished", params);
|
||||
}
|
||||
// TODO: verify getCookie method.
|
||||
//
|
||||
}
|
||||
|
||||
updateRequestHeader(requestId, header) {
|
||||
if (!header) {
|
||||
return;
|
||||
}
|
||||
this.update(requestId, {
|
||||
requestHeaders: header,
|
||||
}).then(() => {
|
||||
window.emit(TEST_EVENTS.RECEIVED_REQUEST_HEADERS, header);
|
||||
});
|
||||
}
|
||||
|
||||
updateResponseTiming(requestId, timings) {
|
||||
if (!timings) {
|
||||
return;
|
||||
}
|
||||
this.update(requestId, {
|
||||
eventTimings: timings,
|
||||
}).then(() => {
|
||||
window.emit(EVENTS.RECEIVED_EVENT_TIMINGS, requestId);
|
||||
});
|
||||
}
|
||||
|
||||
updateResponseState(requestId, state) {
|
||||
this.update(requestId, state).then(() => {
|
||||
window.emit(TEST_EVENTS.STARTED_RECEIVING_RESPONSE, requestId);
|
||||
});
|
||||
}
|
||||
|
||||
updateResponseHeader(requestId, header) {
|
||||
if (!header) {
|
||||
return;
|
||||
}
|
||||
this.update(requestId, {
|
||||
responseHeaders: header,
|
||||
}).then(() => {
|
||||
window.emit(TEST_EVENTS.RECEIVED_RESPONSE_HEADERS, header);
|
||||
});
|
||||
}
|
||||
|
||||
onLoadingFailed(params) {
|
||||
const { requestId } = params;
|
||||
const payload = this.payloads.get(requestId);
|
||||
if (payload) {
|
||||
payload.log("LoadingFailed", params);
|
||||
}
|
||||
// console.log(params.requestId);
|
||||
}
|
||||
|
||||
async getResponseContent(params) {
|
||||
const { requestId, response } = params;
|
||||
|
||||
return this.Network.getResponseBody({ requestId }).then(content => {
|
||||
const payload = this.payloads.get(requestId);
|
||||
return payload
|
||||
.update({ requestId, response, content })
|
||||
.then(
|
||||
([request, header, postData, state, timings, responseContent]) => {
|
||||
const loader = getBulkLoader();
|
||||
loader.add(
|
||||
requestId,
|
||||
resolve => {
|
||||
this.updateResponseContent(requestId, responseContent);
|
||||
return resolve();
|
||||
},
|
||||
PriorityLevels.Normal
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
updateResponseContent(requestId, payload) {
|
||||
if (!payload) {
|
||||
return;
|
||||
}
|
||||
this.actions.updateRequest(requestId, payload, true).then(() => {
|
||||
window.emit(TEST_EVENTS.RECEIVED_RESPONSE_CONTENT, requestId);
|
||||
});
|
||||
}
|
||||
|
||||
updatePostData(requestId, postData) {
|
||||
if (!postData) {
|
||||
return;
|
||||
}
|
||||
this.update(requestId, {
|
||||
requestPostData: postData,
|
||||
}).then(() => {
|
||||
window.emit(TEST_EVENTS.RECEIVED_REQUEST_POST_DATA, requestId);
|
||||
});
|
||||
}
|
||||
|
||||
async update(id, payload) {
|
||||
return this.actions.updateRequest(id, payload, true);
|
||||
}
|
||||
|
||||
async addRequest(id, data) {
|
||||
const {
|
||||
method,
|
||||
url,
|
||||
isXHR,
|
||||
cause,
|
||||
startedDateTime,
|
||||
fromCache,
|
||||
fromServiceWorker,
|
||||
} = data;
|
||||
|
||||
this.actions
|
||||
.addRequest(
|
||||
id,
|
||||
{
|
||||
startedMs: startedDateTime,
|
||||
method,
|
||||
url,
|
||||
isXHR,
|
||||
cause,
|
||||
fromCache,
|
||||
fromServiceWorker,
|
||||
},
|
||||
true
|
||||
)
|
||||
.then(() => window.emit(EVENTS.REQUEST_ADDED, id));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CDPConnector,
|
||||
};
|
|
@ -1,101 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
function mappingCallFrames(callFrames) {
|
||||
const stacktrace = [];
|
||||
callFrames.forEach(frame => {
|
||||
const { functionName, scriptId, url, lineNumber, columnNumber } = frame;
|
||||
const stack = {
|
||||
scriptId,
|
||||
filename: url,
|
||||
lineNumber,
|
||||
columnNumber,
|
||||
functionName,
|
||||
};
|
||||
stacktrace.push(stack);
|
||||
});
|
||||
return stacktrace;
|
||||
}
|
||||
|
||||
function Cause(initiator) {
|
||||
const { url, type, stack } = initiator;
|
||||
const { callFrames } = stack || {};
|
||||
if (!stack || !callFrames.length) {
|
||||
return undefined;
|
||||
}
|
||||
const cause = {
|
||||
type: type,
|
||||
loadingDocumentUri: url,
|
||||
stacktrace: mappingCallFrames(callFrames),
|
||||
};
|
||||
return cause;
|
||||
}
|
||||
|
||||
function Header(id, headers) {
|
||||
const header = [];
|
||||
let headersSize = 0;
|
||||
Object.keys(headers).map(value => {
|
||||
header.push({
|
||||
name: value,
|
||||
value: headers[value],
|
||||
});
|
||||
headersSize += value.length + headers[value].length;
|
||||
});
|
||||
|
||||
return {
|
||||
from: id,
|
||||
headers: header,
|
||||
headersSize: headersSize,
|
||||
rawHeaders: undefined,
|
||||
};
|
||||
}
|
||||
function PostData(id, postData, header) {
|
||||
const { headers, headersSize } = header;
|
||||
const payload = {};
|
||||
const requestPostData = {
|
||||
from: id,
|
||||
postDataDiscarded: false,
|
||||
postData: {},
|
||||
};
|
||||
if (postData) {
|
||||
requestPostData.postData.text = postData;
|
||||
payload.requestPostData = Object.assign({}, requestPostData);
|
||||
payload.requestHeadersFromUploadStream = { headers, headersSize };
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not support on current version.
|
||||
* unstable method: Network.getCookies
|
||||
* cause: https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-getCookies
|
||||
*/
|
||||
function Cookie(id, Network) {
|
||||
// TODO: verify
|
||||
}
|
||||
|
||||
function Request(id, requestData) {
|
||||
const { request, initiator, timestamp } = requestData;
|
||||
const { url, method } = request;
|
||||
const cause = !initiator ? undefined : Cause(initiator);
|
||||
return {
|
||||
method,
|
||||
url,
|
||||
cause,
|
||||
isXHR: false, // TODO: verify
|
||||
startedDateTime: timestamp,
|
||||
fromCache: undefined,
|
||||
fromServiceWorker: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Cause,
|
||||
Cookie,
|
||||
Header,
|
||||
Request,
|
||||
PostData,
|
||||
};
|
|
@ -1,92 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
function ResponseInfo(id, response, content) {
|
||||
const { mimeType } = response;
|
||||
const { body, base64Encoded } = content;
|
||||
return {
|
||||
from: id,
|
||||
content: {
|
||||
mimeType: mimeType,
|
||||
text: !body ? "" : body,
|
||||
size: !body ? 0 : body.length,
|
||||
encoding: base64Encoded ? "base64" : undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function ResponseContent(id, response, content) {
|
||||
const { body } = content;
|
||||
const { mimeType, encodedDataLength } = response;
|
||||
const responseContent = ResponseInfo(id, response, content);
|
||||
const payload = Object.assign(
|
||||
{
|
||||
responseContent,
|
||||
contentSize: !body ? 0 : body.length,
|
||||
transferredSize: encodedDataLength, // TODO: verify
|
||||
mimeType: mimeType,
|
||||
},
|
||||
body
|
||||
);
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not support on current version.
|
||||
* unstable method: Security
|
||||
* cause: https://chromedevtools.github.io/devtools-protocol/tot/Security/
|
||||
*/
|
||||
function SecurityDetails(id, security) {
|
||||
// TODO : verify
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
function Timings(id, timing) {
|
||||
// TODO : implement
|
||||
const {
|
||||
dnsStart,
|
||||
dnsEnd,
|
||||
connectStart,
|
||||
connectEnd,
|
||||
sendStart,
|
||||
sendEnd,
|
||||
receiveHeadersEnd,
|
||||
} = timing;
|
||||
const dns = parseInt(dnsEnd - dnsStart, 10);
|
||||
const connect = parseInt(connectEnd - connectStart, 10);
|
||||
const send = parseInt(sendEnd - sendStart, 10);
|
||||
const total = parseInt(receiveHeadersEnd, 10);
|
||||
return {
|
||||
from: id,
|
||||
timings: {
|
||||
blocked: 0,
|
||||
dns: dns,
|
||||
connect: connect,
|
||||
send: send,
|
||||
wait: parseInt(receiveHeadersEnd - (send + connect + dns), 10),
|
||||
receive: 0,
|
||||
},
|
||||
totalTime: total,
|
||||
};
|
||||
}
|
||||
function State(response, headers) {
|
||||
const { headersSize } = headers;
|
||||
const { status, statusText, remoteIPAddress, remotePort } = response;
|
||||
return {
|
||||
remoteAddress: remoteIPAddress,
|
||||
remotePort,
|
||||
status,
|
||||
statusText,
|
||||
headersSize,
|
||||
};
|
||||
}
|
||||
module.exports = {
|
||||
State,
|
||||
Timings,
|
||||
ResponseContent,
|
||||
SecurityDetails,
|
||||
};
|
|
@ -1,166 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
Request,
|
||||
Header,
|
||||
PostData,
|
||||
} = require("devtools/client/netmonitor/src/connector/chrome/request");
|
||||
const {
|
||||
State,
|
||||
ResponseContent,
|
||||
Timings,
|
||||
} = require("devtools/client/netmonitor/src/connector/chrome/response");
|
||||
const {
|
||||
getBulkLoader,
|
||||
} = require("devtools/client/netmonitor/src/connector/chrome/bulk-loader");
|
||||
|
||||
class Payload {
|
||||
constructor() {
|
||||
this.payload = {};
|
||||
this.update = this.update.bind(this);
|
||||
}
|
||||
async update(payload) {
|
||||
const {
|
||||
request,
|
||||
response,
|
||||
requestId,
|
||||
timestamp,
|
||||
content,
|
||||
dataLength,
|
||||
encodedDataLength,
|
||||
} = payload;
|
||||
const { headers, postData, timing } = (request ? request : response) || {};
|
||||
|
||||
const header = await this.mappingHeader(requestId, headers);
|
||||
|
||||
this.requestId = requestId;
|
||||
|
||||
this.updateTimestamp(timestamp);
|
||||
const data = await this.mappingAll(requestId, {
|
||||
payload,
|
||||
response,
|
||||
postData,
|
||||
header,
|
||||
content,
|
||||
timing,
|
||||
dataLength,
|
||||
encodedDataLength,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
log(reason, info) {
|
||||
this.updatePayload({
|
||||
type: reason,
|
||||
log: info,
|
||||
});
|
||||
}
|
||||
|
||||
updateTimestamp(timestamp) {
|
||||
const { request } = this.payload;
|
||||
this.updatePayload(
|
||||
request ? { response: timestamp } : { request: timestamp }
|
||||
);
|
||||
}
|
||||
|
||||
updatePayload(data) {
|
||||
this.payload = Object.assign({}, this.payload, data);
|
||||
}
|
||||
|
||||
async mappingAll(requestId, data) {
|
||||
const {
|
||||
payload,
|
||||
response,
|
||||
postData,
|
||||
header,
|
||||
content,
|
||||
timing,
|
||||
dataLength,
|
||||
encodedDataLength,
|
||||
} = data;
|
||||
const [
|
||||
requests,
|
||||
headers,
|
||||
post,
|
||||
status,
|
||||
timings,
|
||||
responses,
|
||||
] = await Promise.all([
|
||||
this.mappingRequest(requestId, payload),
|
||||
header,
|
||||
this.mappingRequestPostData(requestId, postData, header),
|
||||
this.mappingResponseStatus(requestId, response, header),
|
||||
this.mappingTiming(requestId, timing),
|
||||
this.mappingResponseContent(requestId, response, content),
|
||||
]);
|
||||
this.updatePayload({
|
||||
requests,
|
||||
headers,
|
||||
post,
|
||||
status,
|
||||
timings,
|
||||
responses,
|
||||
dataLength,
|
||||
encodedDataLength,
|
||||
});
|
||||
return [requests, headers, post, status, timings, responses];
|
||||
}
|
||||
|
||||
async mappingTiming(requestId, timing) {
|
||||
return !timing ? undefined : Timings(requestId, timing);
|
||||
}
|
||||
|
||||
async mappingRequest(requestId, payload) {
|
||||
const { request } = payload;
|
||||
return !request ? undefined : Request(requestId, payload);
|
||||
}
|
||||
|
||||
async mappingHeader(requestId, headers) {
|
||||
return !headers ? undefined : Header(requestId, headers);
|
||||
}
|
||||
|
||||
async mappingRequestPostData(requestId, postData, headers) {
|
||||
return !postData ? undefined : PostData(requestId, postData, headers);
|
||||
}
|
||||
|
||||
async mappingResponseStatus(requestId, response, header) {
|
||||
return !response ? undefined : State(response, header);
|
||||
}
|
||||
|
||||
async mappingResponseContent(requestId, response, content) {
|
||||
return !response || !content
|
||||
? undefined
|
||||
: ResponseContent(requestId, response, content);
|
||||
}
|
||||
}
|
||||
class Payloads {
|
||||
constructor() {
|
||||
this.payloads = new Map();
|
||||
}
|
||||
|
||||
add(id) {
|
||||
if (!this.payloads.has(id)) {
|
||||
this.payloads.set(id, new Payload());
|
||||
}
|
||||
return this.payloads.get(id);
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this.payloads.has(id) ? this.payloads.get(id) : undefined;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.payloads.clear();
|
||||
const loader = getBulkLoader();
|
||||
loader.reset();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Payload,
|
||||
Payloads,
|
||||
};
|
|
@ -16,7 +16,6 @@ class Connector {
|
|||
// Bind public API
|
||||
this.connect = this.connect.bind(this);
|
||||
this.disconnect = this.disconnect.bind(this);
|
||||
this.connectChrome = this.connectChrome.bind(this);
|
||||
this.connectFirefox = this.connectFirefox.bind(this);
|
||||
this.getLongString = this.getLongString.bind(this);
|
||||
this.getTabTarget = this.getTabTarget.bind(this);
|
||||
|
@ -38,9 +37,6 @@ class Connector {
|
|||
|
||||
const { clientType } = connection.tab;
|
||||
switch (clientType) {
|
||||
case "chrome":
|
||||
await this.connectChrome(connection, actions, getState);
|
||||
break;
|
||||
case "firefox":
|
||||
await this.connectFirefox(connection, actions, getState);
|
||||
break;
|
||||
|
@ -53,12 +49,6 @@ class Connector {
|
|||
this.connector && this.connector.disconnect();
|
||||
}
|
||||
|
||||
connectChrome(connection, actions, getState) {
|
||||
const ChromeConnector = require("devtools/client/netmonitor/src/connector/chrome-connector");
|
||||
this.connector = new ChromeConnector();
|
||||
return this.connector.connect(connection, actions, getState);
|
||||
}
|
||||
|
||||
connectFirefox(connection, actions, getState) {
|
||||
const FirefoxConnector = require("devtools/client/netmonitor/src/connector/firefox-connector");
|
||||
this.connector = new FirefoxConnector();
|
||||
|
|
Загрузка…
Ссылка в новой задаче