aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/main.js31
-rw-r--r--content_scripts/vimium_frontend.coffee15
2 files changed, 13 insertions, 33 deletions
diff --git a/background_scripts/main.js b/background_scripts/main.js
index 4dc11181..d770bb56 100644
--- a/background_scripts/main.js
+++ b/background_scripts/main.js
@@ -16,7 +16,6 @@ var namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/;
// Port handler mapping
var portHandlers = {
keyDown: handleKeyDown,
- returnScrollPosition: handleReturnScrollPosition,
getCurrentTabUrl: getCurrentTabUrl,
settings: handleSettings,
filterCompleter: filterCompleter
@@ -40,7 +39,6 @@ var sendRequestHandlers = {
// Event handlers
var selectionChangedHandlers = [];
-var getScrollPositionHandlers = {}; // tabId -> function(tab, scrollX, scrollY);
var tabLoadedHandlers = {}; // tabId -> function()
var completionSources = {
@@ -88,15 +86,6 @@ chrome.extension.onRequest.addListener(function (request, sender, sendResponse)
sendResponse(sendRequestHandlers[request.handler](request, sender));
});
-function handleReturnScrollPosition(args) {
- if (getScrollPositionHandlers[args.currentTab.id]) {
- // Delete first to be sure there's no circular events.
- var toCall = getScrollPositionHandlers[args.currentTab.id];
- delete getScrollPositionHandlers[args.currentTab.id];
- toCall(args.currentTab, args.scrollX, args.scrollY);
- }
-}
-
/*
* Used by the content scripts to get their full URL. This is needed for URLs like "view-source:http:// .."
* because window.location doesn't know anything about the Chrome-specific "view-source:".
@@ -306,14 +295,6 @@ function repeatFunction(func, totalCount, currentCount, frameId) {
func(function() { repeatFunction(func, totalCount, currentCount + 1, frameId); }, frameId);
}
-// Returns the scroll coordinates of the given tab. Pass in a callback of the form:
-// function(tab, scrollX, scrollY) { .. }
-function getScrollPosition(tab, callback) {
- getScrollPositionHandlers[tab.id] = callback;
- var scrollPort = chrome.tabs.connect(tab.id, { name: "getScrollPosition" });
- scrollPort.postMessage({currentTab: tab});
-}
-
// Start action functions
function createTab(callback) {
chrome.tabs.create({}, function(tab) { callback(); });
@@ -783,11 +764,13 @@ function init() {
for (var j in windows[i].tabs) {
var tab = windows[i].tabs[j];
updateOpenTabs(tab);
- getScrollPosition(tab, function(tab, scrollX, scrollY) {
- // Not using the tab defined in the for loop because
- // it might have changed by the time this callback is activated.
- updateScrollPosition(tab, scrollX, scrollY);
- });
+ chrome.tabs.sendRequest(tab.id, { name: "getScrollPosition" }, function() {
+ return function(response) {
+ if (response === undefined)
+ return;
+ updateScrollPosition(tab, response.scrollX, response.scrollY);
+ };
+ }());
}
}
});
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 21c366e9..8ba59b5c 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -119,9 +119,13 @@ initializePreDomReady = ->
focusThisFrame(request.highlight)
else if (request.name == "refreshCompletionKeys")
refreshCompletionKeys(request)
+ else if (request.name == "getScrollPosition")
+ sendResponse
+ scrollX: window.scrollX
+ scrollY: window.scrollY
- # Free up the resources used by this open connection.
- sendResponse({})
+ # Ensure the sendResponse callback is freed.
+ false
chrome.extension.onConnect.addListener (port, name) ->
if (port.name == "executePageCommand")
@@ -133,13 +137,6 @@ initializePreDomReady = ->
Utils.invokeCommandString(args.command) for i in [0...args.count]
refreshCompletionKeys(args)
- else if (port.name == "getScrollPosition")
- port.onMessage.addListener (args) ->
- scrollPort = chrome.extension.connect({ name: "returnScrollPosition" })
- scrollPort.postMessage
- scrollX: window.scrollX,
- scrollY: window.scrollY,
- currentTab: args.currentTab
else if (port.name == "setScrollPosition")
port.onMessage.addListener (args) ->
if (args.scrollX > 0 || args.scrollY > 0)