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.Panel} | 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.Panel.call(this, "security"); | 11 WebInspector.PanelWithSidebar.call(this, "security"); |
12 this.registerRequiredCSS("security/securityPanel.css"); | 12 this.registerRequiredCSS("security/securityPanel.css"); |
13 | 13 |
14 // Create security state section. | 14 // Construct sidebar |
dgozman
2015/06/26 10:50:49
Please remove comments which follow the code and n
lgarron
2015/06/26 16:33:31
Done
| |
15 var securityStateSection = this.element.createChild("div"); | 15 var sidebarTree = new TreeOutline(); |
dgozman
2015/06/26 10:50:49
TreeOutlineInShadow
lgarron
2015/06/26 16:33:31
Done.
However, this breaks the CSS for the sidebar
| |
16 this._lockIcon = securityStateSection.createChild("div", "lock-icon"); | 16 sidebarTree.element.classList.add("sidebar-tree"); |
17 this._securityStateText = securityStateSection.createChild("div", "security- state"); | 17 this.panelSidebarElement().appendChild(sidebarTree.element); |
18 securityStateSection.createChild("hr"); | 18 this.setDefaultFocusedElement(sidebarTree.element); |
19 this._securityExplanations = securityStateSection.createChild("div", "securi ty-explanations"); | |
20 | 19 |
20 // Sidebar element for switching to main view | |
21 this._sidebarMainViewElement = new WebInspector.SecurityMainViewSidebarTreeE lement(this); | |
22 sidebarTree.appendChild(this._sidebarMainViewElement); | |
23 | |
24 // Construct and attach main view. | |
25 this._mainView = new WebInspector.SecurityMainView(); | |
26 this.showMainView(); | |
27 | |
28 // Go! | |
21 WebInspector.targetManager.observeTargets(this); | 29 WebInspector.targetManager.observeTargets(this); |
22 } | 30 } |
23 | 31 |
24 WebInspector.SecurityPanel.prototype = { | 32 WebInspector.SecurityPanel.prototype = { |
25 /** | |
26 * @param {!SecurityAgent.SecurityStateExplanation} explanation | |
27 */ | |
28 _addExplanation: function(explanation) { | |
29 var explanationDiv = this._securityExplanations.createChild("div", "secu rity-explanation"); | |
30 | |
31 var explanationLockIcon = explanationDiv.createChild("div", "lock-icon") ; | |
32 explanationLockIcon.classList.add("lock-icon-" + explanation.securitySta te); | |
33 explanationDiv.createChild("div", "explanation-title").textContent = exp lanation.summary; | |
34 explanationDiv.createChild("div", "explanation-text").textContent = expl anation.description; | |
35 }, | |
36 | 33 |
37 /** | 34 /** |
38 * @param {!SecurityAgent.SecurityState} newSecurityState | 35 * @param {!SecurityAgent.SecurityState} newSecurityState |
39 * @param {!Array<!SecurityAgent.SecurityStateExplanation>} explanations | 36 * @param {!Array<!SecurityAgent.SecurityStateExplanation>} explanations |
40 */ | 37 */ |
41 _updateSecurityState: function(newSecurityState, explanations) | 38 _updateSecurityState: function(newSecurityState, explanations) |
42 { | 39 { |
43 // Remove old state. | 40 this._sidebarMainViewElement.setSecurityState(newSecurityState); |
44 // It's safe to call this even when this._securityState is undefined. | 41 this._mainView.updateSecurityState(newSecurityState, explanations); |
45 this._lockIcon.classList.remove("lock-icon-" + this._securityState); | |
46 | |
47 // Add new state. | |
48 this._securityState = newSecurityState; | |
49 this._lockIcon.classList.add("lock-icon-" + this._securityState); | |
50 this._securityStateText.textContent = WebInspector.UIString("Page securi ty state: %s", this._securityState); | |
51 | |
52 this._securityExplanations.removeChildren(); | |
53 for (var explanation of explanations) | |
54 this._addExplanation(explanation); | |
55 }, | 42 }, |
56 | 43 |
57 /** | 44 /** |
58 * @param {!WebInspector.Event} event | 45 * @param {!WebInspector.Event} event |
59 */ | 46 */ |
60 _onSecurityStateChanged: function(event) | 47 _onSecurityStateChanged: function(event) |
61 { | 48 { |
62 var securityState = /** @type {!SecurityAgent.SecurityState} */ (event.d ata.securityState); | 49 var securityState = /** @type {!SecurityAgent.SecurityState} */ (event.d ata.securityState); |
63 var explanations = /** @type {!Array<!SecurityAgent.SecurityStateExplana tion>} */ (event.data.explanations); | 50 var explanations = /** @type {!Array<!SecurityAgent.SecurityStateExplana tion>} */ (event.data.explanations); |
64 this._updateSecurityState(securityState, explanations); | 51 this._updateSecurityState(securityState, explanations); |
65 }, | 52 }, |
66 | 53 |
54 showMainView: function() | |
55 { | |
56 this.visibleView = this._mainView; | |
57 }, | |
58 | |
59 get visibleView() | |
60 { | |
61 return this._visibleView; | |
62 }, | |
63 | |
64 set visibleView(x) | |
dgozman
2015/06/26 10:50:49
Getters and setters are deprecated. Use methods in
lgarron
2015/06/26 16:33:31
Done.
Should other cases (e.g. Audits panel) be u
| |
65 { | |
66 if (this._visibleView === x) | |
67 return; | |
68 | |
69 if (this._visibleView) | |
70 this._visibleView.detach(); | |
71 | |
72 this._visibleView = x; | |
73 | |
74 if (x) | |
75 this.splitWidget().setMainWidget(x); | |
76 }, | |
77 | |
67 /** | 78 /** |
68 * @override | 79 * @override |
69 * @param {!WebInspector.Target} target | 80 * @param {!WebInspector.Target} target |
70 */ | 81 */ |
71 targetAdded: function(target) | 82 targetAdded: function(target) |
72 { | 83 { |
73 if (!this._target) { | 84 if (!this._target) { |
74 this._target = target; | 85 this._target = target; |
75 this._securityModel = WebInspector.SecurityModel.fromTarget(target); | 86 this._securityModel = WebInspector.SecurityModel.fromTarget(target); |
76 this._securityModel.addEventListener(WebInspector.SecurityModel.Even tTypes.SecurityStateChanged, this._onSecurityStateChanged, this); | 87 this._securityModel.addEventListener(WebInspector.SecurityModel.Even tTypes.SecurityStateChanged, this._onSecurityStateChanged, this); |
77 this._updateSecurityState(this._securityModel.securityState(), []); | 88 this._updateSecurityState(this._securityModel.securityState(), []); |
78 } | 89 } |
79 }, | 90 }, |
80 | 91 |
81 /** | 92 /** |
82 * @override | 93 * @override |
83 * @param {!WebInspector.Target} target | 94 * @param {!WebInspector.Target} target |
84 */ | 95 */ |
85 targetRemoved: function(target) | 96 targetRemoved: function(target) |
86 { | 97 { |
87 if (target === this._target) { | 98 if (target === this._target) { |
88 this._securityModel.removeEventListener(WebInspector.SecurityModel.E ventTypes.SecurityStateChanged, this._onSecurityStateChanged, this); | 99 this._securityModel.removeEventListener(WebInspector.SecurityModel.E ventTypes.SecurityStateChanged, this._onSecurityStateChanged, this); |
89 delete this._securityModel; | 100 delete this._securityModel; |
90 delete this._target; | 101 delete this._target; |
91 this._updateSecurityState(SecurityAgent.SecurityState.Unknown, []); | 102 this._updateSecurityState(SecurityAgent.SecurityState.Unknown, []); |
92 } | 103 } |
93 }, | 104 }, |
94 | 105 |
95 __proto__: WebInspector.Panel.prototype | 106 __proto__: WebInspector.PanelWithSidebar.prototype |
96 } | 107 } |
97 | 108 |
98 /** | 109 /** |
99 * @return {!WebInspector.SecurityPanel} | 110 * @return {!WebInspector.SecurityPanel} |
100 */ | 111 */ |
101 WebInspector.SecurityPanel._instance = function() | 112 WebInspector.SecurityPanel._instance = function() |
102 { | 113 { |
103 if (!WebInspector.SecurityPanel._instanceObject) | 114 if (!WebInspector.SecurityPanel._instanceObject) |
104 WebInspector.SecurityPanel._instanceObject = new WebInspector.SecurityPa nel(); | 115 WebInspector.SecurityPanel._instanceObject = new WebInspector.SecurityPa nel(); |
105 return WebInspector.SecurityPanel._instanceObject; | 116 return WebInspector.SecurityPanel._instanceObject; |
106 } | 117 } |
107 | 118 |
108 /** | 119 /** |
109 * @constructor | 120 * @constructor |
121 * @extends {WebInspector.SidebarTreeElement} | |
122 * @param {!WebInspector.SecurityPanel} panel | |
123 */ | |
124 WebInspector.SecurityMainViewSidebarTreeElement = function(panel) | |
125 { | |
126 this._panel = panel; | |
127 this.small = true; | |
128 WebInspector.SidebarTreeElement.call(this, "security-sidebar-tree-item", Web Inspector.UIString("Overview")); | |
129 this.iconElement.classList.add("lock-icon"); | |
130 } | |
131 | |
132 WebInspector.SecurityMainViewSidebarTreeElement.prototype = { | |
133 onattach: function() | |
134 { | |
135 WebInspector.SidebarTreeElement.prototype.onattach.call(this); | |
136 }, | |
137 | |
138 /** | |
139 * @param {!SecurityAgent.SecurityState} newSecurityState | |
140 */ | |
141 setSecurityState: function(newSecurityState) { | |
dgozman
2015/06/26 10:50:49
{ on next line
lgarron
2015/06/26 16:33:31
Done.
(I'm used to same-line, so I always have to
| |
142 for (var className of this.iconElement.classList) | |
143 if (className.indexOf("lock-icon-") === 0) | |
144 this.iconElement.classList.remove(className); | |
145 | |
146 this.iconElement.classList.add("lock-icon-" + newSecurityState); | |
147 }, | |
148 | |
149 /** | |
150 * @override | |
151 * @return {boolean} | |
152 */ | |
153 onselect: function() | |
154 { | |
155 this._panel.showMainView(); | |
156 return true; | |
157 }, | |
158 | |
159 __proto__: WebInspector.SidebarTreeElement.prototype | |
160 } | |
161 | |
162 /** | |
163 * @constructor | |
110 * @implements {WebInspector.PanelFactory} | 164 * @implements {WebInspector.PanelFactory} |
111 */ | 165 */ |
112 WebInspector.SecurityPanelFactory = function() | 166 WebInspector.SecurityPanelFactory = function() |
113 { | 167 { |
114 } | 168 } |
115 | 169 |
116 WebInspector.SecurityPanelFactory.prototype = { | 170 WebInspector.SecurityPanelFactory.prototype = { |
117 /** | 171 /** |
118 * @override | 172 * @override |
119 * @return {!WebInspector.Panel} | 173 * @return {!WebInspector.Panel} |
120 */ | 174 */ |
121 createPanel: function() | 175 createPanel: function() |
122 { | 176 { |
123 return WebInspector.SecurityPanel._instance(); | 177 return WebInspector.SecurityPanel._instance(); |
124 } | 178 } |
125 } | 179 } |
180 | |
181 /** | |
182 * @constructor | |
183 * @extends {WebInspector.VBox} | |
184 */ | |
185 WebInspector.SecurityMainView = function() | |
186 { | |
187 WebInspector.VBox.call(this); | |
188 this.setMinimumSize(100, 100); | |
189 | |
190 this.element.classList.add("security-main-view"); | |
191 | |
192 // Create security state section. | |
193 var securityStateSection = this.element.createChild("div"); | |
194 this._lockIcon = securityStateSection.createChild("div", "lock-icon"); | |
195 this._securityStateText = securityStateSection.createChild("div", "security- state"); | |
196 securityStateSection.createChild("hr"); | |
197 this._securityExplanations = securityStateSection.createChild("div", "securi ty-explanations"); | |
198 | |
199 } | |
200 | |
201 WebInspector.SecurityMainView.prototype = { | |
202 /** | |
203 * @param {!SecurityAgent.SecurityStateExplanation} explanation | |
204 */ | |
205 _addExplanation: function(explanation) { | |
dgozman
2015/06/26 10:50:49
{ on next line
lgarron
2015/06/26 16:33:31
Done.
| |
206 var explanationDiv = this._securityExplanations.createChild("div", "secu rity-explanation"); | |
207 | |
208 var explanationLockIcon = explanationDiv.createChild("div", "lock-icon") ; | |
209 explanationLockIcon.classList.add("lock-icon-" + explanation.securitySta te); | |
210 explanationDiv.createChild("div", "explanation-title").textContent = exp lanation.summary; | |
211 explanationDiv.createChild("div", "explanation-text").textContent = expl anation.description; | |
212 }, | |
213 | |
214 /** | |
215 * @param {!SecurityAgent.SecurityState} newSecurityState | |
216 * @param {!Array<!SecurityAgent.SecurityStateExplanation>} explanations | |
217 */ | |
218 updateSecurityState: function(newSecurityState, explanations) | |
219 { | |
220 // Remove old state. | |
221 // It's safe to call this even when this._securityState is undefined. | |
dgozman
2015/06/26 10:50:49
This is a great comment which describes not what i
| |
222 this._lockIcon.classList.remove("lock-icon-" + this._securityState); | |
223 | |
224 // Add new state. | |
225 this._securityState = newSecurityState; | |
226 this._lockIcon.classList.add("lock-icon-" + this._securityState); | |
227 this._securityStateText.textContent = WebInspector.UIString("Page securi ty state: %s", this._securityState); | |
228 | |
229 this._securityExplanations.removeChildren(); | |
230 for (var explanation of explanations) | |
231 this._addExplanation(explanation); | |
232 }, | |
233 | |
234 __proto__: WebInspector.VBox.prototype | |
235 } | |
OLD | NEW |