Fix for bug 460512 (Avoid AddRef/Release in scriptable helper methods for NodeList). r/sr=bz.

This commit is contained in:
Peter Van der Beken 2008-10-22 16:31:14 +02:00
Родитель 99472a614a
Коммит a9ba7dc3aa
47 изменённых файлов: 893 добавлений и 1195 удалений

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

@ -88,6 +88,28 @@ public:
PRBool Remove(PRUint32 aIndex) { return mFiles.RemoveObjectAt(aIndex); }
void Clear() { return mFiles.Clear(); }
nsIDOMFile* GetItemAt(PRUint32 aIndex)
{
return mFiles.SafeObjectAt(aIndex);
}
static nsDOMFileList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMFileList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMFileList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == static_cast<nsIDOMFileList*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsDOMFileList*>(aSupports);
}
private:
nsCOMArray<nsIDOMFile> mFiles;
};

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

@ -39,17 +39,18 @@
#define nsINodeList_h___
class nsINode;
class nsIDOMNodeList;
// IID for the nsINodeList interface
#define NS_INODELIST_IID \
{ 0x06a6639a, 0x2d47, 0x4551, \
{ 0x94, 0xef, 0x93, 0xb8, 0xe1, 0x09, 0x3a, 0xb3 } }
{ 0x943420c4, 0x8774, 0x43ea, \
{ 0xb3, 0x53, 0x62, 0xa1, 0x26, 0x1c, 0x9b, 0x55 } }
/**
* An internal interface that allows QI-less getting of nodes from node lists
*/
class nsINodeList : public nsISupports {
class nsINodeList : public nsIDOMNodeList
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODELIST_IID)

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

@ -135,7 +135,6 @@ CPPSRCS = \
nsFrameLoader.cpp \
nsGenConImageContent.cpp \
nsGenericDOMDataNode.cpp \
nsGenericDOMNodeList.cpp \
nsGenericElement.cpp \
nsGkAtoms.cpp \
nsHTMLContentSerializer.cpp \

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

@ -70,10 +70,6 @@ NS_NewPreContentIterator(nsIContentIterator** aInstancePtrResult);
static nsContentList *gCachedContentList;
nsBaseContentList::nsBaseContentList()
{
}
nsBaseContentList::~nsBaseContentList()
{
}
@ -90,7 +86,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsBaseContentList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_END

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

@ -74,11 +74,9 @@ class nsIDocument;
class nsIDOMHTMLFormElement;
class nsBaseContentList : public nsIDOMNodeList,
public nsINodeList
class nsBaseContentList : public nsINodeList
{
public:
nsBaseContentList();
virtual ~nsBaseContentList();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -89,7 +87,7 @@ public:
// nsINodeList
virtual nsINode* GetNodeAt(PRUint32 aIndex);
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsBaseContentList, nsIDOMNodeList)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsBaseContentList, nsINodeList)
void AppendElement(nsIContent *aContent);
void RemoveElement(nsIContent *aContent);
@ -265,6 +263,22 @@ public:
static void OnDocumentDestroy(nsIDocument *aDocument);
static nsContentList* FromSupports(nsISupports* aSupports)
{
nsINodeList* list = static_cast<nsINodeList*>(aSupports);
#ifdef DEBUG
{
nsCOMPtr<nsINodeList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsINodeList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == list, "Uh, fix QI!");
}
#endif
return static_cast<nsContentList*>(list);
}
protected:
/**
* Returns whether the content element matches our criterion

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

@ -46,7 +46,6 @@
#include "nsIDOMAttr.h"
#include "nsIDOMText.h"
#include "nsIDOMNodeList.h"
#include "nsGenericDOMNodeList.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsINodeInfo.h"

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

@ -163,12 +163,10 @@ nsDOMAttributeMap::DropAttribute(PRInt32 aNamespaceID, nsIAtom* aLocalName)
}
nsresult
nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo,
nsIDOMNode** aReturn,
PRBool aRemove)
nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn)
{
NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nsnull!");
NS_ASSERTION(aReturn, "GetAttribute() called with aReturn == nsnull");
NS_ASSERTION(aNodeInfo, "RemoveAttribute() called with aNodeInfo == nsnull!");
NS_ASSERTION(aReturn, "RemoveAttribute() called with aReturn == nsnull");
*aReturn = nsnull;
@ -176,22 +174,16 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo,
if (!mAttributeCache.Get(attr, aReturn)) {
nsAutoString value;
if (aRemove) {
// As we are removing the attribute we need to set the current value in
// the attribute node.
mContent->GetAttr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom(), value);
}
nsCOMPtr<nsIDOMNode> newAttr = new nsDOMAttribute(aRemove ? nsnull : this,
aNodeInfo, value);
// As we are removing the attribute we need to set the current value in
// the attribute node.
mContent->GetAttr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom(), value);
nsCOMPtr<nsIDOMNode> newAttr = new nsDOMAttribute(nsnull, aNodeInfo, value);
if (!newAttr) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!aRemove && !mAttributeCache.Put(attr, newAttr)) {
return NS_ERROR_OUT_OF_MEMORY;
}
newAttr.swap(*aReturn);
}
else if (aRemove) {
else {
nsCOMPtr<nsIAttribute> iAttr(do_QueryInterface(*aReturn));
NS_ASSERTION(iAttr, "non-nsIAttribute somehow made it into the hashmap?!");
@ -205,6 +197,25 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo,
return NS_OK;
}
nsIDOMNode*
nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo)
{
NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nsnull!");
nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());
nsIDOMNode* node = mAttributeCache.GetWeak(attr);
if (!node) {
nsCOMPtr<nsIDOMNode> newAttr =
new nsDOMAttribute(this, aNodeInfo, EmptyString());
if (newAttr && mAttributeCache.Put(attr, newAttr)) {
node = newAttr;
}
}
return node;
}
NS_IMETHODIMP
nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName,
nsIDOMNode** aAttribute)
@ -294,7 +305,7 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode,
ni = iAttribute->NodeInfo();
if (mContent->HasAttr(ni->NamespaceID(), ni->NameAtom())) {
rv = GetAttribute(ni, getter_AddRefs(tmpReturn), PR_TRUE);
rv = RemoveAttribute(ni, getter_AddRefs(tmpReturn));
NS_ENSURE_SUCCESS(rv, rv);
}
}
@ -304,7 +315,7 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode,
// get node-info of old attribute
ni = mContent->GetExistingAttrNameFromQName(name);
if (ni) {
rv = GetAttribute(ni, getter_AddRefs(tmpReturn), PR_TRUE);
rv = RemoveAttribute(ni, getter_AddRefs(tmpReturn));
NS_ENSURE_SUCCESS(rv, rv);
}
else {
@ -374,10 +385,12 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName,
}
NS_IMETHODIMP
nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
nsIDOMNode*
nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aResult = NS_OK;
nsIDOMNode* node = nsnull;
const nsAttrName* name;
if (mContent && (name = mContent->GetAttrNameAt(aIndex))) {
@ -386,14 +399,23 @@ nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
nsCOMPtr<nsINodeInfo> ni;
ni = mContent->NodeInfo()->NodeInfoManager()->
GetNodeInfo(name->LocalName(), name->GetPrefix(), name->NamespaceID());
NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
return GetAttribute(ni, aReturn);
if (ni) {
node = GetAttribute(ni);
}
if (!node) {
*aResult = NS_ERROR_OUT_OF_MEMORY;
}
}
*aReturn = nsnull;
return node;
}
return NS_OK;
NS_IMETHODIMP
nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsresult rv;
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
return rv;
}
nsresult
@ -457,7 +479,7 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI,
GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID);
NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
return GetAttribute(ni, aReturn, aRemove);
return aRemove ? RemoveAttribute(ni, aReturn) : GetAttribute(ni, aReturn);
}
}

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

@ -48,6 +48,7 @@
#include "nsInterfaceHashtable.h"
#include "nsCycleCollectionParticipant.h"
#include "prbit.h"
#include "nsIDOMNode.h"
class nsIAtom;
class nsIContent;
@ -169,6 +170,25 @@ public:
*/
PRUint32 Enumerate(AttrCache::EnumReadFunction aFunc, void *aUserArg) const;
nsIDOMNode* GetItemAt(PRUint32 aIndex, nsresult *rv);
static nsDOMAttributeMap* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMNamedNodeMap> map_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMNamedNodeMap pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(map_qi == static_cast<nsIDOMNamedNodeMap*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsDOMAttributeMap*>(aSupports);
}
NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMAttributeMap)
private:
@ -201,8 +221,25 @@ private:
* creating a new one.
*/
nsresult GetAttribute(nsINodeInfo* aNodeInfo,
nsIDOMNode** aReturn,
PRBool aRemove = PR_FALSE);
nsIDOMNode** aReturn)
{
*aReturn = GetAttribute(aNodeInfo);
if (!*aReturn) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aReturn);
return NS_OK;
}
nsIDOMNode* GetAttribute(nsINodeInfo* aNodeInfo);
/**
* Remove an attribute, returns the removed node.
*/
nsresult RemoveAttribute(nsINodeInfo* aNodeInfo,
nsIDOMNode** aReturn);
};

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

@ -386,7 +386,7 @@ nsDOMFileList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsDOMFileList::Item(PRUint32 aIndex, nsIDOMFile **aFile)
{
NS_IF_ADDREF(*aFile = mFiles.SafeObjectAt(aIndex));
NS_IF_ADDREF(*aFile = GetItemAt(aIndex));
return NS_OK;
}

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

@ -616,20 +616,30 @@ nsDOMStyleSheetList::GetLength(PRUint32* aLength)
return NS_OK;
}
nsIStyleSheet*
nsDOMStyleSheetList::GetItemAt(PRUint32 aIndex)
{
if (!mDocument || aIndex >= (PRUint32)mDocument->GetNumberOfStyleSheets()) {
return nsnull;
}
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(aIndex);
NS_ASSERTION(sheet, "Must have a sheet");
return sheet;
}
NS_IMETHODIMP
nsDOMStyleSheetList::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
{
*aReturn = nsnull;
if (mDocument) {
PRInt32 count = mDocument->GetNumberOfStyleSheets();
if (aIndex < (PRUint32)count) {
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(aIndex);
NS_ASSERTION(sheet, "Must have a sheet");
return CallQueryInterface(sheet, aReturn);
}
nsIStyleSheet *sheet = GetItemAt(aIndex);
if (!sheet) {
*aReturn = nsnull;
return NS_OK;
}
return NS_OK;
return CallQueryInterface(sheet, aReturn);
}
void

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

@ -368,6 +368,24 @@ public:
nsIStyleSheet* aStyleSheet,
PRBool aDocumentSheet);
nsIStyleSheet* GetItemAt(PRUint32 aIndex);
static nsDOMStyleSheetList* FromSupports(nsISupports* aSupports)
{
nsIDOMStyleSheetList* list = static_cast<nsIDOMStyleSheetList*>(aSupports);
#ifdef DEBUG
{
nsCOMPtr<nsIDOMStyleSheetList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMStyleSheetList pointer as the
// nsISupports pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == list, "Uh, fix QI!");
}
#endif
return static_cast<nsDOMStyleSheetList*>(list);
}
protected:
PRInt32 mLength;
nsIDocument* mDocument;

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

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* A base class for simple DOM NodeLists which implements nsISupports
* and expects subclasess to implement GetLength() and Item()
*/
#include "nsGenericDOMNodeList.h"
#include "nsGenericElement.h"
nsGenericDOMNodeList::nsGenericDOMNodeList()
{
}
nsGenericDOMNodeList::~nsGenericDOMNodeList()
{
}
NS_IMPL_ADDREF(nsGenericDOMNodeList)
NS_IMPL_RELEASE(nsGenericDOMNodeList)
// QueryInterface implementation for nsGenericDOMNodeList
NS_INTERFACE_MAP_BEGIN(nsGenericDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsGenericDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsINode* node = GetNodeAt(aIndex);
if (!node) {
*aReturn = nsnull;
return NS_OK;
}
return CallQueryInterface(node, aReturn);
}

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

@ -456,10 +456,15 @@ nsIContent::FindFirstNonNativeAnonymous() const
//----------------------------------------------------------------------
nsChildContentList::~nsChildContentList()
{
MOZ_COUNT_DTOR(nsChildContentList);
}
NS_IMPL_ADDREF(nsChildContentList)
NS_IMPL_RELEASE(nsChildContentList)
NS_INTERFACE_MAP_BEGIN(nsChildContentList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsChildContentList::GetLength(PRUint32* aLength)
@ -469,6 +474,19 @@ nsChildContentList::GetLength(PRUint32* aLength)
return NS_OK;
}
NS_IMETHODIMP
nsChildContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsINode* node = GetNodeAt(aIndex);
if (!node) {
*aReturn = nsnull;
return NS_OK;
}
return CallQueryInterface(node, aReturn);
}
nsINode*
nsChildContentList::GetNodeAt(PRUint32 aIndex)
{

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

@ -55,7 +55,6 @@
#include "nsIDOMNSEventTarget.h"
#include "nsIDOMNSElement.h"
#include "nsILinkHandler.h"
#include "nsGenericDOMNodeList.h"
#include "nsContentUtils.h"
#include "nsNodeUtils.h"
#include "nsAttrAndChildArray.h"
@ -90,18 +89,18 @@ typedef unsigned long PtrBits;
* and Item to its existing child list.
* @see nsIDOMNodeList
*/
class nsChildContentList : public nsGenericDOMNodeList
class nsChildContentList : public nsINodeList
{
public:
nsChildContentList(nsINode* aNode)
: mNode(aNode)
{
MOZ_COUNT_CTOR(nsChildContentList);
}
virtual ~nsChildContentList();
NS_DECL_ISUPPORTS
// nsIDOMNodeList interface
NS_IMETHOD GetLength(PRUint32* aLength);
NS_DECL_NSIDOMNODELIST
// nsINodeList interface
virtual nsINode* GetNodeAt(PRUint32 aIndex);

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

@ -67,6 +67,7 @@ EXPORTS = \
nsHTMLAudioElement.h \
nsHTMLMediaElement.h \
nsHTMLVideoElement.h \
nsIHTMLCollection.h \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -12,18 +12,18 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
* The Original Code is Mozilla DOM code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@propagandism.org> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
@ -35,38 +35,31 @@
*
* ***** END LICENSE BLOCK ***** */
/*
* A base class for simple DOM NodeLists which implements nsISupports and Item()
* and expects subclasess to implement GetLength() and GetNodeAt()
#ifndef nsIHTMLCollection_h___
#define nsIHTMLCollection_h___
#include "nsIDOMHTMLCollection.h";
// IID for the nsIHTMLCollection interface
#define NS_IHTMLCOLLECTION_IID \
{ 0xb90f2c8c, 0xc564, 0x4464, \
{ 0x97, 0x01, 0x05, 0x14, 0xe4, 0xeb, 0x69, 0x65 } }
/**
* An internal interface that allows QI-less getting of nodes from HTML
* collections
*/
// XXXbz we don't use this for much... should we be using it more, or
// just nix it?
#ifndef nsGenericDOMNodeList_h__
#define nsGenericDOMNodeList_h__
#include "nsISupports.h"
#include "nsIDOMNodeList.h"
#include "nsINodeList.h"
class nsGenericDOMNodeList : public nsIDOMNodeList,
public nsINodeList
class nsIHTMLCollection : public nsIDOMHTMLCollection
{
public:
nsGenericDOMNodeList();
virtual ~nsGenericDOMNodeList();
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IHTMLCOLLECTION_IID)
NS_DECL_ISUPPORTS
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
// The following need to be defined in the subclass
// nsIDOMNodeList interface
NS_IMETHOD GetLength(PRUint32* aLength)=0;
// nsINodeList interface
virtual nsINode* GetNodeAt(PRUint32 aIndex) = 0;
/**
* Get the node at the index. Returns null if the index is out of bounds
*/
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult) = 0;
};
#endif // nsGenericDOMNodeList_h__
NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLCollection, NS_IHTMLCOLLECTION_IID)
#endif /* nsIHTMLCollection_h___ */

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

@ -118,12 +118,7 @@ nsClientRectList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsClientRectList::Item(PRUint32 aIndex, nsIDOMClientRect** aReturn)
{
if (aIndex >= PRUint32(mArray.Count())) {
*aReturn = nsnull;
return NS_OK;
}
NS_IF_ADDREF(*aReturn = mArray.ObjectAt(aIndex));
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex));
return NS_OK;
}

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

@ -43,6 +43,7 @@
#include "nsIDOMClientRectList.h"
#include "nsCOMArray.h"
#include "nsRect.h"
#include "nsCOMPtr.h"
class nsPresContext;
@ -76,6 +77,28 @@ public:
void Append(nsIDOMClientRect* aElement) { mArray.AppendObject(aElement); }
nsIDOMClientRect* GetItemAt(PRUint32 aIndex)
{
return mArray.SafeObjectAt(aIndex);
}
static nsClientRectList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMClientRectList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMClientRectList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == static_cast<nsIDOMClientRectList*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsClientRectList*>(aSupports);
}
protected:
virtual ~nsClientRectList() {}

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

@ -88,6 +88,7 @@
#include "nsEventDispatcher.h"
#include "mozAutoDocUpdate.h"
#include "nsIHTMLCollection.h"
static const int NS_FORM_CONTROL_LIST_HASHTABLE_SIZE = 16;
@ -348,7 +349,7 @@ PRBool nsHTMLFormElement::gPasswordManagerInitialized = PR_FALSE;
// nsFormControlList
class nsFormControlList : public nsIDOMNSHTMLFormControlList,
public nsIDOMHTMLCollection
public nsIHTMLCollection
{
public:
nsFormControlList(nsHTMLFormElement* aForm);
@ -366,6 +367,15 @@ public:
// nsIDOMNSHTMLFormControlList interface
NS_DECL_NSIDOMNSHTMLFORMCONTROLLIST
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult)
{
FlushPendingNotifications();
*aResult = NS_OK;
return mElements.SafeElementAt(aIndex, nsnull);
}
nsresult AddElementToTable(nsIFormControl* aChild,
const nsAString& aName);
nsresult RemoveElementFromTable(nsIFormControl* aChild,
@ -398,8 +408,7 @@ public:
nsTArray<nsIFormControl*> mNotInElements; // Holds WEAK references
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFormControlList,
nsIDOMHTMLCollection)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFormControlList, nsIHTMLCollection)
protected:
// Drop all our references to the form elements
@ -2112,7 +2121,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
// XPConnect interface list for nsFormControlList
NS_INTERFACE_TABLE_HEAD(nsFormControlList)
NS_INTERFACE_TABLE2(nsFormControlList,
NS_INTERFACE_TABLE3(nsFormControlList,
nsIHTMLCollection,
nsIDOMHTMLCollection,
nsIDOMNSHTMLFormControlList)
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsFormControlList)
@ -2120,10 +2130,8 @@ NS_INTERFACE_TABLE_HEAD(nsFormControlList)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsFormControlList,
nsIDOMHTMLCollection)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsFormControlList,
nsIDOMHTMLCollection)
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsFormControlList, nsIHTMLCollection)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsFormControlList, nsIHTMLCollection)
// nsIDOMHTMLCollection interface
@ -2139,14 +2147,15 @@ nsFormControlList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsFormControlList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
FlushPendingNotifications();
nsresult rv;
nsISupports* item = GetNodeAt(aIndex, &rv);
if (!item) {
*aReturn = nsnull;
if (aIndex < mElements.Length()) {
return CallQueryInterface(mElements[aIndex], aReturn);
return rv;
}
*aReturn = nsnull;
return NS_OK;
return CallQueryInterface(item, aReturn);
}
NS_IMETHODIMP

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

@ -1845,7 +1845,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
// QueryInterface implementation for nsHTMLOptionCollection
NS_INTERFACE_TABLE_HEAD(nsHTMLOptionCollection)
NS_INTERFACE_TABLE3(nsHTMLOptionCollection,
NS_INTERFACE_TABLE4(nsHTMLOptionCollection,
nsIHTMLCollection,
nsIDOMNSHTMLOptionCollection,
nsIDOMHTMLOptionsCollection,
nsIDOMHTMLCollection)
@ -1855,9 +1856,9 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsHTMLOptionCollection,
nsIDOMNSHTMLOptionCollection)
nsIHTMLCollection)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsHTMLOptionCollection,
nsIDOMNSHTMLOptionCollection)
nsIHTMLCollection)
// nsIDOMNSHTMLOptionCollection interface
@ -1947,11 +1948,15 @@ nsHTMLOptionCollection::SetSelectedIndex(PRInt32 aSelectedIndex)
NS_IMETHODIMP
nsHTMLOptionCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsIDOMHTMLOptionElement *option = mElements.SafeObjectAt(aIndex);
nsresult rv;
nsISupports* item = GetNodeAt(aIndex, &rv);
if (!item) {
*aReturn = nsnull;
NS_IF_ADDREF(*aReturn = option);
return rv;
}
return NS_OK;
return CallQueryInterface(item, aReturn);
}
NS_IMETHODIMP

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

