gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] 02/02: Fix redirect for Firefox on And


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] 02/02: Fix redirect for Firefox on Android
Date: Tue, 20 Feb 2018 15:13:17 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-webex.

commit 6aa929f2a7dfb4264bbcb05e77e91984d3441cae
Author: Florian Dold <address@hidden>
AuthorDate: Tue Feb 20 15:12:45 2018 +0100

    Fix redirect for Firefox on Android
---
 manifest.json          |  4 ++--
 src/webex/compat.ts    | 22 +++++++++++-----------
 src/webex/wxBackend.ts | 36 ++++++++++++++++++++++++++++++++----
 3 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/manifest.json b/manifest.json
index f7c67941..b27fcd23 100644
--- a/manifest.json
+++ b/manifest.json
@@ -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",
diff --git a/src/webex/compat.ts b/src/webex/compat.ts
index f532c43b..30ffd4a8 100644
--- a/src/webex/compat.ts
+++ b/src/webex/compat.ts
@@ -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;
+}
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index f1116637..d7c43225 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -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

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]