Fixed prompts factory regression on Android.
This commit is contained in:
parent
acf1ab6a1b
commit
27ad1c4192
|
@ -39,7 +39,15 @@ var Prompts = (() => {
|
|||
this.close();
|
||||
|
||||
let url = browser.runtime.getURL("ui/prompt.html");
|
||||
|
||||
if (!("windows" in browser)) {
|
||||
// Android, most likely
|
||||
this.currentTab = await browser.tabs.create({url});
|
||||
return;
|
||||
}
|
||||
|
||||
let {width, height, left, top, parent } = data.features;
|
||||
|
||||
let options = {
|
||||
url,
|
||||
type: "popup",
|
||||
|
@ -53,32 +61,23 @@ var Prompts = (() => {
|
|||
options.allowScriptsToClose = true;
|
||||
}
|
||||
|
||||
if (!("windows" in browser)) {
|
||||
// Android, most likely
|
||||
this.currentTab = await browser.tabs.create({url});
|
||||
return;
|
||||
const centerOnParent = bounds => {
|
||||
for (const [p, s] of [["left", "width"], ["top", "height"]]) {
|
||||
if (bounds[s] && bounds[p] === undefined) {
|
||||
bounds[p] = Math.round(parent[p] + (parent[s] - bounds[s]) / 2);
|
||||
}
|
||||
|
||||
const centerOnParent = (dim) => {
|
||||
const { width, height } = dim;
|
||||
dim.left =
|
||||
left === undefined
|
||||
? Math.round(parent.left + (parent.width - width) / 2)
|
||||
: left;
|
||||
dim.top =
|
||||
top === undefined
|
||||
? Math.round(parent.top + (parent.height - height) / 2)
|
||||
: top;
|
||||
return dim;
|
||||
}
|
||||
return bounds;
|
||||
};
|
||||
|
||||
if (width && height) {
|
||||
let size = { width, height };
|
||||
url += `?size=${JSON.stringify(size)}`;
|
||||
const bounds = { width, height, left, top };
|
||||
url += `?winbounds=${JSON.stringify(bounds)}`;
|
||||
if (parent) {
|
||||
({ left, top } = Object.assign(options, centerOnParent(size)));
|
||||
({ left, top } = Object.assign(options, centerOnParent(bounds)));
|
||||
}
|
||||
}
|
||||
|
||||
debug("Prompt pre-opening options", options, left, top, width, height); // DEV_ONLY
|
||||
let popup = (this.currentWindow = await browser.windows.create(options));
|
||||
|
||||
|
@ -93,7 +92,7 @@ var Prompts = (() => {
|
|||
if (top === undefined) ({ top } = popup);
|
||||
}
|
||||
|
||||
debug("Prompt post-opening options", popup, options, left, top, width, height);
|
||||
debug("Prompt post-opening options", popup, options, left, top, width, height); // DEV_ONLY
|
||||
|
||||
// work around for resistFingerprinting new window rounding (https://bugzilla.mozilla.org/show_bug.cgi?id=1330882)
|
||||
if (
|
||||
|
|
|
@ -139,10 +139,8 @@
|
|||
await browser.windows.update(win.id, {
|
||||
height: win.height + delta,
|
||||
top: win.top - Math.round(delta / 2),
|
||||
focused: false
|
||||
});
|
||||
}
|
||||
await browser.windows.update(win.id, {focused: true});
|
||||
}
|
||||
if (document.readyState === "complete") {
|
||||
fitHeight();
|
||||
|
|
|
@ -24,19 +24,19 @@ if ("windows" in browser) document.addEventListener("DOMContentLoaded", async e
|
|||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110
|
||||
let win = await browser.windows.getCurrent({populate: true});
|
||||
if (win.tabs[0].url === document.URL) {
|
||||
let size = decodeURIComponent(location.search).match(/\bsize=(\{\s*"width":[^}]+\})/);
|
||||
let bounds = decodeURIComponent(location.href).match(/\bwinbounds=(\{[^}]*"width":[^}]+\})/);
|
||||
try {
|
||||
size = size && JSON.parse(size[1]);
|
||||
bounds = bounds && JSON.parse(bounds[1]);
|
||||
} catch (e) {
|
||||
size = null;
|
||||
bounds = null;
|
||||
}
|
||||
let {width, height} = size || win;
|
||||
debug("Resize hack", win, size, width, height); // DEV_ONLY
|
||||
let {width} = bounds || win;
|
||||
debug("Resize hack", win, bounds); // DEV_ONLY
|
||||
await browser.windows.update(win.id, {
|
||||
width: width + 1, height
|
||||
width: width + 1
|
||||
});
|
||||
await browser.windows.update(win.id, {
|
||||
width, height
|
||||
width
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue