NS_IMETHODIMP SpeechRecognition::GetUserMediaErrorCallback::OnError(const nsAString& aError) { SpeechRecognitionErrorCode errorCode; if (aError.Equals(NS_LITERAL_STRING("PERMISSION_DENIED"))) { errorCode = SpeechRecognitionErrorCode::Not_allowed; } else { errorCode = SpeechRecognitionErrorCode::Audio_capture; } mRecognition->DispatchError(SpeechRecognition::EVENT_AUDIO_ERROR, errorCode, aError); return NS_OK; }
NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) { if (!mDisplayRequest) { if (FAILED(ActivateGenericInstance(RuntimeClass_Windows_System_Display_DisplayRequest, mDisplayRequest))) { NS_WARNING("Failed to instantiate IDisplayRequest, wakelocks will be broken!"); return NS_OK; } } if (aState.Equals(NS_LITERAL_STRING("locked-foreground"))) { mDisplayRequest->RequestActive(); } else { mDisplayRequest->RequestRelease(); } return NS_OK; }
/* void appendFilter (in AString title, in AString filter); */ NS_IMETHODIMP nsFilePicker::AppendFilter(const nsAString & aTitle, const nsAString & aFilter) { if (aFilter.Equals(NS_LITERAL_STRING("..apps"))) { // No platform specific thing we can do here, really.... return NS_OK; } nsCAutoString filter, name; CopyUTF16toUTF8(aFilter, filter); CopyUTF16toUTF8(aTitle, name); mFilters.AppendCString(filter); mFilterNames.AppendCString(name); return NS_OK; }
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) { nsCOMPtr<nsIWindowsRegKey> regKey = do_CreateInstance("@mozilla.org/windows-registry-key;1"); if (!regKey) return NS_ERROR_NOT_AVAILABLE; NS_ConvertASCIItoUTF16 buf(aScheme); #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN // Vista: use new application association interface if (mAppAssoc) { PRUnichar * pResult = nsnull; // We are responsible for freeing returned strings. HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(), AT_URLPROTOCOL, AL_EFFECTIVE, &pResult); if (SUCCEEDED(hr)) { nsCOMPtr<nsIFile> app; nsAutoString appInfo(pResult); CoTaskMemFree(pResult); if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app)))) return NS_OK; } return NS_ERROR_NOT_AVAILABLE; } #endif nsCOMPtr<nsIFile> app; GetDefaultAppInfo(buf, _retval, getter_AddRefs(app)); if (!_retval.Equals(buf)) return NS_OK; // Fall back to full path buf.AppendLiteral("\\shell\\open\\command"); nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, buf, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_FAILED(rv)) return NS_ERROR_NOT_AVAILABLE; rv = regKey->ReadStringValue(EmptyString(), _retval); return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_NOT_AVAILABLE; }
NS_IMETHODIMP PresentationConnection::NotifyStateChange(const nsAString& aSessionId, uint16_t aState) { if (!aSessionId.Equals(mId)) { return NS_ERROR_INVALID_ARG; } PresentationConnectionState state; switch (aState) { case nsIPresentationSessionListener::STATE_CONNECTED: state = PresentationConnectionState::Connected; break; case nsIPresentationSessionListener::STATE_CLOSED: state = PresentationConnectionState::Closed; break; case nsIPresentationSessionListener::STATE_TERMINATED: state = PresentationConnectionState::Terminated; break; default: NS_WARNING("Unknown presentation session state."); return NS_ERROR_INVALID_ARG; } if (mState == state) { return NS_OK; } mState = state; // Unregister session listener if the session is no longer connected. if (mState == PresentationConnectionState::Terminated) { nsCOMPtr<nsIPresentationService> service = do_GetService(PRESENTATION_SERVICE_CONTRACTID); if (NS_WARN_IF(!service)) { return NS_ERROR_NOT_AVAILABLE; } nsresult rv = service->UnregisterSessionListener(mId); if(NS_WARN_IF(NS_FAILED(rv))) { return rv; } } return DispatchStateChangeEvent(); }
NS_IMETHODIMP PresentationConnection::NotifyStateChange(const nsAString& aSessionId, uint16_t aState, nsresult aReason) { if (!aSessionId.Equals(mId)) { return NS_ERROR_INVALID_ARG; } PresentationConnectionState state; switch (aState) { case nsIPresentationSessionListener::STATE_CONNECTING: state = PresentationConnectionState::Connecting; break; case nsIPresentationSessionListener::STATE_CONNECTED: state = PresentationConnectionState::Connected; break; case nsIPresentationSessionListener::STATE_CLOSED: state = PresentationConnectionState::Closed; break; case nsIPresentationSessionListener::STATE_TERMINATED: state = PresentationConnectionState::Terminated; break; default: NS_WARNING("Unknown presentation session state."); return NS_ERROR_INVALID_ARG; } if (mState == state) { return NS_OK; } mState = state; nsresult rv = ProcessStateChanged(aReason); if(NS_WARN_IF(NS_FAILED(rv))) { return rv; } if (mOwningConnectionList) { mOwningConnectionList->NotifyStateChange(aSessionId, this); } return NS_OK; }
static nsresult IsContentTypeEqual(nsAString &aGuid, sbILibrary* aLibrary, const nsAString &aContentType, PRBool* aIsSame) { NS_ENSURE_ARG_POINTER(aLibrary); NS_ENSURE_ARG_POINTER(aIsSame); nsresult rv; nsCOMPtr<sbIMediaItem> item; rv = aLibrary->GetItemByGuid(aGuid, getter_AddRefs(item)); NS_ENSURE_SUCCESS(rv, rv); nsString contentType; rv = item->GetProperty(NS_LITERAL_STRING(SB_PROPERTY_CONTENTTYPE), contentType); NS_ENSURE_SUCCESS(rv, rv); *aIsSame = aContentType.Equals(contentType); return NS_OK; }
NS_IMETHODIMP sbIPDDevice::SetPreference(const nsAString& aPrefName, nsIVariant* aPrefValue) { // Validate arguments. NS_ENSURE_ARG_POINTER(aPrefValue); // Function variables. nsresult rv; // If a preference needs to be set on the device, enqueue a set preference // request. The internal, locally stored preference is still set here to // provide immediate feedback. if (aPrefName.Equals(SB_SYNC_PARTNER_PREF)) { rv = ReqPushSetNamedValue(REQUEST_SET_PREF, aPrefName, aPrefValue); NS_ENSURE_SUCCESS(rv, rv); } // Forward call to base class. return sbBaseDevice::SetPreference(aPrefName, aPrefValue); }
NS_IMETHODIMP nsHTMLCanvasElement::MozGetIPCContext(const nsAString& aContextId, nsISupports **aContext) { #ifdef MOZ_IPC if(!nsContentUtils::IsCallerTrustedForRead()) { // XXX ERRMSG we need to report an error to developers here! (bug 329026) return NS_ERROR_DOM_SECURITY_ERR; } // We only support 2d shmem contexts for now. if (!aContextId.Equals(NS_LITERAL_STRING("2d"))) return NS_ERROR_INVALID_ARG; if (mCurrentContextId.IsEmpty()) { nsresult rv = GetContextHelper(aContextId, false, getter_AddRefs(mCurrentContext)); NS_ENSURE_SUCCESS(rv, rv); if (!mCurrentContext) { return NS_OK; } mCurrentContext->SetIsIPC(true); rv = UpdateContext(); NS_ENSURE_SUCCESS(rv, rv); mCurrentContextId.Assign(aContextId); } else if (!mCurrentContextId.Equals(aContextId)) { //XXX eventually allow for more than one active context on a given canvas return NS_ERROR_INVALID_ARG; } NS_ADDREF (*aContext = mCurrentContext); return NS_OK; #else return NS_ERROR_NOT_IMPLEMENTED; #endif }
NS_IMETHODIMP nsDOMScriptObjectFactory::GetScriptRuntime(const nsAString &aLanguageName, nsIScriptRuntime **aLanguage) { // Note that many callers have optimized detection for JS (along with // supporting various alternate names for JS), so don't call this. // One exception is for the new "script-type" attribute on a node - and // there is no need to support backwards compatible names. // As JS is the default language, this is still rarely called for JS - // only when a node explicitly sets JS - so that is done last. nsCAutoString contractid(NS_LITERAL_CSTRING( "@mozilla.org/script-language;1?script-type=")); // Arbitrarily use utf8 encoding should the name have extended chars AppendUTF16toUTF8(aLanguageName, contractid); nsresult rv; nsCOMPtr<nsIScriptRuntime> lang = do_GetService(contractid.get(), &rv); if (NS_FAILED(rv)) { if (aLanguageName.Equals(NS_LITERAL_STRING("application/javascript"))) return GetScriptRuntimeByID(nsIProgrammingLanguage::JAVASCRIPT, aLanguage); // Not JS and nothing else we know about. NS_WARNING("No script language registered for this mime-type"); return NS_ERROR_FACTORY_NOT_REGISTERED; } // And stash it away in our array for fast lookup by ID. PRUint32 lang_ndx = NS_STID_INDEX(lang->GetScriptTypeID()); if (mLanguageArray[lang_ndx] == nsnull) { mLanguageArray[lang_ndx] = lang; } else { // All languages are services - we should have an identical object! NS_ASSERTION(mLanguageArray[lang_ndx] == lang, "Got a different language for this ID???"); } *aLanguage = lang; NS_IF_ADDREF(*aLanguage); return NS_OK; }
nsresult nsSceneTracker::SetRDFString (nsIRDFDataSource* aDS, nsIRDFResource* aSource, nsIRDFResource* aProp, const nsAString& aString) { NS_ENSURE_ARG(aDS); NS_ENSURE_ARG(aSource); NS_ENSURE_ARG(aProp); nsCOMPtr<nsIRDFNode> tmpnode; nsCOMPtr<nsIRDFService> rdfsvc = do_GetService( "@mozilla.org/rdf/rdf-service;1"); nsCOMPtr<nsIRDFLiteral> newlit; rdfsvc->GetLiteral(PromiseFlatString(aString).get(), getter_AddRefs(newlit)); nsresult rv = aDS->GetTarget(aSource, aProp, PR_TRUE, getter_AddRefs(tmpnode)); if (NS_FAILED(rv)) return rv; if (tmpnode) { // Check if no change is needed nsCOMPtr<nsIRDFLiteral> litval(do_QueryInterface(tmpnode)); if (litval) { PRUnichar* result; rv = litval->GetValue(&result); if (NS_SUCCEEDED(rv)) { if (aString.Equals(result)) { PR_Free(result); return NS_OK; } PR_Free(result); } } rv = aDS->Change(aSource, aProp, tmpnode, newlit); } else if (! aString.IsEmpty()) { rv = aDS->Assert(aSource, aProp, newlit, PR_TRUE); } return rv; }
// Removes the value aRemoveValue from the string list of white-space separated // values aValueList void ChangeStyleTransaction::RemoveValueFromListOfValues( nsAString& aValues, const nsAString& aRemoveValue) { nsAutoString classStr(aValues); nsAutoString outString; // put an extra null at the end classStr.Append(kNullCh); char16_t* start = classStr.BeginWriting(); char16_t* end = start; while (kNullCh != *start) { while (kNullCh != *start && nsCRT::IsAsciiSpace(*start)) { // skip leading space start++; } end = start; while (kNullCh != *end && !nsCRT::IsAsciiSpace(*end)) { // look for space or end end++; } // end string here *end = kNullCh; if (start < end && !aRemoveValue.Equals(start)) { outString.Append(start); outString.Append(char16_t(' ')); } start = ++end; } aValues.Assign(outString); }
nsresult nsKeygenFormProcessor::GetPublicKey(const nsAString& aValue, const nsAString& aChallenge, const nsAFlatString& aKeyType, nsAString& aOutPublicKey, const nsAString& aKeyParams) { nsNSSShutDownPreventionLock locker; if (isAlreadyShutDown()) { return NS_ERROR_NOT_AVAILABLE; } nsresult rv = NS_ERROR_FAILURE; char *keystring = nullptr; char *keyparamsString = nullptr; uint32_t keyGenMechanism; PK11SlotInfo *slot = nullptr; PK11RSAGenParams rsaParams; SECOidTag algTag; int keysize = 0; void *params = nullptr; SECKEYPrivateKey *privateKey = nullptr; SECKEYPublicKey *publicKey = nullptr; CERTSubjectPublicKeyInfo *spkInfo = nullptr; SECStatus srv = SECFailure; SECItem spkiItem; SECItem pkacItem; SECItem signedItem; CERTPublicKeyAndChallenge pkac; pkac.challenge.data = nullptr; nsIGeneratingKeypairInfoDialogs * dialogs; nsKeygenThread *KeygenRunnable = 0; nsCOMPtr<nsIKeygenThread> runnable; // permanent and sensitive flags for keygen PK11AttrFlags attrFlags = PK11_ATTR_TOKEN | PK11_ATTR_SENSITIVE | PK11_ATTR_PRIVATE; UniquePLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); if (!arena) { goto loser; } // Get the key size // for (size_t i = 0; i < number_of_key_size_choices; ++i) { if (aValue.Equals(mSECKeySizeChoiceList[i].name)) { keysize = mSECKeySizeChoiceList[i].size; break; } } if (!keysize) { goto loser; } // Set the keygen mechanism if (aKeyType.IsEmpty() || aKeyType.LowerCaseEqualsLiteral("rsa")) { keyGenMechanism = CKM_RSA_PKCS_KEY_PAIR_GEN; } else if (aKeyType.LowerCaseEqualsLiteral("ec")) { keyparamsString = ToNewCString(aKeyParams); if (!keyparamsString) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } keyGenMechanism = CKM_EC_KEY_PAIR_GEN; /* ecParams are initialized later */ } else { goto loser; } // Get the slot rv = GetSlot(keyGenMechanism, &slot); if (NS_FAILED(rv)) { goto loser; } switch (keyGenMechanism) { case CKM_RSA_PKCS_KEY_PAIR_GEN: rsaParams.keySizeInBits = keysize; rsaParams.pe = DEFAULT_RSA_KEYGEN_PE; algTag = DEFAULT_RSA_KEYGEN_ALG; params = &rsaParams; break; case CKM_EC_KEY_PAIR_GEN: /* XXX We ought to rethink how the KEYGEN tag is * displayed. The pulldown selections presented * to the user must depend on the keytype. * The displayed selection could be picked * from the keyparams attribute (this is currently called * the pqg attribute). * For now, we pick ecparams from the keyparams field * if it specifies a valid supported curve, or else * we pick one of secp384r1, secp256r1 or secp192r1 * respectively depending on the user's selection * (High, Medium, Low). * (RSA uses RSA-2048, RSA-1024 and RSA-512 for historical * reasons, while ECC choices represent a stronger mapping) * NOTE: The user's selection * is silently ignored when a valid curve is presented * in keyparams. */ if ((params = decode_ec_params(keyparamsString)) == nullptr) { /* The keyparams attribute did not specify a valid * curve name so use a curve based on the keysize. * NOTE: Here keysize is used only as an indication of * High/Medium/Low strength; elliptic curve * cryptography uses smaller keys than RSA to provide * equivalent security. */ switch (keysize) { case 2048: params = decode_ec_params("secp384r1"); break; case 1024: case 512: params = decode_ec_params("secp256r1"); break; } } /* XXX The signature algorithm ought to choose the hashing * algorithm based on key size once ECDSA variations based * on SHA256 SHA384 and SHA512 are standardized. */ algTag = SEC_OID_ANSIX962_ECDSA_SIGNATURE_WITH_SHA1_DIGEST; break; default: goto loser; } /* Make sure token is initialized. */ rv = setPassword(slot, m_ctx, locker); if (NS_FAILED(rv)) goto loser; srv = PK11_Authenticate(slot, true, m_ctx); if (srv != SECSuccess) { goto loser; } rv = getNSSDialogs((void**)&dialogs, NS_GET_IID(nsIGeneratingKeypairInfoDialogs), NS_GENERATINGKEYPAIRINFODIALOGS_CONTRACTID); if (NS_SUCCEEDED(rv)) { KeygenRunnable = new nsKeygenThread(); NS_IF_ADDREF(KeygenRunnable); } if (NS_FAILED(rv) || !KeygenRunnable) { rv = NS_OK; privateKey = PK11_GenerateKeyPairWithFlags(slot, keyGenMechanism, params, &publicKey, attrFlags, m_ctx); } else { KeygenRunnable->SetParams( slot, attrFlags, nullptr, 0, keyGenMechanism, params, m_ctx ); runnable = do_QueryInterface(KeygenRunnable); if (runnable) { rv = dialogs->DisplayGeneratingKeypairInfo(m_ctx, runnable); // We call join on the thread so we can be sure that no // simultaneous access to the passed parameters will happen. KeygenRunnable->Join(); NS_RELEASE(dialogs); if (NS_SUCCEEDED(rv)) { PK11SlotInfo *used_slot = nullptr; rv = KeygenRunnable->ConsumeResult(&used_slot, &privateKey, &publicKey); if (NS_SUCCEEDED(rv) && used_slot) { PK11_FreeSlot(used_slot); } } } } if (NS_FAILED(rv) || !privateKey) { goto loser; } // just in case we'll need to authenticate to the db -jp // privateKey->wincx = m_ctx; /* * Create a subject public key info from the public key. */ spkInfo = SECKEY_CreateSubjectPublicKeyInfo(publicKey); if ( !spkInfo ) { goto loser; } /* * Now DER encode the whole subjectPublicKeyInfo. */ srv = DER_Encode(arena.get(), &spkiItem, CERTSubjectPublicKeyInfoTemplate, spkInfo); if (srv != SECSuccess) { goto loser; } /* * set up the PublicKeyAndChallenge data structure, then DER encode it */ pkac.spki = spkiItem; pkac.challenge.len = aChallenge.Length(); pkac.challenge.data = (unsigned char *)ToNewCString(aChallenge); if (!pkac.challenge.data) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } srv = DER_Encode(arena.get(), &pkacItem, CERTPublicKeyAndChallengeTemplate, &pkac); if (srv != SECSuccess) { goto loser; } /* * now sign the DER encoded PublicKeyAndChallenge */ srv = SEC_DerSignData(arena.get(), &signedItem, pkacItem.data, pkacItem.len, privateKey, algTag); if (srv != SECSuccess) { goto loser; } /* * Convert the signed public key and challenge into base64/ascii. */ keystring = BTOA_DataToAscii(signedItem.data, signedItem.len); if (!keystring) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } CopyASCIItoUTF16(keystring, aOutPublicKey); free(keystring); rv = NS_OK; GatherKeygenTelemetry(keyGenMechanism, keysize, keyparamsString); loser: if (srv != SECSuccess) { if ( privateKey ) { PK11_DestroyTokenObject(privateKey->pkcs11Slot,privateKey->pkcs11ID); } if ( publicKey ) { PK11_DestroyTokenObject(publicKey->pkcs11Slot,publicKey->pkcs11ID); } } if ( spkInfo ) { SECKEY_DestroySubjectPublicKeyInfo(spkInfo); } if ( publicKey ) { SECKEY_DestroyPublicKey(publicKey); } if ( privateKey ) { SECKEY_DestroyPrivateKey(privateKey); } if (slot) { PK11_FreeSlot(slot); } if (KeygenRunnable) { NS_RELEASE(KeygenRunnable); } if (keyparamsString) { free(keyparamsString); } if (pkac.challenge.data) { free(pkac.challenge.data); } // If params is non-null and doesn't point to rsaParams, it was allocated // in decode_ec_params. We have to free this memory. if (params && params != &rsaParams) { SECITEM_FreeItem(static_cast<SECItem*>(params), true); params = nullptr; } return rv; }
bool nsTemplateCondition::CheckMatchStrings(const nsAString& aLeftString, const nsAString& aRightString) { bool match = false; if (aRightString.IsEmpty()) { if ((mRelation == eEquals) && aLeftString.IsEmpty()) match = true; } else { switch (mRelation) { case eEquals: if (mIgnoreCase) match = aLeftString.Equals(aRightString, nsCaseInsensitiveStringComparator()); else match = aLeftString.Equals(aRightString); break; case eLess: case eGreater: { // non-numbers always compare false nsresult err; PRInt32 leftint = PromiseFlatString(aLeftString).ToInteger(&err); if (NS_SUCCEEDED(err)) { PRInt32 rightint = PromiseFlatString(aRightString).ToInteger(&err); if (NS_SUCCEEDED(err)) { match = (mRelation == eLess) ? (leftint < rightint) : (leftint > rightint); } } break; } case eBefore: { nsICollation* collation = nsXULContentUtils::GetCollation(); if (collation) { PRInt32 sortOrder; collation->CompareString((mIgnoreCase ? static_cast<PRInt32>(nsICollation::kCollationCaseInSensitive) : static_cast<PRInt32>(nsICollation::kCollationCaseSensitive)), aLeftString, aRightString, &sortOrder); match = (sortOrder < 0); } else if (mIgnoreCase) { match = (Compare(aLeftString, aRightString, nsCaseInsensitiveStringComparator()) < 0); } else { match = (Compare(aLeftString, aRightString) < 0); } break; } case eAfter: { nsICollation* collation = nsXULContentUtils::GetCollation(); if (collation) { PRInt32 sortOrder; collation->CompareString((mIgnoreCase ? static_cast<PRInt32>(nsICollation::kCollationCaseInSensitive) : static_cast<PRInt32>(nsICollation::kCollationCaseSensitive)), aLeftString, aRightString, &sortOrder); match = (sortOrder > 0); } else if (mIgnoreCase) { match = (Compare(aLeftString, aRightString, nsCaseInsensitiveStringComparator()) > 0); } else { match = (Compare(aLeftString, aRightString) > 0); } break; } case eStartswith: if (mIgnoreCase) match = (StringBeginsWith(aLeftString, aRightString, nsCaseInsensitiveStringComparator())); else match = (StringBeginsWith(aLeftString, aRightString)); break; case eEndswith: if (mIgnoreCase) match = (StringEndsWith(aLeftString, aRightString, nsCaseInsensitiveStringComparator())); else match = (StringEndsWith(aLeftString, aRightString)); break; case eContains: { nsAString::const_iterator start, end; aLeftString.BeginReading(start); aLeftString.EndReading(end); if (mIgnoreCase) match = CaseInsensitiveFindInReadable(aRightString, start, end); else match = FindInReadable(aRightString, start, end); break; } default: break; } } if (mNegate) match = !match; return match; }
nsresult nsMsgSearchAdapter::GetSearchCharsets(nsAString &srcCharset, nsAString &dstCharset) { nsresult rv; if (m_defaultCharset.IsEmpty()) { m_forceAsciiSearch = false; // set the default value in case of error nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIPrefLocalizedString> localizedstr; rv = prefs->GetComplexValue("mailnews.view_default_charset", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(localizedstr)); if (NS_SUCCEEDED(rv)) localizedstr->GetData(getter_Copies(m_defaultCharset)); prefs->GetBoolPref("mailnews.force_ascii_search", &m_forceAsciiSearch); } } srcCharset = m_defaultCharset.IsEmpty() ? NS_LITERAL_STRING("ISO-8859-1") : m_defaultCharset; if (m_scope) { // ### DMB is there a way to get the charset for the "window"? nsCOMPtr<nsIMsgFolder> folder; rv = m_scope->GetFolder(getter_AddRefs(folder)); // Ask the newsgroup/folder for its csid. if (NS_SUCCEEDED(rv) && folder) { nsCString folderCharset; folder->GetCharset(folderCharset); dstCharset.Append(NS_ConvertASCIItoUTF16(folderCharset)); } } else dstCharset.Assign(srcCharset); // If // the destination is still CS_DEFAULT, make the destination match // the source. (CS_DEFAULT is an indication that the charset // was undefined or unavailable.) // ### well, it's not really anymore. Is there an equivalent? if (dstCharset.Equals(m_defaultCharset)) { dstCharset.Assign(srcCharset); } if (m_forceAsciiSearch) { // Special cases to use in order to force US-ASCII searching with Latin1 // or MacRoman text. Eurgh. This only has to happen because IMAP // and Dredd servers currently (4/23/97) only support US-ASCII. // // If the dest csid is ISO Latin 1 or MacRoman, attempt to convert the // source text to US-ASCII. (Not for now.) // if ((dst_csid == CS_LATIN1) || (dst_csid == CS_MAC_ROMAN)) dstCharset.AssignLiteral("us-ascii"); } return NS_OK; }
NS_IMETHODIMP StaticAtom::ScriptableEquals(const nsAString& aString, bool* aResult) { *aResult = aString.Equals(nsDependentString(mString, mLength)); return NS_OK; }
nsresult nsKeygenFormProcessor::GetPublicKey(nsAString& aValue, nsAString& aChallenge, nsAFlatString& aKeyType, nsAString& aOutPublicKey, nsAString& aKeyParams) { nsNSSShutDownPreventionLock locker; nsresult rv = NS_ERROR_FAILURE; char *keystring = nsnull; char *keyparamsString = nsnull, *str = nsnull; KeyType type; PRUint32 keyGenMechanism; PRInt32 primeBits; PK11SlotInfo *slot = nsnull; PK11RSAGenParams rsaParams; SECOidTag algTag; int keysize = 0; void *params; SECKEYPrivateKey *privateKey = nsnull; SECKEYPublicKey *publicKey = nsnull; CERTSubjectPublicKeyInfo *spkInfo = nsnull; PRArenaPool *arena = nsnull; SECStatus sec_rv = SECFailure; SECItem spkiItem; SECItem pkacItem; SECItem signedItem; CERTPublicKeyAndChallenge pkac; pkac.challenge.data = nsnull; nsIGeneratingKeypairInfoDialogs * dialogs; nsKeygenThread *KeygenRunnable = 0; nsCOMPtr<nsIKeygenThread> runnable; // Get the key size // for (size_t i = 0; i < number_of_key_size_choices; ++i) { if (aValue.Equals(mSECKeySizeChoiceList[i].name)) { keysize = mSECKeySizeChoiceList[i].size; break; } } if (!keysize) { goto loser; } arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); if (!arena) { goto loser; } // Set the keygen mechanism if (aKeyType.IsEmpty() || aKeyType.LowerCaseEqualsLiteral("rsa")) { type = rsaKey; keyGenMechanism = CKM_RSA_PKCS_KEY_PAIR_GEN; } else if (aKeyType.LowerCaseEqualsLiteral("dsa")) { char * end; keyparamsString = ToNewCString(aKeyParams); if (!keyparamsString) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } type = dsaKey; keyGenMechanism = CKM_DSA_KEY_PAIR_GEN; if (strcmp(keyparamsString, "null") == 0) goto loser; str = keyparamsString; PRBool found_match = PR_FALSE; do { end = strchr(str, ','); if (end != nsnull) *end = '\0'; primeBits = pqg_prime_bits(str); if (keysize == primeBits) { found_match = PR_TRUE; break; } str = end + 1; } while (end != nsnull); if (!found_match) { goto loser; } } else if (aKeyType.LowerCaseEqualsLiteral("ec")) { keyparamsString = ToNewCString(aKeyParams); if (!keyparamsString) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } type = ecKey; keyGenMechanism = CKM_EC_KEY_PAIR_GEN; /* ecParams are initialized later */ } else { goto loser; } // Get the slot rv = GetSlot(keyGenMechanism, &slot); if (NS_FAILED(rv)) { goto loser; } switch (keyGenMechanism) { case CKM_RSA_PKCS_KEY_PAIR_GEN: rsaParams.keySizeInBits = keysize; rsaParams.pe = DEFAULT_RSA_KEYGEN_PE; algTag = DEFAULT_RSA_KEYGEN_ALG; params = &rsaParams; break; case CKM_DSA_KEY_PAIR_GEN: // XXX Fix this! XXX // goto loser; case CKM_EC_KEY_PAIR_GEN: /* XXX We ought to rethink how the KEYGEN tag is * displayed. The pulldown selections presented * to the user must depend on the keytype. * The displayed selection could be picked * from the keyparams attribute (this is currently called * the pqg attribute). * For now, we pick ecparams from the keyparams field * if it specifies a valid supported curve, or else * we pick one of secp384r1, secp256r1 or secp192r1 * respectively depending on the user's selection * (High, Medium, Low). * (RSA uses RSA-2048, RSA-1024 and RSA-512 for historical * reasons, while ECC choices represent a stronger mapping) * NOTE: The user's selection * is silently ignored when a valid curve is presented * in keyparams. */ if ((params = decode_ec_params(keyparamsString)) == nsnull) { /* The keyparams attribute did not specify a valid * curve name so use a curve based on the keysize. * NOTE: Here keysize is used only as an indication of * High/Medium/Low strength; elliptic curve * cryptography uses smaller keys than RSA to provide * equivalent security. */ switch (keysize) { case 2048: params = decode_ec_params("secp384r1"); break; case 1024: case 512: params = decode_ec_params("secp256r1"); break; } } /* XXX The signature algorithm ought to choose the hashing * algorithm based on key size once ECDSA variations based * on SHA256 SHA384 and SHA512 are standardized. */ algTag = SEC_OID_ANSIX962_ECDSA_SIGNATURE_WITH_SHA1_DIGEST; break; default: goto loser; } /* Make sure token is initialized. */ rv = setPassword(slot, m_ctx); if (NS_FAILED(rv)) goto loser; sec_rv = PK11_Authenticate(slot, PR_TRUE, m_ctx); if (sec_rv != SECSuccess) { goto loser; } rv = getNSSDialogs((void**)&dialogs, NS_GET_IID(nsIGeneratingKeypairInfoDialogs), NS_GENERATINGKEYPAIRINFODIALOGS_CONTRACTID); if (NS_SUCCEEDED(rv)) { KeygenRunnable = new nsKeygenThread(); NS_IF_ADDREF(KeygenRunnable); } if (NS_FAILED(rv) || !KeygenRunnable) { rv = NS_OK; privateKey = PK11_GenerateKeyPair(slot, keyGenMechanism, params, &publicKey, PR_TRUE, PR_TRUE, m_ctx); } else { KeygenRunnable->SetParams( slot, keyGenMechanism, params, PR_TRUE, PR_TRUE, m_ctx ); runnable = do_QueryInterface(KeygenRunnable); if (runnable) { { nsPSMUITracker tracker; if (tracker.isUIForbidden()) { rv = NS_ERROR_NOT_AVAILABLE; } else { rv = dialogs->DisplayGeneratingKeypairInfo(m_ctx, runnable); // We call join on the thread, // so we can be sure that no simultaneous access to the passed parameters will happen. KeygenRunnable->Join(); } } NS_RELEASE(dialogs); if (NS_SUCCEEDED(rv)) { rv = KeygenRunnable->GetParams(&privateKey, &publicKey); } } } if (NS_FAILED(rv) || !privateKey) { goto loser; } // just in case we'll need to authenticate to the db -jp // privateKey->wincx = m_ctx; /* * Create a subject public key info from the public key. */ spkInfo = SECKEY_CreateSubjectPublicKeyInfo(publicKey); if ( !spkInfo ) { goto loser; } /* * Now DER encode the whole subjectPublicKeyInfo. */ sec_rv=DER_Encode(arena, &spkiItem, CERTSubjectPublicKeyInfoTemplate, spkInfo); if (sec_rv != SECSuccess) { goto loser; } /* * set up the PublicKeyAndChallenge data structure, then DER encode it */ pkac.spki = spkiItem; pkac.challenge.len = aChallenge.Length(); pkac.challenge.data = (unsigned char *)ToNewCString(aChallenge); if (!pkac.challenge.data) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } sec_rv = DER_Encode(arena, &pkacItem, CERTPublicKeyAndChallengeTemplate, &pkac); if ( sec_rv != SECSuccess ) { goto loser; } /* * now sign the DER encoded PublicKeyAndChallenge */ sec_rv = SEC_DerSignData(arena, &signedItem, pkacItem.data, pkacItem.len, privateKey, algTag); if ( sec_rv != SECSuccess ) { goto loser; } /* * Convert the signed public key and challenge into base64/ascii. */ keystring = BTOA_DataToAscii(signedItem.data, signedItem.len); if (!keystring) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; } CopyASCIItoUTF16(keystring, aOutPublicKey); nsCRT::free(keystring); rv = NS_OK; loser: if ( sec_rv != SECSuccess ) { if ( privateKey ) { PK11_DestroyTokenObject(privateKey->pkcs11Slot,privateKey->pkcs11ID); } if ( publicKey ) { PK11_DestroyTokenObject(publicKey->pkcs11Slot,publicKey->pkcs11ID); } } if ( spkInfo ) { SECKEY_DestroySubjectPublicKeyInfo(spkInfo); } if ( publicKey ) { SECKEY_DestroyPublicKey(publicKey); } if ( privateKey ) { SECKEY_DestroyPrivateKey(privateKey); } if ( arena ) { PORT_FreeArena(arena, PR_TRUE); } if (slot != nsnull) { PK11_FreeSlot(slot); } if (KeygenRunnable) { NS_RELEASE(KeygenRunnable); } if (keyparamsString) { nsMemory::Free(keyparamsString); } if (pkac.challenge.data) { nsMemory::Free(pkac.challenge.data); } return rv; }
void BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex, uint16_t aCallState, const nsAString& aError, const nsAString& aNumber, const bool aIsOutgoing, const bool aIsConference, bool aSend) { // aCallIndex can be UINT32_MAX for the pending outgoing call state update. // aCallIndex will be updated again after real call state changes. See Bug // 990467. if (aCallIndex == UINT32_MAX) { return; } // Update call state only while (aCallIndex >= mCurrentCallArray.Length()) { Call call; mCurrentCallArray.AppendElement(call); } mCurrentCallArray[aCallIndex].mState = aCallState; // Return if SLC is disconnected if (!IsConnected()) { return; } // Update call information besides call state mCurrentCallArray[aCallIndex].Set(aNumber, aIsOutgoing); // Notify bluedroid of phone state change if this // call state change is not during transition state if (!IsTransitionState(aCallState, aIsConference)) { UpdatePhoneCIND(aCallIndex); } switch (aCallState) { case nsITelephonyService::CALL_STATE_DIALING: // We've send Dialer a dialing request and this is the response. if (!mDialingRequestProcessed) { SendResponse(HFP_AT_RESPONSE_OK); mDialingRequestProcessed = true; } break; case nsITelephonyService::CALL_STATE_DISCONNECTED: // -1 is necessary because call 0 is an invalid (padding) call object. if (mCurrentCallArray.Length() - 1 == GetNumberOfCalls(nsITelephonyService::CALL_STATE_DISCONNECTED)) { // In order to let user hear busy tone via connected Bluetooth headset, // we postpone the timing of dropping SCO. if (aError.Equals(NS_LITERAL_STRING("BusyError"))) { // FIXME: UpdatePhoneCIND later since it causes SCO close but // Dialer is still playing busy tone via HF. NS_DispatchToMainThread(new CloseScoRunnable()); } ResetCallArray(); } break; default: break; } }
bool nsObserverEntry::Matches(const nsAString& aString) { bool result = aString.Equals(mTopic); return result; }
/* void setPreference (in AString aPrefName, in nsIVariant aPrefValue); */ NS_IMETHODIMP sbMockDevice::SetPreference(const nsAString & aPrefName, nsIVariant *aPrefValue) { NS_ENSURE_ARG_POINTER(aPrefValue); nsresult rv; nsCOMPtr<nsIPrefService> prefRoot = do_GetService("@mozilla.org/preferences-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPrefBranch> prefBranch; rv = prefRoot->GetBranch(DEVICE_PREF_BRANCH, getter_AddRefs(prefBranch)); NS_ENSURE_SUCCESS(rv, rv); NS_LossyConvertUTF16toASCII prefNameC(aPrefName); PRUint16 prefType; rv = aPrefValue->GetDataType(&prefType); NS_ENSURE_SUCCESS(rv, rv); PRInt32 oldPrefType; rv = prefBranch->GetPrefType(prefNameC.get(), &oldPrefType); NS_ENSURE_SUCCESS(rv, rv); switch(prefType) { case nsIDataType::VTYPE_INT8: case nsIDataType::VTYPE_INT16: case nsIDataType::VTYPE_INT32: case nsIDataType::VTYPE_INT64: case nsIDataType::VTYPE_UINT8: case nsIDataType::VTYPE_UINT16: case nsIDataType::VTYPE_UINT32: case nsIDataType::VTYPE_UINT64: { if (oldPrefType != nsIPrefBranch::PREF_INVALID && oldPrefType != nsIPrefBranch::PREF_INT) { rv = prefBranch->ClearUserPref(prefNameC.get()); NS_ENSURE_SUCCESS(rv, rv); } PRInt32 value; rv = aPrefValue->GetAsInt32(&value); NS_ENSURE_SUCCESS(rv, rv); rv = prefBranch->SetIntPref(prefNameC.get(), value); NS_ENSURE_SUCCESS(rv, rv); /* special case for state */ if (aPrefName.Equals(NS_LITERAL_STRING("state"))) { mState = value; } break; } case nsIDataType::VTYPE_BOOL: { if (oldPrefType != nsIPrefBranch::PREF_INVALID && oldPrefType != nsIPrefBranch::PREF_BOOL) { rv = prefBranch->ClearUserPref(prefNameC.get()); NS_ENSURE_SUCCESS(rv, rv); } bool value; rv = aPrefValue->GetAsBool(&value); NS_ENSURE_SUCCESS(rv, rv); rv = prefBranch->SetBoolPref(prefNameC.get(), value); NS_ENSURE_SUCCESS(rv, rv); break; } default: { if (oldPrefType != nsIPrefBranch::PREF_INVALID && oldPrefType != nsIPrefBranch::PREF_STRING) { rv = prefBranch->ClearUserPref(prefNameC.get()); NS_ENSURE_SUCCESS(rv, rv); } nsCString value; rv = aPrefValue->GetAsACString(value); NS_ENSURE_SUCCESS(rv, rv); rv = prefBranch->SetCharPref(prefNameC.get(), value.get()); NS_ENSURE_SUCCESS(rv, rv); break; } } return NS_OK; }
bool BasicCardService::IsBasicCardPayment(const nsAString& aSupportedMethods) { return aSupportedMethods.Equals(NS_LITERAL_STRING("basic-card")); }
NS_IMETHODIMP sbWindowWatcher::GetWindow(const nsAString& aWindowType, nsIDOMWindow** _retval) { // Validate arguments. NS_ENSURE_ARG_POINTER(_retval); // Function variables. nsCOMPtr<nsIDOMWindow> retWindow; bool success; nsresult rv; // This method may only be called on the main thread. NS_ENSURE_TRUE(SB_IsMainThread(mThreadManager), NS_ERROR_UNEXPECTED); // Operate within the monitor. mozilla::ReentrantMonitorAutoEnter autoMonitor(mMonitor); // Get an enumerator of all windows of the specified type, sorted from oldest // to youngest. nsCOMPtr<nsISimpleEnumerator> enumerator; rv = mWindowMediator->GetEnumerator(aWindowType.BeginReading(), getter_AddRefs(enumerator)); NS_ENSURE_SUCCESS(rv, rv); // Search for the most recently focused ready window of the specified type. // The enumerator enumerates from oldest to youngest (least recently focused // to most recently), so the last matching window is the most recently focused // one. bool hasMoreElements; rv = enumerator->HasMoreElements(&hasMoreElements); NS_ENSURE_SUCCESS(rv, rv); while (hasMoreElements) { // Get the window. Skip if not ready. nsCOMPtr<nsISupports> _window; nsCOMPtr<nsIDOMWindow> window; rv = enumerator->GetNext(getter_AddRefs(_window)); NS_ENSURE_SUCCESS(rv, rv); window = do_QueryInterface(_window, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = enumerator->HasMoreElements(&hasMoreElements); NS_ENSURE_SUCCESS(rv, rv); // Skip window if not ready. WindowInfo* windowInfo; success = mWindowInfoTable.Get(window, &windowInfo); if (!success || !(windowInfo->isReady)) continue; // Get the window type. nsAutoString windowType; rv = GetWindowType(window, windowType); if (NS_FAILED(rv)) continue; // Check for a match. if (aWindowType.Equals(windowType)) { retWindow = window; } } // Return results. NS_IF_ADDREF(*_retval = retWindow); return NS_OK; }
NS_IMETHODIMP mozSpellChecker::Replace(const nsAString &aOldWord, const nsAString &aNewWord, bool aAllOccurrences) { if(!mConverter) return NS_ERROR_NULL_POINTER; nsAutoString newWord(aNewWord); // sigh if(aAllOccurrences){ int32_t selOffset; int32_t startBlock,currentBlock,currOffset; int32_t begin,end; bool done; nsresult result; nsAutoString str; // find out where we are result = SetupDoc(&selOffset); if(NS_FAILED(result)) return result; result = GetCurrentBlockIndex(mTsDoc,&startBlock); if(NS_FAILED(result)) return result; //start at the beginning result = mTsDoc->FirstBlock(); currOffset=0; currentBlock = 0; while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) { result = mTsDoc->GetCurrentTextBlock(&str); do{ result = mConverter->FindNextWord(str.get(),str.Length(),currOffset,&begin,&end); if(NS_SUCCEEDED(result)&&(begin != -1)){ if (aOldWord.Equals(Substring(str, begin, end-begin))) { // if we are before the current selection point but in the same block // move the selection point forwards if((currentBlock == startBlock)&&(begin < selOffset)){ selOffset += int32_t(aNewWord.Length()) - int32_t(aOldWord.Length()); if(selOffset < begin) selOffset=begin; } mTsDoc->SetSelection(begin, end-begin); mTsDoc->InsertText(&newWord); mTsDoc->GetCurrentTextBlock(&str); end += (aNewWord.Length() - aOldWord.Length()); // recursion was cute in GEB, not here. } } currOffset = end; }while(currOffset != -1); mTsDoc->NextBlock(); currentBlock++; currOffset=0; } // We are done replacing. Put the selection point back where we found it (or equivalent); result = mTsDoc->FirstBlock(); currentBlock = 0; while(( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) &&(currentBlock < startBlock)){ mTsDoc->NextBlock(); } //After we have moved to the block where the first occurrence of replace was done, put the //selection to the next word following it. In case there is no word following it i.e if it happens //to be the last word in that block, then move to the next block and put the selection to the //first word in that block, otherwise when the Setupdoc() is called, it queries the LastSelectedBlock() //and the selection offset of the last occurrence of the replaced word is taken instead of the first //occurrence and things get messed up as reported in the bug 244969 if( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ){ nsString str; result = mTsDoc->GetCurrentTextBlock(&str); result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end); if(end == -1) { mTsDoc->NextBlock(); selOffset=0; result = mTsDoc->GetCurrentTextBlock(&str); result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end); mTsDoc->SetSelection(begin, 0); } else mTsDoc->SetSelection(begin, 0); } } else{ mTsDoc->InsertText(&newWord); } return NS_OK; }
PRBool nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix, const nsAString& aURI, nsIDOMElement* aElement, PRBool aIsAttribute) { if (aPrefix.EqualsLiteral(kXMLNS)) { return PR_FALSE; } if (aURI.EqualsLiteral("http://www.w3.org/XML/1998/namespace")) { // The prefix must be xml for this namespace. We don't need to declare it, // so always just set the prefix to xml. aPrefix.AssignLiteral("xml"); return PR_FALSE; } PRBool mustHavePrefix; if (aIsAttribute) { if (aURI.IsEmpty()) { // Attribute in the null namespace. This just shouldn't have a prefix. // And there's no need to push any namespace decls aPrefix.Truncate(); return PR_FALSE; } // Attribute not in the null namespace -- must have a prefix mustHavePrefix = PR_TRUE; } else { // Not an attribute, so doesn't _have_ to have a prefix mustHavePrefix = PR_FALSE; } // Keep track of the closest prefix that's bound to aURI and whether we've // found such a thing. closestURIMatch holds the prefix, and uriMatch // indicates whether we actually have one. nsAutoString closestURIMatch; PRBool uriMatch = PR_FALSE; // Also keep track of whether we've seen aPrefix already. If we have, that // means that it's already bound to a URI different from aURI, so even if we // later (so in a more outer scope) see it bound to aURI we can't reuse it. PRBool haveSeenOurPrefix = PR_FALSE; PRInt32 count = mNameSpaceStack.Count(); PRInt32 index = count - 1; while (index >= 0) { NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index); // Check if we've found a prefix match if (aPrefix.Equals(decl->mPrefix)) { // If the URIs match and aPrefix is not bound to any other URI, we can // use aPrefix if (!haveSeenOurPrefix && aURI.Equals(decl->mURI)) { // Just use our uriMatch stuff. That will deal with an empty aPrefix // the right way. We can break out of the loop now, though. uriMatch = PR_TRUE; closestURIMatch = aPrefix; break; } haveSeenOurPrefix = PR_TRUE; // If they don't, and either: // 1) We have a prefix (so we'd be redeclaring this prefix to point to a // different namespace) or // 2) We're looking at an existing default namespace decl on aElement (so // we can't create a new default namespace decl for this URI) // then generate a new prefix. Note that we do NOT generate new prefixes // if we happen to have aPrefix == decl->mPrefix == "" and mismatching // URIs when |decl| doesn't have aElement as its owner. In that case we // can simply push the new namespace URI as the default namespace for // aElement. if (!aPrefix.IsEmpty() || decl->mOwner == aElement) { NS_ASSERTION(!aURI.IsEmpty(), "Not allowed to add a xmlns attribute with an empty " "namespace name unless it declares the default " "namespace."); GenerateNewPrefix(aPrefix); // Now we need to validate our new prefix/uri combination; check it // against the full namespace stack again. Note that just restarting // the while loop is ok, since we haven't changed aURI, so the // closestURIMatch and uriMatch state is not affected. index = count - 1; haveSeenOurPrefix = PR_FALSE; continue; } } // If we've found a URI match, then record the first one if (!uriMatch && aURI.Equals(decl->mURI)) { // Need to check that decl->mPrefix is not declared anywhere closer to // us. If it is, we can't use it. PRBool prefixOK = PR_TRUE; PRInt32 index2; for (index2 = count-1; index2 > index && prefixOK; --index2) { NameSpaceDecl* decl2 = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index2); prefixOK = (decl2->mPrefix != decl->mPrefix); } if (prefixOK) { uriMatch = PR_TRUE; closestURIMatch.Assign(decl->mPrefix); } } --index; } // At this point the following invariants hold: // 1) The prefix in closestURIMatch is mapped to aURI in our scope if // uriMatch is set. // 2) There is nothing on the namespace stack that has aPrefix as the prefix // and a _different_ URI, except for the case aPrefix.IsEmpty (and // possible default namespaces on ancestors) // So if uriMatch is set it's OK to use the closestURIMatch prefix. The one // exception is when closestURIMatch is actually empty (default namespace // decl) and we must have a prefix. if (uriMatch && (!mustHavePrefix || !closestURIMatch.IsEmpty())) { aPrefix.Assign(closestURIMatch); return PR_FALSE; } if (aPrefix.IsEmpty()) { // At this point, aPrefix is empty (which means we never had a prefix to // start with). If we must have a prefix, just generate a new prefix and // then send it back through the namespace stack checks to make sure it's // OK. if (mustHavePrefix) { GenerateNewPrefix(aPrefix); return ConfirmPrefix(aPrefix, aURI, aElement, aIsAttribute); } // One final special case. If aPrefix is empty and we never saw an empty // prefix (default namespace decl) on the namespace stack and we're in the // null namespace there is no reason to output an |xmlns=""| here. It just // makes the output less readable. if (!haveSeenOurPrefix && aURI.IsEmpty()) { return PR_FALSE; } } // Now just set aURI as the new default namespace URI. Indicate that we need // to create a namespace decl for the final prefix return PR_TRUE; }
// TODO - eventually, we will want to factor this method // out into different system specific subclasses (or // something) PRInt32 nsDOMDeviceStorage::SetRootFileForType(const nsAString& aType, const PRInt32 aIndex) { PRInt32 typeResult = DEVICE_STORAGE_TYPE_DEFAULT; nsCOMPtr<nsIFile> f; nsCOMPtr<nsIProperties> dirService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); NS_ASSERTION(dirService, "Must have directory service"); // Picture directory if (aType.Equals(NS_LITERAL_STRING("pictures"))) { #ifdef MOZ_WIDGET_GONK if (aIndex == 0) { NS_NewLocalFile(NS_LITERAL_STRING("/data/pictures"), false, getter_AddRefs(f)); } else if (aIndex == 1) { NS_NewLocalFile(NS_LITERAL_STRING("/sdcard/DCIM"), false, getter_AddRefs(f)); typeResult = DEVICE_STORAGE_TYPE_EXTERNAL; } #elif defined (MOZ_WIDGET_COCOA) if (aIndex == 0) { dirService->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } #elif defined (XP_UNIX) if (aIndex == 0) { dirService->Get(NS_UNIX_XDG_PICTURES_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } #endif } // Video directory if (aType.Equals(NS_LITERAL_STRING("videos"))) { #ifdef MOZ_WIDGET_GONK if (aIndex == 0) { NS_NewLocalFile(NS_LITERAL_STRING("/data/videos"), false, getter_AddRefs(f)); } else if (aIndex == 1) { NS_NewLocalFile(NS_LITERAL_STRING("/sdcard/videos"), false, getter_AddRefs(f)); typeResult = DEVICE_STORAGE_TYPE_EXTERNAL; } #elif defined (MOZ_WIDGET_COCOA) if (aIndex == 0) { dirService->Get(NS_OSX_MOVIE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } #elif defined (XP_UNIX) if (aIndex == 0) { dirService->Get(NS_UNIX_XDG_VIDEOS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } #endif } // Music directory if (aType.Equals(NS_LITERAL_STRING("music"))) { #ifdef MOZ_WIDGET_GONK if (aIndex == 0) { NS_NewLocalFile(NS_LITERAL_STRING("/data/music"), false, getter_AddRefs(f)); } else if (aIndex == 1) { NS_NewLocalFile(NS_LITERAL_STRING("/sdcard/music"), false, getter_AddRefs(f)); typeResult = DEVICE_STORAGE_TYPE_EXTERNAL; } #elif defined (MOZ_WIDGET_COCOA) if (aIndex == 0) { dirService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } #elif defined (XP_UNIX) if (aIndex == 0) { dirService->Get(NS_UNIX_XDG_MUSIC_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } #endif } // in testing, we have access to a few more directory locations if (mozilla::Preferences::GetBool("device.storage.testing", false)) { // Temp directory if (aType.Equals(NS_LITERAL_STRING("temp")) && aIndex == 0) { dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } // Profile directory else if (aType.Equals(NS_LITERAL_STRING("profile")) && aIndex == 0) { dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); } } mFile = f; return typeResult; }