Bug 609030: Update createBlobURL/revokeBlobURL to it's final name. r=jst a=blocker

This commit is contained in:
Jonas Sicking 2010-11-23 00:50:55 -08:00
Родитель ddc13efc65
Коммит abf5fa5994
10 изменённых файлов: 167 добавлений и 42 удалений

Просмотреть файл

@ -91,6 +91,22 @@ nsFileDataProtocolHandler::RemoveFileDataEntry(nsACString& aUri)
} }
} }
nsIPrincipal*
nsFileDataProtocolHandler::GetFileDataEntryPrincipal(nsACString& aUri)
{
if (!gFileDataTable) {
return nsnull;
}
FileDataInfo* res;
gFileDataTable->Get(aUri, &res);
if (!res) {
return nsnull;
}
return res->mPrincipal;
}
static FileDataInfo* static FileDataInfo*
GetFileDataInfo(const nsACString& aUri) GetFileDataInfo(const nsACString& aUri)
{ {

Просмотреть файл

@ -61,6 +61,7 @@ public:
nsIDOMBlob* aFile, nsIDOMBlob* aFile,
nsIPrincipal* aPrincipal); nsIPrincipal* aPrincipal);
static void RemoveFileDataEntry(nsACString& aUri); static void RemoveFileDataEntry(nsACString& aUri);
static nsIPrincipal* GetFileDataEntryPrincipal(nsACString& aUri);
}; };

Просмотреть файл

