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