@ -49,11 +49,11 @@
#include "nsIDOMNSXBLFormControl.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMHTMLOptionsCollection.h"
#include "nsIDOMNSHTMLOptionCollectn.h"
#include "nsISelectControlFrame.h"
#include "nsContentUtils.h"
#include "nsIHTMLCollection.h"
// PresState
#include "nsXPCOM.h"
@ -71,7 +71,7 @@ class nsHTMLSelectElement;
*/
class nsHTMLOptionCollection: public nsIDOMHTMLOptionsCollection,
public nsIDOMNSHTMLOptionCollection,
public nsIDOMHTMLCollection
public nsIHTMLCollection
{
public:
nsHTMLOptionCollection(nsHTMLSelectElement* aSelect);
@ -88,8 +88,15 @@ public:
// nsIDOMHTMLCollection interface, all its methods are defined in
// nsIDOMHTMLOptionsCollection
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult)
{
*aResult = NS_OK;
return mElements.SafeObjectAt(aIndex);
}
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTMLOptionCollection,
nsIDOMNSHTMLOptionCollection)
nsIHTMLCollection)
// Helpers for nsHTMLSelectElement
/**

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

@ -54,6 +54,7 @@
/* for collections */
#include "nsIDOMElement.h"
#include "nsGenericHTMLElement.h"
#include "nsIHTMLCollection.h"
/* end for collections */
class TableRowsCollection;
@ -105,7 +106,7 @@ protected:
* This class provides a late-bound collection of rows in a table.
* mParent is NOT ref-counted to avoid circular references
*/
class TableRowsCollection : public nsIDOMHTMLCollection
class TableRowsCollection : public nsIHTMLCollection
{
public:
TableRowsCollection(nsHTMLTableElement *aParent);
@ -116,6 +117,8 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMHTMLCOLLECTION
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult);
NS_IMETHOD ParentDestroyed();
NS_DECL_CYCLE_COLLECTION_CLASS(TableRowsCollection)
@ -172,12 +175,14 @@ TableRowsCollection::Init()
// that this may be null at any time. This macro assumes an nsresult named
// |rv| is in scope.
#define DO_FOR_EACH_ROWGROUP(_code) \
PR_BEGIN_MACRO \
do { \
if (mParent) { \
/* THead */ \
nsCOMPtr<nsIDOMHTMLTableSectionElement> rowGroup; \
rv = mParent->GetTHead(getter_AddRefs(rowGroup)); \
NS_ENSURE_SUCCESS(rv, rv); \
if (NS_FAILED(rv)) { \
break; \
} \
nsCOMPtr<nsIDOMHTMLCollection> rows; \
if (rowGroup) { \
rowGroup->GetRows(getter_AddRefs(rows)); \
@ -188,12 +193,16 @@ TableRowsCollection::Init()
nsCOMPtr<nsIDOMHTMLCollection> _tbodies; \
/* TBodies */ \
rv = mParent->GetTBodies(getter_AddRefs(_tbodies)); \
NS_ENSURE_SUCCESS(rv, rv); \
if (NS_FAILED(rv)) { \
break; \
} \
if (_tbodies) { \
nsCOMPtr<nsIDOMNode> _node; \
PRUint32 _tbodyIndex = 0; \
rv = _tbodies->Item(_tbodyIndex, getter_AddRefs(_node)); \
NS_ENSURE_SUCCESS(rv, rv); \
if (NS_FAILED(rv)) { \
break; \
} \
while (_node) { \
rowGroup = do_QueryInterface(_node); \
if (rowGroup) { \
@ -203,7 +212,12 @@ TableRowsCollection::Init()
} while (0); \
} \
rv = _tbodies->Item(++_tbodyIndex, getter_AddRefs(_node)); \
NS_ENSURE_SUCCESS(rv, rv); \
if (NS_FAILED(rv)) { \
break; \
} \
} \
if (NS_FAILED(rv)) { \
break; \
} \
} \
/* orphan rows */ \
@ -213,7 +227,9 @@ TableRowsCollection::Init()
} while (0); \
/* TFoot */ \
rv = mParent->GetTFoot(getter_AddRefs(rowGroup)); \
NS_ENSURE_SUCCESS(rv, rv); \
if (NS_FAILED(rv)) { \
break; \
} \
rows = nsnull; \
if (rowGroup) { \
rowGroup->GetRows(getter_AddRefs(rows)); \
@ -222,7 +238,7 @@ TableRowsCollection::Init()
} while (0); \
} \
} \
PR_END_MACRO
} while (0);
static PRUint32
CountRowsInRowGroup(nsIDOMHTMLCollection* rows)
@ -252,45 +268,59 @@ TableRowsCollection::GetLength(PRUint32* aLength)
return rv;
}
// Returns the number of items in the row group, only if *aItem ends
// up null. Otherwise, returns 0.
static PRUint32
// Returns the item at index aIndex if available. If null is returned,
// then aCount will be set to the number of rows in this row collection.
// Otherwise, the value of aCount is undefined.
static nsINode*
GetItemOrCountInRowGroup(nsIDOMHTMLCollection* rows,
PRUint32 aIndex, nsIDOMNode** aItem)
PRUint32 aIndex, PRUint32* aCount)
{
NS_PRECONDITION(aItem, "Null out param");
*aItem = nsnull;
PRUint32 length = 0;
*aCount = 0;
if (rows) {
rows->Item(aIndex, aItem);
if (!*aItem) {
rows->GetLength(&length);
rows->GetLength(aCount);
if (aIndex < *aCount) {
nsCOMPtr<nsINodeList> list = do_QueryInterface(rows);
return list->GetNodeAt(aIndex);
}
}
return length;
return nsnull;
}
// increments aReturn refcnt by 1
NS_IMETHODIMP
TableRowsCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
nsISupports*
TableRowsCollection::GetNodeAt(PRUint32 aIndex, nsresult *aResult)
{
*aReturn = nsnull;
nsresult rv = NS_OK;
nsresult rv;
DO_FOR_EACH_ROWGROUP(
PRUint32 count = GetItemOrCountInRowGroup(rows, aIndex, aReturn);
if (*aReturn) {
return NS_OK;
PRUint32 count;
nsINode* node = GetItemOrCountInRowGroup(rows, aIndex, &count);
if (node) {
return node;
}
NS_ASSERTION(count <= aIndex, "GetItemOrCountInRowGroup screwed up");
aIndex -= count;
);
return rv;
*aResult = rv;
return nsnull;
}
NS_IMETHODIMP
TableRowsCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsresult rv;
nsISupports* node = GetNodeAt(aIndex, &rv);
if (!node) {
*aReturn = nsnull;
return rv;
}
return CallQueryInterface(node, aReturn);
}
static nsresult

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

@ -98,7 +98,6 @@
#include "nsIDOMHTMLBodyElement.h"
#include "nsINameSpaceManager.h"
#include "nsGenericHTMLElement.h"
#include "nsGenericDOMNodeList.h"
#include "nsICSSLoader.h"
#include "nsIHttpChannel.h"
#include "nsIFile.h"
@ -2860,7 +2859,7 @@ nsHTMLDocument::ResolveName(const nsAString& aName,
if (aForm) {
// ... we're called from a form, in that case we create a
// nsFormNameContentList which will filter out the elements in the
// nsFormContentList which will filter out the elements in the
// list that don't belong to aForm
nsFormContentList *fc_list = new nsFormContentList(aForm, *list);

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

@ -58,7 +58,6 @@
#include "nsContentCID.h"
#include "nsXMLDocument.h"
#include "nsIStreamListener.h"
#include "nsGenericDOMNodeList.h"
#include "nsXBLBinding.h"
#include "nsXBLPrototypeBinding.h"
@ -92,15 +91,14 @@
{ 0xa29df1f8, 0xaeca, 0x4356, \
{ 0xa8, 0xc2, 0xa7, 0x24, 0xa2, 0x11, 0x73, 0xac } }
class nsAnonymousContentList : public nsIDOMNodeList,
public nsINodeList
class nsAnonymousContentList : public nsINodeList
{
public:
nsAnonymousContentList(nsInsertionPointList* aElements);
virtual ~nsAnonymousContentList();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAnonymousContentList, nsIDOMNodeList)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAnonymousContentList, nsINodeList)
// nsIDOMNodeList interface
NS_DECL_NSIDOMNODELIST
@ -142,10 +140,8 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAnonymousContentList)
NS_INTERFACE_MAP_BEGIN(nsAnonymousContentList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
if (aIID.Equals(NS_GET_IID(nsAnonymousContentList)))
foundInterface = static_cast<nsIDOMNodeList*>(this);
else
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsAnonymousContentList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsAnonymousContentList)
NS_INTERFACE_MAP_END

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

@ -38,7 +38,6 @@
#include "domstubs.idl"
interface nsIDOMOfflineResourceList;
interface nsIDOMLoadStatusList;
[scriptable, uuid(f8bbf8c3-c47b-465a-a221-22824449f689)]
interface nsIDOMClientInformation : nsISupports

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

@ -48,7 +48,6 @@ GRE_MODULE = 1
XPIDLSRCS = \
nsIDOMOfflineResourceList.idl \
nsIDOMLoadStatusList.idl \
nsIDOMLoadStatus.idl \
nsIDOMLoadStatusEvent.idl \
$(NULL)

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

@ -408,7 +408,6 @@ enum nsDOMClassInfoID {
eDOMClassInfo_XULCommandEvent_id,
eDOMClassInfo_CommandEvent_id,
eDOMClassInfo_OfflineResourceList_id,
eDOMClassInfo_LoadStatusList_id,
eDOMClassInfo_LoadStatus_id,
eDOMClassInfo_LoadStatusEvent_id,

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

@ -132,6 +132,7 @@ LOCAL_INCLUDES = \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/html/document/src \
-I$(topsrcdir)/layout/style \
-I$(topsrcdir)/layout/xul/base/src/tree/src \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

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

@ -113,8 +113,7 @@
#include "nsIDOMMediaList.h"
#include "nsIDOMChromeWindow.h"
#include "nsIDOMConstructor.h"
#include "nsIDOMClientRect.h"
#include "nsIDOMClientRectList.h"
#include "nsClientRect.h"
// DOM core includes
#include "nsDOMError.h"
@ -134,6 +133,7 @@
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMNSHTMLFormControlList.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIHTMLCollection.h"
#include "nsHTMLDocument.h"
// HTMLSelectElement helper includes
@ -182,7 +182,8 @@
#include "nsIDOMStyleSheetList.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSRuleList.h"
#include "nsICSSRule.h"
#include "nsICSSRuleList.h"
#include "nsIDOMRect.h"
#include "nsIDOMRGBColor.h"
#include "nsIDOMNSRGBAColor.h"
@ -331,7 +332,7 @@
#include "nsIDOMCSSPrimitiveValue.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSValueList.h"
#include "nsDOMCSSValueList.h"
#include "nsIDOMRange.h"
#include "nsIDOMNSRange.h"
#include "nsIDOMRangeException.h"
@ -351,7 +352,7 @@
#include "nsITreeContentView.h"
#include "nsITreeView.h"
#include "nsIXULTemplateBuilder.h"
#include "nsITreeColumns.h"
#include "nsTreeColumns.h"
#endif
#include "nsIDOMXPathException.h"
#include "nsIDOMXPathExpression.h"
@ -453,7 +454,6 @@
#include "nsIDOMDataTransfer.h"
// Offline includes
#include "nsIDOMLoadStatusList.h"
#include "nsIDOMLoadStatus.h"
#include "nsIDOMLoadStatusEvent.h"
@ -462,8 +462,7 @@
#include "nsIDOMGeoPosition.h"
#include "nsIDOMGeoPositionError.h"
#include "nsIDOMFileList.h"
#include "nsIDOMFile.h"
#include "nsDOMFile.h"
#include "nsIDOMFileException.h"
static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID);
@ -634,7 +633,7 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(ProcessingInstruction, nsNodeSH,
NODE_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Notation, nsNodeSH, NODE_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(NodeList, nsArraySH, ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(NodeList, nsNodeListSH, ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(NamedNodeMap, nsNamedNodeMapSH,
ARRAY_SCRIPTABLE_FLAGS)
@ -1229,8 +1228,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(OfflineResourceList, nsOfflineResourceListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(LoadStatusList, nsLoadStatusListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(LoadStatus, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(LoadStatusEvent, nsDOMGenericSH,
@ -3419,11 +3416,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(LoadStatusList, nsIDOMLoadStatusList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLoadStatusList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(LoadStatus, nsIDOMLoadStatus)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMLoadStatus)
DOM_CLASSINFO_MAP_END
@ -7538,35 +7530,8 @@ nsGenericArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// it doesn't provide one.
PRUint32 length;
nsCOMPtr<nsIDOMNodeList> map = do_QueryWrappedNative(wrapper);
if (map) {
// Fast path: Get the length from our map.
map->GetLength(&length);
} else {
// Slow path: We don't know how to get the length in a fast way, ask our
// implementation.
jsval lenval;
if (!JS_GetProperty(cx, obj, "length", &lenval)) {
return NS_ERROR_UNEXPECTED;
}
if (!JSVAL_IS_INT(lenval)) {
// This can apparently happen with some sparse array impls falling back
// onto this code.
return NS_OK;
}
PRInt32 slen = JSVAL_TO_INT(lenval);
if (slen < 0) {
return NS_OK;
}
length = (PRUint32)slen;
}
nsresult rv = GetLength(wrapper, cx, obj, &length);
NS_ENSURE_SUCCESS(rv, rv);
if ((PRUint32)n < length) {
*_retval = ::JS_DefineElement(cx, obj, n, JSVAL_VOID, nsnull, nsnull,
@ -7578,6 +7543,33 @@ nsGenericArraySH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
nsresult
nsGenericArraySH::GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length)
{
*length = 0;
jsval lenval;
if (!JS_GetProperty(cx, obj, "length", &lenval)) {
return NS_ERROR_UNEXPECTED;
}
if (!JSVAL_IS_INT(lenval)) {
// This can apparently happen with some sparse array impls falling back
// onto this code.
return NS_OK;
}
PRInt32 slen = JSVAL_TO_INT(lenval);
if (slen < 0) {
return NS_OK;
}
*length = (PRUint32)slen;
return NS_OK;
}
NS_IMETHODIMP
nsGenericArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRBool *_retval)
@ -7613,21 +7605,7 @@ nsGenericArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return ok ? NS_OK : NS_ERROR_UNEXPECTED;
}
// NodeList scriptable helper
nsresult
nsArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
{
nsCOMPtr<nsINodeList> list(do_QueryInterface(aNative));
if (!list) {
return NS_ERROR_UNEXPECTED;
}
NS_IF_ADDREF(*aResult = list->GetNodeAt(aIndex));
return NS_OK;
}
// Array scriptable helper
NS_IMETHODIMP
nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
@ -7643,9 +7621,10 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
nsCOMPtr<nsISupports> array_item;
rv = GetItemAt(wrapper->Native(), n, getter_AddRefs(array_item));
// Make sure rv == NS_OK here, so GetItemAt implementations that never fail
// don't have to set rv.
rv = NS_OK;
nsISupports* array_item = GetItemAt(wrapper->Native(), n, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (array_item) {
@ -7662,6 +7641,47 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
// NodeList scriptable helper
nsresult
nsNodeListSH::GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length)
{
nsINodeList* list = static_cast<nsINodeList*>(wrapper->Native());
#ifdef DEBUG
{
nsCOMPtr<nsINodeList> list_qi = do_QueryWrappedNative(wrapper);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsINodeList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == list, "Uh, fix QI!");
}
#endif
return list->GetLength(length);
}
nsISupports*
nsNodeListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult)
{
nsINodeList* list = static_cast<nsINodeList*>(aNative);
#ifdef DEBUG
{
nsCOMPtr<nsINodeList> list_qi = do_QueryInterface(aNative);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsINodeList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == list, "Uh, fix QI!");
}
#endif
return list->GetNodeAt(aIndex);
}
// StringList scriptable helper
nsresult
@ -7707,19 +7727,13 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// NamedNodeMap helper
nsresult
nsISupports*
nsNamedNodeMapSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMNamedNodeMap> map(do_QueryInterface(aNative));
NS_ENSURE_TRUE(map, NS_ERROR_UNEXPECTED);
nsDOMAttributeMap* map = nsDOMAttributeMap::FromSupports(aNative);
nsIDOMNode *node = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = map->Item(aIndex, &node);
*aResult = node;
return rv;
return map->GetItemAt(aIndex, aResult);
}
nsresult
@ -7740,25 +7754,23 @@ nsNamedNodeMapSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
// HTMLCollection helper
nsresult
nsISupports*
nsHTMLCollectionSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
// Common case is that we're also an nsINodeList
nsresult rv = nsArraySH::GetItemAt(aNative, aIndex, aResult);
if (NS_SUCCEEDED(rv)) {
return rv;
nsIHTMLCollection* collection = static_cast<nsIHTMLCollection*>(aNative);
#ifdef DEBUG
{
nsCOMPtr<nsIHTMLCollection> collection_qi = do_QueryInterface(aNative);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIHTMLCollection pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(collection_qi == collection, "Uh, fix QI!");
}
#endif
nsCOMPtr<nsIDOMHTMLCollection> collection(do_QueryInterface(aNative));
NS_ENSURE_TRUE(collection, NS_ERROR_UNEXPECTED);
nsIDOMNode *node = nsnull; // Weak, transfer the ownership over to aResult
rv = collection->Item(aIndex, &node);
*aResult = node;
return rv;
return collection->GetNodeAt(aIndex, aResult);
}
nsresult
@ -7783,14 +7795,7 @@ nsresult
nsContentListSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj)
{
nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(nativeObj));
nsContentList *contentList =
static_cast<nsContentList*>(static_cast<nsIDOMNodeList*>(nodeList));
if (!contentList) {
return NS_OK;
}
nsContentList *contentList = nsContentList::FromSupports(nativeObj);
nsISupports *native_parent = contentList->GetParentObject();
if (!native_parent) {
@ -7809,6 +7814,29 @@ nsContentListSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
return rv;
}
NS_IMETHODIMP
nsContentListSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp,
PRBool *_retval)
{
if (JSVAL_IS_STRING(id) && !ObjectIsNativeWrapper(cx, obj)) {
nsContentList *list = nsContentList::FromSupports(wrapper->Native());
nsINode* node = list->NamedItem(nsDependentJSString(id), PR_TRUE);
if (!node) {
return NS_OK;
}
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, obj, node, NS_GET_IID(nsISupports), vp,
getter_AddRefs(holder));
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
}
return nsNodeListSH::GetProperty(wrapper, cx, obj, id, vp, _retval);
}
// FormControlList helper
nsresult
@ -9846,19 +9874,13 @@ nsHTMLOptionsCollectionSH::Add(JSContext *cx, JSObject *obj, uintN argc,
// Plugin helper
nsresult
nsISupports*
nsPluginSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMPlugin> plugin(do_QueryInterface(aNative));
NS_ENSURE_TRUE(plugin, NS_ERROR_UNEXPECTED);
nsPluginElement* plugin = nsPluginElement::FromSupports(aNative);
nsIDOMMimeType *mime_type = nsnull;
nsresult rv = plugin->Item(aIndex, &mime_type);
*aResult = mime_type;
return rv;
return plugin->GetItemAt(aIndex, aResult);
}
nsresult
@ -9880,19 +9902,13 @@ nsPluginSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
// PluginArray helper
nsresult
nsISupports*
nsPluginArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMPluginArray> array(do_QueryInterface(aNative));
NS_ENSURE_TRUE(array, NS_ERROR_UNEXPECTED);
nsPluginArray* array = nsPluginArray::FromSupports(aNative);
nsIDOMPlugin *plugin = nsnull;
nsresult rv = array->Item(aIndex, &plugin);
*aResult = plugin;
return rv;
return array->GetItemAt(aIndex, aResult);
}
nsresult
@ -9914,19 +9930,13 @@ nsPluginArraySH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
// MimeTypeArray helper
nsresult
nsISupports*
nsMimeTypeArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMMimeTypeArray> array(do_QueryInterface(aNative));
NS_ENSURE_TRUE(array, NS_ERROR_UNEXPECTED);
nsMimeTypeArray* array = nsMimeTypeArray::FromSupports(aNative);
nsIDOMMimeType *mime_type = nsnull;
nsresult rv = array->Item(aIndex, &mime_type);
*aResult = mime_type;
return rv;
return array->GetItemAt(aIndex, aResult);
}
nsresult
@ -10041,37 +10051,25 @@ nsMediaListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
// StyleSheetList helper
nsresult
nsISupports*
nsStyleSheetListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *rv)
{
nsCOMPtr<nsIDOMStyleSheetList> stylesheets(do_QueryInterface(aNative));
NS_ENSURE_TRUE(stylesheets, NS_ERROR_UNEXPECTED);
nsDOMStyleSheetList* list = nsDOMStyleSheetList::FromSupports(aNative);
nsIDOMStyleSheet *sheet = nsnull;
nsresult rv = stylesheets->Item(aIndex, &sheet);
*aResult = sheet;
return rv;
return list->GetItemAt(aIndex);
}
// CSSValueList helper
nsresult
nsISupports*
nsCSSValueListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMCSSValueList> cssValueList(do_QueryInterface(aNative));
NS_ENSURE_TRUE(cssValueList, NS_ERROR_UNEXPECTED);
nsDOMCSSValueList* list = nsDOMCSSValueList::FromSupports(aNative);
nsIDOMCSSValue *cssValue = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = cssValueList->Item(aIndex, &cssValue);
*aResult = cssValue;
return rv;
return list->GetItemAt(aIndex);
}
@ -10093,54 +10091,46 @@ nsCSSStyleDeclSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
// CSSRuleList scriptable helper
nsresult
nsISupports*
nsCSSRuleListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMCSSRuleList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
nsICSSRuleList* list = static_cast<nsICSSRuleList*>(aNative);
#ifdef DEBUG
{
nsCOMPtr<nsICSSRuleList> list_qi = do_QueryInterface(aNative);
nsIDOMCSSRule *rule = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = list->Item(aIndex, &rule);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsICSSRuleList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == list, "Uh, fix QI!");
}
#endif
*aResult = rule;
return rv;
return list->GetItemAt(aIndex, aResult);
}
// ClientRectList scriptable helper
nsresult
nsISupports*
nsClientRectListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMClientRectList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
nsClientRectList* list = nsClientRectList::FromSupports(aNative);
nsIDOMClientRect *rule = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = list->Item(aIndex, &rule);
*aResult = rule;
return rv;
return list->GetItemAt(aIndex);
}
#ifdef MOZ_XUL
// TreeColumns helper
nsresult
nsISupports*
nsTreeColumnsSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsITreeColumns> columns(do_QueryInterface(aNative));
NS_ENSURE_TRUE(columns, NS_ERROR_UNEXPECTED);
nsTreeColumns* columns = nsTreeColumns::FromSupports(aNative);
nsITreeColumn* column = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = columns->GetColumnAt(aIndex, &column);
*aResult = column;
return rv;
return columns->GetColumnAt(aIndex);
}
nsresult
@ -10479,34 +10469,12 @@ nsOfflineResourceListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
return list->Item(aIndex, aResult);
}
// nsLoadStatusListSH
nsresult
nsLoadStatusListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
{
nsCOMPtr<nsIDOMLoadStatusList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
nsIDOMLoadStatus *status = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = list->Item(aIndex, &status);
*aResult = status;
return rv;
}
// nsFileListSH
nsresult
nsISupports*
nsFileListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMFileList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
nsDOMFileList* list = nsDOMFileList::FromSupports(aNative);
nsIDOMFile *file = nsnull; // weak, transfer ownership over to aResult
nsresult rv = list->Item(aIndex, &file);
*aResult = file;
return rv;
return list->GetItemAt(aIndex);
}

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

