Skip to content

Commit 27ad1c4

Browse files
committed
Fixed prompts factory regression on Android.
1 parent acf1ab6 commit 27ad1c4

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

src/ui/Prompts.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ var Prompts = (() => {
3939
this.close();
4040

4141
let url = browser.runtime.getURL("ui/prompt.html");
42+
43+
if (!("windows" in browser)) {
44+
// Android, most likely
45+
this.currentTab = await browser.tabs.create({url});
46+
return;
47+
}
48+
4249
let {width, height, left, top, parent } = data.features;
50+
4351
let options = {
4452
url,
4553
type: "popup",
@@ -53,32 +61,23 @@ var Prompts = (() => {
5361
options.allowScriptsToClose = true;
5462
}
5563

56-
if (!("windows" in browser)) {
57-
// Android, most likely
58-
this.currentTab = await browser.tabs.create({url});
59-
return;
60-
}
61-
62-
const centerOnParent = (dim) => {
63-
const { width, height } = dim;
64-
dim.left =
65-
left === undefined
66-
? Math.round(parent.left + (parent.width - width) / 2)
67-
: left;
68-
dim.top =
69-
top === undefined
70-
? Math.round(parent.top + (parent.height - height) / 2)
71-
: top;
72-
return dim;
64+
const centerOnParent = bounds => {
65+
for (const [p, s] of [["left", "width"], ["top", "height"]]) {
66+
if (bounds[s] && bounds[p] === undefined) {
67+
bounds[p] = Math.round(parent[p] + (parent[s] - bounds[s]) / 2);
68+
}
69+
}
70+
return bounds;
7371
};
7472

7573
if (width && height) {
76-
let size = { width, height };
77-
url += `?size=${JSON.stringify(size)}`;
74+
const bounds = { width, height, left, top };
75+
url += `?winbounds=${JSON.stringify(bounds)}`;
7876
if (parent) {
79-
({ left, top } = Object.assign(options, centerOnParent(size)));
77+
({ left, top } = Object.assign(options, centerOnParent(bounds)));
8078
}
8179
}
80+
8281
debug("Prompt pre-opening options", options, left, top, width, height); // DEV_ONLY
8382
let popup = (this.currentWindow = await browser.windows.create(options));
8483

@@ -93,7 +92,7 @@ var Prompts = (() => {
9392
if (top === undefined) ({ top } = popup);
9493
}
9594

96-
debug("Prompt post-opening options", popup, options, left, top, width, height);
95+
debug("Prompt post-opening options", popup, options, left, top, width, height); // DEV_ONLY
9796

9897
// work around for resistFingerprinting new window rounding (https://bugzilla.mozilla.org/show_bug.cgi?id=1330882)
9998
if (

src/ui/prompt.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@
139139
await browser.windows.update(win.id, {
140140
height: win.height + delta,
141141
top: win.top - Math.round(delta / 2),
142-
focused: false
143142
});
144143
}
145-
await browser.windows.update(win.id, {focused: true});
146144
}
147145
if (document.readyState === "complete") {
148146
fitHeight();

src/ui/resize_hack.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ if ("windows" in browser) document.addEventListener("DOMContentLoaded", async e
2424
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110
2525
let win = await browser.windows.getCurrent({populate: true});
2626
if (win.tabs[0].url === document.URL) {
27-
let size = decodeURIComponent(location.search).match(/\bsize=(\{\s*"width":[^}]+\})/);
27+
let bounds = decodeURIComponent(location.href).match(/\bwinbounds=(\{[^}]*"width":[^}]+\})/);
2828
try {
29-
size = size && JSON.parse(size[1]);
29+
bounds = bounds && JSON.parse(bounds[1]);
3030
} catch (e) {
31-
size = null;
31+
bounds = null;
3232
}
33-
let {width, height} = size || win;
34-
debug("Resize hack", win, size, width, height); // DEV_ONLY
33+
let {width} = bounds || win;
34+
debug("Resize hack", win, bounds); // DEV_ONLY
3535
await browser.windows.update(win.id, {
36-
width: width + 1, height
36+
width: width + 1
3737
});
3838
await browser.windows.update(win.id, {
39-
width, height
39+
width
4040
});
4141
}
4242
});

0 commit comments

Comments
 (0)