зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1306170 part 6. Implement WindowOrWorkerGlobalScope.origin. r=bkelly
This commit is contained in:
Родитель
19cf0c0f4e
Коммит
e1822e6a63
|
@ -9976,6 +9976,13 @@ nsGlobalWindow::Find(const nsAString& aString, bool aCaseSensitive,
|
|||
aError, false);
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::GetOrigin(nsAString& aOrigin)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsInnerWindow());
|
||||
nsContentUtils::GetUTFOrigin(GetPrincipal(), aOrigin);
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::Atob(const nsAString& aAsciiBase64String,
|
||||
nsAString& aBinaryData, ErrorResult& aError)
|
||||
|
|
|
@ -1004,6 +1004,7 @@ public:
|
|||
const mozilla::dom::Sequence<JS::Value>& /* unused */,
|
||||
mozilla::ErrorResult& aError);
|
||||
void ClearInterval(int32_t aHandle);
|
||||
void GetOrigin(nsAString& aOrigin);
|
||||
void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData,
|
||||
mozilla::ErrorResult& aError);
|
||||
void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin
|
||||
[NoInterfaceObject, Exposed=(Window,Worker)]
|
||||
interface WindowOrWorkerGlobalScope {
|
||||
// XXXbz We don't implement 'origin' yet on either window or worker globals.
|
||||
// See bug 1306170.
|
||||
// [Replaceable] readonly attribute USVString origin;
|
||||
[Replaceable] readonly attribute USVString origin;
|
||||
|
||||
// base64 utility methods
|
||||
[Throws]
|
||||
|
|
|
@ -1820,6 +1820,7 @@ WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther)
|
|||
mPrincipalInfo = aOther.mPrincipalInfo.forget();
|
||||
|
||||
mDomain = aOther.mDomain;
|
||||
mOrigin = aOther.mOrigin;
|
||||
mServiceWorkerCacheName = aOther.mServiceWorkerCacheName;
|
||||
mLoadFlags = aOther.mLoadFlags;
|
||||
mWindowID = aOther.mWindowID;
|
||||
|
@ -1874,6 +1875,9 @@ WorkerLoadInfo::SetPrincipalOnMainThread(nsIPrincipal* aPrincipal,
|
|||
rv = PrincipalToPrincipalInfo(aPrincipal, mPrincipalInfo);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = nsContentUtils::GetUTFOrigin(aPrincipal, mOrigin);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -591,6 +591,11 @@ public:
|
|||
return mLoadInfo.mPrincipal;
|
||||
}
|
||||
|
||||
const nsAString& Origin() const
|
||||
{
|
||||
return mLoadInfo.mOrigin;
|
||||
}
|
||||
|
||||
nsILoadGroup*
|
||||
GetLoadGroup() const
|
||||
{
|
||||
|
|
|
@ -335,6 +335,13 @@ WorkerGlobalScope::ClearInterval(int32_t aHandle)
|
|||
mWorkerPrivate->ClearTimeout(aHandle);
|
||||
}
|
||||
|
||||
void
|
||||
WorkerGlobalScope::GetOrigin(nsAString& aOrigin) const
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
aOrigin = mWorkerPrivate->Origin();
|
||||
}
|
||||
|
||||
void
|
||||
WorkerGlobalScope::Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const
|
||||
{
|
||||
|
|
|
@ -139,6 +139,9 @@ public:
|
|||
void
|
||||
ClearInterval(int32_t aHandle);
|
||||
|
||||
void
|
||||
GetOrigin(nsAString& aOrigin) const;
|
||||
|
||||
void
|
||||
Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const;
|
||||
void
|
||||
|
|
|
@ -254,6 +254,7 @@ struct WorkerLoadInfo
|
|||
|
||||
nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
||||
nsCString mDomain;
|
||||
nsString mOrigin; // Derived from mPrincipal; can be used on worker thread.
|
||||
|
||||
nsString mServiceWorkerCacheName;
|
||||
|
||||
|
|
|
@ -45951,6 +45951,11 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"html/dom/resources/self-origin-subframe.html": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"html/dom/resources/untested-interfaces.idl": [
|
||||
[
|
||||
{}
|
||||
|
@ -89836,6 +89841,22 @@
|
|||
}
|
||||
]
|
||||
],
|
||||
"html/dom/self-origin.any.js": [
|
||||
[
|
||||
"/html/dom/self-origin.any.html",
|
||||
{}
|
||||
],
|
||||
[
|
||||
"/html/dom/self-origin.any.worker.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"html/dom/self-origin.sub.html": [
|
||||
[
|
||||
"/html/dom/self-origin.sub.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"html/editing/activation/click.html": [
|
||||
[
|
||||
"/html/editing/activation/click.html",
|
||||
|
@ -167472,7 +167493,7 @@
|
|||
"testharness"
|
||||
],
|
||||
"html/dom/interfaces.worker.js": [
|
||||
"274d32f84c7511fda136212bb9dc146a2cb7f2a7",
|
||||
"9e91d411453d4fdbcead08ad9daccbe2d9d7a975",
|
||||
"testharness"
|
||||
],
|
||||
"html/dom/new-harness.js": [
|
||||
|
@ -167528,13 +167549,25 @@
|
|||
"support"
|
||||
],
|
||||
"html/dom/resources/interfaces.idl": [
|
||||
"d4e094978d8cc85a4dc9f6bf34c12b295a12eb34",
|
||||
"ff2f4c38a4c67be041ce21c60c7591cea0017f60",
|
||||
"support"
|
||||
],
|
||||
"html/dom/resources/self-origin-subframe.html": [
|
||||
"a94fee503c6ad28fdedf1f62fcd96465f7b88e71",
|
||||
"support"
|
||||
],
|
||||
"html/dom/resources/untested-interfaces.idl": [
|
||||
"d3a65dce1b6832b90a8318d121ac2f1e43decdfc",
|
||||
"support"
|
||||
],
|
||||
"html/dom/self-origin.any.js": [
|
||||
"187b3657775b815f9360c01d2ddb358a53e1f920",
|
||||
"testharness"
|
||||
],
|
||||
"html/dom/self-origin.sub.html": [
|
||||
"d821d4b41ac8517d345f86a9f8298f67284d1967",
|
||||
"testharness"
|
||||
],
|
||||
"html/editing/.gitkeep": [
|
||||
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
||||
"support"
|
||||
|
|
|
@ -1649,6 +1649,8 @@ typedef (DOMString or Function) TimerHandler;
|
|||
|
||||
[NoInterfaceObject, Exposed=(Window,Worker)]
|
||||
interface WindowOrWorkerGlobalScope {
|
||||
[Replaceable] readonly attribute USVString origin;
|
||||
|
||||
// base64 utility methods
|
||||
DOMString btoa(DOMString btoa);
|
||||
DOMString atob(DOMString atob);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<script>
|
||||
window.onmessage = function(e){
|
||||
if (e.data == "getOrigin") {
|
||||
parent.postMessage(self.origin, "*");
|
||||
} else if (e.data == "setDomainAndGetOrigin") {
|
||||
var oldDomain = document.domain;
|
||||
try {
|
||||
document.domain = document.domain.replace(/^[^.]*./, "");
|
||||
} catch (e) {
|
||||
parent.postMessage("THREW WHEN SETTING DOMAIN: " + e, "*");
|
||||
return;
|
||||
}
|
||||
if (oldDomain === document.domain) {
|
||||
parent.postMessage("FAILED TO SET DOMAIN", "*");
|
||||
} else {
|
||||
parent.postMessage(self.origin, "*");
|
||||
}
|
||||
} else {
|
||||
parent.postMessage("UNEXPECTED MESSAGE", "*");
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
test(function() {
|
||||
assert_equals(self.origin, "http://" + location.host);
|
||||
}, "self.origin should be correct");
|
|
@ -0,0 +1,93 @@
|
|||
<!DOCTYPE HTML>
|
||||
<meta charset=utf-8>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<iframe></iframe>
|
||||
<iframe id="blob-test"></iframe> <!-- will get blob: URI -->
|
||||
<iframe src="javascript:'javascript'"></iframe>
|
||||
<iframe srcdoc="srcdoc"></iframe>
|
||||
<!-- Use the non-default HTTP port so we can make sure it gets included in
|
||||
self.origin -->
|
||||
<iframe src="http://{{domains[www1]}}:{{ports[http][1]}}{{location[path]}}/../resources/self-origin-subframe.html"></iframe>
|
||||
<!-- Using the punycode version on purpose, we expect to get back the IDNA
|
||||
version in self.origin -->
|
||||
<iframe src="http://xn--lve-6lad.{{domains[]}}:{{ports[http][1]}}{{location[path]}}/../resources/self-origin-subframe.html"></iframe>
|
||||
<iframe src="resources/self-origin-subframe.html" sandbox="allow-scripts"></iframe>
|
||||
<script type="application/javascript">
|
||||
test(function() {
|
||||
var blob = new Blob(['blob']);
|
||||
var url = URL.createObjectURL(blob);
|
||||
document.getElementById("blob-test").src = url;
|
||||
}, "Assigning blob url");
|
||||
|
||||
/* Each message test is a four things: window to send message to, message to
|
||||
send, expected response, async test to use. */
|
||||
var messageTests = [
|
||||
[ frames[4], "getOrigin", "http://{{domains[www1]}}:{{ports[http][1]}}",
|
||||
async_test("Should have the right origin for cross-origin subframe") ],
|
||||
[ frames[4], "setDomainAndGetOrigin", "http://{{domains[www1]}}:{{ports[http][1]}}",
|
||||
async_test("Should have the right origin for cross-origin subframe after setting document.domain") ],
|
||||
[ frames[5], "getOrigin", "http://élève.{{domains[]}}:{{ports[http][1]}}",
|
||||
async_test("Should have the right origin for IDN subframe") ],
|
||||
[ frames[5], "setDomainAndGetOrigin", "http://élève.{{domains[]}}:{{ports[http][1]}}",
|
||||
async_test("Should have the right origin for IDN subframe after setting document.domain") ],
|
||||
[ frames[6], "getOrigin", "null",
|
||||
async_test("Should have the right origin for sandboxed iframe") ],
|
||||
];
|
||||
|
||||
var curTest = 0;
|
||||
function nextMessageTest() {
|
||||
if (curTest == messageTests.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var testData = messageTests[curTest];
|
||||
testData[0].postMessage(testData[1], "*");
|
||||
}
|
||||
|
||||
window.onmessage = function(e) {
|
||||
var testData = messageTests[curTest++];
|
||||
testData[3].step_func(function() {
|
||||
assert_equals(e.data, testData[2])
|
||||
});
|
||||
testData[3].done();
|
||||
nextMessageTest();
|
||||
}
|
||||
|
||||
addEventListener("load", nextMessageTest);
|
||||
|
||||
test(function() {
|
||||
assert_equals(self.origin, "http://{{location[host]}}");
|
||||
}, "We should have the right origin for our page");
|
||||
|
||||
var t1 = async_test("about:blank subframe origins");
|
||||
addEventListener("load", t1.step_func_done(function() {
|
||||
assert_equals(frames[0].location.origin, "null",
|
||||
"Should have the right location origin for about:blank iframe");
|
||||
assert_equals(frames[0].origin, "http://{{location[host]}}",
|
||||
"Should have the right origin for about:blank iframe");
|
||||
}));
|
||||
|
||||
var t2 = async_test("blob: subframe origins");
|
||||
addEventListener("load", t2.step_func_done(function() {
|
||||
assert_equals(frames[1].location.origin, "http://{{location[host]}}",
|
||||
"Should have the right location origin for blob: iframe");
|
||||
assert_equals(frames[1].origin, "http://{{location[host]}}",
|
||||
"Should have the right origin for blob: iframe");
|
||||
}));
|
||||
|
||||
var t3 = async_test("javascript: subframe origins");
|
||||
addEventListener("load", t3.step_func_done(function() {
|
||||
assert_equals(frames[2].origin, "http://{{location[host]}}",
|
||||
"Should have the right origin for javascript: iframe");
|
||||
}));
|
||||
|
||||
var t4 = async_test("srcdoc subframe origins");
|
||||
addEventListener("load", t4.step_func_done(function() {
|
||||
assert_equals(frames[3].location.origin, "null",
|
||||
"Should have the right location origin for srcdoc iframe");
|
||||
assert_equals(frames[3].origin, "http://{{location[host]}}",
|
||||
"Should have the right origin for srcdoc iframe");
|
||||
}));
|
||||
</script>
|
Загрузка…
Ссылка в новой задаче