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*
GetFileDataInfo(const nsACString& aUri)
{

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

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

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

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

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

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

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

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

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

@ -405,6 +405,7 @@ DOMCI_CLASS(File)
DOMCI_CLASS(FileException)
DOMCI_CLASS(FileError)
DOMCI_CLASS(FileReader)
DOMCI_CLASS(MozURLProperty)
// DOM modal content window class, almost identical to Window
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
* on nsGlobalWindow, where any script could see it.
@ -921,6 +1000,10 @@ nsGlobalWindow::~nsGlobalWindow()
delete mPendingStorageEventsObsolete;
if (mURLProperty) {
mURLProperty->ClearWindowReference();
}
nsLayoutStatics::Release();
}
@ -1231,6 +1314,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindow)
NS_INTERFACE_MAP_ENTRY(nsIDOMStorageWindow)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIDOMWindow_2_0_BRANCH)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Window)
OUTER_WINDOW_ONLY
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
@ -3130,32 +3214,13 @@ nsGlobalWindow::GetApplicationCache(nsIDOMOfflineResourceList **aApplicationCach
NS_IMETHODIMP
nsGlobalWindow::CreateBlobURL(nsIDOMBlob* aBlob, nsAString& aURL)
{
FORWARD_TO_INNER(CreateBlobURL, (aBlob, aURL), NS_ERROR_UNEXPECTED);
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;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsGlobalWindow::RevokeBlobURL(const nsAString& aURL)
{
FORWARD_TO_INNER(RevokeBlobURL, (aURL), NS_ERROR_UNEXPECTED);
NS_ENSURE_STATE(mDoc);
NS_LossyConvertUTF16toASCII asciiurl(aURL);
mDoc->UnregisterFileDataUri(asciiurl);
nsFileDataProtocolHandler::RemoveFileDataEntry(asciiurl);
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
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
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow)

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

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

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

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

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

@ -233,3 +233,16 @@ interface nsIDOMWindowInternal : nsIDOMWindow2
*/
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;
};