diff options
| author | Stephen Blott | 2016-03-25 06:31:42 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-03-28 08:21:20 +0100 |
| commit | 23884b31ba643f1ad1e44f5fc949bd3329df6985 (patch) | |
| tree | b39e1df913f0b5370db34fdc4e15ce277ea9b7b5 /background_scripts | |
| parent | 091afd73bb5952d2b30b8de657afb6c3a874d274 (diff) | |
| download | vimium-23884b31ba643f1ad1e44f5fc949bd3329df6985.tar.bz2 | |
Use image data for icons.
This uses image data (instead of a path) for the page icon. It also
only builds 19x19 and 38x38 icons, as per the
chrome.browserAction.setIcon() documentation.
This appears to fix a memory leak related to a recent Chrome regression
(versions 49+).
Fixes #2055.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/main.coffee | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 2fe2fa99..4c69e2bb 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -263,6 +263,30 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) -> runAt: "document_start" chrome.tabs.insertCSS tabId, cssConf, -> chrome.runtime.lastError +# Symbolic names for the three browser-action icons. +ENABLED_ICON = "icons/browser_action_enabled.png" +DISABLED_ICON = "icons/browser_action_disabled.png" +PARTIAL_ICON = "icons/browser_action_partial.png" + +# Convert the three icon PNGs to image data. +iconImageData = {} +for icon in [ENABLED_ICON, DISABLED_ICON, PARTIAL_ICON] + iconImageData[icon] = {} + for scale in [19, 38] + do (icon, scale) -> + canvas = document.createElement "canvas" + canvas.width = canvas.height = scale + # We cannot do the rest of this in the tests. + unless chrome.areRunningVimiumTests? and chrome.areRunningVimiumTests + context = canvas.getContext "2d" + image = new Image + image.src = icon + image.onload = -> + context.drawImage image, 0, 0, scale, scale + iconImageData[icon][scale] = context.getImageData 0, 0, scale, scale + document.body.removeChild canvas + document.body.appendChild canvas + Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] @@ -288,13 +312,15 @@ Frames = enabledState = Exclusions.isEnabledForUrl request.url 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" + chrome.browserAction.setIcon tabId: tabId, imageData: do -> + enabledStateIcon = + if not enabledState.isEnabledForUrl + DISABLED_ICON + else if 0 < enabledState.passKeys.length + PARTIAL_ICON + else + ENABLED_ICON + iconImageData[enabledStateIcon] port.postMessage extend request, enabledState |
