Bug 1058470 - Blob URL should contain the origin as part of the URI, r=bz

This commit is contained in:
Andrea Marchesini 2014-08-31 11:40:11 +01:00
parent 0e42e71b6c
commit eee60d5ec4
16 changed files with 49 additions and 66 deletions

View File

@ -55,8 +55,8 @@ function* navigate(usage, options) {
* Check the expected pages have been visited
*/
function* checkPages(usage) {
// 'load' event order. '' is for the initial location
let expectedVisited = [ '', PAGE_2, PAGE_1, PAGE_3 ];
// 'load' event order. 'null' is for the initial location
let expectedVisited = [ 'null', PAGE_2, PAGE_1, PAGE_3 ];
let actualVisited = yield usage._testOnly_visitedPages();
isEqualJson(actualVisited, expectedVisited, 'Visited');
}

View File

@ -1592,7 +1592,6 @@ public:
static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal,
nsString& aOrigin);
static nsresult GetUTFOrigin(nsIURI* aURI, nsString& aOrigin);
static void GetUTFNonNullOrigin(nsIURI* aURI, nsString& aOrigin);
/**
* This method creates and dispatches "command" event, which implements

View File

@ -41,7 +41,9 @@ public:
NS_IMETHOD NewChannel(nsIURI *aURI, nsIChannel * *_retval) MOZ_OVERRIDE;
NS_IMETHOD AllowPort(int32_t port, const char * scheme, bool *_retval) MOZ_OVERRIDE;
// If principal is not null, its origin will be used to generate the URI.
static nsresult GenerateURIString(const nsACString &aScheme,
nsIPrincipal* aPrincipal,
nsACString &aUri);
// Methods for managing uri->object mapping

View File

@ -282,7 +282,7 @@ Link::GetOrigin(nsAString &aOrigin, ErrorResult& aError)
}
nsString origin;
nsContentUtils::GetUTFNonNullOrigin(uri, origin);
nsContentUtils::GetUTFOrigin(uri, origin);
aOrigin.Assign(origin);
}

View File

@ -5830,19 +5830,6 @@ nsContentUtils::GetUTFOrigin(nsIURI* aURI, nsString& aOrigin)
return NS_OK;
}
/* static */
void
nsContentUtils::GetUTFNonNullOrigin(nsIURI* aURI, nsString& aOrigin)
{
aOrigin.Truncate();
nsString origin;
nsresult rv = GetUTFOrigin(aURI, origin);
if (NS_SUCCEEDED(rv) && !origin.EqualsLiteral("null")) {
aOrigin.Assign(origin);
}
}
/* static */
nsIDocument*
nsContentUtils::GetDocumentFromScriptContext(nsIScriptContext *aScriptContext)

View File

