diff options
| author | Stephen Blott | 2016-03-17 14:02:02 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-17 14:02:02 +0000 | 
| commit | 744e293fb9ff65f086d06b8aeb44231db8e6331c (patch) | |
| tree | fc7adc77b6d5e8a7501c4d8bb0cac850b65817fd /background_scripts/main.coffee | |
| parent | 1199849d929ae20e79d8e07dbf14957d9c1029f8 (diff) | |
| download | vimium-744e293fb9ff65f086d06b8aeb44231db8e6331c.tar.bz2 | |
Refactor setIcon to the background page.
There's no need for the setting of the icon to be driven from the
content script.  We first know the enabled state in the background page,
so set the icon there immediately.
Diffstat (limited to 'background_scripts/main.coffee')
| -rw-r--r-- | background_scripts/main.coffee | 33 | 
1 files changed, 13 insertions, 20 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 1a67f2b2..0d82e61c 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -311,24 +311,6 @@ selectTab = (direction, count = 1) ->              Math.max 0, tabs.length - count        chrome.tabs.update tabs[toSelect].id, selected: true -# Here's how we set the page icon.  The default is "disabled", so if we do nothing else, then we get the -# grey-out disabled icon.  Thereafter, we only set tab-specific icons, so there's no need to update the icon -# when we visit a tab on which Vimium isn't running. -# -# For active tabs, when a frame starts, it requests its active state via isEnabledForUrl.  We also check the -# state every time a frame gets the focus.  In both cases, the frame then updates the tab's icon accordingly. -# -# Exclusion rule changes (from either the options page or the page popup) propagate via the subsequent focus -# change.  In particular, whenever a frame next gets the focus, it requests its new state and sets the icon -# accordingly. -# -setIcon = (request, sender) -> -  path = switch request.icon -    when "enabled" then "icons/browser_action_enabled.png" -    when "partial" then "icons/browser_action_partial.png" -    when "disabled" then "icons/browser_action_disabled.png" -  chrome.browserAction.setIcon tabId: sender.tab.id, path: path -  chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) ->    return unless changeInfo.status == "loading" # only do this once per URL change    cssConf = @@ -373,10 +355,22 @@ Frames =    isEnabledForUrl: ({request, tabId, port}) ->      urlForTab[tabId] = request.url if request.frameIsFocused      rule = Exclusions.getRule request.url -    port.postMessage extend request, +    enabledState =        isEnabledForUrl: not rule or 0 < rule.passKeys.length        passKeys: rule?.passKeys ? "" +    if request.frameIsFocused +      chrome.browserAction.setIcon tabId: tabId, path: +        if not enabledState.isEnabledForUrl +          "icons/browser_action_disabled.png" +        else if 0 < enabledState.passKeys.length +          "icons/browser_action_partial.png" +        else +          "icons/browser_action_enabled.png" + +    # Send the response.  The tests require this to be last. +    port.postMessage extend request, enabledState +    domReady: ({tabId, frameId}) ->      if frameId == 0        tabLoadedHandlers[tabId]?() @@ -423,7 +417,6 @@ sendRequestHandlers =    selectSpecificTab: selectSpecificTab    createMark: Marks.create.bind(Marks)    gotoMark: Marks.goto.bind(Marks) -  setIcon: setIcon    sendMessageToFrames: sendMessageToFrames    log: bgLog    fetchFileContents: (request, sender) -> fetchFileContents request.fileName | 
