Bug 1412893 - Change instances of using getService to Services.jsm where possible in toolkit/components/printing. r?Mossop
MozReview-Commit-ID: 6g26rPnSN1r
--- a/toolkit/components/printing/content/printPageSetup.js
+++ b/toolkit/components/printing/content/printPageSetup.js
@@ -1,17 +1,20 @@
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
var gDialog;
var paramBlock;
-var gPrefs = null;
var gPrintService = null;
var gPrintSettings = null;
var gStringBundle = null;
var gDoingMetric = false;
var gPrintSettingsInterface = Components.interfaces.nsIPrintSettings;
var gDoDebug = false;
@@ -58,17 +61,18 @@ function initDialog() {
gDialog.strings["marginUnits.metric"] = document.getElementById("marginUnits.metric").childNodes[0].nodeValue;
gDialog.strings["customPrompt.title"] = document.getElementById("customPrompt.title").childNodes[0].nodeValue;
gDialog.strings["customPrompt.prompt"] = document.getElementById("customPrompt.prompt").childNodes[0].nodeValue;
}
// ---------------------------------------------------
function isListOfPrinterFeaturesAvailable() {
- return gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures", false);
+ return Services.prefs.getBoolPref("print.tmp.printerfeatures." +
+ gPrintSettings.printerName + ".has_special_printerfeatures", false);
}
// ---------------------------------------------------
function checkDouble(element) {
element.value = element.value.replace(/[^.0-9]/g, "");
}
// Theoretical paper width/height.
@@ -138,22 +142,20 @@ function changeMargins() {
changeMargin( gDialog.leftInput );
changeMargin( gDialog.rightInput );
}
// ---------------------------------------------------
function customize( node ) {
// If selection is now "Custom..." then prompt user for custom setting.
if ( node.value == 6 ) {
- var prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService( Components.interfaces.nsIPromptService );
var title = gDialog.strings["customPrompt.title"];
var promptText = gDialog.strings["customPrompt.prompt"];
var result = { value: node.custom };
- var ok = prompter.prompt(window, title, promptText, result, null, { value: false } );
+ var ok = Services.prompt.prompt(window, title, promptText, result, null, { value: false } );
if ( ok ) {
node.custom = result.value;
}
}
}
// ---------------------------------------------------
function setHeaderFooter( node, value ) {
@@ -231,18 +233,16 @@ function setPrinterDefaultsForSelectedPr
function loadDialog() {
var print_orientation = 0;
var print_margin_top = 0.5;
var print_margin_left = 0.5;
var print_margin_bottom = 0.5;
var print_margin_right = 0.5;
try {
- gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
-
gPrintService = Components.classes["@mozilla.org/gfx/printsettings-service;1"];
if (gPrintService) {
gPrintService = gPrintService.getService();
if (gPrintService) {
gPrintService = gPrintService.QueryInterface(Components.interfaces.nsIPrintSettingsService);
}
}
} catch (ex) {
@@ -310,17 +310,17 @@ function loadDialog() {
setHeaderFooter( gDialog.fCenterOption, gPrintSettings.footerStrCenter );
setHeaderFooter( gDialog.fRightOption, gPrintSettings.footerStrRight );
gDialog.scalingInput.value = (gPrintSettings.scaling * 100).toFixed(0);
// Enable/disable widgets based in the information whether the selected
// printer supports the matching feature or not
if (isListOfPrinterFeaturesAvailable()) {
- if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_orientation"))
+ if (Services.prefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_orientation"))
gDialog.orientation.removeAttribute("disabled");
else
gDialog.orientation.setAttribute("disabled", "true");
}
// Give initial focus to the orientation radio group.
// Done on a timeout due to to bug 103197.
setTimeout( function() { gDialog.orientation.focus(); }, 0 );
--- a/toolkit/components/printing/content/printPreviewBindings.xml
+++ b/toolkit/components/printing/content/printPreviewBindings.xml
@@ -287,21 +287,21 @@
</body>
</method>
<method name="promptForScaleValue">
<parameter name="aValue"/>
<body>
<![CDATA[
var value = Math.round(aValue);
- var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var promptStr = this.mScaleLabel.value;
var renameTitle = this.mCustomTitle;
var result = {value};
- var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value});
+ let {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
+ var confirmed = Services.prompt.prompt(window, renameTitle, promptStr, result, null, {value});
if (!confirmed || (!result.value) || (result.value == "")) {
return -1;
}
return result.value;
]]>
</body>
</method>
--- a/toolkit/components/printing/content/printProgress.js
+++ b/toolkit/components/printing/content/printProgress.js
@@ -1,14 +1,18 @@
// -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
// dialog is just an array we'll use to store various properties from the dialog document...
var dialog;
// the printProgress is a nsIPrintProgress object
var printProgress = null;
// random global variables...
var targetFile;
@@ -52,19 +56,17 @@ var progressListener = {
// Put progress meter at 100%.
dialog.progress.setAttribute( "value", 100 );
dialog.progress.setAttribute( "mode", "normal" );
var percentPrint = getString( "progressText" );
percentPrint = replaceInsert( percentPrint, 1, 100 );
dialog.progressText.setAttribute("value", percentPrint);
- var fm = Components.classes["@mozilla.org/focus-manager;1"]
- .getService(Components.interfaces.nsIFocusManager);
- if (fm && fm.activeWindow == window) {
+ if (Services.focus.activeWindow == window) {
// This progress dialog is the currently active window. In
// this case we need to make sure that some other window
// gets focus before we close this dialog to work around the
// buggy Windows XP Fax dialog, which ends up parenting
// itself to the currently focused window and is unable to
// survive that window going away. What happens without this
// opener.focus() call on Windows XP is that the fax dialog
// is opened only to go away when this dialog actually
--- a/toolkit/components/printing/content/printUtils.js
+++ b/toolkit/components/printing/content/printUtils.js
@@ -67,20 +67,18 @@ var gSavePrintSettings = false;
var gFocusedElement = null;
var PrintUtils = {
init() {
window.messageManager.addMessageListener("Printing:Error", this);
},
get bundle() {
- let stringService = Components.classes["@mozilla.org/intl/stringbundle;1"]
- .getService(Components.interfaces.nsIStringBundleService);
delete this.bundle;
- return this.bundle = stringService.createBundle("chrome://global/locale/printing.properties");
+ return this.bundle = Services.strings.createBundle("chrome://global/locale/printing.properties");
},
/**
* Shows the page setup dialog, and saves any settings changed in
* that dialog if print.save_print_settings is set to true.
*
* @return true on success, false on failure
*/
@@ -397,19 +395,17 @@ var PrintUtils = {
if (!msg) {
msg = this.bundle.GetStringFromName(msgName);
}
title = this.bundle.GetStringFromName(isPrinting ? "print_error_dialog_title"
: "printpreview_error_dialog_title");
- let promptSvc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- promptSvc.alert(window, title, msg);
+ Services.prompt.alert(window, title, msg);
},
receiveMessage(aMessage) {
if (aMessage.name == "Printing:Error") {
this.displayPrintingError(aMessage.data.nsresult,
aMessage.data.isPrinting);
return undefined;
}
@@ -465,22 +461,18 @@ var PrintUtils = {
// First get any defaults from the printer
aPSSVC.initPrintSettingsFromPrinter(aPrintSettings.printerName, aPrintSettings);
// now augment them with any values from last time
aPSSVC.initPrintSettingsFromPrefs(aPrintSettings, true, aPrintSettings.kInitSaveAll);
},
getPrintSettings() {
- var pref = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- if (pref) {
- gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings");
- gSavePrintSettings = pref.getBoolPref("print.save_print_settings");
- }
+ gPrintSettingsAreGlobal = Services.prefs.getBoolPref("print.use_global_printsettings");
+ gSavePrintSettings = Services.prefs.getBoolPref("print.save_print_settings");
var printSettings;
try {
var PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
if (gPrintSettingsAreGlobal) {
printSettings = PSSVC.globalPrintSettings;
this.setPrinterDefaultsForSelectedPrinter(PSSVC, printSettings);
@@ -709,20 +701,18 @@ var PrintUtils = {
document.documentElement.setAttribute("onclose", this._closeHandlerPP);
this._closeHandlerPP = null;
// remove the print preview toolbar
let printPreviewTB = document.getElementById("print-preview-toolbar");
printPreviewTB.destroy();
printPreviewTB.remove();
- let fm = Components.classes["@mozilla.org/focus-manager;1"]
- .getService(Components.interfaces.nsIFocusManager);
if (gFocusedElement)
- fm.setFocus(gFocusedElement, fm.FLAG_NOSCROLL);
+ Services.focus.setFocus(gFocusedElement, Services.focus.FLAG_NOSCROLL);
else
this._sourceBrowser.focus();
gFocusedElement = null;
this.setSimplifiedMode(false);
this.ensureProgressDialogClosed();