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