本文整理汇总了C++中WorkerPrivate::GetPrincipalInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkerPrivate::GetPrincipalInfo方法的具体用法?C++ WorkerPrivate::GetPrincipalInfo怎么用?C++ WorkerPrivate::GetPrincipalInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkerPrivate
的用法示例。
在下文中一共展示了WorkerPrivate::GetPrincipalInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
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);
UniquePtr<mozilla::ipc::PrincipalInfo> principalInfo;
// 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) {
Document* doc = window->GetExtantDoc();
MOZ_ASSERT(doc);
info.InitFromDocument(doc);
principalInfo.reset(new mozilla::ipc::PrincipalInfo());
nsresult rv =
PrincipalToPrincipalInfo(doc->NodePrincipal(), principalInfo.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
return nullptr;
}
internalResponse->InitChannelInfo(info);
} else if (nsContentUtils::IsSystemPrincipal(global->PrincipalOrNull())) {
info.InitFromChromeGlobal(global);
internalResponse->InitChannelInfo(info);
}
/**
* The channel info is left uninitialized if neither the above `if` nor
* `else if` statements are executed; this could be because we're in a
* WebExtensions content script, where the global (i.e. `global`) is a
* wrapper, and the principal is an expanded principal. In this case,
* as far as I can tell, there's no way to get the security info, but we'd
* like the `Response` to be successfully constructed.
*/
} else {
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
internalResponse->InitChannelInfo(worker->GetChannelInfo());
principalInfo =
MakeUnique<mozilla::ipc::PrincipalInfo>(worker->GetPrincipalInfo());
}
internalResponse->SetPrincipalInfo(std::move(principalInfo));
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()) {
//.........这里部分代码省略.........