NS_IMETHODIMP GnomeKeyring::Init()
#endif
{
  nsresult ret;
  nsCOMPtr<nsIServiceManager> servMan;
  nsCOMPtr<nsIPrefService> prefService;
  nsCOMPtr<nsIPrefBranch> pref;
#ifdef PR_LOGGING
  gGnomeKeyringLog = PR_NewLogModule("GnomeKeyringLog");
#endif
  keyringName.AssignLiteral(kDefaultKeyring);
  ret = NS_GetServiceManager(getter_AddRefs(servMan));
  if (ret != NS_OK) { return ret; }

  ret = servMan->GetServiceByContractID("@mozilla.org/preferences-service;1",
                                        NS_GET_IID(nsIPrefService),
                                        getter_AddRefs(prefService));
  if (ret != NS_OK) { return ret; }

  ret = prefService->ReadUserPrefs(nullptr);
  if (ret != NS_OK) { return ret; }

  ret = prefService->GetBranch(kPrefsBranch, getter_AddRefs(pref));
  if (ret != NS_OK) { return ret; }

  PRInt32 prefType;
  ret = pref->GetPrefType(kPrefsKeyring, &prefType);
  if (ret != NS_OK) { return ret; }

  if (prefType == 32) {
    char* tempKeyringName;
    pref->GetCharPref(kPrefsKeyring, &tempKeyringName);
    keyringName = tempKeyringName;
    if ( keyringName.IsVoid() || keyringName.IsEmpty() ) keyringName.AssignLiteral(kDefaultKeyring);
  }

  /* Create the password keyring, it doesn't hurt if it already exists */
  GnomeKeyringResult result = gnome_keyring_create_sync(keyringName.get(), NULL);
  if ((result != GNOME_KEYRING_RESULT_OK) &&
      (result != GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS)) {
    NS_ERROR("Can't open or create password keyring!");
    return NS_ERROR_FAILURE;
  }
  return ret;
}
bool
ExternalHelperAppParent::RecvOnDataAvailable(const nsCString& data,
        const uint64_t& offset,
        const uint32_t& count)
{
    if (NS_FAILED(mStatus))
        return true;

    MOZ_ASSERT(!mDiverted, "child forwarding callbacks after request was diverted");
    MOZ_ASSERT(mPending, "must be pending!");

    nsCOMPtr<nsIInputStream> stringStream;
    DebugOnly<nsresult> rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(), count, NS_ASSIGNMENT_DEPEND);
    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create dependent string!");
    mStatus = mListener->OnDataAvailable(this, nullptr, stringStream, offset, count);

    return true;
}
Example #3
0
bool
ContentParent::RecvGetChildList(const nsCString& domain,
                                nsTArray<nsCString>* list, nsresult* rv)
{
    EnsurePrefService();

    PRUint32 count;
    char **childArray;
    *rv = mPrefService->GetChildList(domain.get(), &count, &childArray);

    if (NS_SUCCEEDED(*rv)) {
      list->SetCapacity(count);
      for (PRUint32 i = 0; i < count; ++i)
        *(list->AppendElement()) = childArray[i];
    }
        
    return true;
}
Example #4
0
/* static */ already_AddRefed<Image>
ImageFactory::CreateAnonymousImage(const nsCString& aMimeType)
{
  nsresult rv;

  nsRefPtr<RasterImage> newImage = new RasterImage();

  nsRefPtr<ProgressTracker> newTracker = new ProgressTracker();
  newTracker->SetImage(newImage);
  newImage->SetProgressTracker(newTracker);

  rv = newImage->Init(aMimeType.get(), Image::INIT_FLAG_SYNC_LOAD);
  if (NS_FAILED(rv)) {
    return BadImage("RasterImage::Init failed", newImage);
  }

  return newImage.forget();
}
/* static */ void
CommonElementAnimationData::LogAsyncAnimationFailure(nsCString& aMessage,
                                                     const nsIContent* aContent)
{
  if (aContent) {
    aMessage.AppendLiteral(" [");
    aMessage.Append(nsAtomCString(aContent->Tag()));

    nsIAtom* id = aContent->GetID();
    if (id) {
      aMessage.AppendLiteral(" with id '");
      aMessage.Append(nsAtomCString(aContent->GetID()));
      aMessage.AppendLiteral("'");
    }
    aMessage.AppendLiteral("]");
  }
  printf_stderr(aMessage.get());
}
Example #6
0
// Determine if aFirstDomain is a different base domain to aSecondURI; or, if
// the concept of base domain does not apply, determine if the two hosts are not
// string-identical.
nsresult
ThirdPartyUtil::IsThirdPartyInternal(const nsCString& aFirstDomain,
                                     nsIURI* aSecondURI,
                                     bool* aResult)
{
  NS_ENSURE_ARG(aSecondURI);

  // Get the base domain for aSecondURI.
  nsCString secondDomain;
  nsresult rv = GetBaseDomain(aSecondURI, secondDomain);
  LOG(("ThirdPartyUtil::IsThirdPartyInternal %s =? %s", aFirstDomain.get(), secondDomain.get()));
  if (NS_FAILED(rv))
    return rv;

  // Check strict equality.
  *aResult = aFirstDomain != secondDomain;
  return NS_OK;
}
// Given the freetype face corresponding to an entryName and face index,
// add the face to the available font list and to the faceList string
void
gfxFT2FontList::AddFaceToList(const nsCString& aEntryName, uint32_t aIndex,
                              bool aStdFile, FT_Face aFace,
                              nsCString& aFaceList)
{
    if (FT_Err_Ok != FT_Select_Charmap(aFace, FT_ENCODING_UNICODE)) {
        // ignore faces that don't support a Unicode charmap
        return;
    }

    // build the font entry name and create an FT2FontEntry,
    // but do -not- keep a reference to the FT_Face
    FT2FontEntry* fe =
        CreateNamedFontEntry(aFace, aEntryName.get(), aIndex);

    if (fe) {
        NS_ConvertUTF8toUTF16 name(aFace->family_name);
        BuildKeyNameFromFontName(name);
        gfxFontFamily *family = mFontFamilies.GetWeak(name);
        if (!family) {
            family = new FT2FontFamily(name);
            mFontFamilies.Put(name, family);
            if (mBadUnderlineFamilyNames.Contains(name)) {
                family->SetBadUnderlineFamily();
            }
        }
        fe->mStandardFace = aStdFile;
        family->AddFontEntry(fe);

        fe->CheckForBrokenFont(family);

        AppendToFaceList(aFaceList, name, fe);
#ifdef PR_LOGGING
        if (LOG_ENABLED()) {
            LOG(("(fontinit) added (%s) to family (%s)"
                 " with style: %s weight: %d stretch: %d",
                 NS_ConvertUTF16toUTF8(fe->Name()).get(),
                 NS_ConvertUTF16toUTF8(family->Name()).get(),
                 fe->IsItalic() ? "italic" : "normal",
                 fe->Weight(), fe->Stretch()));
        }
#endif
    }
}
bool
BrowserStreamChild::RecvNPP_StreamAsFile(const nsCString& fname)
{
  PLUGIN_LOG_DEBUG(("%s (fname=%s)", FULLFUNCTION, fname.get()));

  AssertPluginThread();

  if (ALIVE != mState)
    NS_RUNTIMEABORT("Unexpected state: received file after NPP_DestroyStream?");

  if (kStreamOpen != mStreamStatus)
    return true;

  mStreamAsFilePending = true;
  mStreamAsFileName = fname;
  EnsureDeliveryPending();

  return true;
}
mozilla::ipc::IPCResult
BrowserStreamChild::RecvNPP_StreamAsFile(const nsCString& fname)
{
  PLUGIN_LOG_DEBUG(("%s (fname=%s)", FULLFUNCTION, fname.get()));

  AssertPluginThread();

  if (ALIVE != mState)
    MOZ_CRASH("Unexpected state: received file after NPP_DestroyStream?");

  if (kStreamOpen != mStreamStatus)
    return IPC_OK();

  mStreamAsFilePending = true;
  mStreamAsFileName = fname;
  EnsureDeliveryPending();

  return IPC_OK();
}
Example #10
0
nsresult
rdf_MakeAbsoluteURI(nsIURI* aBase, nsCString& aURI)
{
    nsresult rv;
    nsXPIDLCString result;

    rv = NS_MakeAbsoluteURI(getter_Copies(result), aURI.get(), aBase);

    if (NS_SUCCEEDED(rv)) {
        aURI.Assign(result);
    }
    else {
        // There are some ugly URIs (e.g., "NC:Foo") that netlib can't
        // parse. If NS_MakeAbsoluteURL fails, then just punt and
        // assume that aURI was already absolute.
    }

    return NS_OK;
}
Example #11
0
void
UnixSocketImpl::Connect()
{
  if(mFd.get() < 0)
  {
    mFd = mConnector->Create();
    if (mFd.get() < 0) {
      return;
    }
  }

  int ret;

  mConnector->CreateAddr(false, mAddrSize, &mAddr, mAddress.get());

  ret = connect(mFd.get(), &mAddr, mAddrSize);

  if (ret) {
#if DEBUG
    LOG("Socket connect errno=%d\n", errno);
#endif
    mFd.reset(-1);
    nsRefPtr<OnSocketEventTask> t =
      new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
    NS_DispatchToMainThread(t);
    return;
  }

  if (!mConnector->SetUp(mFd)) {
    NS_WARNING("Could not set up socket!");
    return;
  }

  nsRefPtr<OnSocketEventTask> t =
    new OnSocketEventTask(this, OnSocketEventTask::CONNECT_SUCCESS);
  NS_DispatchToMainThread(t);

  // Due to the fact that we've dispatched our OnConnectSuccess message before
  // starting reading, we're guaranteed that any subsequent read tasks will
  // happen after the object has been notified of a successful connect.
  XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
                                   new StartImplReadingTask(this));
}
Example #12
0
/* static */ void
AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage,
                                         const nsIContent* aContent)
{
  if (aContent) {
    aMessage.AppendLiteral(" [");
    aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom()));

    nsIAtom* id = aContent->GetID();
    if (id) {
      aMessage.AppendLiteral(" with id '");
      aMessage.Append(nsAtomCString(aContent->GetID()));
      aMessage.Append('\'');
    }
    aMessage.Append(']');
  }
  aMessage.Append('\n');
  printf_stderr("%s", aMessage.get());
}
bool
HttpChannelParent::RecvDivertOnDataAvailable(const nsCString& data,
                                             const uint64_t& offset,
                                             const uint32_t& count)
{
  LOG(("HttpChannelParent::RecvDivertOnDataAvailable [this=%p]\n", this));

  MOZ_ASSERT(mParentListener);
  if (NS_WARN_IF(!mDivertingFromChild)) {
    MOZ_ASSERT(mDivertingFromChild,
               "Cannot RecvDivertOnDataAvailable if diverting is not set!");
    FailDiversion(NS_ERROR_UNEXPECTED);
    return false;
  }

  // Drop OnDataAvailables if the parent was canceled already.
  if (NS_FAILED(mStatus)) {
    return true;
  }

  nsCOMPtr<nsIInputStream> stringStream;
  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
                                      count, NS_ASSIGNMENT_DEPEND);
  if (NS_FAILED(rv)) {
    if (mChannel) {
      mChannel->Cancel(rv);
    }
    mStatus = rv;
    return true;
  }

  rv = mParentListener->OnDataAvailable(mChannel, nullptr, stringStream,
                                        offset, count);
  stringStream->Close();
  if (NS_FAILED(rv)) {
    if (mChannel) {
      mChannel->Cancel(rv);
    }
    mStatus = rv;
    return true;
  }
  return true;
}
Example #14
0
 virtual void
 CacheFileInfo(nsCString& aFileName, nsCString& aFaceList,
               PRUint32 aTimestamp, PRUint32 aFilesize)
 {
     if (!mMap.ops) {
         return;
     }
     FNCMapEntry* entry =
         static_cast<FNCMapEntry*>
         (PL_DHashTableOperate(&mMap, aFileName.get(), PL_DHASH_ADD));
     if (entry) {
         entry->mFilename.Assign(aFileName);
         entry->mTimestamp = aTimestamp;
         entry->mFilesize = aFilesize;
         entry->mFaces.Assign(aFaceList);
         entry->mFileExists = true;
     }
     mWriteNeeded = true;
 }
void
nsGIOProtocolHandler::InitSupportedProtocolsPref(nsIPrefBranch *prefs)
{
  // Get user preferences to determine which protocol is supported.
  // Gvfs/GIO has a set of supported protocols like obex, network, archive,
  // computer, dav, cdda, gphoto2, trash, etc. Some of these seems to be
  // irrelevant to process by browser. By default accept only smb and sftp
  // protocols so far.
  nsresult rv = prefs->GetCharPref(MOZ_GIO_SUPPORTED_PROTOCOLS,
                                   getter_Copies(mSupportedProtocols));
  if (NS_SUCCEEDED(rv)) {
    mSupportedProtocols.StripWhitespace();
    ToLowerCase(mSupportedProtocols);
  }
  else
    mSupportedProtocols.AssignLiteral("smb:,sftp:"); // use defaults

  LOG(("gio: supported protocols \"%s\"\n", mSupportedProtocols.get()));
}
Example #16
0
bool
GMPDecryptorChild::RecvCreateSession(const uint32_t& aPromiseId,
                                     const nsCString& aInitDataType,
                                     const nsTArray<uint8_t>& aInitData,
                                     const GMPSessionType& aSessionType)
{
  if (!mSession) {
    return false;
  }

  mSession->CreateSession(aPromiseId,
                          aInitDataType.get(),
                          aInitDataType.Length(),
                          aInitData.Elements(),
                          aInitData.Length(),
                          aSessionType);

  return true;
}
/* static */ already_AddRefed<Image>
ImageFactory::CreateRasterImage(nsIRequest* aRequest,
                                imgStatusTracker* aStatusTracker,
                                const nsCString& aMimeType,
                                nsIURI* aURI,
                                uint32_t aImageFlags,
                                uint32_t aInnerWindowId)
{
  nsresult rv;

  nsRefPtr<RasterImage> newImage = new RasterImage(aStatusTracker, aURI);

  rv = newImage->Init(aMimeType.get(), aImageFlags);
  NS_ENSURE_SUCCESS(rv, BadImage(newImage));

  newImage->SetInnerWindowID(aInnerWindowId);

  uint32_t len = GetContentSize(aRequest);

  // Pass anything usable on so that the RasterImage can preallocate
  // its source buffer.
  if (len > 0) {
    uint32_t sizeHint = std::min<uint32_t>(len, 20000000); // Bound by something reasonable
    rv = newImage->SetSourceSizeHint(sizeHint);
    if (NS_FAILED(rv)) {
      // Flush memory, try to get some back, and try again.
      rv = nsMemory::HeapMinimize(true);
      nsresult rv2 = newImage->SetSourceSizeHint(sizeHint);
      // If we've still failed at this point, things are going downhill.
      if (NS_FAILED(rv) || NS_FAILED(rv2)) {
        NS_WARNING("About to hit OOM in imagelib!");
      }
    }
  }

  mozilla::net::nsMediaFragmentURIParser parser(aURI);
  if (parser.HasResolution()) {
    newImage->SetRequestedResolution(parser.GetResolution());
  }

  return newImage.forget();
}
Example #18
0
void
FTPChannelParent::DivertOnDataAvailable(const nsCString& data,
                                        const uint64_t& offset,
                                        const uint32_t& count)
{
  LOG(("FTPChannelParent::DivertOnDataAvailable [this=%p]\n", this));

  if (NS_WARN_IF(!mDivertingFromChild)) {
    MOZ_ASSERT(mDivertingFromChild,
               "Cannot DivertOnDataAvailable if diverting is not set!");
    FailDiversion(NS_ERROR_UNEXPECTED);
    return;
  }

  // Drop OnDataAvailables if the parent was canceled already.
  if (NS_FAILED(mStatus)) {
    return;
  }

  nsCOMPtr<nsIInputStream> stringStream;
  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
                                      count, NS_ASSIGNMENT_DEPEND);
  if (NS_FAILED(rv)) {
    if (mChannel) {
      mChannel->Cancel(rv);
    }
    mStatus = rv;
    return;
  }

  AutoEventEnqueuer ensureSerialDispatch(mEventQ);

  rv = OnDataAvailable(mChannel, nullptr, stringStream, offset, count);

  stringStream->Close();
  if (NS_FAILED(rv)) {
    if (mChannel) {
      mChannel->Cancel(rv);
    }
    mStatus = rv;
  }
}
void
gfxAndroidPlatform::FindFontsInDirectory(const nsCString& aFontsDir,
                                         FontNameCache* aFontCache)
{
    DIR *d = opendir(aFontsDir.get());
    struct dirent *ent = NULL;
    while(d && (ent = readdir(d)) != NULL) {
        int namelen = strlen(ent->d_name);
        if (namelen > 4 &&
            strcasecmp(ent->d_name + namelen - 4, ".ttf") == 0)
        {
            nsCString s(aFontsDir);
            s.Append(nsDependentCString(ent->d_name));

            AppendFacesFromFontFile(nsPromiseFlatCString(s).get(),
                                    aFontCache, &mFontList);
        }
    }
    closedir(d);
}
AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent,
        nsIWeakReference* aShell,
        const nsCString& aPlugId) :
    nsAccessibleWrap(aContent, aShell)
{
    mAtkObject = mai_atk_socket_new(this);
    if (!mAtkObject)
        return;

    // Embeds the children of an AtkPlug, specified by plugId, as the children of
    // this socket.
    // Using G_TYPE macros instead of ATK_SOCKET macros to avoid undefined
    // symbols.
    if (gCanEmbed && G_TYPE_CHECK_INSTANCE_TYPE(mAtkObject, g_atk_socket_type) &&
            !aPlugId.IsVoid()) {
        AtkSocket* accSocket =
            G_TYPE_CHECK_INSTANCE_CAST(mAtkObject, g_atk_socket_type, AtkSocket);
        g_atk_socket_embed(accSocket, (gchar*)aPlugId.get());
    }
}
void
ChromiumCDMProxy::RejectPromise(PromiseId aId,
                                nsresult aCode,
                                const nsCString& aReason)
{
  if (!NS_IsMainThread()) {
    nsCOMPtr<nsIRunnable> task;
    task = NewRunnableMethod<PromiseId, nsresult, nsCString>(
      this, &ChromiumCDMProxy::RejectPromise, aId, aCode, aReason);
    NS_DispatchToMainThread(task);
    return;
  }
  EME_LOG("ChromiumCDMProxy::RejectPromise(pid=%u, code=0x%x, reason='%s')",
          aId,
          static_cast<uint32_t>(aCode),
          aReason.get());
  if (!mKeys.IsNull()) {
    mKeys->RejectPromise(aId, aCode, aReason);
  }
}
Example #22
0
// i18n helper routines
nsresult
nsEncodingFormSubmission::EncodeVal(const nsAString& aStr, nsCString& aOut,
                                    bool aHeaderEncode)
{
  if (!mEncoder.Encode(aStr, aOut)) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  if (aHeaderEncode) {
    aOut.Adopt(nsLinebreakConverter::
               ConvertLineBreaks(aOut.get(),
                                 nsLinebreakConverter::eLinebreakAny,
                                 nsLinebreakConverter::eLinebreakSpace));
    aOut.ReplaceSubstring(NS_LITERAL_CSTRING("\""),
                          NS_LITERAL_CSTRING("\\\""));
  }


  return NS_OK;
}
Example #23
0
static PRBool
MakeConfFile(const char *regfile, const nsCString &greHome,
             const GREProperty *aProperties, PRUint32 aPropertiesLen)
{
  // If the file exists, don't create it again!
  if (access(regfile, R_OK) == 0)
    return PR_FALSE;

  PRBool ok = PR_TRUE;

  { // scope "fd" so that we can delete the file if something goes wrong
    AutoFDClose fd = PR_Open(regfile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
                             0664);
    if (!fd)
      return PR_FALSE;

    static const char kHeader[] =
      "# Registration file generated by xulrunner. Do not edit.\n\n"
      "[" GRE_BUILD_ID "]\n"
      "GRE_PATH=";

    if (PR_Write(fd, kHeader, sizeof(kHeader) - 1) != sizeof(kHeader) - 1)
      ok = PR_FALSE;

    if (PR_Write(fd, greHome.get(), greHome.Length()) != greHome.Length())
      ok = PR_FALSE;

    for (PRUint32 i = 0; i < aPropertiesLen; ++i) {
      if (PR_fprintf(fd, "\n%s=%s",
                     aProperties[i].property, aProperties[i].value) <= 0)
        ok = PR_FALSE;
    }

    PR_Write(fd, "\n", 1);
  }

  if (!ok)
    PR_Delete(regfile);

  return ok;
}
Example #24
0
nsresult
nsLDAPURL::SetPathInternal(const nsCString &aPath)
{
  LDAPURLDesc *desc;

  // This is from the LDAP C-SDK, which currently doesn't
  // support everything from RFC 2255... :(
  //
  int err = ldap_url_parse(aPath.get(), &desc);
  switch (err) {
  case LDAP_SUCCESS: {
    // The base URL can pick up the host & port details and deal with them
    // better than we can
    mDN = desc->lud_dn;
    mScope = desc->lud_scope;
    mFilter = desc->lud_filter;
    mOptions = desc->lud_options;
    nsresult rv = SetAttributeArray(desc->lud_attrs);
    if (NS_FAILED(rv))
      return rv;

    ldap_free_urldesc(desc);
    return NS_OK;
  }

  case LDAP_URL_ERR_NOTLDAP:
  case LDAP_URL_ERR_NODN:
  case LDAP_URL_ERR_BADSCOPE:
    return NS_ERROR_MALFORMED_URI;

  case LDAP_URL_ERR_MEM:
    NS_ERROR("nsLDAPURL::SetSpec: out of memory ");
    return NS_ERROR_OUT_OF_MEMORY;

  case LDAP_URL_ERR_PARAM: 
    return NS_ERROR_INVALID_POINTER;
  }

  // This shouldn't happen...
  return NS_ERROR_UNEXPECTED;
}
static nsresult
WriteImage(const nsCString& aPath, imgIContainer* aImage)
{
#ifndef MOZ_WIDGET_GTK2
  return NS_ERROR_NOT_AVAILABLE;
#else
  nsCOMPtr<nsIImageToPixbuf> imgToPixbuf =
    do_GetService("@mozilla.org/widget/image-to-gdk-pixbuf;1");
  if (!imgToPixbuf)
      return NS_ERROR_NOT_AVAILABLE;

  GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(aImage);
  if (!pixbuf)
      return NS_ERROR_NOT_AVAILABLE;

  gboolean res = gdk_pixbuf_save(pixbuf, aPath.get(), "png", NULL, NULL);

  g_object_unref(pixbuf);
  return res ? NS_OK : NS_ERROR_FAILURE;
#endif
}
Example #26
0
static nsresult
GetCertFingerprintByDottedOidString(CERTCertificate* nsscert,
                                    const nsCString &dottedOid, 
                                    nsCString &fp)
{
  SECItem oid;
  oid.data = nullptr;
  oid.len = 0;
  SECStatus srv = SEC_StringToOID(nullptr, &oid, 
                    dottedOid.get(), dottedOid.Length());
  if (srv != SECSuccess)
    return NS_ERROR_FAILURE;

  SECOidTag oid_tag = SECOID_FindOIDTag(&oid);
  SECITEM_FreeItem(&oid, false);

  if (oid_tag == SEC_OID_UNKNOWN)
    return NS_ERROR_FAILURE;

  return GetCertFingerprintByOidTag(nsscert, oid_tag, fp);
}
Example #27
0
mozilla::ipc::IPCResult
GMPDecryptorChild::RecvCreateSession(const uint32_t& aCreateSessionToken,
                                     const uint32_t& aPromiseId,
                                     const nsCString& aInitDataType,
                                     InfallibleTArray<uint8_t>&& aInitData,
                                     const GMPSessionType& aSessionType)
{
  if (!mSession) {
    return IPC_FAIL_NO_REASON(this);
  }

  mSession->CreateSession(aCreateSessionToken,
                          aPromiseId,
                          aInitDataType.get(),
                          aInitDataType.Length(),
                          aInitData.Elements(),
                          aInitData.Length(),
                          aSessionType);

  return IPC_OK();
}
Example #28
0
  void Serialize(const nsCString& aInput)
  {
    const unsigned char* p = (const unsigned char*) aInput.get();

    while (p && *p) {
      // ' ' to '+'
      if (*p == 0x20) {
        mValue.Append(0x2B);
      // Percent Encode algorithm
      } else if (*p == 0x2A || *p == 0x2D || *p == 0x2E ||
                 (*p >= 0x30 && *p <= 0x39) ||
                 (*p >= 0x41 && *p <= 0x5A) || *p == 0x5F ||
                 (*p >= 0x61 && *p <= 0x7A)) {
        mValue.Append(*p);
      } else {
        mValue.AppendPrintf("%%%X", *p);
      }

      ++p;
    }
  }
