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
ash / webui / help_app_ui / resources / receiver.ts [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* A script for the app inside the iframe. Implements a delegate.
*/
import './sandboxed_load_time_data.js';
import {COLOR_PROVIDER_CHANGED, ColorChangeUpdater} from '//resources/cr_components/color_change_listener/colors_css_updater.js';
import {MessagePipe} from '//system_apps/message_pipe.js';
import {Message} from './message_types.js';
/** A pipe through which we can send messages to the parent frame. */
const parentMessagePipe = new MessagePipe('chrome://help-app', window.parent);
/**
* A delegate which exposes privileged WebUI functionality to the help
* app.
*/
const DELEGATE: ClientApiDelegate = {
async openFeedbackDialog() {
const response =
await parentMessagePipe.sendMessage(Message.OPEN_FEEDBACK_DIALOG);
return response['errorMessage'] as string;
},
showOnDeviceAppControls() {
return parentMessagePipe.sendMessage(Message.SHOW_ON_DEVICE_APP_CONTROLS);
},
showParentalControls() {
return parentMessagePipe.sendMessage(Message.SHOW_PARENTAL_CONTROLS);
},
triggerWelcomeTipCallToAction(actionTypeId: number) {
return parentMessagePipe.sendMessage(
Message.TRIGGER_WELCOME_TIP_CALL_TO_ACTION, actionTypeId);
},
addOrUpdateSearchIndex(data: SearchableItem[]) {
return parentMessagePipe.sendMessage(
Message.ADD_OR_UPDATE_SEARCH_INDEX, data);
},
clearSearchIndex() {
return parentMessagePipe.sendMessage(Message.CLEAR_SEARCH_INDEX);
},
findInSearchIndex(query: string, maxResults = 50): Promise<FindResponse> {
return parentMessagePipe.sendMessage(
Message.FIND_IN_SEARCH_INDEX, {query, maxResults});
},
closeBackgroundPage() {
parentMessagePipe.sendMessage(Message.CLOSE_BACKGROUND_PAGE);
},
updateLauncherSearchIndex(data: LauncherSearchableItem[]) {
return parentMessagePipe.sendMessage(
Message.UPDATE_LAUNCHER_SEARCH_INDEX, data);
},
launchMicrosoft365Setup() {
return parentMessagePipe.sendMessage(Message.LAUNCH_MICROSOFT_365_SETUP);
},
maybeShowReleaseNotesNotification() {
return parentMessagePipe.sendMessage(
Message.MAYBE_SHOW_RELEASE_NOTES_NOTIFICATION);
},
getDeviceInfo(): Promise<DeviceInfo> {
return parentMessagePipe.sendMessage(Message.GET_DEVICE_INFO);
},
openSettings(path: number) {
parentMessagePipe.sendMessage(Message.OPEN_SETTINGS, path);
},
openUrlInBrowserAndTriggerInstallDialog(url: string) {
return parentMessagePipe.sendMessage(
Message.OPEN_URL_IN_BROWSER_AND_TRIGGER_INSTALL_DIALOG, url);
},
setHasCompletedNewDeviceChecklist() {
parentMessagePipe.sendMessage(
Message.SET_HAS_COMPLETED_NEW_DEVICE_CHECKLIST);
},
setHasVisitedHowToPage() {
parentMessagePipe.sendMessage(Message.SET_HAS_VISITED_HOW_TO_PAGE);
},
openAppMallPath(path: string) {
parentMessagePipe.sendMessage(Message.OPEN_APP_MALL_PATH, {path});
},
};
window.customLaunchData = {
delegate: DELEGATE,
};
window.addEventListener('DOMContentLoaded', function() {
// Start listening to color change events. These events get picked up by
// logic in ts_helpers.ts on the google3 side.
ColorChangeUpdater.forDocument().start();
});
declare global {
interface Window {
addColorChangeListener: (listener: EventListenerOrEventListenerObject|
null) => unknown;
removeColorChangeListener: (listener: EventListenerOrEventListenerObject|
null) => unknown;
}
}
// Expose functions to bind to color change events to window so they can be
// automatically picked up by installColors(). See ts_helpers.ts in google3.
window.addColorChangeListener = function(listener) {
ColorChangeUpdater.forDocument().eventTarget.addEventListener(
COLOR_PROVIDER_CHANGED, listener);
};
window.removeColorChangeListener = function(listener) {
ColorChangeUpdater.forDocument().eventTarget.removeEventListener(
COLOR_PROVIDER_CHANGED, listener);
};
export const TEST_ONLY = {parentMessagePipe};