Bug 921718 - Part b: Move MediaList to WebIDL; r=bz

This commit is contained in:
Ms2ger 2013-11-11 09:03:17 +01:00
parent a6c6f35166
commit 13e017e4f4
13 changed files with 93 additions and 107 deletions

View File

@ -18,4 +18,4 @@
# Modifying this file will now automatically clobber the buildbot machines \o/
#
Bug 906990 needs a clobber because of bug 928195
Bug 921718 presumably needed a clobber due to bug 928195.

View File

@ -70,7 +70,6 @@
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMJSWindow.h"
#include "nsIDOMMediaList.h"
#include "nsIDOMChromeWindow.h"
#include "nsIDOMConstructor.h"
@ -350,8 +349,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CSSRuleList, nsCSSRuleListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MediaList, nsMediaListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(StyleSheetList, nsStyleSheetListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CSSStyleSheet, nsDOMGenericSH,
@ -1046,10 +1043,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRuleList)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MediaList, nsIDOMMediaList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMediaList)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(StyleSheetList, nsIDOMStyleSheetList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStyleSheetList)
DOM_CLASSINFO_MAP_END
@ -4284,30 +4277,6 @@ nsStringArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
// MediaList helper
nsresult
nsMediaListSH::GetStringAt(nsISupports *aNative, int32_t aIndex,
nsAString& aResult)
{
if (aIndex < 0) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
nsCOMPtr<nsIDOMMediaList> media_list(do_QueryInterface(aNative));
nsresult rv = media_list->Item(uint32_t(aIndex), aResult);
#ifdef DEBUG
if (DOMStringIsNull(aResult)) {
uint32_t length = 0;
media_list->GetLength(&length);
NS_ASSERTION(uint32_t(aIndex) >= length, "Item should only return null for out-of-bounds access");
}
#endif
return rv;
}
// StyleSheetList helper
nsISupports*

View File

@ -446,30 +446,6 @@ public:
};
// MediaList helper
class nsMediaListSH : public nsStringArraySH
{
protected:
nsMediaListSH(nsDOMClassInfoData* aData) : nsStringArraySH(aData)
{
}
virtual ~nsMediaListSH()
{
}
virtual nsresult GetStringAt(nsISupports *aNative, int32_t aIndex,
nsAString& aResult) MOZ_OVERRIDE;
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsMediaListSH(aData);
}
};
// StyleSheetList helper
class nsStyleSheetListSH : public nsArraySH

View File

@ -19,7 +19,6 @@ DOMCI_CLASS(CSSImportRule)
DOMCI_CLASS(CSSMediaRule)
DOMCI_CLASS(CSSNameSpaceRule)
DOMCI_CLASS(CSSRuleList)
DOMCI_CLASS(MediaList)
DOMCI_CLASS(StyleSheetList)
DOMCI_CLASS(CSSStyleSheet)

View File

@ -696,6 +696,11 @@ DOMInterfaces = {
'register': False
},
'MediaList': {
'nativeType': 'nsMediaList',
'headerFile': 'nsIMediaList.h',
},
'MediaSource': [{
'resultNotAddRefed': [ 'sourceBuffers', 'activeSourceBuffers' ],
},
@ -1838,7 +1843,6 @@ addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
addExternalIface('LockedFile')
addExternalIface('MediaList')
addExternalIface('MediaQueryList')
addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True)
addExternalIface('MozBoxObject', nativeType='nsIBoxObject')

View File

