本文整理汇总了C++中nsString::IsVoid方法的典型用法代码示例。如果您正苦于以下问题:C++ nsString::IsVoid方法的具体用法?C++ nsString::IsVoid怎么用?C++ nsString::IsVoid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsString
的用法示例。
在下文中一共展示了nsString::IsVoid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
FlyWebPublishedServerParent::RecvWebSocketAccept(const nsString& aProtocol,
const uint64_t& aRequestId)
{
MOZ_ASSERT(!mActorDestroyed);
RefPtr<TransportProviderParent> providerIPC;
mPendingTransportProviders.Remove(aRequestId, getter_AddRefs(providerIPC));
RefPtr<InternalRequest> request;
mPendingRequests.Remove(aRequestId, getter_AddRefs(request));
if (!request || !providerIPC) {
static_cast<ContentParent*>(Manager())->KillHard("unknown websocket request id");
return false;
}
Optional<nsAString> protocol;
if (!aProtocol.IsVoid()) {
protocol = &aProtocol;
}
ErrorResult result;
nsCOMPtr<nsITransportProvider> providerServer =
mPublishedServer->OnWebSocketAcceptInternal(request, protocol, result);
if (result.Failed()) {
return false;
}
providerServer->SetListener(providerIPC);
return true;
}
示例2: SetStringProperty
/**
* Set a property of an object from a nsString.
*
* If the nsString is void (i.e. IsVoid is true), do nothing.
*/
bool SetStringProperty(JSContext *cx, JSObject *aObject, const char *aProperty,
const nsString aValue)
{
if (aValue.IsVoid()) {
return true;
}
JSString* strValue = JS_NewUCStringCopyZ(cx, aValue.get());
jsval valValue = STRING_TO_JSVAL(strValue);
return JS_SetProperty(cx, aObject, aProperty, &valValue);
}
示例3: SetStringProperty
/**
* Set a property of an object from a nsString.
*
* If the nsString is void (i.e. IsVoid is true), do nothing.
*/
bool SetStringProperty(JSContext *cx, JS::Handle<JSObject*> aObject, const char *aProperty,
const nsString aValue)
{
if (aValue.IsVoid()) {
return true;
}
JSString* strValue = JS_NewUCStringCopyZ(cx, aValue.get());
NS_ENSURE_TRUE(strValue, false);
JS::Rooted<JS::Value> valValue(cx, JS::StringValue(strValue));
return JS_SetProperty(cx, aObject, aProperty, valValue);
}
示例4:
bool
xpc_qsStringToJsstring(JSContext *cx, nsString &str, JSString **rval)
{
// From the T_DOMSTRING case in XPCConvert::NativeData2JS.
if (str.IsVoid()) {
*rval = nullptr;
return true;
}
nsStringBuffer* sharedBuffer;
jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str, &sharedBuffer);
if (JSVAL_IS_NULL(jsstr))
return false;
*rval = JSVAL_TO_STRING(jsstr);
if (sharedBuffer) {
// The string was shared but ReadableToJSVal didn't addref it.
// Move the ownership from str to jsstr.
str.ForgetSharedBuffer();
}
return true;
}
示例5: EncodeVal
nsresult
nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
nsIDOMBlob* aBlob,
const nsString& aFilename)
{
// Encode the control name
nsAutoCString nameStr;
nsresult rv = EncodeVal(aName, nameStr, true);
NS_ENSURE_SUCCESS(rv, rv);
nsCString filename, contentType;
nsCOMPtr<nsIInputStream> fileStream;
if (aBlob) {
// We prefer the explicitly passed filename
if (!aFilename.IsVoid()) {
rv = EncodeVal(aFilename, filename, true);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// Get and encode the filename
nsAutoString filename16;
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(aBlob);
if (file) {
rv = file->GetName(filename16);
NS_ENSURE_SUCCESS(rv, rv);
}
if (filename16.IsEmpty()) {
filename16.AssignLiteral("blob");
}
rv = EncodeVal(filename16, filename, true);
NS_ENSURE_SUCCESS(rv, rv);
}
// Get content type
nsAutoString contentType16;
rv = aBlob->GetType(contentType16);
if (NS_FAILED(rv) || contentType16.IsEmpty()) {
contentType16.AssignLiteral("application/octet-stream");
}
contentType.Adopt(nsLinebreakConverter::
ConvertLineBreaks(NS_ConvertUTF16toUTF8(contentType16).get(),
nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakSpace));
// Get input stream
rv = aBlob->GetInternalStream(getter_AddRefs(fileStream));
NS_ENSURE_SUCCESS(rv, rv);
if (fileStream) {
// Create buffered stream (for efficiency)
nsCOMPtr<nsIInputStream> bufferedStream;
rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
fileStream, 8192);
NS_ENSURE_SUCCESS(rv, rv);
fileStream = bufferedStream;
}
}
else {
contentType.AssignLiteral("application/octet-stream");
}
//
// Make MIME block for name/value pair
//
// more appropriate than always using binary?
mPostDataChunk += NS_LITERAL_CSTRING("--") + mBoundary
+ NS_LITERAL_CSTRING(CRLF);
// XXX: name/filename parameter should be encoded per RFC 2231
// RFC 2388 specifies that RFC 2047 be used, but I think it's not
// consistent with the MIME standard.
mPostDataChunk +=
NS_LITERAL_CSTRING("Content-Disposition: form-data; name=\"")
+ nameStr + NS_LITERAL_CSTRING("\"; filename=\"")
+ filename + NS_LITERAL_CSTRING("\"" CRLF)
+ NS_LITERAL_CSTRING("Content-Type: ")
+ contentType + NS_LITERAL_CSTRING(CRLF CRLF);
// We should not try to append an invalid stream. That will happen for example
// if we try to update a file that actually do not exist.
uint64_t size;
if (fileStream && NS_SUCCEEDED(aBlob->GetSize(&size))) {
// We need to dump the data up to this point into the POST data stream here,
// since we're about to add the file input stream
AddPostDataStream();
mPostDataStream->AppendStream(fileStream);
mTotalLength += size;
}
// CRLF after file
mPostDataChunk.AppendLiteral(CRLF);
return NS_OK;
}