aboutsummaryrefslogtreecommitdiffstats
path: root/vimiumFrontend.js
diff options
context:
space:
mode:
authorTim Morgan2010-09-03 06:31:09 -0500
committerTim Morgan2010-09-03 17:52:51 -0500
commitb489a9e4034e35c897083f9ce97866fd837680d8 (patch)
tree9350946fe8b7147152a8c703ebfad02741913cee /vimiumFrontend.js
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.
Diffstat (limited to 'vimiumFrontend.js')
-rw-r--r--vimiumFrontend.js21
1 files changed, 10 insertions, 11 deletions
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",