diff options
Diffstat (limited to 'background_page.html')
| -rw-r--r-- | background_page.html | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/background_page.html b/background_page.html index ba459f53..71bbcf7a 100644 --- a/background_page.html +++ b/background_page.html @@ -71,7 +71,7 @@ }; var sendRequestHandlers = { - getCompletionKeys: getCompletionKeys, + getCompletionKeys: getCompletionKeysRequest, getLinkHintCss: getLinkHintCss, openUrlInNewTab: openUrlInNewTab, openUrlInCurrentTab: openUrlInCurrentTab, @@ -236,8 +236,11 @@ /** * Returns the keys that can complete a valid command given the current key queue. */ - function getCompletionKeys(request) { - return {completionKeys: generateCompletionKeys()}; + function getCompletionKeysRequest(request) { + return { name: "refreshCompletionKeys", + completionKeys: generateCompletionKeys(), + validFirstKeys: validFirstKeys + }; } /** @@ -374,6 +377,8 @@ function updateOpenTabs(tab) { openTabs[tab.id] = { url: tab.url, positionIndex: tab.index, windowId: tab.windowId }; + // Frames are recreated on refresh + delete framesForTab[tab.id]; } function handleUpdateScrollPosition(request, sender) { @@ -508,7 +513,7 @@ populateValidFirstKeys(); populateSingleKeyCommands(); - sendRequestToAllTabs({ name: "refreshCompletionKeys", completionKeys: generateCompletionKeys() }); + sendRequestToAllTabs(getCompletionKeysRequest()); } /* @@ -580,7 +585,11 @@ refreshedCompletionKeys = true; } else { - repeatFunction(this[registryEntry.command], count, 0, frameId); + if(registryEntry.passCountToFunction){ + this[registryEntry.command](count); + } else { + repeatFunction(this[registryEntry.command], count, 0, frameId); + } } newKeyQueue = ""; @@ -598,10 +607,8 @@ // If we haven't sent the completion keys piggybacked on executePageCommand, // send them by themselves. - if (!refreshedCompletionKeys) - { - var port = chrome.tabs.connect(tabId, { name: "refreshCompletionKeys" }); - port.postMessage({ completionKeys: generateCompletionKeys(newKeyQueue) }); + if (!refreshedCompletionKeys) { + chrome.tabs.sendRequest(tabId, getCompletionKeysRequest(), null); } return newKeyQueue; @@ -654,7 +661,7 @@ if (!framesForTab[sender.tab.id]) framesForTab[sender.tab.id] = { frames: [] }; - if (request.top) { + if (request.is_top) { focusedFrame = request.frameId; framesForTab[sender.tab.id].total = request.total; } @@ -687,25 +694,29 @@ focusedFrame = request.frameId; } - function nextFrame(callback, frameId) { + function nextFrame(count) { chrome.tabs.getSelected(null, function(tab) { - var index; var frames = framesForTab[tab.id].frames; + var curr_index = getCurrFrameIndex(frames); - for (index=0; index < frames.length; index++) { - if (frames[index].id == focusedFrame) - break; - } - - if (index >= frames.length-1) - index = 0; - else - index++; + // TODO: Skip the "top" frame (which doesn't actually have a <frame> tag), + // since it exists only to contain the other frames. + var new_index = (curr_index + count) % frames.length; - chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index].id, highlight: true }); + chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[new_index].id, highlight: true }); }); } + function getCurrFrameIndex(frames) { + var index; + for (index=0; index < frames.length; index++) { + if (frames[index].id == focusedFrame) + break; + } + return index; + } + + function init() { clearKeyMappingsAndSetDefaults(); |