@ -620,6 +620,9 @@ public:
NS_IMETHOD Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRBool *_retval);
virtual nsresult GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsGenericArraySH(aData);
@ -627,7 +630,7 @@ public:
};
// NodeList scriptable helper
// Array scriptable helper
class nsArraySH : public nsGenericArraySH
{
@ -640,16 +643,39 @@ protected:
{
}
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
// Subclasses need to override this, if the implementation can't fail it's
// allowed to not set *aResult.
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult) = 0;
public:
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval);
private:
// Not implemented, nothing should create an instance of this class.
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData);
};
// NodeList scriptable helper
class nsNodeListSH : public nsArraySH
{
protected:
nsNodeListSH(nsDOMClassInfoData* aData) : nsArraySH(aData)
{
}
public:
virtual nsresult GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsArraySH(aData);
return new nsNodeListSH(aData);
}
};
@ -673,6 +699,10 @@ protected:
public:
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval);
private:
// Not implemented, nothing should create an instance of this class.
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData);
};
@ -689,10 +719,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
@ -719,10 +747,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
@ -738,20 +764,18 @@ public:
// ContentList helper
class nsContentListSH : public nsHTMLCollectionSH
class nsContentListSH : public nsNodeListSH
{
protected:
nsContentListSH(nsDOMClassInfoData* aData) : nsHTMLCollectionSH(aData)
{
}
virtual ~nsContentListSH()
nsContentListSH(nsDOMClassInfoData* aData) : nsNodeListSH(aData)
{
}
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
@ -1067,10 +1091,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
@ -1097,10 +1119,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
@ -1127,10 +1147,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
@ -1255,10 +1273,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1281,10 +1297,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1331,10 +1345,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1356,10 +1368,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1383,10 +1393,8 @@ protected:
{
}
// Override nsArraySH::GetItemAt() since our list isn't a
// nsIDOMNodeList
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
@ -1424,6 +1432,11 @@ protected:
JSObject *obj, PRUint32 enum_op, jsval *statep,
jsid *idp, PRBool *_retval);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult)
{
return nsnull;
}
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
@ -1446,6 +1459,11 @@ protected:
{
}
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult)
{
return nsnull;
}
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
@ -1571,27 +1589,6 @@ public:
}
};
class nsLoadStatusListSH : public nsArraySH
{
protected:
nsLoadStatusListSH(nsDOMClassInfoData *aData) : nsArraySH(aData)
{
}
virtual ~nsLoadStatusListSH()
{
}
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsLoadStatusListSH(aData);
}
};
class nsFileListSH : public nsArraySH
{
protected:
@ -1603,8 +1600,8 @@ protected:
{
}
virtual nsresult GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)

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

@ -124,7 +124,6 @@ class nsDummyJavaPluginOwner;
class PostMessageEvent;
class nsDOMOfflineResourceList;
class nsDOMOfflineLoadStatusList;
class nsGeolocation;
// permissible values for CheckOpenAllow

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

@ -85,20 +85,34 @@ nsMimeTypeArray::GetLength(PRUint32* aLength)
return NS_OK;
}
nsIDOMMimeType*
nsMimeTypeArray::GetItemAt(PRUint32 aIndex, nsresult *aResult)
{
if (mMimeTypeArray == nsnull) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nsnull;
}
if (aIndex >= mMimeTypeCount) {
*aResult = NS_ERROR_FAILURE;
return nsnull;
}
*aResult = NS_OK;
return mMimeTypeArray[aIndex];
}
NS_IMETHODIMP
nsMimeTypeArray::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
{
if (mMimeTypeArray == nsnull) {
nsresult rv = GetMimeTypes();
if (rv != NS_OK)
return rv;
}
if (aIndex < mMimeTypeCount) {
*aReturn = mMimeTypeArray[aIndex];
NS_IF_ADDREF(*aReturn);
return NS_OK;
}
return NS_ERROR_FAILURE;
nsresult rv;
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
return rv;
}
NS_IMETHODIMP

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

@ -56,6 +56,25 @@ public:
nsresult Refresh();
nsIDOMMimeType* GetItemAt(PRUint32 aIndex, nsresult* aResult);
static nsMimeTypeArray* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMMimeTypeArray> array_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMMimeTypeArray pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(array_qi == static_cast<nsIDOMMimeTypeArray*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsMimeTypeArray*>(aSupports);
}
private:
nsresult GetMimeTypes();
void Clear();

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