already_AddRefed<nsMIMEInfoBase>
nsOSHelperAppService::GetFromType(const nsCString& aMIMEType)
{
	for (int i = 0; mimeTypes[i].type; i++)
	{
		if (strcasecmp(aMIMEType.get(), mimeTypes[i].type) == 0)
		{
			nsCAutoString mimeType(mimeTypes[i].type);
			nsAutoString description = NS_ConvertASCIItoUTF16(mimeTypes[i].description);;

			nsMIMEInfoAmigaOS *mimeInfo = new nsMIMEInfoAmigaOS(mimeType);
			NS_ADDREF(mimeInfo);

			if (mimeTypes[i].handler)
			{
				nsCAutoString path(mimeTypes[i].handler);
				nsAutoString handler = NS_ConvertASCIItoUTF16(mimeTypes[i].handlerDesc);

				nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
				localFile->InitWithNativePath(path);

				NS_IF_ADDREF(localFile);

				mimeInfo->SetDescription(nsAutoString(description));
				mimeInfo->SetDefaultApplication(localFile);
				mimeInfo->SetDefaultDescription(handler);
				mimeInfo->SetPreferredAction(nsIMIMEInfo::useHelperApp);
			}
			else
			{
				mimeInfo->SetDescription(description);
				mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
			}

			return mimeInfo;
		}
	}

	return nsnull;
}
Example #30
0
static nsresult
MakeVersionKey(HKEY root, const char* keyname, const nsCString &grehome,
               const GREProperty *aProperties, PRUint32 aPropertiesLen,
               const char *aGREMilestone)
{
  HKEY  subkey;
  DWORD disp;
  if (::RegCreateKeyEx(root, keyname, NULL, NULL, 0, KEY_WRITE, NULL,
                       &subkey, &disp) != ERROR_SUCCESS)
    return NS_ERROR_FAILURE;

  if (disp != REG_CREATED_NEW_KEY) {
    ::RegCloseKey(subkey);
    return NS_ERROR_FAILURE;
  }

  PRBool failed = PR_FALSE;
  failed |= ::RegSetValueEx(subkey, "Version", NULL, REG_SZ,
                            (BYTE*) aGREMilestone,
                            strlen(aGREMilestone)) != ERROR_SUCCESS;
  failed |= ::RegSetValueEx(subkey, "GreHome", NULL, REG_SZ,
                            (BYTE*) grehome.get(),
                            grehome.Length()) != ERROR_SUCCESS;

  for (PRUint32 i = 0; i < aPropertiesLen; ++i) {
    failed |= ::RegSetValueEx(subkey, aProperties[i].property, NULL, REG_SZ,
                              (BYTE*) aProperties[i].value,
                              strlen(aProperties[i].value)) != ERROR_SUCCESS;
  }

  ::RegCloseKey(subkey);

  if (failed) {
    // we created a key but couldn't fill it properly: delete it
    ::RegDeleteKey(root, keyname);
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}