Bug 1440490 - Move l10n related functions into calL10NUtils.jsm - part 6 - migrate WCAP provider. r=MakeMyDay
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 22 Feb 2018 09:24:01 +0100
changeset 31384 2d043b6dc896494dbef7661f36497151cecb6f51
parent 31383 3e0fec7cfb1b94b6707a96d749338e072e5e93be
child 31385 b2648949aedf65d20f4ef5b641dd25ccbc004b62
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersMakeMyDay
bugs1440490
Bug 1440490 - Move l10n related functions into calL10NUtils.jsm - part 6 - migrate WCAP provider. r=MakeMyDay MozReview-Commit-ID: Dfy77g1G3Sz
calendar/providers/wcap/calWcapCalendarModule.js
calendar/providers/wcap/calWcapErrors.js
calendar/providers/wcap/calWcapSession.js
calendar/providers/wcap/calWcapUtils.js
--- a/calendar/providers/wcap/calWcapCalendarModule.js
+++ b/calendar/providers/wcap/calWcapCalendarModule.js
@@ -49,19 +49,19 @@ var CACHE_LAST_RESULTS_INVALIDATE = 120;
 // logging:
 var LOG_LEVEL = 0;
 
 function initWcapProvider() {
     try {
         initLogging();
 
         // some string resources:
-        g_privateItemTitle = cal.calGetString("wcap", "privateItem.title.text");
-        g_confidentialItemTitle = cal.calGetString("wcap", "confidentialItem.title.text");
-        g_busyItemTitle = cal.calGetString("wcap", "busyItem.title.text");
+        g_privateItemTitle = getWcapString("privateItem.title.text");
+        g_confidentialItemTitle = getWcapString("confidentialItem.title.text");
+        g_busyItemTitle = getWcapString("busyItem.title.text");
         g_busyPhantomItemUuidPrefix = "PHANTOM_uuid_" + cal.getUUID();
 
         CACHE_LAST_RESULTS = Preferences.get("calendar.wcap.cache_last_results", 4);
         CACHE_LAST_RESULTS_INVALIDATE = Preferences.get("calendar.wcap.cache_last_results_invalidate", 120);
     } catch (exc) {
         logError(exc, "error in init sequence");
     }
 }