@ -105,27 +105,31 @@ nsPluginArray::AllowPlugins()
return allowPlugins;
}
nsIDOMPlugin*
nsPluginArray::GetItemAt(PRUint32 aIndex, nsresult* aResult)
{
*aResult = NS_OK;
if (!AllowPlugins())
return nsnull;
if (mPluginArray == nsnull) {
*aResult = GetPlugins();
if (*aResult != NS_OK)
return nsnull;
}
return aIndex < mPluginCount ? mPluginArray[aIndex] : nsnull;
}
NS_IMETHODIMP
nsPluginArray::Item(PRUint32 aIndex, nsIDOMPlugin** aReturn)
{
NS_PRECONDITION(nsnull != aReturn, "null arg");
*aReturn = nsnull;
nsresult rv;
if (!AllowPlugins())
return NS_OK;
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
if (mPluginArray == nsnull) {
nsresult rv = GetPlugins();
if (rv != NS_OK)
return rv;
}
if (aIndex < mPluginCount) {
*aReturn = mPluginArray[aIndex];
NS_IF_ADDREF(*aReturn);
}
return NS_OK;
return rv;
}
NS_IMETHODIMP
@ -330,21 +334,34 @@ nsPluginElement::GetLength(PRUint32* aLength)
return mPlugin->GetLength(aLength);
}
nsIDOMMimeType*
nsPluginElement::GetItemAt(PRUint32 aIndex, nsresult *aResult)
{
if (mMimeTypeArray == nsnull) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nsnull;
}
if (aIndex >= mMimeTypeCount) {
*aResult = NS_ERROR_FAILURE;
return nsnull;
}
*aResult = NS_OK;
return mMimeTypeArray[aIndex];
}
NS_IMETHODIMP
nsPluginElement::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
{
if (mMimeTypeArray == nsnull) {
nsresult rv = GetMimeTypes();
if (rv != NS_OK)
return rv;
}
if (aIndex < mMimeTypeCount) {
nsIDOMMimeType* mimeType = mMimeTypeArray[aIndex];
NS_IF_ADDREF(mimeType);
*aReturn = mimeType;
return NS_OK;
}
return NS_ERROR_FAILURE;
nsresult rv;
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex, &rv));
return rv;
}
NS_IMETHODIMP

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

@ -60,6 +60,25 @@ public:
nsresult GetPluginHost(nsIPluginHost** aPluginHost);
nsIDOMPlugin* GetItemAt(PRUint32 aIndex, nsresult* aResult);
static nsPluginArray* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMPluginArray> array_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMPluginArray pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(array_qi == static_cast<nsIDOMPluginArray*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsPluginArray*>(aSupports);
}
private:
nsresult GetPlugins();
PRBool AllowPlugins();
@ -84,6 +103,25 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMPLUGIN
nsIDOMMimeType* GetItemAt(PRUint32 aIndex, nsresult* aResult);
static nsPluginElement* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMPlugin> plugin_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMPlugin pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(plugin_qi == static_cast<nsIDOMPlugin*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsPluginElement*>(aSupports);
}
private:
nsresult GetMimeTypes();

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

