From 03797626cf857932810a8c336508093628022b17 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 11 Mar 2015 17:54:32 -0600 Subject: [PATCH] Fix vAPI.download across all platforms --- platform/chromium/vapi-common.js | 2 +- platform/firefox/vapi-common.js | 14 +++++++++++--- platform/safari/vapi-background.js | 3 ++- platform/safari/vapi-common.js | 13 ++++++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 3e95b3f10..77216462e 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -71,7 +71,7 @@ vAPI.download = function(details) { }; if ( vAPI.isMainProcess ) { - vAPI.tabs.open(request); + vAPI.tabs.open(request.details); return; } diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index 1e9f81c92..4ae771759 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -57,14 +57,22 @@ vAPI.download = function(details) { a.dispatchEvent(new MouseEvent('click')); return; } - var messager = vAPI.messaging.channel('_download'); - messager.send({ + + var request = { what: 'gotoURL', details: { url: details.url, index: -1 } - }); + }; + + if ( vAPI.isMainProcess ) { + vAPI.tabs.open(request); + return; + } + + var messager = vAPI.messaging.channel('_download'); + messager.send(request); messager.close(); }; diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index 143693ce8..be51b0e06 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -31,7 +31,8 @@ "use strict"; var vAPI = self.vAPI = self.vAPI || {}; - + + vAPI.isMainProcess = true; vAPI.safari = true; /******************************************************************************/ diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index ac47849cf..936d1e846 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -55,14 +55,21 @@ vAPI.download = function(details) { a.dispatchEvent(new MouseEvent('click')); return; } - var messager = vAPI.messaging.channel('_download'); - messager.send({ + var request = { what: 'gotoURL', details: { url: details.url, index: -1 } - }); + }; + + if ( vAPI.isMainProcess ) { + vAPI.tabs.open(request); + return; + } + + var messager = vAPI.messaging.channel('_download'); + messager.send(request); messager.close(); };