mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 05:35:05 +08:00
Backend still sends this since it's a required field. We cannot yet remove it completely since it's non-optional and sent over public protocol API. Bug: 744601 Change-Id: Iee1ea175ba1fa9cf8ce596e218f98109836e5b70 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1546498 Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Commit-Queue: Livvie Lin <livvielin@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#646404} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 9c7d1ffab3ff18776d535bdafea9b147f442119f
121 lines
3.7 KiB
JavaScript
121 lines
3.7 KiB
JavaScript
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
Security.SecurityModel = class extends SDK.SDKModel {
|
|
/**
|
|
* @param {!SDK.Target} target
|
|
*/
|
|
constructor(target) {
|
|
super(target);
|
|
this._dispatcher = new Security.SecurityDispatcher(this);
|
|
this._securityAgent = target.securityAgent();
|
|
target.registerSecurityDispatcher(this._dispatcher);
|
|
this._securityAgent.enable();
|
|
}
|
|
|
|
/**
|
|
* @return {!SDK.ResourceTreeModel}
|
|
*/
|
|
resourceTreeModel() {
|
|
return /** @type {!SDK.ResourceTreeModel} */ (this.target().model(SDK.ResourceTreeModel));
|
|
}
|
|
|
|
/**
|
|
* @return {!SDK.NetworkManager}
|
|
*/
|
|
networkManager() {
|
|
return /** @type {!SDK.NetworkManager} */ (this.target().model(SDK.NetworkManager));
|
|
}
|
|
|
|
/**
|
|
* @param {!Protocol.Security.SecurityState} a
|
|
* @param {!Protocol.Security.SecurityState} b
|
|
* @return {number}
|
|
*/
|
|
static SecurityStateComparator(a, b) {
|
|
let securityStateMap;
|
|
if (Security.SecurityModel._symbolicToNumericSecurityState) {
|
|
securityStateMap = Security.SecurityModel._symbolicToNumericSecurityState;
|
|
} else {
|
|
securityStateMap = new Map();
|
|
const ordering = [
|
|
Protocol.Security.SecurityState.Info, Protocol.Security.SecurityState.Insecure,
|
|
Protocol.Security.SecurityState.Neutral, Protocol.Security.SecurityState.Secure,
|
|
// Unknown is max so that failed/cancelled requests don't overwrite the origin security state for successful requests,
|
|
// and so that failed/cancelled requests appear at the bottom of the origins list.
|
|
Protocol.Security.SecurityState.Unknown
|
|
];
|
|
for (let i = 0; i < ordering.length; i++)
|
|
securityStateMap.set(ordering[i], i + 1);
|
|
Security.SecurityModel._symbolicToNumericSecurityState = securityStateMap;
|
|
}
|
|
const aScore = securityStateMap.get(a) || 0;
|
|
const bScore = securityStateMap.get(b) || 0;
|
|
|
|
return aScore - bScore;
|
|
}
|
|
};
|
|
|
|
SDK.SDKModel.register(Security.SecurityModel, SDK.Target.Capability.Security, false);
|
|
|
|
/** @enum {symbol} */
|
|
Security.SecurityModel.Events = {
|
|
SecurityStateChanged: Symbol('SecurityStateChanged')
|
|
};
|
|
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
Security.PageSecurityState = class {
|
|
/**
|
|
* @param {!Protocol.Security.SecurityState} securityState
|
|
* @param {boolean} schemeIsCryptographic
|
|
* @param {!Array<!Protocol.Security.SecurityStateExplanation>} explanations
|
|
* @param {?string} summary
|
|
*/
|
|
constructor(securityState, schemeIsCryptographic, explanations, summary) {
|
|
this.securityState = securityState;
|
|
this.schemeIsCryptographic = schemeIsCryptographic;
|
|
this.explanations = explanations;
|
|
this.summary = summary;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @implements {Protocol.SecurityDispatcher}
|
|
* @unrestricted
|
|
*/
|
|
Security.SecurityDispatcher = class {
|
|
constructor(model) {
|
|
this._model = model;
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @param {!Protocol.Security.SecurityState} securityState
|
|
* @param {boolean} schemeIsCryptographic
|
|
* @param {!Array<!Protocol.Security.SecurityStateExplanation>} explanations
|
|
* @param {!Protocol.Security.InsecureContentStatus} insecureContentStatus
|
|
* @param {?string=} summary
|
|
*/
|
|
securityStateChanged(securityState, schemeIsCryptographic, explanations, insecureContentStatus, summary) {
|
|
const pageSecurityState =
|
|
new Security.PageSecurityState(securityState, schemeIsCryptographic, explanations, summary || null);
|
|
this._model.dispatchEventToListeners(Security.SecurityModel.Events.SecurityStateChanged, pageSecurityState);
|
|
}
|
|
|
|
|
|
/**
|
|
* @override
|
|
* @param {number} eventId
|
|
* @param {string} errorType
|
|
* @param {string} requestURL
|
|
*/
|
|
certificateError(eventId, errorType, requestURL) {
|
|
}
|
|
};
|