@ -1,577 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Camp <dcamp@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDOMOfflineLoadStatusList.h"
#include "nsDOMClassInfo.h"
#include "nsIMutableArray.h"
#include "nsCPrefetchService.h"
#include "nsIObserverService.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsIContent.h"
#include "nsNetCID.h"
#include "nsICacheService.h"
#include "nsICacheSession.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsContentUtils.h"
#include "nsDOMError.h"
#include "nsNetUtil.h"
#include "nsAutoPtr.h"
#define LOADREQUESTED_STR "loadrequested"
#define LOADCOMPLETED_STR "loadcompleted"
//
// nsDOMOfflineLoadStatus
//
// XXX
//
// nsDOMOfflineLoadStatusList has an array wrapper in its classinfo struct
// (LoadStatusList) that exposes nsDOMOfflineLoadStatusList::Item() as
// array items.
//
// For scripts to recognize these as nsIDOMLoadStatus objects, I needed
// to add a LoadStatus classinfo.
//
// Because the prefetch service is outside the dom module, it can't
// actually use the LoadStatus classinfo.
//
// nsDOMOfflineLoadStatus is just a simple wrapper around the
// nsIDOMLoadStatus objects returned by the prefetch service that adds the
// LoadStatus classinfo implementation.
//
// Is there a better way around this?
class nsDOMOfflineLoadStatus : public nsIDOMLoadStatus
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMLOADSTATUS
nsDOMOfflineLoadStatus(nsIDOMLoadStatus *status);
virtual ~nsDOMOfflineLoadStatus();
const nsIDOMLoadStatus *Implementation() { return mStatus; }
private:
nsCOMPtr<nsIDOMLoadStatus> mStatus;
};
NS_INTERFACE_MAP_BEGIN(nsDOMOfflineLoadStatus)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMLoadStatus)
NS_INTERFACE_MAP_ENTRY(nsIDOMLoadStatus)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(LoadStatus)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMOfflineLoadStatus)
NS_IMPL_RELEASE(nsDOMOfflineLoadStatus)
nsDOMOfflineLoadStatus::nsDOMOfflineLoadStatus(nsIDOMLoadStatus *aStatus)
: mStatus(aStatus)
{
}
nsDOMOfflineLoadStatus::~nsDOMOfflineLoadStatus()
{
}
NS_IMETHODIMP
nsDOMOfflineLoadStatus::GetSource(nsIDOMNode **aSource)
{
return mStatus->GetSource(aSource);
}
NS_IMETHODIMP
nsDOMOfflineLoadStatus::GetUri(nsAString &aURI)
{
return mStatus->GetUri(aURI);
}
NS_IMETHODIMP
nsDOMOfflineLoadStatus::GetTotalSize(PRInt32 *aTotalSize)
{
return mStatus->GetTotalSize(aTotalSize);
}
NS_IMETHODIMP
nsDOMOfflineLoadStatus::GetLoadedSize(PRInt32 *aLoadedSize)
{
return mStatus->GetLoadedSize(aLoadedSize);
}
NS_IMETHODIMP
nsDOMOfflineLoadStatus::GetReadyState(PRUint16 *aReadyState)
{
return mStatus->GetReadyState(aReadyState);
}
NS_IMETHODIMP
nsDOMOfflineLoadStatus::GetStatus(PRUint16 *aStatus)
{
return mStatus->GetStatus(aStatus);
}
//
// nsDOMOfflineLoadStatusList
//
NS_INTERFACE_MAP_BEGIN(nsDOMOfflineLoadStatusList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMLoadStatusList)
NS_INTERFACE_MAP_ENTRY(nsIDOMLoadStatusList)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(LoadStatusList)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMOfflineLoadStatusList)
NS_IMPL_RELEASE(nsDOMOfflineLoadStatusList)
nsDOMOfflineLoadStatusList::nsDOMOfflineLoadStatusList(nsIURI *aURI)
: mInitialized(PR_FALSE)
, mURI(aURI)
{
}
nsDOMOfflineLoadStatusList::~nsDOMOfflineLoadStatusList()
{
mLoadRequestedEventListeners.Clear();
mLoadCompletedEventListeners.Clear();
}
nsresult
nsDOMOfflineLoadStatusList::Init()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
nsresult rv = mURI->GetHostPort(mHostPort);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIOfflineCacheUpdateService> cacheUpdateService =
do_GetService(NS_OFFLINECACHEUPDATESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 numUpdates;
rv = cacheUpdateService->GetNumUpdates(&numUpdates);
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < numUpdates; i++) {
nsCOMPtr<nsIOfflineCacheUpdate> cacheUpdate;
rv = cacheUpdateService->GetUpdate(i, getter_AddRefs(cacheUpdate));
NS_ENSURE_SUCCESS(rv, rv);
UpdateAdded(cacheUpdate);
NS_ENSURE_SUCCESS(rv, rv);
}
// watch for new offline cache updates
nsCOMPtr<nsIObserverService> observerServ =
do_GetService("@mozilla.org/observer-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = observerServ->AddObserver(this, "offline-cache-update-added", PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
rv = observerServ->AddObserver(this, "offline-cache-update-completed", PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
nsIDOMLoadStatus *
nsDOMOfflineLoadStatusList::FindWrapper(nsIDOMLoadStatus *aStatus,
PRUint32 *index)
{
for (int i = 0; i < mItems.Count(); i++) {
nsDOMOfflineLoadStatus *item = static_cast<nsDOMOfflineLoadStatus*>
(mItems[i]);
if (item->Implementation() == aStatus) {
*index = i;
return mItems[i];
}
}
return nsnull;
}
nsresult
nsDOMOfflineLoadStatusList::UpdateAdded(nsIOfflineCacheUpdate *aUpdate)
{
nsCAutoString owner;
nsresult rv = aUpdate->GetUpdateDomain(owner);
NS_ENSURE_SUCCESS(rv, rv);
if (owner != mHostPort) {
// This update doesn't belong to us
return NS_OK;
}
PRUint32 numItems;
rv = aUpdate->GetCount(&numItems);
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < numItems; i++) {
nsCOMPtr<nsIDOMLoadStatus> status;
rv = aUpdate->Item(i, getter_AddRefs(status));
NS_ENSURE_SUCCESS(rv, rv);
nsDOMOfflineLoadStatus *wrapper = new nsDOMOfflineLoadStatus(status);
if (!wrapper) return NS_ERROR_OUT_OF_MEMORY;
mItems.AppendObject(wrapper);
SendLoadEvent(NS_LITERAL_STRING(LOADREQUESTED_STR),
mLoadRequestedEventListeners,
wrapper);
}
return NS_OK;
}
nsresult
nsDOMOfflineLoadStatusList::UpdateCompleted(nsIOfflineCacheUpdate *aUpdate)
{
nsCAutoString owner;
nsresult rv = aUpdate->GetUpdateDomain(owner);
NS_ENSURE_SUCCESS(rv, rv);
if (owner != mHostPort) {
// This update doesn't belong to us
return NS_OK;
}
PRUint32 numItems;
rv = aUpdate->GetCount(&numItems);
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < numItems; i++) {
nsCOMPtr<nsIDOMLoadStatus> status;
rv = aUpdate->Item(i, getter_AddRefs(status));
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 index;
nsCOMPtr<nsIDOMLoadStatus> wrapper = FindWrapper(status, &index);
if (wrapper) {
mItems.RemoveObjectAt(index);
nsresult rv = SendLoadEvent(NS_LITERAL_STRING(LOADCOMPLETED_STR),
mLoadCompletedEventListeners,
wrapper);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
//
// nsDOMOfflineLoadStatusList::nsIDOMLoadStatusList
//
NS_IMETHODIMP
nsDOMOfflineLoadStatusList::GetLength(PRUint32 *aLength)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
*aLength = mItems.Count();
return NS_OK;
}
NS_IMETHODIMP
nsDOMOfflineLoadStatusList::Item(PRUint32 aItem, nsIDOMLoadStatus **aStatus)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
if ((PRInt32)aItem >= mItems.Count()) return NS_ERROR_DOM_INDEX_SIZE_ERR;
NS_ADDREF(*aStatus = mItems[aItem]);
return NS_OK;
}
//
// nsDOMOfflineLoadStatusList::nsIDOMEventTarget
//
static nsIScriptContext *
GetCurrentContext()
{
// Get JSContext from stack.
nsCOMPtr<nsIJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (!stack) {
return nsnull;
}
JSContext *cx;
if (NS_FAILED(stack->Peek(&cx)) || !cx) {
return nsnull;
}
return GetScriptContextFromJSContext(cx);
}
NS_IMETHODIMP
nsDOMOfflineLoadStatusList::AddEventListener(const nsAString& aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG(aListener);
nsCOMArray<nsIDOMEventListener> *array;
#define IMPL_ADD_LISTENER(_type, _member) \
if (aType.EqualsLiteral(_type)) { \
array = &(_member); \
} else
IMPL_ADD_LISTENER(LOADREQUESTED_STR, mLoadRequestedEventListeners)
IMPL_ADD_LISTENER(LOADCOMPLETED_STR, mLoadCompletedEventListeners)
{
return NS_ERROR_INVALID_ARG;
}
array->AppendObject(aListener);
mScriptContext = GetCurrentContext();
#undef IMPL_ADD_LISTENER
return NS_OK;
}
NS_IMETHODIMP
nsDOMOfflineLoadStatusList::RemoveEventListener(const nsAString &aType,
nsIDOMEventListener *aListener,
PRBool aUseCapture)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG(aListener);
nsCOMArray<nsIDOMEventListener> *array;
#define IMPL_REMOVE_LISTENER(_type, _member) \
if (aType.EqualsLiteral(_type)) { \
array = &(_member); \
} else
IMPL_REMOVE_LISTENER(LOADREQUESTED_STR, mLoadRequestedEventListeners)
IMPL_REMOVE_LISTENER(LOADCOMPLETED_STR, mLoadCompletedEventListeners)
{
return NS_ERROR_INVALID_ARG;
}
// Allow a caller to remove O(N^2) behavior by removing end-to-start.
for (PRUint32 i = array->Count() - 1; i != PRUint32(-1); --i) {
if (array->ObjectAt(i) == aListener) {
array->RemoveObjectAt(i);
break;
}
}
#undef IMPL_ADD_LISTENER
return NS_OK;
}
NS_IMETHODIMP
nsDOMOfflineLoadStatusList::DispatchEvent(nsIDOMEvent *evt, PRBool *_retval)
{
// Ignored
return NS_OK;
}
void
nsDOMOfflineLoadStatusList::NotifyEventListeners(const nsCOMArray<nsIDOMEventListener>& aListeners,
nsIDOMEvent* aEvent)
{
// XXXbz wouldn't it be easier to just have an actual nsEventListenerManager
// to work with or something? I feel like we're duplicating code here...
//
// (and this was duplicated from XMLHttpRequest)
if (!aEvent)
return;
nsCOMPtr<nsIJSContextStack> stack;
JSContext *cx = nsnull;
if (mScriptContext) {
stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (stack) {
cx = (JSContext *)mScriptContext->GetNativeContext();
if (cx) {
stack->Push(cx);
}
}
}
PRInt32 count = aListeners.Count();
for (PRInt32 index = 0; index < count; ++index) {
nsIDOMEventListener* listener = aListeners[index];
if (listener) {
listener->HandleEvent(aEvent);
}
}
if (cx) {
stack->Pop(&cx);
}
}
nsresult
nsDOMOfflineLoadStatusList::SendLoadEvent(const nsAString &aEventName,
const nsCOMArray<nsIDOMEventListener> &aListeners,
nsIDOMLoadStatus *aStatus)
{
NS_ENSURE_ARG(aStatus);
if (aListeners.Count() == 0) return NS_OK;
nsRefPtr<nsDOMLoadStatusEvent> event = new nsDOMLoadStatusEvent(aEventName,
aStatus);
if (!event) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = event->Init();
NS_ENSURE_SUCCESS(rv, rv);
NotifyEventListeners(aListeners,
static_cast<nsIDOMLoadStatusEvent*>(event));
return NS_OK;
}
//
// nsDOMLoadStatusList::nsIObserver
//
NS_IMETHODIMP
nsDOMOfflineLoadStatusList::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (!strcmp(aTopic, "offline-cache-update-added")) {
nsCOMPtr<nsIOfflineCacheUpdate> update = do_QueryInterface(aSubject);
if (update) {
UpdateAdded(update);
}
} else if (!strcmp(aTopic, "offline-cache-update-completed")) {
nsCOMPtr<nsIOfflineCacheUpdate> update = do_QueryInterface(aSubject);
if (update) {
UpdateCompleted(update);
}
}
return NS_OK;
}
//
// nsDOMLoadStatusEvent
//
NS_INTERFACE_MAP_BEGIN(nsDOMLoadStatusEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMLoadStatusEvent)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(LoadStatusEvent)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
NS_IMPL_ADDREF_INHERITED(nsDOMLoadStatusEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(nsDOMLoadStatusEvent, nsDOMEvent)
nsresult
nsDOMLoadStatusEvent::Init()
{
nsresult rv = InitEvent(mEventName, PR_TRUE, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// This init method is only called by native code, so set the
// trusted flag there.
SetTrusted(PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsDOMLoadStatusEvent::InitLoadStatusEvent(const nsAString& aTypeArg,
PRBool aCanBubbleArg,
PRBool aCancelableArg,
nsIDOMLoadStatus* aStatusArg)
{
nsresult rv = InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
NS_ENSURE_SUCCESS(rv, rv);
mStatus = aStatusArg;
return NS_OK;
}
NS_IMETHODIMP
nsDOMLoadStatusEvent::InitLoadStatusEventNS(const nsAString& aNamespaceURIArg,
const nsAString& aTypeArg,
PRBool aCanBubbleArg,
PRBool aCancelableArg,
nsIDOMLoadStatus* aStatusArg)
{
// XXX: Figure out what to do with aNamespaceURIArg here!
nsresult rv = InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
NS_ENSURE_SUCCESS(rv, rv);
mStatus = aStatusArg;
return NS_OK;
}
NS_IMETHODIMP
nsDOMLoadStatusEvent::GetStatus(nsIDOMLoadStatus **aStatus)
{
NS_ADDREF(*aStatus = mStatus);
return NS_OK;
}

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

@ -102,6 +102,7 @@ EXPORTS = \
nsICSSParser.h \
nsICSSPseudoComparator.h \
nsICSSRule.h \
nsICSSRuleList.h \
nsICSSStyleRule.h \
nsICSSStyleRuleDOMWrapper.h \
nsICSSStyleSheet.h \

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

@ -61,7 +61,7 @@
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIMediaList.h"
#include "nsIDOMMediaList.h"
#include "nsIDOMCSSRuleList.h"
#include "nsICSSRuleList.h"
#include "nsIDOMStyleSheet.h"
#include "nsIDocument.h"
#include "nsPresContext.h"
@ -76,19 +76,18 @@
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetStyleSheet(nsICSSStyleSheet* aSheet) { return super::SetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
NS_IMETHODIMP _class::GetDOMRule(nsIDOMCSSRule** aDOMRule) { return CallQueryInterface(this, aDOMRule); } \
nsIDOMCSSRule* _class::GetDOMRuleWeak(nsresult *aResult) { *aResult = NS_OK; return this; } \
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
#define IMPL_STYLE_RULE_INHERIT2(_class, super) \
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
NS_IMETHODIMP _class::GetDOMRule(nsIDOMCSSRule** aDOMRule) { return CallQueryInterface(this, aDOMRule); } \
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
// -------------------------------
// Style Rule List for group rules
//
class CSSGroupRuleRuleListImpl : public nsIDOMCSSRuleList
class CSSGroupRuleRuleListImpl : public nsICSSRuleList
{
public:
CSSGroupRuleRuleListImpl(nsICSSGroupRule *aGroupRule);
@ -97,6 +96,8 @@ public:
NS_DECL_NSIDOMCSSRULELIST
virtual nsIDOMCSSRule* GetItemAt(PRUint32 aIndex, nsresult* aResult);
void DropReference() { mGroupRule = nsnull; }
protected:
@ -119,6 +120,7 @@ CSSGroupRuleRuleListImpl::~CSSGroupRuleRuleListImpl()
// QueryInterface implementation for CSSGroupRuleRuleList
NS_INTERFACE_MAP_BEGIN(CSSGroupRuleRuleListImpl)
NS_INTERFACE_MAP_ENTRY(nsICSSRuleList)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSGroupRuleRuleList)
@ -142,24 +144,39 @@ CSSGroupRuleRuleListImpl::GetLength(PRUint32* aLength)
return NS_OK;
}
NS_IMETHODIMP
CSSGroupRuleRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
nsIDOMCSSRule*
CSSGroupRuleRuleListImpl::GetItemAt(PRUint32 aIndex, nsresult* aResult)
{
nsresult result = NS_OK;
*aReturn = nsnull;
if (mGroupRule) {
nsCOMPtr<nsICSSRule> rule;
result = mGroupRule->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
if (rule) {
result = rule->GetDOMRule(aReturn);
} else if (result == NS_ERROR_ILLEGAL_VALUE) {
return rule->GetDOMRuleWeak(aResult);
}
if (result == NS_ERROR_ILLEGAL_VALUE) {
result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
}
}
return result;
*aResult = result;
return nsnull;
}
NS_IMETHODIMP
CSSGroupRuleRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
{
nsresult rv;
nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
if (!rule) {
*aReturn = nsnull;
return rv;
}
return CallQueryInterface(rule, aReturn);
}
// -------------------------------------------

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

@ -56,13 +56,16 @@
class CSSGroupRuleRuleListImpl;
class nsMediaList;
#define DECL_STYLE_RULE_INHERIT \
#define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule); \
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
#define DECL_STYLE_RULE_INHERIT \
DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
// inherits from nsCSSRule and also implements methods on nsICSSGroupRule
// so they can be shared between nsCSSMediaRule and nsCSSDocumentRule
class nsCSSGroupRule : public nsCSSRule, public nsICSSGroupRule
@ -73,7 +76,7 @@ protected:
~nsCSSGroupRule();
// implement part of nsIStyleRule and nsICSSRule
DECL_STYLE_RULE_INHERIT
DECL_STYLE_RULE_INHERIT_NO_DOMRULE
// to help implement nsIStyleRule
#ifdef DEBUG
@ -128,6 +131,11 @@ public:
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); //override nsCSSGroupRule
NS_IMETHOD GetType(PRInt32& aType) const;
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
{
*aResult = NS_OK;
return this;
}
// nsIDOMCSSRule interface
NS_DECL_NSIDOMCSSRULE
@ -164,6 +172,11 @@ public:
// nsICSSRule methods
NS_IMETHOD GetType(PRInt32& aType) const;
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
{
*aResult = NS_OK;
return this;
}
// nsIDOMCSSRule interface
NS_DECL_NSIDOMCSSRULE

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

@ -1187,7 +1187,7 @@ public:
NS_IMETHOD GetType(PRInt32& aType) const;
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule);
nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
virtual already_AddRefed<nsICSSStyleRule>
DeclarationChanged(PRBool aHandleContainer);
@ -1376,26 +1376,24 @@ CSSStyleRuleImpl::Clone(nsICSSRule*& aClone) const
return CallQueryInterface(clone, &aClone);
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetDOMRule(nsIDOMCSSRule** aDOMRule)
nsIDOMCSSRule*
CSSStyleRuleImpl::GetDOMRuleWeak(nsresult *aResult)
{
*aResult = NS_OK;
if (!mSheet) {
// inline style rules aren't supposed to have a DOM rule object, only
// a declaration.
*aDOMRule = nsnull;
return NS_OK;
return nsnull;
}
if (!mDOMRule) {
mDOMRule = new DOMCSSStyleRuleImpl(this);
if (!mDOMRule) {
*aDOMRule = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
*aResult = NS_ERROR_OUT_OF_MEMORY;
return nsnull;
}
NS_ADDREF(mDOMRule);
}
*aDOMRule = mDOMRule;
NS_ADDREF(*aDOMRule);
return NS_OK;
return mDOMRule;
}
/* virtual */ already_AddRefed<nsICSSStyleRule>

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

@ -61,7 +61,7 @@
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSImportRule.h"
#include "nsIDOMCSSRuleList.h"
#include "nsICSSRuleList.h"
#include "nsIDOMMediaList.h"
#include "nsIDOMNode.h"
#include "nsDOMError.h"
@ -81,7 +81,7 @@
// -------------------------------
// Style Rule List for the DOM
//
class CSSRuleListImpl : public nsIDOMCSSRuleList
class CSSRuleListImpl : public nsICSSRuleList
{
public:
CSSRuleListImpl(nsCSSStyleSheet *aStyleSheet);
@ -92,6 +92,8 @@ public:
NS_IMETHOD GetLength(PRUint32* aLength);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn);
virtual nsIDOMCSSRule* GetItemAt(PRUint32 aIndex, nsresult* aResult);
void DropReference() { mStyleSheet = nsnull; }
protected:
@ -116,6 +118,7 @@ CSSRuleListImpl::~CSSRuleListImpl()
// QueryInterface implementation for CSSRuleList
NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl)
NS_INTERFACE_MAP_ENTRY(nsICSSRuleList)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRuleList)
@ -141,12 +144,11 @@ CSSRuleListImpl::GetLength(PRUint32* aLength)
return NS_OK;
}
NS_IMETHODIMP
CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
nsIDOMCSSRule*
CSSRuleListImpl::GetItemAt(PRUint32 aIndex, nsresult* aResult)
{
nsresult result = NS_OK;
*aReturn = nsnull;
if (mStyleSheet) {
result = mStyleSheet->EnsureUniqueInner(); // needed to ensure rules have correct parent
if (NS_SUCCEEDED(result)) {
@ -154,15 +156,31 @@ CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
result = mStyleSheet->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
if (rule) {
result = rule->GetDOMRule(aReturn);
mRulesAccessed = PR_TRUE; // signal to never share rules again
} else if (result == NS_ERROR_ILLEGAL_VALUE) {
return rule->GetDOMRuleWeak(aResult);
}
if (result == NS_ERROR_ILLEGAL_VALUE) {
result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
}
}
}
return result;
*aResult = result;
return nsnull;
}
NS_IMETHODIMP
CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
{
nsresult rv;
nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
if (!rule) {
*aReturn = nsnull;
return rv;
}
return CallQueryInterface(rule, aReturn);
}
template <class Numeric>

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

