本文整理汇总了C++中nsAString::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAString::IsEmpty方法的具体用法?C++ nsAString::IsEmpty怎么用?C++ nsAString::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAString
的用法示例。
在下文中一共展示了nsAString::IsEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetRealFormat
NS_IMETHODIMP
DataTransfer::MozGetDataAt(const nsAString& aFormat, uint32_t aIndex,
nsIVariant** aData)
{
*aData = nullptr;
if (aFormat.IsEmpty())
return NS_OK;
if (aIndex >= mItems.Length()) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
// Only the first item is valid for clipboard events
if (aIndex > 0 &&
(mEventType == NS_CUT || mEventType == NS_COPY || mEventType == NS_PASTE)) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
nsAutoString format;
GetRealFormat(aFormat, format);
nsTArray<TransferItem>& item = mItems[aIndex];
// Check if the caller is allowed to access the drag data. Callers with
// chrome privileges can always read the data. During the
// drop event, allow retrieving the data except in the case where the
// source of the drag is in a child frame of the caller. In that case,
// we only allow access to data of the same principal. During other events,
// only allow access to the data with the same principal.
nsIPrincipal* principal = nullptr;
if (mIsCrossDomainSubFrameDrop ||
(mEventType != NS_DRAGDROP_DROP && mEventType != NS_DRAGDROP_DRAGDROP &&
mEventType != NS_PASTE &&
!nsContentUtils::IsCallerChrome())) {
principal = nsContentUtils::SubjectPrincipal();
}
uint32_t count = item.Length();
for (uint32_t i = 0; i < count; i++) {
TransferItem& formatitem = item[i];
if (formatitem.mFormat.Equals(format)) {
bool subsumes;
if (formatitem.mPrincipal && principal &&
(NS_FAILED(principal->Subsumes(formatitem.mPrincipal, &subsumes)) || !subsumes))
return NS_ERROR_DOM_SECURITY_ERR;
if (!formatitem.mData) {
FillInExternalData(formatitem, aIndex);
} else {
nsCOMPtr<nsISupports> data;
formatitem.mData->GetAsISupports(getter_AddRefs(data));
// Make sure the code that is calling us is same-origin with the data.
nsCOMPtr<EventTarget> pt = do_QueryInterface(data);
if (pt) {
nsresult rv = NS_OK;
nsIScriptContext* c = pt->GetContextForEventHandlers(&rv);
NS_ENSURE_TRUE(c && NS_SUCCEEDED(rv), NS_ERROR_DOM_SECURITY_ERR);
nsIGlobalObject* go = c->GetGlobalObject();
NS_ENSURE_TRUE(go, NS_ERROR_DOM_SECURITY_ERR);
nsCOMPtr<nsIScriptObjectPrincipal> sp = do_QueryInterface(go);
MOZ_ASSERT(sp, "This cannot fail on the main thread.");
nsIPrincipal* dataPrincipal = sp->GetPrincipal();
NS_ENSURE_TRUE(dataPrincipal, NS_ERROR_DOM_SECURITY_ERR);
if (!principal) {
principal = nsContentUtils::SubjectPrincipal();
}
bool equals = false;
NS_ENSURE_TRUE(NS_SUCCEEDED(principal->Equals(dataPrincipal, &equals)) && equals,
NS_ERROR_DOM_SECURITY_ERR);
}
}
*aData = formatitem.mData;
NS_IF_ADDREF(*aData);
return NS_OK;
}
}
return NS_OK;
}
示例2: presShell
NS_IMETHODIMP
nsTypeAheadFind::Find(const nsAString& aSearchString, bool aLinksOnly,
uint16_t* aResult)
{
*aResult = FIND_NOTFOUND;
nsCOMPtr<nsIPresShell> presShell (GetPresShell());
if (!presShell) {
nsCOMPtr<nsIDocShell> ds (do_QueryReferent(mDocShell));
NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE);
presShell = ds->GetPresShell();
mPresShell = do_GetWeakReference(presShell);
}
nsCOMPtr<nsISelection> selection;
nsCOMPtr<nsISelectionController> selectionController =
do_QueryReferent(mSelectionController);
if (!selectionController) {
GetSelection(presShell, getter_AddRefs(selectionController),
getter_AddRefs(selection)); // cache for reuse
mSelectionController = do_GetWeakReference(selectionController);
} else {
selectionController->GetSelection(
nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
}
if (selection)
selection->CollapseToStart();
if (aSearchString.IsEmpty()) {
mTypeAheadBuffer.Truncate();
// These will be initialized to their true values after the first character
// is typed
mStartFindRange = nullptr;
mSelectionController = nullptr;
*aResult = FIND_FOUND;
return NS_OK;
}
bool atEnd = false;
if (mTypeAheadBuffer.Length()) {
const nsAString& oldStr = Substring(mTypeAheadBuffer, 0, mTypeAheadBuffer.Length());
const nsAString& newStr = Substring(aSearchString, 0, mTypeAheadBuffer.Length());
if (oldStr.Equals(newStr))
atEnd = true;
const nsAString& newStr2 = Substring(aSearchString, 0, aSearchString.Length());
const nsAString& oldStr2 = Substring(mTypeAheadBuffer, 0, aSearchString.Length());
if (oldStr2.Equals(newStr2))
atEnd = true;
if (!atEnd)
mStartFindRange = nullptr;
}
if (!mIsSoundInitialized && !mNotFoundSoundURL.IsEmpty()) {
// This makes sure system sound library is loaded so that
// there's no lag before the first sound is played
// by waiting for the first keystroke, we still get the startup time benefits.
mIsSoundInitialized = true;
mSoundInterface = do_CreateInstance("@mozilla.org/sound;1");
if (mSoundInterface && !mNotFoundSoundURL.Equals(NS_LITERAL_CSTRING("beep"))) {
mSoundInterface->Init();
}
}
#ifdef XP_WIN
// After each keystroke, ensure sound object is destroyed, to free up memory
// allocated for error sound, otherwise Windows' nsISound impl
// holds onto the last played sound, using up memory.
mSoundInterface = nullptr;
#endif
int32_t bufferLength = mTypeAheadBuffer.Length();
mTypeAheadBuffer = aSearchString;
bool isFirstVisiblePreferred = false;
// --------- Initialize find if 1st char ----------
if (bufferLength == 0) {
// If you can see the selection (not collapsed or thru caret browsing),
// or if already focused on a page element, start there.
// Otherwise we're going to start at the first visible element
bool isSelectionCollapsed = true;
if (selection)
selection->GetIsCollapsed(&isSelectionCollapsed);
// If true, we will scan from top left of visible area
// If false, we will scan from start of selection
isFirstVisiblePreferred = !atEnd && !mCaretBrowsingOn && isSelectionCollapsed;
if (isFirstVisiblePreferred) {
// Get the focused content. If there is a focused node, ensure the
// selection is at that point. Otherwise, we will just want to start
// from the caret position or the beginning of the document.
nsPresContext* presContext = presShell->GetPresContext();
NS_ENSURE_TRUE(presContext, NS_OK);
//.........这里部分代码省略.........
示例3: WriteInchesFromTwipsPref
//.........这里部分代码省略.........
if (aFlags & nsIPrintSettings::kInitSavePlexName) {
if (NS_SUCCEEDED(aPS->GetPlexName(&uStr))) {
DUMP_STR(kWriteStr, kPrintPlexName, uStr);
Preferences::SetString(GetPrefName(kPrintPlexName, aPrinterName), uStr);
}
}
if (aFlags & nsIPrintSettings::kInitSavePaperData) {
if (NS_SUCCEEDED(aPS->GetPaperData(&iVal16))) {
DUMP_INT(kWriteStr, kPrintPaperData, iVal16);
Preferences::SetInt(GetPrefName(kPrintPaperData, aPrinterName),
int32_t(iVal16));
}
}
if (aFlags & nsIPrintSettings::kInitSaveColorspace) {
if (NS_SUCCEEDED(aPS->GetColorspace(&uStr))) {
DUMP_STR(kWriteStr, kPrintColorspace, uStr);
Preferences::SetString(GetPrefName(kPrintColorspace, aPrinterName), uStr);
}
}
if (aFlags & nsIPrintSettings::kInitSaveResolutionName) {
if (NS_SUCCEEDED(aPS->GetResolutionName(&uStr))) {
DUMP_STR(kWriteStr, kPrintResolutionName, uStr);
Preferences::SetString(GetPrefName(kPrintResolutionName, aPrinterName),
uStr);
}
}
if (aFlags & nsIPrintSettings::kInitSaveDownloadFonts) {
if (NS_SUCCEEDED(aPS->GetDownloadFonts(&b))) {
DUMP_BOOL(kWriteStr, kPrintDownloadFonts, b);
Preferences::SetBool(GetPrefName(kPrintDownloadFonts, aPrinterName), b);
}
}
if (aFlags & nsIPrintSettings::kInitSaveOrientation) {
if (NS_SUCCEEDED(aPS->GetOrientation(&iVal))) {
DUMP_INT(kWriteStr, kPrintOrientation, iVal);
Preferences::SetInt(GetPrefName(kPrintOrientation, aPrinterName), iVal);
}
}
if (aFlags & nsIPrintSettings::kInitSavePrintCommand) {
if (NS_SUCCEEDED(aPS->GetPrintCommand(&uStr))) {
DUMP_STR(kWriteStr, kPrintCommand, uStr);
Preferences::SetString(GetPrefName(kPrintCommand, aPrinterName), uStr);
}
}
// Only the general version of this pref is saved
if ((aFlags & nsIPrintSettings::kInitSavePrinterName)
&& aPrinterName.IsEmpty()) {
if (NS_SUCCEEDED(aPS->GetPrinterName(&uStr))) {
DUMP_STR(kWriteStr, kPrinterName, uStr);
Preferences::SetString(kPrinterName, uStr);
}
}
if (aFlags & nsIPrintSettings::kInitSavePrintToFile) {
if (NS_SUCCEEDED(aPS->GetPrintToFile(&b))) {
DUMP_BOOL(kWriteStr, kPrintToFile, b);
Preferences::SetBool(GetPrefName(kPrintToFile, aPrinterName), b);
}
}
if (aFlags & nsIPrintSettings::kInitSaveToFileName) {
if (NS_SUCCEEDED(aPS->GetToFileName(&uStr))) {
DUMP_STR(kWriteStr, kPrintToFileName, uStr);
Preferences::SetString(GetPrefName(kPrintToFileName, aPrinterName), uStr);
}
}
if (aFlags & nsIPrintSettings::kInitSavePageDelay) {
if (NS_SUCCEEDED(aPS->GetPrintPageDelay(&iVal))) {
DUMP_INT(kWriteStr, kPrintPageDelay, iVal);
Preferences::SetInt(GetPrefName(kPrintPageDelay, aPrinterName), iVal);
}
}
if (aFlags & nsIPrintSettings::kInitSaveShrinkToFit) {
if (NS_SUCCEEDED(aPS->GetShrinkToFit(&b))) {
DUMP_BOOL(kWriteStr, kPrintShrinkToFit, b);
Preferences::SetBool(GetPrefName(kPrintShrinkToFit, aPrinterName), b);
}
}
if (aFlags & nsIPrintSettings::kInitSaveScaling) {
if (NS_SUCCEEDED(aPS->GetScaling(&dbl))) {
DUMP_DBL(kWriteStr, kPrintScaling, dbl);
WritePrefDouble(GetPrefName(kPrintScaling, aPrinterName), dbl);
}
}
// Not Writing Out:
// Number of Copies
return NS_OK;
}
示例4: valueArray
/**
* See sbIMediaList
*/
NS_IMETHODIMP
sbLocalDatabaseMediaListBase::EnumerateItemsByProperty(const nsAString& aID,
const nsAString& aValue,
sbIMediaListEnumerationListener* aEnumerationListener,
PRUint16 aEnumerationType)
{
NS_ENSURE_ARG_POINTER(aEnumerationListener);
nsresult rv = NS_ERROR_UNEXPECTED;
// A property id must be specified.
NS_ENSURE_TRUE(!aID.IsEmpty(), NS_ERROR_INVALID_ARG);
// Get the sortable format of the value
nsCOMPtr<sbIPropertyManager> propMan =
do_GetService(SB_PROPERTYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<sbIPropertyInfo> info;
rv = propMan->GetPropertyInfo(aID, getter_AddRefs(info));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString sortableValue;
rv = info->MakeSortable(aValue, sortableValue);
NS_ENSURE_SUCCESS(rv, rv);
// Make a single-item string array to hold our property value.
sbStringArray valueArray(1);
nsString* value = valueArray.AppendElement(sortableValue);
NS_ENSURE_TRUE(value, NS_ERROR_OUT_OF_MEMORY);
// Make a string enumerator for it.
nsCOMPtr<nsIStringEnumerator> valueEnum =
new sbTArrayStringEnumerator(&valueArray);
NS_ENSURE_TRUE(valueEnum, NS_ERROR_OUT_OF_MEMORY);
switch (aEnumerationType) {
case sbIMediaList::ENUMERATIONTYPE_LOCKING: {
mozilla::MonitorAutoLock mon(mFullArrayMonitor);
// Don't reenter!
NS_ENSURE_FALSE(mLockedEnumerationActive, NS_ERROR_FAILURE);
mLockedEnumerationActive = PR_TRUE;
PRUint16 stepResult;
rv = aEnumerationListener->OnEnumerationBegin(this, &stepResult);
if (NS_SUCCEEDED(rv)) {
if (stepResult == sbIMediaListEnumerationListener::CONTINUE) {
rv = EnumerateItemsByPropertyInternal(aID, valueEnum,
aEnumerationListener);
}
else {
// The user cancelled the enumeration.
rv = NS_ERROR_ABORT;
}
}
mLockedEnumerationActive = PR_FALSE;
} break; // ENUMERATIONTYPE_LOCKING
case sbIMediaList::ENUMERATIONTYPE_SNAPSHOT: {
PRUint16 stepResult;
rv = aEnumerationListener->OnEnumerationBegin(this, &stepResult);
if (NS_SUCCEEDED(rv)) {
if (stepResult == sbIMediaListEnumerationListener::CONTINUE) {
rv = EnumerateItemsByPropertyInternal(aID, valueEnum,
aEnumerationListener);
}
else {
// The user cancelled the enumeration.
rv = NS_ERROR_ABORT;
}
}
} break; // ENUMERATIONTYPE_SNAPSHOT
default: {
NS_NOTREACHED("Invalid enumeration type");
rv = NS_ERROR_INVALID_ARG;
} break;
}
aEnumerationListener->OnEnumerationEnd(this, rv);
return NS_OK;
}
示例5: stackBuffer
NS_IMETHODIMP
nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
void* aKey,
const nsACString& aContentType,
bool aLastCall,
nsDTDMode aMode) // ignored
{
nsresult rv;
if (NS_FAILED(rv = mExecutor->IsBroken())) {
return rv;
}
if (aSourceBuffer.Length() > INT32_MAX) {
return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
}
// Maintain a reference to ourselves so we don't go away
// till we're completely done. The old parser grips itself in this method.
nsCOMPtr<nsIParser> kungFuDeathGrip(this);
// Gripping the other objects just in case, since the other old grip
// required grips to these, too.
nsRefPtr<nsHtml5StreamParser> streamKungFuDeathGrip(mStreamParser);
nsRefPtr<nsHtml5TreeOpExecutor> treeOpKungFuDeathGrip(mExecutor);
if (!mExecutor->HasStarted()) {
NS_ASSERTION(!mStreamParser,
"Had stream parser but document.write started life cycle.");
// This is the first document.write() on a document.open()ed document
mExecutor->SetParser(this);
mTreeBuilder->setScriptingEnabled(mExecutor->IsScriptEnabled());
bool isSrcdoc = false;
nsCOMPtr<nsIChannel> channel;
rv = GetChannel(getter_AddRefs(channel));
if (NS_SUCCEEDED(rv)) {
isSrcdoc = NS_IsSrcdocChannel(channel);
}
mTreeBuilder->setIsSrcdocDocument(isSrcdoc);
mTokenizer->start();
mExecutor->Start();
if (!aContentType.EqualsLiteral("text/html")) {
mTreeBuilder->StartPlainText();
mTokenizer->StartPlainText();
}
/*
* If you move the following line, be very careful not to cause
* WillBuildModel to be called before the document has had its
* script global object set.
*/
mExecutor->WillBuildModel(eDTDMode_unknown);
}
// Return early if the parser has processed EOF
if (mExecutor->IsComplete()) {
return NS_OK;
}
if (aLastCall && aSourceBuffer.IsEmpty() && !aKey) {
// document.close()
NS_ASSERTION(!mStreamParser,
"Had stream parser but got document.close().");
if (mDocumentClosed) {
// already closed
return NS_OK;
}
mDocumentClosed = true;
if (!mBlocked && !mInDocumentWrite) {
ParseUntilBlocked();
}
return NS_OK;
}
// If we got this far, we are dealing with a document.write or
// document.writeln call--not document.close().
NS_ASSERTION(IsInsertionPointDefined(),
"Doc.write reached parser with undefined insertion point.");
NS_ASSERTION(!(mStreamParser && !aKey),
"Got a null key in a non-script-created parser");
// XXX is this optimization bogus?
if (aSourceBuffer.IsEmpty()) {
return NS_OK;
}
// This guard is here to prevent document.close from tokenizing synchronously
// while a document.write (that wrote the script that called document.close!)
// is still on the call stack.
mozilla::AutoRestore<bool> guard(mInDocumentWrite);
mInDocumentWrite = true;
// The script is identified by aKey. If there's nothing in the buffer
// chain for that key, we'll insert at the head of the queue.
// When the script leaves something in the queue, a zero-length
// key-holder "buffer" is inserted in the queue. If the same script
// leaves something in the chain again, it will be inserted immediately
// before the old key holder belonging to the same script.
//
//.........这里部分代码省略.........
示例6: DetectByteOrderMark
/* static */ nsresult
nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const PRUint8* aData,
PRUint32 aLength, const nsAString& aHintCharset,
nsIDocument* aDocument, nsString& aString)
{
if (!aLength) {
aString.Truncate();
return NS_OK;
}
nsCAutoString characterSet;
nsresult rv = NS_OK;
if (aChannel) {
rv = aChannel->GetContentCharset(characterSet);
}
if (!aHintCharset.IsEmpty() && (NS_FAILED(rv) || characterSet.IsEmpty())) {
// charset name is always ASCII.
LossyCopyUTF16toASCII(aHintCharset, characterSet);
}
if (NS_FAILED(rv) || characterSet.IsEmpty()) {
DetectByteOrderMark(aData, aLength, characterSet);
}
if (characterSet.IsEmpty() && aDocument) {
// charset from document default
characterSet = aDocument->GetDocumentCharacterSet();
}
if (characterSet.IsEmpty()) {
// fall back to ISO-8859-1, see bug 118404
characterSet.AssignLiteral("ISO-8859-1");
}
nsCOMPtr<nsICharsetConverterManager> charsetConv =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
if (NS_SUCCEEDED(rv) && charsetConv) {
rv = charsetConv->GetUnicodeDecoder(characterSet.get(),
getter_AddRefs(unicodeDecoder));
if (NS_FAILED(rv)) {
// fall back to ISO-8859-1 if charset is not supported. (bug 230104)
rv = charsetConv->GetUnicodeDecoderRaw("ISO-8859-1",
getter_AddRefs(unicodeDecoder));
}
}
// converts from the charset to unicode
if (NS_SUCCEEDED(rv)) {
PRInt32 unicodeLength = 0;
rv = unicodeDecoder->GetMaxLength(reinterpret_cast<const char*>(aData),
aLength, &unicodeLength);
if (NS_SUCCEEDED(rv)) {
if (!EnsureStringLength(aString, unicodeLength))
return NS_ERROR_OUT_OF_MEMORY;
PRUnichar *ustr = aString.BeginWriting();
PRInt32 consumedLength = 0;
PRInt32 originalLength = aLength;
PRInt32 convertedLength = 0;
PRInt32 bufferLength = unicodeLength;
do {
rv = unicodeDecoder->Convert(reinterpret_cast<const char*>(aData),
(PRInt32 *) &aLength, ustr,
&unicodeLength);
if (NS_FAILED(rv)) {
// if we failed, we consume one byte, replace it with U+FFFD
// and try the conversion again.
ustr[unicodeLength++] = (PRUnichar)0xFFFD;
ustr += unicodeLength;
unicodeDecoder->Reset();
}
aData += ++aLength;
consumedLength += aLength;
aLength = originalLength - consumedLength;
convertedLength += unicodeLength;
unicodeLength = bufferLength - convertedLength;
} while (NS_FAILED(rv) && (originalLength > consumedLength) && (bufferLength > convertedLength));
aString.SetLength(convertedLength);
}
}
return rv;
}
示例7: ResponsiveImageSelector
/* static */ bool
HTMLImageElement::SelectSourceForTagWithAttrs(nsIDocument *aDocument,
bool aIsSourceTag,
const nsAString& aSrcAttr,
const nsAString& aSrcsetAttr,
const nsAString& aSizesAttr,
const nsAString& aTypeAttr,
const nsAString& aMediaAttr,
nsAString& aResult)
{
MOZ_ASSERT(aIsSourceTag || (aTypeAttr.IsEmpty() && aMediaAttr.IsEmpty()),
"Passing type or media attrs makes no sense without aIsSourceTag");
MOZ_ASSERT(!aIsSourceTag || aSrcAttr.IsEmpty(),
"Passing aSrcAttr makes no sense with aIsSourceTag set");
bool pictureEnabled = HTMLPictureElement::IsPictureEnabled();
if (aIsSourceTag && !pictureEnabled) {
return false;
}
if (!IsSrcsetEnabled() || aSrcsetAttr.IsEmpty()) {
if (!aIsSourceTag) {
// For an <img> with no srcset, we would always select the src attr.
aResult.Assign(aSrcAttr);
return true;
}
// Otherwise, a <source> without srcset is never selected
return false;
}
// Would not consider source tags with unsupported media or type
if (aIsSourceTag &&
((!aMediaAttr.IsVoid() &&
!HTMLSourceElement::WouldMatchMediaForDocument(aMediaAttr, aDocument)) ||
(!aTypeAttr.IsVoid() &&
!SupportedPictureSourceType(aTypeAttr)))) {
return false;
}
// Using srcset or picture <source>, build a responsive selector for this tag.
RefPtr<ResponsiveImageSelector> sel =
new ResponsiveImageSelector(aDocument);
sel->SetCandidatesFromSourceSet(aSrcsetAttr);
if (pictureEnabled && !aSizesAttr.IsEmpty()) {
sel->SetSizesFromDescriptor(aSizesAttr);
}
if (!aIsSourceTag) {
sel->SetDefaultSource(aSrcAttr);
}
if (sel->GetSelectedImageURLSpec(aResult)) {
return true;
}
if (!aIsSourceTag) {
// <img> tag with no match would definitively load nothing.
aResult.Truncate();
return true;
}
// <source> tags with no match would leave source yet-undetermined.
return false;
}
示例8: PRNetAddrToNetAddr
nsresult
UDPSocket::InitLocal(const nsAString& aLocalAddress,
const uint16_t& aLocalPort)
{
nsresult rv;
nsCOMPtr<nsIUDPSocket> sock =
do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner(), &rv);
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull();
if (!principal) {
return NS_ERROR_FAILURE;
}
if (aLocalAddress.IsEmpty()) {
rv = sock->Init(aLocalPort, /* loopback = */ false, principal,
mAddressReuse, /* optionalArgc = */ 1);
} else {
PRNetAddr prAddr;
PR_InitializeNetAddr(PR_IpAddrAny, aLocalPort, &prAddr);
PR_StringToNetAddr(NS_ConvertUTF16toUTF8(aLocalAddress).BeginReading(), &prAddr);
UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, NS_ConvertUTF16toUTF8(aLocalAddress).get(), aLocalPort));
mozilla::net::NetAddr addr;
PRNetAddrToNetAddr(&prAddr, &addr);
rv = sock->InitWithAddress(&addr, principal, mAddressReuse,
/* optionalArgc = */ 1);
}
if (NS_FAILED(rv)) {
return rv;
}
rv = sock->SetMulticastLoopback(mLoopback);
if (NS_FAILED(rv)) {
return rv;
}
mSocket = sock;
// Get real local address and local port
nsCOMPtr<nsINetAddr> localAddr;
rv = mSocket->GetLocalAddr(getter_AddRefs(localAddr));
if (NS_FAILED(rv)) {
return rv;
}
nsCString localAddress;
rv = localAddr->GetAddress(localAddress);
if (NS_FAILED(rv)) {
return rv;
}
mLocalAddress = NS_ConvertUTF8toUTF16(localAddress);
uint16_t localPort;
rv = localAddr->GetPort(&localPort);
if (NS_FAILED(rv)) {
return rv;
}
mLocalPort.SetValue(localPort);
mListenerProxy = new ListenerProxy(this);
rv = mSocket->AsyncListen(mListenerProxy);
if (NS_FAILED(rv)) {
return rv;
}
mReadyState = SocketReadyState::Open;
rv = DoPendingMcastCommand();
if (NS_FAILED(rv)) {
return rv;
}
mOpened->MaybeResolve(JS::UndefinedHandleValue);
return NS_OK;
}
示例9: if
NS_IMETHODIMP
nsInternetCiter::Rewrap(const nsAString& aInString,
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
PRBool aRespectNewlines,
nsAString& aOutString)
{
// There shouldn't be returns in this string, only dom newlines.
// Check to make sure:
#ifdef DEBUG
PRInt32 cr = aInString.FindChar(PRUnichar('\r'));
NS_ASSERTION((cr < 0), "Rewrap: CR in string gotten from DOM!\n");
#endif /* DEBUG */
aOutString.Truncate();
nsCOMPtr<nsILineBreaker> lineBreaker;
nsILineBreakerFactory *lf;
nsresult rv;
rv = CallGetService(NS_LWBRK_CONTRACTID, &lf);
if (NS_SUCCEEDED(rv))
{
nsAutoString lbarg;
lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker));
NS_RELEASE(lf);
}
// Loop over lines in the input string, rewrapping each one.
PRUint32 length;
PRUint32 posInString = 0;
PRUint32 outStringCol = 0;
PRUint32 citeLevel = 0;
const nsPromiseFlatString &tString = PromiseFlatString(aInString);
length = tString.Length();
#ifdef DEBUG_wrapping
int loopcount = 0;
#endif
while (posInString < length)
{
#ifdef DEBUG_wrapping
printf("Outer loop: '%s'\n",
NS_LossyConvertUCS2toASCII(Substring(tString, posInString,
length-posInString)).get());
printf("out string is now: '%s'\n",
NS_LossyConvertUCS2toASCII(aOutString).get());
#endif
// Get the new cite level here since we're at the beginning of a line
PRUint32 newCiteLevel = 0;
while (posInString < length && tString[posInString] == gt)
{
++newCiteLevel;
++posInString;
while (posInString < length && tString[posInString] == space)
++posInString;
}
if (posInString >= length)
break;
// Special case: if this is a blank line, maintain a blank line
// (retain the original paragraph breaks)
if (tString[posInString] == nl && !aOutString.IsEmpty())
{
if (aOutString.Last() != nl)
aOutString.Append(nl);
AddCite(aOutString, newCiteLevel);
aOutString.Append(nl);
++posInString;
outStringCol = 0;
continue;
}
// If the cite level has changed, then start a new line with the
// new cite level (but if we're at the beginning of the string,
// don't bother).
if (newCiteLevel != citeLevel && posInString > newCiteLevel+1
&& outStringCol != 0)
{
BreakLine(aOutString, outStringCol, 0);
}
citeLevel = newCiteLevel;
// Prepend the quote level to the out string if appropriate
if (outStringCol == 0)
{
AddCite(aOutString, citeLevel);
outStringCol = citeLevel + (citeLevel ? 1 : 0);
}
// If it's not a cite, and we're not at the beginning of a line in
// the output string, add a space to separate new text from the
// previous text.
else if (outStringCol > citeLevel)
{
aOutString.Append(space);
++outStringCol;
}
// find the next newline -- don't want to go farther than that
PRInt32 nextNewline = tString.FindChar(nl, posInString);
//.........这里部分代码省略.........
示例10: importType
/* static */ nsresult
sbDeviceMediaItemDecorator::DecorateMediaItem(sbIDevice * aDevice,
sbIMediaItem * aMediaItem,
const nsAString & aImportType)
{
NS_ENSURE_ARG_POINTER(aDevice);
NS_ENSURE_ARG_POINTER(aMediaItem);
nsresult rv;
#if DEBUG
// Get media item info for viewing in debugger:
nsAutoString mi;
aMediaItem->ToString(mi);
nsCOMPtr<nsIURI> contentUri;
rv = aMediaItem->GetContentSrc(getter_AddRefs(contentUri));
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString contentSpec;
rv = contentUri->GetSpec(contentSpec);
NS_ENSURE_SUCCESS(rv, rv);
#endif // #if DEBUG
// Do nothing if no import type:
if (aImportType.IsEmpty()) {
return NS_OK;
}
// Save the import type to the media item properties to track
// how the file was classified at mount time and how it has
// been and should be processed on import:
nsAutoString importType(aImportType);
rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_IMPORTTYPE),
importType);
NS_ENSURE_SUCCESS(rv, rv);
// Dispatch on import type and adjust the media item properties as
// specified at
// http://wiki.songbirdnest.com/Releases/Ratatat/Device_Import_and_Sync#Sync_Logic
if (importType == NS_LITERAL_STRING(SB_VALUE_IMPORTTYPE_FM_RECORDING) ||
importType == NS_LITERAL_STRING(SB_VALUE_IMPORTTYPE_VIDEO_RECORDING) ||
importType == NS_LITERAL_STRING(SB_VALUE_IMPORTTYPE_VOICE_RECORDING))
{
// A recording. Set the genre to identify it as such. Localizable
// strings reside in the default bundle and use the device.sync. prefix:
sbStringBundle bundle;
nsAutoString genreKey(NS_LITERAL_STRING("device.sync.import_type."));
genreKey.Append(importType);
nsAutoString genre = bundle.Get(genreKey);
rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_GENRE), genre);
NS_ENSURE_SUCCESS(rv, rv);
// Set the artist name to the device name:
nsAutoString deviceName;
rv = aDevice->GetName(deviceName);
NS_ENSURE_SUCCESS(rv, rv);
rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ARTISTNAME),
deviceName);
NS_ENSURE_SUCCESS(rv, rv);
/// @todo Include the file creation timestamp in the track name
/// if possible.
}
return NS_OK;
}
示例11: typeStr
void
nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
const char* const* aFormatNames,
PRInt32 aWidth, PRInt32 aHeight,
const nsAString& aStatus)
{
nsXPIDLString fileStr;
if (mDocumentURI) {
nsCAutoString fileName;
nsCOMPtr<nsIURL> url = do_QueryInterface(mDocumentURI);
if (url)
url->GetFileName(fileName);
nsCAutoString docCharset;
// Now that the charset is set in |StartDocumentLoad| to the charset of
// the document viewer instead of a bogus value ("ISO-8859-1" set in
// |nsDocument|'s ctor), the priority is given to the current charset.
// This is necessary to deal with a media document being opened in a new
// window or a new tab, in which case |originCharset| of |nsIURI| is not
// reliable.
if (mCharacterSetSource != kCharsetUninitialized) {
docCharset = mCharacterSet;
}
else {
// resort to |originCharset|
mDocumentURI->GetOriginCharset(docCharset);
SetDocumentCharacterSet(docCharset);
}
if (!fileName.IsEmpty()) {
nsresult rv;
nsCOMPtr<nsITextToSubURI> textToSubURI =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
// UnEscapeURIForUI always succeeds
textToSubURI->UnEscapeURIForUI(docCharset, fileName, fileStr);
else
CopyUTF8toUTF16(fileName, fileStr);
}
}
NS_ConvertASCIItoUTF16 typeStr(aTypeStr);
nsXPIDLString title;
if (mStringBundle) {
// if we got a valid size (not all media have a size)
if (aWidth != 0 && aHeight != 0) {
nsAutoString widthStr;
nsAutoString heightStr;
widthStr.AppendInt(aWidth);
heightStr.AppendInt(aHeight);
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
const PRUnichar *formatStrings[4] = {fileStr.get(), typeStr.get(),
widthStr.get(), heightStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithDimAndFile]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 4,
getter_Copies(title));
}
else {
const PRUnichar *formatStrings[3] = {typeStr.get(), widthStr.get(),
heightStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithDim]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 3,
getter_Copies(title));
}
}
else {
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
const PRUnichar *formatStrings[2] = {fileStr.get(), typeStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithFile]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
getter_Copies(title));
}
else {
const PRUnichar *formatStrings[1] = {typeStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithNoInfo]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
getter_Copies(title));
}
}
}
// set it on the document
if (aStatus.IsEmpty()) {
SetTitle(title);
}
else {
nsXPIDLString titleWithStatus;
const nsPromiseFlatString& status = PromiseFlatString(aStatus);
const PRUnichar *formatStrings[2] = {title.get(), status.get()};
NS_NAMED_LITERAL_STRING(fmtName, "TitleWithStatus");
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
getter_Copies(titleWithStatus));
SetTitle(titleWithStatus);
}
}
示例12: switch
/**
* Static callback functions
*/
static void
ClassToIcon(uint32_t aClass, nsAString& aRetIcon)
{
switch ((aClass & 0x1f00) >> 8) {
case 0x01:
aRetIcon.AssignLiteral("computer");
break;
case 0x02:
switch ((aClass & 0xfc) >> 2) {
case 0x01:
case 0x02:
case 0x03:
case 0x05:
aRetIcon.AssignLiteral("phone");
break;
case 0x04:
aRetIcon.AssignLiteral("modem");
break;
}
break;
case 0x03:
aRetIcon.AssignLiteral("network-wireless");
break;
case 0x04:
switch ((aClass & 0xfc) >> 2) {
case 0x01:
case 0x02:
case 0x06:
aRetIcon.AssignLiteral("audio-card");
break;
case 0x0b:
case 0x0c:
case 0x0d:
aRetIcon.AssignLiteral("camera-video");
break;
default:
aRetIcon.AssignLiteral("audio-card");
break;
}
break;
case 0x05:
switch ((aClass & 0xc0) >> 6) {
case 0x00:
switch ((aClass && 0x1e) >> 2) {
case 0x01:
case 0x02:
aRetIcon.AssignLiteral("input-gaming");
break;
}
break;
case 0x01:
aRetIcon.AssignLiteral("input-keyboard");
break;
case 0x02:
switch ((aClass && 0x1e) >> 2) {
case 0x05:
aRetIcon.AssignLiteral("input-tablet");
break;
default:
aRetIcon.AssignLiteral("input-mouse");
break;
}
}
break;
case 0x06:
if (aClass & 0x80) {
aRetIcon.AssignLiteral("printer");
break;
}
if (aClass & 0x20) {
aRetIcon.AssignLiteral("camera-photo");
break;
}
break;
}
if (aRetIcon.IsEmpty()) {
if (HAS_AUDIO(aClass)) {
/**
* Property 'Icon' may be missed due to CoD of major class is TOY(0x08).
* But we need to assign Icon as audio-card if service class is 'Audio'.
* This is for PTS test case TC_AG_COD_BV_02_I. As HFP specification
* defines that service class is 'Audio' can be considered as HFP HF.
*/
aRetIcon.AssignLiteral("audio-card");
} else {
BT_LOGR("No icon to match class: %x", aClass);
}
}
}
示例13: spec
/**
* Translate a "rows" or "cols" spec into an array of nsFramesetSpecs
*/
nsresult
HTMLFrameSetElement::ParseRowCol(const nsAString & aValue,
int32_t& aNumSpecs,
nsFramesetSpec** aSpecs)
{
if (aValue.IsEmpty()) {
aNumSpecs = 0;
*aSpecs = nullptr;
return NS_OK;
}
static const PRUnichar sAster('*');
static const PRUnichar sPercent('%');
static const PRUnichar sComma(',');
nsAutoString spec(aValue);
// remove whitespace (Bug 33699) and quotation marks (bug 224598)
// also remove leading/trailing commas (bug 31482)
spec.StripChars(" \n\r\t\"\'");
spec.Trim(",");
// Count the commas. Don't count more than X commas (bug 576447).
PR_STATIC_ASSERT(NS_MAX_FRAMESET_SPEC_COUNT * sizeof(nsFramesetSpec) < (1 << 30));
int32_t commaX = spec.FindChar(sComma);
int32_t count = 1;
while (commaX != kNotFound && count < NS_MAX_FRAMESET_SPEC_COUNT) {
count++;
commaX = spec.FindChar(sComma, commaX + 1);
}
nsFramesetSpec* specs = new nsFramesetSpec[count];
if (!specs) {
*aSpecs = nullptr;
aNumSpecs = 0;
return NS_ERROR_OUT_OF_MEMORY;
}
// Pre-grab the compat mode; we may need it later in the loop.
bool isInQuirks = InNavQuirksMode(OwnerDoc());
// Parse each comma separated token
int32_t start = 0;
int32_t specLen = spec.Length();
for (int32_t i = 0; i < count; i++) {
// Find our comma
commaX = spec.FindChar(sComma, start);
NS_ASSERTION(i == count - 1 || commaX != kNotFound,
"Failed to find comma, somehow");
int32_t end = (commaX == kNotFound) ? specLen : commaX;
// Note: If end == start then it means that the token has no
// data in it other than a terminating comma (or the end of the spec).
// So default to a fixed width of 0.
specs[i].mUnit = eFramesetUnit_Fixed;
specs[i].mValue = 0;
if (end > start) {
int32_t numberEnd = end;
PRUnichar ch = spec.CharAt(numberEnd - 1);
if (sAster == ch) {
specs[i].mUnit = eFramesetUnit_Relative;
numberEnd--;
} else if (sPercent == ch) {
specs[i].mUnit = eFramesetUnit_Percent;
numberEnd--;
// check for "*%"
if (numberEnd > start) {
ch = spec.CharAt(numberEnd - 1);
if (sAster == ch) {
specs[i].mUnit = eFramesetUnit_Relative;
numberEnd--;
}
}
}
// Translate value to an integer
nsAutoString token;
spec.Mid(token, start, numberEnd - start);
// Treat * as 1*
if ((eFramesetUnit_Relative == specs[i].mUnit) &&
(0 == token.Length())) {
specs[i].mValue = 1;
}
else {
// Otherwise just convert to integer.
nsresult err;
specs[i].mValue = token.ToInteger(&err);
if (NS_FAILED(err)) {
specs[i].mValue = 0;
}
}
// Treat 0* as 1* in quirks mode (bug 40383)
if (isInQuirks) {
if ((eFramesetUnit_Relative == specs[i].mUnit) &&
//.........这里部分代码省略.........
示例14: SetDomTitle
nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDocument> domDoc;
nsresult res = editor->GetDocument(getter_AddRefs(domDoc));
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMNodeList> titleList;
res = domDoc->GetElementsByTagName(NS_LITERAL_STRING("title"), getter_AddRefs(titleList));
NS_ENSURE_SUCCESS(res, res);
// First assume we will NOT really do anything
// (transaction will not be pushed on stack)
mIsTransient = true;
nsCOMPtr<nsIDOMNode>titleNode;
if(titleList)
{
res = titleList->Item(0, getter_AddRefs(titleNode));
NS_ENSURE_SUCCESS(res, res);
if (titleNode)
{
// Delete existing child textnode of title node
// (Note: all contents under a TITLE node are always in a single text node)
nsCOMPtr<nsIDOMNode> child;
res = titleNode->GetFirstChild(getter_AddRefs(child));
if(NS_FAILED(res)) return res;
if(child)
{
// Save current text as the undo value
nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(child);
if(textNode)
{
textNode->GetData(mUndoValue);
// If title text is identical to what already exists,
// quit now (mIsTransient is now TRUE)
if (mUndoValue == aTitle)
return NS_OK;
}
res = editor->DeleteNode(child);
if(NS_FAILED(res)) return res;
}
}
}
// We didn't return above, thus we really will be changing the title
mIsTransient = false;
// Get the <HEAD> node, create a <TITLE> and insert it under the HEAD
nsCOMPtr<nsIDocument> document = do_QueryInterface(domDoc);
NS_ENSURE_STATE(document);
dom::Element* head = document->GetHeadElement();
NS_ENSURE_STATE(head);
bool newTitleNode = false;
uint32_t newTitleIndex = 0;
if (!titleNode)
{
// Didn't find one above: Create a new one
nsCOMPtr<nsIDOMElement>titleElement;
res = domDoc->CreateElement(NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(titleElement, NS_ERROR_FAILURE);
titleNode = do_QueryInterface(titleElement);
newTitleNode = true;
// Get index so we append new title node after all existing HEAD children.
newTitleIndex = head->GetChildCount();
}
// Append a text node under the TITLE
// only if the title text isn't empty
if (titleNode && !aTitle.IsEmpty())
{
nsCOMPtr<nsIDOMText> textNode;
res = domDoc->CreateTextNode(aTitle, getter_AddRefs(textNode));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(textNode);
NS_ENSURE_TRUE(newNode, NS_ERROR_FAILURE);
if (newTitleNode)
{
// Not undoable: We will insert newTitleNode below
nsCOMPtr<nsIDOMNode> resultNode;
res = titleNode->AppendChild(newNode, getter_AddRefs(resultNode));
}
else
{
// This is an undoable transaction
res = editor->InsertNode(newNode, titleNode, 0);
}
NS_ENSURE_SUCCESS(res, res);
}
if (newTitleNode)
//.........这里部分代码省略.........
示例15: PDMFactory
/* static */
bool
MP4Decoder::CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
const nsAString& aCodecs)
{
if (!IsEnabled()) {
return false;
}
// Whitelist MP4 types, so they explicitly match what we encounter on
// the web, as opposed to what we use internally (i.e. what our demuxers
// etc output).
const bool isMP4Audio = aMIMETypeExcludingCodecs.EqualsASCII("audio/mp4") ||
aMIMETypeExcludingCodecs.EqualsASCII("audio/x-m4a");
const bool isMP4Video =
// On B2G, treat 3GPP as MP4 when Gonk PDM is available.
#ifdef MOZ_GONK_MEDIACODEC
aMIMETypeExcludingCodecs.EqualsASCII(VIDEO_3GPP) ||
#endif
aMIMETypeExcludingCodecs.EqualsASCII("video/mp4") ||
aMIMETypeExcludingCodecs.EqualsASCII("video/quicktime") ||
aMIMETypeExcludingCodecs.EqualsASCII("video/x-m4v");
if (!isMP4Audio && !isMP4Video) {
return false;
}
nsTArray<nsCString> codecMimes;
if (aCodecs.IsEmpty()) {
// No codecs specified. Assume AAC/H.264
if (isMP4Audio) {
codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mp4a-latm"));
} else {
MOZ_ASSERT(isMP4Video);
codecMimes.AppendElement(NS_LITERAL_CSTRING("video/avc"));
}
} else {
// Verify that all the codecs specified are ones that we expect that
// we can play.
nsTArray<nsString> codecs;
if (!ParseCodecsString(aCodecs, codecs)) {
return false;
}
for (const nsString& codec : codecs) {
if (IsAACCodecString(codec)) {
codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mp4a-latm"));
continue;
}
if (codec.EqualsLiteral("mp3")) {
codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mpeg"));
continue;
}
// Note: Only accept H.264 in a video content type, not in an audio
// content type.
if (IsWhitelistedH264Codec(codec) && isMP4Video) {
codecMimes.AppendElement(NS_LITERAL_CSTRING("video/avc"));
continue;
}
// Some unsupported codec.
return false;
}
}
// Verify that we have a PDM that supports the whitelisted types.
PDMFactory::Init();
RefPtr<PDMFactory> platform = new PDMFactory();
for (const nsCString& codecMime : codecMimes) {
if (!platform->SupportsMimeType(codecMime)) {
return false;
}
}
return true;
}