Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsDOMParser.cpp File Reference
#include "jsapi.h"
#include "nsDOMParser.h"
#include "nsIURI.h"
#include "nsIChannel.h"
#include "nsILoadGroup.h"
#include "nsIInputStream.h"
#include "nsNetUtil.h"
#include "nsIByteArrayInputStream.h"
#include "nsIXPConnect.h"
#include "nsIUnicodeEncoder.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsLayoutCID.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMWindow.h"
#include "nsIPrivateDOMImplementation.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMClassInfo.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsIDOMEventReceiver.h"
#include "nsLoadListenerProxy.h"
#include "nsStreamUtils.h"
#include "nsNetCID.h"
#include "nsContentUtils.h"
#include "nsPIDOMWindow.h"

Go to the source code of this file.

Classes

class  nsDOMParserChannel

Functions

static NS_DEFINE_IID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
static NS_DEFINE_CID (kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID)
static NS_DEFINE_CID (kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID)
 NS_IMPL_ISUPPORTS2 (nsDOMParserChannel, nsIChannel, nsIRequest) NS_IMETHODIMP nsDOMParserChannel
static NS_INTERFACE_MAP_END
nsresult 
ConvertWStringToStream (const PRUnichar *aStr, PRInt32 aLength, nsIInputStream **aStream, PRInt32 *aContentLength)

Variables

static const char * kLoadAsData = "loadAsData"

Function Documentation

static NS_INTERFACE_MAP_END nsresult ConvertWStringToStream ( const PRUnichar aStr,
PRInt32  aLength,
nsIInputStream **  aStream,
PRInt32 aContentLength 
) [static]

Definition at line 361 of file nsDOMParser.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIUnicodeEncoder> encoder;
  char* charBuf;

  // We want to encode the string as utf-8, so get the right encoder
  nsCOMPtr<nsICharsetConverterManager> charsetConv = 
           do_GetService(kCharsetConverterManagerCID, &rv);
  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
  
  rv = charsetConv->GetUnicodeEncoderRaw("UTF-8",
                                      getter_AddRefs(encoder));
  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
  
  // Convert to utf-8
  PRInt32 charLength;
  const PRUnichar* unicodeBuf = aStr;
  PRInt32 unicodeLength = aLength;
    
  rv = encoder->GetMaxLength(unicodeBuf, unicodeLength, &charLength);
  if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
  
  charBuf = (char*)nsMemory::Alloc(charLength + 1);
  if (!charBuf) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  rv = encoder->Convert(unicodeBuf, 
                        &unicodeLength, 
                        charBuf, 
                        &charLength);
  if (NS_FAILED(rv)) {
    nsMemory::Free(charBuf);
    return NS_ERROR_FAILURE;
  }

  // The new stream takes ownership of the buffer
  rv = NS_NewByteArrayInputStream((nsIByteArrayInputStream**)aStream, 
                                  charBuf, 
                                  charLength);
  if (NS_FAILED(rv)) {
    nsMemory::Free(charBuf);
    return NS_ERROR_FAILURE;
  }
  
  *aContentLength = charLength;

  return NS_OK;
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kIDOMDOMImplementationCID  ,
NS_DOM_IMPLEMENTATION_CID   
) [static]
static NS_DEFINE_CID ( kCharsetConverterManagerCID  ,
NS_ICHARSETCONVERTERMANAGER_CID   
) [static]

Definition at line 114 of file nsDOMParser.cpp.

{
    NS_NOTREACHED("nsDOMParserChannel::GetName");
    return NS_ERROR_NOT_IMPLEMENTED;
}

Variable Documentation

const char* kLoadAsData = "loadAsData" [static]

Definition at line 73 of file nsDOMParser.cpp.