Bug 1214616 - Remove encoding conversion methods from nsPrimitiveHelpers. r=emk.
authorHenri Sivonen <hsivonen@hsivonen.fi>
Tue, 20 Oct 2015 12:06:27 +0300
changeset 303667 01a5ca4ef014d37dfaec8a8f1ed2d3631fda4ffa
parent 303666 3711cda860a1f195cb71213bfa75cd02d84aaebd
child 303668 8c5c0a783412bfae2c746bc0e36dc3966071e71b
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1214616
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1214616 - Remove encoding conversion methods from nsPrimitiveHelpers. r=emk.
widget/nsPrimitiveHelpers.cpp
widget/nsPrimitiveHelpers.h
--- a/widget/nsPrimitiveHelpers.cpp
+++ b/widget/nsPrimitiveHelpers.cpp
@@ -24,27 +24,16 @@
 #include "nsCOMPtr.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsITransferable.h"
 #include "nsIComponentManager.h"
 #include "nsLinebreakConverter.h"
 #include "nsReadableUtils.h"
 
-#include "nsIServiceManager.h"
-// unicode conversion
-#include "nsIPlatformCharset.h"
-#include "nsIUnicodeDecoder.h"
-#include "nsISaveAsCharset.h"
-#include "nsAutoPtr.h"
-#include "mozilla/Likely.h"
-#include "mozilla/dom/EncodingUtils.h"
-
-using mozilla::dom::EncodingUtils;
-
 
 //
 // CreatePrimitiveForData
 //
 // Given some data and the flavor it corresponds to, creates the appropriate
 // nsISupports* wrapper for passing across IDL boundaries. Right now, everything
 // creates a two-byte |nsISupportsString|, except for "text/plain" and native
 // platform HTML (CF_HTML on win32)
@@ -123,116 +112,16 @@ nsPrimitiveHelpers :: CreateDataFromPrim
       *aDataBuff = ToNewUnicode(data);
     }
   }
 
 }
 
 
 //
