aboutsummaryrefslogtreecommitdiff
path: root/src/content/client/FollowSlaveClient.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/client/FollowSlaveClient.ts')
-rw-r--r--src/content/client/FollowSlaveClient.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/content/client/FollowSlaveClient.ts b/src/content/client/FollowSlaveClient.ts
new file mode 100644
index 0000000..0905cd9
--- /dev/null
+++ b/src/content/client/FollowSlaveClient.ts
@@ -0,0 +1,76 @@
+import * as messages from '../../shared/messages';
+
+interface Size {
+ width: number;
+ height: number;
+}
+
+interface Point {
+ x: number;
+ y: number;
+}
+
+export default interface FollowSlaveClient {
+ filterHints(prefix: string): void;
+
+ requestHintCount(viewSize: Size, framePosition: Point): void;
+
+ createHints(viewSize: Size, framePosition: Point, tags: string[]): void;
+
+ clearHints(): void;
+
+ activateIfExists(tag: string, newTab: boolean, background: boolean): void;
+
+ // eslint-disable-next-line semi
+}
+
+export class FollowSlaveClientImpl implements FollowSlaveClient {
+ private target: Window;
+
+ constructor(target: Window) {
+ this.target = target;
+ }
+
+ filterHints(prefix: string): void {
+ this.postMessage({
+ type: messages.FOLLOW_SHOW_HINTS,
+ prefix,
+ });
+ }
+
+ requestHintCount(viewSize: Size, framePosition: Point): void {
+ this.postMessage({
+ type: messages.FOLLOW_REQUEST_COUNT_TARGETS,
+ viewSize,
+ framePosition,
+ });
+ }
+
+ createHints(viewSize: Size, framePosition: Point, tags: string[]): void {
+ this.postMessage({
+ type: messages.FOLLOW_CREATE_HINTS,
+ viewSize,
+ framePosition,
+ tags,
+ });
+ }
+
+ clearHints(): void {
+ this.postMessage({
+ type: messages.FOLLOW_REMOVE_HINTS,
+ });
+ }
+
+ activateIfExists(tag: string, newTab: boolean, background: boolean): void {
+ this.postMessage({
+ type: messages.FOLLOW_ACTIVATE,
+ tag,
+ newTab,
+ background,
+ });
+ }
+
+ private postMessage(msg: messages.Message): void {
+ this.target.postMessage(JSON.stringify(msg), '*');
+ }
+}