1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {getTemplate} from './app_service_internals.html.js';
import type {AppCapabilityInfo, AppInfo, PreferredAppInfo, PromiseAppInfo} from './app_service_internals.mojom-webui.js';
import {AppServiceInternalsPageHandler} from './app_service_internals.mojom-webui.js';
export class AppServiceInternalsElement extends PolymerElement {
static get is() {
return 'app-service-internals';
}
static get template() {
return getTemplate();
}
static get properties() {
return {
appList_: {
type: Array,
value: () => [],
},
preferredAppList_: {
type: Array,
value: () => [],
},
promiseAppList_: {
type: Array,
value: () => [],
},
appCapabilityList_: {
type: Array,
value: () => [],
},
};
}
/** List containing debug information for all installed apps. */
declare private appList_: AppInfo[];
private hashChangeListener_ = () => this.onHashChanged_();
/** List containing preferred app debug information for installed apps. */
declare private preferredAppList_: PreferredAppInfo[];
/** List containing debug information for all promise apps. */
declare private promiseAppList_: PromiseAppInfo[];
/** List containing app capability access information. */
declare private appCapabilityList_: AppCapabilityInfo[];
override ready() {
super.ready();
(async () => {
const remote = AppServiceInternalsPageHandler.getRemote();
const {debugInfo} = await remote.getDebugInfo();
if (debugInfo) {
this.appList_ = debugInfo.appList;
this.preferredAppList_ = debugInfo.preferredAppList;
this.promiseAppList_ = debugInfo.promiseAppList;
this.appCapabilityList_ = debugInfo.appCapabilityList;
}
window.addEventListener('hashchange', this.hashChangeListener_);
// setTimeout ensures that we only apply the hash change after all the
// page content has rendered.
setTimeout(() => this.onHashChanged_(), 0);
})();
}
override disconnectedCallback() {
window.removeEventListener('hashchange', this.hashChangeListener_);
}
/**
* Manually responds to URL hash changes, since the regular browser handling
* doesn't work in the Shadow DOM.
*/
private onHashChanged_() {
if (!location.hash || !this.shadowRoot) {
window.scrollTo(0, 0);
return;
}
const selected = this.shadowRoot.querySelector(location.hash);
if (!selected) {
return;
}
selected.scrollIntoView();
}
private save_() {
const fileParts: string[] = [];
fileParts.push('App List\n');
fileParts.push('========\n\n');
for (const app of this.appList_) {
fileParts.push(app.name + '\n');
fileParts.push('-----\n');
fileParts.push(app.debugInfo + '\n');
}
fileParts.push('Preferred Apps\n');
fileParts.push('==============\n\n');
for (const preferredApp of this.preferredAppList_) {
fileParts.push(preferredApp.name + ' (' + preferredApp.id + ')\n');
fileParts.push('-----\n');
fileParts.push(preferredApp.preferredFilters + '\n');
}
fileParts.push('App Capabilities\n');
fileParts.push('================\n\n');
for (const appCapability of this.appCapabilityList_) {
fileParts.push(appCapability.name + '\n');
fileParts.push('-----\n');
fileParts.push(appCapability.debugInfo + '\n');
}
fileParts.push('Promise App List\n');
fileParts.push('================\n\n');
for (const promiseApp of this.promiseAppList_) {
fileParts.push(promiseApp.packageId + '\n');
fileParts.push('-----\n');
fileParts.push(promiseApp.debugInfo + '\n');
}
const file = new Blob(fileParts);
const a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = 'app-service-internals.txt';
a.click();
URL.revokeObjectURL(a.href);
}
}
customElements.define(
AppServiceInternalsElement.is, AppServiceInternalsElement);
|