From dcbd868c2d1d137d9ae9e700387d76942968f8ad Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 20 Feb 2018 14:51:02 +0100 Subject: [PATCH] Fix ACL dialog on Android --- add-on/src/lib/ipfs-proxy/request-access.js | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/add-on/src/lib/ipfs-proxy/request-access.js b/add-on/src/lib/ipfs-proxy/request-access.js index 9cdbdb65e..631a7bf75 100644 --- a/add-on/src/lib/ipfs-proxy/request-access.js +++ b/add-on/src/lib/ipfs-proxy/request-access.js @@ -9,21 +9,28 @@ function createRequestAccess (browser, screen) { return async function requestAccess (scope, permission, opts) { opts = opts || {} - const width = opts.dialogWidth || DIALOG_WIDTH - const height = opts.dialogHeight || DIALOG_HEIGHT - const url = browser.extension.getURL(opts.dialogPath || DIALOG_PATH) - const currentWin = await browser.windows.getCurrent() - - const top = Math.round(((screen.width / 2) - (width / 2)) + currentWin.left) - const left = Math.round(((screen.height / 2) - (height / 2)) + currentWin.top) - const dialogWindow = await browser.windows.create({ url, width, height, top, left, type: 'popup' }) - const dialogTabId = dialogWindow.tabs[0].id - // Fix for Fx57 bug where bundled page loaded using - // browser.windows.create won't show contents unless resized. - // See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110 - await browser.windows.update(dialogWindow.id, {width: dialogWindow.width + 1}) + let dialogTabId + if (browser && browser.windows && browser.windows.create) { + // display modal dialog in a centered popup window + const currentWin = await browser.windows.getCurrent() + const width = opts.dialogWidth || DIALOG_WIDTH + const height = opts.dialogHeight || DIALOG_HEIGHT + const top = Math.round(((screen.width / 2) - (width / 2)) + currentWin.left) + const left = Math.round(((screen.height / 2) - (height / 2)) + currentWin.top) + + const dialogWindow = await browser.windows.create({ url, width, height, top, left, type: 'popup' }) + dialogTabId = dialogWindow.tabs[0].id + // Fix for Fx57 bug where bundled page loaded using + // browser.windows.create won't show contents unless resized. + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110 + await browser.windows.update(dialogWindow.id, {width: dialogWindow.width + 1}) + } else { + // fallback: opening dialog as a new active tab + // (runtimes without browser.windows.create, eg. Andorid) + dialogTabId = (await browser.tabs.create({active: true, url: url})).id + } // Resolves with { allow, wildcard } const userResponse = getUserResponse(dialogTabId, scope, permission, opts)