-// ConvertUnicodeToPlatformPlainText
-//
-// Given a unicode buffer (flavor text/unicode), this converts it to plain text using
-// the appropriate platform charset encoding. |inUnicodeLen| is the length of the input
-// string, not the # of bytes in the buffer. The |outPlainTextData| is null terminated,
-// but its length parameter, |outPlainTextLen|, does not reflect that.
-//
-nsresult
-nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, int32_t inUnicodeLen,
-                                                            char** outPlainTextData, int32_t* outPlainTextLen )
-{
-  if ( !outPlainTextData || !outPlainTextLen )
-    return NS_ERROR_INVALID_ARG;
-
-  // get the charset
-  nsresult rv;
-  nsCOMPtr <nsIPlatformCharset> platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
-
-  nsAutoCString platformCharset;
-  if (NS_SUCCEEDED(rv))
-    rv = platformCharsetService->GetCharset(kPlatformCharsetSel_PlainTextInClipboard, platformCharset);
-  if (NS_FAILED(rv))
-    platformCharset.AssignLiteral("ISO-8859-1");
-
-  // use transliterate to convert things like smart quotes to normal quotes for plain text
-
-  nsCOMPtr<nsISaveAsCharset> converter = do_CreateInstance("@mozilla.org/intl/saveascharset;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = converter->Init(platformCharset.get(),
-                  nsISaveAsCharset::attr_EntityAfterCharsetConv +
-                  nsISaveAsCharset::attr_FallbackQuestionMark,
-                  0);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = converter->Convert(inUnicode, outPlainTextData);
-  *outPlainTextLen = *outPlainTextData ? strlen(*outPlainTextData) : 0;
-
-  NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting unicode to plain text" );
-
-  return rv;
-} // ConvertUnicodeToPlatformPlainText
-
-
-//
-// ConvertPlatformPlainTextToUnicode
-//
-// Given a char buffer (flavor text/plaikn), this converts it to unicode using
-// the appropriate platform charset encoding. |outUnicode| is null terminated,
-// but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is
-// the length of the string in characters, not bytes.
-//
-nsresult
-nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, int32_t inTextLen,
-                                                            char16_t** outUnicode, int32_t* outUnicodeLen )
-{
-  if ( !outUnicode || !outUnicodeLen )
-    return NS_ERROR_INVALID_ARG;
-
-  // Get the appropriate unicode decoder. We're guaranteed that this won't change
-  // through the life of the app so we can cache it.
-  nsresult rv = NS_OK;
-  static nsCOMPtr<nsIUnicodeDecoder> decoder;
-  static bool hasConverter = false;
-  if ( !hasConverter ) {
-    // get the charset
-    nsAutoCString platformCharset;
-    nsCOMPtr <nsIPlatformCharset> platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv))
-      rv = platformCharsetService->GetCharset(kPlatformCharsetSel_PlainTextInClipboard, platformCharset);
-    if (NS_FAILED(rv))
-      platformCharset.AssignLiteral("windows-1252");
-
-    decoder = EncodingUtils::DecoderForEncoding(platformCharset);
-
-    hasConverter = true;
-  }
-
-  // Estimate out length and allocate the buffer based on a worst-case estimate, then do
-  // the conversion.
-  rv = decoder->GetMaxLength(inText, inTextLen, outUnicodeLen);   // |outUnicodeLen| is number of chars
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  if ( *outUnicodeLen ) {
-    *outUnicode = reinterpret_cast<char16_t*>(moz_xmalloc((*outUnicodeLen + 1) * sizeof(char16_t)));
-    if ( *outUnicode ) {
-      rv = decoder->Convert(inText, &inTextLen, *outUnicode, outUnicodeLen);
-      (*outUnicode)[*outUnicodeLen] = '\0';                   // null terminate. Convert() doesn't do it for us
-    }
-  } // if valid length
-
-  NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting plain text to unicode" );
-
-  return rv;
-} // ConvertPlatformPlainTextToUnicode
-
-
-//
 // ConvertPlatformToDOMLinebreaks
 //
 // Given some data, convert from the platform linebreaks into the LF expected by the
 // DOM. This will attempt to convert the data in place, but the buffer may still need to
 // be reallocated regardless (disposing the old buffer is taken care of internally, see
 // the note below).
 //
 // NOTE: this assumes that it can use 'free' to dispose of the old buffer.
--- a/widget/nsPrimitiveHelpers.h
+++ b/widget/nsPrimitiveHelpers.h
@@ -24,30 +24,16 @@ public:
                                          uint32_t aDataLen, nsISupports** aPrimitive ) ;
 
     // Given a nsISupports* primitive and the flavor it represents, creates a new data
     // buffer with the data in it. This data will be null terminated, but the length
     // parameter does not reflect that.
   static void CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive, 
                                          void** aDataBuff, uint32_t aDataLen ) ;
 
-    // Given a unicode buffer (flavor text/unicode), this converts it to plain text using
-    // the appropriate platform charset encoding. |inUnicodeLen| is the length of the input
-    // string, not the # of bytes in the buffer. |outPlainTextData| is null terminated, 
-    // but its length parameter, |outPlainTextLen|, does not reflect that.
-  static nsresult ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, int32_t inUnicodeLen, 
-                                                    char** outPlainTextData, int32_t* outPlainTextLen ) ;
-
-    // Given a char buffer (flavor text/plaikn), this converts it to unicode using
-    // the appropriate platform charset encoding. |outUnicode| is null terminated, 
-    // but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is
-    // the length of the string in characters, not bytes.
-  static nsresult ConvertPlatformPlainTextToUnicode ( const char* inText, int32_t inTextLen, 
-                                                    char16_t** outUnicode, int32_t* outUnicodeLen ) ;
-
 }; // class nsPrimitiveHelpers
 
 
 
 class nsLinebreakHelpers
 {
 public: