aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2017-09-30 07:18:00 +0100
committerGitHub2017-09-30 07:18:00 +0100
commit245fd88b58297733765571b4db37ff958f7a32c2 (patch)
treec31664c7e08b715a6b368e39ab3779932585db40
parente3e4347038c7580241e44c0d8b0f2febc3796c8c (diff)
parentfdc374f0904ddc0179f352aa9b4049c68872768e (diff)
downloadvimium-245fd88b58297733765571b4db37ff958f7a32c2.tar.bz2
Merge pull request #2682 from mrmr1993/ff-setOpener
Use openerTabId in chrome.tabs.create when possible
-rw-r--r--background_scripts/main.coffee13
-rw-r--r--lib/utils.coffee10
2 files changed, 15 insertions, 8 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 8afecd4f..10d383f9 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -109,13 +109,12 @@ TabOperations =
tabConfig.active = request.active if request.active?
# Firefox does not support "about:newtab" in chrome.tabs.create.
delete tabConfig["url"] if tabConfig["url"] == Settings.defaults.newTabUrl
- chrome.tabs.create tabConfig, (tab) ->
- # NOTE(mrmr1993, 2017-02-08): Firefox currently doesn't support openerTabId (issue 1238314) and throws
- # a type error if it is present. We work around this by attempting to set it separately from creating
- # the tab.
- try chrome.tabs.update tab.id, { openerTabId : request.tab.id }, callback
- catch
- callback.apply this, arguments
+
+ # Firefox <57 throws an error when openerTabId is used (issue 1238314).
+ canUseOpenerTabId = not (Utils.isFirefox() and Utils.compareVersions(Utils.firefoxVersion(), "57") < 0)
+ tabConfig.openerTabId = request.tab.id if canUseOpenerTabId
+
+ chrome.tabs.create tabConfig, callback
# Opens request.url in new window and switches to it.
openUrlInNewWindow: (request, callback = (->)) ->
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 03dab999..d0a82cf7 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -6,14 +6,22 @@ window.forTrusted ?= (handler) -> (event) ->
else
true
+browserInfo = browser?.runtime?.getBrowserInfo?()
+
Utils =
isFirefox: do ->
# NOTE(mrmr1993): This test only works in the background page, this is overwritten by isEnabledForUrl for
# content scripts.
isFirefox = false
- browser?.runtime?.getBrowserInfo?()?.then? (browserInfo) ->
+ browserInfo?.then? (browserInfo) ->
isFirefox = browserInfo?.name == "Firefox"
-> isFirefox
+ firefoxVersion: do ->
+ # NOTE(mrmr1993): This only works in the background page.
+ ffVersion = undefined
+ browserInfo?.then? (browserInfo) ->
+ ffVersion = browserInfo?.version
+ -> ffVersion
getCurrentVersion: ->
chrome.runtime.getManifest().version