show popup inside iframe for closed shadow dom
This commit is contained in:
parent
fbaf50def1
commit
85706c421b
@ -24,7 +24,7 @@
|
|||||||
* apiOptionsGet
|
* apiOptionsGet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function createIframePopupProxy(url, frameOffsetForwarder) {
|
async function createIframePopupProxy(url, frameOffsetForwarder, setDisabled) {
|
||||||
const rootPopupInformationPromise = yomichan.getTemporaryListenerResult(
|
const rootPopupInformationPromise = yomichan.getTemporaryListenerResult(
|
||||||
chrome.runtime.onMessage,
|
chrome.runtime.onMessage,
|
||||||
({action, params}, {resolve}) => {
|
({action, params}, {resolve}) => {
|
||||||
@ -38,7 +38,7 @@ async function createIframePopupProxy(url, frameOffsetForwarder) {
|
|||||||
|
|
||||||
const getFrameOffset = frameOffsetForwarder.getOffset.bind(frameOffsetForwarder);
|
const getFrameOffset = frameOffsetForwarder.getOffset.bind(frameOffsetForwarder);
|
||||||
|
|
||||||
const popup = new PopupProxy(popupId, 0, null, frameId, url, getFrameOffset);
|
const popup = new PopupProxy(popupId, 0, null, frameId, url, getFrameOffset, setDisabled);
|
||||||
await popup.prepare();
|
await popup.prepare();
|
||||||
|
|
||||||
return popup;
|
return popup;
|
||||||
@ -78,6 +78,13 @@ async function main() {
|
|||||||
let frontendPreparePromise = null;
|
let frontendPreparePromise = null;
|
||||||
let frameOffsetForwarder = null;
|
let frameOffsetForwarder = null;
|
||||||
|
|
||||||
|
let iframePopupsInRootFrameAvailable = true;
|
||||||
|
|
||||||
|
const disableIframePopupsInRootFrame = () => {
|
||||||
|
iframePopupsInRootFrameAvailable = false;
|
||||||
|
applyOptions();
|
||||||
|
};
|
||||||
|
|
||||||
const applyOptions = async () => {
|
const applyOptions = async () => {
|
||||||
const optionsContext = {depth: isSearchPage ? 0 : depth, url};
|
const optionsContext = {depth: isSearchPage ? 0 : depth, url};
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
@ -88,8 +95,8 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let popup;
|
let popup;
|
||||||
if (isIframe && options.general.showIframePopupsInRootFrame && !document.fullscreen) {
|
if (isIframe && options.general.showIframePopupsInRootFrame && !document.fullscreen && iframePopupsInRootFrameAvailable) {
|
||||||
popup = popups.iframe || await createIframePopupProxy(url, frameOffsetForwarder);
|
popup = popups.iframe || await createIframePopupProxy(url, frameOffsetForwarder, disableIframePopupsInRootFrame);
|
||||||
popups.iframe = popup;
|
popups.iframe = popup;
|
||||||
} else if (proxy) {
|
} else if (proxy) {
|
||||||
popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId, url);
|
popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId, url);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class PopupProxy {
|
class PopupProxy {
|
||||||
constructor(id, depth, parentId, parentFrameId, url, getFrameOffset=null) {
|
constructor(id, depth, parentId, parentFrameId, url, getFrameOffset=null, setDisabled=null) {
|
||||||
this._parentId = parentId;
|
this._parentId = parentId;
|
||||||
this._parentFrameId = parentFrameId;
|
this._parentFrameId = parentFrameId;
|
||||||
this._id = id;
|
this._id = id;
|
||||||
@ -28,6 +28,7 @@ class PopupProxy {
|
|||||||
this._url = url;
|
this._url = url;
|
||||||
this._apiSender = new FrontendApiSender();
|
this._apiSender = new FrontendApiSender();
|
||||||
this._getFrameOffset = getFrameOffset;
|
this._getFrameOffset = getFrameOffset;
|
||||||
|
this._setDisabled = setDisabled;
|
||||||
|
|
||||||
this._frameOffset = null;
|
this._frameOffset = null;
|
||||||
this._frameOffsetPromise = null;
|
this._frameOffsetPromise = null;
|
||||||
@ -142,6 +143,10 @@ class PopupProxy {
|
|||||||
try {
|
try {
|
||||||
const offset = await this._frameOffsetPromise;
|
const offset = await this._frameOffsetPromise;
|
||||||
this._frameOffset = offset !== null ? offset : [0, 0];
|
this._frameOffset = offset !== null ? offset : [0, 0];
|
||||||
|
if (offset === null && this._setDisabled !== null) {
|
||||||
|
this._setDisabled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._frameOffsetUpdatedAt = now;
|
this._frameOffsetUpdatedAt = now;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e);
|
logError(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user