本文整理汇总了C++中nsAString类的典型用法代码示例。如果您正苦于以下问题:C++ nsAString类的具体用法?C++ nsAString怎么用?C++ nsAString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了nsAString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_NewDOMDocument
nsresult
NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIURI* aDocumentURI,
nsIURI* aBaseURI,
nsIPrincipal* aPrincipal,
bool aLoadedAsData,
nsIScriptGlobalObject* aEventObject,
DocumentFlavor aFlavor)
{
// Note: can't require that aDocumentURI/aBaseURI/aPrincipal be non-null,
// since at least one caller (XMLHttpRequest) doesn't have decent args to
// pass in.
nsresult rv;
*aInstancePtrResult = nullptr;
nsCOMPtr<nsIDocument> d;
bool isHTML = false;
bool isXHTML = false;
if (aFlavor == DocumentFlavorSVG) {
rv = NS_NewSVGDocument(getter_AddRefs(d));
} else if (aFlavor == DocumentFlavorHTML) {
rv = NS_NewHTMLDocument(getter_AddRefs(d));
isHTML = true;
} else if (aDoctype) {
nsAutoString publicId, name;
aDoctype->GetPublicId(publicId);
if (publicId.IsEmpty()) {
aDoctype->GetName(name);
}
if (name.EqualsLiteral("html") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.01//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.01 Frameset//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.01 Transitional//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.0//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Frameset//EN") ||
publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Transitional//EN")) {
rv = NS_NewHTMLDocument(getter_AddRefs(d));
isHTML = true;
} else if (publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Strict//EN") ||
publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Transitional//EN") ||
publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Frameset//EN")) {
rv = NS_NewHTMLDocument(getter_AddRefs(d));
isHTML = true;
isXHTML = true;
}
else if (publicId.EqualsLiteral("-//W3C//DTD SVG 1.1//EN")) {
rv = NS_NewSVGDocument(getter_AddRefs(d));
}
// XXX Add support for XUL documents.
else {
rv = NS_NewXMLDocument(getter_AddRefs(d));
}
} else {
rv = NS_NewXMLDocument(getter_AddRefs(d));
}
if (NS_FAILED(rv)) {
return rv;
}
d->SetScriptHandlingObject(aEventObject);
if (isHTML) {
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(d);
NS_ASSERTION(htmlDoc, "HTML Document doesn't implement nsIHTMLDocument?");
htmlDoc->SetCompatibilityMode(eCompatibility_FullStandards);
htmlDoc->SetIsXHTML(isXHTML);
}
nsDocument* doc = static_cast<nsDocument*>(d.get());
doc->SetLoadedAsData(aLoadedAsData);
doc->nsDocument::SetDocumentURI(aDocumentURI);
// Must set the principal first, since SetBaseURI checks it.
doc->SetPrincipal(aPrincipal);
doc->SetBaseURI(aBaseURI);
// XMLDocuments and documents "created in memory" get to be UTF-8 by default,
// unlike the legacy HTML mess
doc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
if (aDoctype) {
nsCOMPtr<nsIDOMNode> tmpNode;
rv = doc->AppendChild(aDoctype, getter_AddRefs(tmpNode));
NS_ENSURE_SUCCESS(rv, rv);
}
if (!aQualifiedName.IsEmpty()) {
nsCOMPtr<nsIDOMElement> root;
rv = doc->CreateElementNS(aNamespaceURI, aQualifiedName,
getter_AddRefs(root));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> tmpNode;
rv = doc->AppendChild(root, getter_AddRefs(tmpNode));
NS_ENSURE_SUCCESS(rv, rv);
//.........这里部分代码省略.........
示例2:
RangedPtr<const PRUnichar>
SVGContentUtils::GetEndRangedPtr(const nsAString& aString)
{
return RangedPtr<const PRUnichar>(aString.Data() + aString.Length(),
aString.Data(), aString.Length());
}
示例3: GetName
NS_IMETHODIMP nsDBusHandlerApp::GetName(nsAString& aName)
{
aName.Assign(mName);
return NS_OK;
}
示例4:
nsresult
nsXULMenubarAccessible::GetNameInternal(nsAString& aName)
{
aName.AssignLiteral("Application");
return NS_OK;
}
示例5: BlacklistFeatureToGfxFeature
static int32_t
BlacklistFeatureToGfxFeature(const nsAString& aFeature)
{
MOZ_ASSERT(!aFeature.IsEmpty());
if (aFeature.EqualsLiteral("DIRECT2D"))
return nsIGfxInfo::FEATURE_DIRECT2D;
else if (aFeature.EqualsLiteral("DIRECT3D_9_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_10_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_10_1_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_11_LAYERS"))
return nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS;
else if (aFeature.EqualsLiteral("DIRECT3D_11_ANGLE"))
return nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE;
else if (aFeature.EqualsLiteral("HARDWARE_VIDEO_DECODING"))
return nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING;
else if (aFeature.EqualsLiteral("OPENGL_LAYERS"))
return nsIGfxInfo::FEATURE_OPENGL_LAYERS;
else if (aFeature.EqualsLiteral("WEBGL_OPENGL"))
return nsIGfxInfo::FEATURE_WEBGL_OPENGL;
else if (aFeature.EqualsLiteral("WEBGL_ANGLE"))
return nsIGfxInfo::FEATURE_WEBGL_ANGLE;
else if (aFeature.EqualsLiteral("WEBGL_MSAA"))
return nsIGfxInfo::FEATURE_WEBGL_MSAA;
else if (aFeature.EqualsLiteral("STAGEFRIGHT"))
return nsIGfxInfo::FEATURE_STAGEFRIGHT;
else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_ENCODE"))
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_ENCODE;
else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION_DECODE"))
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION_DECODE;
else if (aFeature.EqualsLiteral("WEBRTC_HW_ACCELERATION"))
return nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION;
else if (aFeature.EqualsLiteral("CANVAS2D_ACCELERATION"))
return nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION;
// If we don't recognize the feature, it may be new, and something
// this version doesn't understand. So, nothing to do. This is
// different from feature not being specified at all, in which case
// this method should not get called and we should continue with the
// "all features" blocklisting.
return -1;
}
示例6: switch
/* readonly attribute wstring name; */
NS_IMETHODIMP
nsSchemaBuiltinType::GetName(nsAString& aName)
{
switch (mBuiltinType) {
case BUILTIN_TYPE_ANYTYPE:
aName.AssignLiteral("anyType");
break;
case BUILTIN_TYPE_STRING:
aName.AssignLiteral("string");
break;
case BUILTIN_TYPE_NORMALIZED_STRING:
aName.AssignLiteral("normalizedString");
break;
case BUILTIN_TYPE_TOKEN:
aName.AssignLiteral("token");
break;
case BUILTIN_TYPE_BYTE:
aName.AssignLiteral("byte");
break;
case BUILTIN_TYPE_UNSIGNEDBYTE:
aName.AssignLiteral("unsignedByte");
break;
case BUILTIN_TYPE_BASE64BINARY:
aName.AssignLiteral("base64Binary");
break;
case BUILTIN_TYPE_HEXBINARY:
aName.AssignLiteral("hexBinary");
break;
case BUILTIN_TYPE_INTEGER:
aName.AssignLiteral("integer");
break;
case BUILTIN_TYPE_POSITIVEINTEGER:
aName.AssignLiteral("positiveInteger");
break;
case BUILTIN_TYPE_NEGATIVEINTEGER:
aName.AssignLiteral("negativeInteger");
break;
case BUILTIN_TYPE_NONNEGATIVEINTEGER:
aName.AssignLiteral("nonNegativeInteger");
break;
case BUILTIN_TYPE_NONPOSITIVEINTEGER:
aName.AssignLiteral("nonPositiveInteger");
break;
case BUILTIN_TYPE_INT:
aName.AssignLiteral("int");
break;
case BUILTIN_TYPE_UNSIGNEDINT:
aName.AssignLiteral("unsignedInt");
break;
case BUILTIN_TYPE_LONG:
aName.AssignLiteral("long");
break;
case BUILTIN_TYPE_UNSIGNEDLONG:
aName.AssignLiteral("unsignedLong");
break;
case BUILTIN_TYPE_SHORT:
aName.AssignLiteral("short");
break;
case BUILTIN_TYPE_UNSIGNEDSHORT:
aName.AssignLiteral("unsignedShort");
break;
case BUILTIN_TYPE_DECIMAL:
aName.AssignLiteral("decimal");
break;
case BUILTIN_TYPE_FLOAT:
aName.AssignLiteral("float");
break;
case BUILTIN_TYPE_DOUBLE:
aName.AssignLiteral("double");
break;
case BUILTIN_TYPE_BOOLEAN:
aName.AssignLiteral("boolean");
break;
case BUILTIN_TYPE_TIME:
aName.AssignLiteral("time");
break;
case BUILTIN_TYPE_DATETIME:
aName.AssignLiteral("dateTime");
break;
case BUILTIN_TYPE_DURATION:
aName.AssignLiteral("duration");
break;
case BUILTIN_TYPE_DATE:
aName.AssignLiteral("date");
break;
case BUILTIN_TYPE_GMONTH:
aName.AssignLiteral("gMonth");
break;
case BUILTIN_TYPE_GYEAR:
aName.AssignLiteral("gYear");
break;
case BUILTIN_TYPE_GYEARMONTH:
aName.AssignLiteral("gYearMonth");
break;
case BUILTIN_TYPE_GDAY:
aName.AssignLiteral("gDay");
break;
case BUILTIN_TYPE_GMONTHDAY:
aName.AssignLiteral("gMonthDay");
//.........这里部分代码省略.........
示例7: if
/* static */
already_AddRefed<MediaEncoder>
MediaEncoder::CreateEncoder(const nsAString& aMIMEType, uint8_t aTrackTypes)
{
if (!gMediaEncoderLog) {
gMediaEncoderLog = PR_NewLogModule("MediaEncoder");
}
PROFILER_LABEL("MediaEncoder", "CreateEncoder",
js::ProfileEntry::Category::OTHER);
nsAutoPtr<ContainerWriter> writer;
nsAutoPtr<AudioTrackEncoder> audioEncoder;
nsAutoPtr<VideoTrackEncoder> videoEncoder;
nsRefPtr<MediaEncoder> encoder;
nsString mimeType;
if (!aTrackTypes) {
LOG(PR_LOG_ERROR, ("NO TrackTypes!!!"));
return nullptr;
}
#ifdef MOZ_WEBM_ENCODER
else if (MediaEncoder::IsWebMEncoderEnabled() &&
(aMIMEType.EqualsLiteral(VIDEO_WEBM) ||
(aTrackTypes & ContainerWriter::CREATE_VIDEO_TRACK))) {
if (aTrackTypes & ContainerWriter::CREATE_AUDIO_TRACK) {
audioEncoder = new VorbisTrackEncoder();
NS_ENSURE_TRUE(audioEncoder, nullptr);
}
videoEncoder = new VP8TrackEncoder();
writer = new WebMWriter(aTrackTypes);
NS_ENSURE_TRUE(writer, nullptr);
NS_ENSURE_TRUE(videoEncoder, nullptr);
mimeType = NS_LITERAL_STRING(VIDEO_WEBM);
}
#endif //MOZ_WEBM_ENCODER
#ifdef MOZ_OMX_ENCODER
else if (MediaEncoder::IsOMXEncoderEnabled() &&
(aMIMEType.EqualsLiteral(VIDEO_MP4) ||
(aTrackTypes & ContainerWriter::CREATE_VIDEO_TRACK))) {
if (aTrackTypes & ContainerWriter::CREATE_AUDIO_TRACK) {
audioEncoder = new OmxAACAudioTrackEncoder();
NS_ENSURE_TRUE(audioEncoder, nullptr);
}
videoEncoder = new OmxVideoTrackEncoder();
writer = new ISOMediaWriter(aTrackTypes);
NS_ENSURE_TRUE(writer, nullptr);
NS_ENSURE_TRUE(videoEncoder, nullptr);
mimeType = NS_LITERAL_STRING(VIDEO_MP4);
} else if (MediaEncoder::IsOMXEncoderEnabled() &&
(aMIMEType.EqualsLiteral(AUDIO_3GPP))) {
audioEncoder = new OmxAMRAudioTrackEncoder();
NS_ENSURE_TRUE(audioEncoder, nullptr);
writer = new ISOMediaWriter(aTrackTypes, ISOMediaWriter::TYPE_FRAG_3GP);
NS_ENSURE_TRUE(writer, nullptr);
mimeType = NS_LITERAL_STRING(AUDIO_3GPP);
}
#endif // MOZ_OMX_ENCODER
else if (MediaDecoder::IsOggEnabled() && MediaDecoder::IsOpusEnabled() &&
(aMIMEType.EqualsLiteral(AUDIO_OGG) ||
(aTrackTypes & ContainerWriter::CREATE_AUDIO_TRACK))) {
writer = new OggWriter();
audioEncoder = new OpusTrackEncoder();
NS_ENSURE_TRUE(writer, nullptr);
NS_ENSURE_TRUE(audioEncoder, nullptr);
mimeType = NS_LITERAL_STRING(AUDIO_OGG);
}
else {
LOG(PR_LOG_ERROR, ("Can not find any encoder to record this media stream"));
return nullptr;
}
LOG(PR_LOG_DEBUG, ("Create encoder result:a[%d] v[%d] w[%d] mimeType = %s.",
audioEncoder != nullptr, videoEncoder != nullptr,
writer != nullptr, mimeType.get()));
encoder = new MediaEncoder(writer.forget(), audioEncoder.forget(),
videoEncoder.forget(), mimeType);
return encoder.forget();
}
示例8:
NS_IMETHODIMP
Navigator::GetVendorSub(nsAString& aVendorSub)
{
aVendorSub.Truncate();
return NS_OK;
}
示例9: FormatTMTime
// performs a locale sensitive date formatting operation on the struct tm parameter
nsresult nsDateTimeFormatWin::FormatTMTime(nsILocale* locale,
const nsDateFormatSelector dateFormatSelector,
const nsTimeFormatSelector timeFormatSelector,
const struct tm* tmTime,
nsAString& stringOut)
{
SYSTEMTIME system_time;
DWORD dwFlags_Date = 0, dwFlags_Time = 0;
int dateLen, timeLen;
char16_t dateBuffer[NSDATETIMEFORMAT_BUFFER_LEN], timeBuffer[NSDATETIMEFORMAT_BUFFER_LEN];
// set up locale data
(void) Initialize(locale);
// Map tm to SYSTEMTIME
system_time.wYear = 1900 + tmTime->tm_year;
system_time.wMonth = tmTime->tm_mon + 1;
system_time.wDayOfWeek = tmTime->tm_wday;
system_time.wDay = tmTime->tm_mday;
system_time.wHour = tmTime->tm_hour;
system_time.wMinute = tmTime->tm_min;
system_time.wSecond = tmTime->tm_sec;
system_time.wMilliseconds = 0;
// Map to WinAPI date format
switch (dateFormatSelector) {
case kDateFormatLong:
dwFlags_Date = DATE_LONGDATE;
break;
case kDateFormatShort:
dwFlags_Date = DATE_SHORTDATE;
break;
case kDateFormatWeekday:
dwFlags_Date = 0;
break;
case kDateFormatYearMonth:
dwFlags_Date = 0; // TODO:only availabe NT5
break;
}
// Map to WinAPI time format
switch (timeFormatSelector) {
case kTimeFormatSeconds:
dwFlags_Time = 0;
break;
case kTimeFormatNoSeconds:
dwFlags_Time = TIME_NOSECONDS;
break;
case kTimeFormatSecondsForce24Hour:
dwFlags_Time = TIME_FORCE24HOURFORMAT;
break;
case kTimeFormatNoSecondsForce24Hour:
dwFlags_Time = TIME_NOSECONDS + TIME_FORCE24HOURFORMAT;
break;
}
// Call GetDateFormatW
if (dateFormatSelector == kDateFormatNone) {
dateLen = 0;
}
else {
if (dateFormatSelector == kDateFormatYearMonth) {
dateLen = nsGetDateFormatW(0, &system_time, "yyyy/MM",
dateBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
}
else if (dateFormatSelector == kDateFormatWeekday) {
dateLen = nsGetDateFormatW(0, &system_time, "ddd",
dateBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
}
else {
dateLen = nsGetDateFormatW(dwFlags_Date, &system_time, nullptr,
dateBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
}
if (dateLen != 0) {
dateLen--; // Since the count includes the terminating null.
}
}
// Call GetTimeFormatW
if (timeFormatSelector == kTimeFormatNone) {
timeLen = 0;
}
else {
timeLen = nsGetTimeFormatW(dwFlags_Time, &system_time, nullptr,
timeBuffer, NSDATETIMEFORMAT_BUFFER_LEN);
if (timeLen != 0) {
timeLen--; // Since the count includes the terminating null.
}
}
NS_ASSERTION(NSDATETIMEFORMAT_BUFFER_LEN >= (uint32_t) (dateLen + 1), "internal date buffer is not large enough");
NS_ASSERTION(NSDATETIMEFORMAT_BUFFER_LEN >= (uint32_t) (timeLen + 1), "internal time buffer is not large enough");
// Copy the result
stringOut.Truncate();
if (dateLen != 0 && timeLen != 0) {
stringOut.Assign(dateBuffer, dateLen);
stringOut.Append((char16_t *)(L" "), 1);
stringOut.Append(timeBuffer, timeLen);
//.........这里部分代码省略.........
示例10: ActionNameAt
void HTMLLabelAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
if (aIndex == 0) {
if (nsCoreUtils::IsLabelWithControl(mContent)) aName.AssignLiteral("click");
}
}
示例11: NS_NewDOMMutationEvent
/* static */ nsresult
nsEventDispatcher::CreateEvent(nsPresContext* aPresContext,
nsEvent* aEvent,
const nsAString& aEventType,
nsIDOMEvent** aDOMEvent)
{
*aDOMEvent = nullptr;
if (aEvent) {
switch(aEvent->eventStructType) {
case NS_MUTATION_EVENT:
return NS_NewDOMMutationEvent(aDOMEvent, aPresContext,
static_cast<nsMutationEvent*>(aEvent));
case NS_GUI_EVENT:
case NS_SCROLLPORT_EVENT:
case NS_UI_EVENT:
return NS_NewDOMUIEvent(aDOMEvent, aPresContext,
static_cast<nsGUIEvent*>(aEvent));
case NS_SCROLLAREA_EVENT:
return NS_NewDOMScrollAreaEvent(aDOMEvent, aPresContext,
static_cast<nsScrollAreaEvent *>(aEvent));
case NS_KEY_EVENT:
return NS_NewDOMKeyboardEvent(aDOMEvent, aPresContext,
static_cast<nsKeyEvent*>(aEvent));
case NS_COMPOSITION_EVENT:
return NS_NewDOMCompositionEvent(
aDOMEvent, aPresContext, static_cast<nsCompositionEvent*>(aEvent));
case NS_MOUSE_EVENT:
return NS_NewDOMMouseEvent(aDOMEvent, aPresContext,
static_cast<nsInputEvent*>(aEvent));
case NS_MOUSE_SCROLL_EVENT:
return NS_NewDOMMouseScrollEvent(aDOMEvent, aPresContext,
static_cast<nsInputEvent*>(aEvent));
case NS_WHEEL_EVENT:
return NS_NewDOMWheelEvent(aDOMEvent, aPresContext,
static_cast<widget::WheelEvent*>(aEvent));
case NS_DRAG_EVENT:
return NS_NewDOMDragEvent(aDOMEvent, aPresContext,
static_cast<nsDragEvent*>(aEvent));
case NS_TEXT_EVENT:
return NS_NewDOMTextEvent(aDOMEvent, aPresContext,
static_cast<nsTextEvent*>(aEvent));
case NS_SVG_EVENT:
return NS_NewDOMSVGEvent(aDOMEvent, aPresContext,
aEvent);
case NS_SVGZOOM_EVENT:
return NS_NewDOMSVGZoomEvent(aDOMEvent, aPresContext,
static_cast<nsGUIEvent*>(aEvent));
case NS_SMIL_TIME_EVENT:
return NS_NewDOMTimeEvent(aDOMEvent, aPresContext, aEvent);
case NS_COMMAND_EVENT:
return NS_NewDOMCommandEvent(aDOMEvent, aPresContext,
static_cast<nsCommandEvent*>(aEvent));
case NS_SIMPLE_GESTURE_EVENT:
return NS_NewDOMSimpleGestureEvent(aDOMEvent, aPresContext,
static_cast<nsSimpleGestureEvent*>(aEvent));
case NS_TOUCH_EVENT:
return NS_NewDOMTouchEvent(aDOMEvent, aPresContext,
static_cast<nsTouchEvent*>(aEvent));
case NS_TRANSITION_EVENT:
return NS_NewDOMTransitionEvent(aDOMEvent, aPresContext,
static_cast<nsTransitionEvent*>(aEvent));
case NS_ANIMATION_EVENT:
return NS_NewDOMAnimationEvent(aDOMEvent, aPresContext,
static_cast<nsAnimationEvent*>(aEvent));
default:
// For all other types of events, create a vanilla event object.
return NS_NewDOMEvent(aDOMEvent, aPresContext, aEvent);
}
}
// And if we didn't get an event, check the type argument.
if (aEventType.LowerCaseEqualsLiteral("mouseevent") ||
aEventType.LowerCaseEqualsLiteral("mouseevents") ||
aEventType.LowerCaseEqualsLiteral("popupevents"))
return NS_NewDOMMouseEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("mousescrollevents"))
return NS_NewDOMMouseScrollEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("dragevent") ||
aEventType.LowerCaseEqualsLiteral("dragevents"))
return NS_NewDOMDragEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("keyboardevent") ||
aEventType.LowerCaseEqualsLiteral("keyevents"))
return NS_NewDOMKeyboardEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("compositionevent"))
return NS_NewDOMCompositionEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("mutationevent") ||
aEventType.LowerCaseEqualsLiteral("mutationevents"))
return NS_NewDOMMutationEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("textevent") ||
aEventType.LowerCaseEqualsLiteral("textevents"))
return NS_NewDOMTextEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("popupblockedevents"))
return NS_NewDOMPopupBlockedEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("deviceorientationevent"))
return NS_NewDOMDeviceOrientationEvent(aDOMEvent, aPresContext, nullptr);
if (aEventType.LowerCaseEqualsLiteral("devicemotionevent"))
return NS_NewDOMDeviceMotionEvent(aDOMEvent, aPresContext, nullptr);
//.........这里部分代码省略.........
示例12: DOMFileResult
NS_IMETHODIMP
nsDOMFile::GetAsDataURL(nsAString &aResult)
{
aResult.AssignLiteral("data:");
nsresult rv;
if (!mContentType.Length()) {
nsCOMPtr<nsIMIMEService> mimeService =
do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString contentType;
rv = mimeService->GetTypeFromFile(mFile, contentType);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(contentType, mContentType);
}
}
if (mContentType.Length()) {
aResult.Append(mContentType);
} else {
aResult.AppendLiteral("application/octet-stream");
}
aResult.AppendLiteral(";base64,");
nsCOMPtr<nsIInputStream> stream;
rv = GetInternalStream(getter_AddRefs(stream));
NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
char readBuf[4096];
PRUint32 leftOver = 0;
PRUint32 numRead;
do {
rv = stream->Read(readBuf + leftOver, sizeof(readBuf) - leftOver, &numRead);
NS_ENSURE_SUCCESS(rv, DOMFileResult(rv));
PRUint32 numEncode = numRead + leftOver;
leftOver = 0;
if (numEncode == 0) break;
// unless this is the end of the file, encode in multiples of 3
if (numRead > 0) {
leftOver = numEncode % 3;
numEncode -= leftOver;
}
// out buffer should be at least 4/3rds the read buf, plus a terminator
char *base64 = PL_Base64Encode(readBuf, numEncode, nsnull);
if (!base64) {
return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
}
nsDependentCString str(base64);
PRUint32 strLen = str.Length();
PRUint32 oldLength = aResult.Length();
AppendASCIItoUTF16(str, aResult);
PR_Free(base64);
if (aResult.Length() - oldLength != strLen) {
return DOMFileResult(NS_ERROR_OUT_OF_MEMORY);
}
if (leftOver) {
memmove(readBuf, readBuf + numEncode, leftOver);
}
} while (numRead > 0);
return NS_OK;
}
示例13: JS_ReportPendingException
nsresult
BluetoothService::HandleSettingsChanged(const nsAString& aData)
{
MOZ_ASSERT(NS_IsMainThread());
// The string that we're interested in will be a JSON string that looks like:
// {"key":"bluetooth.enabled","value":true}
JSContext* cx = nsContentUtils::GetSafeJSContext();
if (!cx) {
return NS_OK;
}
JS::Value val;
if (!JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val)) {
return JS_ReportPendingException(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
if (!val.isObject()) {
return NS_OK;
}
JSObject& obj(val.toObject());
JS::Value key;
if (!JS_GetProperty(cx, &obj, "key", &key)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!key.isString()) {
return NS_OK;
}
JSBool match;
if (!JS_StringEqualsAscii(cx, key.toString(), BLUETOOTH_ENABLED_SETTING,
&match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!match) {
return NS_OK;
}
JS::Value value;
if (!JS_GetProperty(cx, &obj, "value", &value)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!value.isBoolean()) {
MOZ_ASSERT(false, "Expecting a boolean for 'bluetooth.enabled'!");
return NS_ERROR_UNEXPECTED;
}
if (mSettingsCheckInProgress) {
// Somehow the setting for bluetooth has been flipped before our first
// settings check completed. Flip this flag so that we ignore the result
// of that check whenever it finishes.
mSettingsCheckInProgress = false;
}
if (value.toBoolean() == IsEnabled()) {
// Nothing to do here.
return NS_OK;
}
nsresult rv;
if (IsEnabled()) {
rv = StartStopBluetooth(false);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
rv = StartStopBluetooth(true);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例14: defined
NS_IMETHODIMP
nsCommandLine::ResolveFile(const nsAString& aArgument, nsIFile* *aResult)
{
NS_ENSURE_TRUE(mWorkingDir, NS_ERROR_NOT_INITIALIZED);
// This is some seriously screwed-up code. nsIFile.appendRelativeNativePath
// explicitly does not accept .. or . path parts, but that is exactly what we
// need here. So we hack around it.
nsresult rv;
#if defined(MOZ_WIDGET_COCOA)
nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(mWorkingDir));
NS_ENSURE_TRUE(lfm, NS_ERROR_NO_INTERFACE);
nsCOMPtr<nsILocalFileMac> newfile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(newfile, NS_ERROR_OUT_OF_MEMORY);
CFURLRef baseurl;
rv = lfm->GetCFURL(&baseurl);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString path;
NS_CopyUnicodeToNative(aArgument, path);
CFURLRef newurl =
CFURLCreateFromFileSystemRepresentationRelativeToBase(nullptr, (const UInt8*) path.get(),
path.Length(),
true, baseurl);
CFRelease(baseurl);
rv = newfile->InitWithCFURL(newurl);
CFRelease(newurl);
if (NS_FAILED(rv)) return rv;
newfile.forget(aResult);
return NS_OK;
#elif defined(XP_UNIX)
nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
if (aArgument.First() == '/') {
// absolute path
rv = lf->InitWithPath(aArgument);
if (NS_FAILED(rv)) return rv;
NS_ADDREF(*aResult = lf);
return NS_OK;
}
nsAutoCString nativeArg;
NS_CopyUnicodeToNative(aArgument, nativeArg);
nsAutoCString newpath;
mWorkingDir->GetNativePath(newpath);
newpath.Append('/');
newpath.Append(nativeArg);
rv = lf->InitWithNativePath(newpath);
if (NS_FAILED(rv)) return rv;
rv = lf->Normalize();
if (NS_FAILED(rv)) return rv;
lf.forget(aResult);
return NS_OK;
#elif defined(XP_WIN32)
nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);
rv = lf->InitWithPath(aArgument);
if (NS_FAILED(rv)) {
// If it's a relative path, the Init is *going* to fail. We use string magic and
// win32 _fullpath. Note that paths of the form "\Relative\To\CurDrive" are
// going to fail, and I haven't figured out a way to work around this without
// the PathCombine() function, which is not available in plain win95/nt4
nsAutoString fullPath;
mWorkingDir->GetPath(fullPath);
fullPath.Append('\\');
fullPath.Append(aArgument);
WCHAR pathBuf[MAX_PATH];
if (!_wfullpath(pathBuf, fullPath.get(), MAX_PATH))
return NS_ERROR_FAILURE;
rv = lf->InitWithPath(nsDependentString(pathBuf));
if (NS_FAILED(rv)) return rv;
}
lf.forget(aResult);
return NS_OK;
#else
#error Need platform-specific logic here.
#endif
//.........这里部分代码省略.........
示例15:
NS_IMETHODIMP
nsXMLProcessingInstruction::GetNodeName(nsAString& aNodeName)
{
aNodeName.Assign(mTarget);
return NS_OK;
}