Bug 792675. Part 1: Make the URL interface use WebIDL. r=bz

--HG--
extra : rebase_source : dbb7a3158b71446930400ad523a2896b6306de40
This commit is contained in:
Robert O'Callahan 2012-09-25 15:24:43 +12:00
parent 9a6a3bf063
commit ab861f5738
14 changed files with 185 additions and 167 deletions

View File

@ -84,6 +84,7 @@ EXPORTS_mozilla/dom = \
DOMRequest.h \
StructuredCloneTags.h \
ScreenOrientation.h \
URL.h \
$(NULL)
CPPSRCS = \
@ -115,6 +116,7 @@ CPPSRCS = \
DOMError.cpp \
DOMRequest.cpp \
Navigator.cpp \
URL.cpp \
$(NULL)
include $(topsrcdir)/dom/dom-config.mk

76
dom/base/URL.cpp Normal file
View File

@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "URL.h"
#include "nsGlobalWindow.h"
#include "nsIDOMFile.h"
#include "nsIDocument.h"
#include "nsIPrincipal.h"
#include "nsContentUtils.h"
#include "nsBlobProtocolHandler.h"
namespace mozilla {
namespace dom {
void
URL::CreateObjectURL(nsISupports* aGlobal, nsIDOMBlob* aBlob,
const objectURLOptions& aOptions,
nsAString& aResult,
ErrorResult& aError)
{
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal);
nsGlobalWindow* window = static_cast<nsGlobalWindow*>(w.get());
NS_PRECONDITION(!window || window->IsInnerWindow(),
"Should be inner window");
if (!window || !window->GetExtantDoc()) {
aError.Throw(NS_ERROR_INVALID_POINTER);
return;
}
nsIDocument* doc = window->GetExtantDoc();
nsresult rv = aBlob->GetInternalUrl(doc->NodePrincipal(), aResult);
if (NS_FAILED(rv)) {
aError.Throw(rv);
return;
}
doc->RegisterFileDataUri(NS_LossyConvertUTF16toASCII(aResult));
}
void
URL::RevokeObjectURL(nsISupports* aGlobal, const nsAString& aURL)
{
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal);
nsGlobalWindow* window = static_cast<nsGlobalWindow*>(w.get());
NS_PRECONDITION(!window || window->IsInnerWindow(),
"Should be inner window");
if (!window)
return;
NS_LossyConvertUTF16toASCII asciiurl(aURL);
nsIPrincipal* winPrincipal = window->GetPrincipal();
if (!winPrincipal) {
return;
}
nsIPrincipal* principal =
nsBlobProtocolHandler::GetFileDataEntryPrincipal(asciiurl);
bool subsumes;
if (principal && winPrincipal &&
NS_SUCCEEDED(winPrincipal->Subsumes(principal, &subsumes)) &&
subsumes) {
if (window->GetExtantDoc()) {
window->GetExtantDoc()->UnregisterFileDataUri(asciiurl);
}
nsBlobProtocolHandler::RemoveFileDataEntry(asciiurl);
}
}
}
}

30
dom/base/URL.h Normal file
View File

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef URL_h___
#define URL_h___
#include "nscore.h"
#include "mozilla/dom/URLBinding.h"
class nsIDOMBlob;
namespace mozilla {
namespace dom {
class URL MOZ_FINAL
{
public:
// WebIDL methods
static void CreateObjectURL(nsISupports* aGlobal, nsIDOMBlob* aBlob,
const objectURLOptions& aOptions,
nsAString& aResult,
ErrorResult& aError);
static void RevokeObjectURL(nsISupports* aGlobal, const nsAString& aURL);
};
}
}
#endif /* URL_h___ */

View File

@ -1434,8 +1434,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(ArchiveRequest, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozURLProperty, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(ModalContentWindow, nsWindowSH,
DEFAULT_SCRIPTABLE_FLAGS |
@ -4008,10 +4006,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMRequest)
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_WINDOW_MAP_ENTRIES(nsGlobalWindow::HasIndexedDBSupport())
DOM_CLASSINFO_MAP_ENTRY(nsIDOMModalContentWindow)

View File

@ -366,7 +366,6 @@ DOMCI_CLASS(File)
DOMCI_CLASS(FileReader)
DOMCI_CLASS(ArchiveReader)
DOMCI_CLASS(ArchiveRequest)
DOMCI_CLASS(MozURLProperty)
// DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow)

View File

@ -148,7 +148,6 @@
#include "nsAutoPtr.h"
#include "nsContentUtils.h"
#include "nsCSSProps.h"
#include "nsBlobProtocolHandler.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIURIFixup.h"
@ -422,85 +421,6 @@ static const char sPopStatePrefStr[] = "browser.history.allowPopState";
#define NETWORK_UPLOAD_EVENT_NAME NS_LITERAL_STRING("moznetworkupload")
#define NETWORK_DOWNLOAD_EVENT_NAME NS_LITERAL_STRING("moznetworkdownload")
/**
* An object implementing the window.URL property.
*/
class nsDOMMozURLProperty MOZ_FINAL : public nsIDOMMozURLProperty
{
public:
nsDOMMozURLProperty(nsGlobalWindow* aWindow)
: mWindow(aWindow)
{
}
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMOZURLPROPERTY
void ClearWindowReference() {
mWindow = nullptr;
}
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 =
nsBlobProtocolHandler::GetFileDataEntryPrincipal(asciiurl);
bool subsumes;
if (principal && winPrincipal &&
NS_SUCCEEDED(winPrincipal->Subsumes(principal, &subsumes)) &&
subsumes) {
if (mWindow->mDoc) {
mWindow->mDoc->UnregisterFileDataUri(asciiurl);
}
nsBlobProtocolHandler::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.
@ -928,10 +848,6 @@ nsGlobalWindow::~nsGlobalWindow()
nsCycleCollector_DEBUG_wasFreed(static_cast<nsIScriptGlobalObject*>(this));
#endif
if (mURLProperty) {
mURLProperty->ClearWindowReference();
}
nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
if (ac)
ac->RemoveWindowAsListener(this);
@ -10770,20 +10686,6 @@ nsGlobalWindow::DisableDeviceSensor(uint32_t aType)
}
}
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;
}
void
nsGlobalWindow::EnableTimeChangeNotifications()
{

View File

@ -111,7 +111,6 @@ class PostMessageEvent;
class nsRunnable;
class nsDOMEventTargetHelper;
class nsDOMOfflineResourceList;
class nsDOMMozURLProperty;
class nsDOMWindowUtils;
class nsIIdleService;
@ -124,6 +123,7 @@ class nsWindowSizes;
namespace mozilla {
namespace dom {
class Navigator;
class URL;
} // namespace dom
} // namespace mozilla
@ -282,8 +282,6 @@ class nsGlobalWindow : public nsPIDOMWindow,
#endif // MOZ_B2G
{
public:
friend class nsDOMMozURLProperty;
typedef mozilla::TimeStamp TimeStamp;
typedef mozilla::TimeDuration TimeDuration;
typedef mozilla::dom::Navigator Navigator;
@ -1128,8 +1126,6 @@ protected:
// destroying this window).
bool mDialogsPermanentlyDisabled;
nsRefPtr<nsDOMMozURLProperty> mURLProperty;
nsTHashtable<nsPtrHashKey<nsDOMEventTargetHelper> > mEventTargetObjects;
nsTArray<uint32_t> mEnabledSensors;

View File

@ -48,8 +48,8 @@ class nsIArray;
class nsPIWindowRoot;
#define NS_PIDOMWINDOW_IID \
{ 0x54fd92bd, 0xda33, 0x4451, \
{ 0x8f, 0xb5, 0x11, 0x20, 0x5c, 0x03, 0xce, 0xaa } }
{ 0x7b18e421, 0x2179, 0x4e24, \
{ 0x96, 0x58, 0x26, 0x75, 0xa4, 0x37, 0xf3, 0x8f } }
class nsPIDOMWindow : public nsIDOMWindowInternal
{

View File

@ -365,6 +365,10 @@ DOMInterfaces = {
'implicitJSContext': [ 'encode' ],
},
'URL' : {
'concrete': False,
},
'WebGLActiveInfo': {
'nativeType': 'mozilla::WebGLActiveInfo',
'headerFile': 'WebGLContext.h',

View File

@ -5636,50 +5636,53 @@ class CGDescriptor(CGThing):
assert not descriptor.concrete or descriptor.interface.hasInterfacePrototypeObject()
cgThings = []
if descriptor.interface.hasInterfacePrototypeObject():
# These are set to true if at least one non-static
# method/getter/setter exist on the interface.
(hasMethod, hasGetter, hasLenientGetter,
hasSetter, hasLenientSetter) = False, False, False, False, False
for m in descriptor.interface.members:
if (m.isMethod() and
(not m.isIdentifierLess() or m == descriptor.operations['Stringifier'])):
if m.isStatic():
cgThings.append(CGStaticMethod(descriptor, m))
# These are set to true if at least one non-static
# method/getter/setter exist on the interface.
(hasMethod, hasGetter, hasLenientGetter,
hasSetter, hasLenientSetter) = False, False, False, False, False
for m in descriptor.interface.members:
if (m.isMethod() and
(not m.isIdentifierLess() or m == descriptor.operations['Stringifier'])):
if m.isStatic():
assert descriptor.interface.hasInterfaceObject
cgThings.append(CGStaticMethod(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGSpecializedMethod(descriptor, m))
cgThings.append(CGMemberJITInfo(descriptor, m))
hasMethod = True
elif m.isAttr():
if m.isStatic():
assert descriptor.interface.hasInterfaceObject
cgThings.append(CGStaticGetter(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGSpecializedGetter(descriptor, m))
if m.hasLenientThis():
hasLenientGetter = True
else:
cgThings.append(CGSpecializedMethod(descriptor, m))
cgThings.append(CGMemberJITInfo(descriptor, m))
hasMethod = True
elif m.isAttr():
hasGetter = True
if not m.readonly:
if m.isStatic():
cgThings.append(CGStaticGetter(descriptor, m))
else:
cgThings.append(CGSpecializedGetter(descriptor, m))
assert descriptor.interface.hasInterfaceObject
cgThings.append(CGStaticSetter(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGSpecializedSetter(descriptor, m))
if m.hasLenientThis():
hasLenientGetter = True
hasLenientSetter = True
else:
hasGetter = True
if not m.readonly:
if m.isStatic():
cgThings.append(CGStaticSetter(descriptor, m))
else:
cgThings.append(CGSpecializedSetter(descriptor, m))
if m.hasLenientThis():
hasLenientSetter = True
else:
hasSetter = True
elif m.getExtendedAttribute("PutForwards"):
cgThings.append(CGSpecializedForwardingSetter(descriptor, m))
hasSetter = True
if not m.isStatic():
cgThings.append(CGMemberJITInfo(descriptor, m))
if hasMethod: cgThings.append(CGGenericMethod(descriptor))
if hasGetter: cgThings.append(CGGenericGetter(descriptor))
if hasLenientGetter: cgThings.append(CGGenericGetter(descriptor,
lenientThis=True))
if hasSetter: cgThings.append(CGGenericSetter(descriptor))
if hasLenientSetter: cgThings.append(CGGenericSetter(descriptor,
lenientThis=True))
hasSetter = True
elif m.getExtendedAttribute("PutForwards"):
cgThings.append(CGSpecializedForwardingSetter(descriptor, m))
hasSetter = True
if (not m.isStatic() and
descriptor.interface.hasInterfacePrototypeObject()):
cgThings.append(CGMemberJITInfo(descriptor, m))
if hasMethod: cgThings.append(CGGenericMethod(descriptor))
if hasGetter: cgThings.append(CGGenericGetter(descriptor))
if hasLenientGetter: cgThings.append(CGGenericGetter(descriptor,
lenientThis=True))
if hasSetter: cgThings.append(CGGenericSetter(descriptor))
if hasLenientSetter: cgThings.append(CGGenericSetter(descriptor,
lenientThis=True))
if descriptor.concrete:
if descriptor.nativeOwnership == 'owned' or descriptor.nativeOwnership == 'refcounted':

View File

@ -16,13 +16,6 @@ interface nsIPrompt;
interface nsISelection;
interface nsIVariant;
[scriptable, uuid(8fc58f56-f769-4368-a098-edd08550cf1a)]
interface nsIDOMMozURLProperty : nsISupports
{
DOMString createObjectURL(in nsIDOMBlob blob);
void revokeObjectURL(in DOMString URL);
};
/**
* The nsIDOMWindow interface is the primary interface for a DOM
* window object. It represents a single window object that may
@ -32,7 +25,7 @@ interface nsIDOMMozURLProperty : nsISupports
* @see <http://www.whatwg.org/html/#window>
*/
[scriptable, uuid(1534ecd7-e298-420e-9063-e6c2d1243d49)]
[scriptable, uuid(b9c71e0b-7f81-419a-8253-91f4c8893c4f)]
interface nsIDOMWindow : nsISupports
{
// the current browsing context
@ -461,11 +454,6 @@ interface nsIDOMWindow : nsISupports
*/
readonly attribute long long mozAnimationStartTime;
/**
* @see <http://dev.w3.org/2006/webapi/FileAPI/#creating-revoking>
*/
readonly attribute nsIDOMMozURLProperty URL;
/**
* HTML5 event attributes that only apply to windows and <body>/<frameset>
*/
@ -525,5 +513,5 @@ interface nsIWindowCrypto : nsISupports
* Empty interface for compatibility with older versions.
* @deprecated Use nsIDOMWindow instead
*/
[scriptable, uuid(8da641ab-906a-456e-97f2-b77df4ca2d95)]
[scriptable, uuid(a5cd0946-bac1-4606-9aaa-9e68dd0a3279)]
interface nsIDOMWindowInternal : nsIDOMWindow {};

View File

@ -342,7 +342,7 @@ var interfaceNamesInGlobalScope =
"HTMLSelectElement",
"MessageEvent",
"SVGFEImageElement",
"MozURLProperty",
"URL",
"DeviceStorage",
"SVGFEOffsetElement",
"DOMImplementation",

23
dom/webidl/URL.webidl Normal file
View File

@ -0,0 +1,23 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origins of this IDL file are
* http://dev.w3.org/2006/webapi/FileAPI/#creating-revoking
* http://dev.w3.org/2011/webrtc/editor/getusermedia.html#url
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface URL {
[Throws]
static DOMString? createObjectURL(Blob blob, optional objectURLOptions options);
static void revokeObjectURL(DOMString url);
};
dictionary objectURLOptions
{
/* boolean autoRevoke = true; */ /* not supported yet */
};

View File

@ -52,6 +52,7 @@ webidl_files = \
SVGTransformList.webidl \
TextDecoder.webidl \
TextEncoder.webidl \
URL.webidl \
WebSocket.webidl \
XMLHttpRequest.webidl \
XMLHttpRequestEventTarget.webidl \