Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 4 | |
| 5 | import * as Common from '../common/common.js'; |
| 6 | import * as SDK from '../sdk/sdk.js'; |
| 7 | import * as UI from '../ui/ui.js'; |
| 8 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 9 | /** |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 10 | * @implements {UI.ContextFlavorListener.ContextFlavorListener} |
| 11 | * @implements {UI.Toolbar.ItemsProvider} |
| 12 | * @implements {UI.ListControl.ListDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 13 | * @unrestricted |
| 14 | */ |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 15 | export class XHRBreakpointsSidebarPane extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 16 | constructor() { |
| 17 | super(true); |
| 18 | this.registerRequiredCSS('browser_debugger/xhrBreakpointsSidebarPane.css'); |
| 19 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 20 | /** @type {!UI.ListModel.ListModel<string>} */ |
| 21 | this._breakpoints = new UI.ListModel.ListModel(); |
| 22 | this._list = new UI.ListControl.ListControl(this._breakpoints, this, UI.ListControl.ListMode.NonViewport); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 23 | this.contentElement.appendChild(this._list.element); |
| 24 | this._list.element.classList.add('breakpoint-list', 'hidden'); |
| 25 | UI.ARIAUtils.markAsList(this._list.element); |
| 26 | UI.ARIAUtils.setAccessibleName(this._list.element, ls`XHR/fetch Breakpoints`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 27 | this._emptyElement = this.contentElement.createChild('div', 'gray-info-message'); |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 28 | this._emptyElement.textContent = Common.UIString.UIString('No breakpoints'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 29 | |
| 30 | /** @type {!Map.<string, !Element>} */ |
| 31 | this._breakpointElements = new Map(); |
| 32 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 33 | this._addButton = new UI.Toolbar.ToolbarButton(ls`Add XHR/fetch breakpoint`, 'largeicon-add'); |
Tim van der Lippe | 37a35ff | 2020-03-03 13:49:02 | [diff] [blame] | 34 | this._addButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, event => { |
| 35 | this._addButtonClicked(); |
| 36 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 37 | |
| 38 | this._emptyElement.addEventListener('contextmenu', this._emptyElementContextMenu.bind(this), true); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 39 | this._emptyElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 40 | this._restoreBreakpoints(); |
| 41 | this._update(); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @override |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 46 | * @return {!Array<!UI.Toolbar.ToolbarItem>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 47 | */ |
| 48 | toolbarItems() { |
| 49 | return [this._addButton]; |
| 50 | } |
| 51 | |
Tim van der Lippe | 37a35ff | 2020-03-03 13:49:02 | [diff] [blame] | 52 | /** |
| 53 | * @param {!Event} event |
| 54 | */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 55 | _emptyElementContextMenu(event) { |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 56 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
| 57 | contextMenu.defaultSection().appendItem( |
| 58 | Common.UIString.UIString('Add breakpoint'), this._addButtonClicked.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 59 | contextMenu.show(); |
| 60 | } |
| 61 | |
Joel Einbinder | 4ea5355 | 2018-12-13 23:18:04 | [diff] [blame] | 62 | async _addButtonClicked() { |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 63 | await UI.ViewManager.ViewManager.instance().showView('sources.xhrBreakpoints'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 64 | |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 65 | const inputElementContainer = document.createElement('p'); |
| 66 | inputElementContainer.classList.add('breakpoint-condition'); |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 67 | inputElementContainer.textContent = Common.UIString.UIString('Break when URL contains:'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 68 | |
| 69 | const inputElement = inputElementContainer.createChild('span', 'breakpoint-condition-input'); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 70 | this._addListElement(inputElementContainer, /** @type {?Element} */ (this._list.element.firstChild)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * @param {boolean} accept |
| 74 | * @param {!Element} e |
| 75 | * @param {string} text |
Paul Lewis | 2a4f9fe | 2020-01-09 15:19:41 | [diff] [blame] | 76 | * @this {XHRBreakpointsSidebarPane} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 77 | */ |
| 78 | function finishEditing(accept, e, text) { |
| 79 | this._removeListElement(inputElementContainer); |
| 80 | if (accept) { |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 81 | self.SDK.domDebuggerManager.addXHRBreakpoint(text, true); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 82 | this._setBreakpoint(text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | } |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 84 | this._update(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | const config = new UI.InplaceEditor.Config(finishEditing.bind(this, true), finishEditing.bind(this, false)); |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 88 | UI.InplaceEditor.InplaceEditor.startEditing(inputElement, config); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 92 | * @override |
| 93 | * @param {string} item |
| 94 | * @return {number} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 95 | */ |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 96 | heightForItem(item) { |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @override |
| 102 | * @param {string} item |
| 103 | * @return {boolean} |
| 104 | */ |
| 105 | isItemSelectable(item) { |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @param {string} url |
| 111 | */ |
| 112 | _setBreakpoint(url) { |
| 113 | if (this._breakpoints.indexOf(url) !== -1) { |
| 114 | this._list.refreshItem(url); |
| 115 | } else { |
| 116 | this._breakpoints.insertWithComparator(url, (a, b) => { |
| 117 | if (a > b) { |
| 118 | return 1; |
| 119 | } |
| 120 | if (a < b) { |
| 121 | return -1; |
| 122 | } |
| 123 | return 0; |
| 124 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 125 | } |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 126 | if (!this._list.selectedItem() || !this.hasFocus()) { |
| 127 | this._list.selectItem(this._breakpoints.at(0)); |
| 128 | } |
| 129 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 130 | |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 131 | /** |
| 132 | * @override |
| 133 | * @param {string} item |
| 134 | * @return {!Element} |
| 135 | */ |
| 136 | createElementForItem(item) { |
| 137 | const listItemElement = createElement('div'); |
| 138 | UI.ARIAUtils.markAsListitem(listItemElement); |
| 139 | const element = listItemElement.createChild('div', 'breakpoint-entry'); |
| 140 | listItemElement.checkboxElement = element; |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 141 | const enabled = self.SDK.domDebuggerManager.xhrBreakpoints().get(item); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 142 | UI.ARIAUtils.markAsCheckbox(element); |
| 143 | UI.ARIAUtils.setChecked(element, enabled); |
| 144 | element._url = item; |
| 145 | element.addEventListener('contextmenu', this._contextMenu.bind(this, item), true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 146 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 147 | const title = |
| 148 | item ? Common.UIString.UIString('URL contains "%s"', item) : Common.UIString.UIString('Any XHR or fetch'); |
| 149 | const label = UI.UIUtils.CheckboxLabel.create(title, enabled); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 150 | UI.ARIAUtils.markAsHidden(label); |
| 151 | UI.ARIAUtils.setAccessibleName(element, title); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 152 | element.appendChild(label); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 153 | label.checkboxElement.addEventListener('click', this._checkboxClicked.bind(this, item, enabled), false); |
| 154 | element.addEventListener('click', event => { |
| 155 | if (event.target === element) { |
| 156 | this._checkboxClicked(item, enabled); |
| 157 | } |
| 158 | }, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 159 | element._checkboxElement = label.checkboxElement; |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 160 | label.checkboxElement.tabIndex = -1; |
| 161 | element.tabIndex = -1; |
| 162 | if (item === this._list.selectedItem()) { |
| 163 | element.tabIndex = 0; |
| 164 | this.setDefaultFocusedElement(element); |
| 165 | } |
| 166 | element.addEventListener('keydown', event => { |
| 167 | let handled = false; |
| 168 | if (event.key === ' ') { |
| 169 | this._checkboxClicked(item, enabled); |
| 170 | handled = true; |
| 171 | } else if (isEnterKey(event)) { |
| 172 | this._labelClicked(item); |
| 173 | handled = true; |
| 174 | } |
| 175 | |
| 176 | if (handled) { |
| 177 | event.consume(true); |
| 178 | } |
| 179 | }); |
| 180 | |
| 181 | if (item === this._hitBreakpoint) { |
| 182 | element.classList.add('breakpoint-hit'); |
| 183 | UI.ARIAUtils.setDescription(element, ls`breakpoint hit`); |
| 184 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 185 | |
| 186 | label.classList.add('cursor-auto'); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 187 | label.textElement.addEventListener('dblclick', this._labelClicked.bind(this, item), false); |
| 188 | this._breakpointElements.set(item, listItemElement); |
| 189 | return listItemElement; |
| 190 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 191 | |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 192 | /** |
| 193 | * @override |
| 194 | * @param {string} from |
| 195 | * @param {string} to |
| 196 | * @param {?Element} fromElement |
| 197 | * @param {?Element} toElement |
| 198 | */ |
| 199 | selectedItemChanged(from, to, fromElement, toElement) { |
| 200 | if (fromElement) { |
| 201 | fromElement.checkboxElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 202 | } |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 203 | if (toElement) { |
| 204 | this.setDefaultFocusedElement(toElement.checkboxElement); |
| 205 | toElement.checkboxElement.tabIndex = 0; |
| 206 | if (this.hasFocus()) { |
| 207 | toElement.checkboxElement.focus(); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * @override |
| 214 | * @param {?Element} fromElement |
| 215 | * @param {?Element} toElement |
| 216 | */ |
| 217 | updateSelectedItemARIA(fromElement, toElement) { |
| 218 | return true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @param {string} url |
| 223 | */ |
| 224 | _removeBreakpoint(url) { |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 225 | const index = this._breakpoints.indexOf(url); |
| 226 | if (index >= 0) { |
| 227 | this._breakpoints.remove(index); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 228 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 229 | this._breakpointElements.delete(url); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 230 | this._update(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @param {!Element} element |
| 235 | * @param {?Node} beforeNode |
| 236 | */ |
| 237 | _addListElement(element, beforeNode) { |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 238 | this._list.element.insertBefore(element, beforeNode); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 239 | this._emptyElement.classList.add('hidden'); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 240 | this._list.element.classList.remove('hidden'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /** |
| 244 | * @param {!Element} element |
| 245 | */ |
| 246 | _removeListElement(element) { |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 247 | this._list.element.removeChild(element); |
| 248 | if (!this._list.element.firstElementChild) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 249 | this._emptyElement.classList.remove('hidden'); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 250 | this._list.element.classList.add('hidden'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | _contextMenu(url, event) { |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 255 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 256 | |
| 257 | /** |
Paul Lewis | 2a4f9fe | 2020-01-09 15:19:41 | [diff] [blame] | 258 | * @this {XHRBreakpointsSidebarPane} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 259 | */ |
| 260 | function removeBreakpoint() { |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 261 | self.SDK.domDebuggerManager.removeXHRBreakpoint(url); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 262 | this._removeBreakpoint(url); |
| 263 | } |
| 264 | |
| 265 | /** |
Paul Lewis | 2a4f9fe | 2020-01-09 15:19:41 | [diff] [blame] | 266 | * @this {XHRBreakpointsSidebarPane} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 267 | */ |
| 268 | function removeAllBreakpoints() { |
| 269 | for (const url of this._breakpointElements.keys()) { |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 270 | self.SDK.domDebuggerManager.removeXHRBreakpoint(url); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 271 | this._removeBreakpoint(url); |
| 272 | } |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 273 | this._update(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 274 | } |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 275 | const removeAllTitle = Common.UIString.UIString('Remove all breakpoints'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 276 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 277 | contextMenu.defaultSection().appendItem( |
| 278 | Common.UIString.UIString('Add breakpoint'), this._addButtonClicked.bind(this)); |
| 279 | contextMenu.defaultSection().appendItem(Common.UIString.UIString('Remove breakpoint'), removeBreakpoint.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 280 | contextMenu.defaultSection().appendItem(removeAllTitle, removeAllBreakpoints.bind(this)); |
| 281 | contextMenu.show(); |
| 282 | } |
| 283 | |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 284 | /** |
| 285 | * @param {string} url |
| 286 | * @param {boolean} checked |
| 287 | */ |
| 288 | _checkboxClicked(url, checked) { |
| 289 | const hadFocus = this.hasFocus(); |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 290 | self.SDK.domDebuggerManager.toggleXHRBreakpoint(url, !checked); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 291 | this._list.refreshItem(url); |
| 292 | this._list.selectItem(url); |
| 293 | if (hadFocus) { |
| 294 | this.focus(); |
| 295 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 296 | } |
| 297 | |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 298 | /** |
| 299 | * @param {string} url |
| 300 | */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 301 | _labelClicked(url) { |
| 302 | const element = this._breakpointElements.get(url) || null; |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 303 | const inputElement = document.createElement('span'); |
| 304 | inputElement.classList.add('breakpoint-condition'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 305 | inputElement.textContent = url; |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 306 | this._list.element.insertBefore(inputElement, element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 307 | element.classList.add('hidden'); |
| 308 | |
| 309 | /** |
| 310 | * @param {boolean} accept |
| 311 | * @param {!Element} e |
| 312 | * @param {string} text |
Paul Lewis | 2a4f9fe | 2020-01-09 15:19:41 | [diff] [blame] | 313 | * @this {XHRBreakpointsSidebarPane} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 314 | */ |
| 315 | function finishEditing(accept, e, text) { |
| 316 | this._removeListElement(inputElement); |
| 317 | if (accept) { |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 318 | self.SDK.domDebuggerManager.removeXHRBreakpoint(url); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 319 | this._removeBreakpoint(url); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 320 | const enabled = element ? element.checkboxElement._checkboxElement.checked : true; |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 321 | self.SDK.domDebuggerManager.addXHRBreakpoint(text, enabled); |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 322 | this._setBreakpoint(text); |
| 323 | this._list.selectItem(text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 324 | } else { |
| 325 | element.classList.remove('hidden'); |
| 326 | } |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 327 | this.focus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 328 | } |
| 329 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 330 | UI.InplaceEditor.InplaceEditor.startEditing( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 331 | inputElement, new UI.InplaceEditor.Config(finishEditing.bind(this, true), finishEditing.bind(this, false))); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * @override |
| 336 | * @param {?Object} object |
| 337 | */ |
| 338 | flavorChanged(object) { |
| 339 | this._update(); |
| 340 | } |
| 341 | |
| 342 | _update() { |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 343 | const isEmpty = this._breakpoints.length === 0; |
| 344 | this._list.element.classList.toggle('hidden', isEmpty); |
| 345 | this._emptyElement.classList.toggle('hidden', !isEmpty); |
| 346 | |
Tim van der Lippe | 046db88 | 2020-02-13 13:55:11 | [diff] [blame] | 347 | const details = self.UI.context.flavor(SDK.DebuggerModel.DebuggerPausedDetails); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 348 | if (!details || details.reason !== SDK.DebuggerModel.BreakReason.XHR) { |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 349 | if (this._hitBreakpoint) { |
| 350 | const oldHitBreakpoint = this._hitBreakpoint; |
| 351 | delete this._hitBreakpoint; |
| 352 | if (this._breakpoints.indexOf(oldHitBreakpoint) >= 0) { |
| 353 | this._list.refreshItem(oldHitBreakpoint); |
| 354 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 355 | } |
| 356 | return; |
| 357 | } |
| 358 | const url = details.auxData['breakpointURL']; |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 359 | this._hitBreakpoint = url; |
| 360 | if (this._breakpoints.indexOf(url) < 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 361 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 362 | } |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 363 | this._list.refreshItem(url); |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 364 | UI.ViewManager.ViewManager.instance().showView('sources.xhrBreakpoints'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | _restoreBreakpoints() { |
Paul Lewis | 5e21b5e | 2020-01-24 14:01:22 | [diff] [blame] | 368 | const breakpoints = self.SDK.domDebuggerManager.xhrBreakpoints(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 369 | for (const url of breakpoints.keys()) { |
Jack Lynch | de07ab8 | 2020-01-07 23:40:59 | [diff] [blame] | 370 | this._setBreakpoint(url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 371 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 372 | } |
Paul Lewis | 7f7a920 | 2019-11-26 16:10:56 | [diff] [blame] | 373 | } |