From be17ec68f6038e176b8a72e674697861228dfb56 Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 9 Nov 2009 01:48:39 -0800 Subject: Implement 'gf' -- toggle view source for the current page. --- background_page.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'background_page.html') 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[''] = "scrollPageDown"; keyToCommandRegistry[''] = "scrollPageUp"; keyToCommandRegistry['r'] = 'reload'; + keyToCommandRegistry['gf'] = 'toggleViewSource'; keyToCommandRegistry['ba'] = 'goBack'; keyToCommandRegistry['H'] = 'goBack'; -- cgit v1.2.3