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