aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/main.coffee26
-rw-r--r--content_scripts/link_hints.coffee2
-rw-r--r--content_scripts/vimium_frontend.coffee26
-rw-r--r--content_scripts/vomnibar.coffee8
-rw-r--r--tests/dom_tests/chrome.coffee4
5 files changed, 30 insertions, 36 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index c750162e..6d696b49 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -48,18 +48,12 @@ chrome.extension.onConnect.addListener((port, name) ->
# domReady is the appropriate time to show the "vimium has been upgraded" message.
# TODO: This might be broken on pages with frames.
if (shouldShowUpgradeMessage())
- chrome.tabs.sendRequest(senderTabId, { name: "showUpgradeNotification", version: currentVersion })
+ chrome.tabs.sendMessage(senderTabId, { name: "showUpgradeNotification", version: currentVersion })
if (portHandlers[port.name])
port.onMessage.addListener(portHandlers[port.name])
)
-chrome.extension.onRequest.addListener((request, sender, sendResponse) ->
- if (sendRequestHandlers[request.handler])
- sendResponse(sendRequestHandlers[request.handler](request, sender))
- # Ensure the sendResponse callback is freed.
- return false)
-
chrome.extension.onMessage.addListener((request, sender, sendResponse) ->
if (sendRequestHandlers[request.handler])
sendResponse(sendRequestHandlers[request.handler](request, sender))
@@ -257,7 +251,7 @@ BackgroundCommands =
# wait until that's over before we can call setScrollPosition.
chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) ->
tabLoadedHandlers[tab.id] = ->
- chrome.tabs.sendRequest(tab.id,
+ chrome.tabs.sendMessage(tab.id,
name: "setScrollPosition",
scrollX: tabQueueEntry.scrollX,
scrollY: tabQueueEntry.scrollY)
@@ -266,7 +260,7 @@ BackgroundCommands =
openCopiedUrlInNewTab: (request) -> openUrlInNewTab({ url: Clipboard.paste() })
showHelp: (callback, frameId) ->
chrome.tabs.getSelected(null, (tab) ->
- chrome.tabs.sendRequest(tab.id,
+ chrome.tabs.sendMessage(tab.id,
{ name: "toggleHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId }))
nextFrame: (count) ->
chrome.tabs.getSelected(null, (tab) ->
@@ -277,7 +271,7 @@ BackgroundCommands =
# since it exists only to contain the other frames.
newIndex = (currIndex + count) % frames.length
- chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[newIndex].id, highlight: true }))
+ chrome.tabs.sendMessage(tab.id, { name: "focusFrame", frameId: frames[newIndex].id, highlight: true }))
# Selects a tab before or after the currently selected tab.
# - direction: "next", "previous", "first" or "last".
@@ -325,7 +319,7 @@ updateActiveState = (tabId) ->
chrome.tabs.get(tabId, (tab) ->
# Default to disabled state in case we can't connect to Vimium, primarily for the "New Tab" page.
chrome.browserAction.setIcon({ path: disabledIcon })
- chrome.tabs.sendRequest(tabId, { name: "getActiveState" }, (response) ->
+ chrome.tabs.sendMessage(tabId, { name: "getActiveState" }, (response) ->
isCurrentlyEnabled = (response? && response.enabled)
shouldBeEnabled = isEnabledForUrl({url: tab.url}).isEnabledForUrl
@@ -334,7 +328,7 @@ updateActiveState = (tabId) ->
chrome.browserAction.setIcon({ path: enabledIcon })
else
chrome.browserAction.setIcon({ path: disabledIcon })
- chrome.tabs.sendRequest(tabId, { name: "disableVimium" })
+ chrome.tabs.sendMessage(tabId, { name: "disableVimium" })
else
chrome.browserAction.setIcon({ path: disabledIcon })))
@@ -479,7 +473,7 @@ checkKeyQueue = (keysToCheck, tabId, frameId) ->
registryEntry = Commands.keyToCommandRegistry[command]
if !registryEntry.isBackgroundCommand
- chrome.tabs.sendRequest(tabId,
+ chrome.tabs.sendMessage(tabId,
name: "executePageCommand",
command: registryEntry.command,
frameId: frameId,
@@ -510,7 +504,7 @@ checkKeyQueue = (keysToCheck, tabId, frameId) ->
# If we haven't sent the completion keys piggybacked on executePageCommand,
# send them by themselves.
unless refreshedCompletionKeys
- chrome.tabs.sendRequest(tabId, getCompletionKeysRequest(null, newKeyQueue), null)
+ chrome.tabs.sendMessage(tabId, getCompletionKeysRequest(null, newKeyQueue), null)
newKeyQueue
@@ -521,7 +515,7 @@ sendRequestToAllTabs = (args) ->
chrome.windows.getAll({ populate: true }, (windows) ->
for window in windows
for tab in window.tabs
- chrome.tabs.sendRequest(tab.id, args, null))
+ chrome.tabs.sendMessage(tab.id, args, null))
#
# Returns true if the current extension version is greater than the previously recorded version in
@@ -602,4 +596,4 @@ chrome.windows.getAll { populate: true }, (windows) ->
updateOpenTabs(tab)
createScrollPositionHandler = ->
(response) -> updateScrollPosition(tab, response.scrollX, response.scrollY) if response?
- chrome.tabs.sendRequest(tab.id, { name: "getScrollPosition" }, createScrollPositionHandler())
+ chrome.tabs.sendMessage(tab.id, { name: "getScrollPosition" }, createScrollPositionHandler())
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 30dd98a4..302acaac 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -91,7 +91,7 @@ LinkHints =
else if @mode is COPY_LINK_URL
HUD.show("Copy link URL to Clipboard")
@linkActivator = (link) ->
- chrome.extension.sendRequest({handler: "copyToClipboard", data: link.href})
+ chrome.extension.sendMessage({handler: "copyToClipboard", data: link.href})
else if @mode is OPEN_INCOGNITO
HUD.show("Open link in incognito window")
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 1b97c30a..676014f5 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -118,10 +118,10 @@ initializePreDomReady = ->
getActiveState: -> { enabled: isEnabledForUrl }
disableVimium: disableVimium
- chrome.extension.onRequest.addListener (request, sender, sendResponse) ->
+ chrome.extension.onMessage.addListener (request, sender, sendResponse) ->
# in the options page, we will receive requests from both content and background scripts. ignore those
# from the former.
- return unless sender.tab?.url.startsWith 'chrome-extension://'
+ return if sender.tab and not sender.tab.url.startsWith 'chrome-extension://'
return unless isEnabledForUrl or request.name == 'getActiveState'
sendResponse requestHandlers[request.name](request, sender)
# Ensure the sendResponse callback is freed.
@@ -158,7 +158,7 @@ disableVimium = ->
window.addEventListener "focus", ->
# settings may have changed since the frame last had focus
settings.load()
- chrome.extension.sendRequest({ handler: "frameFocused", frameId: frameId })
+ chrome.extension.sendMessage({ handler: "frameFocused", frameId: frameId })
#
# Initialization tasks that must wait for the document to be ready.
@@ -174,7 +174,7 @@ initializeOnDomReady = ->
# This is a little hacky but sometimes the size wasn't available on domReady?
registerFrameIfSizeAvailable = (is_top) ->
if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0)
- chrome.extension.sendRequest(
+ chrome.extension.sendMessage(
handler: "registerFrame"
frameId: frameId
area: innerWidth * innerHeight
@@ -250,19 +250,19 @@ extend window,
window.location.href = window.location.origin
toggleViewSource: ->
- chrome.extension.sendRequest { handler: "getCurrentTabUrl" }, (url) ->
+ chrome.extension.sendMessage { handler: "getCurrentTabUrl" }, (url) ->
if (url.substr(0, 12) == "view-source:")
url = url.substr(12, url.length - 12)
else
url = "view-source:" + url
- chrome.extension.sendRequest({ handler: "openUrlInNewTab", url: url, selected: true })
+ chrome.extension.sendMessage({ handler: "openUrlInNewTab", url: url, selected: true })
copyCurrentUrl: ->
# TODO(ilya): When the following bug is fixed, revisit this approach of sending back to the background
# page to copy.
# http://code.google.com/p/chromium/issues/detail?id=55188
- chrome.extension.sendRequest { handler: "getCurrentTabUrl" }, (url) ->
- chrome.extension.sendRequest { handler: "copyToClipboard", data: url }
+ chrome.extension.sendMessage { handler: "getCurrentTabUrl" }, (url) ->
+ chrome.extension.sendMessage { handler: "copyToClipboard", data: url }
HUD.showForDuration("Yanked URL", 1000)
@@ -437,7 +437,7 @@ onKeyup = (event) -> return unless handlerStack.bubbleEvent('keyup', event)
checkIfEnabledForUrl = ->
url = window.location.toString()
- chrome.extension.sendRequest { handler: "isEnabledForUrl", url: url }, (response) ->
+ chrome.extension.sendMessage { handler: "isEnabledForUrl", url: url }, (response) ->
isEnabledForUrl = response.isEnabledForUrl
if (isEnabledForUrl)
initializeWhenEnabled()
@@ -452,7 +452,7 @@ refreshCompletionKeys = (response) ->
if (response.validFirstKeys)
validFirstKeys = response.validFirstKeys
else
- chrome.extension.sendRequest({ handler: "getCompletionKeys" }, refreshCompletionKeys)
+ chrome.extension.sendMessage({ handler: "getCompletionKeys" }, refreshCompletionKeys)
isValidFirstKey = (keyChar) ->
validFirstKeys[keyChar] || /[1-9]/.test(keyChar)
@@ -869,7 +869,7 @@ window.showHelpDialog = (html, fid) ->
VimiumHelpDialog.init()
container.getElementsByClassName("optionsPage")[0].addEventListener("click",
- -> chrome.extension.sendRequest({ handler: "openOptionsPageInNewTab" })
+ -> chrome.extension.sendMessage({ handler: "openOptionsPageInNewTab" })
false)
@@ -926,7 +926,7 @@ HUD =
onUpdateLinkClicked: (event) ->
HUD.hideUpgradeNotification()
- chrome.extension.sendRequest({ handler: "upgradeNotificationClosed" })
+ chrome.extension.sendMessage({ handler: "upgradeNotificationClosed" })
hideUpgradeNotification: (clickEvent) ->
Tween.fade(HUD.upgradeNotificationElement(), 0, 150,
@@ -998,7 +998,7 @@ initializePreDomReady()
window.addEventListener("DOMContentLoaded", initializeOnDomReady)
window.onbeforeunload = ->
- chrome.extension.sendRequest(
+ chrome.extension.sendMessage(
handler: "updateScrollPosition"
scrollX: window.scrollX
scrollY: window.scrollY)
diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee
index b8d373c8..b8c28bcb 100644
--- a/content_scripts/vomnibar.coffee
+++ b/content_scripts/vomnibar.coffee
@@ -115,7 +115,7 @@ class VomnibarUI
# <Enter> on an empty vomnibar is a no-op.
return unless 0 < query.length
@hide()
- chrome.extension.sendRequest({
+ chrome.extension.sendMessage({
handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab"
url: query })
else
@@ -188,7 +188,7 @@ class BackgroundCompleter
constructor: (@name) ->
@filterPort = chrome.extension.connect({ name: "filterCompleter" })
- refresh: -> chrome.extension.sendRequest({ handler: "refreshCompleter", name: @name })
+ refresh: -> chrome.extension.sendMessage({ handler: "refreshCompleter", name: @name })
filter: (query, callback) ->
id = Utils.createUniqueId()
@@ -220,12 +220,12 @@ extend BackgroundCompleter,
script.textContent = decodeURIComponent(url["javascript:".length..])
(document.head || document.documentElement).appendChild script
else
- chrome.extension.sendRequest(
+ chrome.extension.sendMessage(
handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab"
url: url,
selected: openInNewTab)
- switchToTab: (tabId) -> chrome.extension.sendRequest({ handler: "selectSpecificTab", id: tabId })
+ switchToTab: (tabId) -> chrome.extension.sendMessage({ handler: "selectSpecificTab", id: tabId })
root = exports ? window
root.Vomnibar = Vomnibar
diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee
index ff7a53d0..c8ec9d29 100644
--- a/tests/dom_tests/chrome.coffee
+++ b/tests/dom_tests/chrome.coffee
@@ -12,9 +12,9 @@ root.chrome = {
}
postMessage: ->
}
- onRequest: {
+ onMessage: {
addListener: ->
}
- sendRequest: ->
+ sendMessage: ->
}
}