зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1155898 - Fetch support for running outside of window/worker. r=nsm
--HG-- extra : transplant_source : %90P%A2O%7F%89%06%BF%AE_Q%0D%95%BEI%CC%85%E1%B2%40
This commit is contained in:
Родитель
b5e6bf097a
Коммит
b87ff904d8
|
@ -224,23 +224,34 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
|
||||||
|
|
||||||
if (NS_IsMainThread()) {
|
if (NS_IsMainThread()) {
|
||||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal);
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal);
|
||||||
if (!window) {
|
nsCOMPtr<nsIDocument> doc;
|
||||||
aRv.Throw(NS_ERROR_FAILURE);
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
||||||
return nullptr;
|
nsIPrincipal* principal;
|
||||||
}
|
if (window) {
|
||||||
|
doc = window->GetExtantDoc();
|
||||||
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
|
if (!doc) {
|
||||||
if (!doc) {
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
aRv.Throw(NS_ERROR_FAILURE);
|
return nullptr;
|
||||||
return nullptr;
|
}
|
||||||
|
principal = doc->NodePrincipal();
|
||||||
|
loadGroup = doc->GetDocumentLoadGroup();
|
||||||
|
} else {
|
||||||
|
principal = aGlobal->PrincipalOrNull();
|
||||||
|
if (NS_WARN_IF(!principal)) {
|
||||||
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
nsresult rv = NS_NewLoadGroup(getter_AddRefs(loadGroup), principal);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
aRv.Throw(rv);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Telemetry::Accumulate(Telemetry::FETCH_IS_MAINTHREAD, 1);
|
Telemetry::Accumulate(Telemetry::FETCH_IS_MAINTHREAD, 1);
|
||||||
|
|
||||||
nsRefPtr<MainThreadFetchResolver> resolver = new MainThreadFetchResolver(p);
|
nsRefPtr<MainThreadFetchResolver> resolver = new MainThreadFetchResolver(p);
|
||||||
nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup();
|
nsRefPtr<FetchDriver> fetch = new FetchDriver(r, principal, loadGroup);
|
||||||
nsRefPtr<FetchDriver> fetch =
|
|
||||||
new FetchDriver(r, doc->NodePrincipal(), loadGroup);
|
|
||||||
fetch->SetDocument(doc);
|
fetch->SetDocument(doc);
|
||||||
aRv = fetch->Fetch(resolver);
|
aRv = fetch->Fetch(resolver);
|
||||||
if (NS_WARN_IF(aRv.Failed())) {
|
if (NS_WARN_IF(aRv.Failed())) {
|
||||||
|
@ -411,6 +422,23 @@ UpdateRequestReferrer(nsIGlobalObject* aGlobal, InternalRequest* aRequest)
|
||||||
doc->GetReferrer(referrer);
|
doc->GetReferrer(referrer);
|
||||||
aRequest->SetReferrer(referrer);
|
aRequest->SetReferrer(referrer);
|
||||||
}
|
}
|
||||||
|
} else if (NS_IsMainThread()) {
|
||||||
|
// Pull the principal from the global for non-worker scripts.
|
||||||
|
nsIPrincipal *principal = aGlobal->PrincipalOrNull();
|
||||||
|
bool isNull;
|
||||||
|
// Only set the referrer if the principal is present,
|
||||||
|
// and the principal is not null or the system principal.
|
||||||
|
if (principal &&
|
||||||
|
NS_SUCCEEDED(principal->GetIsNullPrincipal(&isNull)) && !isNull &&
|
||||||
|
!nsContentUtils::IsSystemPrincipal(principal)) {
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
if (NS_SUCCEEDED(principal->GetURI(getter_AddRefs(uri))) && uri) {
|
||||||
|
nsAutoCString referrer;
|
||||||
|
if (NS_SUCCEEDED(uri->GetSpec(referrer))) {
|
||||||
|
aRequest->SetReferrer(NS_ConvertUTF8toUTF16(referrer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
||||||
MOZ_ASSERT(worker);
|
MOZ_ASSERT(worker);
|
||||||
|
|
|
@ -39,6 +39,7 @@ function testSameOriginBlobURL() {
|
||||||
var blob = new Blob(["english ", "sentence"], { type: "text/plain" });
|
var blob = new Blob(["english ", "sentence"], { type: "text/plain" });
|
||||||
var url = URL.createObjectURL(blob);
|
var url = URL.createObjectURL(blob);
|
||||||
return fetch(url).then(function(res) {
|
return fetch(url).then(function(res) {
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
ok(true, "Blob URL fetch should resolve");
|
ok(true, "Blob URL fetch should resolve");
|
||||||
if (res.type == "error") {
|
if (res.type == "error") {
|
||||||
ok(false, "Blob URL fetch should not fail.");
|
ok(false, "Blob URL fetch should not fail.");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче