forked from microsoft/accessibility-insights-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup-initializer.ts
258 lines (230 loc) · 11 KB
/
popup-initializer.ts
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { loadTheme } from '@fluentui/react';
import { Assessments } from 'assessments/assessments';
import { assessmentsProviderForRequirements } from 'assessments/assessments-requirements-filter';
import { QuickAssessRequirementMap } from 'assessments/quick-assess-requirements';
import { BrowserAdapter } from 'common/browser-adapters/browser-adapter';
import { WebVisualizationConfigurationFactory } from 'common/configs/web-visualization-configuration-factory';
import { DocumentManipulator } from 'common/document-manipulator';
import { StoreUpdateMessageHub } from 'common/store-update-message-hub';
import { ExceptionTelemetryListener } from 'common/telemetry/exception-telemetry-listener';
import { ExceptionTelemetrySanitizer } from 'common/telemetry/exception-telemetry-sanitizer';
import { createRoot } from 'react-dom/client';
import { AxeInfo } from '../common/axe-info';
import { NewTabLink } from '../common/components/new-tab-link';
import { DropdownClickHandler } from '../common/dropdown-click-handler';
import { EnumHelper } from '../common/enum-helper';
import { TelemetryEventSource } from '../common/extension-telemetry-events';
import { HTMLElementUtils } from '../common/html-element-utils';
import { IsSupportedBrowser } from '../common/is-supported-browser';
import { Logger } from '../common/logging/logger';
import { ContentActionMessageCreator } from '../common/message-creators/content-action-message-creator';
import { DropdownActionMessageCreator } from '../common/message-creators/dropdown-action-message-creator';
import { RemoteActionMessageDispatcher } from '../common/message-creators/remote-action-message-dispatcher';
import { UserConfigMessageCreator } from '../common/message-creators/user-config-message-creator';
import { VisualizationActionMessageCreator } from '../common/message-creators/visualization-action-message-creator';
import { SelfFastPass, SelfFastPassContainer } from '../common/self-fast-pass';
import { StoreProxy } from '../common/store-proxy';
import { ClientStoresHub } from '../common/stores/client-stores-hub';
import { StoreNames } from '../common/stores/store-names';
import { TelemetryDataFactory } from '../common/telemetry-data-factory';
import { CommandStoreData } from '../common/types/store-data/command-store-data';
import { FeatureFlagStoreData } from '../common/types/store-data/feature-flag-store-data';
import { LaunchPanelStoreData } from '../common/types/store-data/launch-panel-store-data';
import { UserConfigurationStoreData } from '../common/types/store-data/user-configuration-store';
import { VisualizationStoreData } from '../common/types/store-data/visualization-store-data';
import { VisualizationType } from '../common/types/visualization-type';
import { WindowUtils } from '../common/window-utils';
import { contentPages } from '../content';
import { ScannerUtils } from '../injected/scanner-utils';
import { scan } from '../scanner/exposed-apis';
import { PopupActionMessageCreator } from './actions/popup-action-message-creator';
import { DiagnosticViewToggleDeps } from './components/diagnostic-view-toggle';
import { DiagnosticViewToggleFactory } from './components/diagnostic-view-toggle-factory';
import { PopupViewControllerState } from './components/popup-view';
import { DiagnosticViewClickHandler } from './handlers/diagnostic-view-toggle-click-handler';
import { LaunchPanelHeaderClickHandler } from './handlers/launch-panel-header-click-handler';
import { PopupHandlers } from './handlers/popup-handlers';
import { PopupViewControllerHandler } from './handlers/popup-view-controller-handler';
import { IncompatibleBrowserRenderer } from './incompatible-browser-renderer';
import { LaunchPadRowConfigurationFactory } from './launch-pad-row-configuration-factory';
import { MainRenderer, MainRendererDeps } from './main-renderer';
import { TargetTabFinder, TargetTabInfo } from './target-tab-finder';
declare let window: SelfFastPassContainer & Window;
export class PopupInitializer {
private targetTabInfo: TargetTabInfo;
constructor(
private readonly browserAdapter: BrowserAdapter,
private readonly targetTabFinder: TargetTabFinder,
private readonly isSupportedBrowser: IsSupportedBrowser,
private logger: Logger,
) {}
public initialize(): Promise<void> {
if (!this.isSupportedBrowser()) {
this.useIncompatibleBrowserRenderer();
return;
}
return this.targetTabFinder
.getTargetTab()
.then(tabInfo => {
this.targetTabInfo = tabInfo;
})
.then(this.initializePopup, err => {
this.logger.log('Error occurred at popup initialization:', err);
});
}
private useIncompatibleBrowserRenderer = () => {
const incompatibleBrowserRenderer = new IncompatibleBrowserRenderer(createRoot, document);
incompatibleBrowserRenderer.render();
};
private initializePopup = (): void => {
const telemetryFactory = new TelemetryDataFactory();
const tab = this.targetTabInfo.tab;
const actionMessageDispatcher = new RemoteActionMessageDispatcher(
this.browserAdapter.sendMessageToFrames,
tab.id,
this.logger,
);
const telemetrySanitizer = new ExceptionTelemetrySanitizer(
this.browserAdapter.getExtensionId(),
);
const exceptionTelemetryListener = new ExceptionTelemetryListener(
TelemetryEventSource.PopUp,
actionMessageDispatcher.sendTelemetry,
telemetrySanitizer,
);
exceptionTelemetryListener.initialize(this.logger);
const visualizationActionCreator = new VisualizationActionMessageCreator(
actionMessageDispatcher,
);
const windowUtils = new WindowUtils();
const popupActionMessageCreator = new PopupActionMessageCreator(
telemetryFactory,
actionMessageDispatcher,
windowUtils,
);
const userConfigMessageCreator = new UserConfigMessageCreator(
actionMessageDispatcher,
telemetryFactory,
);
const contentActionMessageCreator = new ContentActionMessageCreator(
telemetryFactory,
TelemetryEventSource.DetailsView,
actionMessageDispatcher,
);
const dropdownActionMessageCreator = new DropdownActionMessageCreator(
telemetryFactory,
actionMessageDispatcher,
);
const storeUpdateMessageHub = new StoreUpdateMessageHub(actionMessageDispatcher, tab.id);
this.browserAdapter.addListenerOnRuntimeMessage(storeUpdateMessageHub.handleBrowserMessage);
const visualizationStoreName = StoreNames[StoreNames.VisualizationStore];
const commandStoreName = StoreNames[StoreNames.CommandStore];
const featureFlagStoreName = StoreNames[StoreNames.FeatureFlagStore];
const launchPanelStateStoreName = StoreNames[StoreNames.LaunchPanelStateStore];
const userConfigurationStoreName = StoreNames[StoreNames.UserConfigurationStore];
const visualizationStore = new StoreProxy<VisualizationStoreData>(
visualizationStoreName,
storeUpdateMessageHub,
);
const launchPanelStateStore = new StoreProxy<LaunchPanelStoreData>(
launchPanelStateStoreName,
storeUpdateMessageHub,
);
const commandStore = new StoreProxy<CommandStoreData>(
commandStoreName,
storeUpdateMessageHub,
);
const featureFlagStore = new StoreProxy<FeatureFlagStoreData>(
featureFlagStoreName,
storeUpdateMessageHub,
);
const userConfigurationStore = new StoreProxy<UserConfigurationStoreData>(
userConfigurationStoreName,
storeUpdateMessageHub,
);
const visualizationConfigurationFactory = new WebVisualizationConfigurationFactory(
Assessments,
assessmentsProviderForRequirements(Assessments, QuickAssessRequirementMap),
);
const launchPadRowConfigurationFactory = new LaunchPadRowConfigurationFactory();
const diagnosticViewClickHandler: DiagnosticViewClickHandler =
new DiagnosticViewClickHandler(
telemetryFactory,
visualizationActionCreator,
visualizationConfigurationFactory,
);
const popupViewControllerHandler = new PopupViewControllerHandler();
const dropdownClickHandler = new DropdownClickHandler(
dropdownActionMessageCreator,
TelemetryEventSource.LaunchPad,
);
const launchPanelHeaderClickHandler = new LaunchPanelHeaderClickHandler();
const popupHandlers: PopupHandlers = {
diagnosticViewClickHandler,
popupViewControllerHandler,
launchPanelHeaderClickHandler,
};
const actionInitiators = {
...contentActionMessageCreator.initiators,
};
const visualizationTypes =
EnumHelper.getNumericValues<VisualizationType>(VisualizationType);
const storesHub = new ClientStoresHub<PopupViewControllerState>([
visualizationStore,
launchPanelStateStore,
commandStore,
featureFlagStore,
userConfigurationStore,
]);
const axeInfo = AxeInfo.Default;
const documentManipulator = new DocumentManipulator(document);
const deps: DiagnosticViewToggleDeps & MainRendererDeps = {
contentProvider: contentPages,
popupActionMessageCreator,
contentActionMessageCreator,
actionInitiators,
dropdownClickHandler,
userConfigMessageCreator,
storesHub,
loadTheme,
axeInfo,
launchPanelHeaderClickHandler,
browserAdapter: this.browserAdapter,
LinkComponent: NewTabLink,
documentManipulator,
};
const diagnosticViewToggleFactory = new DiagnosticViewToggleFactory(
deps,
document,
visualizationTypes,
visualizationConfigurationFactory,
visualizationStore,
featureFlagStore,
commandStore,
popupActionMessageCreator,
diagnosticViewClickHandler,
);
const renderer = new MainRenderer(
deps,
popupHandlers,
createRoot,
document,
window,
tab.url,
this.targetTabInfo.hasAccess,
launchPadRowConfigurationFactory,
diagnosticViewToggleFactory,
dropdownClickHandler,
);
renderer.render();
popupActionMessageCreator.popupInitialized(tab);
const selfFastPass = new SelfFastPass(
new ScannerUtils(scan, this.logger),
new HTMLElementUtils(),
this.logger,
);
window.selfFastPass = selfFastPass;
};
}