@ -84,8 +84,7 @@ nsDOMCSSValueList::Item(PRUint32 aIndex, nsIDOMCSSValue **aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = mCSSValues[aIndex];
NS_IF_ADDREF(*aReturn);
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex));
return NS_OK;
}

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

@ -68,6 +68,28 @@ public:
*/
PRBool AppendCSSValue(nsIDOMCSSValue* aValue);
nsIDOMCSSValue* GetItemAt(PRUint32 aIndex)
{
return mCSSValues.SafeObjectAt(aIndex);
}
static nsDOMCSSValueList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMCSSValueList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMCSSValueList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == static_cast<nsIDOMCSSValueList*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsDOMCSSValueList*>(aSupports);
}
private:
PRPackedBool mCommaDelimited; // some value lists use a comma
// as the delimiter, some just use

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

@ -41,15 +41,15 @@
#define nsICSSRule_h___
#include "nsIStyleRule.h"
#include "nsIDOMCSSRule.h"
class nsICSSStyleSheet;
class nsICSSGroupRule;
class nsIDOMCSSRule;
class nsAString;
// IID for the nsICSSRule interface {b9791e20-1a04-11d3-805a-006008159b5a}
// IID for the nsICSSRule interface {e775eac0-b022-462c-b1f9-221c01aa2988}
#define NS_ICSS_RULE_IID \
{0xb9791e20, 0x1a04, 0x11d3, {0x80, 0x5a, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
{0xe775eac0, 0xb022, 0x462c, {0xb1, 0xf9, 0x22, 0x1c, 0x01, 0xaa, 0x29, 0x88}}
// inheriting from nsIStyleRule is only for style rules, not other rule types
class nsICSSRule : public nsIStyleRule {
@ -77,7 +77,13 @@ public:
// Note that this returns null for inline style rules since they aren't
// supposed to have a DOM rule representation (and our code wouldn't work).
NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule) = 0;
nsresult GetDOMRule(nsIDOMCSSRule** aDOMRule)
{
nsresult rv;
NS_IF_ADDREF(*aDOMRule = GetDOMRuleWeak(&rv));
return rv;
}
virtual nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSRule, NS_ICSS_RULE_IID)

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

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -12,15 +12,14 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is Mozilla layout code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2007
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Camp <dcamp@mozilla.com>
* Peter Van der Beken <peterv@propagandism.org> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -36,13 +35,24 @@
*
* ***** END LICENSE BLOCK ***** */
#include "domstubs.idl"
#ifndef nsICSSRuleList_h___
#define nsICSSRuleList_h___
interface nsIDOMLoadStatus;
#include "nsIDOMCSSRuleList.h"
[scriptable, uuid(d58bc0cf-e35c-4d22-9e21-9ada8fc4203a)]
interface nsIDOMLoadStatusList : nsISupports
// IID for the nsICSSRuleList interface
#define NS_ICSSRULELIST_IID \
{ 0x7ae746fd, 0x259a, 0x4a69, \
{ 0x97, 0x2d, 0x2c, 0x10, 0xf7, 0xb0, 0x04, 0xa1 } }
class nsICSSRuleList : public nsIDOMCSSRuleList
{
readonly attribute unsigned long length;
nsIDOMLoadStatus item(in unsigned long index);
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSRULELIST_IID)
virtual nsIDOMCSSRule* GetItemAt(PRUint32 aIndex, nsresult* aResult) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSRuleList, NS_ICSSRULELIST_IID)
#endif /* nsICSSRuleList_h___ */

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

@ -535,17 +535,23 @@ nsTreeColumns::GetNamedColumn(const nsAString& aId, nsITreeColumn** _retval)
return NS_OK;
}
nsITreeColumn*
nsTreeColumns::GetColumnAt(PRInt32 aIndex)
{
EnsureColumns();
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->GetIndex() == aIndex) {
return currCol;
}
}
return nsnull;
}
NS_IMETHODIMP
nsTreeColumns::GetColumnAt(PRInt32 aIndex, nsITreeColumn** _retval)
{
EnsureColumns();
*_retval = nsnull;
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->GetIndex() == aIndex) {
NS_ADDREF(*_retval = currCol);
break;
}
}
NS_IF_ADDREF(*_retval = GetColumnAt(aIndex));
return NS_OK;
}

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

@ -144,6 +144,25 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSITREECOLUMNS
nsITreeColumn* GetColumnAt(PRInt32 aIndex);
static nsTreeColumns* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsITreeColumns> columns_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsITreeColumns pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(columns_qi == static_cast<nsITreeColumns*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsTreeColumns*>(aSupports);
}
friend class nsTreeBodyFrame;
protected:
void SetTree(nsITreeBoxObject* aTree) { mTree = aTree; }