@ -67,12 +67,7 @@ function testDOMStringList() {
function testMediaList() {
var s = document.createElement("style");
document.head.appendChild(s);
try {
is(s.sheet.media[-1], undefined, "Wrong value for out of bounds access (MediaList)");
todo(true, "Didn't throw");
} catch (e) {
todo(false, "Shouldn't throw");
}
is(s.sheet.media[-1], undefined, "Wrong value for out of bounds access (MediaList)");
is(s.sheet.media[0], undefined, "Wrong value for out of bounds access (MediaList)");
is(s.sheet.media[1], undefined, "Wrong value for out of bounds access (MediaList)");
is(s.sheet.media[2], undefined, "Wrong value for out of bounds access (MediaList) (MediaList)");
@ -83,12 +78,7 @@ function testMediaList() {
s.setAttribute("media", "a, b");
try {
is(s.sheet.media[-1], undefined, "Wrong value for out of bounds access (MediaList)");
todo(true, "Didn't throw");
} catch (e) {
todo(false, "Shouldn't throw");
}
is(s.sheet.media[-1], undefined, "Wrong value for out of bounds access (MediaList)");
is(s.sheet.media[0], "a", "Wrong value for in bounds access (MediaList)");
is(s.sheet.media[1], "b", "Wrong value for in bounds access (MediaList)");
is(s.sheet.media[2], undefined, "Wrong value for out of bounds access (MediaList) (MediaList)");

View File

@ -0,0 +1,19 @@
/* -*- 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/. */
// http://dev.w3.org/csswg/cssom/#the-medialist-interface
[ArrayClass]
interface MediaList {
[TreatNullAs=EmptyString]
attribute DOMString mediaText;
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);
[Throws]
void deleteMedium(DOMString oldMedium);
[Throws]
void appendMedium(DOMString newMedium);
};

View File

@ -8,7 +8,6 @@
*/
interface CSSRule;
interface MediaList;
interface StyleSheet {
[Constant]

View File

@ -210,6 +210,7 @@ WEBIDL_FILES = [
'Location.webidl',
'MediaElementAudioSourceNode.webidl',
'MediaError.webidl',
'MediaList.webidl',
'MediaRecorder.webidl',
'MediaSource.webidl',
'MediaStream.webidl',

View File

@ -413,10 +413,7 @@ ImportRule::SetSheet(nsCSSStyleSheet* aSheet)
aSheet->SetOwnerRule(this);
// set our medialist to be the same as the sheet's medialist
nsCOMPtr<nsIDOMMediaList> mediaList;
mChildSheet->GetMedia(getter_AddRefs(mediaList));
NS_ABORT_IF_FALSE(mediaList, "GetMedia returned null");
mMedia = static_cast<nsMediaList*>(mediaList.get());
mMedia = mChildSheet->Media();
}
NS_IMETHODIMP

View File

@ -12,6 +12,7 @@
#include "nsCSSRuleProcessor.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/MediaListBinding.h"
#include "mozilla/css/NameSpaceRule.h"
#include "mozilla/css/GroupRule.h"
#include "mozilla/css/ImportRule.h"
@ -479,35 +480,40 @@ nsMediaQuery::Matches(nsPresContext* aPresContext,
return match == !mNegated;
}
DOMCI_DATA(MediaList, nsMediaList)
NS_INTERFACE_MAP_BEGIN(nsMediaList)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsMediaList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaList)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsMediaList)
NS_IMPL_RELEASE(nsMediaList)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsMediaList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsMediaList)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsMediaList)
nsMediaList::nsMediaList()
: mStyleSheet(nullptr)
{
SetIsDOMBinding();
}
nsMediaList::~nsMediaList()
{
}
nsresult
/* virtual */ JSObject*
nsMediaList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return MediaListBinding::Wrap(aCx, aScope, this);
}
void
nsMediaList::GetText(nsAString& aMediaText)
{
aMediaText.Truncate();
for (int32_t i = 0, i_end = mArray.Length(); i < i_end; ++i) {
nsMediaQuery* query = mArray[i];
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
query->AppendToString(aMediaText);
@ -515,13 +521,11 @@ nsMediaList::GetText(nsAString& aMediaText)
aMediaText.AppendLiteral(", ");
}
}
return NS_OK;
}
// XXXbz this is so ill-defined in the spec, it's not clear quite what
// it should be doing....
nsresult
void
nsMediaList::SetText(const nsAString& aMediaText)
{
nsCSSParser parser;
@ -529,7 +533,6 @@ nsMediaList::SetText(const nsAString& aMediaText)
bool htmlMode = mStyleSheet && mStyleSheet->GetOwnerNode();
parser.ParseMediaList(aMediaText, nullptr, 0, this, htmlMode);
return NS_OK;
}
bool
@ -568,7 +571,8 @@ nsMediaList::Clone()
NS_IMETHODIMP
nsMediaList::GetMediaText(nsAString& aMediaText)
{
return GetText(aMediaText);
GetText(aMediaText);
return NS_OK;
}
// "sheet" should be an nsCSSStyleSheet and "doc" should be an
@ -595,18 +599,15 @@ nsMediaList::GetMediaText(nsAString& aMediaText)
NS_IMETHODIMP
nsMediaList::SetMediaText(const nsAString& aMediaText)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIDocument> doc;
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
rv = SetText(aMediaText);
if (NS_FAILED(rv))
return rv;
SetText(aMediaText);
END_MEDIA_CHANGE(mStyleSheet, doc)
return rv;
return NS_OK;
}
NS_IMETHODIMP
@ -621,17 +622,22 @@ nsMediaList::GetLength(uint32_t* aLength)
NS_IMETHODIMP
nsMediaList::Item(uint32_t aIndex, nsAString& aReturn)
{
if (aIndex < Length()) {
nsMediaQuery* query = mArray[aIndex];
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
bool dummy;
IndexedGetter(aIndex, dummy, aReturn);
return NS_OK;
}
void
nsMediaList::IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aReturn)
{
if (aIndex < Length()) {
aFound = true;
aReturn.Truncate();
query->AppendToString(aReturn);
mArray[aIndex]->AppendToString(aReturn);
} else {
aFound = false;
SetDOMStringToNull(aReturn);
}
return NS_OK;
}
NS_IMETHODIMP
@ -676,7 +682,6 @@ nsMediaList::Delete(const nsAString& aOldMedium)
for (int32_t i = 0, i_end = mArray.Length(); i < i_end; ++i) {
nsMediaQuery* query = mArray[i];
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
nsAutoString buf;
query->AppendToString(buf);
@ -1755,7 +1760,7 @@ nsCSSStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
return NS_OK;
}
nsIDOMMediaList*
nsMediaList*
nsCSSStyleSheet::Media()
{
if (!mMedia) {

View File

@ -266,7 +266,7 @@ public:
void GetTitle(nsString& aTitle) {
const_cast<const nsCSSStyleSheet*>(this)->GetTitle(aTitle);
}
nsIDOMMediaList* Media();
nsMediaList* Media();
bool Disabled() const { return mDisabled; }
// The XPCOM SetDisabled is fine for WebIDL

View File

@ -16,7 +16,9 @@
#include "nsTArray.h"
#include "nsIAtom.h"
#include "nsCSSValue.h"
#include "nsWrapperCache.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
class nsPresContext;
class nsCSSStyleSheet;
@ -143,16 +145,28 @@ private:
nsTArray<nsMediaExpression> mExpressions;
};
class nsMediaList MOZ_FINAL : public nsIDOMMediaList {
class nsMediaList MOZ_FINAL : public nsIDOMMediaList
, public nsWrapperCache
{
public:
typedef mozilla::ErrorResult ErrorResult;
nsMediaList();
NS_DECL_ISUPPORTS
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
nsISupports* GetParentObject() const
{
return nullptr;
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsMediaList)
NS_DECL_NSIDOMMEDIALIST
nsresult GetText(nsAString& aMediaText);
nsresult SetText(const nsAString& aMediaText);
void GetText(nsAString& aMediaText);
void SetText(const nsAString& aMediaText);
// Does this query apply to the presentation?
// If |aKey| is non-null, add cache information to it.
@ -167,10 +181,23 @@ public:
already_AddRefed<nsMediaList> Clone();
uint32_t Length() { return mArray.Length(); }
nsMediaQuery* MediumAt(int32_t aIndex) { return mArray[aIndex]; }
void Clear() { mArray.Clear(); }
// WebIDL
// XPCOM GetMediaText and SetMediaText are fine.
uint32_t Length() { return mArray.Length(); }
void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aReturn);
// XPCOM Item is fine.
void DeleteMedium(const nsAString& aMedium, ErrorResult& aRv)
{
aRv = DeleteMedium(aMedium);
}
void AppendMedium(const nsAString& aMedium, ErrorResult& aRv)
{
aRv = AppendMedium(aMedium);
}
protected:
~nsMediaList();