diff options
| -rw-r--r-- | background_scripts/main.coffee | 13 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 5 | ||||
| -rw-r--r-- | lib/utils.coffee | 10 | 
3 files changed, 18 insertions, 10 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 8eb6e57d..97d8fa65 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/dom_utils.coffee b/lib/dom_utils.coffee index 32d402df..ff5991dc 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -276,8 +276,7 @@ DomUtils =        # but Webkit will. Dispatching a click on an input box does not seem to focus it; we do that separately        element.dispatchEvent(mouseEvent) -  simulateClickDefaultAction: (element, modifiers) -> -    return unless modifiers? +  simulateClickDefaultAction: (element, modifiers = {}) ->      return unless element.tagName?.toLowerCase() == "a" and element.href?      {ctrlKey, shiftKey, metaKey, altKey} = modifiers @@ -295,6 +294,8 @@ DomUtils =      else if shiftKey == true and metaKey == false and ctrlKey == false and altKey == false        # Open in new window.        chrome.runtime.sendMessage {handler: "openUrlInNewWindow", url: element.href} +    else if element.target == "_blank" +      chrome.runtime.sendMessage {handler: "openUrlInNewTab", url: element.href, active: true}      return 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 | 
