aboutsummaryrefslogtreecommitdiffstats
path: root/background_page.html
diff options
context:
space:
mode:
Diffstat (limited to 'background_page.html')
-rw-r--r--background_page.html95
1 files changed, 33 insertions, 62 deletions
diff --git a/background_page.html b/background_page.html
index 71208d12..706aeb1f 100644
--- a/background_page.html
+++ b/background_page.html
@@ -3,13 +3,9 @@
<script type="text/javascript" src="commands.js"></script>
<script type="text/javascript" src="lib/clipboard.js"></script>
<script type="text/javascript" src="lib/utils.js"></script>
+<script type="text/javascript" src="background/settings.js"></script>
<script type="text/javascript" charset="utf-8">
- // Chromium #15242 will make this XHR request to access the manifest unnecessary.
- var manifestRequest = new XMLHttpRequest();
- manifestRequest.open("GET", chrome.extension.getURL("manifest.json"), false);
- manifestRequest.send(null);
-
- var currentVersion = JSON.parse(manifestRequest.responseText).version;
+ var currentVersion = utils.getCurrentVersion();
var tabQueue = {}; // windowId -> Array
var openTabs = {}; // tabId -> object with various tab properties
@@ -25,36 +21,12 @@
// the string.
var namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/;
- var defaultSettings = {
- scrollStepSize: 60,
- linkHintCharacters: "sadfjklewcmpgh",
- filterLinkHints: false,
- userDefinedLinkHintCss:
- "#vimiumHintMarkerContainer .vimiumHintMarker \n/* linkhint boxes */ " +
- "{\nborder: 1px solid #AA852F;\n}\n\n" +
- "#vimiumHintMarkerContainer .vimiumHintMarker span \n/* linkhint text */ " +
- "{\nfont-weight: bold;\n}\n\n" +
- "#vimiumHintMarkerContainer .vimiumHintMarker > .matchingCharacter {\n\n}",
- excludedUrls: "http*://mail.google.com/*\n" +
- "http*://www.google.com/reader/*\n",
-
- // NOTE : If a page contains both a single angle-bracket link and a double angle-bracket link, then in
- // most cases the single bracket link will be "prev/next page" and the double bracket link will be
- // "first/last page", so we put the single bracket first in the pattern string so that it gets searched
- // for first.
-
- // "\bprev\b,\bprevious\b,\bback\b,<,←,«,≪,<<"
- previousPatterns: "prev,previous,back,<,\u2190,\xab,\u226a,<<",
- // "\bnext\b,\bmore\b,>,→,»,≫,>>"
- nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>",
- };
-
// Port handler mapping
var portHandlers = {
keyDown: handleKeyDown,
returnScrollPosition: handleReturnScrollPosition,
getCurrentTabUrl: getCurrentTabUrl,
- getSetting: getSetting,
+ settings: handleSettings,
getBookmarks: getBookmarks
};
@@ -66,6 +38,7 @@
openOptionsPageInNewTab: openOptionsPageInNewTab,
registerFrame: registerFrame,
frameFocused: handleFrameFocused,
+ focusTopFrame: focusTopFrame,
upgradeNotificationClosed: upgradeNotificationClosed,
updateScrollPosition: handleUpdateScrollPosition,
copyToClipboard: copyToClipboard,
@@ -132,7 +105,7 @@
*/
function isEnabledForUrl(request) {
// excludedUrls are stored as a series of URL expressions separated by newlines.
- var excludedUrls = getSettingFromLocalStorage("excludedUrls").split("\n");
+ var excludedUrls = settings.get("excludedUrls").split("\n");
var isEnabled = true;
for (var i = 0; i < excludedUrls.length; i++) {
// The user can add "*" to the URL which means ".*"
@@ -144,7 +117,7 @@
}
function saveHelpDialogSettings(request) {
- localStorage["helpDialog_showAdvancedCommands"] = request.showAdvancedCommands;
+ settings.set("helpDialog_showAdvancedCommands", request.showAdvancedCommands);
}
function showHelp(callback, frameId) {
@@ -170,8 +143,7 @@
showUnboundCommands, showCommandNames));
dialogHtml = dialogHtml.replace("{{version}}", currentVersion);
dialogHtml = dialogHtml.replace("{{title}}", customTitle || "Help");
- dialogHtml = dialogHtml.replace("{{showAdvancedCommands}}",
- localStorage["helpDialog_showAdvancedCommands"] == "true");
+ dialogHtml = dialogHtml.replace("{{showAdvancedCommands}}", settings.get("helpDialog_showAdvancedCommands"));
return dialogHtml;
}
@@ -259,7 +231,7 @@
* Returns the user-provided CSS overrides.
*/
function getLinkHintCss(request) {
- return { linkHintCss: (localStorage['userDefinedLinkHintCss'] || "") };
+ return { linkHintCss: (settings.get("userDefinedLinkHintCss") || "") };
}
/*
@@ -267,7 +239,7 @@
* We should now dismiss that message in all tabs.
*/
function upgradeNotificationClosed(request) {
- localStorage.previousVersion = currentVersion;
+ settings.set("previousVersion", currentVersion);
sendRequestToAllTabs({ name: "hideUpgradeNotification" });
}
@@ -281,10 +253,14 @@
/*
* Used by the content scripts to get settings from the local storage.
*/
- function getSetting(args, port) {
- var value = getSettingFromLocalStorage(args.key);
- var returnPort = chrome.tabs.connect(port.tab.id, { name: "returnSetting" });
- returnPort.postMessage({ key: args.key, value: value });
+ function handleSettings(args, port) {
+ if (args.operation == "get") {
+ var value = settings.get(args.key);
+ port.postMessage({ key: args.key, value: value });
+ }
+ else { // operation == "set"
+ settings.set(args.key, args.value);
+ }
}
function getBookmarks(args, port) {
@@ -293,17 +269,6 @@
})
}
- /*
- * Used by everyone to get settings from local storage.
- */
- function getSettingFromLocalStorage(setting) {
- if (localStorage[setting] != "" && !localStorage[setting]) {
- return defaultSettings[setting];
- } else {
- return localStorage[setting];
- }
- }
-
function getCurrentTimeInSeconds() { Math.floor((new Date()).getTime() / 1000); }
chrome.tabs.onSelectionChanged.addListener(function(tabId, selectionInfo) {
@@ -644,11 +609,11 @@
* localStorage, and false otherwise.
*/
function shouldShowUpgradeMessage() {
- // Avoid showing the upgrade notification when localStorage.previousVersion is undefined, which is the
- // case for new installs.
- if (!localStorage.previousVersion)
- localStorage.previousVersion = currentVersion;
- return compareVersions(currentVersion, localStorage.previousVersion) == 1;
+ // Avoid showing the upgrade notification when previousVersion is undefined, which is the case for new
+ // installs.
+ if (!settings.get("previousVersion"))
+ settings.set("previousVersion", currentVersion);
+ return compareVersions(currentVersion, settings.get("previousVersion")) == 1;
}
function openOptionsPageInNewTab() {
@@ -663,6 +628,7 @@
if (request.is_top) {
focusedFrame = request.frameId;
+ framesForTab[sender.tab.id].topId = request.frameId;
framesForTab[sender.tab.id].total = request.total;
}
@@ -690,6 +656,11 @@
chrome.tabs.sendRequest(tabId, { name: "focusFrame", frameId: mainFrameId, highlight: false });
}
+ function focusTopFrame(request, sender) {
+ var tabId = sender.tab.id;
+ chrome.tabs.sendRequest(tabId, { name: "focusFrame", frameId: framesForTab[tabId].topId, highlight: true });
+ }
+
function handleFrameFocused(request, sender) {
focusedFrame = request.frameId;
}
@@ -720,20 +691,20 @@
function init() {
clearKeyMappingsAndSetDefaults();
- if (localStorage["keyMappings"])
- parseCustomKeyMappings(localStorage["keyMappings"]);
+ if (settings.has("keyMappings"))
+ parseCustomKeyMappings(settings.get("keyMappings"));
// In version 1.22, we changed the mapping for "d" and "u" to be scroll page down/up instead of close
// and restore tab. For existing users, we want to preserve existing behavior for them by adding some
// custom key mappings on their behalf.
- if (localStorage.previousVersion == "1.21") {
- var customKeyMappings = localStorage["keyMappings"] || "";
+ if (settings.get("previousVersion") == "1.21") {
+ var customKeyMappings = settings.get("keyMappings") || "";
if ((keyToCommandRegistry["d"] || {}).command == "scrollPageDown")
customKeyMappings += "\nmap d removeTab";
if ((keyToCommandRegistry["u"] || {}).command == "scrollPageUp")
customKeyMappings += "\nmap u restoreTab";
if (customKeyMappings != "") {
- localStorage["keyMappings"] = customKeyMappings;
+ settings.set("keyMappings", customKeyMappings);
parseCustomKeyMappings(customKeyMappings);
}
}