本文整理汇总了C++中ChannelInfo::InitFromDocument方法的典型用法代码示例。如果您正苦于以下问题:C++ ChannelInfo::InitFromDocument方法的具体用法?C++ ChannelInfo::InitFromDocument怎么用?C++ ChannelInfo::InitFromDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChannelInfo
的用法示例。
在下文中一共展示了ChannelInfo::InitFromDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InternalResponse
/*static*/ already_AddRefed<Response>
Response::Constructor(const GlobalObject& aGlobal,
const Optional<ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>& aBody,
const ResponseInit& aInit, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
if (aInit.mStatus < 200 || aInit.mStatus > 599) {
aRv.ThrowRangeError(MSG_INVALID_RESPONSE_STATUSCODE_ERROR);
return nullptr;
}
nsCString statusText;
if (aInit.mStatusText.WasPassed()) {
statusText = aInit.mStatusText.Value();
nsACString::const_iterator start, end;
statusText.BeginReading(start);
statusText.EndReading(end);
if (FindCharInReadable('\r', start, end)) {
aRv.ThrowTypeError(MSG_RESPONSE_INVALID_STATUSTEXT_ERROR);
return nullptr;
}
// Reset iterator since FindCharInReadable advances it.
statusText.BeginReading(start);
if (FindCharInReadable('\n', start, end)) {
aRv.ThrowTypeError(MSG_RESPONSE_INVALID_STATUSTEXT_ERROR);
return nullptr;
}
} else {
// Since we don't support default values for ByteString.
statusText = NS_LITERAL_CSTRING("OK");
}
nsRefPtr<InternalResponse> internalResponse =
new InternalResponse(aInit.mStatus, statusText);
// Grab a valid channel info from the global so this response is 'valid' for
// interception.
if (NS_IsMainThread()) {
ChannelInfo info;
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global);
if (window) {
nsIDocument* doc = window->GetExtantDoc();
MOZ_ASSERT(doc);
info.InitFromDocument(doc);
} else {
info.InitFromChromeGlobal(global);
}
internalResponse->InitChannelInfo(info);
} else {
workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
internalResponse->InitChannelInfo(worker->GetChannelInfo());
}
nsRefPtr<Response> r = new Response(global, internalResponse);
if (aInit.mHeaders.WasPassed()) {
internalResponse->Headers()->Clear();
// Instead of using Fill, create an object to allow the constructor to
// unwrap the HeadersInit.
nsRefPtr<Headers> headers =
Headers::Create(global, aInit.mHeaders.Value(), aRv);
if (aRv.Failed()) {
return nullptr;
}
internalResponse->Headers()->Fill(*headers->GetInternalHeaders(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
}
if (aBody.WasPassed()) {
nsCOMPtr<nsIInputStream> bodyStream;
nsCString contentType;
aRv = ExtractByteStreamFromBody(aBody.Value(), getter_AddRefs(bodyStream), contentType);
internalResponse->SetBody(bodyStream);
if (!contentType.IsVoid() &&
!internalResponse->Headers()->Has(NS_LITERAL_CSTRING("Content-Type"), aRv)) {
internalResponse->Headers()->Append(NS_LITERAL_CSTRING("Content-Type"), contentType, aRv);
}
if (aRv.Failed()) {
return nullptr;
}
}
r->SetMimeType();
return r.forget();
}
示例2: InternalResponse
/*static*/ already_AddRefed<Response>
Response::Constructor(const GlobalObject& aGlobal,
const Optional<Nullable<fetch::ResponseBodyInit>>& aBody,
const ResponseInit& aInit, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
if (aInit.mStatus < 200 || aInit.mStatus > 599) {
aRv.ThrowRangeError<MSG_INVALID_RESPONSE_STATUSCODE_ERROR>();
return nullptr;
}
// Check if the status text contains illegal characters
nsACString::const_iterator start, end;
aInit.mStatusText.BeginReading(start);
aInit.mStatusText.EndReading(end);
if (FindCharInReadable('\r', start, end)) {
aRv.ThrowTypeError<MSG_RESPONSE_INVALID_STATUSTEXT_ERROR>();
return nullptr;
}
// Reset iterator since FindCharInReadable advances it.
aInit.mStatusText.BeginReading(start);
if (FindCharInReadable('\n', start, end)) {
aRv.ThrowTypeError<MSG_RESPONSE_INVALID_STATUSTEXT_ERROR>();
return nullptr;
}
RefPtr<InternalResponse> internalResponse =
new InternalResponse(aInit.mStatus, aInit.mStatusText);
// Grab a valid channel info from the global so this response is 'valid' for
// interception.
if (NS_IsMainThread()) {
ChannelInfo info;
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
if (window) {
nsIDocument* doc = window->GetExtantDoc();
MOZ_ASSERT(doc);
info.InitFromDocument(doc);
} else {
info.InitFromChromeGlobal(global);
}
internalResponse->InitChannelInfo(info);
} else {
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
internalResponse->InitChannelInfo(worker->GetChannelInfo());
}
RefPtr<Response> r = new Response(global, internalResponse, nullptr);
if (aInit.mHeaders.WasPassed()) {
internalResponse->Headers()->Clear();
// Instead of using Fill, create an object to allow the constructor to
// unwrap the HeadersInit.
RefPtr<Headers> headers =
Headers::Create(global, aInit.mHeaders.Value(), aRv);
if (aRv.Failed()) {
return nullptr;
}
internalResponse->Headers()->Fill(*headers->GetInternalHeaders(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
}
if (aBody.WasPassed() && !aBody.Value().IsNull()) {
if (aInit.mStatus == 204 || aInit.mStatus == 205 || aInit.mStatus == 304) {
aRv.ThrowTypeError<MSG_RESPONSE_NULL_STATUS_WITH_BODY>();
return nullptr;
}
nsCString contentTypeWithCharset;
nsCOMPtr<nsIInputStream> bodyStream;
int64_t bodySize = InternalResponse::UNKNOWN_BODY_SIZE;
const fetch::ResponseBodyInit& body = aBody.Value().Value();
if (body.IsReadableStream()) {
aRv.MightThrowJSException();
JSContext* cx = aGlobal.Context();
const ReadableStream& readableStream = body.GetAsReadableStream();
JS::Rooted<JSObject*> readableStreamObj(cx, readableStream.Obj());
bool disturbed;
bool locked;
if (!JS::ReadableStreamIsDisturbed(cx, readableStreamObj, &disturbed) ||
!JS::ReadableStreamIsLocked(cx, readableStreamObj, &locked)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
if (disturbed || locked) {
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
return nullptr;
}
r->SetReadableStreamBody(cx, readableStreamObj);
//.........这里部分代码省略.........