@ -197,7 +197,7 @@ function imageLoadHandler(event) {
var imgfile = createFileWithData(testBinaryData + fileData + testBinaryData); var imgfile = createFileWithData(testBinaryData + fileData + testBinaryData);
is(imgfile.size, size + testBinaryData.length * 2, "correct file size"); is(imgfile.size, size + testBinaryData.length * 2, "correct file size");
var img = new Image; var img = new Image;
img.src = createBlobURL(imgfile.slice(testBinaryData.length, size)); img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, size));
img.onload = imageLoadHandler; img.onload = imageLoadHandler;
expectedTestCount++; expectedTestCount++;
@ -205,7 +205,7 @@ expectedTestCount++;
var imgfile = createFileWithData(fileData + testBinaryData); var imgfile = createFileWithData(fileData + testBinaryData);
is(imgfile.size, size + testBinaryData.length, "correct file size"); is(imgfile.size, size + testBinaryData.length, "correct file size");
var img = new Image; var img = new Image;
img.src = createBlobURL(imgfile.slice(0, size)); img.src = URL.createObjectURL(imgfile.slice(0, size));
img.onload = imageLoadHandler; img.onload = imageLoadHandler;
expectedTestCount++; expectedTestCount++;
@ -213,7 +213,7 @@ expectedTestCount++;
var imgfile = createFileWithData(testBinaryData + fileData); var imgfile = createFileWithData(testBinaryData + fileData);
is(imgfile.size, size + testBinaryData.length, "correct file size"); is(imgfile.size, size + testBinaryData.length, "correct file size");
var img = new Image; var img = new Image;
img.src = createBlobURL(imgfile.slice(testBinaryData.length, size)); img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, size));
img.onload = imageLoadHandler; img.onload = imageLoadHandler;
expectedTestCount++; expectedTestCount++;
@ -221,7 +221,7 @@ expectedTestCount++;
var imgfile = createFileWithData(testBinaryData + fileData); var imgfile = createFileWithData(testBinaryData + fileData);
is(imgfile.size, size + testBinaryData.length, "correct file size"); is(imgfile.size, size + testBinaryData.length, "correct file size");
var img = new Image; var img = new Image;
img.src = createBlobURL(imgfile.slice(testBinaryData.length, size + 1000)); img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, size + 1000));
img.onload = imageLoadHandler; img.onload = imageLoadHandler;
expectedTestCount++; expectedTestCount++;
@ -234,9 +234,9 @@ function testFile(file, contents, test) {
r.readAsBinaryString(file); r.readAsBinaryString(file);
expectedTestCount++; expectedTestCount++;
// Load file using createBlobURL and XMLHttpRequest // Load file using URL.createObjectURL and XMLHttpRequest
var xhr = new XMLHttpRequest; var xhr = new XMLHttpRequest;
xhr.open("GET", createBlobURL(file)); xhr.open("GET", URL.createObjectURL(file));
xhr.onload = getXHRLoadHandler(contents, contents.length, false, xhr.onload = getXHRLoadHandler(contents, contents.length, false,
"XMLHttpRequest load of " + test); "XMLHttpRequest load of " + test);
xhr.overrideMimeType('text/plain; charset=x-user-defined'); xhr.overrideMimeType('text/plain; charset=x-user-defined');

Просмотреть файл

@ -22,7 +22,7 @@
<script class="testbody" type="application/javascript;version=1.8"> <script class="testbody" type="application/javascript;version=1.8">
try { try {
createBlobURL(undefined); URL.createObjectURL(undefined);
} catch(e) { } } catch(e) { }
window.addEventListener("message", function(e) { window.addEventListener("message", function(e) {
@ -44,7 +44,7 @@ function runTest() {
// Attempt to load a image in this document // Attempt to load a image in this document
var file = getFile("file_mozfiledataurl_img.jpg"); var file = getFile("file_mozfiledataurl_img.jpg");
var fileurl = createBlobURL(file); var fileurl = URL.createObjectURL(file);
img.src = fileurl; img.src = fileurl;
var e = (yield); var e = (yield);
is(e.type, "load", "loaded successfully"); is(e.type, "load", "loaded successfully");
@ -54,7 +54,7 @@ function runTest() {
// Revoke url and attempt to load a image in this document // Revoke url and attempt to load a image in this document
img.src = "file_mozfiledataurl_img.jpg"; img.src = "file_mozfiledataurl_img.jpg";
is((yield).type, "load", "successfull reset image"); is((yield).type, "load", "successfull reset image");
revokeBlobURL(fileurl); URL.revokeObjectURL(fileurl);
todo(false, "urls need to act like 404s, not fail to parse"); todo(false, "urls need to act like 404s, not fail to parse");
/* img.src = fileurl; /* img.src = fileurl;
var e = (yield); var e = (yield);
@ -64,8 +64,8 @@ function runTest() {
*/ */
// Generate new fileurl and make sure it's different from the old // Generate new fileurl and make sure it's different from the old
var oldFileurl = fileurl; var oldFileurl = fileurl;
var fileurl = createBlobURL(file); var fileurl = URL.createObjectURL(file);
isnot(fileurl, oldFileurl, "createBlobURL generated the same url twice"); isnot(fileurl, oldFileurl, "URL.createObjectURL generated the same url twice");
// Attempt to load an image in a different same-origin document // Attempt to load an image in a different same-origin document
inner.src = innerSameSiteURI; inner.src = innerSameSiteURI;
@ -87,7 +87,7 @@ function runTest() {
// Attempt to load an audio in this document // Attempt to load an audio in this document
var file = getFile("file_mozfiledataurl_audio.ogg"); var file = getFile("file_mozfiledataurl_audio.ogg");
var fileurl = createBlobURL(file); var fileurl = URL.createObjectURL(file);
audio.src = fileurl; audio.src = fileurl;
var e = (yield); var e = (yield);
is(e.type, "canplay", "loaded successfully"); is(e.type, "canplay", "loaded successfully");
@ -95,7 +95,7 @@ function runTest() {
// Revoke url and attempt to load a audio in this document // Revoke url and attempt to load a audio in this document
audio.src = "file_mozfiledataurl_audio.ogg"; audio.src = "file_mozfiledataurl_audio.ogg";
is((yield).type, "canplay", "successfully reset audio"); is((yield).type, "canplay", "successfully reset audio");
revokeBlobURL(fileurl); URL.revokeObjectURL(fileurl);
todo(false, "urls need to act like 404s, not fail to parse"); todo(false, "urls need to act like 404s, not fail to parse");
/* img.src = fileurl; /* img.src = fileurl;
var e = (yield); var e = (yield);
@ -105,8 +105,8 @@ function runTest() {
*/ */
// Generate new fileurl and make sure it's different from the old // Generate new fileurl and make sure it's different from the old
var oldFileurl = fileurl; var oldFileurl = fileurl;
var fileurl = createBlobURL(file); var fileurl = URL.createObjectURL(file);
isnot(fileurl, oldFileurl, "createBlobURL generated the same url twice"); isnot(fileurl, oldFileurl, "URL.createObjectURL generated the same url twice");
// Attempt to load an audio in a different same-origin document // Attempt to load an audio in a different same-origin document
inner.src = innerSameSiteURI; inner.src = innerSameSiteURI;
@ -136,7 +136,7 @@ function runTest() {
// Attempt to load a HTML document in an iframe in this document, using file url // Attempt to load a HTML document in an iframe in this document, using file url
file = getFile("file_mozfiledataurl_doc.html"); file = getFile("file_mozfiledataurl_doc.html");
fileurl = createBlobURL(file); fileurl = URL.createObjectURL(file);
iframe.src = fileurl; iframe.src = fileurl;
yield; yield;
is(iframe.contentDocument.getElementsByTagName("p")[0].textContent, is(iframe.contentDocument.getElementsByTagName("p")[0].textContent,
@ -172,7 +172,7 @@ function runTest() {
// Attempt to load file url using XHR // Attempt to load file url using XHR
file = getFile("file_mozfiledataurl_text.txt"); file = getFile("file_mozfiledataurl_text.txt");
fileurl = createBlobURL(file); fileurl = URL.createObjectURL(file);
xhr = new XMLHttpRequest; xhr = new XMLHttpRequest;
xhr.onload = function() { gen.send("XHR finished"); }; xhr.onload = function() { gen.send("XHR finished"); };
xhr.open("GET", fileurl); xhr.open("GET", fileurl);

Просмотреть файл

@ -1322,6 +1322,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS) DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(FileReader, nsEventTargetSH, NS_DEFINE_CLASSINFO_DATA(FileReader, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS) EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozURLProperty, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(ModalContentWindow, nsWindowSH, NS_DEFINE_CLASSINFO_DATA(ModalContentWindow, nsWindowSH,
DEFAULT_SCRIPTABLE_FLAGS | DEFAULT_SCRIPTABLE_FLAGS |
@ -2246,6 +2248,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS) DOM_CLASSINFO_MAP_ENTRY(nsIDOMViewCSS)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView) DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow) DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow_2_0_BRANCH)
DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WindowUtils, nsIDOMWindowUtils) DOM_CLASSINFO_MAP_BEGIN(WindowUtils, nsIDOMWindowUtils)
@ -3819,6 +3822,10 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIInterfaceRequestor) DOM_CLASSINFO_MAP_ENTRY(nsIInterfaceRequestor)
DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozURLProperty, nsIDOMMozURLProperty)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozURLProperty)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ModalContentWindow, nsIDOMWindow) DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ModalContentWindow, nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow) DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow) DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)

Просмотреть файл

@ -405,6 +405,7 @@ DOMCI_CLASS(File)
DOMCI_CLASS(FileException) DOMCI_CLASS(FileException)
DOMCI_CLASS(FileError) DOMCI_CLASS(FileError)
DOMCI_CLASS(FileReader) DOMCI_CLASS(FileReader)
DOMCI_CLASS(MozURLProperty)
// DOM modal content window class, almost identical to Window // DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow) DOMCI_CLASS(ModalContentWindow)

Просмотреть файл

@ -590,6 +590,85 @@ nsDummyJavaPluginOwner::SendIdleEvent()
{ {
} }
/**
* An object implementing the window.URL property.
*/
class nsDOMMozURLProperty : public nsIDOMMozURLProperty
{
public:
nsDOMMozURLProperty(nsGlobalWindow* aWindow)
: mWindow(aWindow)
{
}
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMOZURLPROPERTY
void ClearWindowReference() {
mWindow = nsnull;
}
private:
nsGlobalWindow* mWindow;
};
DOMCI_DATA(MozURLProperty, nsDOMMozURLProperty)
NS_IMPL_ADDREF(nsDOMMozURLProperty)
NS_IMPL_RELEASE(nsDOMMozURLProperty)
NS_INTERFACE_MAP_BEGIN(nsDOMMozURLProperty)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozURLProperty)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMozURLProperty)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozURLProperty)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsDOMMozURLProperty::CreateObjectURL(nsIDOMBlob* aBlob, nsAString& aURL)
{
NS_PRECONDITION(!mWindow || mWindow->IsInnerWindow(),
"Should be inner window");
NS_ENSURE_STATE(mWindow && mWindow->mDoc);
NS_ENSURE_ARG_POINTER(aBlob);
nsIDocument* doc = mWindow->mDoc;
nsresult rv = aBlob->GetInternalUrl(doc->NodePrincipal(), aURL);
NS_ENSURE_SUCCESS(rv, rv);
doc->RegisterFileDataUri(NS_LossyConvertUTF16toASCII(aURL));
return NS_OK;
}
NS_IMETHODIMP
nsDOMMozURLProperty::RevokeObjectURL(const nsAString& aURL)
{
NS_PRECONDITION(!mWindow || mWindow->IsInnerWindow(),
"Should be inner window");
NS_ENSURE_STATE(mWindow);
NS_LossyConvertUTF16toASCII asciiurl(aURL);
nsIPrincipal* winPrincipal = mWindow->GetPrincipal();
if (!winPrincipal) {
return NS_OK;
}
nsIPrincipal* principal =
nsFileDataProtocolHandler::GetFileDataEntryPrincipal(asciiurl);
PRBool subsumes;
if (principal && winPrincipal &&
NS_SUCCEEDED(winPrincipal->Subsumes(principal, &subsumes)) &&
subsumes) {
if (mWindow->mDoc) {
mWindow->mDoc->UnregisterFileDataUri(asciiurl);
}
nsFileDataProtocolHandler::RemoveFileDataEntry(asciiurl);
}
return NS_OK;
}
/** /**
* An indirect observer object that means we don't have to implement nsIObserver * An indirect observer object that means we don't have to implement nsIObserver
* on nsGlobalWindow, where any script could see it. * on nsGlobalWindow, where any script could see it.
@ -921,6 +1000,10 @@ nsGlobalWindow::~nsGlobalWindow()
delete mPendingStorageEventsObsolete; delete mPendingStorageEventsObsolete;
if (mURLProperty) {
mURLProperty->ClearWindowReference();
}
nsLayoutStatics::Release(); nsLayoutStatics::Release();
} }
@ -1231,6 +1314,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindow)
NS_INTERFACE_MAP_ENTRY(nsIDOMStorageWindow) NS_INTERFACE_MAP_ENTRY(nsIDOMStorageWindow)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIDOMWindow_2_0_BRANCH)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Window) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Window)
OUTER_WINDOW_ONLY OUTER_WINDOW_ONLY
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
@ -3130,32 +3214,13 @@ nsGlobalWindow::GetApplicationCache(nsIDOMOfflineResourceList **aApplicationCach
NS_IMETHODIMP NS_IMETHODIMP
nsGlobalWindow::CreateBlobURL(nsIDOMBlob* aBlob, nsAString& aURL) nsGlobalWindow::CreateBlobURL(nsIDOMBlob* aBlob, nsAString& aURL)
{ {
FORWARD_TO_INNER(CreateBlobURL, (aBlob, aURL), NS_ERROR_UNEXPECTED); return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_STATE(mDoc);
NS_ENSURE_ARG_POINTER(aBlob);
nsresult rv = aBlob->GetInternalUrl(mDoc->NodePrincipal(), aURL);
NS_ENSURE_SUCCESS(rv, rv);
mDoc->RegisterFileDataUri(NS_LossyConvertUTF16toASCII(aURL));
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsGlobalWindow::RevokeBlobURL(const nsAString& aURL) nsGlobalWindow::RevokeBlobURL(const nsAString& aURL)
{ {
FORWARD_TO_INNER(RevokeBlobURL, (aURL), NS_ERROR_UNEXPECTED); return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_STATE(mDoc);
NS_LossyConvertUTF16toASCII asciiurl(aURL);
mDoc->UnregisterFileDataUri(asciiurl);
nsFileDataProtocolHandler::RemoveFileDataEntry(asciiurl);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -9716,6 +9781,20 @@ nsGlobalWindow::SetHasOrientationEventListener()
} }
} }
NS_IMETHODIMP
nsGlobalWindow::GetURL(nsIDOMMozURLProperty** aURL)
{
FORWARD_TO_INNER(GetURL, (aURL), NS_ERROR_UNEXPECTED);
if (!mURLProperty) {
mURLProperty = new nsDOMMozURLProperty(this);
}
NS_ADDREF(*aURL = mURLProperty);
return NS_OK;
}
// nsGlobalChromeWindow implementation // nsGlobalChromeWindow implementation
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow) NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow)

Просмотреть файл

@ -148,6 +148,7 @@ class nsRunnable;
class nsDOMOfflineResourceList; class nsDOMOfflineResourceList;
class nsGeolocation; class nsGeolocation;
class nsDesktopNotificationCenter; class nsDesktopNotificationCenter;
class nsDOMMozURLProperty;
#ifdef MOZ_DISABLE_DOMCRYPTO #ifdef MOZ_DISABLE_DOMCRYPTO
class nsIDOMCrypto; class nsIDOMCrypto;
@ -281,10 +282,13 @@ class nsGlobalWindow : public nsPIDOMWindow,
public nsIDOMStorageWindow, public nsIDOMStorageWindow,
public nsSupportsWeakReference, public nsSupportsWeakReference,
public nsIInterfaceRequestor, public nsIInterfaceRequestor,
public nsIDOMWindow_2_0_BRANCH,
public nsWrapperCache, public nsWrapperCache,
public PRCListStr public PRCListStr
{ {
public: public:
friend class nsDOMMozURLProperty;
typedef mozilla::TimeStamp TimeStamp; typedef mozilla::TimeStamp TimeStamp;
typedef mozilla::TimeDuration TimeDuration; typedef mozilla::TimeDuration TimeDuration;
@ -340,6 +344,9 @@ public:
// nsIDOMNSEventTarget // nsIDOMNSEventTarget
NS_DECL_NSIDOMNSEVENTTARGET NS_DECL_NSIDOMNSEVENTTARGET
// nsIDOMWindow_2_0_BRANCH
NS_DECL_NSIDOMWINDOW_2_0_BRANCH
// nsPIDOMWindow // nsPIDOMWindow
virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot(); virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot();
@ -947,6 +954,8 @@ protected:
TimeStamp mLastDialogQuitTime; TimeStamp mLastDialogQuitTime;
PRPackedBool mDialogDisabled; PRPackedBool mDialogDisabled;
nsRefPtr<nsDOMMozURLProperty> mURLProperty;
friend class nsDOMScriptableHelper; friend class nsDOMScriptableHelper;
friend class nsDOMWindowUtils; friend class nsDOMWindowUtils;
friend class PostMessageEvent; friend class PostMessageEvent;

Просмотреть файл

@ -56,9 +56,8 @@ interface nsIDOMWindow2 : nsIDOMWindow
readonly attribute nsIDOMOfflineResourceList applicationCache; readonly attribute nsIDOMOfflineResourceList applicationCache;
/** /**
* Create and revoke blob urls. createBlobURL will always return a new URL * Deprecated, but can't remove yet since we don't want to change interfaces.
* with the lifetime of the current Document.
*/ */
DOMString createBlobURL(in nsIDOMBlob blob); [noscript] DOMString createBlobURL(in nsIDOMBlob blob);
void revokeBlobURL(in DOMString URL); [noscript] void revokeBlobURL(in DOMString URL);
}; };

Просмотреть файл

@ -233,3 +233,16 @@ interface nsIDOMWindowInternal : nsIDOMWindow2
*/ */
readonly attribute long long mozAnimationStartTime; readonly attribute long long mozAnimationStartTime;
}; };
[scriptable, uuid(8fc58f56-f769-4368-a098-edd08550cf1a)]
interface nsIDOMMozURLProperty : nsISupports
{
DOMString createObjectURL(in nsIDOMBlob blob);
void revokeObjectURL(in DOMString URL);
};
[scriptable, uuid(05563c0c-b74c-41ad-91d1-bc22d580a581)]
interface nsIDOMWindow_2_0_BRANCH : nsISupports
{
readonly attribute nsIDOMMozURLProperty URL;
};