aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Morgan2010-09-03 06:31:09 -0500
committerTim Morgan2010-09-03 17:52:51 -0500
commitb489a9e4034e35c897083f9ce97866fd837680d8 (patch)
tree9350946fe8b7147152a8c703ebfad02741913cee
parent12413ec1de1fc2a0fdc46c6e0ef3141d2a7193cf (diff)
downloadvimium-b489a9e4034e35c897083f9ce97866fd837680d8.tar.bz2
Basic Support for Frames
Only the focused frame will act on key commands. On some sites (such as Gmail), the main frame is already focused, so commands just work. For other sites, focusing the desired frame may be necessary, which can be done with the Tab key (not optimal) or by clicking with the mouse (even less optimal). An additional command to cycle through frames is desirable, which will likely come in a future commit.
-rw-r--r--background_page.html9
-rw-r--r--manifest.json3
-rw-r--r--vimiumFrontend.js21
3 files changed, 17 insertions, 16 deletions
diff --git a/background_page.html b/background_page.html
index 349212ef..4133a023 100644
--- a/background_page.html
+++ b/background_page.html
@@ -480,19 +480,20 @@
return {count: count, command: command};
}
- function handleKeyDown(key, port) {
+ function handleKeyDown(request, port) {
+ var key = request.keyChar;
if (key == "<ESC>") {
console.log("clearing keyQueue");
keyQueue = ""
}
else {
console.log("checking keyQueue: [", keyQueue + key, "]");
- keyQueue = checkKeyQueue(keyQueue + key, port.tab.id);
+ keyQueue = checkKeyQueue(keyQueue + key, port.tab.id, request.frameId);
console.log("new KeyQueue: " + keyQueue);
}
}
- function checkKeyQueue(keysToCheck, tabId) {
+ function checkKeyQueue(keysToCheck, tabId, frameId) {
var refreshedCompletionKeys = false;
var splitHash = splitKeyQueue(keysToCheck);
command = splitHash.command;
@@ -507,7 +508,7 @@
if (!registryEntry.isBackgroundCommand) {
var port = chrome.tabs.connect(tabId, { name: "executePageCommand" });
- port.postMessage({ command: registryEntry.command, count: count,
+ port.postMessage({ command: registryEntry.command, count: count, frameId: frameId,
completionKeys: generateCompletionKeys("") });
refreshedCompletionKeys = true;
diff --git a/manifest.json b/manifest.json
index 97966dd5..703fd069 100644
--- a/manifest.json
+++ b/manifest.json
@@ -18,7 +18,8 @@
"linkHints.js",
"vimiumFrontend.js"
],
- "run_at": "document_start"
+ "run_at": "document_start",
+ "all_frames": true
}
]
}
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index e288714a..226c7953 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -75,7 +75,7 @@ function initializePreDomReady() {
chrome.extension.onConnect.addListener(function(port, name) {
if (port.name == "executePageCommand") {
port.onMessage.addListener(function(args) {
- if (this[args.command]) {
+ if (this[args.command] && frameId == args.frameId) {
for (var i = 0; i < args.count; i++) { this[args.command].call(); }
}
@@ -135,6 +135,11 @@ function initializeWhenEnabled() {
}
/*
+ * Give this frame a unique id.
+ */
+frameId = Math.floor(Math.random()*999999999)
+
+/*
* Initialization tasks that must wait for the document to be ready.
*/
function initializeOnDomReady() {
@@ -324,10 +329,10 @@ function onKeydown(event) {
event.stopPropagation();
}
- keyPort.postMessage(keyChar);
+ keyPort.postMessage({keyChar:keyChar, frameId:frameId});
}
else if (isEscape(event)) {
- keyPort.postMessage("<ESC>");
+ keyPort.postMessage({keyChar:"<ESC>", frameId:frameId});
}
}
}
@@ -690,14 +695,8 @@ function addCssToPage(css) {
head.appendChild(style);
}
-// Prevent our content script from being run on iframes -- only allow it to run on the top level DOM "window".
-// TODO(philc): We don't want to process multiple keyhandlers etc. when embedded on a page containing IFrames.
-// This should be revisited, because sometimes we *do* want to listen inside of the currently focused iframe.
-var isIframe = (window.self != window.parent);
-if (!isIframe) {
- initializePreDomReady();
- window.addEventListener("DOMContentLoaded", initializeOnDomReady);
-}
+initializePreDomReady();
+window.addEventListener("DOMContentLoaded", initializeOnDomReady);
window.onbeforeunload = function() {
chrome.extension.sendRequest({ handler: "updateScrollPosition",