| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.BlockedURLsPane = class extends WebInspector.VBox { | 7 Network.BlockedURLsPane = class extends UI.VBox { |
| 8 constructor() { | 8 constructor() { |
| 9 super(true); | 9 super(true); |
| 10 this.registerRequiredCSS('network/blockedURLsPane.css'); | 10 this.registerRequiredCSS('network/blockedURLsPane.css'); |
| 11 this.contentElement.classList.add('blocked-urls-pane'); | 11 this.contentElement.classList.add('blocked-urls-pane'); |
| 12 | 12 |
| 13 WebInspector.BlockedURLsPane._instance = this; | 13 Network.BlockedURLsPane._instance = this; |
| 14 | 14 |
| 15 this._blockedURLsSetting = WebInspector.moduleSetting('blockedURLs'); | 15 this._blockedURLsSetting = Common.moduleSetting('blockedURLs'); |
| 16 this._blockedURLsSetting.addChangeListener(this._update, this); | 16 this._blockedURLsSetting.addChangeListener(this._update, this); |
| 17 | 17 |
| 18 this._toolbar = new WebInspector.Toolbar('', this.contentElement); | 18 this._toolbar = new UI.Toolbar('', this.contentElement); |
| 19 this._toolbar.element.addEventListener('click', (e) => e.consume()); | 19 this._toolbar.element.addEventListener('click', (e) => e.consume()); |
| 20 var addButton = new WebInspector.ToolbarButton(WebInspector.UIString('Add pa
ttern'), 'largeicon-add'); | 20 var addButton = new UI.ToolbarButton(Common.UIString('Add pattern'), 'largei
con-add'); |
| 21 addButton.addEventListener('click', this._addButtonClicked.bind(this)); | 21 addButton.addEventListener('click', this._addButtonClicked.bind(this)); |
| 22 this._toolbar.appendToolbarItem(addButton); | 22 this._toolbar.appendToolbarItem(addButton); |
| 23 var clearButton = new WebInspector.ToolbarButton(WebInspector.UIString('Remo
ve all'), 'largeicon-clear'); | 23 var clearButton = new UI.ToolbarButton(Common.UIString('Remove all'), 'large
icon-clear'); |
| 24 clearButton.addEventListener('click', this._removeAll.bind(this)); | 24 clearButton.addEventListener('click', this._removeAll.bind(this)); |
| 25 this._toolbar.appendToolbarItem(clearButton); | 25 this._toolbar.appendToolbarItem(clearButton); |
| 26 | 26 |
| 27 this._emptyElement = this.contentElement.createChild('div', 'no-blocked-urls
'); | 27 this._emptyElement = this.contentElement.createChild('div', 'no-blocked-urls
'); |
| 28 this._emptyElement.createChild('span').textContent = WebInspector.UIString('
Requests are not blocked. '); | 28 this._emptyElement.createChild('span').textContent = Common.UIString('Reques
ts are not blocked. '); |
| 29 var addLink = this._emptyElement.createChild('span', 'link'); | 29 var addLink = this._emptyElement.createChild('span', 'link'); |
| 30 addLink.textContent = WebInspector.UIString('Add pattern.'); | 30 addLink.textContent = Common.UIString('Add pattern.'); |
| 31 addLink.href = ''; | 31 addLink.href = ''; |
| 32 addLink.addEventListener('click', this._addButtonClicked.bind(this), false); | 32 addLink.addEventListener('click', this._addButtonClicked.bind(this), false); |
| 33 this._emptyElement.addEventListener('contextmenu', this._emptyElementContext
Menu.bind(this), true); | 33 this._emptyElement.addEventListener('contextmenu', this._emptyElementContext
Menu.bind(this), true); |
| 34 | 34 |
| 35 this._listElement = this.contentElement.createChild('div', 'blocked-urls-lis
t'); | 35 this._listElement = this.contentElement.createChild('div', 'blocked-urls-lis
t'); |
| 36 | 36 |
| 37 /** @type {!Map<string, number>} */ | 37 /** @type {!Map<string, number>} */ |
| 38 this._blockedCountForUrl = new Map(); | 38 this._blockedCountForUrl = new Map(); |
| 39 WebInspector.targetManager.addModelListener( | 39 SDK.targetManager.addModelListener( |
| 40 WebInspector.NetworkManager, WebInspector.NetworkManager.Events.RequestF
inished, this._onRequestFinished, this); | 40 SDK.NetworkManager, SDK.NetworkManager.Events.RequestFinished, this._onR
equestFinished, this); |
| 41 | 41 |
| 42 this._updateThrottler = new WebInspector.Throttler(200); | 42 this._updateThrottler = new Common.Throttler(200); |
| 43 | 43 |
| 44 this._update(); | 44 this._update(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static reset() { | 47 static reset() { |
| 48 if (WebInspector.BlockedURLsPane._instance) | 48 if (Network.BlockedURLsPane._instance) |
| 49 WebInspector.BlockedURLsPane._instance.reset(); | 49 Network.BlockedURLsPane._instance.reset(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @param {!Event} event | 53 * @param {!Event} event |
| 54 */ | 54 */ |
| 55 _emptyElementContextMenu(event) { | 55 _emptyElementContextMenu(event) { |
| 56 var contextMenu = new WebInspector.ContextMenu(event); | 56 var contextMenu = new UI.ContextMenu(event); |
| 57 contextMenu.appendItem(WebInspector.UIString.capitalize('Add ^pattern'), thi
s._addButtonClicked.bind(this)); | 57 contextMenu.appendItem(Common.UIString.capitalize('Add ^pattern'), this._add
ButtonClicked.bind(this)); |
| 58 contextMenu.show(); | 58 contextMenu.show(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 _addButtonClicked() { | 61 _addButtonClicked() { |
| 62 this._emptyElement.classList.add('hidden'); | 62 this._emptyElement.classList.add('hidden'); |
| 63 var element = this._createElement('', this._blockedURLsSetting.get().length)
; | 63 var element = this._createElement('', this._blockedURLsSetting.get().length)
; |
| 64 this._listElement.appendChild(element); | 64 this._listElement.appendChild(element); |
| 65 element.scrollIntoViewIfNeeded(); | 65 element.scrollIntoViewIfNeeded(); |
| 66 this._edit('', element, this._addBlockedURL.bind(this)); | 66 this._edit('', element, this._addBlockedURL.bind(this)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @param {string} content | 70 * @param {string} content |
| 71 * @param {!Element} element | 71 * @param {!Element} element |
| 72 * @param {function(string)} onAccept | 72 * @param {function(string)} onAccept |
| 73 * @private | 73 * @private |
| 74 */ | 74 */ |
| 75 _edit(content, element, onAccept) { | 75 _edit(content, element, onAccept) { |
| 76 this._editing = true; | 76 this._editing = true; |
| 77 | 77 |
| 78 element.classList.add('blocked-url-editing'); | 78 element.classList.add('blocked-url-editing'); |
| 79 var input = element.createChild('input'); | 79 var input = element.createChild('input'); |
| 80 input.setAttribute('type', 'text'); | 80 input.setAttribute('type', 'text'); |
| 81 input.value = content; | 81 input.value = content; |
| 82 input.placeholder = WebInspector.UIString('Text pattern to block matching re
quests; use * for wildcard'); | 82 input.placeholder = Common.UIString('Text pattern to block matching requests
; use * for wildcard'); |
| 83 input.addEventListener('blur', commit.bind(this), false); | 83 input.addEventListener('blur', commit.bind(this), false); |
| 84 input.addEventListener('keydown', keydown.bind(this), false); | 84 input.addEventListener('keydown', keydown.bind(this), false); |
| 85 input.focus(); | 85 input.focus(); |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @this {WebInspector.BlockedURLsPane} | 88 * @this {Network.BlockedURLsPane} |
| 89 */ | 89 */ |
| 90 function finish() { | 90 function finish() { |
| 91 this._editing = false; | 91 this._editing = false; |
| 92 element.removeChild(input); | 92 element.removeChild(input); |
| 93 element.classList.remove('blocked-url-editing'); | 93 element.classList.remove('blocked-url-editing'); |
| 94 } | 94 } |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @this {WebInspector.BlockedURLsPane} | 97 * @this {Network.BlockedURLsPane} |
| 98 */ | 98 */ |
| 99 function commit() { | 99 function commit() { |
| 100 if (!this._editing) | 100 if (!this._editing) |
| 101 return; | 101 return; |
| 102 var text = input.value.trim(); | 102 var text = input.value.trim(); |
| 103 finish.call(this); | 103 finish.call(this); |
| 104 if (text) | 104 if (text) |
| 105 onAccept(text); | 105 onAccept(text); |
| 106 else | 106 else |
| 107 this._update(); | 107 this._update(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * @this {WebInspector.BlockedURLsPane} | 111 * @this {Network.BlockedURLsPane} |
| 112 * @param {!Event} event | 112 * @param {!Event} event |
| 113 */ | 113 */ |
| 114 function keydown(event) { | 114 function keydown(event) { |
| 115 if (isEnterKey(event)) { | 115 if (isEnterKey(event)) { |
| 116 event.consume(); | 116 event.consume(); |
| 117 commit.call(this); | 117 commit.call(this); |
| 118 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code |
| event.key === 'Escape') { | 118 } else if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code || event.ke
y === 'Escape') { |
| 119 event.consume(); | 119 event.consume(); |
| 120 finish.call(this); | 120 finish.call(this); |
| 121 this._update(); | 121 this._update(); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * @param {string} url | 127 * @param {string} url |
| 128 */ | 128 */ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 153 | 153 |
| 154 _removeAll() { | 154 _removeAll() { |
| 155 this._blockedURLsSetting.set([]); | 155 this._blockedURLsSetting.set([]); |
| 156 } | 156 } |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * @param {number} index | 159 * @param {number} index |
| 160 * @param {!Event} event | 160 * @param {!Event} event |
| 161 */ | 161 */ |
| 162 _contextMenu(index, event) { | 162 _contextMenu(index, event) { |
| 163 var contextMenu = new WebInspector.ContextMenu(event); | 163 var contextMenu = new UI.ContextMenu(event); |
| 164 contextMenu.appendItem(WebInspector.UIString.capitalize('Add ^pattern'), thi
s._addButtonClicked.bind(this)); | 164 contextMenu.appendItem(Common.UIString.capitalize('Add ^pattern'), this._add
ButtonClicked.bind(this)); |
| 165 contextMenu.appendItem( | 165 contextMenu.appendItem( |
| 166 WebInspector.UIString.capitalize('Remove ^pattern'), this._removeBlocked
URL.bind(this, index)); | 166 Common.UIString.capitalize('Remove ^pattern'), this._removeBlockedURL.bi
nd(this, index)); |
| 167 contextMenu.appendItem(WebInspector.UIString.capitalize('Remove ^all'), this
._removeAll.bind(this)); | 167 contextMenu.appendItem(Common.UIString.capitalize('Remove ^all'), this._remo
veAll.bind(this)); |
| 168 contextMenu.show(); | 168 contextMenu.show(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @return {!Promise<?>} | 172 * @return {!Promise<?>} |
| 173 */ | 173 */ |
| 174 _update() { | 174 _update() { |
| 175 if (this._editing) | 175 if (this._editing) |
| 176 return Promise.resolve(); | 176 return Promise.resolve(); |
| 177 | 177 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 191 */ | 191 */ |
| 192 _createElement(url, index) { | 192 _createElement(url, index) { |
| 193 var element = createElementWithClass('div', 'blocked-url'); | 193 var element = createElementWithClass('div', 'blocked-url'); |
| 194 | 194 |
| 195 var label = element.createChild('div', 'blocked-url-text'); | 195 var label = element.createChild('div', 'blocked-url-text'); |
| 196 label.textContent = url; | 196 label.textContent = url; |
| 197 | 197 |
| 198 var count = this._blockedRequestsCount(url); | 198 var count = this._blockedRequestsCount(url); |
| 199 var countElement = element.createChild('div', 'blocked-count monospace'); | 199 var countElement = element.createChild('div', 'blocked-count monospace'); |
| 200 countElement.textContent = String.sprintf('[%d]', count); | 200 countElement.textContent = String.sprintf('[%d]', count); |
| 201 countElement.title = WebInspector.UIString( | 201 countElement.title = Common.UIString( |
| 202 count === 1 ? '%d request blocked by this pattern' : '%d requests blocke
d by this pattern', count); | 202 count === 1 ? '%d request blocked by this pattern' : '%d requests blocke
d by this pattern', count); |
| 203 | 203 |
| 204 var removeButton = element.createChild('div', 'remove-button'); | 204 var removeButton = element.createChild('div', 'remove-button'); |
| 205 removeButton.title = WebInspector.UIString('Remove'); | 205 removeButton.title = Common.UIString('Remove'); |
| 206 removeButton.addEventListener('click', this._removeBlockedURL.bind(this, ind
ex), false); | 206 removeButton.addEventListener('click', this._removeBlockedURL.bind(this, ind
ex), false); |
| 207 | 207 |
| 208 element.addEventListener('contextmenu', this._contextMenu.bind(this, index),
true); | 208 element.addEventListener('contextmenu', this._contextMenu.bind(this, index),
true); |
| 209 element.addEventListener( | 209 element.addEventListener( |
| 210 'dblclick', this._edit.bind(this, url, element, this._changeBlockedURL.b
ind(this, index)), false); | 210 'dblclick', this._edit.bind(this, url, element, this._changeBlockedURL.b
ind(this, index)), false); |
| 211 return element; | 211 return element; |
| 212 } | 212 } |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * @param {string} url | 215 * @param {string} url |
| (...skipping 29 matching lines...) Expand all Loading... |
| 245 pos += part.length; | 245 pos += part.length; |
| 246 } | 246 } |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 reset() { | 250 reset() { |
| 251 this._blockedCountForUrl.clear(); | 251 this._blockedCountForUrl.clear(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 /** | 254 /** |
| 255 * @param {!WebInspector.Event} event | 255 * @param {!Common.Event} event |
| 256 */ | 256 */ |
| 257 _onRequestFinished(event) { | 257 _onRequestFinished(event) { |
| 258 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); | 258 var request = /** @type {!SDK.NetworkRequest} */ (event.data); |
| 259 if (request.wasBlocked()) { | 259 if (request.wasBlocked()) { |
| 260 var count = this._blockedCountForUrl.get(request.url) || 0; | 260 var count = this._blockedCountForUrl.get(request.url) || 0; |
| 261 this._blockedCountForUrl.set(request.url, count + 1); | 261 this._blockedCountForUrl.set(request.url, count + 1); |
| 262 this._updateThrottler.schedule(this._update.bind(this)); | 262 this._updateThrottler.schedule(this._update.bind(this)); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 /** @type {?WebInspector.BlockedURLsPane} */ | 267 /** @type {?Network.BlockedURLsPane} */ |
| 268 WebInspector.BlockedURLsPane._instance = null; | 268 Network.BlockedURLsPane._instance = null; |
| 269 | 269 |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * @implements {WebInspector.ActionDelegate} | 272 * @implements {UI.ActionDelegate} |
| 273 * @unrestricted | 273 * @unrestricted |
| 274 */ | 274 */ |
| 275 WebInspector.BlockedURLsPane.ActionDelegate = class { | 275 Network.BlockedURLsPane.ActionDelegate = class { |
| 276 /** | 276 /** |
| 277 * @override | 277 * @override |
| 278 * @param {!WebInspector.Context} context | 278 * @param {!UI.Context} context |
| 279 * @param {string} actionId | 279 * @param {string} actionId |
| 280 * @return {boolean} | 280 * @return {boolean} |
| 281 */ | 281 */ |
| 282 handleAction(context, actionId) { | 282 handleAction(context, actionId) { |
| 283 WebInspector.viewManager.showView('network.blocked-urls'); | 283 UI.viewManager.showView('network.blocked-urls'); |
| 284 return true; | 284 return true; |
| 285 } | 285 } |
| 286 }; | 286 }; |
| OLD | NEW |