@ -301,7 +301,7 @@ nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aScheme,
{
Init();
nsresult rv = GenerateURIString(aScheme, aUri);
nsresult rv = GenerateURIString(aScheme, aPrincipal, aUri);
NS_ENSURE_SUCCESS(rv, rv);
if (!gDataTable) {
@ -340,6 +340,7 @@ nsHostObjectProtocolHandler::RemoveDataEntry(const nsACString& aUri)
nsresult
nsHostObjectProtocolHandler::GenerateURIString(const nsACString &aScheme,
nsIPrincipal* aPrincipal,
nsACString& aUri)
{
nsresult rv;
@ -354,8 +355,20 @@ nsHostObjectProtocolHandler::GenerateURIString(const nsACString &aScheme,
char chars[NSID_LENGTH];
id.ToProvidedString(chars);
aUri += aScheme;
aUri += NS_LITERAL_CSTRING(":");
aUri = aScheme;
aUri.Append(':');
if (aPrincipal) {
nsAutoString origin;
rv = nsContentUtils::GetUTFOrigin(aPrincipal, origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
AppendUTF16toUTF8(origin, aUri);
aUri.Append('/');
}
aUri += Substring(chars + 1, chars + NSID_LENGTH - 2);
return NS_OK;

View File

@ -203,16 +203,6 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aURL)
}
}
nsIPrincipal*
URL::GetPrincipalFromURL(const GlobalObject& aGlobal, const nsAString& aURL,
ErrorResult& aRv)
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
NS_LossyConvertUTF16toASCII asciiurl(aURL);
return nsHostObjectProtocolHandler::GetDataEntryPrincipal(asciiurl);
}
void
URL::GetHref(nsString& aHref, ErrorResult& aRv) const
{
@ -252,7 +242,18 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
void
URL::GetOrigin(nsString& aOrigin, ErrorResult& aRv) const
{
nsContentUtils::GetUTFNonNullOrigin(mURI, aOrigin);
nsCOMPtr<nsIURIWithPrincipal> uriWithPrincipal = do_QueryInterface(mURI);
if (uriWithPrincipal) {
nsCOMPtr<nsIPrincipal> principal;
uriWithPrincipal->GetPrincipal(getter_AddRefs(principal));
if (principal) {
nsContentUtils::GetUTFOrigin(principal, aOrigin);
return;
}
}
nsContentUtils::GetUTFOrigin(mURI, aOrigin);
}
void

View File

@ -69,9 +69,6 @@ public:
ErrorResult& aError);
static void RevokeObjectURL(const GlobalObject& aGlobal,
const nsAString& aURL);
static nsIPrincipal* GetPrincipalFromURL(const GlobalObject& aGlobal,
const nsAString& aURL,
ErrorResult& aError);
void GetHref(nsString& aHref, ErrorResult& aRv) const;

View File

@ -13,9 +13,9 @@ this.checkFromJSM = function checkFromJSM(ok, is) {
var url = URL.createObjectURL(blob);
ok(url, "URL is created!");
var p = URL.getPrincipalFromURL(url);
ok(p, "Principal exists.");
ok(p instanceof Components.interfaces.nsIPrincipal, "Principal is a nsIPrincipal");
var u = new URL(url);
ok(u, "URL created");
is(u.origin, "null", "Url doesn't have an origin if created in a JSM");
URL.revokeObjectURL(url);
ok(true, "URL is revoked");

View File

@ -324,14 +324,8 @@
var blob = new Blob(['a']);
var url = URL.createObjectURL(blob);
ok(!('getPrincipalFromURL' in URL), "URL.getPrincipalFromURL is not exposed");
var fakeP = SpecialPowers.wrap(URL).getPrincipalFromURL("hello world!");
ok(!fakeP, "Principal doesn't exists.");
var p = SpecialPowers.wrap(URL).getPrincipalFromURL(url);
ok(p, "Principal exists.");
ok(p.URI, "Principal.URI exists.");
is(p.URI.spec, window.location.href, "Principal.URI is correct");
var u = new URL(url);
ok(u.origin, 'http://mochi.test:8888', "The URL generated from a blob URI has an origin");
</script>
</body>
</html>

View File

@ -38,9 +38,3 @@ partial interface URL {
[Throws]
static DOMString? createObjectURL(MediaSource source, optional objectURLOptions options);
};
// mozilla extensions
partial interface URL {
[Throws, ChromeOnly]
static Principal getPrincipalFromURL(DOMString blobURL);
};

View File

@ -893,16 +893,6 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl)
}
}
// static
nsIPrincipal*
URL::GetPrincipalFromURL(const GlobalObject& aGlobal, const nsAString& aUrl,
ErrorResult& aRv)
{
// This method is not implemented in workers.
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
return nullptr;
}
void
URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
{

View File

@ -69,10 +69,6 @@ public:
static void
RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl);
static nsIPrincipal* GetPrincipalFromURL(const GlobalObject& aGlobal,
const nsAString& aURL,
ErrorResult& aError);
void GetHref(nsString& aHref, ErrorResult& aRv) const;
void SetHref(const nsAString& aHref, ErrorResult& aRv);

View File

@ -3375,7 +3375,7 @@ WorkerPrivateParent<Derived>::SetBaseURI(nsIURI* aBaseURI)
mLocationInfo.mHost.Assign(mLocationInfo.mHostname);
}
nsContentUtils::GetUTFNonNullOrigin(aBaseURI, mLocationInfo.mOrigin);
nsContentUtils::GetUTFOrigin(aBaseURI, mLocationInfo.mOrigin);
}
template <class Derived>

View File

@ -78,5 +78,14 @@ onmessage = function(event) {
postMessage({type: 'status', status: status, msg: 'Exception wanted' });
var blob = new Blob([123]);
var uri = URL.createObjectURL(blob);
postMessage({type: 'status', status: !!uri,
msg: "The URI has been generated from the blob"});
var u = new URL(uri);
postMessage({type: 'status', status: u.origin == 'http://mochi.test:8888',
msg: "The URL generated from a blob URI has an origin."});
postMessage({type: 'finish' });
}

View File

@ -342,6 +342,7 @@ gfxSVGGlyphsDocument::ParseDocument(const uint8_t *aBuffer, uint32_t aBufLen)
nsCOMPtr<nsIURI> uri;
nsHostObjectProtocolHandler::GenerateURIString(NS_LITERAL_CSTRING(FONTTABLEURI_SCHEME),
nullptr,
mSVGGlyphsDocumentURI);
rv = NS_NewURI(getter_AddRefs(uri), mSVGGlyphsDocumentURI);