Bug 1349722 - Remove nsIScriptableUnicodeConverter from feeds. r=mkmelin
authoralta88@gmail.com
Mon, 17 Apr 2017 12:05:18 -0600
changeset 21434 55b04a77e7610a1907960a9268f5e816869cddc8
parent 21433 ae3cb512e8d286c2161d44a8ac15ffffa96b9c29
child 21435 a0d1a7b5c018625c017e1640419f51f8a3bbfb6e
push id13047
push usermozilla@jorgk.com
push dateThu, 20 Apr 2017 06:22:24 +0000
treeherdercomm-central@55b04a77e761 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1349722
Bug 1349722 - Remove nsIScriptableUnicodeConverter from feeds. r=mkmelin
mailnews/extensions/newsblog/content/FeedItem.js
mailnews/extensions/newsblog/content/newsblogOverlay.js
--- a/mailnews/extensions/newsblog/content/FeedItem.js
+++ b/mailnews/extensions/newsblog/content/FeedItem.js
@@ -1,20 +1,17 @@
 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
 
 function FeedItem()
 {
   this.mDate = FeedUtils.getValidRFC5322Date();
-  this.mUnicodeConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
-                           createInstance(Ci.nsIScriptableUnicodeConverter);
-  this.mParserUtils = Cc["@mozilla.org/parserutils;1"].
-                      getService(Ci.nsIParserUtils);
+  this.mParserUtils = Cc["@mozilla.org/parserutils;1"].getService(Ci.nsIParserUtils);
 }
 
 FeedItem.prototype =
 {
   // Only for IETF Atom.
   xmlContentBase: null,
   id: null,
   feed: null,
@@ -354,20 +351,20 @@ FeedItem.prototype =
 
     FeedUtils.log.trace("FeedItem.writeToFolder: " + this.identity +
                         " is " + source.length + " characters long");
 
     // Get the folder and database storing the feed's messages and headers.
     let folder = this.feed.folder.QueryInterface(Ci.nsIMsgLocalMailFolder);
     let msgFolder = folder.QueryInterface(Ci.nsIMsgFolder);
     msgFolder.gettingNewMessages = true;
-    // Source is a unicode string, we want to save a char * string in
-    // the original charset. So convert back.
-    this.mUnicodeConverter.charset = this.characterSet;
-    let msgDBHdr = folder.addMessage(this.mUnicodeConverter.ConvertFromUnicode(source));
+    // Source is a unicode js string, as UTF-16, and we want to save a
+    // char * cpp |string| as UTF-8 bytes. The source xml doc encoding is utf8.
+    source = unescape(encodeURIComponent(source));
+    let msgDBHdr = folder.addMessage(source);
     msgDBHdr.OrFlags(Ci.nsMsgMessageFlags.FeedMsg);
     msgFolder.gettingNewMessages = false;
     this.tagItem(msgDBHdr, this.keywords);
   },
 
 /**
  * Autotag messages.
  *
--- a/mailnews/extensions/newsblog/content/newsblogOverlay.js
+++ b/mailnews/extensions/newsblog/content/newsblogOverlay.js
@@ -194,22 +194,21 @@ var FeedMessageHandler = {
    *                                  'messagepane', 'browser', 'tab', 'window'.
    */
   loadWebPage: function(aMessageHdr, aWhere) {
     MsgHdrToMimeMessage(aMessageHdr, null, function(aMsgHdr, aMimeMsg) {
       if (aMimeMsg && aMimeMsg.headers["content-base"] &&
           aMimeMsg.headers["content-base"][0]) {
         let url = aMimeMsg.headers["content-base"], uri;
         try {
-          let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
-                            .createInstance(Ci.nsIScriptableUnicodeConverter);
-          converter.charset = "UTF-8";
-          url = converter.ConvertToUnicode(url);
+          // The message and headers are stored as a string of UTF-8 bytes
+          // and we need to convert that cpp |string| to js UTF-16 explicitly
+          // for idn and non-ascii urls with this api.
+          url = decodeURIComponent(escape(url));
           uri = Services.io.newURI(url);
-          url = uri.spec;
         }
         catch (ex) {
           FeedUtils.log.info("FeedMessageHandler.loadWebPage: " +
                              "invalid Content-Base header url - " + url);
           return;
         }
         if (aWhere.browser)
           Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
@@ -348,20 +347,17 @@ function openComposeWindowForRSSArticle(
 
     try
     {
       // The feed's web page url is stored in the Content-Base header.
       MsgHdrToMimeMessage(msgHdr, null, function(aMsgHdr, aMimeMsg) {
         if (aMimeMsg && aMimeMsg.headers["content-base"] &&
             aMimeMsg.headers["content-base"][0])
         {
-          let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
-                            .createInstance(Ci.nsIScriptableUnicodeConverter);
-          converter.charset = "UTF-8";
-          let url = converter.ConvertToUnicode(aMimeMsg.headers["content-base"]);
+          let url = decodeURIComponent(escape(aMimeMsg.headers["content-base"]));
           params.composeFields.body = url;
           params.bodyIsLink = true;
           MailServices.compose.OpenComposeWindowWithParams(null, params);
         }
         else
           // No content-base url, use the summary.
           MailServices.compose.OpenComposeWindow(aMsgComposeWindow, aMsgHdr, aMessageUri,
                                                  aType, aFormat, aIdentity, aMsgWindow);