From 3ffb4b066cdcc60a49ce4ecd0bbc498da6256534 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 17 Mar 2021 23:20:41 +0900 Subject: Attach/detach console iframe on addon enabled/disabled --- src/content/usecases/AddonEnabledUseCase.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/content/usecases') diff --git a/src/content/usecases/AddonEnabledUseCase.ts b/src/content/usecases/AddonEnabledUseCase.ts index f7e78c5..b45c47f 100644 --- a/src/content/usecases/AddonEnabledUseCase.ts +++ b/src/content/usecases/AddonEnabledUseCase.ts @@ -1,15 +1,17 @@ import { injectable, inject } from "tsyringe"; import AddonIndicatorClient from "../client/AddonIndicatorClient"; import AddonEnabledRepository from "../repositories/AddonEnabledRepository"; +import ConsoleFramePresenter from "../presenters/ConsoleFramePresenter"; @injectable() export default class AddonEnabledUseCase { constructor( @inject("AddonIndicatorClient") - private indicator: AddonIndicatorClient, - + private readonly indicator: AddonIndicatorClient, @inject("AddonEnabledRepository") - private repository: AddonEnabledRepository + private readonly repository: AddonEnabledRepository, + @inject("ConsoleFramePresenter") + private readonly consoleFramePresenter: ConsoleFramePresenter ) {} async enable(): Promise { @@ -31,6 +33,12 @@ export default class AddonEnabledUseCase { private async setEnabled(on: boolean): Promise { this.repository.set(on); + + if (on) { + this.consoleFramePresenter.attach(); + } else { + this.consoleFramePresenter.detach(); + } await this.indicator.setEnabled(on); } } -- cgit v1.2.3 From 8828d175d9754e7afedf1dbb0b7bda2824608b0a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 20 Mar 2021 11:51:08 +0900 Subject: Inject iframe on top window --- src/content/presenters/ConsoleFramePresenter.ts | 6 ++++++ src/content/usecases/AddonEnabledUseCase.ts | 10 ++++++---- test/content/operators/impls/MockConsoleFramePresenter.ts | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src/content/usecases') diff --git a/src/content/presenters/ConsoleFramePresenter.ts b/src/content/presenters/ConsoleFramePresenter.ts index 9c4b3f1..0db58f0 100644 --- a/src/content/presenters/ConsoleFramePresenter.ts +++ b/src/content/presenters/ConsoleFramePresenter.ts @@ -6,6 +6,8 @@ export default interface ConsoleFramePresenter { blur(): void; resize(width: number, height: number): void; + + isTopWindow(): boolean; } export class ConsoleFramePresenterImpl implements ConsoleFramePresenter { @@ -47,4 +49,8 @@ export class ConsoleFramePresenterImpl implements ConsoleFramePresenter { } ele.style.height = `${height}px`; } + + isTopWindow(): boolean { + return window.top === window; + } } diff --git a/src/content/usecases/AddonEnabledUseCase.ts b/src/content/usecases/AddonEnabledUseCase.ts index b45c47f..f49fde5 100644 --- a/src/content/usecases/AddonEnabledUseCase.ts +++ b/src/content/usecases/AddonEnabledUseCase.ts @@ -34,10 +34,12 @@ export default class AddonEnabledUseCase { private async setEnabled(on: boolean): Promise { this.repository.set(on); - if (on) { - this.consoleFramePresenter.attach(); - } else { - this.consoleFramePresenter.detach(); + if (this.consoleFramePresenter.isTopWindow()) { + if (on) { + this.consoleFramePresenter.attach(); + } else { + this.consoleFramePresenter.detach(); + } } await this.indicator.setEnabled(on); } diff --git a/test/content/operators/impls/MockConsoleFramePresenter.ts b/test/content/operators/impls/MockConsoleFramePresenter.ts index f8ac70b..23bc27f 100644 --- a/test/content/operators/impls/MockConsoleFramePresenter.ts +++ b/test/content/operators/impls/MockConsoleFramePresenter.ts @@ -19,4 +19,8 @@ export default class MockConsoleFramePresenter resize(_width: number, _height: number): void { throw new Error("not implemented"); } + + isTopWindow(): boolean { + return true; + } } -- cgit v1.2.3