OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.SDKModel} | 7 * @extends {WebInspector.SDKModel} |
8 * @param {!WebInspector.Target} target | 8 * @param {!WebInspector.Target} target |
9 */ | 9 */ |
10 WebInspector.SecurityModel = function(target) | 10 WebInspector.SecurityModel = function(target) |
11 { | 11 { |
12 WebInspector.SDKModel.call(this, WebInspector.SecurityModel, target); | 12 WebInspector.SDKModel.call(this, WebInspector.SecurityModel, target); |
13 this._dispatcher = new WebInspector.SecurityDispatcher(this); | 13 this._dispatcher = new WebInspector.SecurityDispatcher(this); |
14 this._securityAgent = target.securityAgent(); | 14 this._securityAgent = target.securityAgent(); |
15 this._networkManager = target.networkManager; | |
15 target.registerSecurityDispatcher(this._dispatcher); | 16 target.registerSecurityDispatcher(this._dispatcher); |
17 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,
| |
16 this._securityAgent.enable(); | 18 this._securityAgent.enable(); |
17 | 19 |
20 // TODO(lgarron): Reset upon page reload. | |
21 this.origins = { | |
lgarron
2015/08/18 02:47:22
My plan is for SecurityModel as a middleman to kee
| |
22 | |
23 }; | |
24 | |
18 this._securityState = SecurityAgent.SecurityState.Unknown; | 25 this._securityState = SecurityAgent.SecurityState.Unknown; |
19 } | 26 } |
20 | 27 |
21 WebInspector.SecurityModel.EventTypes = { | 28 WebInspector.SecurityModel.EventTypes = { |
22 SecurityStateChanged: "SecurityStateChanged" | 29 SecurityStateChanged: "SecurityStateChanged", |
30 OriginSecurityChanged: "OriginSecurityChanged" | |
23 } | 31 } |
24 | 32 |
25 WebInspector.SecurityModel.prototype = { | 33 WebInspector.SecurityModel.prototype = { |
26 /** | 34 /** |
27 * @return {!SecurityAgent.SecurityState} securityState | 35 * @return {!SecurityAgent.SecurityState} securityState |
28 */ | 36 */ |
29 securityState: function() | 37 securityState: function() |
30 { | 38 { |
31 return /** @type {!SecurityAgent.SecurityState} */ (this._securityState) ; | 39 return /** @type {!SecurityAgent.SecurityState} */ (this._securityState) ; |
32 }, | 40 }, |
33 | 41 |
42 /** | |
43 * @param {!WebInspector.Event} event | |
44 */ | |
45 _onReceivedResponseSecurity: function(event) | |
46 { | |
47 var response = event.data; | |
48 var origin = response.origin; | |
49 var securityState = response.securityState; | |
50 if (origin in this.origins) { | |
51 if (this._securityStateDecreased(this.origins[origin].securityState) , securityState) { | |
52 this.origins[origin].securityState = securityState; | |
53 | |
54 var originEventData = {}; | |
55 originEventData.origin = origin; | |
56 originEventData.securityState = securityState; | |
57 if (response.securityDetails) { | |
58 originEventData.securityDetails = response.securityDetails; | |
59 originEventData.certificateDetails = response.certificateDet ails; | |
60 } | |
61 this.dispatchEventToListeners(WebInspector.SecurityModel.EventTy pes.OriginSecurityChanged, originEventData); | |
62 } | |
63 } | |
64 else { | |
dgozman
2015/08/18 18:41:49
nit: else on the same line as }
| |
65 this.origins[origin] = {}; | |
66 this.origins[origin].securityState = securityState; | |
67 } | |
68 }, | |
69 | |
70 | |
71 /** | |
72 * @param {!SecurityAgent.SecurityState} oldState | |
73 * @param {!SecurityAgent.SecurityState} newState | |
74 * @return {!bool} | |
75 */ | |
76 _securityStateDecreased: function(oldState, newState) { | |
dgozman
2015/08/18 18:41:49
nit: { on next line
| |
77 // TODO(lgarron): this doesn't take active mixed content into account. | |
78 var ordering = ["unknown", "insecure", "http", "warning", "secure"]; | |
79 return ordering.indexOf(newState) < ordering.indexOf(oldState); | |
80 }, | |
81 | |
34 __proto__: WebInspector.SDKModel.prototype | 82 __proto__: WebInspector.SDKModel.prototype |
35 } | 83 } |
36 | 84 |
37 /** | 85 /** |
38 * @param {!WebInspector.Target} target | 86 * @param {!WebInspector.Target} target |
39 * @return {?WebInspector.SecurityModel} | 87 * @return {?WebInspector.SecurityModel} |
40 */ | 88 */ |
41 WebInspector.SecurityModel.fromTarget = function(target) | 89 WebInspector.SecurityModel.fromTarget = function(target) |
42 { | 90 { |
43 var model = /** @type {?WebInspector.SecurityModel} */ (target.model(WebInsp ector.SecurityModel)); | 91 var model = /** @type {?WebInspector.SecurityModel} */ (target.model(WebInsp ector.SecurityModel)); |
(...skipping 16 matching lines...) Expand all Loading... | |
60 * @override | 108 * @override |
61 * @param {!SecurityAgent.SecurityState} securityState | 109 * @param {!SecurityAgent.SecurityState} securityState |
62 * @param {!Array<!SecurityAgent.SecurityStateExplanation>=} explanations | 110 * @param {!Array<!SecurityAgent.SecurityStateExplanation>=} explanations |
63 */ | 111 */ |
64 securityStateChanged: function(securityState, explanations) | 112 securityStateChanged: function(securityState, explanations) |
65 { | 113 { |
66 var data = {"securityState": securityState, "explanations": explanations || []}; | 114 var data = {"securityState": securityState, "explanations": explanations || []}; |
67 this._model.dispatchEventToListeners(WebInspector.SecurityModel.EventTyp es.SecurityStateChanged, data); | 115 this._model.dispatchEventToListeners(WebInspector.SecurityModel.EventTyp es.SecurityStateChanged, data); |
68 } | 116 } |
69 } | 117 } |
OLD | NEW |