diff options
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/bg_utils.coffee | 2 | ||||
| -rw-r--r-- | background_scripts/commands.coffee | 7 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 37 | ||||
| -rw-r--r-- | background_scripts/marks.coffee | 6 |
4 files changed, 31 insertions, 21 deletions
diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee index b8e618ff..698f5352 100644 --- a/background_scripts/bg_utils.coffee +++ b/background_scripts/bg_utils.coffee @@ -18,7 +18,7 @@ class TabRecency @deregister removedTabId @register addedTabId - chrome.windows.onFocusChanged.addListener (wnd) => + chrome.windows?.onFocusChanged.addListener (wnd) => if wnd != chrome.windows.WINDOW_ID_NONE chrome.tabs.query {windowId: wnd, active: true}, (tabs) => @register tabs[0].id if tabs[0] diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index cda036e6..4d2e1606 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -113,6 +113,9 @@ Commands = # We don't need these properties in the content scripts. delete currentMapping[key][prop] for prop in ["keySequence", "description"] chrome.storage.local.set normalModeKeyStateMapping: keyStateMapping + # Inform `KeyboardUtils.isEscape()` whether `<c-[>` should be interpreted as `Escape` (which it is by + # default). + chrome.storage.local.set useVimLikeEscape: "<c-[>" not of keyStateMapping # Build the "helpPageData" data structure which the help page needs and place it in Chrome storage. prepareHelpPageData: -> @@ -337,8 +340,8 @@ commandDescriptions = toggleViewSource: ["View page source", { noRepeat: true }] copyCurrentUrl: ["Copy the current URL to the clipboard", { noRepeat: true }] - openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { background: true, noRepeat: true }] - openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true, repeatLimit: 20 }] + openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { noRepeat: true }] + openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { repeatLimit: 20 }] enterInsertMode: ["Enter insert mode", { noRepeat: true }] passNextKey: ["Pass the next key to the page"] diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 97d8fa65..8220545d 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -114,7 +114,7 @@ TabOperations = canUseOpenerTabId = not (Utils.isFirefox() and Utils.compareVersions(Utils.firefoxVersion(), "57") < 0) tabConfig.openerTabId = request.tab.id if canUseOpenerTabId - chrome.tabs.create tabConfig, callback + chrome.tabs.create tabConfig, -> callback request # Opens request.url in new window and switches to it. openUrlInNewWindow: (request, callback = (->)) -> @@ -148,7 +148,7 @@ toggleMuteTab = do -> # selectSpecificTab = (request) -> chrome.tabs.get(request.id, (tab) -> - chrome.windows.update(tab.windowId, { focused: true }) + chrome.windows?.update(tab.windowId, { focused: true }) chrome.tabs.update(request.id, { active: true })) moveTab = ({count, tab, registryEntry}) -> @@ -188,13 +188,20 @@ BackgroundCommands = [if request.tab.incognito then "chrome://newtab" else chrome.runtime.getURL newTabUrl] else [newTabUrl] - urls = request.urls[..].reverse() - do openNextUrl = (request) -> - if 0 < urls.length - TabOperations.openUrlInNewTab (extend request, {url: urls.pop()}), (tab) -> - openNextUrl extend request, {tab, tabId: tab.id} - else - callback request + if request.registryEntry.options.incognito or request.registryEntry.options.window + windowConfig = + url: request.urls + focused: true + incognito: request.registryEntry.options.incognito ? false + chrome.windows.create windowConfig, -> callback request + else + urls = request.urls[..].reverse() + do openNextUrl = (request) -> + if 0 < urls.length + TabOperations.openUrlInNewTab (extend request, {url: urls.pop()}), (tab) -> + openNextUrl extend request, {tab, tabId: tab.id} + else + callback request duplicateTab: mkRepeatCommand (request, callback) -> chrome.tabs.duplicate request.tabId, (tab) -> callback extend request, {tab, tabId: tab.id} moveTabToNewWindow: ({count, tab}) -> @@ -214,8 +221,6 @@ BackgroundCommands = startTabIndex = Math.max 0, Math.min activeTabIndex, tabs.length - count chrome.tabs.remove (tab.id for tab in tabs[startTabIndex...startTabIndex + count]) restoreTab: mkRepeatCommand (request, callback) -> chrome.sessions.restore null, callback request - openCopiedUrlInCurrentTab: (request) -> TabOperations.openUrlInCurrentTab extend request, url: Clipboard.paste() - openCopiedUrlInNewTab: (request) -> @createTab extend request, url: Clipboard.paste() togglePinTab: ({tab}) -> chrome.tabs.update tab.id, {pinned: !tab.pinned} toggleMuteTab: toggleMuteTab moveTabLeft: moveTab @@ -324,7 +329,7 @@ Frames = enabledState = Exclusions.isEnabledForUrl request.url if request.frameIsFocused - chrome.browserAction.setIcon tabId: tabId, imageData: do -> + chrome.browserAction.setIcon? tabId: tabId, imageData: do -> enabledStateIcon = if not enabledState.isEnabledForUrl DISABLED_ICON @@ -355,7 +360,7 @@ handleFrameFocused = ({tabId, frameId}) -> # Rotate through frames to the frame count places after frameId. cycleToFrame = (frames, frameId, count = 0) -> - # We can't always track which frame chrome has focussed, but here we learn that it's frameId; so add an + # We can't always track which frame chrome has focused, but here we learn that it's frameId; so add an # additional offset such that we do indeed start from frameId. count = (count + Math.max 0, frames.indexOf frameId) % frames.length [frames[count..]..., frames[0...count]...] @@ -423,7 +428,7 @@ sendRequestHandlers = # getCurrentTabUrl is used by the content scripts to get their full URL, because window.location cannot help # with Chrome-specific URLs like "view-source:http:..". getCurrentTabUrl: ({tab}) -> tab.url - openUrlInNewTab: (request) -> TabOperations.openUrlInNewTab request + openUrlInNewTab: mkRepeatCommand (request, callback) -> TabOperations.openUrlInNewTab request, callback openUrlInNewWindow: (request) -> TabOperations.openUrlInNewWindow request openUrlInIncognito: (request) -> chrome.windows.create incognito: true, url: Utils.convertToUrl request.url openUrlInCurrentTab: TabOperations.openUrlInCurrentTab @@ -431,8 +436,6 @@ sendRequestHandlers = chrome.tabs.create url: chrome.runtime.getURL("pages/options.html"), index: request.tab.index + 1 frameFocused: handleFrameFocused nextFrame: BackgroundCommands.nextFrame - copyToClipboard: Clipboard.copy.bind Clipboard - pasteFromClipboard: Clipboard.paste.bind Clipboard selectSpecificTab: selectSpecificTab createMark: Marks.create.bind(Marks) gotoMark: Marks.goto.bind(Marks) @@ -449,7 +452,7 @@ chrome.tabs.onRemoved.addListener (tabId) -> delete cache[tabId] for cache in [frameIdsForTab, urlForTab, portsForTab, HintCoordinator.tabState] chrome.storage.local.get "findModeRawQueryListIncognito", (items) -> if items.findModeRawQueryListIncognito - chrome.windows.getAll null, (windows) -> + chrome.windows?.getAll null, (windows) -> for window in windows return if window.incognito # There are no remaining incognito-mode tabs, and findModeRawQueryListIncognito is set. diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee index a6491b9e..77b07b41 100644 --- a/background_scripts/marks.coffee +++ b/background_scripts/marks.coffee @@ -82,7 +82,7 @@ Marks = # Given a list of tabs candidate tabs, pick one. Prefer tabs in the current window and tabs with shorter # (matching) URLs. pickTab: (tabs, callback) -> - chrome.windows.getCurrent ({ id }) -> + tabPicker = ({ id }) -> # Prefer tabs in the current window, if there are any. tabsInWindow = tabs.filter (tab) -> tab.windowId == id tabs = tabsInWindow if 0 < tabsInWindow.length @@ -92,6 +92,10 @@ Marks = # Prefer shorter URLs. tabs.sort (a,b) -> a.url.length - b.url.length callback tabs[0] + if chrome.windows? + chrome.windows.getCurrent tabPicker + else + tabPicker({id: undefined}) root = exports ? window root.Marks = Marks |
