• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {assertDefined} from 'common/assert_utils';
18import {ScreenRecordingTraceEntry} from 'trace/screen_recording';
19import {Trace} from 'trace/trace';
20import {Traces} from 'trace/traces';
21import {TraceEntryFinder} from 'trace/trace_entry_finder';
22import {TracePosition} from 'trace/trace_position';
23import {TraceType} from 'trace/trace_type';
24import {View, Viewer, ViewType} from 'viewers/viewer';
25import {ViewerScreenRecordingComponent} from './viewer_screen_recording_component';
26
27class ViewerScreenRecording implements Viewer {
28  static readonly DEPENDENCIES: TraceType[] = [TraceType.SCREEN_RECORDING];
29  private readonly trace: Trace<ScreenRecordingTraceEntry>;
30  private readonly htmlElement: HTMLElement;
31
32  constructor(traces: Traces) {
33    this.trace = assertDefined(traces.getTrace(TraceType.SCREEN_RECORDING));
34    this.htmlElement = document.createElement('viewer-screen-recording');
35  }
36
37  async onTracePositionUpdate(position: TracePosition) {
38    const entry = TraceEntryFinder.findCorrespondingEntry(this.trace, position);
39    (this.htmlElement as unknown as ViewerScreenRecordingComponent).currentTraceEntry =
40      await entry?.getValue();
41  }
42
43  getViews(): View[] {
44    return [
45      new View(
46        ViewType.OVERLAY,
47        this.getDependencies(),
48        this.htmlElement,
49        'ScreenRecording',
50        TraceType.SCREEN_RECORDING
51      ),
52    ];
53  }
54
55  getDependencies(): TraceType[] {
56    return ViewerScreenRecording.DEPENDENCIES;
57  }
58}
59
60export {ViewerScreenRecording};
61