Index: Source/devtools/front_end/security/SecurityModel.js |
diff --git a/Source/devtools/front_end/security/SecurityModel.js b/Source/devtools/front_end/security/SecurityModel.js |
index cdd7dc2332578e4fbfb459f5deb44c373bda96eb..5cc69425f01220ea79f3bd7aa0dbab7d1bfe4be1 100644 |
--- a/Source/devtools/front_end/security/SecurityModel.js |
+++ b/Source/devtools/front_end/security/SecurityModel.js |
@@ -12,14 +12,22 @@ WebInspector.SecurityModel = function(target) |
WebInspector.SDKModel.call(this, WebInspector.SecurityModel, target); |
this._dispatcher = new WebInspector.SecurityDispatcher(this); |
this._securityAgent = target.securityAgent(); |
+ this._networkManager = target.networkManager; |
target.registerSecurityDispatcher(this._dispatcher); |
+ this._networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ReceivedResponseSecurity, this._onReceivedResponseSecurity, this); |
pfeldman
2015/08/18 18:35:08
It is not typical for models to listen to each oth
lgarron
2015/08/18 19:37:06
Thanks, that's very useful to know.
In that case,
|
this._securityAgent.enable(); |
+ // TODO(lgarron): Reset upon page reload. |
+ this.origins = { |
lgarron
2015/08/18 02:47:22
My plan is for SecurityModel as a middleman to kee
|
+ |
+ }; |
+ |
this._securityState = SecurityAgent.SecurityState.Unknown; |
} |
WebInspector.SecurityModel.EventTypes = { |
- SecurityStateChanged: "SecurityStateChanged" |
+ SecurityStateChanged: "SecurityStateChanged", |
+ OriginSecurityChanged: "OriginSecurityChanged" |
} |
WebInspector.SecurityModel.prototype = { |
@@ -31,6 +39,46 @@ WebInspector.SecurityModel.prototype = { |
return /** @type {!SecurityAgent.SecurityState} */ (this._securityState); |
}, |
+ /** |
+ * @param {!WebInspector.Event} event |
+ */ |
+ _onReceivedResponseSecurity: function(event) |
+ { |
+ var response = event.data; |
+ var origin = response.origin; |
+ var securityState = response.securityState; |
+ if (origin in this.origins) { |
+ if (this._securityStateDecreased(this.origins[origin].securityState), securityState) { |
+ this.origins[origin].securityState = securityState; |
+ |
+ var originEventData = {}; |
+ originEventData.origin = origin; |
+ originEventData.securityState = securityState; |
+ if (response.securityDetails) { |
+ originEventData.securityDetails = response.securityDetails; |
+ originEventData.certificateDetails = response.certificateDetails; |
+ } |
+ this.dispatchEventToListeners(WebInspector.SecurityModel.EventTypes.OriginSecurityChanged, originEventData); |
+ } |
+ } |
+ else { |
dgozman
2015/08/18 18:41:49
nit: else on the same line as }
|
+ this.origins[origin] = {}; |
+ this.origins[origin].securityState = securityState; |
+ } |
+ }, |
+ |
+ |
+ /** |
+ * @param {!SecurityAgent.SecurityState} oldState |
+ * @param {!SecurityAgent.SecurityState} newState |
+ * @return {!bool} |
+ */ |
+ _securityStateDecreased: function(oldState, newState) { |
dgozman
2015/08/18 18:41:49
nit: { on next line
|
+ // TODO(lgarron): this doesn't take active mixed content into account. |
+ var ordering = ["unknown", "insecure", "http", "warning", "secure"]; |
+ return ordering.indexOf(newState) < ordering.indexOf(oldState); |
+ }, |
+ |
__proto__: WebInspector.SDKModel.prototype |
} |