Fix for bug 461560 (Make nsNamedArraySH::NamedItem not AddRef/Release). r/sr=bz.

This commit is contained in:
Peter Van der Beken 2008-10-31 08:55:59 -07:00
Родитель abbb12e8ae
Коммит ef4e05905a
19 изменённых файлов: 482 добавлений и 388 удалений

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

@ -351,6 +351,7 @@ nsContentList::~nsContentList()
// QueryInterface implementation for nsContentList
NS_INTERFACE_MAP_BEGIN(nsContentList)
NS_INTERFACE_MAP_ENTRY(nsIHTMLCollection)
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection)
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ContentList)
@ -501,6 +502,20 @@ nsContentList::GetNodeAt(PRUint32 aIndex)
return Item(aIndex, PR_TRUE);
}
nsISupports*
nsContentList::GetNodeAt(PRUint32 aIndex, nsresult* aResult)
{
*aResult = NS_OK;
return Item(aIndex, PR_TRUE);
}
nsISupports*
nsContentList::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
*aResult = NS_OK;
return NamedItem(aName, PR_TRUE);
}
void
nsContentList::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent,
PRInt32 aNameSpaceID, nsIAtom* aAttribute,

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

@ -47,7 +47,7 @@
#include "nsISupports.h"
#include "nsCOMArray.h"
#include "nsString.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIHTMLCollection.h"
#include "nsIDOMNodeList.h"
#include "nsINodeList.h"
#include "nsStubMutationObserver.h"
@ -181,7 +181,7 @@ protected:
*/
class nsContentList : public nsBaseContentList,
protected nsContentListKey,
public nsIDOMHTMLCollection,
public nsIHTMLCollection,
public nsStubMutationObserver
{
public:
@ -241,7 +241,10 @@ public:
// nsBaseContentList overrides
virtual PRInt32 IndexOf(nsIContent *aContent, PRBool aDoFlush);
virtual nsINode* GetNodeAt(PRUint32 aIndex);
// nsIHTMLCollection
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult);
virtual nsISupports* GetNamedItem(const nsAString& aName, nsresult* aResult);
// nsContentList public methods
NS_HIDDEN_(nsISupports*) GetParentObject();

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

@ -216,21 +216,35 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo)
return node;
}
nsIDOMNode*
nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult)
{
*aResult = NS_OK;
if (mContent) {
nsCOMPtr<nsINodeInfo> ni =
mContent->GetExistingAttrNameFromQName(aAttrName);
if (ni) {
nsIDOMNode* node = GetAttribute(ni);
if (node) {
return node;
}
*aResult = NS_ERROR_OUT_OF_MEMORY;
}
}
return nsnull;
}
NS_IMETHODIMP
nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName,
nsIDOMNode** aAttribute)
{
NS_ENSURE_ARG_POINTER(aAttribute);
*aAttribute = nsnull;
nsresult rv = NS_OK;
if (mContent) {
nsCOMPtr<nsINodeInfo> ni =
mContent->GetExistingAttrNameFromQName(aAttrName);
if (ni) {
rv = GetAttribute(ni, aAttribute);
}
}
nsresult rv;
NS_IF_ADDREF(*aAttribute = GetNamedItem(aAttrName, &rv));
return rv;
}

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

@ -171,6 +171,7 @@ public:
PRUint32 Enumerate(AttrCache::EnumReadFunction aFunc, void *aUserArg) const;
nsIDOMNode* GetItemAt(PRUint32 aIndex, nsresult *rv);
nsIDOMNode* GetNamedItem(const nsAString& aAttrName, nsresult *rv);
static nsDOMAttributeMap* FromSupports(nsISupports* aSupports)
{

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

@ -42,8 +42,8 @@
// IID for the nsIHTMLCollection interface
#define NS_IHTMLCOLLECTION_IID \
{ 0xb90f2c8c, 0xc564, 0x4464, \
{ 0x97, 0x01, 0x05, 0x14, 0xe4, 0xeb, 0x69, 0x65 } }
{ 0x5709485b, 0xc057, 0x4ba7, \
{ 0x95, 0xbd, 0x98, 0xb7, 0x94, 0x4f, 0x13, 0xe7 } }
/**
* An internal interface that allows QI-less getting of nodes from HTML
@ -55,9 +55,15 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IHTMLCOLLECTION_IID)
/**
* Get the node at the index. Returns null if the index is out of bounds
* Get the node at the index. Returns null if the index is out of bounds.
*/
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult) = 0;
/**
* Get the node for the name. Returns null if no node exists for the name.
*/
virtual nsISupports* GetNamedItem(const nsAString& aName,
nsresult* aResult) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLCollection, NS_IHTMLCOLLECTION_IID)

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

