-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathinlineWorker.ts
110 lines (86 loc) · 3.97 KB
/
inlineWorker.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
import {ClientInfo} from "../../clientInfo";
import {ClientType} from "../../clientType";
import {Communicator} from "../../communicator/communicator";
import {IFrameMessageHandler} from "../../communicator/iframeMessageHandler";
import {InlineMessageHandler} from "../../communicator/inlineMessageHandler";
import {SmartValue} from "../../communicator/smartValue";
import * as Log from "../../logging/log";
import {Logger} from "../../logging/logger";
import {ClipperData} from "../../storage/clipperData";
import {LocalStorage} from "../../storage/localStorage";
import {ClipperUrls} from "../../clipperUrls";
import {Constants} from "../../constants";
import {AuthType} from "../../userInfo";
import {ChangeLog} from "../../versioning/changeLog";
import {AuthenticationHelper} from "../authenticationHelper";
import {ExtensionWorkerBase} from "../extensionWorkerBase";
import {InvokeMode} from "../invokeOptions";
import {InvokeSource} from "../invokeSource";
import {InlineExtension} from "./inlineExtension";
export class InlineWorker extends ExtensionWorkerBase<any, any> {
constructor(clientInfo: SmartValue<ClientInfo>, auth: AuthenticationHelper) {
let uiMessageHandlerThunk = () => { return new InlineMessageHandler(); };
let injectMessageHandlerThunk = () => { return new IFrameMessageHandler(() => parent); };
super(clientInfo, auth, new ClipperData(new LocalStorage()), uiMessageHandlerThunk, injectMessageHandlerThunk);
this.logger.setContextProperty(Log.Context.Custom.InPrivateBrowsing, Log.unknownValue);
let invokeOptions = {
invokeMode: InvokeMode.Default
};
this.sendInvokeOptionsToInject(invokeOptions);
// The inline worker gets created after the UI was successfully inject, so we can safely log this here
this.logger.logUserFunnel(Log.Funnel.Label.Invoke);
this.logClipperInvoke({
invokeSource: InvokeSource.Bookmarklet
}, invokeOptions);
}
public getUiMessageHandler(): InlineMessageHandler {
return this.uiCommunicator.getMessageHandler() as InlineMessageHandler;
}
public getUrl(): string {
return "inline - unknown";
}
protected invokeClipperBrowserSpecific(): Promise<boolean> {
return this.throwNotImplementedFailure();
}
protected invokeDebugLoggingBrowserSpecific(): Promise<boolean> {
return this.throwNotImplementedFailure();
}
protected invokeWhatsNewTooltipBrowserSpecific(newVersions: ChangeLog.Update[]): Promise<boolean> {
return this.throwNotImplementedFailure();
}
protected invokeTooltipBrowserSpecific(): Promise<boolean> {
return this.throwNotImplementedFailure();
}
protected isAllowedFileSchemeAccessBrowserSpecific(callback: (isAllowed: boolean) => void): void {
callback(false);
}
protected takeTabScreenshot(): Promise<string> {
return this.throwNotImplementedFailure();
}
/**
* Launches the sign in window, rejecting with an error object if something went wrong on the server during
* authentication. Otherwise, it resolves with true if the redirect endpoint was hit as a result of a successful
* sign in attempt, and false if it was not hit (e.g., user manually closed the popup)
*/
protected doSignInAction(authType: AuthType): Promise<boolean> {
let usidQueryParamValue = this.getUserSessionIdQueryParamValue();
let signInUrl = ClipperUrls.generateSignInUrl(this.clientInfo.get().clipperId, usidQueryParamValue, AuthType[authType]);
return this.launchPopupAndWaitForClose(signInUrl);
}
/**
* Signs the user out
*/
protected doSignOutAction(authType: AuthType) {
let usidQueryParamValue = this.getUserSessionIdQueryParamValue();
let signOutUrl = ClipperUrls.generateSignOutUrl(this.clientInfo.get().clipperId, usidQueryParamValue, AuthType[authType]);
let iframe = document.createElement("iframe");
iframe.hidden = true;
iframe.style.display = "none";
iframe.src = signOutUrl;
document.body.appendChild(iframe);
}
private throwNotImplementedFailure(): any {
this.logger.logFailure(Log.Failure.Label.NotImplemented, Log.Failure.Type.Unexpected);
throw new Error("not implemented");
}
}