Fix redirect for Firefox on Android

This commit is contained in:
Florian Dold 2018-02-20 15:12:45 +01:00
parent aa4757355a
commit 6aa929f2a7
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 45 additions and 17 deletions

View File

@ -4,8 +4,8 @@
"name": "GNU Taler Wallet (git)",
"description": "Privacy preserving and transparent payments",
"author": "GNU Taler Developers",
"version": "0.6.55",
"version_name": "0.5.0-pre8",
"version": "0.6.56",
"version_name": "0.5.0-pre9",
"minimum_chrome_version": "51",
"minimum_opera_version": "36",

View File

@ -14,15 +14,15 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* Compatibility helpers needed for browsers that don't implement
* WebExtension APIs consistently.
*/
/**
* Compatibility helpers needed for browsers that don't implement
* WebExtension APIs consistently.
*/
export function isFirefox(): boolean {
const rt = chrome.runtime as any;
if (typeof rt.getBrowserInfo === "function") {
return true;
}
return false;
}
export function isFirefox(): boolean {
const rt = chrome.runtime as any;
if (typeof rt.getBrowserInfo === "function") {
return true;
}
return false;
}

View File

@ -44,6 +44,8 @@ import {
Wallet,
} from "../wallet";
import { isFirefox } from "./compat";
import {
PurchaseRecord,
Stores,
@ -449,7 +451,21 @@ async function talerPay(fields: any, url: string, tabId: number): Promise<string
}
function makeSyncWalletRedirect(url: string, params?: {[name: string]: string | undefined}): object {
function getTab(tabId: number): Promise<chrome.tabs.Tab> {
return new Promise((resolve, reject) => {
chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab));
});
}
function waitMs(timeoutMs: number): Promise<void> {
return new Promise((resolve, reject) => {
chrome.extension.getBackgroundPage().setTimeout(() => resolve(), timeoutMs);
});
}
function makeSyncWalletRedirect(url: string, tabId: number, oldUrl: string, params?: {[name: string]: string | undefined}): object {
const innerUrl = new URI(chrome.extension.getURL("/src/webex/pages/" + url));
if (params) {
for (const key in params) {
@ -460,6 +476,18 @@ function makeSyncWalletRedirect(url: string, params?: {[name: string]: string |
}
const outerUrl = new URI(chrome.extension.getURL("/src/webex/pages/redirect.html"));
outerUrl.addSearch("url", innerUrl);
if (isFirefox()) {
// Some platforms don't support the sync redirect (yet), so fall back to
// async redirect after a timeout.
const doit = async() => {
await waitMs(150);
const tab = await getTab(tabId);
if (tab.url === oldUrl) {
chrome.tabs.update(tabId, { url: outerUrl.href() });
}
};
doit();
}
return { redirectUrl: outerUrl.href() };
}
@ -512,7 +540,7 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
}
// Synchronous fast path for new contract
if (fields.contract_url) {
return makeSyncWalletRedirect("confirm-contract.html", {
return makeSyncWalletRedirect("confirm-contract.html", tabId, url, {
contractUrl: fields.contract_url,
sessionId: fields.session_id,
resourceUrl: fields.resource_url,
@ -521,13 +549,13 @@ function handleHttpPayment(headerList: chrome.webRequest.HttpHeader[], url: stri
// Synchronous fast path for tip
if (fields.tip) {
return makeSyncWalletRedirect("tip.html", { tip_token: fields.tip });
return makeSyncWalletRedirect("tip.html", tabId, url, { tip_token: fields.tip });
}
// Synchronous fast path for refund
if (fields.refund_url) {
console.log("processing refund");
return makeSyncWalletRedirect("refund.html", { refundUrl: fields.refund_url });
return makeSyncWalletRedirect("refund.html", tabId, url, { refundUrl: fields.refund_url });
}
// We need to do some asynchronous operation, we can't directly redirect