--- a/calendar/providers/wcap/calWcapErrors.js
+++ b/calendar/providers/wcap/calWcapErrors.js
@@ -123,17 +123,17 @@ function netErrorToString(rc) {
 
 //
 // WCAP error handling helpers
 //
 
 var g_wcapErrorCodes = [
     /* -1 */ NS_OK, "Logout successful.",
     /*  0 */ NS_OK, "Command successful.",
-    /*  1 */ calIWcapErrors.WCAP_LOGIN_FAILED, cal.calGetString("wcap", "loginFailed.text"),
+    /*  1 */ calIWcapErrors.WCAP_LOGIN_FAILED, getWcapString("loginFailed.text"),
     /*  2 */ calIWcapErrors.WCAP_LOGIN_OK_DEFAULT_CALENDAR_NOT_FOUND, "login.wcap was successful, but the default calendar for this user was not found. A new default calendar set to the userid was created.",
     /*  3 */ NS_ERROR_INVALID_ARG, "No WCAP error code.",
     /*  4 */ NS_ERROR_INVALID_ARG, "No WCAP error code.",
     /*  5 */ NS_ERROR_INVALID_ARG, "No WCAP error code.",
     /*  6 */ calIWcapErrors.WCAP_DELETE_EVENTS_BY_ID_FAILED, "WCAP_DELETE_EVENTS_BY_ID_FAILED",
     /*  7 */ NS_ERROR_INVALID_ARG, "No WCAP error code.",
     /*  8 */ calIWcapErrors.WCAP_SETCALPROPS_FAILED, "WCAP_SETCALPROPS_FAILED",
     /*  9 */ calIWcapErrors.WCAP_FETCH_EVENTS_BY_ID_FAILED, "WCAP_FETCH_EVENTS_BY_ID_FAILED",
@@ -150,17 +150,17 @@ var g_wcapErrorCodes = [
     /* 20 */ calIWcapErrors.WCAP_GET_CALPROPS_FAILED, "WCAP_GET_CALPROPS_FAILED",
     /* 21 */ calIWcapErrors.WCAP_DELETECOMPONENTS_BY_RANGE_FAILED, "WCAP_DELETECOMPONENTS_BY_RANGE_FAILED",
     /* 22 */ calIWcapErrors.WCAP_DELETEEVENTS_BY_RANGE_FAILED, "WCAP_DELETEEVENTS_BY_RANGE_FAILED",
     /* 23 */ calIWcapErrors.WCAP_DELETETODOS_BY_RANGE_FAILED, "WCAP_DELETETODOS_BY_RANGE_FAILED",
     /* 24 */ calIWcapErrors.WCAP_GET_ALL_TIMEZONES_FAILED, "WCAP_GET_ALL_TIMEZONES_FAILED",
     /* 25 */ calIWcapErrors.WCAP_CREATECALENDAR_ALREADY_EXISTS_FAILED, "The command createcalendar.wcap failed. A calendar with that name already exists in the database.",
     /* 26 */ calIWcapErrors.WCAP_SET_USERPREFS_FAILED, "WCAP_SET_USERPREFS_FAILED",
     /* 27 */ calIWcapErrors.WCAP_CHANGE_PASSWORD_FAILED, "WCAP_CHANGE_PASSWORD_FAILED",
-    /* 28 */ calIWcapErrors.WCAP_ACCESS_DENIED_TO_CALENDAR, cal.calGetString("wcap", "accessDenied.text"),
+    /* 28 */ calIWcapErrors.WCAP_ACCESS_DENIED_TO_CALENDAR, getWcapString("accessDenied.text"),
     /* 29 */ calIWcapErrors.WCAP_CALENDAR_DOES_NOT_EXIST, "Command failed. The requested calendar does not exist in the database.",
     /* 30 */ calIWcapErrors.WCAP_ILLEGAL_CALID_NAME, "createcalendar.wcap failed. Invalid calid passed in.",
     /* 31 */ calIWcapErrors.WCAP_CANNOT_MODIFY_LINKED_EVENTS, "storeevents.wcap failed. The event to modify was a linked event.",
     /* 32 */ calIWcapErrors.WCAP_CANNOT_MODIFY_LINKED_TODOS, "storetodos.wcap failed. The todo to modify was a linked todo.",
     /* 33 */ calIWcapErrors.WCAP_CANNOT_SENT_EMAIL, "Command failed. Email notification failed. Usually caused by the server not being properly configured to send email. This can occur in storeevents.wcap, storetodos.wcap, deleteevents_by_id.wcap, deletetodos_by_id.wcap.",
     /* 34 */ calIWcapErrors.WCAP_CALENDAR_DISABLED, "Command failed. The calendar is disabled in the database.",
     /* 35 */ calIWcapErrors.WCAP_WRITE_IMPORT_FAILED, "Import failed when writing files to the server.",
     /* 36 */ calIWcapErrors.WCAP_FETCH_BY_LAST_MODIFIED_FAILED, "WCAP_FETCH_BY_LAST_MODIFIED_FAILED",
--- a/calendar/providers/wcap/calWcapSession.js
+++ b/calendar/providers/wcap/calWcapSession.js
@@ -278,17 +278,17 @@ calWcapSession.prototype = {
                 if (outUser.value && !outPW.value) { // lookup pw manager
                     log("looking in pw db for: " + this.uri.spec, this);
                     cal.auth.passwordManagerGet(outUser.value, outPW, this.uri.spec, "wcap login");
                 }
 
                 let promptAndLoginLoop_resp = (loginerr, sessionId) => {
                     if (checkErrorCode(loginerr, calIWcapErrors.WCAP_LOGIN_FAILED)) {
                         log("prompting for [user/]pw...", this);
-                        if (cal.auth.getCredentials(cal.calGetString("wcap", "loginDialog.label"),
+                        if (cal.auth.getCredentials(getWcapString("loginDialog.label"),
                                                     this.sessionUri.hostPort,
                                                     outUser,
                                                     outPW,
                                                     outSavePW,
                                                     this.credentials.userId != null)) {
                             this.login(request, promptAndLoginLoop_resp,
                                        outUser.value, outPW.value);
                         } else {
@@ -347,18 +347,18 @@ calWcapSession.prototype = {
                     }
                     log("login succeeded: " + sessionId, this);
                 } catch (exc) {
                     err = exc;
                     if (checkErrorCode(err, calIWcapErrors.WCAP_LOGIN_FAILED)) {
                         log("error: " + errorToString(exc), this); // log login failure
                     } else if (getErrorModule(err) == NS_ERROR_MODULE_NETWORK) {
                         // server seems unavailable:
-                        err = new Components.Exception(cal.calGetString("wcap", "accessingServerFailedError.text",
-                                                                        [this.sessionUri.hostPort]), exc);
+                        err = new Components.Exception(getWcapString("accessingServerFailedError.text",
+                                                                     [this.sessionUri.hostPort]), exc);
                     }
                 }
                 respFunc(err, sessionId);
             },
             this.sessionUri.spec + "login.wcap?fmt-out=text%2Fcalendar&user=" +
             encodeURIComponent(user) + "&password=" + encodeURIComponent(password),
             false /* no logging */);
     },
@@ -421,18 +421,18 @@ calWcapSession.prototype = {
                         }
                     }
                     if (err) {
                         if (checkErrorCode(err, calIErrors.OPERATION_CANCELLED)) {
                             throw err;
                         } else {
                             // soft error; request denied etc.
                             // map into localized message:
-                            throw new Components.Exception(cal.calGetString("wcap", "accessingServerFailedError.text",
-                                                                            [this.sessionUri.hostPort]),
+                            throw new Components.Exception(getWcapString("accessingServerFailedError.text",
+                                                                         [this.sessionUri.hostPort]),
                                                            calIWcapErrors.WCAP_LOGIN_FAILED);
                         }
                     }
                     let prop = icalRootComp.getFirstProperty("X-NSCP-WCAPVERSION");
                     if (!prop) {
                         throw new Components.Exception("missing X-NSCP-WCAPVERSION!");
                     }
                     let wcapVersion = parseInt(prop.value, 10);
@@ -441,19 +441,19 @@ calWcapSession.prototype = {
                         let vars = [this.sessionUri.hostPort];
                         prop = icalRootComp.getFirstProperty("PRODID");
                         vars.push(prop ? prop.value : "<unknown>");
                         prop = icalRootComp.getFirstProperty("X-NSCP-SERVERVERSION");
                         vars.push(prop ? prop.value : "<unknown>");
                         vars.push(strVers);
 
                         let prompt = Services.ww.getNewPrompter(null);
-                        let labelText = cal.calGetString("wcap", "insufficientWcapVersionConfirmation.label");
+                        let labelText = getWcapString("insufficientWcapVersionConfirmation.label");
                         if (!prompt.confirm(labelText,
-                                            cal.calGetString("wcap", "insufficientWcapVersionConfirmation.text", vars))) {
+                                            getWcapString("insufficientWcapVersionConfirmation.text", vars))) {
                             throw new Components.Exception(labelText, calIWcapErrors.WCAP_LOGIN_FAILED);
                         }
                     }
                 } catch (exc) {
                     err = exc;
                 }
                 respFunc(err);
             },
@@ -1108,19 +1108,19 @@ function confirmInsecureLogin(uri) {
     let encodedHost = encodeURIComponent(host);
     let confirmedEntry = confirmInsecureLogin.m_confirmedHttpLogins[encodedHost];
     if (confirmedEntry) {
         bConfirmed = (confirmedEntry == "1");
     } else {
         let prompt = Services.ww.getNewPrompter(null);
         let out_dontAskAgain = { value: false };
         bConfirmed = prompt.confirmCheck(
-            cal.calGetString("wcap", "noHttpsConfirmation.label"),
-            cal.calGetString("wcap", "noHttpsConfirmation.text", [host]),
-            cal.calGetString("wcap", "noHttpsConfirmation.check.text"),
+            getWcapString("noHttpsConfirmation.label"),
+            getWcapString("noHttpsConfirmation.text", [host]),
+            getWcapString("noHttpsConfirmation.check.text"),
             out_dontAskAgain);
 
         if (out_dontAskAgain.value) {
             // save decision for all running calendars and
             // all future confirmations:
             let newConfirmedLogins = getPref("calendar.wcap.confirmed_http_logins", "");
             if (newConfirmedLogins.length > 0) {
                 newConfirmedLogins += ",";
--- a/calendar/providers/wcap/calWcapUtils.js
+++ b/calendar/providers/wcap/calWcapUtils.js
@@ -1,14 +1,14 @@
 /* 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/. */
 
 /* exported getCalendarSearchService, getDomParser, isParent, filterXmlNodes,
- *          getIcalUTC, getDatetimeFromIcalProp
+ *          getIcalUTC, getDatetimeFromIcalProp, getWcapString
  */
 
 ChromeUtils.import("resource://calendar/modules/calIteratorUtils.jsm");
 ChromeUtils.import("resource://calendar/modules/calUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 
 var g_bShutdown = false;
@@ -213,8 +213,12 @@ function getDatetimeFromIcalProp(prop) {
     return getDatetimeFromIcalString(prop.valueAsIcalString);
 }
 
 function getPref(prefName, defaultValue) {
     let ret = Preferences.get(prefName, defaultValue);
     log(ret, "getPref(): prefName=" + prefName);
     return ret;
 }
+
+function getWcapString(aStringName, aParams) {
+    return cal.l10n.getString("wcap", aStringName, aParams);
+}