From aca953e06a7cf5aa6906df677a8fb6ed3e688a03 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 25 Oct 2017 16:45:45 +0100 Subject: FF: Share |root| global proxy, re-add the globals to window on DOMLoad This is a workaround for Firefox bug 1408996. --- content_scripts/vimium_frontend.coffee | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'content_scripts/vimium_frontend.coffee') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 96ce81a3..0beb2110 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -2,6 +2,12 @@ # This content script must be run prior to domReady so that we perform some operations very early. # +root = exports ? (window.root ?= {}) +# On Firefox, sometimes the variables assigned to window are lost (bug 1408996), so we reinstall them. +# NOTE(mrmr1993): This bug leads to catastrophic failure (ie. nothing works and errors abound). +DomUtils.documentReady -> + (extend ? root.extend) window, root + isEnabledForUrl = true isIncognitoMode = chrome.extension.inIncognitoContext normalMode = null @@ -245,7 +251,7 @@ Frame = postMessage: (handler, request = {}) -> @port.postMessage extend request, {handler} linkHintsMessage: (request) -> HintCoordinator[request.messageType] request registerFrameId: ({chromeFrameId}) -> - frameId = window.frameId = chromeFrameId + frameId = root.frameId = window.frameId = chromeFrameId # We register a frame immediately only if it is focused or its window isn't tiny. We register tiny # frames later, when necessary. This affects focusFrame() and link hints. if windowIsFocused() or not DomUtils.windowIsTooSmall() @@ -327,7 +333,7 @@ focusThisFrame = (request) -> document.activeElement.blur() if document.activeElement.tagName.toLowerCase() == "iframe" flashFrame() if request.highlight -extend window, +extend root, scrollToBottom: -> Marks.setPreviousPosition() Scroller.scrollTo "y", "max" @@ -345,7 +351,7 @@ extend window, scrollLeft: (count) -> Scroller.scrollBy "x", -1 * Settings.get("scrollStepSize") * count scrollRight: (count) -> Scroller.scrollBy "x", Settings.get("scrollStepSize") * count -extend window, +extend root, reload: (count, options) -> hard = options?.hard window.location.reload(hard) @@ -654,12 +660,12 @@ findAndFollowRel = (value) -> followLink(element) return true -window.goPrevious = -> +root.goPrevious = -> previousPatterns = Settings.get("previousPatterns") || "" previousStrings = previousPatterns.split(",").filter( (s) -> s.trim().length ) findAndFollowRel("prev") || findAndFollowLink(previousStrings) -window.goNext = -> +root.goNext = -> nextPatterns = Settings.get("nextPatterns") || "" nextStrings = nextPatterns.split(",").filter( (s) -> s.trim().length ) findAndFollowRel("next") || findAndFollowLink(nextStrings) @@ -669,11 +675,11 @@ enterFindMode = -> Marks.setPreviousPosition() new FindMode() -window.showHelp = (sourceFrameId) -> +root.showHelp = (sourceFrameId) -> HelpDialog.toggle {sourceFrameId, showAllCommandDetails: false} # If we are in the help dialog iframe, then HelpDialog is already defined with the necessary functions. -window.HelpDialog ?= +root.HelpDialog ?= helpUI: null isShowing: -> @helpUI?.showing abort: -> @helpUI.hide false if @isShowing() @@ -690,7 +696,6 @@ window.HelpDialog ?= initializePreDomReady() DomUtils.documentReady initializeOnDomReady -root = exports ? window root.handlerStack = handlerStack root.frameId = frameId root.Frame = Frame @@ -701,3 +706,4 @@ extend root, {handleEscapeForFindMode, handleEnterForFindMode, performFind, perf enterFindMode, focusThisFrame} # These are exported only for the tests. extend root, {installModes} +extend window, root unless exports? -- cgit v1.2.3