aboutsummaryrefslogtreecommitdiffstats
path: root/vimiumFrontend.js
diff options
context:
space:
mode:
authorIlya Sukhar2010-09-23 23:38:53 -0700
committerIlya Sukhar2010-09-23 23:38:53 -0700
commit0370d60be82aead007f6b0804dd5b90e6fdb1b1c (patch)
tree7e27ab136de0b1f939ddfe041a0f011503286b12 /vimiumFrontend.js
parent0d15a8fbdf78ab1a12783406bf678339882323a5 (diff)
parent64b550a4a7fa4af1d9c0996d6f66715dc479ccb5 (diff)
downloadvimium-0370d60be82aead007f6b0804dd5b90e6fdb1b1c.tar.bz2
Merge branch 'frames'
Conflicts: README.markdown background_page.html commands.js vimiumFrontend.js
Diffstat (limited to 'vimiumFrontend.js')
-rw-r--r--vimiumFrontend.js68
1 files changed, 52 insertions, 16 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index 334e3a77..3b73144a 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -26,6 +26,11 @@ var linkHintCss;
// TODO(philc): This should be pulled from the extension's storage when the page loads.
var currentZoomLevel = 100;
+/*
+ * Give this frame a unique id.
+ */
+frameId = Math.floor(Math.random()*999999999)
+
var hasModifiersRegex = /^<([amc]-)+.>/;
function getSetting(key) {
@@ -66,7 +71,10 @@ function initializePreDomReady() {
if (isShowingHelpDialog)
hideHelpDialog();
else
- showHelpDialog(request.dialogHtml);
+ showHelpDialog(request.dialogHtml, request.frameId);
+ else if (request.name == "focusFrame")
+ if(frameId == request.frameId)
+ focusThisFrame(request.highlight);
else if (request.name == "refreshCompletionKeys")
refreshCompletionKeys(request.completionKeys);
sendResponse({}); // Free up the resources used by this open connection.
@@ -75,7 +83,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) {
if (args.passCountToFunction) {
this[args.command].call(null, args.count);
} else {
@@ -138,10 +146,35 @@ function initializeWhenEnabled() {
enterInsertModeIfElementIsFocused();
}
+
+/*
+ * The backend needs to know which frame has focus.
+ */
+window.addEventListener("focus", function(e){
+ chrome.extension.sendRequest({handler: "frameFocused", frameId: frameId});
+});
+
+/*
+ * Called from the backend in order to change frame focus.
+ */
+function focusThisFrame(shouldHighlight) {
+ window.focus();
+ if (document.body && shouldHighlight) {
+ var borderWas = document.body.style.border;
+ document.body.style.border = '5px solid yellow';
+ setTimeout(function(){document.body.style.border = borderWas}, 200);
+ }
+}
+
/*
* Initialization tasks that must wait for the document to be ready.
*/
function initializeOnDomReady() {
+ if (window.top == window.self)
+ chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, top: true, total: frames.length });
+ else
+ registerFrameIfSizeAvailable();
+
if (isEnabledForUrl)
enterInsertModeIfElementIsFocused();
@@ -149,6 +182,14 @@ function initializeOnDomReady() {
chrome.extension.connect({ name: "domReady" });
};
+// This is a little hacky but sometimes the size wasn't available on domReady?
+function registerFrameIfSizeAvailable () {
+ if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0)
+ chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, area: innerWidth * innerHeight });
+ else
+ setTimeout(registerFrameIfSizeAvailable, 100);
+}
+
/*
* Checks the currently focused element of the document and will enter insert mode if that element is focusable.
*/
@@ -257,9 +298,10 @@ function copyCurrentUrl() {
function toggleViewSourceCallback(url) {
if (url.substr(0, 12) == "view-source:")
{
- window.location.href = url.substr(12, url.length - 12);
+ url = url.substr(12, url.length - 12);
}
- else { window.location.href = "view-source:" + url; }
+ else { url = "view-source:" + url; }
+ chrome.extension.sendRequest({handler: "openUrlInCurrentTab", url:url});
}
/**
@@ -348,10 +390,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});
}
}
}
@@ -493,8 +535,8 @@ function exitFindMode() {
HUD.hide();
}
-function showHelpDialog(html) {
- if (isShowingHelpDialog || !document.body)
+function showHelpDialog(html, fid) {
+ if (isShowingHelpDialog || !document.body || fid != frameId)
return;
isShowingHelpDialog = true;
var container = document.createElement("div");
@@ -715,14 +757,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",