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
ash / webui / diagnostics_ui / resources / ip_config_info_drawer.ts [blame]
// 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 './data_point.js';
import './diagnostics_shared.css.js';
import 'chrome://resources/ash/common/cr_elements/cr_expand_button/cr_expand_button.js';
import {loadTimeData} from 'chrome://resources/ash/common/load_time_data.m.js';
import {I18nMixin} from 'chrome://resources/ash/common/cr_elements/i18n_mixin.js';
import {PolymerElementProperties} from 'chrome://resources/polymer/v3_0/polymer/interfaces.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {DiagnosticsBrowserProxyImpl} from './diagnostics_browser_proxy.js';
import {getSubnetMaskFromRoutingPrefix} from './diagnostics_utils.js';
import {getTemplate} from './ip_config_info_drawer.html.js';
import {Network} from './network_health_provider.mojom-webui.js';
/**
* @fileoverview
* 'ip-config-info-drawer' displays standard IP related configuration data in a
* collapsible drawer.
*/
const IpConfigInfoDrawerElementBase = I18nMixin(PolymerElement);
export class IpConfigInfoDrawerElement extends IpConfigInfoDrawerElementBase {
static get is(): string {
return 'ip-config-info-drawer';
}
static get template(): HTMLTemplateElement {
return getTemplate();
}
static get properties(): PolymerElementProperties {
return {
expanded: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
gateway: {
type: String,
computed: 'computeGateway(network.ipConfig.gateway)',
},
nameServers: {
type: String,
computed: 'computeNameServers(network.ipConfig.nameServers)',
},
network: {
type: Object,
},
subnetMask: {
type: String,
computed: 'computeSubnetMask(network.ipConfig.routingPrefix)',
},
nameServersHeader: {
type: String,
value: '',
},
};
}
network: Network;
protected expanded: boolean;
protected gateway: string;
protected nameServers: string;
protected subnetMask: string;
protected nameServersHeader: string;
private browserProxy: DiagnosticsBrowserProxyImpl =
DiagnosticsBrowserProxyImpl.getInstance();
static get observers(): string[] {
return ['getNameServersHeader(network.ipConfig.nameServers)'];
}
protected computeGateway(): string {
return this.network?.ipConfig?.gateway || '';
}
protected computeNameServers(): string {
if (!this.network?.ipConfig) {
return '';
}
// Handle name servers null or zero length state.
if (!this.network.ipConfig?.nameServers ||
this.network.ipConfig.nameServers?.length === 0) {
return loadTimeData.getStringF('networkDnsNotConfigured');
}
return this.network.ipConfig.nameServers.join(', ');
}
protected computeSubnetMask(): string {
// Routing prefix should be [1,32] when set. 0 indicates an unset value.
if (this.network?.ipConfig && this.network?.ipConfig?.routingPrefix &&
this.network?.ipConfig?.routingPrefix >= 0 &&
this.network?.ipConfig?.routingPrefix <= 32) {
return getSubnetMaskFromRoutingPrefix(
this.network?.ipConfig?.routingPrefix);
}
return '';
}
protected getNameServersHeader(nameServers?: string[]): void {
const count = nameServers ? nameServers.length : 0;
this.browserProxy.getPluralString('nameServersText', count)
.then((localizedString: string) => {
this.nameServersHeader = localizedString;
});
}
}
declare global {
interface HTMLElementTagNameMap {
'ip-config-info-drawer': IpConfigInfoDrawerElement;
}
}
customElements.define(IpConfigInfoDrawerElement.is, IpConfigInfoDrawerElement);