aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_page.html15
-rw-r--r--vimiumFrontend.js20
2 files changed, 34 insertions, 1 deletions
diff --git a/background_page.html b/background_page.html
index d15c3331..df63632a 100644
--- a/background_page.html
+++ b/background_page.html
@@ -6,7 +6,8 @@
// Port handler mapping
var portHandlers = { "keyDown": handleKeyDown,
- "returnScrollPosition": handleReturnScrollPosition };
+ "returnScrollPosition": handleReturnScrollPosition,
+ "getCurrentTabUrl": getCurrentTabUrl };
// Event handlers
var selectionChangedHandlers = [];
@@ -38,6 +39,17 @@
}
}
+ /*
+ * 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:".
+ */
+ function getCurrentTabUrl(args) {
+ chrome.tabs.getSelected(null, function (tab) {
+ var returnPort = chrome.tabs.connect(tab.id, { name: "returnCurrentTabUrl" });
+ returnPort.postMessage({ url: tab.url });
+ });
+ }
+
chrome.tabs.onSelectionChanged.addListener(function (tabId, selectionInfo) {
if (selectionChangedHandlers.length > 0) { selectionChangedHandlers.pop().call(); }
});
@@ -138,6 +150,7 @@
keyToCommandRegistry['<c-d>'] = "scrollPageDown";
keyToCommandRegistry['<c-u>'] = "scrollPageUp";
keyToCommandRegistry['r'] = 'reload';
+ keyToCommandRegistry['gf'] = 'toggleViewSource';
keyToCommandRegistry['ba'] = 'goBack';
keyToCommandRegistry['H'] = 'goBack';
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index f9a42d75..11a4d701 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -1,4 +1,5 @@
var SCROLL_STEP_SIZE = 60; // Pixels
+var getCurrentUrlHandlers = []; // function (url)
document.addEventListener("keydown", onKeydown);
document.addEventListener("focus", onFocusCapturePhase, true);
@@ -22,6 +23,21 @@ function reload() { window.location.reload(); }
function goBack() { history.back(); }
function goForward() { history.forward(); }
+function toggleViewSource() {
+ getCurrentUrlHandlers.push(toggleViewSourceCallback);
+
+ var getCurrentUrlPort = chrome.extension.connect({ name: "getCurrentTabUrl" });
+ getCurrentUrlPort.postMessage({});
+}
+
+function toggleViewSourceCallback(url) {
+ if (url.substr(0, 12) == "view-source:")
+ {
+ window.location.href = url.substr(12, url.length - 12);
+ }
+ else { window.location.href = "view-source:" + url; }
+}
+
chrome.extension.onConnect.addListener(function (port, name) {
if (port.name == "executePageCommand") {
port.onMessage.addListener(function (args) {
@@ -44,6 +60,10 @@ chrome.extension.onConnect.addListener(function (port, name) {
port.onMessage.addListener(function (args) {
if (args.scrollX > 0 || args.scrollY > 0) { window.scrollBy(args.scrollX, args.scrollY); }
});
+ } else if (port.name == "returnCurrentTabUrl") {
+ port.onMessage.addListener(function (args) {
+ if (getCurrentUrlHandlers.length > 0) { getCurrentUrlHandlers.pop()(args.url); }
+ });
}
});