Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 1 | // Copyright 2019 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. |
| 4 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 5 | /* eslint-disable rulesdir/no_underscored_properties */ |
| 6 | |
Tim van der Lippe | 7696157 | 2021-04-06 10:48:07 | [diff] [blame] | 7 | import * as Common from '../../core/common/common.js'; // eslint-disable-line no-unused-vars |
Tim van der Lippe | bb352e6 | 2021-04-01 17:57:28 | [diff] [blame] | 8 | import * as i18n from '../../core/i18n/i18n.js'; |
Tim van der Lippe | aa1ed7a | 2021-03-31 14:38:27 | [diff] [blame] | 9 | import * as Platform from '../../core/platform/platform.js'; |
Tim van der Lippe | e00b92f | 2021-03-31 16:52:17 | [diff] [blame] | 10 | import * as SDK from '../../core/sdk/sdk.js'; |
Tim van der Lippe | 959b6f0 | 2021-04-07 09:07:59 | [diff] [blame] | 11 | import * as Bindings from '../../models/bindings/bindings.js'; |
Tim van der Lippe | 8499fe2 | 2021-04-12 16:42:47 | [diff] [blame^] | 12 | import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js'; |
Tim van der Lippe | aa61faf | 2021-04-07 15:32:07 | [diff] [blame] | 13 | import * as UI from '../../ui/legacy/legacy.js'; |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 14 | |
Paul Lewis | ddf5834 | 2020-01-15 14:18:07 | [diff] [blame] | 15 | import {BackgroundServiceModel, Events} from './BackgroundServiceModel.js'; // eslint-disable-line no-unused-vars |
| 16 | |
Simon Zünd | 697fb0b | 2021-03-01 10:12:42 | [diff] [blame] | 17 | const UIStrings = { |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 18 | /** |
| 19 | *@description Text in Background Service View of the Application panel |
| 20 | */ |
| 21 | backgroundFetch: 'Background Fetch', |
| 22 | /** |
| 23 | *@description Text in Background Service View of the Application panel |
| 24 | */ |
| 25 | backgroundSync: 'Background Sync', |
| 26 | /** |
| 27 | *@description Text in Background Service View of the Application panel |
| 28 | */ |
| 29 | pushMessaging: 'Push Messaging', |
| 30 | /** |
| 31 | *@description Text in Background Service View of the Application panel |
| 32 | */ |
| 33 | notifications: 'Notifications', |
| 34 | /** |
| 35 | *@description Text in Background Service View of the Application panel |
| 36 | */ |
| 37 | paymentHandler: 'Payment Handler', |
| 38 | /** |
| 39 | *@description Text in the Periodic Background Service View of the Application panel |
| 40 | */ |
| 41 | periodicBackgroundSync: 'Periodic Background Sync', |
| 42 | /** |
| 43 | *@description Text to clear content |
| 44 | */ |
| 45 | clear: 'Clear', |
| 46 | /** |
| 47 | *@description Tooltip text that appears when hovering over the largeicon download button in the Background Service View of the Application panel |
| 48 | */ |
| 49 | saveEvents: 'Save events', |
| 50 | /** |
| 51 | *@description Text in Background Service View of the Application panel |
| 52 | */ |
| 53 | showEventsFromOtherDomains: 'Show events from other domains', |
| 54 | /** |
| 55 | *@description Title of an action under the Background Services category that can be invoked through the Command Menu |
| 56 | */ |
| 57 | stopRecordingEvents: 'Stop recording events', |
| 58 | /** |
| 59 | *@description Title of an action under the Background Services category that can be invoked through the Command Menu |
| 60 | */ |
| 61 | startRecordingEvents: 'Start recording events', |
| 62 | /** |
| 63 | *@description Text for timestamps of items |
| 64 | */ |
| 65 | timestamp: 'Timestamp', |
| 66 | /** |
| 67 | *@description Text that refers to some events |
| 68 | */ |
| 69 | event: 'Event', |
| 70 | /** |
| 71 | *@description Text for the origin of something |
| 72 | */ |
| 73 | origin: 'Origin', |
| 74 | /** |
Sigurd Schneider | bee57a8 | 2021-02-23 12:58:24 | [diff] [blame] | 75 | *@description Text in Background Service View of the Application panel. The Scope is a URL associated with the Service Worker, which limits which pages/sites the Service Worker operates on. |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 76 | */ |
Sigurd Schneider | bee57a8 | 2021-02-23 12:58:24 | [diff] [blame] | 77 | swScope: 'Service Worker Scope', |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 78 | /** |
| 79 | *@description Text in Background Service View of the Application panel |
| 80 | */ |
| 81 | instanceId: 'Instance ID', |
| 82 | /** |
| 83 | *@description Text in Application Panel Sidebar of the Application panel |
| 84 | */ |
| 85 | backgroundServices: 'Background Services', |
| 86 | /** |
| 87 | *@description Text that is usually a hyperlink to more documentation |
| 88 | */ |
| 89 | learnMore: 'Learn more', |
| 90 | /** |
| 91 | *@description Text in Background Service View of the Application panel |
| 92 | */ |
| 93 | selectAnEntryToViewMetadata: 'Select an entry to view metadata', |
| 94 | /** |
| 95 | *@description Text in Background Service View of the Application panel |
| 96 | *@example {Background Fetch} PH1 |
| 97 | */ |
| 98 | recordingSActivity: 'Recording {PH1} activity...', |
| 99 | /** |
| 100 | *@description Inform users that DevTools are recording/waiting for events in the Periodic Background Sync tool of the Application panel |
| 101 | *@example {Background Fetch} PH1 |
| 102 | */ |
| 103 | devtoolsWillRecordAllSActivity: 'DevTools will record all {PH1} activity for up to 3 days, even when closed.', |
| 104 | /** |
| 105 | *@description Text in Background Service View of the Application panel |
| 106 | *@example {record} PH1 |
| 107 | *@example {Ctrl + R} PH2 |
| 108 | */ |
| 109 | clickTheRecordButtonSOrHitSTo: 'Click the record button {PH1} or hit {PH2} to start recording.', |
| 110 | /** |
| 111 | *@description Text to show an item is empty |
| 112 | */ |
| 113 | empty: 'empty', |
| 114 | /** |
| 115 | *@description Text in Background Service View of the Application panel |
| 116 | */ |
| 117 | noMetadataForThisEvent: 'No metadata for this event', |
| 118 | }; |
Tim van der Lippe | c59708f | 2021-03-31 15:07:19 | [diff] [blame] | 119 | const str_ = i18n.i18n.registerUIStrings('panels/application/BackgroundServiceView.ts', UIStrings); |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 120 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 121 | export class BackgroundServiceView extends UI.Widget.VBox { |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 122 | _serviceName: Protocol.BackgroundService.ServiceName; |
| 123 | _model: BackgroundServiceModel; |
| 124 | _serviceWorkerManager: SDK.ServiceWorkerManager.ServiceWorkerManager|null; |
| 125 | _securityOriginManager: SDK.SecurityOriginManager.SecurityOriginManager; |
| 126 | _recordAction: UI.ActionRegistration.Action; |
| 127 | _recordButton!: UI.Toolbar.ToolbarToggle; |
| 128 | _originCheckbox!: UI.Toolbar.ToolbarCheckbox; |
| 129 | _saveButton!: UI.Toolbar.ToolbarButton; |
| 130 | _toolbar: UI.Toolbar.Toolbar; |
| 131 | _splitWidget: UI.SplitWidget.SplitWidget; |
| 132 | _dataGrid: DataGrid.DataGrid.DataGridImpl<EventData>; |
| 133 | _previewPanel: UI.Widget.VBox; |
| 134 | _selectedEventNode: EventDataNode|null; |
| 135 | _preview: UI.Widget.Widget|null; |
| 136 | |
| 137 | static getUIString(serviceName: string): string { |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 138 | switch (serviceName) { |
| 139 | case Protocol.BackgroundService.ServiceName.BackgroundFetch: |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 140 | return i18nString(UIStrings.backgroundFetch); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 141 | case Protocol.BackgroundService.ServiceName.BackgroundSync: |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 142 | return i18nString(UIStrings.backgroundSync); |
Fergus Dall | 0be4f4c | 2019-05-21 00:01:29 | [diff] [blame] | 143 | case Protocol.BackgroundService.ServiceName.PushMessaging: |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 144 | return i18nString(UIStrings.pushMessaging); |
Fergus Dall | 0be4f4c | 2019-05-21 00:01:29 | [diff] [blame] | 145 | case Protocol.BackgroundService.ServiceName.Notifications: |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 146 | return i18nString(UIStrings.notifications); |
Rayan Kanso | 8d7918a | 2019-07-03 21:03:38 | [diff] [blame] | 147 | case Protocol.BackgroundService.ServiceName.PaymentHandler: |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 148 | return i18nString(UIStrings.paymentHandler); |
Rayan Kanso | 5480967 | 2019-07-24 18:40:28 | [diff] [blame] | 149 | case Protocol.BackgroundService.ServiceName.PeriodicBackgroundSync: |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 150 | return i18nString(UIStrings.periodicBackgroundSync); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 151 | default: |
| 152 | return ''; |
| 153 | } |
| 154 | } |
| 155 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 156 | constructor(serviceName: Protocol.BackgroundService.ServiceName, model: BackgroundServiceModel) { |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 157 | super(true); |
Tim van der Lippe | c59708f | 2021-03-31 15:07:19 | [diff] [blame] | 158 | this.registerRequiredCSS('panels/application/backgroundServiceView.css', {enableLegacyPatching: false}); |
Tim van der Lippe | aa61faf | 2021-04-07 15:32:07 | [diff] [blame] | 159 | this.registerRequiredCSS('ui/legacy/emptyWidget.css', {enableLegacyPatching: false}); |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 160 | |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 161 | this._serviceName = serviceName; |
| 162 | |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 163 | this._model = model; |
Paul Lewis | ddf5834 | 2020-01-15 14:18:07 | [diff] [blame] | 164 | this._model.addEventListener(Events.RecordingStateChanged, this._onRecordingStateChanged, this); |
| 165 | this._model.addEventListener(Events.BackgroundServiceEventReceived, this._onEventReceived, this); |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 166 | this._model.enable(this._serviceName); |
| 167 | |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 168 | this._serviceWorkerManager = this._model.target().model(SDK.ServiceWorkerManager.ServiceWorkerManager); |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 169 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 170 | this._securityOriginManager = this._model.target().model(SDK.SecurityOriginManager.SecurityOriginManager) as |
| 171 | SDK.SecurityOriginManager.SecurityOriginManager; |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 172 | if (!this._securityOriginManager) { |
| 173 | throw new Error('SecurityOriginManager instance is missing'); |
| 174 | } |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 175 | this._securityOriginManager.addEventListener( |
| 176 | SDK.SecurityOriginManager.Events.MainSecurityOriginChanged, () => this._onOriginChanged()); |
Paul Lewis | 24cb740 | 2020-01-24 13:46:35 | [diff] [blame] | 177 | this._recordAction = |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 178 | (UI.ActionRegistry.ActionRegistry.instance().action('background-service.toggle-recording') as |
| 179 | UI.ActionRegistration.Action); |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 180 | |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 181 | this._toolbar = new UI.Toolbar.Toolbar('background-service-toolbar', this.contentElement); |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 182 | this._setupToolbar(); |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 183 | |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 184 | /** |
| 185 | * This will contain the DataGrid for displaying events, and a panel at the bottom for showing |
| 186 | * extra metadata related to the selected event. |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 187 | */ |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 188 | this._splitWidget = new UI.SplitWidget.SplitWidget(/* isVertical= */ false, /* secondIsSidebar= */ true); |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 189 | this._splitWidget.show(this.contentElement); |
| 190 | |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 191 | this._dataGrid = this._createDataGrid(); |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 192 | |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 193 | this._previewPanel = new UI.Widget.VBox(); |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 194 | |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 195 | this._selectedEventNode = null; |
| 196 | |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 197 | this._preview = null; |
| 198 | |
| 199 | this._splitWidget.setMainWidget(this._dataGrid.asWidget()); |
| 200 | this._splitWidget.setSidebarWidget(this._previewPanel); |
| 201 | |
| 202 | this._showPreview(null); |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Creates the toolbar UI element. |
| 207 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 208 | async _setupToolbar(): Promise<void> { |
| 209 | this._recordButton = (UI.Toolbar.Toolbar.createActionButton(this._recordAction) as UI.Toolbar.ToolbarToggle); |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 210 | this._toolbar.appendToolbarItem(this._recordButton); |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 211 | |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 212 | const clearButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.clear), 'largeicon-clear'); |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 213 | clearButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, () => this._clearEvents()); |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 214 | this._toolbar.appendToolbarItem(clearButton); |
| 215 | |
| 216 | this._toolbar.appendSeparator(); |
| 217 | |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 218 | this._saveButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.saveEvents), 'largeicon-download'); |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 219 | this._saveButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, _event => { |
Tim van der Lippe | 37a35ff | 2020-03-03 13:49:02 | [diff] [blame] | 220 | this._saveToFile(); |
| 221 | }); |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 222 | this._saveButton.setEnabled(false); |
| 223 | this._toolbar.appendToolbarItem(this._saveButton); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 224 | |
| 225 | this._toolbar.appendSeparator(); |
| 226 | |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 227 | this._originCheckbox = new UI.Toolbar.ToolbarCheckbox( |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 228 | i18nString(UIStrings.showEventsFromOtherDomains), i18nString(UIStrings.showEventsFromOtherDomains), |
| 229 | () => this._refreshView()); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 230 | this._toolbar.appendToolbarItem(this._originCheckbox); |
Rayan Kanso | 6890420 | 2019-02-21 14:16:25 | [diff] [blame] | 231 | } |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 232 | |
| 233 | /** |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 234 | * Displays all available events in the grid. |
| 235 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 236 | _refreshView(): void { |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 237 | this._clearView(); |
| 238 | const events = this._model.getEvents(this._serviceName).filter(event => this._acceptEvent(event)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 239 | for (const event of events) { |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 240 | this._addEvent(event); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 241 | } |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Clears the grid and panel. |
| 246 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 247 | _clearView(): void { |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 248 | this._selectedEventNode = null; |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 249 | this._dataGrid.rootNode().removeChildren(); |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 250 | this._saveButton.setEnabled(false); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 251 | this._showPreview(null); |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /** |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 255 | * Called when the `Toggle Record` button is clicked. |
| 256 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 257 | _toggleRecording(): void { |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 258 | this._model.setRecording(!this._recordButton.toggled(), this._serviceName); |
| 259 | } |
| 260 | |
| 261 | /** |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 262 | * Called when the `Clear` button is clicked. |
| 263 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 264 | _clearEvents(): void { |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 265 | this._model.clearEvents(this._serviceName); |
| 266 | this._clearView(); |
| 267 | } |
| 268 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 269 | _onRecordingStateChanged(event: Common.EventTarget.EventTargetEvent): void { |
| 270 | const state = (event.data as RecordingState); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 271 | if (state.serviceName !== this._serviceName) { |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 272 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 273 | } |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 274 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 275 | if (state.isRecording === this._recordButton.toggled()) { |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 276 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 277 | } |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 278 | |
Rayan Kanso | 0b30aba | 2019-05-17 13:39:59 | [diff] [blame] | 279 | this._recordButton.setToggled(state.isRecording); |
Christy Chen | 13a12ff | 2020-08-20 07:43:26 | [diff] [blame] | 280 | this._updateRecordButtonTooltip(); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 281 | this._showPreview(this._selectedEventNode); |
Rayan Kanso | 8fe8ee2 | 2019-03-04 14:58:46 | [diff] [blame] | 282 | } |
Rayan Kanso | f40e315 | 2019-03-11 13:49:43 | [diff] [blame] | 283 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 284 | _updateRecordButtonTooltip(): void { |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 285 | const buttonTooltip = this._recordButton.toggled() ? i18nString(UIStrings.stopRecordingEvents) : |
| 286 | i18nString(UIStrings.startRecordingEvents); |
Christy Chen | 13a12ff | 2020-08-20 07:43:26 | [diff] [blame] | 287 | this._recordButton.setTitle(buttonTooltip, 'background-service.toggle-recording'); |
| 288 | } |
| 289 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 290 | _onEventReceived(event: Common.EventTarget.EventTargetEvent): void { |
| 291 | const serviceEvent = (event.data as Protocol.BackgroundService.BackgroundServiceEvent); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 292 | if (!this._acceptEvent(serviceEvent)) { |
Rayan Kanso | f40e315 | 2019-03-11 13:49:43 | [diff] [blame] | 293 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 294 | } |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 295 | this._addEvent(serviceEvent); |
| 296 | } |
| 297 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 298 | _onOriginChanged(): void { |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 299 | // No need to refresh the view if we are already showing all events. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 300 | if (this._originCheckbox.checked()) { |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 301 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 302 | } |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 303 | this._refreshView(); |
| 304 | } |
| 305 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 306 | _addEvent(serviceEvent: Protocol.BackgroundService.BackgroundServiceEvent): void { |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 307 | const data = this._createEventData(serviceEvent); |
Tim van der Lippe | 097cdec | 2020-01-06 14:44:17 | [diff] [blame] | 308 | const dataNode = new EventDataNode(data, serviceEvent.eventMetadata); |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 309 | this._dataGrid.rootNode().appendChild(dataNode); |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 310 | |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 311 | if (this._dataGrid.rootNode().children.length === 1) { |
| 312 | this._saveButton.setEnabled(true); |
| 313 | this._showPreview(this._selectedEventNode); |
| 314 | } |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 315 | } |
| 316 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 317 | _createDataGrid(): DataGrid.DataGrid.DataGridImpl<EventData> { |
| 318 | const columns = ([ |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 319 | {id: 'id', title: '#', weight: 1}, |
| 320 | {id: 'timestamp', title: i18nString(UIStrings.timestamp), weight: 8}, |
| 321 | {id: 'eventName', title: i18nString(UIStrings.event), weight: 10}, |
| 322 | {id: 'origin', title: i18nString(UIStrings.origin), weight: 10}, |
Sigurd Schneider | bee57a8 | 2021-02-23 12:58:24 | [diff] [blame] | 323 | {id: 'swScope', title: i18nString(UIStrings.swScope), weight: 5}, |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 324 | {id: 'instanceId', title: i18nString(UIStrings.instanceId), weight: 10}, |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 325 | ] as DataGrid.DataGrid.ColumnDescriptor[]); |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 326 | const dataGrid = new DataGrid.DataGrid.DataGridImpl({ |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 327 | displayName: i18nString(UIStrings.backgroundServices), |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 328 | columns, |
| 329 | editCallback: undefined, |
| 330 | refreshCallback: undefined, |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 331 | deleteCallback: undefined, |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 332 | }); |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 333 | dataGrid.setStriped(true); |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 334 | |
| 335 | dataGrid.addEventListener( |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 336 | DataGrid.DataGrid.Events.SelectedNode, event => this._showPreview((event.data as EventDataNode))); |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 337 | |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 338 | return dataGrid; |
| 339 | } |
| 340 | |
| 341 | /** |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 342 | * Creates the data object to pass to the DataGrid Node. |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 343 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 344 | _createEventData(serviceEvent: Protocol.BackgroundService.BackgroundServiceEvent): EventData { |
Rayan Kanso | cc02ea3 | 2019-05-02 21:26:52 | [diff] [blame] | 345 | let swScope = ''; |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 346 | |
Rayan Kanso | cc02ea3 | 2019-05-02 21:26:52 | [diff] [blame] | 347 | // Try to get the scope of the Service Worker registration to be more user-friendly. |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 348 | const registration = this._serviceWorkerManager ? |
| 349 | this._serviceWorkerManager.registrations().get(serviceEvent.serviceWorkerRegistrationId) : |
| 350 | undefined; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 351 | if (registration) { |
Rayan Kanso | cc02ea3 | 2019-05-02 21:26:52 | [diff] [blame] | 352 | swScope = registration.scopeURL.substr(registration.securityOrigin.length); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 353 | } |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 354 | |
| 355 | return { |
Rayan Kanso | c79a8bb | 2019-05-29 21:08:38 | [diff] [blame] | 356 | id: this._dataGrid.rootNode().children.length + 1, |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 357 | timestamp: UI.UIUtils.formatTimestamp(serviceEvent.timestamp * 1000, /* full= */ true), |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 358 | origin: serviceEvent.origin, |
Rayan Kanso | cc02ea3 | 2019-05-02 21:26:52 | [diff] [blame] | 359 | swScope, |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 360 | eventName: serviceEvent.eventName, |
| 361 | instanceId: serviceEvent.instanceId, |
| 362 | }; |
| 363 | } |
| 364 | |
| 365 | /** |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 366 | * Filtration function to know whether event should be shown or not. |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 367 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 368 | _acceptEvent(event: Protocol.BackgroundService.BackgroundServiceEvent): boolean { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 369 | if (event.service !== this._serviceName) { |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 370 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 371 | } |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 372 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 373 | if (this._originCheckbox.checked()) { |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 374 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 375 | } |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 376 | |
| 377 | // Trim the trailing '/'. |
| 378 | const origin = event.origin.substr(0, event.origin.length - 1); |
| 379 | |
| 380 | return this._securityOriginManager.securityOrigins().includes(origin); |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 381 | } |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 382 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 383 | _createLearnMoreLink(): Element { |
Jecelyn | 90c0416 | 2021-04-07 08:41:35 | [diff] [blame] | 384 | let url = 'https://developer.chrome.com/docs/devtools/javascript/background-services/?utm_source=devtools'; |
Rayan Kanso | 42c0f9e | 2019-09-02 12:21:09 | [diff] [blame] | 385 | |
| 386 | switch (this._serviceName) { |
| 387 | case Protocol.BackgroundService.ServiceName.BackgroundFetch: |
| 388 | url += '#fetch'; |
| 389 | break; |
| 390 | case Protocol.BackgroundService.ServiceName.BackgroundSync: |
| 391 | url += '#sync'; |
| 392 | break; |
| 393 | case Protocol.BackgroundService.ServiceName.PushMessaging: |
| 394 | url += '#push'; |
| 395 | break; |
| 396 | case Protocol.BackgroundService.ServiceName.Notifications: |
| 397 | url += '#notifications'; |
| 398 | break; |
| 399 | default: |
| 400 | break; |
| 401 | } |
| 402 | |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 403 | return UI.XLink.XLink.create(url, i18nString(UIStrings.learnMore)); |
Rayan Kanso | 42c0f9e | 2019-09-02 12:21:09 | [diff] [blame] | 404 | } |
| 405 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 406 | _showPreview(dataNode: EventDataNode|null): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 407 | if (this._selectedEventNode && this._selectedEventNode === dataNode) { |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 408 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 409 | } |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 410 | |
| 411 | this._selectedEventNode = dataNode; |
| 412 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 413 | if (this._preview) { |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 414 | this._preview.detach(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 415 | } |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 416 | |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 417 | if (this._selectedEventNode) { |
| 418 | this._preview = this._selectedEventNode.createPreview(); |
Rayan Kanso | 4476ca5 | 2019-07-22 11:51:24 | [diff] [blame] | 419 | this._preview.show(this._previewPanel.contentElement); |
| 420 | return; |
| 421 | } |
| 422 | |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 423 | this._preview = new UI.Widget.VBox(); |
Rayan Kanso | 4476ca5 | 2019-07-22 11:51:24 | [diff] [blame] | 424 | this._preview.contentElement.classList.add('background-service-preview', 'fill'); |
| 425 | const centered = this._preview.contentElement.createChild('div'); |
| 426 | |
| 427 | if (this._dataGrid.rootNode().children.length) { |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 428 | // Inform users that grid entries are clickable. |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 429 | centered.createChild('p').textContent = i18nString(UIStrings.selectAnEntryToViewMetadata); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 430 | } else if (this._recordButton.toggled()) { |
| 431 | // Inform users that we are recording/waiting for events. |
Tim van der Lippe | 097cdec | 2020-01-06 14:44:17 | [diff] [blame] | 432 | const featureName = BackgroundServiceView.getUIString(this._serviceName); |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 433 | centered.createChild('p').textContent = i18nString(UIStrings.recordingSActivity, {PH1: featureName}); |
| 434 | centered.createChild('p').textContent = i18nString(UIStrings.devtoolsWillRecordAllSActivity, {PH1: featureName}); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 435 | } else { |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 436 | const landingRecordButton = UI.Toolbar.Toolbar.createActionButton(this._recordAction); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 437 | |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 438 | const recordKey = document.createElement('b'); |
| 439 | recordKey.classList.add('background-service-shortcut'); |
Tim van der Lippe | 9c9fb12 | 2020-09-08 15:06:17 | [diff] [blame] | 440 | recordKey.textContent = UI.ShortcutRegistry.ShortcutRegistry.instance() |
| 441 | .shortcutsForAction('background-service.toggle-recording')[0] |
| 442 | .title(); |
Rayan Kanso | 6156d22 | 2019-04-29 23:40:55 | [diff] [blame] | 443 | |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 444 | const inlineButton = UI.UIUtils.createInlineButton(landingRecordButton); |
Rayan Kanso | f402ef3 | 2019-08-12 13:05:18 | [diff] [blame] | 445 | inlineButton.classList.add('background-service-record-inline-button'); |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 446 | centered.createChild('p').appendChild(i18n.i18n.getFormatLocalizedString( |
| 447 | str_, UIStrings.clickTheRecordButtonSOrHitSTo, {PH1: inlineButton, PH2: recordKey})); |
Rayan Kanso | 42c0f9e | 2019-09-02 12:21:09 | [diff] [blame] | 448 | |
| 449 | centered.appendChild(this._createLearnMoreLink()); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 450 | } |
Rayan Kanso | b451b4f | 2019-04-04 23:12:11 | [diff] [blame] | 451 | |
| 452 | this._preview.show(this._previewPanel.contentElement); |
| 453 | } |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 454 | |
| 455 | /** |
| 456 | * Saves all currently displayed events in a file (JSON format). |
| 457 | */ |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 458 | async _saveToFile(): Promise<void> { |
Simon Zünd | 2c704cd | 2020-06-04 09:08:35 | [diff] [blame] | 459 | const fileName = `${this._serviceName}-${Platform.DateUtilities.toISO8601Compact(new Date())}.json`; |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 460 | const stream = new Bindings.FileUtils.FileOutputStream(); |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 461 | |
| 462 | const accepted = await stream.open(fileName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 463 | if (!accepted) { |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 464 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 465 | } |
Rayan Kanso | b852ba8 | 2019-04-08 13:48:07 | [diff] [blame] | 466 | |
| 467 | const events = this._model.getEvents(this._serviceName).filter(event => this._acceptEvent(event)); |
| 468 | await stream.write(JSON.stringify(events, undefined, 2)); |
| 469 | stream.close(); |
| 470 | } |
Tim van der Lippe | 097cdec | 2020-01-06 14:44:17 | [diff] [blame] | 471 | } |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 472 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 473 | export class EventDataNode extends DataGrid.DataGrid.DataGridNode<EventData> { |
| 474 | _eventMetadata: Protocol.BackgroundService.EventMetadata[]; |
| 475 | |
| 476 | constructor(data: EventData, eventMetadata: Protocol.BackgroundService.EventMetadata[]) { |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 477 | super(data); |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 478 | |
Jack Franklin | 056c400 | 2021-01-13 13:53:20 | [diff] [blame] | 479 | this._eventMetadata = eventMetadata.sort((m1, m2) => Platform.StringUtilities.compare(m1.key, m2.key)); |
Rayan Kanso | 3252d5e | 2019-03-27 11:37:24 | [diff] [blame] | 480 | } |
| 481 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 482 | createPreview(): UI.Widget.VBox { |
Tim van der Lippe | 0efccf0 | 2020-02-12 15:15:39 | [diff] [blame] | 483 | const preview = new UI.Widget.VBox(); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 484 | preview.element.classList.add('background-service-metadata'); |
| 485 | |
| 486 | for (const entry of this._eventMetadata) { |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 487 | const div = document.createElement('div'); |
| 488 | div.classList.add('background-service-metadata-entry'); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 489 | div.createChild('div', 'background-service-metadata-name').textContent = entry.key + ': '; |
Rayan Kanso | 4476ca5 | 2019-07-22 11:51:24 | [diff] [blame] | 490 | if (entry.value) { |
| 491 | div.createChild('div', 'background-service-metadata-value source-code').textContent = entry.value; |
| 492 | } else { |
| 493 | div.createChild('div', 'background-service-metadata-value background-service-empty-value').textContent = |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 494 | i18nString(UIStrings.empty); |
Rayan Kanso | 4476ca5 | 2019-07-22 11:51:24 | [diff] [blame] | 495 | } |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 496 | preview.element.appendChild(div); |
| 497 | } |
| 498 | |
| 499 | if (!preview.element.children.length) { |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 500 | const div = document.createElement('div'); |
| 501 | div.classList.add('background-service-metadata-entry'); |
Sigurd Schneider | fec75bb | 2021-03-19 10:23:34 | [diff] [blame] | 502 | div.createChild('div', 'background-service-metadata-name background-service-empty-value').textContent = |
Vidal Guillermo Diazleal Ortega | 0a997bb | 2021-02-09 04:33:01 | [diff] [blame] | 503 | i18nString(UIStrings.noMetadataForThisEvent); |
Rayan Kanso | c0bfdd8 | 2019-04-24 12:32:22 | [diff] [blame] | 504 | preview.element.appendChild(div); |
| 505 | } |
| 506 | |
| 507 | return preview; |
Rayan Kanso | f40e315 | 2019-03-11 13:49:43 | [diff] [blame] | 508 | } |
Tim van der Lippe | 097cdec | 2020-01-06 14:44:17 | [diff] [blame] | 509 | } |
Rayan Kanso | 6156d22 | 2019-04-29 23:40:55 | [diff] [blame] | 510 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 511 | let actionDelegateInstance: ActionDelegate; |
Andres Olivares | 7957851 | 2021-02-02 00:27:49 | [diff] [blame] | 512 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 513 | export class ActionDelegate implements UI.ActionRegistration.ActionDelegate { |
| 514 | static instance(opts: { |
| 515 | forceNew: boolean|null, |
| 516 | } = {forceNew: null}): ActionDelegate { |
Andres Olivares | 7957851 | 2021-02-02 00:27:49 | [diff] [blame] | 517 | const {forceNew} = opts; |
| 518 | if (!actionDelegateInstance || forceNew) { |
| 519 | actionDelegateInstance = new ActionDelegate(); |
| 520 | } |
| 521 | |
| 522 | return actionDelegateInstance; |
| 523 | } |
| 524 | |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 525 | handleAction(context: UI.Context.Context, actionId: string): boolean { |
Tim van der Lippe | 097cdec | 2020-01-06 14:44:17 | [diff] [blame] | 526 | const view = context.flavor(BackgroundServiceView); |
Rayan Kanso | 6156d22 | 2019-04-29 23:40:55 | [diff] [blame] | 527 | switch (actionId) { |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 528 | case 'background-service.toggle-recording': { |
| 529 | if (!view) { |
| 530 | throw new Error('BackgroundServiceView instance is missing'); |
| 531 | } |
Rayan Kanso | 6156d22 | 2019-04-29 23:40:55 | [diff] [blame] | 532 | view._toggleRecording(); |
| 533 | return true; |
Alex Rudenko | 60a3e94 | 2020-11-02 12:27:57 | [diff] [blame] | 534 | } |
Rayan Kanso | 6156d22 | 2019-04-29 23:40:55 | [diff] [blame] | 535 | } |
| 536 | return false; |
| 537 | } |
Tim van der Lippe | 097cdec | 2020-01-06 14:44:17 | [diff] [blame] | 538 | } |
Jan Scheffler | 1026b9d | 2021-02-26 17:12:00 | [diff] [blame] | 539 | export interface RecordingState { |
| 540 | isRecording: boolean; |
| 541 | serviceName: Protocol.BackgroundService.ServiceName; |
| 542 | } |
| 543 | export interface EventData { |
| 544 | id: number; |
| 545 | timestamp: string; |
| 546 | origin: string; |
| 547 | swScope: string; |
| 548 | eventName: string; |
| 549 | instanceId: string; |
| 550 | } |