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.PanelWithSidebar} | 7 * @extends {WebInspector.PanelWithSidebar} |
8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
9 */ | 9 */ |
10 WebInspector.SecurityPanel = function() { | 10 WebInspector.SecurityPanel = function() { |
11 WebInspector.PanelWithSidebar.call(this, "security"); | 11 WebInspector.PanelWithSidebar.call(this, "security"); |
12 this.registerRequiredCSS("security/securityPanel.css"); | 12 this.registerRequiredCSS("security/securityPanel.css"); |
13 this.registerRequiredCSS("security/lockIcon.css"); | 13 this.registerRequiredCSS("security/lockIcon.css"); |
14 | 14 |
15 var sidebarTree = new TreeOutlineInShadow(); | 15 var sidebarTree = new TreeOutlineInShadow(); |
16 sidebarTree.element.classList.add("sidebar-tree"); | 16 sidebarTree.element.classList.add("sidebar-tree"); |
17 this.panelSidebarElement().appendChild(sidebarTree.element); | 17 this.panelSidebarElement().appendChild(sidebarTree.element); |
18 sidebarTree.registerRequiredCSS("security/lockIcon.css"); | 18 sidebarTree.registerRequiredCSS("security/lockIcon.css"); |
19 this.setDefaultFocusedElement(sidebarTree.element); | 19 this.setDefaultFocusedElement(sidebarTree.element); |
20 | 20 |
21 this._sidebarMainViewElement = new WebInspector.SecurityMainViewSidebarTreeE
lement(this); | 21 this._sidebarMainViewElement = new WebInspector.SecurityMainViewSidebarTreeE
lement(this); |
22 sidebarTree.appendChild(this._sidebarMainViewElement); | 22 sidebarTree.appendChild(this._sidebarMainViewElement); |
23 | 23 |
24 this._mainView = new WebInspector.SecurityMainView(); | 24 this._mainView = new WebInspector.SecurityMainView(); |
25 this.showMainView(); | 25 this.showMainView(); |
26 | 26 |
| 27 /** @type {!Map<string, !{securityState: !SecurityAgent.SecurityState, secur
ityDetails: ?NetworkAgent.SecurityDetails}>} */ |
| 28 this._origins = new Map(); |
| 29 WebInspector.targetManager.addEventListener(WebInspector.ResourceTreeModel.E
ventTypes.InspectedURLChanged, this._clear, this); |
| 30 WebInspector.targetManager.addEventListener(WebInspector.ResourceTreeModel.E
ventTypes.WillReloadPage, this._clear, this); |
| 31 WebInspector.targetManager.addEventListener(WebInspector.ResourceTreeModel.E
ventTypes.MainFrameNavigated, this._clear, this); |
| 32 |
27 WebInspector.targetManager.observeTargets(this); | 33 WebInspector.targetManager.observeTargets(this); |
28 } | 34 } |
29 | 35 |
30 WebInspector.SecurityPanel.prototype = { | 36 WebInspector.SecurityPanel.prototype = { |
31 | 37 |
32 /** | 38 /** |
33 * @param {!SecurityAgent.SecurityState} newSecurityState | 39 * @param {!SecurityAgent.SecurityState} newSecurityState |
34 * @param {!Array<!SecurityAgent.SecurityStateExplanation>} explanations | 40 * @param {!Array<!SecurityAgent.SecurityStateExplanation>} explanations |
35 */ | 41 */ |
36 _updateSecurityState: function(newSecurityState, explanations) | 42 _updateSecurityState: function(newSecurityState, explanations) |
(...skipping 28 matching lines...) Expand all Loading... |
65 if (this._visibleView) | 71 if (this._visibleView) |
66 this._visibleView.detach(); | 72 this._visibleView.detach(); |
67 | 73 |
68 this._visibleView = view; | 74 this._visibleView = view; |
69 | 75 |
70 if (view) | 76 if (view) |
71 this.splitWidget().setMainWidget(view); | 77 this.splitWidget().setMainWidget(view); |
72 }, | 78 }, |
73 | 79 |
74 /** | 80 /** |
| 81 * @param {!WebInspector.Event} event |
| 82 */ |
| 83 _onResponseReceivedSecurityDetails: function(event) |
| 84 { |
| 85 var data = event.data; |
| 86 var origin = /** @type {string} */ (data.origin); |
| 87 var securityState = /** @type {!SecurityAgent.SecurityState} */ (data.se
curityState); |
| 88 |
| 89 if (this._origins.has(origin)) { |
| 90 var originData = this._origins.get(origin); |
| 91 originData.securityState = this._securityStateMin(originData.securit
yState, securityState); |
| 92 } else { |
| 93 // TODO(lgarron): Store a (deduplicated) list of different security
details we have seen. |
| 94 var originData = {}; |
| 95 originData.securityState = securityState; |
| 96 if (data.securityDetails) |
| 97 originData.securityDetails = data.securityDetails; |
| 98 |
| 99 this._origins.set(origin, originData); |
| 100 } |
| 101 }, |
| 102 |
| 103 /** |
| 104 * @param {!SecurityAgent.SecurityState} stateA |
| 105 * @param {!SecurityAgent.SecurityState} stateB |
| 106 * @return {!SecurityAgent.SecurityState} |
| 107 */ |
| 108 _securityStateMin: function(stateA, stateB) |
| 109 { |
| 110 var ordering = ["unknown", "insecure", "neutral", "warning", "secure"]; |
| 111 return (ordering.indexOf(stateA) < ordering.indexOf(stateB)) ? stateA :
stateB; |
| 112 }, |
| 113 |
| 114 /** |
75 * @override | 115 * @override |
76 * @param {!WebInspector.Target} target | 116 * @param {!WebInspector.Target} target |
77 */ | 117 */ |
78 targetAdded: function(target) | 118 targetAdded: function(target) |
79 { | 119 { |
80 if (!this._target) { | 120 if (!this._target) { |
81 this._target = target; | 121 this._target = target; |
82 this._securityModel = WebInspector.SecurityModel.fromTarget(target); | 122 this._securityModel = WebInspector.SecurityModel.fromTarget(target); |
83 this._securityModel.addEventListener(WebInspector.SecurityModel.Even
tTypes.SecurityStateChanged, this._onSecurityStateChanged, this); | 123 this._securityModel.addEventListener(WebInspector.SecurityModel.Even
tTypes.SecurityStateChanged, this._onSecurityStateChanged, this); |
84 this._updateSecurityState(this._securityModel.securityState(), []); | 124 this._updateSecurityState(this._securityModel.securityState(), []); |
| 125 |
| 126 this._origins.clear(); |
| 127 this._networkManager = target.networkManager; |
| 128 this._networkManager.addEventListener(WebInspector.NetworkManager.Ev
entTypes.ResponseReceivedSecurityDetails, this._onResponseReceivedSecurityDetail
s, this); |
85 } | 129 } |
86 }, | 130 }, |
87 | 131 |
88 /** | 132 /** |
89 * @override | 133 * @override |
90 * @param {!WebInspector.Target} target | 134 * @param {!WebInspector.Target} target |
91 */ | 135 */ |
92 targetRemoved: function(target) | 136 targetRemoved: function(target) |
93 { | 137 { |
94 if (target === this._target) { | 138 if (target === this._target) { |
95 this._securityModel.removeEventListener(WebInspector.SecurityModel.E
ventTypes.SecurityStateChanged, this._onSecurityStateChanged, this); | 139 this._securityModel.removeEventListener(WebInspector.SecurityModel.E
ventTypes.SecurityStateChanged, this._onSecurityStateChanged, this); |
96 delete this._securityModel; | 140 delete this._securityModel; |
| 141 this._networkManager.removeEventListener(WebInspector.NetworkManager
.EventTypes.ResponseReceivedSecurityDetails, this._onResponseReceivedSecurityDet
ails, this); |
| 142 delete this._networkManager; |
97 delete this._target; | 143 delete this._target; |
98 this._updateSecurityState(SecurityAgent.SecurityState.Unknown, []); | 144 this._clear(); |
99 } | 145 } |
100 }, | 146 }, |
101 | 147 |
| 148 _clear: function() |
| 149 { |
| 150 this._updateSecurityState(SecurityAgent.SecurityState.Unknown, []); |
| 151 this._origins.clear(); |
| 152 }, |
| 153 |
102 __proto__: WebInspector.PanelWithSidebar.prototype | 154 __proto__: WebInspector.PanelWithSidebar.prototype |
103 } | 155 } |
104 | 156 |
105 /** | 157 /** |
106 * @return {!WebInspector.SecurityPanel} | 158 * @return {!WebInspector.SecurityPanel} |
107 */ | 159 */ |
108 WebInspector.SecurityPanel._instance = function() | 160 WebInspector.SecurityPanel._instance = function() |
109 { | 161 { |
110 if (!WebInspector.SecurityPanel._instanceObject) | 162 if (!WebInspector.SecurityPanel._instanceObject) |
111 WebInspector.SecurityPanel._instanceObject = new WebInspector.SecurityPa
nel(); | 163 WebInspector.SecurityPanel._instanceObject = new WebInspector.SecurityPa
nel(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 this._lockIcon.classList.add("lock-icon-" + this._securityState); | 276 this._lockIcon.classList.add("lock-icon-" + this._securityState); |
225 this._securityStateText.textContent = WebInspector.UIString("Page securi
ty state: %s", this._securityState); | 277 this._securityStateText.textContent = WebInspector.UIString("Page securi
ty state: %s", this._securityState); |
226 | 278 |
227 this._securityExplanations.removeChildren(); | 279 this._securityExplanations.removeChildren(); |
228 for (var explanation of explanations) | 280 for (var explanation of explanations) |
229 this._addExplanation(explanation); | 281 this._addExplanation(explanation); |
230 }, | 282 }, |
231 | 283 |
232 __proto__: WebInspector.VBox.prototype | 284 __proto__: WebInspector.VBox.prototype |
233 } | 285 } |
OLD | NEW |