mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1046240 - Expose the principal for a blob URI for chrome-only js code. r=smaug
This commit is contained in:
parent
e984d4c73c
commit
6aa8d79e5d
@ -203,6 +203,16 @@ 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
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIDOMBlob;
|
||||
class nsIPrincipal;
|
||||
class nsISupports;
|
||||
class nsIURI;
|
||||
|
||||
@ -68,6 +69,9 @@ 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;
|
||||
|
||||
|
@ -13,6 +13,10 @@ 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");
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
ok(true, "URL is revoked");
|
||||
}
|
||||
|
@ -319,5 +319,19 @@
|
||||
url.hostname = "2001::1";
|
||||
is(url.hostname, "localhost", "Setting bad hostname fails");
|
||||
</script>
|
||||
|
||||
<script>
|
||||
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");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -38,3 +38,9 @@ partial interface URL {
|
||||
[Throws]
|
||||
static DOMString? createObjectURL(MediaSource source, optional objectURLOptions options);
|
||||
};
|
||||
|
||||
// mozilla extensions
|
||||
partial interface URL {
|
||||
[Throws, ChromeOnly]
|
||||
static Principal getPrincipalFromURL(DOMString blobURL);
|
||||
};
|
||||
|
@ -893,6 +893,16 @@ 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)
|
||||
{
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
|
||||
class nsIPrincipal;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
struct objectURLOptions;
|
||||
@ -67,6 +69,10 @@ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user