Backed out 3 changesets (bug 1155898) for test_sandbox_fetch.html failures.

Backed out changeset 21e041962894 (bug 1155898)
Backed out changeset e42c9f4794d9 (bug 1155898)
Backed out changeset 7ef9cce1a775 (bug 1155898)

CLOSED TREE
This commit is contained in:
Ryan VanderMeulen 2015-05-20 11:54:34 -04:00
parent 8a67ad1cd5
commit 9e434dd3f0
8 changed files with 19 additions and 189 deletions

View File

@ -224,34 +224,23 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal);
nsCOMPtr<nsIDocument> doc;
nsCOMPtr<nsILoadGroup> loadGroup;
nsIPrincipal* principal;
if (window) {
doc = window->GetExtantDoc();
if (!doc) {
aRv.Throw(NS_ERROR_FAILURE);
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;
}
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (!doc) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
Telemetry::Accumulate(Telemetry::FETCH_IS_MAINTHREAD, 1);
nsRefPtr<MainThreadFetchResolver> resolver = new MainThreadFetchResolver(p);
nsRefPtr<FetchDriver> fetch = new FetchDriver(r, principal, loadGroup);
nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup();
nsRefPtr<FetchDriver> fetch =
new FetchDriver(r, doc->NodePrincipal(), loadGroup);
fetch->SetDocument(doc);
aRv = fetch->Fetch(resolver);
if (NS_WARN_IF(aRv.Failed())) {
@ -422,23 +411,6 @@ UpdateRequestReferrer(nsIGlobalObject* aGlobal, InternalRequest* aRequest)
doc->GetReferrer(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 {
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);

View File

@ -207,7 +207,7 @@ IdpSandbox.prototype = {
wantGlobalProperties: [
'indexedDB', 'XMLHttpRequest', 'TextEncoder', 'TextDecoder',
'URL', 'URLSearchParams', 'atob', 'btoa', 'Blob', 'crypto',
'rtcIdentityProvider', 'fetch'
'rtcIdentityProvider'
]
});
let registrar = this.sandbox.rtcIdentityProvider;

View File

@ -21,8 +21,12 @@
IDPJS.prototype = {
getLogin: function() {
return fetch('https://example.com/.well-known/idp-proxy/idp.sjs?' + this.id)
.then(response => response.status === 200);
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://example.com/.well-known/idp-proxy/idp.sjs?' + this.id);
return new Promise(resolve => {
xhr.onload = e => resolve(xhr.status === 200);
xhr.send();
});
},
checkLogin: function(result) {
return this.getLogin()

View File

@ -39,7 +39,6 @@ function testSameOriginBlobURL() {
var blob = new Blob(["english ", "sentence"], { type: "text/plain" });
var url = URL.createObjectURL(blob);
return fetch(url).then(function(res) {
URL.revokeObjectURL(url);
ok(true, "Blob URL fetch should resolve");
if (res.type == "error") {
ok(false, "Blob URL fetch should not fail.");

View File

@ -33,16 +33,11 @@
#include "mozilla/dom/CSSBinding.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/FileBinding.h"
#include "mozilla/dom/Fetch.h"
#include "mozilla/dom/HeadersBinding.h"
#include "mozilla/dom/PromiseBinding.h"
#include "mozilla/dom/RequestBinding.h"
#include "mozilla/dom/ResponseBinding.h"
#include "mozilla/dom/RTCIdentityProviderRegistrar.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/TextDecoderBinding.h"
#include "mozilla/dom/TextEncoderBinding.h"
#include "mozilla/dom/UnionConversions.h"
#include "mozilla/dom/URLBinding.h"
#include "mozilla/dom/URLSearchParamsBinding.h"
@ -241,83 +236,6 @@ SandboxCreateRTCIdentityProvider(JSContext* cx, JS::HandleObject obj)
return JS_DefineProperty(cx, obj, "rtcIdentityProvider", wrapped, JSPROP_ENUMERATE);
}
static bool
SetFetchRequestFromValue(JSContext *cx, RequestOrUSVString& request,
const MutableHandleValue& requestOrUrl)
{
RequestOrUSVStringArgument requestHolder(request);
bool noMatch = true;
if (requestOrUrl.isObject() &&
!requestHolder.TrySetToRequest(cx, requestOrUrl, noMatch, false)) {
return false;
}
if (noMatch &&
!requestHolder.TrySetToUSVString(cx, requestOrUrl, noMatch)) {
return false;
}
if (noMatch) {
return false;
}
return true;
}
static bool
SandboxFetch(JSContext* cx, JS::HandleObject scope, const CallArgs& args)
{
if (args.length() < 1) {
JS_ReportError(cx, "fetch requires at least 1 argument");
return false;
}
RequestOrUSVString request;
if (!SetFetchRequestFromValue(cx, request, args[0])) {
JS_ReportError(cx, "fetch requires a string or Request in argument 1");
return false;
}
RootedDictionary<dom::RequestInit> options(cx);
if (!options.Init(cx, args.hasDefined(1) ? args[1] : JS::NullHandleValue,
"Argument 2 of fetch", false)) {
return false;
}
nsCOMPtr<nsIGlobalObject> global = xpc::NativeGlobal(scope);
if (!global) {
return false;
}
ErrorResult rv;
nsRefPtr<dom::Promise> response =
FetchRequest(global, Constify(request), Constify(options), rv);
rv.WouldReportJSException();
if (rv.Failed()) {
return ThrowMethodFailedWithDetails(cx, rv, "Sandbox", "fetch");
}
if (!GetOrCreateDOMReflector(cx, scope, response, args.rval())) {
return false;
}
return true;
}
static bool SandboxFetchPromise(JSContext* cx, unsigned argc, jsval* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject callee(cx, &args.callee());
RootedObject scope(cx, JS::CurrentGlobalOrNull(cx));
if (SandboxFetch(cx, scope, args)) {
return true;
}
return ConvertExceptionToPromise(cx, scope, args.rval());
}
static bool
SandboxCreateFetch(JSContext* cx, HandleObject obj)
{
MOZ_ASSERT(JS_IsGlobalObject(obj));
return JS_DefineFunction(cx, obj, "fetch", SandboxFetchPromise, 2, 0) &&
dom::RequestBinding::GetConstructorObject(cx, obj) &&
dom::ResponseBinding::GetConstructorObject(cx, obj) &&
dom::HeadersBinding::GetConstructorObject(cx, obj);
}
static bool
SandboxIsProxy(JSContext* cx, unsigned argc, jsval* vp)
{
@ -900,8 +818,6 @@ xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj)
crypto = true;
} else if (!strcmp(name.ptr(), "rtcIdentityProvider")) {
rtcIdentityProvider = true;
} else if (!strcmp(name.ptr(), "fetch")) {
fetch = true;
} else {
JS_ReportError(cx, "Unknown property name: %s", name.ptr());
return false;
@ -962,9 +878,6 @@ xpc::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj)
if (rtcIdentityProvider && !SandboxCreateRTCIdentityProvider(cx, obj))
return false;
if (fetch && !SandboxCreateFetch(cx, obj))
return false;
return true;
}

View File

@ -3400,7 +3400,6 @@ struct GlobalProperties {
bool File : 1;
bool crypto : 1;
bool rtcIdentityProvider : 1;
bool fetch : 1;
};
// Infallible.

View File

@ -105,6 +105,3 @@ skip-if= buildapp == 'mulet'
skip-if = (debug == false || os == "android")
[test_nac.xhtml]
[test_sameOriginPolicy.html]
[test_sandbox_fetch.html]
support-files =
../../../../dom/tests/mochitest/fetch/test_fetch_basic.js

View File

@ -1,54 +0,0 @@
<!doctype html>
<html>
<head>
<title>Fetch In JS Sandbox</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
<script src="test_fetch_basic.js"></script>
</head>
<body>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function testHttpFetch(url) {
info('fetch: ' + url);
return fetch(new Request(url, { method: 'GET' }))
.then(response => {
is(response.status, 200, 'Response is 200');
is(response.url, url, 'Response URL matches');
});
}
function runSandboxTest(testFunc, argString) {
is(typeof testFunc, 'function');
var resolveTest;
var testPromise = new Promise(r => resolveTest = r);
var finishFuncName = 'finish_' + testFunc.name;
SpecialPowers.Cu.exportFunction(_ => resolvePromise(), sb,
{ defineAs: finishFuncName });
SpecialPowers.Cu.evalInSandbox('(' + testFunc.toSource() + ')' +
'(' + argString + ')' +
'.then(' + finishFuncName + ');', sb);
return testPromise;
}
var origin = 'https://example.com';
var properties = ['fetch', 'Blob', 'URL'];
var sb = new SpecialPowers.Cu.Sandbox(origin,
{ wantGlobalProperties: properties });
sb.ok = SpecialPowers.Cu.exportFunction(ok, sb);
sb.is = SpecialPowers.Cu.exportFunction(is, sb);
sb.info = SpecialPowers.Cu.exportFunction(info, sb);
Promise.resolve()
.then(_ => runSandboxTest(testHttpFetch, '"' + origin + window.location.pathname + '"'))
.then(_ => runSandboxTest(testAboutURL))
.then(_ => runSandboxTest(testDataURL))
.then(_ => runSandboxTest(testSameOriginBlobURL))
.then(_ => SimpleTest.finish());
</script>
</body>
</html>