Bug 661876: Remove obsolete nsIDOMFile methods/properties. r=sicking
authorKyle Huey <khuey@kylehuey.com>
Sun, 05 Jun 2011 11:54:50 -0700
changeset 70572 1dec937dfbb64510d1acd48badfed563840c946d
parent 70571 64dd0ffff3f20f2ec4a8c7b0c0734d9cb274d046
child 70573 52b9e864be0eec472a1a450c95306f037e931beb
push id20361
push userkhuey@mozilla.com
push dateSun, 05 Jun 2011 19:10:49 +0000
treeherdermozilla-central@52b9e864be0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs661876
milestone7.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 661876: Remove obsolete nsIDOMFile methods/properties. r=sicking
content/base/public/nsDOMFile.h
content/base/public/nsIDOMFile.idl
content/base/src/nsDOMFile.cpp
--- a/content/base/public/nsDOMFile.h
+++ b/content/base/public/nsDOMFile.h
@@ -59,17 +59,16 @@ class nsIInputStream;
 class nsIClassInfo;
 class nsIBlobBuilder;
 
 nsresult NS_NewBlobBuilder(nsISupports* *aSupports);
 void ParseSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd);
 
 class nsDOMFile : public nsIDOMFile,
                   public nsIXHRSendable,
-                  public nsICharsetDetectionObserver,
                   public nsIJSNativeInitializer
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMBLOB
   NS_DECL_NSIDOMFILE
   NS_DECL_NSIXHRSENDABLE
 
@@ -95,19 +94,16 @@ public:
   {
     NS_ASSERTION(mFile, "must have file");
     // Ensure non-null mContentType
     mContentType.SetIsVoid(PR_FALSE);
   }
 
   virtual ~nsDOMFile() {}
 
-  // from nsICharsetDetectionObserver
-  NS_IMETHOD Notify(const char *aCharset, nsDetectionConfident aConf);
-
   // nsIJSNativeInitializer
   NS_IMETHOD Initialize(nsISupports* aOwner,
                         JSContext* aCx,
                         JSObject* aObj,
                         PRUint32 aArgc,
                         jsval* aArgv);
 
   // DOMClassInfo constructor (for File("foo"))
@@ -119,23 +115,16 @@ protected:
 
   // start and length in 
   PRUint64 mStart;
   PRUint64 mLength;
 
   nsString mContentType;
   
   bool mIsFullFile;
-
-  // Used during charset detection
-  nsCString mCharset;
-  nsresult GuessCharset(nsIInputStream *aStream,
-                        nsACString &aCharset);
-  nsresult ConvertStream(nsIInputStream *aStream, const char *aCharset,
-                         nsAString &aResult);
 };
 
 class nsDOMMemoryFile : public nsDOMFile
 {
 public:
   nsDOMMemoryFile(void *aMemoryBuffer,
                   PRUint64 aLength,
                   const nsAString& aName,
--- a/content/base/public/nsIDOMFile.idl
+++ b/content/base/public/nsIDOMFile.idl
@@ -58,32 +58,24 @@ interface nsIDOMBlob : nsISupports
   // moz-filedata: protocol handler
   [noscript] DOMString getInternalUrl(in nsIPrincipal principal);
 
   [optional_argc] nsIDOMBlob mozSlice(in long long start,
                                       [optional] in long long end,
                                       [optional] in DOMString contentType);
 };
 
-[scriptable, uuid(91c9ebd9-2a4a-4a38-9412-ef492a2799be)]
+[scriptable, uuid(b096ef67-7b77-47f8-8e70-5d8ee36416bf)]
 interface nsIDOMFile : nsIDOMBlob
 {
   readonly attribute DOMString name;
   readonly attribute DOMString mozFullPath;
 
   // This performs no security checks!
   [noscript] readonly attribute DOMString mozFullPathInternal;
-
-  // These are all deprecated and not in spec. Will be removed in a future
-  // release
-  readonly attribute DOMString fileName;
-  readonly attribute unsigned long long fileSize;
-  DOMString getAsText(in DOMString encoding); // raises(FileException) on retrieval
-  DOMString getAsDataURL();             // raises(FileException) on retrieval
-  DOMString getAsBinary();              // raises(FileException) on retrieval
 };
 
 [scriptable, uuid(c4a77171-039b-4f84-97f9-820fb51626af)]
 interface nsIDOMMozBlobBuilder : nsISupports
 {
   nsIDOMBlob getBlob([optional] in DOMString contentType);
   [implicit_jscontext] void append(in jsval data);
 };
--- a/content/base/src/nsDOMFile.cpp
+++ b/content/base/src/nsDOMFile.cpp
@@ -137,17 +137,16 @@ nsresult DataOwnerAdapter::Create(DataOw
 DOMCI_DATA(File, nsDOMFile)
 DOMCI_DATA(Blob, nsDOMFile)
 
 NS_INTERFACE_MAP_BEGIN(nsDOMFile)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile)
   NS_INTERFACE_MAP_ENTRY(nsIDOMBlob)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFile, mIsFullFile)
   NS_INTERFACE_MAP_ENTRY(nsIXHRSendable)
-  NS_INTERFACE_MAP_ENTRY(nsICharsetDetectionObserver)
   NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(File, mIsFullFile)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(Blob, !mIsFullFile)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF(nsDOMFile)
 NS_IMPL_RELEASE(nsDOMFile)
 
@@ -169,28 +168,16 @@ DOMFileResult(nsresult rv)
 nsDOMFile::NewFile(nsISupports* *aNewObject)
 {
   nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMFile(nsnull));
   file.forget(aNewObject);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMFile::GetFileName(nsAString &aFileName)
-{
-  return GetName(aFileName);
-}
-
-NS_IMETHODIMP
-nsDOMFile::GetFileSize(PRUint64 *aFileSize)
-{
-  return GetSize(aFileSize);
-}
-
-NS_IMETHODIMP
 nsDOMFile::GetName(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFullFile, "Should only be called on files");
   return mFile->GetLeafName(aFileName);
 }
 
 NS_IMETHODIMP
 nsDOMFile::GetMozFullPath(nsAString &aFileName)
@@ -354,241 +341,16 @@ nsDOMFile::GetInternalUrl(nsIPrincipal* 
                                               aPrincipal);
 
   CopyASCIItoUTF16(url, aURL);
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMFile::GetAsText(const nsAString &aCharset, nsAString &aResult)
-{
-  aResult.Truncate();
-
-  nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = GetInternalStream(getter_AddRefs(stream));
-  NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-
-  nsCAutoString charsetGuess;
-  if (!aCharset.IsEmpty()) {
-    CopyUTF16toUTF8(aCharset, charsetGuess);
-  } else {
-    rv = GuessCharset(stream, charsetGuess);
-    NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-
-    nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(stream);
-    if (!seekable) return NS_ERROR_FAILURE;
-    rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
-    NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-  }
-
-  nsCAutoString charset;
-  nsCOMPtr<nsICharsetAlias> alias =
-    do_GetService(NS_CHARSETALIAS_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = alias->GetPreferred(charsetGuess, charset);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return DOMFileResult(ConvertStream(stream, charset.get(), aResult));
-}
-
-NS_IMETHODIMP
-nsDOMFile::GetAsDataURL(nsAString &aResult)
-{
-  aResult.AssignLiteral("data:");
-
-  nsresult rv;
-  if (!mContentType.Length()) {
-    nsCOMPtr<nsIMIMEService> mimeService =
-      do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCAutoString contentType;
-    rv = mimeService->GetTypeFromFile(mFile, contentType);
-    if (NS_SUCCEEDED(rv)) {
-      CopyUTF8toUTF16(contentType, mContentType);
-    }
-  }
-
-  if (mContentType.Length()) {
-    aResult.Append(mContentType);
-  } else {
-    aResult.AppendLiteral("application/octet-stream");
-  }
-  aResult.AppendLiteral(";base64,");
-
-  nsCOMPtr<nsIInputStream> stream;
-  rv = GetInternalStream(getter_AddRefs(stream));
-  NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-
-  char readBuf[4096];
-  PRUint32 leftOver = 0;
-  PRUint32 numRead;
-  do {
-    rv = stream->Read(readBuf + leftOver, sizeof(readBuf) - leftOver, &numRead);
-    NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-
-    PRUint32 numEncode = numRead + leftOver;
-    leftOver = 0;
-
-    if (numEncode == 0) break;
-
-    // unless this is the end of the file, encode in multiples of 3
-    if (numRead > 0) {
-      leftOver = numEncode % 3;
-      numEncode -= leftOver;
-    }
-
-    // out buffer should be at least 4/3rds the read buf, plus a terminator
-    char *base64 = PL_Base64Encode(readBuf, numEncode, nsnull);
-    if (!base64) {
-      return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
-    }
-    nsDependentCString str(base64);
-    PRUint32 strLen = str.Length();
-    PRUint32 oldLength = aResult.Length();
-    AppendASCIItoUTF16(str, aResult);
-    PR_Free(base64);
-    if (aResult.Length() - oldLength != strLen) {
-      return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
-    }
-
-    if (leftOver) {
-      memmove(readBuf, readBuf + numEncode, leftOver);
-    }
-  } while (numRead > 0);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMFile::GetAsBinary(nsAString &aResult)
-{
-  aResult.Truncate();
-
-  nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = GetInternalStream(getter_AddRefs(stream));
-  NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-
-  PRUint32 numRead;
-  do {
-    char readBuf[4096];
-    rv = stream->Read(readBuf, sizeof(readBuf), &numRead);
-    NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
-    PRUint32 oldLength = aResult.Length();
-    AppendASCIItoUTF16(Substring(readBuf, readBuf + numRead), aResult);
-    if (aResult.Length() - oldLength != numRead) {
-      return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
-    }
-  } while (numRead > 0);
-
-  return NS_OK;
-}
-
-nsresult
-nsDOMFile::GuessCharset(nsIInputStream *aStream,
-                        nsACString &aCharset)
-{
-
-  if (!mCharset.IsEmpty()) {
-    aCharset = mCharset;
-    return NS_OK;
-  }
-
-  // First try the universal charset detector
-  nsCOMPtr<nsICharsetDetector> detector
-    = do_CreateInstance(NS_CHARSET_DETECTOR_CONTRACTID_BASE
-                        "universal_charset_detector");
-  if (!detector) {
-    // No universal charset detector, try the default charset detector
-    const nsAdoptingCString& detectorName =
-      Preferences::GetLocalizedCString("intl.charset.detector");
-    if (!detectorName.IsEmpty()) {
-      nsCAutoString detectorContractID;
-      detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
-      detectorContractID += detectorName;
-      detector = do_CreateInstance(detectorContractID.get());
-    }
-  }
-
-  nsresult rv;
-  if (detector) {
-    detector->Init(this);
-
-    PRBool done;
-    PRUint32 numRead;
-    do {
-      char readBuf[4096];
-      rv = aStream->Read(readBuf, sizeof(readBuf), &numRead);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = detector->DoIt(readBuf, numRead, &done);
-      NS_ENSURE_SUCCESS(rv, rv);
-    } while (!done && numRead > 0);
-
-    rv = detector->Done();
-    NS_ENSURE_SUCCESS(rv, rv);
-  } else {
-    // no charset detector available, check the BOM
-    unsigned char sniffBuf[4];
-    PRUint32 numRead;
-    rv = aStream->Read(reinterpret_cast<char*>(sniffBuf),
-                       sizeof(sniffBuf), &numRead);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (numRead >= 4 &&
-        sniffBuf[0] == 0x00 &&
-        sniffBuf[1] == 0x00 &&
-        sniffBuf[2] == 0xfe &&
-        sniffBuf[3] == 0xff) {
-      mCharset = "UTF-32BE";
-    } else if (numRead >= 4 &&
-               sniffBuf[0] == 0xff &&
-               sniffBuf[1] == 0xfe &&
-               sniffBuf[2] == 0x00 &&
-               sniffBuf[3] == 0x00) {
-      mCharset = "UTF-32LE";
-    } else if (numRead >= 2 &&
-               sniffBuf[0] == 0xfe &&
-               sniffBuf[1] == 0xff) {
-      mCharset = "UTF-16BE";
-    } else if (numRead >= 2 &&
-               sniffBuf[0] == 0xff &&
-               sniffBuf[1] == 0xfe) {
-      mCharset = "UTF-16LE";
-    } else if (numRead >= 3 &&
-               sniffBuf[0] == 0xef &&
-               sniffBuf[1] == 0xbb &&
-               sniffBuf[2] == 0xbf) {
-      mCharset = "UTF-8";
-    }
-  }
-
-  if (mCharset.IsEmpty()) {
-    // no charset detected, default to the system charset
-    nsCOMPtr<nsIPlatformCharset> platformCharset =
-      do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv)) {
-      rv = platformCharset->GetCharset(kPlatformCharsetSel_PlainTextInFile,
-                                       mCharset);
-    }
-  }
-
-  if (mCharset.IsEmpty()) {
-    // no sniffed or default charset, try UTF-8
-    mCharset.AssignLiteral("UTF-8");
-  }
-
-  aCharset = mCharset;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDOMFile::GetSendInfo(nsIInputStream** aBody,
                        nsACString& aContentType,
                        nsACString& aCharset)
 {
   nsresult rv;
 
   nsCOMPtr<nsIInputStream> stream;
   rv = this->GetInternalStream(getter_AddRefs(stream));
@@ -602,24 +364,16 @@ nsDOMFile::GetSendInfo(nsIInputStream** 
 
   aCharset.Truncate();
 
   stream.forget(aBody);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMFile::Notify(const char* aCharset, nsDetectionConfident aConf)
-{
-  mCharset.Assign(aCharset);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDOMFile::Initialize(nsISupports* aOwner,
                       JSContext* aCx,
                       JSObject* aObj,
                       PRUint32 aArgc,
                       jsval* aArgv)
 {
   nsresult rv;
 
@@ -669,52 +423,16 @@ nsDOMFile::Initialize(nsISupports* aOwne
   rv = file->Exists(&exists);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
 
   mFile = file;
   return NS_OK;
 }
 
-nsresult
-nsDOMFile::ConvertStream(nsIInputStream *aStream,
-                         const char *aCharset,
-                         nsAString &aResult)
-{
-  aResult.Truncate();
-
-  nsCOMPtr<nsIConverterInputStream> converterStream =
-    do_CreateInstance("@mozilla.org/intl/converter-input-stream;1");
-  if (!converterStream) return NS_ERROR_FAILURE;
-
-  nsresult rv = converterStream->Init
-                  (aStream, aCharset,
-                   8192,
-                   nsIConverterInputStream::DEFAULT_REPLACEMENT_CHARACTER);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIUnicharInputStream> unicharStream =
-    do_QueryInterface(converterStream);
-  if (!unicharStream) return NS_ERROR_FAILURE;
-
-  PRUint32 numChars;
-  nsString result;
-  rv = unicharStream->ReadString(8192, result, &numChars);
-  while (NS_SUCCEEDED(rv) && numChars > 0) {
-    PRUint32 oldLength = aResult.Length();
-    aResult.Append(result);
-    if (aResult.Length() - oldLength != result.Length()) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-    rv = unicharStream->ReadString(8192, result, &numChars);
-  }
-
-  return rv;
-}
-
 // nsDOMMemoryFile Implementation
 NS_IMETHODIMP
 nsDOMMemoryFile::GetName(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFullFile, "Should only be called on files");
   aFileName = mName;
   return NS_OK;
 }