aboutsummaryrefslogtreecommitdiff
path: root/src/content/Application.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/Application.ts')
-rw-r--r--src/content/Application.ts53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/content/Application.ts b/src/content/Application.ts
index b09edfa..6b881fe 100644
--- a/src/content/Application.ts
+++ b/src/content/Application.ts
@@ -1,6 +1,5 @@
import { injectable } from "tsyringe";
import MessageListener from "./MessageListener";
-import FindController from "./controllers/FindController";
import MarkController from "./controllers/MarkController";
import FollowMasterController from "./controllers/FollowMasterController";
import FollowSlaveController from "./controllers/FollowSlaveController";
@@ -14,6 +13,7 @@ import SettingController from "./controllers/SettingController";
import ConsoleFrameController from "./controllers/ConsoleFrameController";
import NavigateController from "./controllers/NavigateController";
import * as messages from "../shared/messages";
+import FindController from "./controllers/FindController";
type Message = messages.Message;
@@ -22,7 +22,6 @@ export default class Application {
// eslint-disable-next-line max-params
constructor(
private messageListener: MessageListener,
- private findController: FindController,
private markController: MarkController,
private followMasterController: FollowMasterController,
private followSlaveController: FollowSlaveController,
@@ -33,7 +32,8 @@ export default class Application {
private addonEnabledController: AddonEnabledController,
private settingController: SettingController,
private consoleFrameController: ConsoleFrameController,
- private navigateController: NavigateController
+ private navigateController: NavigateController,
+ private findController: FindController
) {}
init(): Promise<void> {
@@ -41,18 +41,26 @@ export default class Application {
if (window.self === window.top) {
this.routeMasterComponents();
}
- return this.routeCommonComponents();
+ this.routeCommonComponents();
+ // Make sure the background script sends a message to the content script by
+ // establishing a connection. If the background script tries to send a
+ // message to a frame on which cannot run the content script, it fails with
+ // a message "Could not establish connection."
+ //
+ // The port is never used, and the messages are delivered via
+ // `browser.tabs.sendMessage` API because sending a message via port cannot
+ // receive returned value.
+ //
+ // /* on background script */
+ // port.sendMessage({ type: "do something" }); <- returns void
+ //
+ browser.runtime.connect(undefined, { name: "vimvixen-find" });
+ return Promise.resolve();
}
private routeMasterComponents() {
this.messageListener.onWebMessage((msg: Message, sender: Window) => {
switch (msg.type) {
- case messages.CONSOLE_ENTER_FIND:
- return this.findController.start(msg);
- case messages.FIND_NEXT:
- return this.findController.next(msg);
- case messages.FIND_PREV:
- return this.findController.prev(msg);
case messages.CONSOLE_UNFOCUS:
return this.consoleFrameController.unfocus(msg);
case messages.FOLLOW_START:
@@ -64,16 +72,6 @@ export default class Application {
}
return undefined;
});
-
- this.messageListener.onBackgroundMessage((msg: Message) => {
- switch (msg.type) {
- case messages.ADDON_ENABLED_QUERY:
- return this.addonEnabledController.getAddonEnabled(msg);
- case messages.TAB_SCROLL_TO:
- return this.markController.scrollTo(msg);
- }
- return undefined;
- });
}
private routeCommonComponents(): Promise<void> {
@@ -109,6 +107,21 @@ export default class Application {
return this.navigateController.openLinkPrev(msg);
case messages.CONSOLE_RESIZE:
return this.consoleFrameController.resize(msg);
+ case messages.FIND_NEXT:
+ return this.findController.findNext(msg.keyword);
+ case messages.FIND_PREV:
+ return this.findController.findPrev(msg.keyword);
+ case messages.FIND_CLEAR_SELECTION:
+ return this.findController.clearSelection();
+ }
+
+ if (window.self === window.top) {
+ switch (msg.type) {
+ case messages.ADDON_ENABLED_QUERY:
+ return this.addonEnabledController.getAddonEnabled(msg);
+ case messages.TAB_SCROLL_TO:
+ return this.markController.scrollTo(msg);
+ }
}
});