blob: 65b3ad137793b32a4363f74e28f50f8e5e010feb [file] [log] [blame]
Rayan Kanso68904202019-02-21 14:16:251// 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
5Resources.BackgroundServiceView = class extends UI.VBox {
6 /**
Rayan Kanso8fe8ee22019-03-04 14:58:467 * @param {!Protocol.BackgroundService.ServiceName} serviceName
8 * @param {!Resources.BackgroundServiceModel} model
Rayan Kanso68904202019-02-21 14:16:259 */
Rayan Kanso8fe8ee22019-03-04 14:58:4610 constructor(serviceName, model) {
Rayan Kanso68904202019-02-21 14:16:2511 super(true);
12 this.registerRequiredCSS('resources/backgroundServiceView.css');
13
Rayan Kanso8fe8ee22019-03-04 14:58:4614 /** @const {!Protocol.BackgroundService.ServiceName} */
Rayan Kanso68904202019-02-21 14:16:2515 this._serviceName = serviceName;
16
Rayan Kanso8fe8ee22019-03-04 14:58:4617 /** @const {!Resources.BackgroundServiceModel} */
18 this._model = model;
19 this._model.addEventListener(
20 Resources.BackgroundServiceModel.Events.RecordingStateChanged, this._onRecordingStateChanged, this);
Rayan Kansof40e3152019-03-11 13:49:4321 this._model.addEventListener(
22 Resources.BackgroundServiceModel.Events.BackgroundServiceEventReceived, this._onEventReceived, this);
Rayan Kanso8fe8ee22019-03-04 14:58:4623 this._model.enable(this._serviceName);
24
25 /** @type {?UI.ToolbarToggle} */
26 this._recordButton = null;
27
Rayan Kanso68904202019-02-21 14:16:2528 /** @const {!UI.Toolbar} */
29 this._toolbar = new UI.Toolbar('background-service-toolbar', this.contentElement);
30 this._setupToolbar();
31 }
32
33 /**
34 * Creates the toolbar UI element.
35 */
Rayan Kanso8fe8ee22019-03-04 14:58:4636 async _setupToolbar() {
37 this._recordButton =
Rayan Kanso68904202019-02-21 14:16:2538 new UI.ToolbarToggle(Common.UIString('Toggle Record'), 'largeicon-start-recording', 'largeicon-stop-recording');
Rayan Kanso8fe8ee22019-03-04 14:58:4639 this._recordButton.addEventListener(UI.ToolbarButton.Events.Click, () => this._toggleRecording());
40 this._recordButton.setToggleWithRedColor(true);
41 this._toolbar.appendToolbarItem(this._recordButton);
Rayan Kanso68904202019-02-21 14:16:2542
43 const refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'largeicon-refresh');
44 refreshButton.addEventListener(UI.ToolbarButton.Events.Click, () => {});
45 this._toolbar.appendToolbarItem(refreshButton);
46
47 const clearButton = new UI.ToolbarButton(Common.UIString('Clear'), 'largeicon-clear');
48 clearButton.addEventListener(UI.ToolbarButton.Events.Click, () => {});
49 this._toolbar.appendToolbarItem(clearButton);
50
51 this._toolbar.appendSeparator();
52
53 const deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largeicon-trash-bin');
Rayan Kansof40e3152019-03-11 13:49:4354 deleteButton.addEventListener(UI.ToolbarButton.Events.Click, () => this._model.clearEvents(this._serviceName));
Rayan Kanso68904202019-02-21 14:16:2555 this._toolbar.appendToolbarItem(deleteButton);
56 }
Rayan Kanso8fe8ee22019-03-04 14:58:4657
58 /**
59 * Called when the `Toggle Record` button is clicked.
60 */
61 _toggleRecording() {
62 this._model.setRecording(!this._recordButton.toggled(), this._serviceName);
63 }
64
65 /**
66 * @param {!Common.Event} event
67 */
68 _onRecordingStateChanged(event) {
69 const state = /** @type {!Resources.BackgroundServiceModel.RecordingState} */ (event.data);
70 if (state.serviceName !== this._serviceName)
71 return;
72 this._recordButton.setToggled(state.isRecording);
73 }
Rayan Kansof40e3152019-03-11 13:49:4374
75 /**
76 * @param {!Common.Event} event
77 */
78 _onEventReceived(event) {
79 const serviceEvent = /** @type {!Protocol.BackgroundService.BackgroundServiceEvent} */ (event.data);
80 if (serviceEvent.service !== this._serviceName)
81 return;
82 }
Rayan Kanso68904202019-02-21 14:16:2583};