Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsDataObj.cpp File Reference
#include <ole2.h>
#include <urlmon.h>
#include <shlobj.h>
#include "nsDataObj.h"
#include "nsClipboard.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsVoidArray.h"
#include "nsITransferable.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "IENUMFE.H"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsPrimitiveHelpers.h"
#include "nsXPIDLString.h"
#include "nsIImage.h"
#include "nsImageClipboard.h"
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "prprf.h"
#include "nsCRT.h"
#include "nsPrintfCString.h"
#include "nsIStringBundle.h"

Go to the source code of this file.

Defines

#define PRNTDEBUG(_x)
#define PRNTDEBUG2(_x1, _x2)
#define PRNTDEBUG3(_x1, _x2, _x3)
#define NS_MAX_FILEDESCRIPTOR   128 + 1
#define PAGEINFO_PROPERTIES   "chrome://navigator/locale/pageInfo.properties"

Functions

 STDMETHODIMP_ (ULONG) nsDataObj
static void MangleTextToValidFilename (nsString &aText)
static PRBool CreateFilenameFromTextA (nsString &aText, const char *aExtension, char *aFilename, PRUint32 aFilenameLen)
static PRBool CreateFilenameFromTextW (nsString &aText, const wchar_t *aExtension, wchar_t *aFilename, PRUint32 aFilenameLen)
static NS_DEFINE_CID (kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID)
static PRBool GetLocalizedString (const PRUnichar *aName, nsXPIDLString &aString)

Variables

EXTERN_C GUID CDECL CLSID_nsDataObj

Define Documentation

Definition at line 93 of file nsDataObj.cpp.

#define PAGEINFO_PROPERTIES   "chrome://navigator/locale/pageInfo.properties"

Definition at line 608 of file nsDataObj.cpp.

#define PRNTDEBUG (   _x)

Definition at line 77 of file nsDataObj.cpp.

#define PRNTDEBUG2 (   _x1,
  _x2 
)

Definition at line 78 of file nsDataObj.cpp.

#define PRNTDEBUG3 (   _x1,
  _x2,
  _x3 
)

Definition at line 79 of file nsDataObj.cpp.


Function Documentation

static PRBool CreateFilenameFromTextA ( nsString aText,
const char *  aExtension,
char *  aFilename,
PRUint32  aFilenameLen 
) [static]

Definition at line 554 of file nsDataObj.cpp.

{
  // ensure that the supplied name doesn't have invalid characters. If 
  // a valid mangled filename couldn't be created then it will leave the
  // text empty.
  MangleTextToValidFilename(aText);
  if (aText.IsEmpty())
    return PR_FALSE;

  // repeatably call WideCharToMultiByte as long as the title doesn't fit in the buffer 
  // available to us. Continually reduce the length of the source title until the MBCS
  // version will fit in the buffer with room for the supplied extension. Doing it this
  // way ensures that even in MBCS environments there will be a valid MBCS filename of
  // the correct length.
  int maxUsableFilenameLen = aFilenameLen - strlen(aExtension) - 1; // space for ext + null byte
  int currLen, textLen = (int) NS_MIN(aText.Length(), aFilenameLen);
  char defaultChar = '_';
  do {
    currLen = WideCharToMultiByte(CP_ACP, 
      WC_COMPOSITECHECK|WC_DEFAULTCHAR,
      aText.get(), textLen--, aFilename, maxUsableFilenameLen, &defaultChar, NULL);
  }
  while (currLen == 0 && textLen > 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
  if (currLen > 0 && textLen > 0) {
    strcpy(&aFilename[currLen], aExtension);
    return PR_TRUE;
  }
  else {
    // empty names aren't permitted
    return PR_FALSE;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool CreateFilenameFromTextW ( nsString aText,
const wchar_t *  aExtension,
wchar_t *  aFilename,
PRUint32  aFilenameLen 
) [static]

Definition at line 589 of file nsDataObj.cpp.

{
  // ensure that the supplied name doesn't have invalid characters. If 
  // a valid mangled filename couldn't be created then it will leave the
  // text empty.
  MangleTextToValidFilename(aText);
  if (aText.IsEmpty())
    return PR_FALSE;

  const int extensionLen = wcslen(aExtension);
  if (aText.Length() + extensionLen + 1 > aFilenameLen)
    aText.Truncate(aFilenameLen - extensionLen - 1);
  wcscpy(&aFilename[0], aText.get());
  wcscpy(&aFilename[aText.Length()], aExtension);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool GetLocalizedString ( const PRUnichar aName,
nsXPIDLString aString 
) [static]

Definition at line 611 of file nsDataObj.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIStringBundleService> stringService = do_GetService(kStringBundleServiceCID, &rv);
  if (NS_FAILED(rv)) 
    return PR_FALSE;

  nsCOMPtr<nsIStringBundle> stringBundle;
  rv = stringService->CreateBundle(PAGEINFO_PROPERTIES, getter_AddRefs(stringBundle));
  if (NS_FAILED(rv))
    return PR_FALSE;

  rv = stringBundle->GetStringFromName(aName, getter_Copies(aString));
  return NS_SUCCEEDED(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void MangleTextToValidFilename ( nsString aText) [static]

Definition at line 523 of file nsDataObj.cpp.

{
  static const char* forbiddenNames[] = {
    "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", 
    "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
    "CON", "PRN", "AUX", "NUL", "CLOCK$"
  };

  aText.StripChars(FILE_PATH_SEPARATOR  FILE_ILLEGAL_CHARACTERS);
  aText.CompressWhitespace(PR_TRUE, PR_TRUE);
  PRUint32 nameLen;
  for (size_t n = 0; n < NS_ARRAY_LENGTH(forbiddenNames); ++n) {
    nameLen = (PRUint32) strlen(forbiddenNames[n]);
    if (aText.EqualsIgnoreCase(forbiddenNames[n], nameLen)) {
      // invalid name is either the entire string, or a prefix with a period
      if (aText.Length() == nameLen || aText.CharAt(nameLen) == PRUnichar('.')) {
        aText.Truncate();
        break;
      }
    }
  }
}

Here is the caller graph for this function:

static NS_DEFINE_CID ( kStringBundleServiceCID  ,
NS_STRINGBUNDLESERVICE_CID   
) [static]

Definition at line 154 of file nsDataObj.cpp.

{
       ++g_cRef;
       ++m_cRef;
       NS_LOG_ADDREF(this, m_cRef, "nsDataObj", sizeof(*this));
  //PRNTDEBUG3("nsDataObj::AddRef  >>>>>>>>>>>>>>>>>> %d on %p\n", (m_cRef+1), this);
       return m_cRef;
}

Variable Documentation

Initial value:
       { 0x1bba7640, 0xdf52, 0x11cf, { 0x82, 0x7b, 0, 0xa0, 0x24, 0x3a, 0xe5, 0x05 } }

Definition at line 84 of file nsDataObj.cpp.