# HG changeset patch # User Frank-Rainer Grahl # Date 1586617414 -3600 # Parent 5ffa038aac6c21e798fee5a0e8827dd51f86259a Bug 1454408 - Replace getPref calls needing a default value with standard Services calls. Follow-up for 2.53.3. r=IanN a=IanN diff --git a/editor/ui/composer/content/editingOverlay.js b/editor/ui/composer/content/editingOverlay.js --- a/editor/ui/composer/content/editingOverlay.js +++ b/editor/ui/composer/content/editingOverlay.js @@ -261,24 +261,24 @@ function BuildRecentPagesMenu() // Current page is the "0" item in the list we save in prefs, // but we don't include it in the menu. var curUrl = StripPassword(GetDocumentUrl()); var historyCount = Services.prefs.getIntPref("editor.history.url_maximum", 10); var menuIndex = 1; for (var i = 0; i < historyCount; i++) { - var url = GetStringPref("editor.history_url_" + i); + var url = Services.prefs.getStringPref("editor.history_url_" + i, ""); // Skip over current url if (url && url != curUrl) { // Build the menu - var title = GetStringPref("editor.history_title_" + i); - var fileType = GetStringPref("editor.history_type_" + i); + var title = Services.prefs.getStringPref("editor.history_title_" + i, ""); + var fileType = Services.prefs.getStringPref("editor.history_type_" + i, ""); AppendRecentMenuitem(popup, title, url, fileType, menuIndex); menuIndex++; } } } function AppendRecentMenuitem(aPopup, aTitle, aUrl, aFileType, aIndex) { @@ -313,21 +313,21 @@ function EditorInitFileMenu() if (scheme && scheme != "file") SetElementEnabledById("menu_saveCmd", false); // Enable recent pages submenu if there are any history entries in prefs. var historyUrl = ""; if (Services.prefs.getIntPref("editor.history.url_maximum", 10)) { - historyUrl = GetStringPref("editor.history_url_0"); + historyUrl = Services.prefs.getStringPref("editor.history_url_0", ""); // See if there's more if current file is only entry in history list. if (historyUrl && historyUrl == docUrl) - historyUrl = GetStringPref("editor.history_url_1"); + historyUrl = Services.prefs.getStringPref("editor.history_url_1", ""); } SetElementEnabledById("menu_RecentFiles", historyUrl != ""); } function EditorUpdateCharsetMenu(aMenuPopup) { if (IsDocumentModified() && !IsDocumentEmpty()) { diff --git a/editor/ui/composer/content/editor.js b/editor/ui/composer/content/editor.js --- a/editor/ui/composer/content/editor.js +++ b/editor/ui/composer/content/editor.js @@ -2001,26 +2001,26 @@ function SaveRecentFilesPrefs(aTitle, aF { titleArray.push(aTitle); urlArray.push(curUrl); typeArray.push(aFileType); } for (let i = 0; i < historyCount && urlArray.length < historyCount; i++) { - let url = GetStringPref("editor.history_url_" + i); + let url = Services.prefs.getStringPref("editor.history_url_" + i, ""); // Continue if URL pref is missing because // a URL not found during loading may have been removed // Skip over current an "data" URLs if (url && url != curUrl && GetScheme(url) != "data") { - let title = GetStringPref("editor.history_title_" + i); - let fileType = GetStringPref("editor.history_type_" + i); + let title = Services.prefs.getStringPref("editor.history_title_" + i, ""); + let fileType = Services.prefs.getStringPref("editor.history_type_" + i, ""); titleArray.push(title); urlArray.push(url); typeArray.push(fileType); } } // Resave the list back to prefs in the new order for (let i = 0; i < urlArray.length; i++) diff --git a/editor/ui/composer/content/editorUtilities.js b/editor/ui/composer/content/editorUtilities.js --- a/editor/ui/composer/content/editorUtilities.js +++ b/editor/ui/composer/content/editorUtilities.js @@ -403,24 +403,16 @@ function SetElementEnabled(element, doEn /************* Services / Prefs ***************/ function GetFileProtocolHandler() { let handler = Services.io.getProtocolHandler("file"); return handler.QueryInterface(Ci.nsIFileProtocolHandler); } -function GetStringPref(name) -{ - try { - return Services.prefs.getStringPref(name); - } catch (e) {} - return ""; -} - function SetStringPref(aPrefName, aPrefValue) { try { Services.prefs.setStringPref(aPrefName, aPrefValue); } catch(e) {} } diff --git a/suite/base/content/openLocation.js b/suite/base/content/openLocation.js --- a/suite/base/content/openLocation.js +++ b/suite/base/content/openLocation.js @@ -49,17 +49,17 @@ function onLoad() gAction = "-1"; } break; default: // open web page gOpenAppList.value = Services.prefs.getIntPref("general.open_location.last_window_choice"); } - gInput.value = GetStringPref(gLastPref); + gInput.value = Services.prefs.getStringPref(gLastPref, ""); if (gInput.value) gInput.select(); // XXX should probably be done automatically doEnabling(); } function doEnabling() { diff --git a/suite/base/content/utilityOverlay.js b/suite/base/content/utilityOverlay.js --- a/suite/base/content/utilityOverlay.js +++ b/suite/base/content/utilityOverlay.js @@ -93,32 +93,32 @@ function InitProxyMenu() networkProxyWpad.removeAttribute("disabled"); networkProxySystem.removeAttribute("disabled"); } // If no proxy is configured, disable the menuitems. // Checking for proxy manual settings. var proxyManuallyConfigured = false; for (var i = 0; i < kProxyManual.length; i++) { - if (GetStringPref(kProxyManual[i]) != "") { + if (Services.prefs.getStringPref(kProxyManual[i], "") != "") { proxyManuallyConfigured = true; break; } } if (proxyManuallyConfigured && !proxyLocked) { networkProxyManual.removeAttribute("disabled"); } else { networkProxyManual.setAttribute("disabled", "true"); } //Checking for proxy PAC settings. var proxyAutoConfigured = false; - if (GetStringPref("network.proxy.autoconfig_url") != "") + if (Services.prefs.getStringPref("network.proxy.autoconfig_url", "") != "") proxyAutoConfigured = true; if (proxyAutoConfigured && !proxyLocked) { networkProxyPac.removeAttribute("disabled"); } else { networkProxyPac.setAttribute("disabled", "true"); } @@ -139,30 +139,21 @@ function setProxyTypeUI() return; var onlineTooltip = "onlineTooltip" + Services.prefs.getIntPref("network.proxy.type", 0); panel.setAttribute("tooltiptext", gUtilityBundle.getString(onlineTooltip)); } function SetStringPref(aPref, aValue) { - const nsISupportsString = Ci.nsISupportsString; try { Services.prefs.setStringPref(aPref, aValue); } catch (e) {} } -function GetStringPref(name) -{ - try { - return Services.prefs.getStringPref(name); - } catch (e) {} - return ""; -} - function GetLocalizedStringPref(aPrefName, aDefaultValue) { try { return Services.prefs.getComplexValue(aPrefName, Ci.nsIPrefLocalizedString).data; } catch (e) { Cu.reportError("Couldn't get " + aPrefName + " pref: " + e); } diff --git a/suite/browser/navigator.js b/suite/browser/navigator.js --- a/suite/browser/navigator.js +++ b/suite/browser/navigator.js @@ -918,17 +918,17 @@ function Startup() { default: uriArray = ["about:blank"]; break; case 1: uriArray = getHomePage(); break; case 2: - uriArray = [GetStringPref("browser.history.last_page_visited")]; + uriArray = [Services.prefs.getStringPref("browser.history.last_page_visited", "")]; break; } } uriToLoad = uriArray.splice(0, 1)[0]; if (uriArray.length > 0) window.setTimeout(function(arg) { for (var i in arg) gBrowser.addTab(arg[i]); }, 0, uriArray); } @@ -1745,17 +1745,17 @@ function BrowserOpenTab() { default: uriToLoad = "about:blank"; break; case 1: uriToLoad = GetLocalizedStringPref("browser.startup.homepage"); break; case 2: - uriToLoad = GetStringPref("browser.history.last_page_visited"); + uriToLoad = Services.prefs.getStringPref("browser.history.last_page_visited", ""); break; } if (!gBrowser) { var win = getTopWin(); if (win) { // If there's an open browser window, it should handle this command win.focus(); diff --git a/suite/mailnews/components/compose/content/MsgComposeCommands.js b/suite/mailnews/components/compose/content/MsgComposeCommands.js --- a/suite/mailnews/components/compose/content/MsgComposeCommands.js +++ b/suite/mailnews/components/compose/content/MsgComposeCommands.js @@ -3214,19 +3214,17 @@ function SwitchElementFocus(event) SetMsgIdentityElementFocus(); else SetMsgAddressingWidgetElementFocus(); } } function loadHTMLMsgPrefs() { - // This version of GetStringPref() comes from editorUtilities.js instead of - // utilitiesOverlay.js - var fontFace = GetStringPref("msgcompose.font_face"); + var fontFace = Services.prefs.getStringPref("msgcompose.font_face", ""); doStatefulCommand("cmd_fontFace", fontFace); var fontSize = Services.prefs.getCharPref("msgcompose.font_size", ""); if (fontSize) { EditorSetFontSize(fontSize); } var bodyElement = GetBodyElement();