NS_IMETHODIMP
nsSVGGenericContainerFrame::AttributeChanged(PRInt32         aNameSpaceID,
                                             nsIAtom*        aAttribute,
                                             PRInt32         aModType)
{
#ifdef DEBUG
    nsAutoString str;
    aAttribute->ToString(str);
    printf("** nsSVGGenericContainerFrame::AttributeChanged(%s)\n",
           NS_LossyConvertUTF16toASCII(str).get());
#endif

  return NS_OK;
}
Esempio n. 2
0
already_AddRefed<gfxOS2Font>
gfxOS2Platform::FindFontForChar(uint32_t aCh, gfxOS2Font *aFont)
{
#ifdef DEBUG_thebes
    printf("gfxOS2Platform::FindFontForChar(%d, ...)\n", aCh);
#endif

    // is codepoint with no matching font? return null immediately
    if (mCodepointsWithNoFonts.test(aCh)) {
        return nullptr;
    }

    // the following is not very clever but it's a quick fix to search all fonts
    // (one should instead cache the charmaps as done on Mac and Win)

    // just continue to append all fonts known to the system
    nsTArray<nsString> fontList;
    nsAutoCString generic;
    nsresult rv = GetFontList(aFont->GetStyle()->language, generic, fontList);
    if (NS_SUCCEEDED(rv)) {
        // start at 3 to skip over the generic entries
        for (uint32_t i = 3; i < fontList.Length(); i++) {
#ifdef DEBUG_thebes
            printf("searching in entry i=%d (%s)\n",
                   i, NS_LossyConvertUTF16toASCII(fontList[i]).get());
#endif
            nsRefPtr<gfxOS2Font> font =
                gfxOS2Font::GetOrMakeFont(fontList[i], aFont->GetStyle());
            if (!font)
                continue;
            FT_Face face = cairo_ft_scaled_font_lock_face(font->CairoScaledFont());
            if (!face || !face->charmap) {
                if (face)
                    cairo_ft_scaled_font_unlock_face(font->CairoScaledFont());
                continue;
            }

            FT_UInt gid = FT_Get_Char_Index(face, aCh); // find the glyph id
            if (gid != 0) {
                // this is the font
                cairo_ft_scaled_font_unlock_face(font->CairoScaledFont());
                return font.forget();
            }
        }
    }

    // no match found, so add to the set of non-matching codepoints
    mCodepointsWithNoFonts.set(aCh);
    return nullptr;
}
Esempio n. 3
0
void
nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const
{
  PRInt32 index;
  for (index = aIndent; --index >= 0; ) fputs("  ", out);

  fprintf(out, "CDATASection refcount=%d<", mRefCnt.get());

  nsAutoString tmp;
  ToCString(tmp, 0, mText.GetLength());
  fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);

  fputs(">\n", out);
}
void
RDFContentSinkImpl::ParseText(nsIRDFNode **aResult)
{
    // XXXwaterson wasteful, but we'd need to make a copy anyway to be
    // able to call nsIRDFService::Get[Resource|Literal|...]().
    nsAutoString value;
    value.Append(mText, mTextLength);
    value.Trim(" \t\n\r");

    switch (mParseMode) {
    case eRDFContentSinkParseMode_Literal:
        {
            nsIRDFLiteral *result;
            gRDFService->GetLiteral(value.get(), &result);
            *aResult = result;
        }
        break;

    case eRDFContentSinkParseMode_Resource:
        {
            nsIRDFResource *result;
            gRDFService->GetUnicodeResource(value, &result);
            *aResult = result;
        }
        break;

    case eRDFContentSinkParseMode_Int:
        {
            PRInt32 i, err;
            i = value.ToInteger(&err);
            nsIRDFInt *result;
            gRDFService->GetIntLiteral(i, &result);
            *aResult = result;
        }
        break;

    case eRDFContentSinkParseMode_Date:
        {
            PRTime t = rdf_ParseDate(nsDependentCString(NS_LossyConvertUTF16toASCII(value).get(), value.Length()));
            nsIRDFDate *result;
            gRDFService->GetDateLiteral(t, &result);
            *aResult = result;
        }
        break;

    default:
        NS_NOTREACHED("unknown parse type");
        break;
    }
}
NS_IMETHODIMP
sbWatchFolderService::OnFileSystemChanged(const nsAString & aFilePath)
{
  LOG(("sbWatchFolderService::OnFileSystemChanged %s",
    NS_LossyConvertUTF16toASCII(aFilePath).get()));

  bool isIgnoredPath = PR_FALSE;
  nsresult rv = DecrementIgnoredPathCount(aFilePath, &isIgnoredPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // Don't bother with this change if it is currently being ignored.
  if (isIgnoredPath) {
    return NS_OK;
  }

  nsString filePath(aFilePath);

  // The watcher will report all changes from the previous session before the
  // watcher has started. Don't set the timer until then.
  if (mHasWatcherStarted) {
    // See if the changed path set already has this path inside of it.
    sbStringSetIter foundIter = mChangedPaths.find(filePath);
    if (foundIter != mChangedPaths.end()) {
      // If this path is currently in the changed path vector already,
      // delay processing this path until a later time.
      mDelayedChangedPaths.insert(filePath);

      // Start the delayed timer if it isn't running already.
      if (!mChangeDelayTimerIsSet) {
        rv = mChangeDelayTimer->InitWithCallback(this,
                                                 CHANGE_DELAY_TIMER_DELAY,
                                                 nsITimer::TYPE_ONE_SHOT);
        NS_ENSURE_SUCCESS(rv, rv);

        mChangeDelayTimerIsSet = PR_TRUE;
      }
    }
    else {
      mChangedPaths.insert(filePath);
      rv = SetEventPumpTimer();
      NS_ENSURE_SUCCESS(rv, rv);
    }
  }
  else {
    mChangedPaths.insert(filePath);
  }

  return NS_OK;
}
NS_IMETHODIMP nsAbLDAPCard::SetMetaProperties(nsILDAPMessage *aMessage)
{
  NS_ENSURE_ARG_POINTER(aMessage);
  
  // Get DN
  nsAutoCString dn;
  nsresult rv = aMessage->GetDn(dn);
  NS_ENSURE_SUCCESS(rv, rv);

  SetDn(dn);

  // Get the list of set attributes
  CharPtrArrayGuard attrs;
  rv = aMessage->GetAttributes(attrs.GetSizeAddr(), attrs.GetArrayAddr());
  NS_ENSURE_SUCCESS(rv, rv);
 
  nsAutoCString attr;
  m_attributes.Clear();
  for (uint32_t i = 0; i < attrs.GetSize(); ++i)
  {
    attr.Assign(nsDependentCString(attrs[i]));
    ToLowerCase(attr);
    m_attributes.AppendElement(attr);
  }

  // Get the objectClass values
  m_objectClass.Clear();
  PRUnicharPtrArrayGuard vals;
  rv = aMessage->GetValues("objectClass", vals.GetSizeAddr(),
    vals.GetArrayAddr());

  // objectClass is not always included in search result entries and
  // nsILDAPMessage::GetValues returns NS_ERROR_LDAP_DECODING_ERROR if the
  // requested attribute doesn't exist.
  if (rv ==  NS_ERROR_LDAP_DECODING_ERROR)
    return NS_OK;

  NS_ENSURE_SUCCESS(rv, rv);
  
  nsAutoCString oclass;
  for (uint32_t i = 0; i < vals.GetSize(); ++i)
  {
    oclass.Assign(NS_LossyConvertUTF16toASCII(nsDependentString(vals[i])));
    ToLowerCase(oclass);
    m_objectClass.AppendElement(oclass);
  }

  return NS_OK;
}
void
nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const
{
    PRInt32 index;
    for (index = aIndent; --index >= 0; ) fputs("  ", out);

    fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());

    nsAutoString tmp;
    ToCString(tmp, 0, mText.GetLength());
    tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
    fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);

    fputs(">\n", out);
}
Esempio n. 8
0
nsresult
nsContentDLF::CreateDocument(const char* aCommand,
                             nsIChannel* aChannel,
                             nsILoadGroup* aLoadGroup,
                             nsISupports* aContainer,
                             const nsCID& aDocumentCID,
                             nsIStreamListener** aDocListener,
                             nsIContentViewer** aContentViewer)
{
    NS_TIME_FUNCTION;

    nsresult rv = NS_ERROR_FAILURE;

    nsCOMPtr<nsIURI> aURL;
    rv = aChannel->GetURI(getter_AddRefs(aURL));
    if (NS_FAILED(rv)) return rv;

#ifdef NOISY_CREATE_DOC
    if (nullptr != aURL) {
        nsAutoString tmp;
        aURL->ToString(tmp);
        fputs(NS_LossyConvertUTF16toASCII(tmp).get(), stdout);
        printf(": creating document\n");
    }
#endif

    // Create the document
    nsCOMPtr<nsIDocument> doc = do_CreateInstance(aDocumentCID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    // Create the content viewer  XXX: could reuse content viewer here!
    nsCOMPtr<nsIContentViewer> contentViewer;
    rv = NS_NewContentViewer(getter_AddRefs(contentViewer));
    NS_ENSURE_SUCCESS(rv, rv);

    doc->SetContainer(aContainer);

    // Initialize the document to begin loading the data.  An
    // nsIStreamListener connected to the parser is returned in
    // aDocListener.
    rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, true);
    NS_ENSURE_SUCCESS(rv, rv);

    // Bind the document to the Content Viewer
    rv = contentViewer->LoadStart(doc);
    contentViewer.forget(aContentViewer);
    return rv;
}
Esempio n. 9
0
nsresult nsTestUConv::DisplayDetectors()
{
  const char * trace = "DisplayDetectors";
  mLog.AddTrace(trace);
  nsresult res = NS_OK;

  nsCOMPtr<nsICharsetConverterManager> ccMan = 
           do_GetService(kCharsetConverterManagerCID, &res);
  if (NS_FAILED(res)) {
    mLog.PrintError("NS_WITH_SERVICE", res);
    return res;
  }

  // charset detectors
  nsCOMPtr<nsIUTF8StringEnumerator> detectors;

  res = ccMan->GetCharsetDetectorList(getter_AddRefs(detectors));
  if (NS_FAILED(res)) {
    mLog.PrintError("GetCharsetDetectorList()", res);
    return res;
  }

  printf("***** Character Set Detectors *****\n");

  bool hasMore;
  detectors->HasMore(&hasMore);
  while (hasMore) {
    nsAutoCString detectorName;
    res = detectors->GetNext(detectorName);
    if (NS_FAILED(res)) {
      mLog.PrintError("GetNext()", res);
      return res;
    }

    printf("%s", detectorName.get());
    PrintSpaces(36 - detectorName.Length()); // align to hard coded column number

    nsAutoString title;
    res = ccMan->GetCharsetTitle(detectorName.get(), title);
    if (NS_FAILED(res)) title.SetLength(0);
    printf("\"%s\"\n", NS_LossyConvertUTF16toASCII(title).get());

    detectors->HasMore(&hasMore);
  }
  
  mLog.DelTrace(trace);
  return NS_OK;
}
Esempio n. 10
0
void
GeckoMediaPluginServiceParent::RemoveOnGMPThread(const nsAString& aDirectory,
                                                 const bool aDeleteFromDisk,
                                                 const bool aCanDefer)
{
  MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
  LOGD(("%s::%s: %s", __CLASS__, __FUNCTION__, NS_LossyConvertUTF16toASCII(aDirectory).get()));

  nsCOMPtr<nsIFile> directory;
  nsresult rv = NS_NewLocalFile(aDirectory, false, getter_AddRefs(directory));
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return;
  }

  MutexAutoLock lock(mMutex);
  for (size_t i = mPlugins.Length() - 1; i < mPlugins.Length(); i--) {
    nsCOMPtr<nsIFile> pluginpath = mPlugins[i]->GetDirectory();
    bool equals;
    if (NS_FAILED(directory->Equals(pluginpath, &equals)) || !equals) {
      continue;
    }

    nsRefPtr<GMPParent> gmp = mPlugins[i];
    if (aDeleteFromDisk && gmp->State() != GMPStateNotLoaded) {
      // We have to wait for the child process to release its lib handle
      // before we can delete the GMP.
      gmp->MarkForDeletion();

      if (!mPluginsWaitingForDeletion.Contains(aDirectory)) {
        mPluginsWaitingForDeletion.AppendElement(aDirectory);
      }
    }

    if (gmp->State() == GMPStateNotLoaded || !aCanDefer) {
      // GMP not in use or shutdown is being forced; can shut it down now.
      gmp->AbortAsyncShutdown();
      gmp->CloseActive(true);
      mPlugins.RemoveElementAt(i);
    }
  }

  if (aDeleteFromDisk) {
    if (NS_SUCCEEDED(directory->Remove(true))) {
      mPluginsWaitingForDeletion.RemoveElement(aDirectory);
    }
  }
}
Esempio n. 11
0
void
nsVolume::UpdateMountLock(bool aMountLocked)
{
    MOZ_ASSERT(NS_IsMainThread());

    if (aMountLocked == mMountLocked) {
        return;
    }
    // The locked/unlocked state changed. Tell IOThread about it.
    mMountLocked = aMountLocked;
    LogState();
    XRE_GetIOMessageLoop()->PostTask(
        FROM_HERE,
        NewRunnableFunction(Volume::UpdateMountLock,
                            NS_LossyConvertUTF16toASCII(Name()),
                            MountGeneration(), aMountLocked));
}
Esempio n. 12
0
NS_IMETHODIMP
nsCSSMediaRule::List(FILE* out, PRInt32 aIndent) const
{
  for (PRInt32 indent = aIndent; --indent >= 0; ) fputs("  ", out);

  nsAutoString  buffer;

  fputs("@media ", out);

  if (mMedia) {
    nsAutoString mediaText;
    mMedia->GetText(mediaText);
    fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
  }

  return nsCSSGroupRule::List(out, aIndent);
}
nsresult
mozSqlConnectionODBC::RealExec(const nsAString& aQuery,
                               mozISqlResult** aResult, PRInt32* aAffectedRows)
{
  if (!mConnection)
    return NS_ERROR_NOT_INITIALIZED;

  SQLHSTMT hstmt;
  SQLAllocHandle(SQL_HANDLE_STMT, mConnection, &hstmt);

  if(!SQL_SUCCEEDED(SQLExecDirect(hstmt, (SQLCHAR*) NS_LossyConvertUTF16toASCII(aQuery).get(), SQL_NTS))){
    SetError(hstmt, SQL_HANDLE_STMT);

    return NS_ERROR_FAILURE;
  }

  if (!aResult){
    if (!aAffectedRows)
      return NS_ERROR_NULL_POINTER;

    SQLINTEGER count;
    SQLRowCount(hstmt, &count);
    *aAffectedRows = (PRInt32) count;

    return NS_OK;
  }

  mozSqlResult *mozresult = new mozSqlResultODBC(this, aQuery);
  if (!mozresult){
    SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
    return NS_ERROR_OUT_OF_MEMORY;
  }

  ((mozSqlResultODBC*)mozresult)->SetResult(hstmt);
  nsresult rv = mozresult->Init();
  if (NS_FAILED(rv)){
    delete mozresult;
    return rv;
  }

  *aResult = mozresult;
  NS_ADDREF(*aResult);

  return NS_OK;
}
NS_IMETHODIMP
sbWatchFolderService::AddIgnorePath(const nsAString & aFilePath)
{
  LOG(("sbWatchFolderService::AddIgnorePath %s",
        NS_LossyConvertUTF16toASCII(aFilePath).get()));

  nsString filePath(aFilePath);

  sbStringMap::iterator it = mIgnorePaths.find(filePath);
  if (it == mIgnorePaths.end()) {
    // new ignore path
    mIgnorePaths[filePath] = ignorePathData_t(1, 0);
  } else {
    // existing ignore path, set the always-ignore flag
    ++(it->second.depth);
  }
  return NS_OK;
}
Esempio n. 15
0
// see the comment in GLLibraryEGL::EnsureInitialized() for the rationale here.
static PRLibrary*
LoadLibraryForEGLOnWindows(const nsAString& filename)
{
    nsCOMPtr<nsIFile> file;
    nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
    if (NS_FAILED(rv))
        return nullptr;

    file->Append(filename);
    PRLibrary* lib = nullptr;
    rv = file->Load(&lib);
    if (NS_FAILED(rv)) {
        nsPrintfCString msg("Failed to load %s - Expect EGL initialization to fail",
                            NS_LossyConvertUTF16toASCII(filename).get());
        NS_WARNING(msg.get());
    }
    return lib;
}
nsresult
txStylesheetCompilerState::loadIncludedStylesheet(const nsAString& aURI)
{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("CompilerState::loadIncludedStylesheet: %s\n",
            NS_LossyConvertUTF16toASCII(aURI).get()));
    if (mStylesheetURI.Equals(aURI)) {
        return NS_ERROR_XSLT_LOAD_RECURSION;
    }
    NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED);

    nsAutoPtr<txToplevelItem> item(new txDummyItem);
    NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);

    nsresult rv = mToplevelIterator.addBefore(item);
    NS_ENSURE_SUCCESS(rv, rv);
    
    item.forget();

    // step back to the dummy-item
    mToplevelIterator.previous();
    
    txACompileObserver* observer = static_cast<txStylesheetCompiler*>(this);

    nsRefPtr<txStylesheetCompiler> compiler =
        new txStylesheetCompiler(aURI, mStylesheet, &mToplevelIterator,
                                 observer);
    NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);

    // step forward before calling the observer in case of syncronous loading
    mToplevelIterator.next();

    if (mChildCompilerList.AppendElement(compiler) == nsnull) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
    if (NS_FAILED(rv)) {
        mChildCompilerList.RemoveElement(compiler);
    }

    return rv;
}
NS_IMETHODIMP 
nsMacLocale::GetPlatformLocale(const nsAString& locale, short* scriptCode, short* langCode, short* regionCode)
{
  char  country_code[3];
  char  lang_code[3];
  char  region_code[3];
  bool  validCountryFound;
  int  i;
  
  if (!ParseLocaleString(NS_LossyConvertUTF16toASCII(locale).get(), lang_code, country_code, region_code, '-')) {
    *scriptCode = smRoman;
    *langCode = langEnglish;
    *regionCode = verUS;
    return NS_ERROR_FAILURE;
  }
  
  if (country_code[0]!=0) 
  {
    validCountryFound=false;
    for(i=0;country_list[i].iso_code;i++) {
      if (strcmp(country_list[i].iso_code,country_code)==0) {
        *regionCode = country_list[i].mac_region_code;
        validCountryFound=true;
        break;
      }
    }
    if (!validCountryFound) {
      *scriptCode = smRoman;
      *langCode = langEnglish;
      *regionCode = verUS;
      return NS_ERROR_FAILURE;
    }
  }
    
  for(i=0;lang_list[i].iso_code;i++) {
    if (strcmp(lang_list[i].iso_code, lang_code)==0) {
      *scriptCode = lang_list[i].mac_script_code;
      *langCode = lang_list[i].mac_lang_code;
      return NS_OK;
    }
  }
  return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
sbRemoteCommands::RemoveCommand( const nsAString &aID )
{
  LOG(("sbRemoteCommands::RemoveCommand()"));
  PRUint32 num = mCommands.Length();
  for ( PRUint32 index = 0; index < num; index++ ) {
    LOG(( "sbRemoteCommands::RemoveCommand(%d:%s)",
          index,
          NS_LossyConvertUTF16toASCII(mCommands.ElementAt(index).id).get()));
    if ( mCommands.ElementAt(index).id == aID ) {
      mCommands.RemoveElementAt(index);
      DoCommandsUpdated();
      return NS_OK;
    }
  }
  // XXXredfive check an error code here and log a warning if the command
  //            isn't found
  return NS_OK;
}
NS_IMETHODIMP
sbRemoteCommands::AddCommand( const nsAString &aType,
                              const nsAString &aID,
                              const nsAString &aName,
                              const nsAString &aTooltip )
{
  LOG(( "sbRemoteCommands::AddCommand(%s)",
        NS_LossyConvertUTF16toASCII(aID).get() ));
  sbCommand command;
  command.type = aType;
  command.id = aID;
  command.name = aName;
  command.tooltip = aTooltip;

  if ( !mCommands.AppendElement(command) )
    return NS_ERROR_OUT_OF_MEMORY;
  DoCommandsUpdated();
  return NS_OK;
}
void
txStylesheetCompiler::cancel(nsresult aError, const PRUnichar *aErrorText,
                             const PRUnichar *aParam)
{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("Compiler::cancel: %s, module: %d, code %d\n",
            NS_LossyConvertUTF16toASCII(mStylesheetURI).get(),
            NS_ERROR_GET_MODULE(aError),
            NS_ERROR_GET_CODE(aError)));
    if (NS_SUCCEEDED(mStatus)) {
        mStatus = aError;
    }

    if (mObserver) {
        mObserver->onDoneCompiling(this, mStatus, aErrorText, aParam);
        // This will ensure that we don't call onDoneCompiling twice. Also
        // ensures that we don't keep the observer alive longer then necessary.
        mObserver = nsnull;
    }
}
Esempio n. 21
0
static void
ListFloats(FILE* out, PRInt32 aIndent, const nsFloatCacheList& aFloats)
{
  nsFloatCache* fc = aFloats.Head();
  while (fc) {
    nsFrame::IndentBy(out, aIndent);
    nsIFrame* frame = fc->mFloat;
    fprintf(out, "floatframe@%p ", static_cast<void*>(frame));
    if (frame) {
      nsAutoString frameName;
      frame->GetFrameName(frameName);
      fputs(NS_LossyConvertUTF16toASCII(frameName).get(), out);
    }
    else {
      fputs("\n###!!! NULL out-of-flow frame", out);
    }
    fprintf(out, "\n");
    fc = fc->Next();
  }
}
NS_IMETHODIMP
sbWatchFolderService::RemoveIgnorePath(const nsAString & aFilePath)
{
  LOG(("sbWatchFolderService::RemoveIgnorePath %s",
        NS_LossyConvertUTF16toASCII(aFilePath).get()));

  nsString filePath(aFilePath);

  sbStringMap::iterator it = mIgnorePaths.find(filePath);
  // note: there is no error if this is called too many times.
  if (it != mIgnorePaths.end()) {
    it->second.depth = PR_MAX(0, it->second.depth - 1);
    if (it->second.depth < 1 && it->second.count < 1) {
      // there is no counter, the ignore path can be removed
      mIgnorePaths.erase(it);
    }
  }

  return NS_OK;
}
NS_IMETHODIMP
sbWatchFolderService::OnFileSystemAdded(const nsAString & aFilePath)
{
  LOG(("sbWatchFolderService::OnFileSystemAdded %s",
    NS_LossyConvertUTF16toASCII(aFilePath).get()));

  bool isIgnoredPath = PR_FALSE;
  nsresult rv = DecrementIgnoredPathCount(aFilePath, &isIgnoredPath);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!isIgnoredPath) {
    mAddedPaths.insert(nsString(aFilePath));

    // The method will guard against |mHasWatcherStarted|
    rv = SetEventPumpTimer();
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}
Esempio n. 24
0
FILE* operator<<(FILE* out, const nsRect& rect)
{
  nsAutoString tmp;

  // Output the coordinates in fractional pixels so they're easier to read
  tmp.Append('{');
  tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.x,
                       nsDeviceContext::AppUnitsPerCSSPixel()));
  tmp.AppendLiteral(", ");
  tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.y,
                       nsDeviceContext::AppUnitsPerCSSPixel()));
  tmp.AppendLiteral(", ");
  tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.width,
                       nsDeviceContext::AppUnitsPerCSSPixel()));
  tmp.AppendLiteral(", ");
  tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.height,
                       nsDeviceContext::AppUnitsPerCSSPixel()));
  tmp.Append('}');
  fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
  return out;
}
const txXPathNode*
txExecutionState::retrieveDocument(const nsAString& aUri)
{
    NS_ASSERTION(aUri.FindChar(PRUnichar('#')) == kNotFound,
                 "Remove the fragment.");

    if (mDisableLoads) {
        return nsnull;
    }

    PR_LOG(txLog::xslt, PR_LOG_DEBUG,
           ("Retrieve Document %s", NS_LossyConvertUTF16toASCII(aUri).get()));

    // try to get already loaded document
    txLoadedDocumentEntry *entry = mLoadedDocuments.PutEntry(aUri);
    if (!entry) {
        return nsnull;
    }

    if (!entry->mDocument) {
        // open URI
        nsAutoString errMsg;
        // XXX we should get the loader from the actual node
        // triggering the load, but this will do for the time being
        nsresult rv;
        rv = txParseDocumentFromURI(aUri, *mLoadedDocuments.mSourceDocument,
                                    errMsg,
                                    getter_Transfers(entry->mDocument));

        if (NS_FAILED(rv) || !entry->mDocument) {
            mLoadedDocuments.RawRemoveEntry(entry);
            receiveError(NS_LITERAL_STRING("Couldn't load document '") +
                         aUri + NS_LITERAL_STRING("': ") + errMsg, rv);

            return nsnull;
        }
    }

    return entry->mDocument;
}
Esempio n. 26
0
nsresult
GMPParent::Init(GeckoMediaPluginService *aService, nsIFile* aPluginDir)
{
  MOZ_ASSERT(aPluginDir);
  MOZ_ASSERT(aService);
  MOZ_ASSERT(GMPThread() == NS_GetCurrentThread());

  mService = aService;
  mDirectory = aPluginDir;

  nsAutoString leafname;
  nsresult rv = aPluginDir->GetLeafName(leafname);
  if (NS_FAILED(rv)) {
    return rv;
  }
  LOGD(("%s::%s: %p for %s", __CLASS__, __FUNCTION__, this, 
       NS_LossyConvertUTF16toASCII(leafname).get()));

  MOZ_ASSERT(leafname.Length() > 4);
  mName = Substring(leafname, 4);

  return ReadGMPMetaData();
}
Esempio n. 27
0
nsresult nsAbManager::AppendProperty(const char *aProperty, const PRUnichar *aValue, nsACString &aResult)
{
  NS_ENSURE_ARG_POINTER(aValue);

  aResult += aProperty;

  // if the string is not safe "as is", base64 encode it
  if (IsSafeLDIFString(aValue)) {
    aResult.AppendLiteral(": ");
    aResult.Append(NS_LossyConvertUTF16toASCII(aValue));
  }
  else {
    char *base64Str = PL_Base64Encode(NS_ConvertUTF16toUTF8(aValue).get(), 0, nsnull);
    if (!base64Str)
      return NS_ERROR_OUT_OF_MEMORY;

    aResult.AppendLiteral(":: ");
    aResult.Append(nsDependentCString(base64Str));
    PR_Free(base64Str);
  }

  return NS_OK;
}
Esempio n. 28
0
const txXPathNode*
txExecutionState::retrieveDocument(const nsAString& aUri)
{
    NS_ASSERTION(!aUri.Contains(char16_t('#')),
                 "Remove the fragment.");

    if (mDisableLoads) {
        return nullptr;
    }

    MOZ_LOG(txLog::xslt, LogLevel::Debug,
           ("Retrieve Document %s", NS_LossyConvertUTF16toASCII(aUri).get()));

    // try to get already loaded document
    txLoadedDocumentEntry *entry = mLoadedDocuments.PutEntry(aUri);
    if (!entry) {
        return nullptr;
    }

    if (!entry->mDocument && !entry->LoadingFailed()) {
        // open URI
        nsAutoString errMsg;
        // XXX we should get the loader from the actual node
        // triggering the load, but this will do for the time being
        entry->mLoadResult =
            txParseDocumentFromURI(aUri, *mLoadedDocuments.mSourceDocument,
                                   errMsg, getter_Transfers(entry->mDocument));

        if (entry->LoadingFailed()) {
            receiveError(NS_LITERAL_STRING("Couldn't load document '") +
                         aUri + NS_LITERAL_STRING("': ") + errMsg,
                         entry->mLoadResult);
        }
    }

    return entry->mDocument;
}
Esempio n. 29
0
nsresult
nsComboboxControlFrame::RedisplayText(PRInt32 aIndex)
{
  // Get the text to display
  if (aIndex != -1) {
    mListControlFrame->GetOptionText(aIndex, mDisplayedOptionText);
  } else {
    mDisplayedOptionText.Truncate();
  }
  mDisplayedIndex = aIndex;

  REFLOW_DEBUG_MSG2("RedisplayText \"%s\"\n",
                    NS_LossyConvertUTF16toASCII(mDisplayedOptionText).get());

  // Send reflow command because the new text maybe larger
  nsresult rv = NS_OK;
  if (mDisplayContent) {
    // Don't call ActuallyDisplayText(PR_TRUE) directly here since that
    // could cause recursive frame construction. See bug 283117 and the comment in
    // HandleRedisplayTextEvent() below.

    // Revoke outstanding events to avoid out-of-order events which could mean
    // displaying the wrong text.
    mRedisplayTextEvent.Revoke();

    NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
                 "If we happen to run our redisplay event now, we might kill "
                 "ourselves!");

    nsRefPtr<RedisplayTextEvent> event = new RedisplayTextEvent(this);
    mRedisplayTextEvent = event;
    if (!nsContentUtils::AddScriptRunner(event))
      mRedisplayTextEvent.Forget();
  }
  return rv;
}
TEST(TextFormatter, Tests)
{
  nsAutoString fmt(NS_LITERAL_STRING("%3$s %4$S %1$d %2$d %2$d %3$s"));
  char utf8[] = "Hello";
  char16_t ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103, 0x00};
  int d=3;

  char16_t buf[256];
  nsTextFormatter::snprintf(buf, 256, fmt.get(), d, 333, utf8, ucs2);
  nsAutoString out(buf);
  ASSERT_STREQ("Hello World", NS_LossyConvertUTF16toASCII(out).get());

  const char16_t *uout = out.get();
  const char16_t expected[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20,
                                0x57, 0x6F, 0x72, 0x6C, 0x64, 0x4E00,
                                0xAC00, 0xFF45, 0x0103, 0x20, 0x33,
                                0x20, 0x33, 0x33, 0x33, 0x20, 0x33,
                                0x33, 0x33, 0x20, 0x48, 0x65, 0x6C,
                                0x6C, 0x6F};

  for (uint32_t i=0; i<out.Length(); i++) {
    ASSERT_EQ(uout[i], expected[i]);
  }
}