@ -375,6 +375,12 @@ public:
return mElements.SafeElementAt(aIndex, nsnull);
}
virtual nsISupports* GetNamedItem(const nsAString& aName, nsresult* aResult)
{
*aResult = NS_OK;
return NamedItemInternal(aName, PR_TRUE);
}
nsresult AddElementToTable(nsIFormControl* aChild,
const nsAString& aName);
@ -383,8 +389,7 @@ public:
nsresult IndexOfControl(nsIFormControl* aControl,
PRInt32* aIndex);
void NamedItemInternal(const nsAString& aName, PRBool aFlushContent,
nsISupports **aResult);
nsISupports* NamedItemInternal(const nsAString& aName, PRBool aFlushContent);
/**
* Create a sorted list of form control elements. This list is sorted
@ -1547,8 +1552,8 @@ already_AddRefed<nsISupports>
nsHTMLFormElement::DoResolveName(const nsAString& aName,
PRBool aFlushContent)
{
nsISupports *result = nsnull;
mControls->NamedItemInternal(aName, aFlushContent, &result);
nsISupports *result;
NS_IF_ADDREF(result = mControls->NamedItemInternal(aName, aFlushContent));
return result;
}
@ -2197,20 +2202,19 @@ NS_IMETHODIMP
nsFormControlList::NamedItem(const nsAString& aName,
nsISupports** aReturn)
{
NamedItemInternal(aName, PR_TRUE, aReturn);
NS_IF_ADDREF(*aReturn = NamedItemInternal(aName, PR_TRUE));
return NS_OK;
}
void
nsISupports*
nsFormControlList::NamedItemInternal(const nsAString& aName,
PRBool aFlushContent,
nsISupports** aReturn)
PRBool aFlushContent)
{
if (aFlushContent) {
FlushPendingNotifications();
}
mNameLookupTable.Get(aName, aReturn);
return mNameLookupTable.GetWeak(aName);
}
nsresult

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

@ -1959,31 +1959,39 @@ nsHTMLOptionCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
return CallQueryInterface(item, aReturn);
}
nsISupports*
nsHTMLOptionCollection::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
*aResult = NS_OK;
PRInt32 count = mElements.Count();
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> content = do_QueryInterface(mElements.ObjectAt(i));
if (content &&
(content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, aName,
eCaseMatters) ||
content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id, aName,
eCaseMatters))) {
return content;
}
}
return nsnull;
}
NS_IMETHODIMP
nsHTMLOptionCollection::NamedItem(const nsAString& aName,
nsIDOMNode** aReturn)
{
PRInt32 count = mElements.Count();
nsresult rv = NS_OK;
nsresult rv;
nsISupports* item = GetNamedItem(aName, &rv);
if (!item) {
*aReturn = nsnull;
*aReturn = nsnull;
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> content = do_QueryInterface(mElements.ObjectAt(i));
if (content) {
if (content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, aName,
eCaseMatters) ||
content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id, aName,
eCaseMatters)) {
rv = CallQueryInterface(content, aReturn);
break;
}
}
return rv;
}
return rv;
return CallQueryInterface(item, aReturn);
}
NS_IMETHODIMP

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

@ -94,6 +94,7 @@ public:
return mElements.SafeObjectAt(aIndex);
}
virtual nsISupports* GetNamedItem(const nsAString& aName, nsresult* aResult);
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTMLOptionCollection,
nsIHTMLCollection)

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

@ -118,6 +118,7 @@ public:
NS_DECL_NSIDOMHTMLCOLLECTION
virtual nsISupports* GetNodeAt(PRUint32 aIndex, nsresult* aResult);
virtual nsISupports* GetNamedItem(const nsAString& aName, nsresult* aResult);
NS_IMETHOD ParentDestroyed();
@ -324,32 +325,42 @@ TableRowsCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
return CallQueryInterface(node, aReturn);
}
static nsresult
static nsISupports*
GetNamedItemInRowGroup(nsIDOMHTMLCollection* aRows,
const nsAString& aName, nsIDOMNode** aNamedItem)
const nsAString& aName, nsresult* aResult)
{
if (aRows) {
return aRows->NamedItem(aName, aNamedItem);
nsCOMPtr<nsIHTMLCollection> rows = do_QueryInterface(aRows);
if (rows) {
return rows->GetNamedItem(aName, aResult);
}
*aNamedItem = nsnull;
return NS_OK;
*aResult = NS_OK;
return nsnull;
}
nsISupports*
TableRowsCollection::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
nsresult rv = NS_OK;
DO_FOR_EACH_ROWGROUP(
nsISupports* item = GetNamedItemInRowGroup(rows, aName, aResult);
if (NS_FAILED(*aResult) || item) {
return item;
}
);
*aResult = rv;
return nsnull;
}
NS_IMETHODIMP
TableRowsCollection::NamedItem(const nsAString& aName,
nsIDOMNode** aReturn)
{
*aReturn = nsnull;
nsresult rv = NS_OK;
DO_FOR_EACH_ROWGROUP(
rv = GetNamedItemInRowGroup(rows, aName, aReturn);
NS_ENSURE_SUCCESS(rv, rv);
if (*aReturn) {
return rv;
}
);
return rv;
nsresult rv;
nsISupports* item = GetNamedItem(aName, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(item, aReturn);
}
NS_IMETHODIMP

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

@ -443,12 +443,7 @@
#include "nsIImageDocument.h"
// Storage includes
#include "nsIDOMStorage.h"
#include "nsPIDOMStorage.h"
#include "nsIDOMStorageList.h"
#include "nsIDOMStorageItem.h"
#include "nsIDOMStorageEvent.h"
#include "nsIDOMToString.h"
#include "nsDOMStorage.h"
// Drag and drop
#include "nsIDOMDataTransfer.h"
@ -674,7 +669,7 @@ static nsDOMClassInfoData sClassInfoData[] = {
ARRAY_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_SETPROPERTY)
NS_DEFINE_CLASSINFO_DATA_WITH_NAME(HTMLFormControlCollection, HTMLCollection,
nsFormControlListSH,
nsHTMLCollectionSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA_WITH_NAME(HTMLGenericCollection, HTMLCollection,
nsHTMLCollectionSH,
@ -7715,9 +7710,9 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
PRBool *_retval)
{
if (JSVAL_IS_STRING(id) && !ObjectIsNativeWrapper(cx, obj)) {
nsCOMPtr<nsISupports> item;
nsresult rv = GetNamedItem(wrapper->Native(), nsDependentJSString(id),
getter_AddRefs(item));
nsresult rv = NS_OK;
nsISupports* item = GetNamedItem(wrapper->Native(), nsDependentJSString(id),
&rv);
NS_ENSURE_SUCCESS(rv, rv);
if (item) {
@ -7748,24 +7743,39 @@ nsNamedNodeMapSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
return map->GetItemAt(aIndex, aResult);
}
nsresult
nsISupports*
nsNamedNodeMapSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
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->GetNamedItem(aName, &node);
*aResult = node;
return rv;
return map->GetNamedItem(aName, aResult);
}
// HTMLCollection helper
nsresult
nsHTMLCollectionSH::GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length)
{
nsIHTMLCollection* collection =
static_cast<nsIHTMLCollection*>(wrapper->Native());
#ifdef DEBUG
{
nsCOMPtr<nsIHTMLCollection> collection_qi =
do_QueryInterface(wrapper->Native());
// 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
return collection->GetLength(length);
}
nsISupports*
nsHTMLCollectionSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult)
@ -7785,20 +7795,24 @@ nsHTMLCollectionSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
return collection->GetNodeAt(aIndex, aResult);
}
nsresult
nsISupports*
nsHTMLCollectionSH::GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMHTMLCollection> collection(do_QueryInterface(aNative));
NS_ENSURE_TRUE(collection, NS_ERROR_UNEXPECTED);
nsIHTMLCollection* collection = static_cast<nsIHTMLCollection*>(aNative);
#ifdef DEBUG
{
nsCOMPtr<nsIHTMLCollection> collection_qi = do_QueryInterface(aNative);
nsIDOMNode *node = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = collection->NamedItem(aName, &node);
// 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
*aResult = node;
return rv;
return collection->GetNamedItem(aName, aResult);
}
@ -7826,42 +7840,34 @@ 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
nsFormControlListSH::GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsISupports **aResult)
nsContentListSH::GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length)
{
nsCOMPtr<nsIDOMNSHTMLFormControlList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
nsContentList *list = nsContentList::FromSupports(wrapper->Native());
return list->NamedItem(aName, aResult);
return list->GetLength(length);
}
nsISupports*
nsContentListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult)
{
nsContentList *list = nsContentList::FromSupports(aNative);
return list->GetNodeAt(aIndex, aResult);
}
nsISupports*
nsContentListSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsresult *aResult)
{
nsContentList *list = nsContentList::FromSupports(aNative);
return list->GetNamedItem(aName, aResult);
}
// Document helper for document.location and document.on*
NS_IMETHODIMP
@ -9895,20 +9901,13 @@ nsPluginSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
return plugin->GetItemAt(aIndex, aResult);
}
nsresult
nsISupports*
nsPluginSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
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->NamedItem(aName, &mime_type);
*aResult = mime_type;
return rv;
return plugin->GetNamedItem(aName, aResult);
}
@ -9923,20 +9922,13 @@ nsPluginArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
return array->GetItemAt(aIndex, aResult);
}
nsresult
nsISupports*
nsPluginArraySH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
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->NamedItem(aName, &plugin);
*aResult = plugin;
return rv;
return array->GetNamedItem(aName, aResult);
}
@ -9951,20 +9943,13 @@ nsMimeTypeArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
return array->GetItemAt(aIndex, aResult);
}
nsresult
nsISupports*
nsMimeTypeArraySH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
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->NamedItem(aName, &mime_type);
*aResult = mime_type;
return rv;
return array->GetNamedItem(aName, aResult);
}
@ -10145,20 +10130,14 @@ nsTreeColumnsSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
return columns->GetColumnAt(aIndex);
}
nsresult
nsISupports*
nsTreeColumnsSH::GetNamedItem(nsISupports *aNative,
const nsAString& aName,
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->GetNamedColumn(aName, &column);
*aResult = column;
return rv;
return columns->GetNamedColumn(aName);
}
#endif
@ -10224,20 +10203,13 @@ nsStorageSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
nsresult
nsISupports*
nsStorageSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMStorage> storage(do_QueryInterface(aNative));
NS_ENSURE_TRUE(storage, NS_ERROR_UNEXPECTED);
nsDOMStorage* storage = nsDOMStorage::FromSupports(aNative);
// Weak, transfer the ownership over to aResult
nsIDOMStorageItem* item = nsnull;
nsresult rv = storage->GetItem(aName, &item);
*aResult = item;
return rv;
return storage->GetNamedItem(aName, aResult);
}
NS_IMETHODIMP
@ -10342,20 +10314,13 @@ nsStorageSH::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// StorageList scriptable helper
nsresult
nsISupports*
nsStorageListSH::GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult)
nsresult *aResult)
{
nsCOMPtr<nsIDOMStorageList> storagelist(do_QueryInterface(aNative));
NS_ENSURE_TRUE(storagelist, NS_ERROR_UNEXPECTED);
nsDOMStorageList* storagelist = static_cast<nsDOMStorageList*>(aNative);
// Weak, transfer the ownership over to aResult
nsIDOMStorage* storage = nsnull;
nsresult rv = storagelist->NamedItem(aName, &storage);
*aResult = storage;
return rv;
return storagelist->GetNamedItem(aName, aResult);
}

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

@ -693,8 +693,9 @@ protected:
{
}
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult) = 0;
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult) = 0;
public:
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
@ -723,8 +724,9 @@ protected:
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -747,12 +749,15 @@ protected:
{
}
virtual nsresult GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -764,18 +769,24 @@ public:
// ContentList helper
class nsContentListSH : public nsNodeListSH
class nsContentListSH : public nsNamedArraySH
{
protected:
nsContentListSH(nsDOMClassInfoData* aData) : nsNodeListSH(aData)
nsContentListSH(nsDOMClassInfoData* aData) : nsNamedArraySH(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);
virtual nsresult GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRUint32 *length);
virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsresult *aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
@ -785,32 +796,6 @@ public:
// FomrControlList helper
class nsFormControlListSH : public nsHTMLCollectionSH
{
protected:
nsFormControlListSH(nsDOMClassInfoData* aData) : nsHTMLCollectionSH(aData)
{
}
virtual ~nsFormControlListSH()
{
}
// Override nsNamedArraySH::GetNamedItem() since our NamedItem() can
// return either a nsIDOMNode or a nsIHTMLCollection
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsFormControlListSH(aData);
}
};
// Document helper, for document.location and document.on*
class nsDocumentSH : public nsNodeSH
@ -1095,8 +1080,9 @@ protected:
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1123,8 +1109,9 @@ protected:
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1151,8 +1138,9 @@ protected:
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1397,8 +1385,9 @@ protected:
nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1438,8 +1427,9 @@ protected:
return nsnull;
}
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
@ -1465,8 +1455,9 @@ protected:
return nsnull;
}
// Override nsNamedArraySH::GetNamedItem()
virtual nsresult GetNamedItem(nsISupports *aNative, const nsAString& aName,
nsISupports **aResult);
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)

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

@ -49,10 +49,10 @@
nsMimeTypeArray::nsMimeTypeArray(nsIDOMNavigator* navigator)
: mNavigator(navigator),
mPluginMimeTypeCount(0),
mInited(PR_FALSE)
{
mNavigator = navigator;
mMimeTypeCount = 0;
mMimeTypeArray = nsnull;
}
nsMimeTypeArray::~nsMimeTypeArray()
@ -76,25 +76,34 @@ NS_IMPL_RELEASE(nsMimeTypeArray)
NS_IMETHODIMP
nsMimeTypeArray::GetLength(PRUint32* aLength)
{
if (mMimeTypeArray == nsnull) {
if (!mInited) {
nsresult rv = GetMimeTypes();
if (rv != NS_OK)
return rv;
}
*aLength = mMimeTypeCount;
NS_ASSERTION(mPluginMimeTypeCount <= mMimeTypeArray.Count(),
"The number of total mimetypes should be equal to or higher "
"than the number of plugin mimetypes.");
*aLength = mPluginMimeTypeCount;
return NS_OK;
}
nsIDOMMimeType*
nsMimeTypeArray::GetItemAt(PRUint32 aIndex, nsresult *aResult)
{
if (mMimeTypeArray == nsnull) {
if (!mInited) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nsnull;
}
if (aIndex >= mMimeTypeCount) {
NS_ASSERTION(mPluginMimeTypeCount <= mMimeTypeArray.Count(),
"The number of total mimetypes should be equal to or higher "
"than the number of plugin mimetypes.");
if (aIndex >= mPluginMimeTypeCount) {
*aResult = NS_ERROR_FAILURE;
return nsnull;
@ -115,31 +124,30 @@ nsMimeTypeArray::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
return rv;
}
NS_IMETHODIMP
nsMimeTypeArray::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
nsIDOMMimeType*
nsMimeTypeArray::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
if (mMimeTypeArray == nsnull) {
nsresult rv = GetMimeTypes();
if (rv != NS_OK)
return rv;
if (!mInited) {
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nsnull;
}
NS_ASSERTION(mPluginMimeTypeCount <= mMimeTypeArray.Count(),
"The number of total mimetypes should be equal to or higher "
"than the number of plugin mimetypes.");
*aResult = NS_OK;
nsAutoString type;
for (PRUint32 i = 0; i < mMimeTypeCount; i++) {
for (PRInt32 i = 0; i < mMimeTypeArray.Count(); i++) {
nsIDOMMimeType *mtype = mMimeTypeArray[i];
mtype->GetType(type);
if (type.Equals(aName)) {
*aReturn = mtype;
NS_ADDREF(*aReturn);
return NS_OK;
return mtype;
}
}
@ -166,39 +174,43 @@ nsMimeTypeArray::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
mimeInfo->GetDefaultDescription(defaultDescription);
if (defaultDescription.IsEmpty()) {
// no support; just leave
return NS_OK;
return nsnull;
}
}
}
}
// If we got here, we support this type! Say so.
nsCOMPtr<nsIDOMMimeType> helper = new nsHelperMimeType(aName);
if (!helper) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIDOMMimeType> entry = new nsMimeType(nsnull, helper);
if (!entry) {
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIDOMMimeType> helper, entry;
if (!(helper = new nsHelperMimeType(aName)) ||
!(entry = new nsMimeType(nsnull, helper)) ||
!mMimeTypeArray.AppendObject(entry)) {
*aResult = NS_ERROR_OUT_OF_MEMORY;
return nsnull;
}
entry.swap(*aReturn);
return entry;
}
}
return NS_OK;
return nsnull;
}
NS_IMETHODIMP
nsMimeTypeArray::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
{
nsresult rv;
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
return rv;
}
void nsMimeTypeArray::Clear()
{
if (mMimeTypeArray != nsnull) {
for (PRUint32 i = 0; i < mMimeTypeCount; i++) {
NS_IF_RELEASE(mMimeTypeArray[i]);
}
delete[] mMimeTypeArray;
mMimeTypeArray = nsnull;
}
mMimeTypeCount = 0;
mMimeTypeArray.Clear();
mPluginMimeTypeCount = 0;
}
nsresult nsMimeTypeArray::Refresh()
@ -209,7 +221,7 @@ nsresult nsMimeTypeArray::Refresh()
nsresult nsMimeTypeArray::GetMimeTypes()
{
NS_PRECONDITION(!mMimeTypeArray && mMimeTypeCount==0,
NS_PRECONDITION(!mInited && mPluginMimeTypeCount==0,
"already initialized");
nsIDOMPluginArray* pluginArray = nsnull;
@ -217,7 +229,7 @@ nsresult nsMimeTypeArray::GetMimeTypes()
if (rv == NS_OK) {
// count up all possible MimeTypes, and collect them here. Later,
// we'll remove duplicates.
mMimeTypeCount = 0;
mPluginMimeTypeCount = 0;
PRUint32 pluginCount = 0;
rv = pluginArray->GetLength(&pluginCount);
if (rv == NS_OK) {
@ -228,22 +240,23 @@ nsresult nsMimeTypeArray::GetMimeTypes()
plugin) {
PRUint32 mimeTypeCount = 0;
if (plugin->GetLength(&mimeTypeCount) == NS_OK)
mMimeTypeCount += mimeTypeCount;
mPluginMimeTypeCount += mimeTypeCount;
}
}
// now we know how many there are, start gathering them.
mMimeTypeArray = new nsIDOMMimeType*[mMimeTypeCount];
if (mMimeTypeArray == nsnull)
if (!mMimeTypeArray.SetCapacity(mPluginMimeTypeCount))
return NS_ERROR_OUT_OF_MEMORY;
PRUint32 mimeTypeIndex = 0;
PRUint32 k;
for (k = 0; k < pluginCount; k++) {
nsIDOMPlugin* plugin = nsnull;
if (pluginArray->Item(k, &plugin) == NS_OK) {
PRUint32 mimeTypeCount = 0;
if (plugin->GetLength(&mimeTypeCount) == NS_OK) {
for (PRUint32 j = 0; j < mimeTypeCount; j++)
plugin->Item(j, &mMimeTypeArray[mimeTypeIndex++]);
nsCOMPtr<nsIDOMMimeType> item;
for (PRUint32 j = 0; j < mimeTypeCount; j++) {
plugin->Item(j, getter_AddRefs(item));
mMimeTypeArray.AppendObject(item);
}
}
NS_RELEASE(plugin);
}

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

@ -42,6 +42,7 @@
#include "nsIDOMMimeType.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
class nsIDOMNavigator;
@ -57,6 +58,7 @@ public:
nsresult Refresh();
nsIDOMMimeType* GetItemAt(PRUint32 aIndex, nsresult* aResult);
nsIDOMMimeType* GetNamedItem(const nsAString& aName, nsresult* aResult);
static nsMimeTypeArray* FromSupports(nsISupports* aSupports)
{
@ -81,8 +83,14 @@ private:
protected:
nsIDOMNavigator* mNavigator;
PRUint32 mMimeTypeCount;
nsIDOMMimeType** mMimeTypeArray;
// Number of mimetypes handled by plugins.
PRUint32 mPluginMimeTypeCount;
// mMimeTypeArray contains all mimetypes handled by plugins
// (mPluginMimeTypeCount) and any mimetypes that we handle internally and
// have been looked up before. The number of items in mMimeTypeArray should
// thus always be equal to or higher than mPluginMimeTypeCount.
nsCOMArray<nsIDOMMimeType> mMimeTypeArray;
PRBool mInited;
};
class nsMimeType : public nsIDOMMimeType

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

@ -132,34 +132,41 @@ nsPluginArray::Item(PRUint32 aIndex, nsIDOMPlugin** aReturn)
return rv;
}
NS_IMETHODIMP
nsPluginArray::NamedItem(const nsAString& aName, nsIDOMPlugin** aReturn)
nsIDOMPlugin*
nsPluginArray::GetNamedItem(const nsAString& aName, nsresult* aResult)
{
NS_PRECONDITION(nsnull != aReturn, "null arg");
*aReturn = nsnull;
*aResult = NS_OK;
if (!AllowPlugins())
return NS_OK;
return nsnull;
if (mPluginArray == nsnull) {
nsresult rv = GetPlugins();
if (rv != NS_OK)
return rv;
*aResult = GetPlugins();
if (*aResult != NS_OK)
return nsnull;
}
for (PRUint32 i = 0; i < mPluginCount; i++) {
nsAutoString pluginName;
nsIDOMPlugin* plugin = mPluginArray[i];
if (plugin->GetName(pluginName) == NS_OK) {
if (pluginName.Equals(aName)) {
*aReturn = plugin;
NS_IF_ADDREF(plugin);
break;
}
if (plugin->GetName(pluginName) == NS_OK && pluginName.Equals(aName)) {
return plugin;
}
}
return NS_OK;
return nsnull;
}
NS_IMETHODIMP
nsPluginArray::NamedItem(const nsAString& aName, nsIDOMPlugin** aReturn)
{
NS_PRECONDITION(nsnull != aReturn, "null arg");
nsresult rv;
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
return rv;
}
nsresult
@ -364,29 +371,35 @@ nsPluginElement::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn)
return rv;
}
NS_IMETHODIMP
nsPluginElement::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
nsIDOMMimeType*
nsPluginElement::GetNamedItem(const nsAString& aName, nsresult *aResult)
{
if (mMimeTypeArray == nsnull) {
nsresult rv = GetMimeTypes();
if (rv != NS_OK)
return rv;
*aResult = GetMimeTypes();
if (*aResult != NS_OK)
return nsnull;
}
*aReturn = nsnull;
*aResult = NS_OK;
for (PRUint32 i = 0; i < mMimeTypeCount; i++) {
nsAutoString type;
nsIDOMMimeType* mimeType = mMimeTypeArray[i];
if (mimeType->GetType(type) == NS_OK) {
if (type.Equals(aName)) {
*aReturn = mimeType;
NS_ADDREF(mimeType);
break;
}
if (mimeType->GetType(type) == NS_OK && type.Equals(aName)) {
return mimeType;
}
}
return NS_OK;
return nsnull;
}
NS_IMETHODIMP
nsPluginElement::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn)
{
nsresult rv;
NS_IF_ADDREF(*aReturn = GetNamedItem(aName, &rv));
return rv;
}
nsresult

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

@ -61,6 +61,7 @@ public:
nsresult GetPluginHost(nsIPluginHost** aPluginHost);
nsIDOMPlugin* GetItemAt(PRUint32 aIndex, nsresult* aResult);
nsIDOMPlugin* GetNamedItem(const nsAString& aName, nsresult* aResult);
static nsPluginArray* FromSupports(nsISupports* aSupports)
{
@ -104,6 +105,7 @@ public:
NS_DECL_NSIDOMPLUGIN
nsIDOMMimeType* GetItemAt(PRUint32 aIndex, nsresult* aResult);
nsIDOMMimeType* GetNamedItem(const nsAString& aName, nsresult* aResult);
static nsPluginElement* FromSupports(nsISupports* aSupports)
{

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

@ -606,24 +606,24 @@ nsDOMStorage::Key(PRUint32 aIndex, nsAString& aKey)
return NS_OK;
}
NS_IMETHODIMP
nsDOMStorage::GetItem(const nsAString& aKey, nsIDOMStorageItem **aItem)
nsIDOMStorageItem*
nsDOMStorage::GetNamedItem(const nsAString& aKey, nsresult* aResult)
{
*aItem = nsnull;
if (!CacheStoragePermissions())
return NS_ERROR_DOM_SECURITY_ERR;
if (!CacheStoragePermissions()) {
*aResult = NS_ERROR_DOM_SECURITY_ERR;
return nsnull;
}
*aResult = NS_OK;
if (aKey.IsEmpty())
return NS_OK;
return nsnull;
nsSessionStorageEntry *entry = mItems.GetEntry(aKey);
nsIDOMStorageItem* item = nsnull;
if (entry) {
if (!IsCallerSecure() && entry->mItem->IsSecure()) {
return NS_OK;
if (IsCallerSecure() || !entry->mItem->IsSecure()) {
item = entry->mItem;
}
NS_ADDREF(*aItem = entry->mItem);
}
else if (UseDB()) {
PRBool secure;
@ -632,22 +632,33 @@ nsDOMStorage::GetItem(const nsAString& aKey, nsIDOMStorageItem **aItem)
nsresult rv = GetDBValue(aKey, value, &secure, unused);
// return null if access isn't allowed or the key wasn't found
if (rv == NS_ERROR_DOM_SECURITY_ERR || rv == NS_ERROR_DOM_NOT_FOUND_ERR)
return NS_OK;
NS_ENSURE_SUCCESS(rv, rv);
return nsnull;
*aResult = rv;
NS_ENSURE_SUCCESS(rv, nsnull);
nsRefPtr<nsDOMStorageItem> newitem =
new nsDOMStorageItem(this, aKey, value, secure);
if (!newitem)
return NS_ERROR_OUT_OF_MEMORY;
entry = mItems.PutEntry(aKey);
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
entry->mItem = newitem;
NS_ADDREF(*aItem = newitem);
if (newitem && (entry = mItems.PutEntry(aKey))) {
item = entry->mItem = newitem;
}
else {
*aResult = NS_ERROR_OUT_OF_MEMORY;
}
}
return NS_OK;
return item;
}
NS_IMETHODIMP
nsDOMStorage::GetItem(const nsAString& aKey, nsIDOMStorageItem **aItem)
{
nsresult rv;
NS_ADDREF(*aItem = GetNamedItem(aKey, &rv));
return rv;
}
NS_IMETHODIMP
@ -1041,21 +1052,17 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMStorageList)
NS_IMPL_RELEASE(nsDOMStorageList)
nsresult
nsDOMStorageList::NamedItem(const nsAString& aDomain,
nsIDOMStorage** aStorage)
nsIDOMStorage*
nsDOMStorageList::GetNamedItem(const nsAString& aDomain, nsresult* aResult)
{
*aStorage = nsnull;
nsCAutoString requestedDomain;
nsresult rv;
// Normalize the requested domain
nsCOMPtr<nsIIDNService> idn = do_GetService(NS_IDNSERVICE_CONTRACTID);
if (idn) {
rv = idn->ConvertUTF8toACE(NS_ConvertUTF16toUTF8(aDomain),
requestedDomain);
NS_ENSURE_SUCCESS(rv, rv);
*aResult = idn->ConvertUTF8toACE(NS_ConvertUTF16toUTF8(aDomain),
requestedDomain);
NS_ENSURE_SUCCESS(*aResult, nsnull);
} else {
// Don't have the IDN service, best we can do is URL escape.
NS_EscapeURL(NS_ConvertUTF16toUTF8(aDomain),
@ -1065,42 +1072,51 @@ nsDOMStorageList::NamedItem(const nsAString& aDomain,
ToLowerCase(requestedDomain);
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
if (!ssm)
return NS_ERROR_FAILURE;
if (!ssm) {
*aResult = NS_ERROR_FAILURE;
return nsnull;
}
nsCOMPtr<nsIPrincipal> subjectPrincipal;
rv = ssm->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
NS_ENSURE_SUCCESS(rv, rv);
*aResult = ssm->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
NS_ENSURE_SUCCESS(*aResult, nsnull);
nsCOMPtr<nsIURI> uri;
nsCAutoString currentDomain;
if (subjectPrincipal) {
rv = subjectPrincipal->GetDomain(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
*aResult = subjectPrincipal->GetDomain(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(*aResult, nsnull);
if (!uri) {
rv = subjectPrincipal->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
*aResult = subjectPrincipal->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(*aResult, nsnull);
}
if (uri) {
PRPackedBool sessionOnly;
if (!nsDOMStorage::CanUseStorage(uri, &sessionOnly))
return NS_ERROR_DOM_SECURITY_ERR;
if (!nsDOMStorage::CanUseStorage(uri, &sessionOnly)) {
*aResult = NS_ERROR_DOM_SECURITY_ERR;
return nsnull;
}
nsCOMPtr<nsIURI> innerUri = NS_GetInnermostURI(uri);
if (!innerUri)
return NS_ERROR_UNEXPECTED;
if (!innerUri) {
*aResult = NS_ERROR_UNEXPECTED;
return nsnull;
}
uri = innerUri;
rv = uri->GetAsciiHost(currentDomain);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_SECURITY_ERR);
nsresult rv = uri->GetAsciiHost(currentDomain);
if (NS_FAILED(rv)) {
*aResult = NS_ERROR_DOM_SECURITY_ERR;
return nsnull;
}
}
}
PRBool isSystem;
rv = ssm->SubjectPrincipalIsSystem(&isSystem);
NS_ENSURE_SUCCESS(rv, rv);
*aResult = ssm->SubjectPrincipalIsSystem(&isSystem);
NS_ENSURE_SUCCESS(*aResult, nsnull);
// allow code that has read privileges to get the storage for any domain
if (!isSystem && nsContentUtils::IsCallerTrustedForRead())
@ -1109,10 +1125,20 @@ nsDOMStorageList::NamedItem(const nsAString& aDomain,
if (isSystem || !currentDomain.IsEmpty()) {
return GetStorageForDomain(uri, NS_ConvertUTF8toUTF16(requestedDomain),
NS_ConvertUTF8toUTF16(currentDomain),
isSystem, aStorage);
isSystem, aResult);
}
return NS_ERROR_DOM_SECURITY_ERR;
*aResult = NS_ERROR_DOM_SECURITY_ERR;
return nsnull;
}
NS_IMETHODIMP
nsDOMStorageList::NamedItem(const nsAString& aDomain,
nsIDOMStorage** aStorage)
{
nsresult rv;
NS_IF_ADDREF(*aStorage = GetNamedItem(aDomain, &rv));
return rv;
}
// static
@ -1123,23 +1149,22 @@ nsDOMStorageList::CanAccessDomain(const nsAString& aRequestedDomain,
return aRequestedDomain.Equals(aCurrentDomain);
}
nsresult
nsIDOMStorage*
nsDOMStorageList::GetStorageForDomain(nsIURI* aURI,
const nsAString& aRequestedDomain,
const nsAString& aCurrentDomain,
PRBool aNoCurrentDomainCheck,
nsIDOMStorage** aStorage)
nsresult* aResult)
{
if (!aNoCurrentDomainCheck && !CanAccessDomain(aRequestedDomain,
aCurrentDomain)) {
return NS_ERROR_DOM_SECURITY_ERR;
nsStringArray requestedDomainArray;
if ((!aNoCurrentDomainCheck &&
!CanAccessDomain(aRequestedDomain, aCurrentDomain)) ||
!ConvertDomainToArray(aRequestedDomain, &requestedDomainArray)) {
*aResult = NS_ERROR_DOM_SECURITY_ERR;
return nsnull;
}
nsStringArray requestedDomainArray;
PRBool ok = ConvertDomainToArray(aRequestedDomain, &requestedDomainArray);
if (!ok)
return NS_ERROR_DOM_SECURITY_ERR;
// now rebuild a string for the domain.
nsAutoString usedDomain;
PRInt32 requestedPos = 0;
@ -1150,19 +1175,19 @@ nsDOMStorageList::GetStorageForDomain(nsIURI* aURI,
usedDomain.Append(*requestedDomainArray[requestedPos]);
}
*aResult = NS_OK;
// now have a valid domain, so look it up in the storage table
if (!mStorages.Get(usedDomain, aStorage)) {
nsIDOMStorage* storage = mStorages.GetWeak(usedDomain);
if (!storage) {
nsCOMPtr<nsIDOMStorage> newstorage = new nsDOMStorage(aURI, usedDomain, PR_TRUE);
if (!newstorage)
return NS_ERROR_OUT_OF_MEMORY;
if (!mStorages.Put(usedDomain, newstorage))
return NS_ERROR_OUT_OF_MEMORY;
newstorage.swap(*aStorage);
if (newstorage && mStorages.Put(usedDomain, newstorage))
storage = newstorage;
else
*aResult = NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
return storage;
}
// static

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

@ -167,6 +167,13 @@ public:
// clear all values from the store
void ClearAll();
nsIDOMStorageItem* GetNamedItem(const nsAString& aKey, nsresult* aResult);
static nsDOMStorage* FromSupports(nsISupports* aSupports)
{
return static_cast<nsDOMStorage*>(static_cast<nsIDOMStorage*>(aSupports));
}
protected:
friend class nsDOMStorageManager;
@ -217,6 +224,8 @@ public:
// nsIDOMStorageList
NS_DECL_NSIDOMSTORAGELIST
nsIDOMStorage* GetNamedItem(const nsAString& aDomain, nsresult* aResult);
/**
* Check whether aCurrentDomain has access to aRequestedDomain
*/
@ -236,12 +245,12 @@ protected:
* @param aCurrentDomain domain of current caller
* @param aNoCurrentDomainCheck true to skip domain comparison
*/
nsresult
nsIDOMStorage*
GetStorageForDomain(nsIURI* aURI,
const nsAString& aRequestedDomain,
const nsAString& aCurrentDomain,
PRBool aNoCurrentDomainCheck,
nsIDOMStorage** aStorage);
nsresult* aResult);
/**
* Convert the domain into an array of its component parts.

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

@ -524,17 +524,22 @@ nsTreeColumns::GetColumnFor(nsIDOMElement* aElement, nsITreeColumn** _retval)
return NS_OK;
}
nsITreeColumn*
nsTreeColumns::GetNamedColumn(const nsAString& aId)
{
EnsureColumns();
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->GetId().Equals(aId)) {
return currCol;
}
}
return nsnull;
}
NS_IMETHODIMP
nsTreeColumns::GetNamedColumn(const nsAString& aId, nsITreeColumn** _retval)
{
EnsureColumns();
*_retval = nsnull;
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->GetId().Equals(aId)) {
NS_ADDREF(*_retval = currCol);
break;
}
}
NS_IF_ADDREF(*_retval = GetNamedColumn(aId));
return NS_OK;
}
@ -553,7 +558,6 @@ nsTreeColumns::GetColumnAt(PRInt32 aIndex)
NS_IMETHODIMP
nsTreeColumns::GetColumnAt(PRInt32 aIndex, nsITreeColumn** _retval)
{
EnsureColumns();
NS_IF_ADDREF(*_retval = GetColumnAt(aIndex));
return NS_OK;
}

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

@ -149,6 +149,7 @@ public:
NS_DECL_NSITREECOLUMNS
nsITreeColumn* GetColumnAt(PRInt32 aIndex);
nsITreeColumn* GetNamedColumn(const nsAString& aId);
static nsTreeColumns* FromSupports(nsISupports* aSupports)
{