diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp
index 27805473658..b91a7777ff2 100644
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -89,7 +89,7 @@
#include "nsIDOMNodeList.h"
#include "nsIDOMXULButtonElement.h"
#include "nsIDOMXULCheckboxElement.h"
-#include "nsIDOMXULDocument.h"
+#include "nsIDOMDocument.h"
#include "nsIDOMXULElement.h"
#include "nsIDOMXULLabelElement.h"
#include "nsIDOMXULSelectCntrlEl.h"
diff --git a/accessible/src/base/nsRootAccessible.cpp b/accessible/src/base/nsRootAccessible.cpp
index 34aff08cf77..e505610b9a1 100644
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -926,9 +926,7 @@ NS_IMETHODIMP nsDocAccessibleMixin::GetURL(nsAString& aURL)
NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAString& aTitle)
{
- // This doesn't leak - we don't own the const pointer that's returned
- aTitle = *(mDocument->GetDocumentTitle());
- return NS_OK;
+ return mDocument->GetDocumentTitle(aTitle);
}
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAString& aMimeType)
diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h
index 9883a19e54e..052a866b488 100644
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -41,7 +41,6 @@
#include "nsISupports.h"
#include "nsEvent.h"
#include "nsAString.h"
-#include "nsString.h"
#include "nsChangeHint.h"
#include "nsCOMArray.h"
@@ -78,7 +77,6 @@ class nsIBindingManager;
class nsIObserver;
class nsISupportsArray;
class nsIScriptLoader;
-class nsString;
class nsIContentSink;
class nsIScriptEventManager;
@@ -118,7 +116,7 @@ public:
/**
* Return the title of the document. May return null.
*/
- virtual const nsString* GetDocumentTitle() const = 0;
+ NS_IMETHOD GetDocumentTitle(nsAString& aTitle) const = 0;
/**
* Return the URL for the document. May return null.
@@ -143,7 +141,8 @@ public:
NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup** aGroup) const = 0;
/**
- * Return the base URL for relative URLs in the document. May return null (or the document URL).
+ * Return the base URL for relative URLs in the document. May return
+ * null (or the document URL).
*/
NS_IMETHOD GetBaseURL(nsIURI*& aURL) const = 0;
NS_IMETHOD SetBaseURL(nsIURI* aURL) = 0;
@@ -155,8 +154,9 @@ public:
NS_IMETHOD SetBaseTarget(const nsAString &aBaseTarget)=0;
/**
- * Return a standard name for the document's character set. This will
- * trigger a startDocumentLoad if necessary to answer the question.
+ * Return a standard name for the document's character set. This
+ * will trigger a startDocumentLoad if necessary to answer the
+ * question.
*/
NS_IMETHOD GetDocumentCharacterSet(nsAString& oCharSetID) = 0;
NS_IMETHOD SetDocumentCharacterSet(const nsAString& aCharSetID) = 0;
@@ -188,8 +188,8 @@ public:
*/
NS_IMETHOD GetContentLanguage(nsAString& aContentLanguage) const = 0;
- // The state BidiEnabled should persist across multiple views (screen, print)
- // of the same document.
+ // The state BidiEnabled should persist across multiple views
+ // (screen, print) of the same document.
/**
* Check if the document contains bidi data.
@@ -214,15 +214,15 @@ public:
NS_IMETHOD SetWordBreaker(nsIWordBreaker* aWordBreaker) = 0;
/**
- * Access HTTP header data (this may also get set from other sources, like
- * HTML META tags).
+ * Access HTTP header data (this may also get set from other
+ * sources, like HTML META tags).
*/
NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
/**
- * Create a new presentation shell that will use aContext for
- * it's presentation context (presentation context's must not be
+ * Create a new presentation shell that will use aContext for it's
+ * presentation context (presentation context's must not be
* shared among multiple presentation shell's).
*/
NS_IMETHOD CreateShell(nsIPresContext* aContext,
@@ -431,8 +431,6 @@ public:
PRUint32 aFlags,
nsEventStatus* aEventStatus) = 0;
- NS_IMETHOD_(PRBool) EventCaptureRegistration(PRInt32 aCapturerIncrement) = 0;
-
NS_IMETHOD FlushPendingNotifications(PRBool aFlushReflows=PR_TRUE,
PRBool aUpdateViews=PR_FALSE) = 0;
diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp
index aa420df3b4e..ff7d4da849d 100644
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -510,6 +510,7 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode,
#endif
nsCOMPtr domDoc;
aTrustedNode->GetOwnerDocument(getter_AddRefs(domDoc));
+
if (!domDoc) {
// In theory this should never happen. But since theory and reality are
// different for XUL elements we'll try to get the principal from the
@@ -530,8 +531,7 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode,
return NS_ERROR_UNEXPECTED;
}
- }
- else {
+ } else {
trustedDoc = do_QueryInterface(domDoc);
NS_ASSERTION(trustedDoc, "QI to nsIDocument failed");
}
@@ -560,13 +560,16 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode,
*/
// If they are in the same document then everything is just fine
- if (trustedDoc == unTrustedDoc && trustedDoc)
+ if (trustedDoc == unTrustedDoc && trustedDoc) {
return NS_OK;
+ }
if (!trustedPrincipal) {
trustedDoc->GetPrincipal(getter_AddRefs(trustedPrincipal));
+
if (!trustedPrincipal) {
- // If the trusted node doesn't have a principal we can't check security against it
+ // If the trusted node doesn't have a principal we can't check
+ // security against it
return NS_ERROR_DOM_SECURITY_ERR;
}
diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp
index 51049b6c8c4..7f8f687a804 100644
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -20,9 +20,10 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
- * L. David Baron
- * Pierre Phaneuf
- * Pete Collins
+ * Johnny Stenback
+ * L. David Baron
+ * Pierre Phaneuf
+ * Pete Collins
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -40,26 +41,11 @@
* ***** END LICENSE BLOCK ***** */
#include "plstr.h"
-#include "nsCOMPtr.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsDocument.h"
#include "nsIArena.h"
-#include "nsIURL.h"
-#include "nsILoadGroup.h"
-#include "nsIChannel.h"
-#include "nsString.h"
#include "nsUnicharUtils.h"
-#include "nsIContent.h"
-#include "nsIStyleSet.h"
-#include "nsIStyleSheet.h"
-#include "nsIPresShell.h"
-#include "nsIPresContext.h"
-#include "nsIDocumentObserver.h"
-#include "nsIEventListenerManager.h"
-#include "nsIScriptGlobalObject.h"
-#include "nsIScriptEventListener.h"
-#include "nsIDOMEvent.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIEventStateManager.h"
#include "nsContentList.h"
@@ -68,46 +54,31 @@
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
-#include "nsIDOMEventListener.h"
#include "nsGUIEvent.h"
#include "nsIDOMStyleSheet.h"
#include "nsDOMAttribute.h"
-#include "nsDOMCID.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOMDocumentXBL.h"
-#include "nsIDOMNavigator.h"
#include "nsGenericElement.h"
#include "nsIDOMEventGroup.h"
-#include "nsICSSStyleSheet.h"
-
-#include "nsITextContent.h"
-#include "nsIDocumentEncoder.h"
-#include "nsIHTMLContentSink.h"
-#include "nsIParser.h"
-#include "nsParserCIID.h"
-#include "nsIFileStreams.h"
-
#include "nsRange.h"
#include "nsIDOMText.h"
#include "nsIDOMComment.h"
#include "nsDOMDocumentType.h"
#include "nsTreeWalker.h"
-#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
-#include "nsLayoutAtoms.h"
#include "nsContentCID.h"
-#include "nsLayoutCID.h"
-#include "nsIDOMRange.h"
-#include "nsIEnumerator.h"
#include "nsDOMError.h"
#include "nsIScrollableView.h"
-#include "nsIFrame.h"
+#include "nsIPresShell.h"
+#include "nsIPresContext.h"
+#include "nsIStyleSet.h"
#include "nsContentUtils.h"
#include "nsNodeInfoManager.h"
#include "nsIXBLService.h"
@@ -134,29 +105,50 @@
#include "nsBidiUtils.h"
-static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID);
#include "nsILineBreakerFactory.h"
#include "nsIWordBreakerFactory.h"
#include "nsLWBrkCIID.h"
-#include "nsIHTMLDocument.h"
#include "nsHTMLAtoms.h"
-#include "nsIHttpChannel.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsScriptEventManager.h"
#include "nsIXPathEvaluatorInternal.h"
+// Helper structs for the content->subdoc map
+
+class SubDocMapEntry : public PLDHashEntryHdr
+{
+public:
+ // Both of these are strong references
+ nsIContent *mKey; // must be first, to look like PLDHashEntryStub
+ nsIDocument *mSubDocument;
+};
+
+struct FindContentData
+{
+ FindContentData(nsIDocument *aSubDoc)
+ : mSubDocument(aSubDoc), mResult(nsnull)
+ {
+ }
+
+ nsISupports *mSubDocument;
+ nsIContent *mResult;
+};
+
+
/**
* A struct that holds all the information about a radio group.
*/
struct nsRadioGroupStruct
{
- /** A strong pointer to the currently selected radio button. */
+ /**
+ * A strong pointer to the currently selected radio button.
+ */
nsCOMPtr mSelectedRadioButton;
nsSmallVoidArray mRadioButtons;
};
@@ -173,10 +165,9 @@ nsDOMStyleSheetList::nsDOMStyleSheetList(nsIDocument *aDocument)
nsDOMStyleSheetList::~nsDOMStyleSheetList()
{
- if (nsnull != mDocument) {
+ if (mDocument) {
mDocument->RemoveObserver(this);
}
- mDocument = nsnull;
}
@@ -194,16 +185,16 @@ NS_IMPL_ADDREF(nsDOMStyleSheetList)
NS_IMPL_RELEASE(nsDOMStyleSheetList)
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDOMStyleSheetList::GetLength(PRUint32* aLength)
{
if (mDocument) {
- // XXX Find the number and then cache it. We'll use the
+ // XXX Find the number and then cache it. We'll use the
// observer notification to figure out if new ones have
// been added or removed.
if (-1 == mLength) {
mDocument->GetNumberOfStyleSheets(PR_FALSE, &mLength);
-
+
#ifdef DEBUG
PRInt32 i;
for (i = 0; i < mLength; i++) {
@@ -219,11 +210,11 @@ nsDOMStyleSheetList::GetLength(PRUint32* aLength)
else {
*aLength = 0;
}
-
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDOMStyleSheetList::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
{
*aReturn = nsnull;
@@ -241,7 +232,7 @@ nsDOMStyleSheetList::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDOMStyleSheetList::StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet)
{
@@ -251,11 +242,11 @@ nsDOMStyleSheetList::StyleSheetAdded(nsIDocument *aDocument,
mLength++;
}
}
-
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDOMStyleSheetList::StyleSheetRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet)
{
@@ -265,7 +256,7 @@ nsDOMStyleSheetList::StyleSheetRemoved(nsIDocument *aDocument,
mLength--;
}
}
- return NS_OK;
+ return NS_OK;
}
NS_IMETHODIMP
@@ -275,14 +266,10 @@ nsDOMStyleSheetList::DocumentWillBeDestroyed(nsIDocument *aDocument)
aDocument->RemoveObserver(this);
mDocument = nsnull;
}
-
+
return NS_OK;
}
-// ==================================================================
-// =
-// ==================================================================
-
class nsDOMImplementation : public nsIDOMDOMImplementation,
public nsIPrivateDOMImplementation
{
@@ -291,22 +278,11 @@ public:
virtual ~nsDOMImplementation();
NS_DECL_ISUPPORTS
-
+
// nsIDOMDOMImplementation
- NS_IMETHOD HasFeature(const nsAString& aFeature,
- const nsAString& aVersion,
- PRBool* aReturn);
- NS_IMETHOD CreateDocumentType(const nsAString& aQualifiedName,
- const nsAString& aPublicId,
- const nsAString& aSystemId,
- nsIDOMDocumentType** aReturn);
+ NS_DECL_NSIDOMDOMIMPLEMENTATION
- NS_IMETHOD CreateDocument(const nsAString& aNamespaceURI,
- const nsAString& aQualifiedName,
- nsIDOMDocumentType* aDoctype,
- nsIDOMDocument** aReturn);
-
- //nsIPrivateDOMImplementation
+ // nsIPrivateDOMImplementation
NS_IMETHOD Init(nsIURI* aBaseURI);
protected:
@@ -317,12 +293,14 @@ protected:
nsresult
NS_NewDOMImplementation(nsIDOMDOMImplementation** aInstancePtrResult)
{
- nsDOMImplementation* domImpl = new nsDOMImplementation();
- if (!domImpl) {
+ *aInstancePtrResult = new nsDOMImplementation();
+ if (!*aInstancePtrResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
- return CallQueryInterface(domImpl, aInstancePtrResult);
+ NS_ADDREF(*aInstancePtrResult);
+
+ return NS_OK;
}
nsDOMImplementation::nsDOMImplementation(nsIURI* aBaseURI)
@@ -347,9 +325,9 @@ NS_IMPL_ADDREF(nsDOMImplementation);
NS_IMPL_RELEASE(nsDOMImplementation);
-NS_IMETHODIMP
-nsDOMImplementation::HasFeature(const nsAString& aFeature,
- const nsAString& aVersion,
+NS_IMETHODIMP
+nsDOMImplementation::HasFeature(const nsAString& aFeature,
+ const nsAString& aVersion,
PRBool* aReturn)
{
return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn);
@@ -357,8 +335,8 @@ nsDOMImplementation::HasFeature(const nsAString& aFeature,
NS_IMETHODIMP
nsDOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
- const nsAString& aPublicId,
- const nsAString& aSystemId,
+ const nsAString& aPublicId,
+ const nsAString& aSystemId,
nsIDOMDocumentType** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
@@ -368,15 +346,15 @@ nsDOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
}
NS_IMETHODIMP
-nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
- const nsAString& aQualifiedName,
- nsIDOMDocumentType* aDoctype,
+nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
+ const nsAString& aQualifiedName,
+ nsIDOMDocumentType* aDoctype,
nsIDOMDocument** aReturn)
-{
+{
NS_ENSURE_ARG_POINTER(aReturn);
-
+
*aReturn = nsnull;
-
+
if (aDoctype) {
nsCOMPtr owner;
aDoctype->GetOwnerDocument(getter_AddRefs(owner));
@@ -387,6 +365,7 @@ nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
nsresult rv = NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName,
aDoctype, mBaseURI);
+
nsCOMPtr docShell;
nsContentUtils::GetDocShellFromCaller(getter_AddRefs(docShell));
if (docShell) {
@@ -433,36 +412,34 @@ nsDocumentChildNodes::~nsDocumentChildNodes()
NS_IMETHODIMP
nsDocumentChildNodes::GetLength(PRUint32* aLength)
{
- if (nsnull != mDocument) {
- PRInt32 count;
+ PRInt32 count = 0;
+
+ if (mDocument) {
mDocument->GetChildCount(count);
- *aLength = (PRUint32)count;
}
- else {
- *aLength = 0;
- }
-
+
+ *aLength = (PRUint32)count;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocumentChildNodes::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
*aReturn = nsnull;
- nsresult result = NS_OK;
if (mDocument) {
nsCOMPtr content;
- result = mDocument->ChildAt(aIndex, *getter_AddRefs(content));
- if (NS_SUCCEEDED(result) && content) {
- result = CallQueryInterface(content, aReturn);
+ mDocument->ChildAt(aIndex, *getter_AddRefs(content));
+ if (content) {
+ return CallQueryInterface(content, aReturn);
}
}
- return result;
+ return NS_OK;
}
-void
+void
nsDocumentChildNodes::DropReference()
{
mDocument = nsnull;
@@ -472,8 +449,8 @@ class nsXPathDocumentTearoff : public nsIDOMXPathEvaluator
{
public:
nsXPathDocumentTearoff(nsIDOMXPathEvaluator* aEvaluator,
- nsIDocument* aDocument) : mEvaluator(aEvaluator),
- mDocument(aDocument)
+ nsIDocument* aDocument)
+ : mEvaluator(aEvaluator), mDocument(aDocument)
{
}
virtual ~nsXPathDocumentTearoff()
@@ -492,6 +469,7 @@ private:
NS_INTERFACE_MAP_BEGIN(nsXPathDocumentTearoff)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator)
NS_INTERFACE_MAP_END_AGGREGATED(mDocument)
+
NS_IMPL_ADDREF_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument)
NS_IMPL_RELEASE_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument)
@@ -500,38 +478,31 @@ NS_IMPL_RELEASE_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument)
// =
// ==================================================================
-nsDocument::nsDocument() : mSubDocuments(nsnull),
- mIsGoingAway(PR_FALSE),
- mCSSLoader(nsnull),
- mXPathDocument(nsnull)
+ // NOTE! nsDocument::operator new() zeroes out all members, so don't
+ // bother initializing members to 0.
+
+nsDocument::nsDocument()
+ : mCharacterSet(NS_LITERAL_STRING("ISO-8859-1")),
+ mNextContentID(NS_CONTENT_ID_COUNTER_BASE)
{
- mArena = nsnull;
- mDocumentURL = nsnull;
- mCharacterSet.Assign(NS_LITERAL_STRING("ISO-8859-1"));
- mParentDocument = nsnull;
- mRootContent = nsnull;
- mListenerManager = nsnull;
- mInDestructor = PR_FALSE;
- mHeaderData = nsnull;
- mChildNodes = nsnull;
- mNextContentID = NS_CONTENT_ID_COUNTER_BASE;
- mBoxObjectTable = nsnull;
- mNumCapturers = 0;
- mBidiEnabled = PR_FALSE;
+ // NOTE! nsDocument::operator new() zeroes out all members, so don't
+ // bother initializing members to 0.
// Force initialization.
mBindingManager = do_CreateInstance("@mozilla.org/xbl/binding-manager;1");
- nsCOMPtr observer(do_QueryInterface(mBindingManager));
- if (observer) // We must always be the first observer of the document.
- mObservers.InsertElementAt(observer, 0);
-}
+ nsCOMPtr observer(do_QueryInterface(mBindingManager));
+ if (observer) {
+ // The binding manager must always be the first observer of the
+ // document.
+
+ mObservers.InsertElementAt(observer, 0);
+ }
+}
nsDocument::~nsDocument()
{
- delete mXPathDocument;
-
mInDestructor = PR_TRUE;
// XXX Inform any remaining observers that we are going away.
@@ -544,13 +515,12 @@ nsDocument::~nsDocument()
PRInt32 indx;
for (indx = mObservers.Count() - 1; indx >= 0; --indx) {
// XXX Should this be a kungfudeathgrip?!!!!
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx);
+ nsIDocumentObserver* observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(indx));
+
observer->DocumentWillBeDestroyed(this);
}
- mLoadFlags = nsIRequest::LOAD_NORMAL; // XXX maybe not required
- mDocumentLoadGroup = nsnull;
-
mParentDocument = nsnull;
// Kill the subdocument map, doing this will release its strong
@@ -586,38 +556,29 @@ nsDocument::~nsDocument()
mStyleSheets[indx]->SetOwningDocument(nsnull);
}
- if (nsnull != mChildNodes) {
+ if (mChildNodes) {
mChildNodes->DropReference();
- NS_RELEASE(mChildNodes);
}
- NS_IF_RELEASE(mArena);
-
- if (mListenerManager != nsnull) {
+ if (mListenerManager) {
mListenerManager->SetListenerTarget(nsnull);
- NS_RELEASE(mListenerManager);
}
if (mScriptLoader) {
mScriptLoader->DropDocumentReference();
}
- mDOMStyleSheets = nsnull; // Release the stylesheets list.
-
- if (nsnull != mHeaderData) {
- delete mHeaderData;
- mHeaderData = nsnull;
+ if (mCSSLoader) {
+ mCSSLoader->DropDocumentReference();
}
- delete mBoxObjectTable;
-
if (mNodeInfoManager) {
mNodeInfoManager->DropDocumentReference();
}
- // Do this after notifying the nodeinfo manager that we're going away since
- // it will save our url before dropping the reference.
- NS_IF_RELEASE(mDocumentURL);
+ delete mHeaderData;
+ delete mBoxObjectTable;
+ delete mXPathDocument;
}
PRBool gCheckedForXPathDOM = PR_FALSE;
@@ -661,7 +622,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocument)
if (internal) {
internal->SetDocument(this);
}
-
+
mXPathDocument = new nsXPathDocumentTearoff(evaluator, this);
NS_ENSURE_TRUE(mXPathDocument, NS_ERROR_OUT_OF_MEMORY);
}
@@ -673,15 +634,14 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDocument)
NS_IMPL_RELEASE(nsDocument)
-nsresult nsDocument::Init()
+nsresult
+nsDocument::Init()
{
if (mArena) {
return NS_ERROR_ALREADY_INITIALIZED;
}
- nsresult rv;
-
- rv = NS_NewHeapArena(&mArena, nsnull);
+ nsresult rv = NS_NewHeapArena(getter_AddRefs(mArena), nsnull);
NS_ENSURE_SUCCESS(rv, rv);
mNodeInfoManager = new nsNodeInfoManager();
@@ -695,37 +655,35 @@ nsresult nsDocument::Init()
NS_IMETHODIMP
nsDocument::GetArena(nsIArena** aArena)
{
- NS_IF_ADDREF(*aArena = mArena);
+ *aArena = mArena;
+ NS_IF_ADDREF(*aArena);
+
return NS_OK;
}
NS_IMETHODIMP
nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
{
- nsresult rv = NS_OK;
-
nsCOMPtr uri;
if (aChannel) {
-
aChannel->GetOriginalURI(getter_AddRefs(uri));
PRBool isChrome = PR_FALSE;
PRBool isRes = PR_FALSE;
- (void)uri->SchemeIs("chrome", &isChrome);
- (void)uri->SchemeIs("resource", &isRes);
+ uri->SchemeIs("chrome", &isChrome);
+ uri->SchemeIs("resource", &isRes);
if (!isChrome && !isRes)
aChannel->GetURI(getter_AddRefs(uri));
}
- rv = ResetToURI(uri, aLoadGroup);
+ nsresult rv = ResetToURI(uri, aLoadGroup);
if (aChannel) {
nsCOMPtr owner;
aChannel->GetOwner(getter_AddRefs(owner));
- if (owner)
- mPrincipal = do_QueryInterface(owner);
- aChannel->GetLoadFlags(&mLoadFlags);
+
+ mPrincipal = do_QueryInterface(owner);
}
return rv;
@@ -736,9 +694,7 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
{
mDocumentTitle.Truncate();
- NS_IF_RELEASE(mDocumentURL);
mPrincipal = nsnull;
- mLoadFlags = nsIRequest::LOAD_NORMAL;
mDocumentLoadGroup = nsnull;
// Delete references to sub-documents and kill the subdocument map,
@@ -771,18 +727,20 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
if (applicable) {
RemoveStyleSheetFromStyleSets(sheet);
}
-
+
// XXX Tell observers?
}
+
// Release all the sheets
mStyleSheets.Clear();
- NS_IF_RELEASE(mListenerManager);
+ // Release the listener manager
+ mListenerManager = nsnull;
- mDOMStyleSheets = nsnull; // Release the stylesheets list.
+ // Release the stylesheets list.
+ mDOMStyleSheets = nsnull;
mDocumentURL = aURI;
- NS_IF_ADDREF(mDocumentURL);
mDocumentBaseURL = mDocumentURL;
if (aLoadGroup) {
@@ -795,28 +753,25 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::SetDocumentURL(nsIURI* aURI)
{
- NS_IF_RELEASE(mDocumentURL);
mDocumentURL = aURI;
- NS_IF_ADDREF(mDocumentURL);
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::StartDocumentLoad(const char* aCommand,
- nsIChannel* aChannel,
+nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
nsIStreamListener **aDocListener,
- PRBool aReset,
- nsIContentSink* aSink)
+ PRBool aReset, nsIContentSink* aSink)
{
nsresult rv = NS_OK;
- if (aReset)
+ if (aReset) {
rv = Reset(aChannel, aLoadGroup);
+ }
nsCAutoString contentType;
if (NS_SUCCEEDED(aChannel->GetContentType(contentType))) {
@@ -828,24 +783,35 @@ nsDocument::StartDocumentLoad(const char* aCommand,
FindCharInReadable(';', semicolon, end);
CopyASCIItoUCS2(Substring(start, semicolon), mContentType);
}
-
+
PRBool have_contentLanguage = PR_FALSE;
nsCOMPtr httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
nsCAutoString contentLanguage;
- if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Language"),
- contentLanguage))) {
- CopyASCIItoUCS2(contentLanguage, mContentLanguage); // XXX what's wrong w/ ASCII?
+ rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Language"),
+ contentLanguage);
+
+ if (NS_SUCCEEDED(rv)) {
+ // XXX what's wrong w/ ASCII?
+ CopyASCIItoUCS2(contentLanguage, mContentLanguage);
+
have_contentLanguage = PR_TRUE;
}
}
+
if (!have_contentLanguage) {
- nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
+ nsCOMPtr prefBranch =
+ do_GetService(NS_PREFSERVICE_CONTRACTID);
+
if (prefBranch) {
nsXPIDLCString prefLanguage;
- if (NS_SUCCEEDED(prefBranch->GetCharPref("intl.accept_languages",
- getter_Copies(prefLanguage)))) {
+
+ rv = prefBranch->GetCharPref("intl.accept_languages",
+ getter_Copies(prefLanguage));
+
+ if (NS_SUCCEEDED(rv)) {
mContentLanguage.AssignWithConversion(prefLanguage);
+
have_contentLanguage = PR_TRUE;
}
}
@@ -854,44 +820,52 @@ nsDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::StopDocumentLoad()
{
return NS_OK;
}
-const nsString* nsDocument::GetDocumentTitle() const
+NS_IMETHODIMP
+nsDocument::GetDocumentTitle(nsAString& aTitle) const
{
- return &mDocumentTitle;
+ aTitle = mDocumentTitle;
+
+ return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetDocumentURL(nsIURI** aURI) const
{
- NS_IF_ADDREF(*aURI = mDocumentURL);
+ *aURI = mDocumentURL;
+ NS_IF_ADDREF(*aURI);
+
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
{
+ *aPrincipal = nsnull;
+
if (!mPrincipal) {
nsresult rv;
- nsCOMPtr securityManager =
+ nsCOMPtr securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv))
return rv;
NS_WARN_IF_FALSE(mDocumentURL, "no URL!");
- if (NS_FAILED(rv = securityManager->GetCodebasePrincipal(mDocumentURL,
- getter_AddRefs(mPrincipal))))
- return rv;
+ rv = securityManager->GetCodebasePrincipal(mDocumentURL,
+ getter_AddRefs(mPrincipal));
+
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
}
- if(aPrincipal)
- {
- *aPrincipal = mPrincipal;
- NS_ADDREF(*aPrincipal);
- }
+ *aPrincipal = mPrincipal;
+ NS_ADDREF(*aPrincipal);
+
return NS_OK;
}
@@ -912,19 +886,21 @@ nsDocument::AddPrincipal(nsIPrincipal *aNewPrincipal)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetContentType(nsAString& aContentType)
{
aContentType = mContentType;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::SetContentType(const nsAString& aContentType)
{
NS_ASSERTION(mContentType.IsEmpty() || mContentType.Equals(aContentType),
"Do you really want to change the content-type?");
mContentType = aContentType;
+
return NS_OK;
}
@@ -932,6 +908,7 @@ NS_IMETHODIMP
nsDocument::GetContentLanguage(nsAString& aContentLanguage) const
{
aContentLanguage = mContentLanguage;
+
return NS_OK;
}
@@ -942,14 +919,21 @@ nsDocument::GetDocumentLoadGroup(nsILoadGroup **aGroup) const
*aGroup = group;
NS_IF_ADDREF(*aGroup);
+
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetBaseURL(nsIURI*& aURL) const
{
- aURL = mDocumentBaseURL.get();
+ aURL = mDocumentBaseURL;
+
+ if (!aURL) {
+ aURL = mDocumentURL;
+ }
+
NS_IF_ADDREF(aURL);
+
return NS_OK;
}
@@ -957,18 +941,19 @@ NS_IMETHODIMP
nsDocument::SetBaseURL(nsIURI* aURL)
{
nsresult rv = NS_OK;
+
if (aURL) {
- nsCOMPtr securityManager =
+ nsCOMPtr securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
- rv = securityManager->CheckLoadURI(mDocumentURL, aURL, nsIScriptSecurityManager::STANDARD);
+ rv = securityManager->CheckLoadURI(mDocumentURL, aURL,
+ nsIScriptSecurityManager::STANDARD);
if (NS_SUCCEEDED(rv)) {
mDocumentBaseURL = aURL;
}
}
- }
- else {
- mDocumentBaseURL = aURL;
+ } else {
+ mDocumentBaseURL = nsnull;
}
return rv;
@@ -978,6 +963,7 @@ NS_IMETHODIMP
nsDocument::GetBaseTarget(nsAString &aBaseTarget)
{
aBaseTarget.Truncate();
+
return NS_OK;
}
@@ -987,93 +973,123 @@ nsDocument::SetBaseTarget(const nsAString &aBaseTarget)
return NS_OK;
}
-NS_IMETHODIMP nsDocument::GetDocumentCharacterSet(nsAString& oCharSetID)
+NS_IMETHODIMP
+nsDocument::GetDocumentCharacterSet(nsAString& aCharSetID)
{
- oCharSetID = mCharacterSet;
+ aCharSetID = mCharacterSet;
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::SetDocumentCharacterSet(const nsAString& aCharSetID)
+NS_IMETHODIMP
+nsDocument::SetDocumentCharacterSet(const nsAString& aCharSetID)
{
if (!mCharacterSet.Equals(aCharSetID)) {
mCharacterSet = aCharSetID;
+
PRInt32 n = mCharSetObservers.Count();
+
for (PRInt32 i = 0; i < n; i++) {
- nsIObserver* observer = (nsIObserver*) mCharSetObservers.ElementAt(i);
- observer->Observe((nsIDocument*) this, "charset", PromiseFlatString(aCharSetID).get());
+ nsIObserver* observer =
+ NS_STATIC_CAST(nsIObserver *, mCharSetObservers.ElementAt(i));
+
+ observer->Observe(NS_STATIC_CAST(nsIDocument *, this), "charset",
+ PromiseFlatString(aCharSetID).get());
}
}
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::GetDocumentCharacterSetSource(PRInt32* aCharsetSource)
+NS_IMETHODIMP
+nsDocument::GetDocumentCharacterSetSource(PRInt32* aCharsetSource)
{
*aCharsetSource = mCharacterSetSource;
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::SetDocumentCharacterSetSource(PRInt32 aCharsetSource)
+
+NS_IMETHODIMP
+nsDocument::SetDocumentCharacterSetSource(PRInt32 aCharsetSource)
{
mCharacterSetSource = aCharsetSource;
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::AddCharSetObserver(nsIObserver* aObserver)
+NS_IMETHODIMP
+nsDocument::AddCharSetObserver(nsIObserver* aObserver)
{
NS_ENSURE_ARG_POINTER(aObserver);
+
NS_ENSURE_TRUE(mCharSetObservers.AppendElement(aObserver), NS_ERROR_FAILURE);
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::RemoveCharSetObserver(nsIObserver* aObserver)
+NS_IMETHODIMP
+nsDocument::RemoveCharSetObserver(nsIObserver* aObserver)
{
NS_ENSURE_ARG_POINTER(aObserver);
+
NS_ENSURE_TRUE(mCharSetObservers.RemoveElement(aObserver), NS_ERROR_FAILURE);
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::GetLineBreaker(nsILineBreaker** aResult)
+NS_IMETHODIMP
+nsDocument::GetLineBreaker(nsILineBreaker** aResult)
{
if (!mLineBreaker) {
// no line breaker, find a default one
- nsresult result;
- nsCOMPtr lbf(do_GetService(NS_LWBRK_CONTRACTID, &result));
+ nsresult rv;
+ nsCOMPtr lbf =
+ do_GetService(NS_LWBRK_CONTRACTID, &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
- if (NS_SUCCEEDED(result)) {
- nsAutoString lbarg;
- lbf->GetBreaker(lbarg, getter_AddRefs(mLineBreaker));
- }
+ lbf->GetBreaker(nsString(), getter_AddRefs(mLineBreaker));
+ NS_ENSURE_TRUE(mLineBreaker, NS_ERROR_UNEXPECTED);
}
- *aResult = mLineBreaker;
- NS_IF_ADDREF(*aResult);
- return NS_OK; // XXX we should do error handling here
-}
-NS_IMETHODIMP nsDocument::SetLineBreaker(nsILineBreaker* aLineBreaker)
-{
- mLineBreaker = aLineBreaker;
+ *aResult = mLineBreaker;
+ NS_ADDREF(*aResult);
+
return NS_OK;
}
-NS_IMETHODIMP nsDocument::GetWordBreaker(nsIWordBreaker** aResult)
+NS_IMETHODIMP
+nsDocument::SetLineBreaker(nsILineBreaker* aLineBreaker)
+{
+ mLineBreaker = aLineBreaker;
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsDocument::GetWordBreaker(nsIWordBreaker** aResult)
{
if (!mWordBreaker) {
// no word breaker, find a default one
- nsresult result;
- nsCOMPtr wbf(do_GetService(NS_LWBRK_CONTRACTID, &result));
+ nsresult rv;
+ nsCOMPtr wbf =
+ do_GetService(NS_LWBRK_CONTRACTID, &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
- if (NS_SUCCEEDED(result)) {
- nsAutoString wbarg;
- wbf->GetBreaker(wbarg, getter_AddRefs(mWordBreaker));
- }
+ wbf->GetBreaker(nsString(), getter_AddRefs(mWordBreaker));
+ NS_ENSURE_TRUE(wbf, NS_ERROR_UNEXPECTED);
}
+
*aResult = mWordBreaker;
- NS_IF_ADDREF(*aResult);
- return NS_OK; // XXX we should do error handling here
+ NS_ADDREF(*aResult);
+
+ return NS_OK;
}
-NS_IMETHODIMP nsDocument::SetWordBreaker(nsIWordBreaker* aWordBreaker)
+NS_IMETHODIMP
+nsDocument::SetWordBreaker(nsIWordBreaker* aWordBreaker)
{
mWordBreaker = aWordBreaker;
+
return NS_OK;
}
@@ -1082,123 +1098,127 @@ nsDocument::GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const
{
aData.Truncate();
const nsDocHeaderData* data = mHeaderData;
- while (nsnull != data) {
+ while (data) {
if (data->mField == aHeaderField) {
aData = data->mData;
+
break;
}
data = data->mNext;
}
+
return NS_OK;
}
NS_IMETHODIMP
nsDocument::SetHeaderData(nsIAtom* aHeaderField, const nsAString& aData)
{
- if (nsnull != aHeaderField) {
- if (nsnull == mHeaderData) {
- if (!aData.IsEmpty()) { // don't bother storing empty string
- mHeaderData = new nsDocHeaderData(aHeaderField, aData);
- }
- }
- else {
- nsDocHeaderData* data = mHeaderData;
- nsDocHeaderData** lastPtr = &mHeaderData;
- PRBool found = PR_FALSE;
- do { // look for existing and replace
- if (data->mField == aHeaderField) {
- if (!aData.IsEmpty()) {
- data->mData.Assign(aData);
- }
- else { // don't store empty string
- *lastPtr = data->mNext;
- data->mNext = nsnull;
- delete data;
- }
- found = PR_TRUE;
- break;
- }
- lastPtr = &(data->mNext);
- data = *lastPtr;
- } while (data);
+ NS_ENSURE_ARG_POINTER(aHeaderField);
- if (!aData.IsEmpty() && !found) {
- // didn't find, append
- *lastPtr = new nsDocHeaderData(aHeaderField, aData);
- }
+ if (!mHeaderData) {
+ if (!aData.IsEmpty()) { // don't bother storing empty string
+ mHeaderData = new nsDocHeaderData(aHeaderField, aData);
}
- if (aHeaderField == nsHTMLAtoms::headerDefaultStyle) {
- // switch alternate style sheets based on default
- nsAutoString type;
- nsAutoString title;
- PRInt32 index;
-
- mCSSLoader->SetPreferredSheet(aData);
-
- PRInt32 count = mStyleSheets.Count();
- for (index = 0; index < count; index++) {
- nsIStyleSheet* sheet = mStyleSheets[index];
- sheet->GetType(type);
- if (!type.Equals(NS_LITERAL_STRING("text/html"))) {
- sheet->GetTitle(title);
- if (!title.IsEmpty()) { // if sheet has title
- PRBool enabled = (!aData.IsEmpty() &&
- title.Equals(aData,
- nsCaseInsensitiveStringComparator()));
- sheet->SetEnabled(enabled);
- }
- }
- }
- }
- return NS_OK;
}
- return NS_ERROR_NULL_POINTER;
+ else {
+ nsDocHeaderData* data = mHeaderData;
+ nsDocHeaderData** lastPtr = &mHeaderData;
+ PRBool found = PR_FALSE;
+ do { // look for existing and replace
+ if (data->mField == aHeaderField) {
+ if (!aData.IsEmpty()) {
+ data->mData.Assign(aData);
+ }
+ else { // don't store empty string
+ *lastPtr = data->mNext;
+ data->mNext = nsnull;
+ delete data;
+ }
+ found = PR_TRUE;
+
+ break;
+ }
+ lastPtr = &(data->mNext);
+ data = *lastPtr;
+ } while (data);
+
+ if (!aData.IsEmpty() && !found) {
+ // didn't find, append
+ *lastPtr = new nsDocHeaderData(aHeaderField, aData);
+ }
+ }
+
+ if (aHeaderField == nsHTMLAtoms::headerDefaultStyle) {
+ // switch alternate style sheets based on default
+ nsAutoString type;
+ nsAutoString title;
+ PRInt32 index;
+
+ mCSSLoader->SetPreferredSheet(aData);
+
+ PRInt32 count = mStyleSheets.Count();
+ for (index = 0; index < count; index++) {
+ nsIStyleSheet* sheet = mStyleSheets[index];
+ sheet->GetType(type);
+ if (!type.Equals(NS_LITERAL_STRING("text/html"))) {
+ sheet->GetTitle(title);
+ if (!title.IsEmpty()) { // if sheet has title
+ PRBool enabled =
+ (!aData.IsEmpty() &&
+ title.Equals(aData, nsCaseInsensitiveStringComparator()));
+
+ sheet->SetEnabled(enabled);
+ }
+ }
+ }
+ }
+
+ return NS_OK;
}
-#if 0
-// XXX Temp hack: moved to nsMarkupDocument
NS_IMETHODIMP
-nsDocument::CreateShell(nsIPresContext* aContext,
- nsIViewManager* aViewManager,
+nsDocument::CreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager,
nsIStyleSet* aStyleSet,
nsIPresShell** aInstancePtrResult)
{
- NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
- if (nsnull == aInstancePtrResult) {
- return NS_ERROR_NULL_POINTER;
- }
+ // Don't add anything here. Add it to |doCreateShell| instead.
+ // This exists so that subclasses can pass other values for the 4th
+ // parameter some of the time.
+ return doCreateShell(aContext, aViewManager, aStyleSet,
+ eCompatibility_FullStandards, aInstancePtrResult);
+}
- nsresult rv;
- nsCOMPtr shell(do_CreateInstance(kPresShellCID,&rv));
+nsresult
+nsDocument::doCreateShell(nsIPresContext* aContext,
+ nsIViewManager* aViewManager, nsIStyleSet* aStyleSet,
+ nsCompatibility aCompatMode,
+ nsIPresShell** aInstancePtrResult)
+{
+ nsCOMPtr shell;
+ nsresult rv = NS_NewPresShell(getter_AddRefs(shell));
if (NS_FAILED(rv)) {
return rv;
}
- rv = shell->Init(this, aContext, aViewManager, aStyleSet);
- if (NS_FAILED(rv)) {
- return rv;
- }
+ rv = shell->Init(this, aContext, aViewManager, aStyleSet, aCompatMode);
+ NS_ENSURE_SUCCESS(rv, rv);
// Note: we don't hold a ref to the shell (it holds a ref to us)
mPresShells.AppendElement(shell);
*aInstancePtrResult = shell.get();
NS_ADDREF(*aInstancePtrResult);
- // tell the context the mode we want (always standard, which
- // should be correct for everything except HTML)
- // nsHTMLDocument overrides this method and sets it differently
- aContext->SetCompatibilityMode(eCompatibility_Standard);
-
return NS_OK;
}
-#endif
-PRBool nsDocument::DeleteShell(nsIPresShell* aShell)
+PRBool
+nsDocument::DeleteShell(nsIPresShell* aShell)
{
return mPresShells.RemoveElement(aShell);
}
-PRInt32 nsDocument::GetNumberOfShells()
+PRInt32
+nsDocument::GetNumberOfShells()
{
return mPresShells.Count();
}
@@ -1215,18 +1235,19 @@ nsDocument::GetShellAt(PRInt32 aIndex, nsIPresShell** aShell)
NS_IMETHODIMP
nsDocument::GetParentDocument(nsIDocument** aParent)
{
- NS_IF_ADDREF(*aParent = mParentDocument);
+ *aParent = mParentDocument;
+ NS_IF_ADDREF(*aParent);
+
return NS_OK;
}
-/**
- * Note that we do *not* AddRef our parent because that would
- * create a circular reference.
- */
NS_IMETHODIMP
nsDocument::SetParentDocument(nsIDocument* aParent)
{
+ // Note that we do *not* AddRef our parent because that would create
+ // a circular reference.
mParentDocument = aParent;
+
return NS_OK;
}
@@ -1382,7 +1403,10 @@ nsDocument::FindContentForSubDocument(nsIDocument *aDocument,
NS_IMETHODIMP
nsDocument::GetRootContent(nsIContent** aRoot)
{
- NS_IF_ADDREF(*aRoot = mRootContent);
+ *aRoot = mRootContent;
+
+ NS_IF_ADDREF(*aRoot);
+
return NS_OK;
}
@@ -1404,7 +1428,7 @@ nsDocument::SetRootContent(nsIContent* aRoot)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
{
NS_PRECONDITION(aIndex >= 0, "Negative indices are bad");
@@ -1416,14 +1440,14 @@ nsDocument::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const
{
aIndex = mChildren.IndexOf(aPossibleChild);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetChildCount(PRInt32& aCount)
{
aCount = mChildren.Count();
@@ -1433,10 +1457,10 @@ nsDocument::GetChildCount(PRInt32& aCount)
PRInt32
nsDocument::InternalGetNumberOfStyleSheets()
{
- return mStyleSheets.Count();
+ return mStyleSheets.Count();
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetNumberOfStyleSheets(PRBool aIncludeSpecialSheets,
PRInt32* aCount)
{
@@ -1451,17 +1475,18 @@ nsDocument::GetNumberOfStyleSheets(PRBool aIncludeSpecialSheets,
already_AddRefed
nsDocument::InternalGetStyleSheetAt(PRInt32 aIndex)
{
- if (aIndex >= 0 && aIndex < mStyleSheets.Count()) {
- nsIStyleSheet* sheet = mStyleSheets[aIndex];
- NS_ADDREF(sheet);
- return sheet;
- } else {
+ if (aIndex < 0 || aIndex >= mStyleSheets.Count()) {
NS_ERROR("Index out of range");
return nsnull;
}
+
+ nsIStyleSheet* sheet = mStyleSheets[aIndex];
+ NS_ADDREF(sheet);
+
+ return sheet;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetStyleSheetAt(PRInt32 aIndex, PRBool aIncludeSpecialSheets,
nsIStyleSheet** aSheet)
{
@@ -1476,11 +1501,11 @@ nsDocument::GetStyleSheetAt(PRInt32 aIndex, PRBool aIncludeSpecialSheets,
} else {
*aSheet = InternalGetStyleSheetAt(aIndex).get();
}
-
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex)
{
*aIndex = mStyleSheets.IndexOf(aSheet);
@@ -1488,17 +1513,19 @@ nsDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex)
}
// subclass hooks for sheet ordering
-void nsDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
+void
+nsDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
{
mStyleSheets.AppendObject(aSheet);
}
-void nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
+void
+nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
{
PRInt32 count = mPresShells.Count();
PRInt32 indx;
for (indx = 0; indx < count; ++indx) {
- nsCOMPtr shell = (nsIPresShell*)mPresShells.ElementAt(indx);
+ nsCOMPtr shell = (nsIPresShell *)mPresShells.ElementAt(indx);
nsCOMPtr set;
if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
if (set) {
@@ -1508,7 +1535,8 @@ void nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
}
}
-void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
+void
+nsDocument::AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
{
NS_PRECONDITION(aSheet, "null arg");
InternalAddStyleSheet(aSheet, aFlags);
@@ -1516,7 +1544,7 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
PRBool applicable;
aSheet->GetApplicable(applicable);
-
+
if (applicable) {
AddStyleSheetToStyleSets(aSheet);
}
@@ -1524,36 +1552,40 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
// if an observer removes itself, we're ok (not if it removes others though)
PRInt32 i;
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
+ nsIDocumentObserver* observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
observer->StyleSheetAdded(this, aSheet);
- }
+ }
}
-void nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
+void
+nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
{
PRInt32 count = mPresShells.Count();
PRInt32 indx;
for (indx = 0; indx < count; ++indx) {
- nsCOMPtr shell = (nsIPresShell*)mPresShells.ElementAt(indx);
+ nsCOMPtr shell = (nsIPresShell *)mPresShells.ElementAt(indx);
nsCOMPtr set;
- if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) {
- if (set) {
- set->RemoveDocStyleSheet(aSheet);
- }
+ shell->GetStyleSet(getter_AddRefs(set));
+
+ if (set) {
+ set->RemoveDocStyleSheet(aSheet);
}
}
}
-void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
+void
+nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
nsCOMPtr sheet = aSheet; // hold ref so it won't die too soon
-
+
if (!mStyleSheets.RemoveObject(aSheet)) {
NS_NOTREACHED("stylesheet not found");
return;
}
-
+
if (!mIsGoingAway) {
PRBool applicable = PR_TRUE;
aSheet->GetApplicable(applicable);
@@ -1561,9 +1593,13 @@ void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
RemoveStyleSheetFromStyleSets(aSheet);
}
- // if an observer removes itself, we're ok (not if it removes others though)
+ // if an observer removes itself, we're ok (not if it removes
+ // others though)
+
for (PRInt32 indx = mObservers.Count() - 1; indx >= 0; --indx) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(indx);
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(indx));
+
observer->StyleSheetRemoved(this, aSheet);
}
}
@@ -1590,7 +1626,7 @@ nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets,
PRInt32 oldIndex = mStyleSheets.IndexOf(oldSheet);
NS_ASSERTION(oldIndex != -1, "stylesheet not found");
mStyleSheets.RemoveObjectAt(oldIndex);
-
+
PRBool applicable = PR_TRUE;
oldSheet->GetApplicable(applicable);
if (applicable) {
@@ -1623,19 +1659,21 @@ nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets,
// others though)
// XXXldb Hopefully the observer doesn't care which sheet you use.
for (PRInt32 indx = mObservers.Count() - 1; indx >= 0; --indx) {
- nsIDocumentObserver* observer =
- (nsIDocumentObserver*)mObservers.ElementAt(indx);
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(indx));
+
observer->StyleSheetRemoved(this, oldSheet);
}
}
-
+
return NS_OK;
}
-void
+void
nsDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
-{ // subclass hook for sheet ordering
+{
+ // subclass hook for sheet ordering
mStyleSheets.InsertObjectAt(aSheet, aIndex);
}
@@ -1649,23 +1687,27 @@ nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
PRBool applicable;
aSheet->GetApplicable(applicable);
-
+
if (applicable) {
AddStyleSheetToStyleSets(aSheet);
}
- // if an observer removes itself, we're ok (not if it removes others though)
+ // if an observer removes itself, we're ok (not if it removes others
+ // though)
PRInt32 i;
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(i);
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
observer->StyleSheetAdded(this, aSheet);
- }
+ }
return NS_OK;
}
-void nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
- PRBool aApplicable)
+void
+nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
+ PRBool aApplicable)
{
NS_PRECONDITION(aSheet, "null arg");
@@ -1681,17 +1723,17 @@ void nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
// We have to always notify, since this will be called for sheets
// that are children of sheets in our style set, as well as some
// sheets for nsHTMLEditor.
-
+
PRInt32 indx;
// if an observer removes itself, we're ok (not if it removes others though)
for (indx = mObservers.Count() - 1; indx >= 0; --indx) {
- nsIDocumentObserver* observer =
+ nsIDocumentObserver* observer =
(nsIDocumentObserver*)mObservers.ElementAt(indx);
observer->StyleSheetApplicableStateChanged(this, aSheet, aApplicable);
}
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject)
{
NS_ENSURE_ARG_POINTER(aScriptGlobalObject);
@@ -1701,24 +1743,26 @@ nsDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject)
// caller through our docshell.
if (mIsGoingAway) {
- nsCOMPtr requestor = do_QueryReferent(mDocumentContainer);
+ nsCOMPtr requestor =
+ do_QueryReferent(mDocumentContainer);
if (requestor)
return CallGetInterface(requestor.get(), aScriptGlobalObject);
}
*aScriptGlobalObject = mScriptGlobalObject;
NS_IF_ADDREF(*aScriptGlobalObject);
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
{
// XXX HACK ALERT! If the script context owner is null, the document
// will soon be going away. So tell our content that to lose its
- // reference to the document. This has to be done before we
- // actually set the script context owner to null so that the
- // content elements can remove references to their script objects.
+ // reference to the document. This has to be done before we actually
+ // set the script context owner to null so that the content elements
+ // can remove references to their script objects.
if (!aScriptGlobalObject) {
PRInt32 count, indx;
@@ -1753,11 +1797,12 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
}
mScriptGlobalObject = aScriptGlobalObject;
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::GetScriptLoader(nsIScriptLoader** aScriptLoader)
+nsDocument::GetScriptLoader(nsIScriptLoader** aScriptLoader)
{
NS_ENSURE_ARG_POINTER(aScriptLoader);
@@ -1778,7 +1823,8 @@ nsDocument::GetScriptLoader(nsIScriptLoader** aScriptLoader)
// Note: We don't hold a reference to the document observer; we assume
// that it has a live reference to the document.
-void nsDocument::AddObserver(nsIDocumentObserver* aObserver)
+void
+nsDocument::AddObserver(nsIDocumentObserver* aObserver)
{
// XXX Make sure the observer isn't already in the list
if (mObservers.IndexOf(aObserver) == -1) {
@@ -1786,19 +1832,21 @@ void nsDocument::AddObserver(nsIDocumentObserver* aObserver)
}
}
-PRBool nsDocument::RemoveObserver(nsIDocumentObserver* aObserver)
+PRBool
+nsDocument::RemoveObserver(nsIDocumentObserver* aObserver)
{
// If we're in the process of destroying the document (and we're
// informing the observers of the destruction), don't remove the
// observers from the list. This is not a big deal, since we
// don't hold a live reference to the observers.
- if (!mInDestructor)
+ if (!mInDestructor) {
return mObservers.RemoveElement(aObserver);
- else
- return (mObservers.IndexOf(aObserver) != -1);
+ }
+
+ return (mObservers.IndexOf(aObserver) != -1);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::BeginUpdate()
{
PRInt32 i;
@@ -1806,10 +1854,11 @@ nsDocument::BeginUpdate()
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
observer->BeginUpdate(this);
}
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::EndUpdate()
{
PRInt32 i;
@@ -1817,6 +1866,7 @@ nsDocument::EndUpdate()
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
observer->EndUpdate(this);
}
+
return NS_OK;
}
@@ -1828,6 +1878,7 @@ nsDocument::BeginLoad()
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
observer->BeginLoad(this);
}
+
return NS_OK;
}
@@ -1980,29 +2031,33 @@ nsDocument::EndLoad()
}
NS_IMETHODIMP
-nsDocument::ContentChanged(nsIContent* aContent,
- nsISupports* aSubContent)
+nsDocument::ContentChanged(nsIContent* aContent, nsISupports* aSubContent)
{
NS_ABORT_IF_FALSE(aContent, "Null content!");
PRInt32 i;
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
observer->ContentChanged(this, aContent, aSubContent);
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::ContentStatesChanged(nsIContent* aContent1,
- nsIContent* aContent2,
+nsDocument::ContentStatesChanged(nsIContent* aContent1, nsIContent* aContent2,
PRInt32 aStateMask)
{
PRInt32 i;
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
observer->ContentStatesChanged(this, aContent1, aContent2, aStateMask);
}
+
return NS_OK;
}
@@ -2017,11 +2072,14 @@ nsDocument::ContentAppended(nsIContent* aContainer,
volatile
#endif
PRInt32 i;
- // XXXdwh There is a hacky ordering dependency between the binding manager
- // and the frame constructor that forces us to walk the observer list
- // in a forward order
+
+ // XXXdwh There is a hacky ordering dependency between the binding
+ // manager and the frame constructor that forces us to walk the
+ // observer list in a forward order
for (i = 0; i < mObservers.Count(); i++) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
observer->ContentAppended(this, aContainer, aNewIndexInContainer);
// Make sure that the observer didn't remove itself during the
// notification. If it did, update our index
@@ -2030,22 +2088,24 @@ nsDocument::ContentAppended(nsIContent* aContainer,
i--;
}
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::ContentInserted(nsIContent* aContainer,
- nsIContent* aChild,
+nsDocument::ContentInserted(nsIContent* aContainer, nsIContent* aChild,
PRInt32 aIndexInContainer)
{
NS_ABORT_IF_FALSE(aChild, "Null child!");
PRInt32 i;
- // XXXdwh There is a hacky ordering dependency between the binding manager
- // and the frame constructor that forces us to walk the observer list
+ // XXXdwh There is a hacky ordering dependency between the binding manager
+ // and the frame constructor that forces us to walk the observer list
// in a forward order
for (i = 0; i < mObservers.Count(); i++) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
observer->ContentInserted(this, aContainer, aChild, aIndexInContainer);
// Make sure that the observer didn't remove itself during the
// notification. If it did, update our index.
@@ -2054,92 +2114,97 @@ nsDocument::ContentInserted(nsIContent* aContainer,
i--;
}
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::ContentReplaced(nsIContent* aContainer,
- nsIContent* aOldChild,
- nsIContent* aNewChild,
- PRInt32 aIndexInContainer)
+nsDocument::ContentReplaced(nsIContent* aContainer, nsIContent* aOldChild,
+ nsIContent* aNewChild, PRInt32 aIndexInContainer)
{
NS_ABORT_IF_FALSE(aOldChild && aNewChild, "Null old or new child child!");
PRInt32 i;
- // XXXdwh There is a hacky ordering dependency between the binding manager
- // and the frame constructor that forces us to walk the observer list
- // in a reverse order
+ // XXXdwh There is a hacky ordering dependency between the binding
+ // manager and the frame constructor that forces us to walk the
+ // observer list in a reverse order
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->ContentReplaced(this, aContainer, aOldChild, aNewChild,
aIndexInContainer);
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::ContentRemoved(nsIContent* aContainer,
- nsIContent* aChild,
+nsDocument::ContentRemoved(nsIContent* aContainer, nsIContent* aChild,
PRInt32 aIndexInContainer)
{
NS_ABORT_IF_FALSE(aChild, "Null child!");
PRInt32 i;
- // XXXdwh There is a hacky ordering dependency between the binding manager
- // and the frame constructor that forces us to walk the observer list
- // in a reverse order
+ // XXXdwh There is a hacky ordering dependency between the binding
+ // manager and the frame constructor that forces us to walk the
+ // observer list in a reverse order
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
- observer->ContentRemoved(this, aContainer,
+ nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ observer->ContentRemoved(this, aContainer,
aChild, aIndexInContainer);
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::AttributeWillChange(nsIContent* aChild,
- PRInt32 aNameSpaceID,
+nsDocument::AttributeWillChange(nsIContent* aChild, PRInt32 aNameSpaceID,
nsIAtom* aAttribute)
{
- NS_ABORT_IF_FALSE(aChild, "Null child!");
+ NS_ASSERTION(aChild, "Null child!");
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::AttributeChanged(nsIContent* aChild,
- PRInt32 aNameSpaceID,
- nsIAtom* aAttribute,
- PRInt32 aModType,
+nsDocument::AttributeChanged(nsIContent* aChild, PRInt32 aNameSpaceID,
+ nsIAtom* aAttribute, PRInt32 aModType,
nsChangeHint aHint)
{
NS_ABORT_IF_FALSE(aChild, "Null child!");
PRInt32 i;
- nsresult result = NS_OK;
+ nsresult rv = NS_OK;
for (i = mObservers.Count() - 1; i >= 0; --i) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
- nsresult rv = observer->AttributeChanged(this, aChild, aNameSpaceID, aAttribute, aModType, aHint);
- if (NS_FAILED(rv) && NS_SUCCEEDED(result))
- result = rv;
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
+ nsresult rv2 = observer->AttributeChanged(this, aChild, aNameSpaceID,
+ aAttribute, aModType, aHint);
+ if (NS_FAILED(rv2) && NS_SUCCEEDED(rv))
+ rv = rv2;
}
- return result;
+
+ return rv;
}
NS_IMETHODIMP
-nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule,
- nsChangeHint aHint)
+nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet,
+ nsIStyleRule* aStyleRule, nsChangeHint aHint)
{
PRInt32 i;
- // Get new value of count for every iteration in case
- // observers remove themselves during the loop.
+
+ // Get new value of count for every iteration in case observers
+ // remove themselves during the loop.
for (i = 0; i < mObservers.Count(); i++) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
// XXXbz We should _not_ be calling BeginUpdate from in here! The
// caller of StyleRuleChanged should do that!
observer->BeginUpdate(this);
observer->StyleRuleChanged(this, aStyleSheet, aStyleRule, aHint);
+
// Make sure that the observer didn't remove itself during the
// notification. If it did, update our index and count.
if (i < mObservers.Count() &&
@@ -2150,17 +2215,22 @@ nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRul
observer->EndUpdate(this);
}
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
+nsDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet,
+ nsIStyleRule* aStyleRule)
{
PRInt32 i;
+
// Get new value of count for every iteration in case
// observers remove themselves during the loop.
for (i = 0; i < mObservers.Count(); i++) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
// XXXbz We should _not_ be calling BeginUpdate from in here! The
// caller of StyleRuleAdded should do that!
observer->BeginUpdate(this);
@@ -2175,21 +2245,27 @@ nsDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
observer->EndUpdate(this);
}
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
+nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
+ nsIStyleRule* aStyleRule)
{
PRInt32 i;
+
// Get new value of count for every iteration in case
// observers remove themselves during the loop.
for (i = 0; i < mObservers.Count(); i++) {
- nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
+ nsIDocumentObserver *observer =
+ NS_STATIC_CAST(nsIDocumentObserver *, mObservers.ElementAt(i));
+
// XXXbz We should _not_ be calling BeginUpdate from in here! The
// caller of StyleRuleRemoved should do that!
observer->BeginUpdate(this);
observer->StyleRuleRemoved(this, aStyleSheet, aStyleRule);
+
// Make sure that the observer didn't remove itself during the
// notification. If it did, update our index and count.
if (i < mObservers.Count() &&
@@ -2200,6 +2276,7 @@ nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRul
observer->EndUpdate(this);
}
}
+
return NS_OK;
}
@@ -2207,7 +2284,7 @@ nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRul
//
// nsIDOMDocument interface
//
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetDoctype(nsIDOMDocumentType** aDoctype)
{
NS_ENSURE_ARG_POINTER(aDoctype);
@@ -2215,7 +2292,7 @@ nsDocument::GetDoctype(nsIDOMDocumentType** aDoctype)
*aDoctype = nsnull;
PRInt32 i, count;
count = mChildren.Count();
- nsCOMPtr rootContentNode( do_QueryInterface(mRootContent) );
+ nsCOMPtr rootContentNode(do_QueryInterface(mRootContent) );
nsCOMPtr node;
for (i = 0; i < count; i++) {
@@ -2243,47 +2320,47 @@ nsDocument::GetDoctype(nsIDOMDocumentType** aDoctype)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
{
// For now, create a new implementation every time. This shouldn't
// be a high bandwidth operation
- nsDOMImplementation* impl = new nsDOMImplementation(mDocumentURL);
- if (!impl) {
+ *aImplementation = new nsDOMImplementation(mDocumentURL);
+ if (!*aImplementation) {
return NS_ERROR_OUT_OF_MEMORY;
}
- return CallQueryInterface(impl, aImplementation);
+ NS_ADDREF(*aImplementation);
+
+ return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
{
- if (nsnull == aDocumentElement) {
- return NS_ERROR_NULL_POINTER;
- }
+ NS_ENSURE_ARG_POINTER(aDocumentElement);
- nsresult res = NS_OK;
+ nsresult rv = NS_OK;
if (mRootContent) {
- res = CallQueryInterface(mRootContent, aDocumentElement);
- NS_ASSERTION(NS_OK == res, "Must be a DOM Element");
+ rv = CallQueryInterface(mRootContent, aDocumentElement);
+ NS_ASSERTION(NS_OK == rv, "Must be a DOM Element");
} else {
*aDocumentElement = nsnull;
}
-
- return res;
+
+ return rv;
}
-NS_IMETHODIMP
-nsDocument::CreateElement(const nsAString& aTagName,
+NS_IMETHODIMP
+nsDocument::CreateElement(const nsAString& aTagName,
nsIDOMElement** aReturn)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CreateElementNS(const nsAString & namespaceURI,
const nsAString & qualifiedName,
nsIDOMElement **_retval)
@@ -2308,15 +2385,17 @@ nsDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn)
return rv;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
{
return NS_NewDocumentFragment(aReturn, this);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn)
{
+ *aReturn = nsnull;
+
nsCOMPtr comment;
nsresult rv = NS_NewCommentNode(getter_AddRefs(comment));
@@ -2328,24 +2407,25 @@ nsDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn)
return rv;
}
-NS_IMETHODIMP
-nsDocument::CreateCDATASection(const nsAString& aData, nsIDOMCDATASection** aReturn)
+NS_IMETHODIMP
+nsDocument::CreateCDATASection(const nsAString& aData,
+ nsIDOMCDATASection** aReturn)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
-nsDocument::CreateProcessingInstruction(const nsAString& aTarget,
- const nsAString& aData,
+NS_IMETHODIMP
+nsDocument::CreateProcessingInstruction(const nsAString& aTarget,
+ const nsAString& aData,
nsIDOMProcessingInstruction** aReturn)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
-nsDocument::CreateAttribute(const nsAString& aName,
+NS_IMETHODIMP
+nsDocument::CreateAttribute(const nsAString& aName,
nsIDOMAttr** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
@@ -2357,10 +2437,10 @@ nsDocument::CreateAttribute(const nsAString& aName,
nsCOMPtr nodeInfo;
nsresult rv = mNodeInfoManager->GetNodeInfo(aName, nsnull, kNameSpaceID_None,
*getter_AddRefs(nodeInfo));
- NS_ENSURE_SUCCESS(rv, rv);
-
+ NS_ENSURE_SUCCESS(rv, rv);
+
attribute = new nsDOMAttribute(nsnull, nodeInfo, value);
- NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
+ NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
return CallQueryInterface(attribute, aReturn);
}
@@ -2374,19 +2454,20 @@ nsDocument::CreateAttributeNS(const nsAString & namespaceURI,
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
-nsDocument::CreateEntityReference(const nsAString& aName,
+NS_IMETHODIMP
+nsDocument::CreateEntityReference(const nsAString& aName,
nsIDOMEntityReference** aReturn)
{
// Should be implemented by subclass
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
-nsDocument::GetElementsByTagName(const nsAString& aTagname,
+NS_IMETHODIMP
+nsDocument::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
{
nsCOMPtr nameAtom = do_GetAtom(aTagname);
+ NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr list;
NS_GetContentList(this, nameAtom, kNameSpaceID_Unknown, nsnull,
@@ -2396,7 +2477,7 @@ nsDocument::GetElementsByTagName(const nsAString& aTagname,
return CallQueryInterface(list, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
nsIDOMNodeList** aReturn)
@@ -2420,7 +2501,7 @@ nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
if (!list) {
nsCOMPtr nameAtom = do_GetAtom(aLocalName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
-
+
NS_GetContentList(this, nameAtom, nameSpaceId, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
@@ -2429,7 +2510,7 @@ nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
return CallQueryInterface(list, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetElementById(const nsAString & elementId,
nsIDOMElement **_retval)
{
@@ -2478,7 +2559,7 @@ nsDocument::EvaluateXPointer(const nsAString& aExpression,
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets)
{
if (!mDOMStyleSheets) {
@@ -2494,7 +2575,7 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetCharacterSet(nsAString& aCharacterSet)
{
return GetDocumentCharacterSet(aCharacterSet);
@@ -2507,7 +2588,7 @@ nsDocument::ImportNode(nsIDOMNode* aImportedNode,
{
NS_ENSURE_ARG(aImportedNode);
NS_ENSURE_ARG_POINTER(aReturn);
-
+
nsresult rv = nsContentUtils::CheckSameOrigin(this, aImportedNode);
if (NS_FAILED(rv)) {
return rv;
@@ -2548,18 +2629,21 @@ nsDocument::RemoveBinding(nsIDOMElement* aContent, const nsAString& aURL)
}
NS_IMETHODIMP
-nsDocument::LoadBindingDocument(const nsAString& aURL, nsIDOMDocument** aResult)
+nsDocument::LoadBindingDocument(const nsAString& aURL,
+ nsIDOMDocument** aResult)
{
- if (mBindingManager) {
- nsCOMPtr doc;
- mBindingManager->LoadBindingDocument(this, aURL, getter_AddRefs(doc));
- nsCOMPtr domDoc(do_QueryInterface(doc));
- *aResult = domDoc;
- NS_IF_ADDREF(*aResult);
- return NS_OK;
+ if (!mBindingManager) {
+ return NS_ERROR_FAILURE;
}
- return NS_ERROR_FAILURE;
+ nsCOMPtr doc;
+ mBindingManager->LoadBindingDocument(this, aURL, getter_AddRefs(doc));
+
+ nsCOMPtr domDoc(do_QueryInterface(doc));
+ *aResult = domDoc;
+ NS_IF_ADDREF(*aResult);
+
+ return NS_OK;
}
NS_IMETHODIMP
@@ -2579,19 +2663,17 @@ nsDocument::GetBindingParent(nsIDOMNode* aNode, nsIDOMElement** aResult)
}
static nsresult
-GetElementByAttribute(nsIContent* aContent,
- nsIAtom* aAttrName,
- const nsAString& aAttrValue,
- PRBool aUniversalMatch,
+GetElementByAttribute(nsIContent* aContent, nsIAtom* aAttrName,
+ const nsAString& aAttrValue, PRBool aUniversalMatch,
nsIDOMElement** aResult)
{
nsAutoString value;
nsresult rv = aContent->GetAttr(kNameSpaceID_None, aAttrName, value);
- if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
- if (aUniversalMatch || value.Equals(aAttrValue))
- return CallQueryInterface(aContent, aResult);
+ if (rv == NS_CONTENT_ATTR_HAS_VALUE &&
+ (aUniversalMatch || value.Equals(aAttrValue))) {
+ return CallQueryInterface(aContent, aResult);
}
-
+
PRInt32 childCount;
aContent->ChildCount(childCount);
@@ -2599,7 +2681,8 @@ GetElementByAttribute(nsIContent* aContent,
nsCOMPtr current;
aContent->ChildAt(i, *getter_AddRefs(current));
- GetElementByAttribute(current, aAttrName, aAttrValue, aUniversalMatch, aResult);
+ GetElementByAttribute(current, aAttrName, aAttrValue, aUniversalMatch,
+ aResult);
if (*aResult)
return NS_OK;
@@ -2610,16 +2693,16 @@ GetElementByAttribute(nsIContent* aContent,
NS_IMETHODIMP
nsDocument::GetAnonymousElementByAttribute(nsIDOMElement* aElement,
- const nsAString& aAttrName,
- const nsAString& aAttrValue,
+ const nsAString& aAttrName,
+ const nsAString& aAttrValue,
nsIDOMElement** aResult)
{
*aResult = nsnull;
nsCOMPtr nodeList;
GetAnonymousNodes(aElement, getter_AddRefs(nodeList));
-
- if (!nodeList)
+
+ if (!nodeList)
return NS_OK;
nsCOMPtr attribute = do_GetAtom(aAttrName);
@@ -2632,10 +2715,11 @@ nsDocument::GetAnonymousElementByAttribute(nsIDOMElement* aElement,
for (PRUint32 i = 0; i < length; ++i) {
nsCOMPtr current;
nodeList->Item(i, getter_AddRefs(current));
-
+
nsCOMPtr content(do_QueryInterface(current));
- GetElementByAttribute(content, attribute, aAttrValue, universalMatch, aResult);
+ GetElementByAttribute(content, attribute, aAttrValue, universalMatch,
+ aResult);
if (*aResult)
return NS_OK;
}
@@ -2649,20 +2733,21 @@ nsDocument::GetAnonymousNodes(nsIDOMElement* aElement,
nsIDOMNodeList** aResult)
{
*aResult = nsnull;
- if (mBindingManager) {
- nsCOMPtr content(do_QueryInterface(aElement));
- return mBindingManager->GetAnonymousNodesFor(content, aResult);
+ if (!mBindingManager) {
+ return NS_OK;
}
- return NS_OK;
+
+ nsCOMPtr content(do_QueryInterface(aElement));
+ return mBindingManager->GetAnonymousNodesFor(content, aResult);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CreateRange(nsIDOMRange** aReturn)
{
return NS_NewRange(aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CreateNodeIterator(nsIDOMNode *aRoot,
PRUint32 aWhatToShow,
nsIDOMNodeFilter *aFilter,
@@ -2672,7 +2757,7 @@ nsDocument::CreateNodeIterator(nsIDOMNode *aRoot,
return NS_ERROR_NOT_IMPLEMENTED;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CreateTreeWalker(nsIDOMNode *aRoot,
PRUint32 aWhatToShow,
nsIDOMNodeFilter *aFilter,
@@ -2682,14 +2767,12 @@ nsDocument::CreateTreeWalker(nsIDOMNode *aRoot,
*_retval = nsnull;
nsresult rv = nsContentUtils::CheckSameOrigin(this, aRoot);
- if(NS_FAILED(rv))
+ if (NS_FAILED(rv)) {
return rv;
+ }
- return NS_NewTreeWalker(aRoot,
- aWhatToShow,
- aFilter,
- aEntityReferenceExpansion,
- _retval);
+ return NS_NewTreeWalker(aRoot, aWhatToShow, aFilter,
+ aEntityReferenceExpansion, _retval);
}
@@ -2728,11 +2811,11 @@ nsDocument::GetLocation(nsIDOMLocation **_retval)
nsCOMPtr w(do_QueryInterface(mScriptGlobalObject));
- if(w) {
- return w->GetLocation(_retval);
+ if (!w) {
+ return NS_OK;
}
- return NS_OK;
+ return w->GetLocation(_retval);
}
NS_IMETHODIMP
@@ -2762,7 +2845,7 @@ nsDocument::SetTitle(const nsAString& aTitle)
continue;
nsCOMPtr docShellWin = do_QueryInterface(container);
- if(!docShellWin)
+ if (!docShellWin)
continue;
rv = docShellWin->SetTitle(PromiseFlatString(aTitle).get());
@@ -2790,15 +2873,17 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
*aResult = nsnull;
- if (!mBoxObjectTable)
+ if (!mBoxObjectTable) {
mBoxObjectTable = new nsSupportsHashtable;
- else {
+ } else {
nsISupportsKey key(aElement);
- nsCOMPtr supports(dont_AddRef(NS_STATIC_CAST(nsISupports*, mBoxObjectTable->Get(&key))));
+ nsCOMPtr supports = dont_AddRef(mBoxObjectTable->Get(&key));
+
nsCOMPtr boxObject(do_QueryInterface(supports));
if (boxObject) {
*aResult = boxObject;
NS_ADDREF(*aResult);
+
return NS_OK;
}
}
@@ -2810,40 +2895,44 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
PRInt32 namespaceID;
nsCOMPtr tag;
- nsCOMPtr xblService =
+ nsCOMPtr xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
nsCOMPtr content(do_QueryInterface(aElement));
xblService->ResolveTag(content, &namespaceID, getter_AddRefs(tag));
-
+
nsCAutoString contractID("@mozilla.org/layout/xul-boxobject");
if (namespaceID == kNameSpaceID_XUL) {
- if (tag.get() == nsXULAtoms::browser)
+ if (tag == nsXULAtoms::browser)
contractID += "-browser";
- else if (tag.get() == nsXULAtoms::editor)
+ else if (tag == nsXULAtoms::editor)
contractID += "-editor";
- else if (tag.get() == nsXULAtoms::iframe)
+ else if (tag == nsXULAtoms::iframe)
contractID += "-iframe";
- else if (tag.get() == nsXULAtoms::menu)
+ else if (tag == nsXULAtoms::menu)
contractID += "-menu";
- else if (tag.get() == nsXULAtoms::popup || tag.get() == nsXULAtoms::menupopup ||
- tag.get() == nsXULAtoms::tooltip)
+ else if (tag == nsXULAtoms::popup ||
+ tag == nsXULAtoms::menupopup ||
+ tag == nsXULAtoms::tooltip)
contractID += "-popup";
- else if (tag.get() == nsXULAtoms::tree)
+ else if (tag == nsXULAtoms::tree)
contractID += "-tree";
- else if (tag.get() == nsXULAtoms::listbox)
+ else if (tag == nsXULAtoms::listbox)
contractID += "-listbox";
- else if (tag.get() == nsXULAtoms::scrollbox)
+ else if (tag == nsXULAtoms::scrollbox)
contractID += "-scrollbox";
}
contractID += ";1";
-
+
nsCOMPtr boxObject(do_CreateInstance(contractID.get()));
- if (!boxObject)
+ if (!boxObject)
return NS_ERROR_FAILURE;
nsCOMPtr privateBox(do_QueryInterface(boxObject));
- if (NS_FAILED(rv = privateBox->Init(content, shell)))
+ rv = privateBox->Init(content, shell);
+
+ if (NS_FAILED(rv)) {
return rv;
+ }
SetBoxObjectFor(aElement, boxObject);
@@ -2857,21 +2946,22 @@ NS_IMETHODIMP
nsDocument::SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject)
{
if (!mBoxObjectTable) {
- if (!aBoxObject)
+ if (!aBoxObject)
return NS_OK;
mBoxObjectTable = new nsSupportsHashtable(12);
}
nsISupportsKey key(aElement);
- if (aBoxObject)
+ if (aBoxObject) {
mBoxObjectTable->Put(&key, aBoxObject);
- else {
+ } else {
nsCOMPtr supp;
mBoxObjectTable->Remove(&key, getter_AddRefs(supp));
nsCOMPtr boxObject(do_QueryInterface(supp));
- if (boxObject)
+ if (boxObject) {
boxObject->SetDocument(nsnull);
+ }
}
return NS_OK;
@@ -2881,6 +2971,7 @@ struct DirTable {
const char* mName;
PRUint8 mValue;
};
+
static const DirTable dirAttributes[] = {
{"ltr", IBMBIDI_TEXTDIRECTION_LTR},
{"rtl", IBMBIDI_TEXTDIRECTION_RTL},
@@ -2888,9 +2979,9 @@ static const DirTable dirAttributes[] = {
};
/**
- * Retrieve the "direction" property of the document.
+ * Retrieve the "direction" property of the document.
*
- * @lina 01/09/2001
+ * @lina 01/09/2001
*/
NS_IMETHODIMP
nsDocument::GetDir(nsAString& aDirection)
@@ -2898,13 +2989,13 @@ nsDocument::GetDir(nsAString& aDirection)
nsCOMPtr shell = (nsIPresShell*)mPresShells.SafeElementAt(0);
if (shell) {
nsCOMPtr context;
- shell->GetPresContext(getter_AddRefs(context) );
+ shell->GetPresContext(getter_AddRefs(context));
if (context) {
PRUint32 options;
context->GetBidi(&options);
for (const DirTable* elt = dirAttributes; elt->mName; elt++) {
if (GET_BIDI_OPTION_DIRECTION(options) == elt->mValue) {
- aDirection.Assign(NS_ConvertASCIItoUCS2(elt->mName) );
+ aDirection.Assign(NS_ConvertASCIItoUCS2(elt->mName));
break;
}
}
@@ -2915,33 +3006,38 @@ nsDocument::GetDir(nsAString& aDirection)
}
/**
- * Set the "direction" property of the document.
+ * Set the "direction" property of the document.
*
- * @lina 01/09/2001
+ * @lina 01/09/2001
*/
NS_IMETHODIMP
nsDocument::SetDir(const nsAString& aDirection)
{
- if (mPresShells.Count() != 0) {
- nsCOMPtr shell = (nsIPresShell*)mPresShells.ElementAt(0);
- if (shell) {
- nsCOMPtr context;
- shell->GetPresContext(getter_AddRefs(context) );
- if (context) {
- PRUint32 options;
- context->GetBidi(&options);
- for (const DirTable* elt = dirAttributes; elt->mName; elt++) {
- if (aDirection == NS_ConvertASCIItoUCS2(elt->mName) ) {
- if (GET_BIDI_OPTION_DIRECTION(options) != elt->mValue) {
- SET_BIDI_OPTION_DIRECTION(options, elt->mValue);
- context->SetBidi(options, PR_TRUE);
- }
- break;
- }
- } // for
+ nsIPresShell *shell =
+ NS_STATIC_CAST(nsIPresShell *, mPresShells.SafeElementAt(0));
+
+ if (!shell) {
+ return NS_OK;
+ }
+
+ nsCOMPtr context;
+ shell->GetPresContext(getter_AddRefs(context));
+ NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
+
+ PRUint32 options;
+ context->GetBidi(&options);
+
+ for (const DirTable* elt = dirAttributes; elt->mName; elt++) {
+ if (aDirection == NS_ConvertASCIItoUCS2(elt->mName)) {
+ if (GET_BIDI_OPTION_DIRECTION(options) != elt->mValue) {
+ SET_BIDI_OPTION_DIRECTION(options, elt->mValue);
+ context->SetBidi(options, PR_TRUE);
}
+
+ break;
}
}
+
return NS_OK;
}
@@ -2949,14 +3045,15 @@ nsDocument::SetDir(const nsAString& aDirection)
//
// nsIDOMNode methods
//
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetNodeName(nsAString& aNodeName)
{
aNodeName.Assign(NS_LITERAL_STRING("#document"));
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetNodeValue(nsAString& aNodeValue)
{
SetDOMStringToNull(aNodeValue);
@@ -2964,27 +3061,29 @@ nsDocument::GetNodeValue(nsAString& aNodeValue)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::SetNodeValue(const nsAString& aNodeValue)
{
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = nsIDOMNode::DOCUMENT_NODE;
+
return NS_OK;
}
-NS_IMETHODIMP
-nsDocument::GetParentNode(nsIDOMNode** aParentNode)
+NS_IMETHODIMP
+nsDocument::GetParentNode(nsIDOMNode** aParentNode)
{
*aParentNode = nsnull;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
if (!mChildNodes) {
@@ -2992,13 +3091,12 @@ nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
if (!mChildNodes) {
return NS_ERROR_OUT_OF_MEMORY;
}
- NS_ADDREF(mChildNodes);
}
- return CallQueryInterface(mChildNodes, aChildNodes);
+ return CallQueryInterface(mChildNodes.get(), aChildNodes);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::HasChildNodes(PRBool* aHasChildNodes)
{
NS_ENSURE_ARG(aHasChildNodes);
@@ -3008,7 +3106,7 @@ nsDocument::HasChildNodes(PRBool* aHasChildNodes)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::HasAttributes(PRBool* aHasAttributes)
{
NS_ENSURE_ARG(aHasAttributes);
@@ -3018,53 +3116,58 @@ nsDocument::HasAttributes(PRBool* aHasAttributes)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
{
if (mChildren.Count()) {
return CallQueryInterface(mChildren[0], aFirstChild);
}
-
+
*aFirstChild = nsnull;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetLastChild(nsIDOMNode** aLastChild)
{
PRInt32 count = mChildren.Count();
if (count) {
return CallQueryInterface(mChildren[count-1], aLastChild);
}
-
+
*aLastChild = nsnull;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
*aPreviousSibling = nsnull;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetNextSibling(nsIDOMNode** aNextSibling)
{
*aNextSibling = nsnull;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
*aAttributes = nsnull;
+
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetNamespaceURI(nsAString& aNamespaceURI)
-{
+{
SetDOMStringToNull(aNamespaceURI);
return NS_OK;
@@ -3092,17 +3195,17 @@ nsDocument::GetLocalName(nsAString& aLocalName)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
nsIDOMNode** aReturn)
{
- NS_ASSERTION(nsnull != aNewChild, "null ptr");
+ NS_ASSERTION(aNewChild, "null ptr");
PRInt32 indx;
PRUint16 nodeType;
*aReturn = nsnull; // Do we need to do this?
- if (nsnull == aNewChild) {
+ if (!aNewChild) {
return NS_ERROR_NULL_POINTER;
}
@@ -3115,16 +3218,16 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
// element and we already have a root (our addition to DOM spec), throw
// HIERARCHY_REQUEST_ERR.
aNewChild->GetNodeType(&nodeType);
- if (((COMMENT_NODE != nodeType) &&
- (TEXT_NODE != nodeType) &&
- (PROCESSING_INSTRUCTION_NODE != nodeType) &&
- (DOCUMENT_TYPE_NODE != nodeType) &&
- (ELEMENT_NODE != nodeType)) ||
- ((ELEMENT_NODE == nodeType) && mRootContent)){
+ if (((nodeType != COMMENT_NODE) &&
+ (nodeType != TEXT_NODE) &&
+ (nodeType != PROCESSING_INSTRUCTION_NODE) &&
+ (nodeType != DOCUMENT_TYPE_NODE) &&
+ (nodeType != ELEMENT_NODE)) ||
+ ((nodeType == ELEMENT_NODE) && mRootContent)) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
- nsCOMPtr content( do_QueryInterface(aNewChild) );
+ nsCOMPtr content(do_QueryInterface(aNewChild));
if (!content) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
@@ -3134,7 +3237,7 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
mChildren.AppendObject(content);
}
else {
- nsCOMPtr refContent( do_QueryInterface(aRefChild) );
+ nsCOMPtr refContent(do_QueryInterface(aRefChild));
if (!refContent) {
return NS_ERROR_DOM_NOT_FOUND_ERR;
@@ -3151,8 +3254,9 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
// If we get here, we've succesfully inserted content into the
// index-th spot in mChildren.
- if (ELEMENT_NODE == nodeType)
+ if (nodeType == ELEMENT_NODE) {
mRootContent = content;
+ }
content->SetDocument(this, PR_TRUE, PR_TRUE);
@@ -3164,23 +3268,21 @@ nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
return NS_OK;
}
-NS_IMETHODIMP
-nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
+NS_IMETHODIMP
+nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
+ nsIDOMNode** aReturn)
{
- NS_ASSERTION(((nsnull != aNewChild) && (nsnull != aOldChild)), "null ptr");
- nsresult result = NS_OK;
+ *aReturn = nsnull;
+
+ NS_ENSURE_TRUE(aNewChild && aOldChild, NS_ERROR_NULL_POINTER);
+
+ nsresult rv = NS_OK;
PRInt32 indx;
PRUint16 nodeType;
-
- *aReturn = nsnull; // is this necessary?
- if ((nsnull == aNewChild) || (nsnull == aOldChild)) {
- return NS_ERROR_NULL_POINTER;
- }
-
- result = nsContentUtils::CheckSameOrigin(this, aNewChild);
- if (NS_FAILED(result)) {
- return result;
+ rv = nsContentUtils::CheckSameOrigin(this, aNewChild);
+ if (NS_FAILED(rv)) {
+ return rv;
}
aNewChild->GetNodeType(&nodeType);
@@ -3193,22 +3295,20 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
- nsCOMPtr content( do_QueryInterface(aNewChild) );
- nsCOMPtr refContent( do_QueryInterface(aOldChild) );
+ nsCOMPtr content(do_QueryInterface(aNewChild));
+ nsCOMPtr refContent(do_QueryInterface(aOldChild));
if (!content || !refContent) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
- if ((ELEMENT_NODE == nodeType) &&
- mRootContent &&
- (mRootContent != refContent.get()))
- {
+ if (nodeType == ELEMENT_NODE && mRootContent &&
+ mRootContent != refContent) {
// Caller attempted to add a second element as a child.
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
-
+
indx = mChildren.IndexOf(refContent);
- if (-1 == indx) {
+ if (indx == -1) {
// The reference child is not a child of the document.
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
@@ -3218,8 +3318,9 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
mChildren.ReplaceObjectAt(content, indx);
// This is OK because we checked above.
- if (ELEMENT_NODE == nodeType)
+ if (nodeType == ELEMENT_NODE) {
mRootContent = content;
+ }
content->SetDocument(this, PR_TRUE, PR_TRUE);
ContentInserted(nsnull, content, indx);
@@ -3227,27 +3328,23 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNod
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
- return result;
+ return rv;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
- NS_ASSERTION(nsnull != aOldChild, "null ptr");
-
*aReturn = nsnull; // do we need to do this?
- if (nsnull == aOldChild) {
- return NS_ERROR_NULL_POINTER;
- }
+ NS_ENSURE_TRUE(aOldChild, NS_ERROR_NULL_POINTER);
- nsCOMPtr content( do_QueryInterface(aOldChild) );
+ nsCOMPtr content(do_QueryInterface(aOldChild));
if (!content) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
PRInt32 indx = mChildren.IndexOf(content);
- if (-1 == indx) {
+ if (indx == -1) {
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
@@ -3261,21 +3358,22 @@ nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
-
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
{
return InsertBefore(aNewChild, nsnull, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
// XXX should be implemented by subclass
*aReturn = nsnull;
+
return NS_OK;
}
@@ -3291,12 +3389,12 @@ nsDocument::Normalize()
return node->Normalize();
}
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::IsSupported(const nsAString& aFeature,
- const nsAString& aVersion,
+nsDocument::IsSupported(const nsAString& aFeature, const nsAString& aVersion,
PRBool* aReturn)
{
return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn);
@@ -3311,12 +3409,12 @@ nsDocument::GetBaseURI(nsAString &aURI)
mDocumentBaseURL->GetSpec(spec);
aURI = NS_ConvertUTF8toUCS2(spec);
}
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::CompareDocumentPosition(nsIDOMNode* aOther,
- PRUint16* aReturn)
+nsDocument::CompareDocumentPosition(nsIDOMNode* aOther, PRUint16* aReturn)
{
NS_ENSURE_ARG_POINTER(aOther);
NS_PRECONDITION(aReturn, "Must have an out parameter");
@@ -3383,12 +3481,12 @@ nsDocument::CompareDocumentPosition(nsIDOMNode* aOther,
}
*aReturn = mask;
+
return NS_OK;
}
NS_IMETHODIMP
-nsDocument::IsSameNode(nsIDOMNode* aOther,
- PRBool* aReturn)
+nsDocument::IsSameNode(nsIDOMNode* aOther, PRBool* aReturn)
{
PRBool sameNode = PR_FALSE;
@@ -3397,51 +3495,64 @@ nsDocument::IsSameNode(nsIDOMNode* aOther,
}
*aReturn = sameNode;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::LookupNamespacePrefix(const nsAString& aNamespaceURI,
- nsAString& aPrefix)
+ nsAString& aPrefix)
{
aPrefix.Truncate();
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
aNamespaceURI.Truncate();
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
{
*aOwnerDocument = nsnull;
+
return NS_OK;
}
-nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrResult)
+nsresult
+nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrResult)
{
- if (nsnull != mListenerManager) {
- return CallQueryInterface(mListenerManager, aInstancePtrResult);
- }
- if (NS_OK == NS_NewEventListenerManager(aInstancePtrResult)) {
- mListenerManager = *aInstancePtrResult;
- NS_ADDREF(mListenerManager);
- mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIDocument*,this));
+ if (mListenerManager) {
+ *aInstancePtrResult = mListenerManager;
+ NS_ADDREF(*aInstancePtrResult);
+
return NS_OK;
}
- return NS_ERROR_FAILURE;
+
+ nsresult rv = NS_NewEventListenerManager(getter_AddRefs(mListenerManager));
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIDocument *,this));
+
+ *aInstancePtrResult = mListenerManager;
+ NS_ADDREF(*aInstancePtrResult);
+
+ return NS_OK;
}
-nsresult nsDocument::HandleEvent(nsIDOMEvent *aEvent)
+nsresult
+nsDocument::HandleEvent(nsIDOMEvent *aEvent)
{
PRBool noDefault;
+
return DispatchEvent(aEvent, &noDefault);
-}
+}
NS_IMETHODIMP
nsDocument::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
@@ -3450,14 +3561,14 @@ nsDocument::GetSystemEventGroup(nsIDOMEventGroup **aGroup)
if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(manager))) && manager) {
return manager->GetSystemEventGroupLM(aGroup);
}
+
return NS_ERROR_FAILURE;
}
-nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
- nsEvent* aEvent,
- nsIDOMEvent** aDOMEvent,
- PRUint32 aFlags,
- nsEventStatus* aEventStatus)
+nsresult
+nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
+ nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
+ nsEventStatus* aEventStatus)
{
nsresult mRet = NS_OK;
PRBool externalDOMEvent = PR_FALSE;
@@ -3467,7 +3578,7 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
if (NS_EVENT_FLAG_INIT & aFlags) {
if (aDOMEvent) {
if (*aDOMEvent) {
- externalDOMEvent = PR_TRUE;
+ externalDOMEvent = PR_TRUE;
}
}
else {
@@ -3477,37 +3588,48 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
}
-
- //Capturing stage
+
+ // Capturing stage
if (NS_EVENT_FLAG_CAPTURE & aFlags && nsnull != mScriptGlobalObject) {
- mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
+ mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
+ aFlags & NS_EVENT_CAPTURE_MASK,
+ aEventStatus);
}
-
- //Local handling stage
- //Check for null mDOMSlots or ELM, check if we're a non-bubbling event in the bubbling state (bubbling state
- //is indicated by the presence of the NS_EVENT_FLAG_BUBBLE flag and not the NS_EVENT_FLAG_INIT).
+
+ // Local handling stage
+ // Check for null mDOMSlots or ELM, check if we're a non-bubbling
+ // event in the bubbling state (bubbling state is indicated by the
+ // presence of the NS_EVENT_FLAG_BUBBLE flag and not the
+ // NS_EVENT_FLAG_INIT).
if (mListenerManager &&
- !(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags && NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags))) {
+ !(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags &&
+ NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags))) {
aEvent->flags |= aFlags;
- mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
+ mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this,
+ aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
- //Bubbling stage
+ // Bubbling stage
if (NS_EVENT_FLAG_BUBBLE & aFlags && nsnull != mScriptGlobalObject) {
- mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags & NS_EVENT_BUBBLE_MASK, aEventStatus);
+ mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
+ aFlags & NS_EVENT_BUBBLE_MASK,
+ aEventStatus);
}
if (NS_EVENT_FLAG_INIT & aFlags) {
- // We're leaving the DOM event loop so if we created a DOM event, release here.
+ // We're leaving the DOM event loop so if we created a DOM event,
+ // release here.
if (*aDOMEvent && !externalDOMEvent) {
nsrefcnt rc;
NS_RELEASE2(*aDOMEvent, rc);
if (0 != rc) {
- // Okay, so someone in the DOM loop (a listener, JS object) still has
- // a ref to the DOM Event but the internal data hasn't been malloc'd.
- // Force a copy of the data here so the DOM Event is still valid.
- nsCOMPtr privateEvent = do_QueryInterface(*aDOMEvent);
+ // Okay, so someone in the DOM loop (a listener, JS object)
+ // still has a ref to the DOM Event but the internal data
+ // hasn't been malloc'd. Force a copy of the data here so the
+ // DOM Event is still valid.
+ nsCOMPtr privateEvent =
+ do_QueryInterface(*aDOMEvent);
if (privateEvent) {
privateEvent->DuplicatePrivateData();
}
@@ -3519,15 +3641,9 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
return mRet;
}
-NS_IMETHODIMP_(PRBool)
-nsDocument::EventCaptureRegistration(PRInt32 aCapturerIncrement)
-{
- mNumCapturers += aCapturerIncrement;
- NS_WARN_IF_FALSE(mNumCapturers >= 0, "Number of capturers has become negative");
- return (mNumCapturers > 0 ? PR_TRUE : PR_FALSE);
-}
-
-nsresult nsDocument::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
+nsresult
+nsDocument::AddEventListenerByIID(nsIDOMEventListener *aListener,
+ const nsIID& aIID)
{
nsCOMPtr manager;
@@ -3536,26 +3652,35 @@ nsresult nsDocument::AddEventListenerByIID(nsIDOMEventListener *aListener, const
manager->AddEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
return NS_OK;
}
+
return NS_ERROR_FAILURE;
}
-nsresult nsDocument::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
+nsresult
+nsDocument::RemoveEventListenerByIID(nsIDOMEventListener *aListener,
+ const nsIID& aIID)
{
- if (nsnull != mListenerManager) {
- mListenerManager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
- return NS_OK;
+ if (!mListenerManager) {
+ return NS_ERROR_FAILURE;
}
- return NS_ERROR_FAILURE;
+
+ mListenerManager->RemoveEventListenerByIID(aListener, aIID,
+ NS_EVENT_FLAG_BUBBLE);
+ return NS_OK;
}
-nsresult nsDocument::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
- PRBool aUseCapture)
+nsresult
+nsDocument::AddEventListener(const nsAString& aType,
+ nsIDOMEventListener* aListener,
+ PRBool aUseCapture)
{
return AddGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
-nsresult nsDocument::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener,
- PRBool aUseCapture)
+nsresult
+nsDocument::RemoveEventListener(const nsAString& aType,
+ nsIDOMEventListener* aListener,
+ PRBool aUseCapture)
{
return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
}
@@ -3572,23 +3697,24 @@ nsDocument::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
GetShellAt(0, getter_AddRefs(shell));
if (!shell)
return NS_ERROR_FAILURE;
-
+
// Retrieve the context
nsCOMPtr presContext;
shell->GetPresContext(getter_AddRefs(presContext));
nsCOMPtr esm;
- if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) {
- return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDOMDocument *, this),
- aEvent, _retval);
- }
+ nsresult rv = presContext->GetEventStateManager(getter_AddRefs(esm));
+ NS_ENSURE_SUCCESS(rv, rv);
- return NS_ERROR_FAILURE;
+ return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDOMDocument *, this), aEvent,
+ _retval);
}
NS_IMETHODIMP
-nsDocument::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
- PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
+nsDocument::AddGroupedEventListener(const nsAString& aType,
+ nsIDOMEventListener *aListener,
+ PRBool aUseCapture,
+ nsIDOMEventGroup *aEvtGrp)
{
nsCOMPtr manager;
@@ -3599,20 +3725,25 @@ nsDocument::AddGroupedEventListener(const nsAString & aType, nsIDOMEventListener
manager->AddEventListenerByType(aListener, aType, flags, aEvtGrp);
return NS_OK;
}
+
return rv;
}
NS_IMETHODIMP
-nsDocument::RemoveGroupedEventListener(const nsAString & aType, nsIDOMEventListener *aListener,
- PRBool aUseCapture, nsIDOMEventGroup *aEvtGrp)
+nsDocument::RemoveGroupedEventListener(const nsAString& aType,
+ nsIDOMEventListener *aListener,
+ PRBool aUseCapture,
+ nsIDOMEventGroup *aEvtGrp)
{
- if (mListenerManager) {
- PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
-
- mListenerManager->RemoveEventListenerByType(aListener, aType, flags, aEvtGrp);
- return NS_OK;
+ if (!mListenerManager) {
+ return NS_ERROR_FAILURE;
}
- return NS_ERROR_FAILURE;
+
+ PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
+
+ mListenerManager->RemoveEventListenerByType(aListener, aType, flags,
+ aEvtGrp);
+ return NS_OK;
}
NS_IMETHODIMP
@@ -3628,32 +3759,27 @@ nsDocument::IsRegisteredHere(const nsAString & type, PRBool *_retval)
}
NS_IMETHODIMP
-nsDocument::CreateEvent(const nsAString& aEventType,
- nsIDOMEvent** aReturn)
+nsDocument::CreateEvent(const nsAString& aEventType, nsIDOMEvent** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
*aReturn = nsnull;
// Obtain a presentation context
- PRInt32 count = GetNumberOfShells();
- if (count == 0)
- return NS_OK;
nsCOMPtr shell;
GetShellAt(0, getter_AddRefs(shell));
- if (!shell)
- return NS_ERROR_FAILURE;
-
- // Retrieve the context
- nsCOMPtr presContext;
- shell->GetPresContext(getter_AddRefs(presContext));
- if (presContext) {
- nsCOMPtr manager;
- GetListenerManager(getter_AddRefs(manager));
- if (manager) {
- return manager->CreateEvent(presContext, nsnull, aEventType, aReturn);
- }
+ nsCOMPtr presContext;
+
+ if (shell) {
+ // Retrieve the context
+ shell->GetPresContext(getter_AddRefs(presContext));
+ }
+
+ nsCOMPtr manager;
+ GetListenerManager(getter_AddRefs(manager));
+ if (manager) {
+ return manager->CreateEvent(presContext, nsnull, aEventType, aReturn);
}
return NS_ERROR_FAILURE;
@@ -3662,61 +3788,62 @@ nsDocument::CreateEvent(const nsAString& aEventType,
NS_IMETHODIMP
nsDocument::CreateEventGroup(nsIDOMEventGroup **aInstancePtrResult)
{
- nsresult result;
- nsCOMPtr group(do_CreateInstance(kDOMEventGroupCID,&result));
- if (NS_FAILED(result))
- return result;
+ nsresult rv;
+ nsCOMPtr group(do_CreateInstance(kDOMEventGroupCID, &rv));
+ NS_ENSURE_SUCCESS(rv, rv);
- *aInstancePtrResult = group.get();
+ *aInstancePtrResult = group;
NS_ADDREF(*aInstancePtrResult);
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsDocument::FlushPendingNotifications(PRBool aFlushReflows,
PRBool aUpdateViews)
{
- if (aFlushReflows && mScriptGlobalObject) {
- // We should be able to replace all this nsIDocShell* code with
- // code that uses mParentDocument, but mParentDocument is never
- // set in the current code!
+ if (!aFlushReflows || !mScriptGlobalObject) {
+ return NS_OK;
+ }
- nsCOMPtr docShell;
- mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
+ // We should be able to replace all this nsIDocShell* code with code
+ // that uses mParentDocument, but mParentDocument is never set in
+ // the current code!
- nsCOMPtr docShellAsItem =
- do_QueryInterface(docShell);
+ nsCOMPtr docShell;
+ mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
- if (docShellAsItem) {
- nsCOMPtr docShellParent;
- docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
+ nsCOMPtr docShellAsItem(do_QueryInterface(docShell));
- nsCOMPtr win(do_GetInterface(docShellParent));
+ if (docShellAsItem) {
+ nsCOMPtr docShellParent;
+ docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
- if (win) {
- nsCOMPtr dom_doc;
- win->GetDocument(getter_AddRefs(dom_doc));
+ nsCOMPtr win(do_GetInterface(docShellParent));
- nsCOMPtr doc(do_QueryInterface(dom_doc));
+ if (win) {
+ nsCOMPtr dom_doc;
+ win->GetDocument(getter_AddRefs(dom_doc));
- if (doc) {
- // If we have a parent we must flush the parent too to ensure
- // that our container is reflown if its size was changed.
+ nsCOMPtr doc(do_QueryInterface(dom_doc));
- doc->FlushPendingNotifications(aFlushReflows, aUpdateViews);
- }
+ if (doc) {
+ // If we have a parent we must flush the parent too to ensure
+ // that our container is reflown if its size was changed.
+
+ doc->FlushPendingNotifications(aFlushReflows, aUpdateViews);
}
}
+ }
- PRInt32 i, count = mPresShells.Count();
+ PRInt32 i, count = mPresShells.Count();
- for (i = 0; i < count; i++) {
- nsCOMPtr shell =
- NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
+ for (i = 0; i < count; i++) {
+ nsCOMPtr shell =
+ NS_STATIC_CAST(nsIPresShell*, mPresShells[i]);
- if (shell) {
- shell->FlushPendingNotifications(aUpdateViews);
- }
+ if (shell) {
+ shell->FlushPendingNotifications(aUpdateViews);
}
}
@@ -3727,6 +3854,7 @@ NS_IMETHODIMP
nsDocument::GetAndIncrementContentID(PRInt32* aID)
{
*aID = mNextContentID++;
+
return NS_OK;
}
@@ -3735,6 +3863,7 @@ nsDocument::GetBindingManager(nsIBindingManager** aResult)
{
*aResult = mBindingManager;
NS_IF_ADDREF(*aResult);
+
return NS_OK;
}
@@ -3809,13 +3938,15 @@ nsDocument::GetRadioGroup(const nsAString& aName,
nsRadioGroupStruct **aRadioGroup)
{
nsStringKey key(aName);
- nsRadioGroupStruct* radioGroup = (nsRadioGroupStruct*)mRadioGroups.Get(&key);
-
+ nsRadioGroupStruct *radioGroup =
+ NS_STATIC_CAST(nsRadioGroupStruct *, mRadioGroups.Get(&key));
+
if (!radioGroup) {
radioGroup = new nsRadioGroupStruct();
NS_ENSURE_TRUE(radioGroup, NS_ERROR_OUT_OF_MEMORY);
mRadioGroups.Put(&key, radioGroup);
}
+
*aRadioGroup = radioGroup;
return NS_OK;
@@ -3830,6 +3961,7 @@ nsDocument::SetCurrentRadioButton(const nsAString& aName,
if (radioGroup) {
radioGroup->mSelectedRadioButton = aRadio;
}
+
return NS_OK;
}
@@ -3843,6 +3975,7 @@ nsDocument::GetCurrentRadioButton(const nsAString& aName,
*aRadio = radioGroup->mSelectedRadioButton;
NS_IF_ADDREF(*aRadio);
}
+
return NS_OK;
}
@@ -3856,6 +3989,7 @@ nsDocument::AddToRadioGroup(const nsAString& aName,
radioGroup->mRadioButtons.AppendElement(aRadio);
NS_IF_ADDREF(aRadio);
}
+
return NS_OK;
}
@@ -3870,6 +4004,7 @@ nsDocument::RemoveFromRadioGroup(const nsAString& aName,
NS_IF_RELEASE(aRadio);
}
}
+
return NS_OK;
}
@@ -3877,44 +4012,49 @@ NS_IMETHODIMP
nsDocument::WalkRadioGroup(const nsAString& aName,
nsIRadioVisitor* aVisitor)
{
- nsresult rv = NS_OK;
nsRadioGroupStruct* radioGroup = nsnull;
GetRadioGroup(aName, &radioGroup);
- if (radioGroup) {
- PRBool stop = PR_FALSE;
- for (int i = 0; i < radioGroup->mRadioButtons.Count(); i++) {
- aVisitor->Visit(NS_STATIC_CAST(nsIFormControl *,
- radioGroup->mRadioButtons.ElementAt(i)), &stop);
- if (stop) {
- break;
- }
+ if (!radioGroup) {
+ return NS_OK;
+ }
+
+ PRBool stop = PR_FALSE;
+ for (int i = 0; i < radioGroup->mRadioButtons.Count(); i++) {
+ aVisitor->Visit(NS_STATIC_CAST(nsIFormControl *,
+ radioGroup->mRadioButtons.ElementAt(i)),
+ &stop);
+ if (stop) {
+ return NS_OK;
}
}
- return rv;
+
+ return NS_OK;
}
/**
- * Check if bidi enabled (set depending on the presence of RTL
- * characters). If enabled, we should apply the Unicode Bidi Algorithm
+ * Check if bidi enabled (set depending on the presence of RTL
+ * characters). If enabled, we should apply the Unicode Bidi Algorithm
*
- * @lina 07/12/2000
+ * @lina 07/12/2000
*/
NS_IMETHODIMP
nsDocument::GetBidiEnabled(PRBool* aBidiEnabled) const
{
NS_ENSURE_ARG_POINTER(aBidiEnabled);
*aBidiEnabled = mBidiEnabled;
+
return NS_OK;
}
/**
- * Indicate the document contains RTL characters.
+ * Indicate the document contains RTL characters.
*
- * @lina 07/12/2000
+ * @lina 07/12/2000
*/
NS_IMETHODIMP
nsDocument::SetBidiEnabled(PRBool aBidiEnabled)
{
mBidiEnabled = aBidiEnabled;
+
return NS_OK;
}
diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h
index 6b5f9055d2d..93bcbc2fe3b 100644
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -38,9 +38,13 @@
#ifndef nsDocument_h___
#define nsDocument_h___
+#include "nsCOMPtr.h"
+#include "nsAutoPtr.h"
+#include "nsCRT.h"
#include "nsIDocument.h"
#include "nsWeakReference.h"
#include "nsWeakPtr.h"
+#include "nsIArena.h"
#include "nsVoidArray.h"
#include "nsIDOMXMLDocument.h"
#include "nsIDOMDocumentView.h"
@@ -56,6 +60,7 @@
#include "nsIScriptGlobalObject.h"
#include "nsIDOMEventTarget.h"
#include "nsIContent.h"
+#include "nsIEventListenerManager.h"
#include "nsGenericDOMNodeList.h"
#include "nsIPrincipal.h"
#include "nsIBindingManager.h"
@@ -84,51 +89,25 @@ class nsIDTD;
class nsXPathDocumentTearoff;
class nsIRadioVisitor;
class nsIFormControl;
-
struct nsRadioGroupStruct;
-#if 0
-class nsPostData : public nsIPostData {
-public:
- nsPostData(PRBool aIsFile, char* aData);
-
- NS_DECL_ISUPPORTS
-
- virtual PRBool IsFile();
- virtual const char* GetData();
- virtual PRInt32 GetDataLength();
-
-protected:
- virtual ~nsPostData();
-
- PRBool mIsFile;
- char* mData;
- PRInt32 mDataLen;
-};
-#endif
class nsDocHeaderData
{
public:
nsDocHeaderData(nsIAtom* aField, const nsAString& aData)
+ : mField(aField), mData(aData), mNext(nsnull)
{
- mField = aField;
- NS_IF_ADDREF(mField);
- mData.Assign(aData);
- mNext = nsnull;
- }
- ~nsDocHeaderData(void)
- {
- NS_IF_RELEASE(mField);
- if (nsnull != mNext) {
- delete mNext;
- mNext = nsnull;
- }
}
- nsIAtom* mField;
- nsString mData;
- nsDocHeaderData* mNext;
+ ~nsDocHeaderData(void)
+ {
+ delete mNext;
+ }
+
+ nsCOMPtr mField;
+ nsString mData;
+ nsDocHeaderData* mNext;
};
// Represents the children of a document (prolog, epilog and
@@ -145,6 +124,8 @@ public:
void DropReference();
protected:
+ nsDocumentChildNodes(); // Not implemented
+
nsIDocument* mDocument;
};
@@ -159,7 +140,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMSTYLESHEETLIST
-
+
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
@@ -167,7 +148,7 @@ public:
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD EndReflow(nsIDocument *aDocument,
- nsIPresShell* aShell) { return NS_OK; }
+ nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
nsIContent* aContent,
nsISupports* aSubContent) { return NS_OK; }
@@ -183,7 +164,7 @@ public:
nsChangeHint aHint) { return NS_OK; }
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
nsIContent* aContainer,
- PRInt32 aNewIndexInContainer)
+ PRInt32 aNewIndexInContainer)
{ return NS_OK; }
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
nsIContent* aContainer,
@@ -224,28 +205,6 @@ protected:
};
-// Helper structs for the content->subdoc map
-
-class SubDocMapEntry : public PLDHashEntryHdr
-{
-public:
- // Both of these are strong references
- nsIContent *mKey; // must be first, to look like PLDHashEntryStub
- nsIDocument *mSubDocument;
-};
-
-struct FindContentData
-{
- FindContentData(nsIDocument *aSubDoc)
- : mSubDocument(aSubDoc), mResult(nsnull)
- {
- }
-
- nsISupports *mSubDocument;
- nsIContent *mResult;
-};
-
-
// Base class for our document implementations.
//
// Note that this class *implements* nsIDOMXMLDocument, but it's not
@@ -255,8 +214,8 @@ struct FindContentData
// nsIDOMXMLDocument's. nsDocument's QI should *not* claim to support
// nsIDOMXMLDocument unless someone writes a real implementation of
// the interface.
-class nsDocument : public nsIDocument,
- public nsIDOMXMLDocument, // inherits nsIDOMDocument
+class nsDocument : public nsIDocument,
+ public nsIDOMXMLDocument, // inherits nsIDOMDocument
public nsIDOMNSDocument,
public nsIDOMDocumentEvent,
public nsIDOM3DocumentEvent,
@@ -275,6 +234,8 @@ class nsDocument : public nsIDocument,
public:
NS_DECL_ISUPPORTS
+ NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
+
NS_IMETHOD GetArena(nsIArena** aArena);
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
@@ -293,7 +254,7 @@ public:
/**
* Return the title of the document. May return null.
*/
- virtual const nsString* GetDocumentTitle() const;
+ NS_IMETHOD GetDocumentTitle(nsAString& aTitle) const;
/**
* Return the URL for the document. May return null.
@@ -396,13 +357,10 @@ public:
* it's presentation context (presentation context's must not be
* shared among multiple presentation shell's).
*/
-#if 0
- // XXX Temp hack: moved to nsMarkupDocument
NS_IMETHOD CreateShell(nsIPresContext* aContext,
nsIViewManager* aViewManager,
nsIStyleSet* aStyleSet,
nsIPresShell** aInstancePtrResult);
-#endif
virtual PRBool DeleteShell(nsIPresShell* aShell);
virtual PRInt32 GetNumberOfShells();
NS_IMETHOD GetShellAt(PRInt32 aIndex, nsIPresShell** aShell);
@@ -425,7 +383,7 @@ public:
NS_IMETHOD GetRootContent(nsIContent** aRoot);
NS_IMETHOD SetRootContent(nsIContent* aRoot);
- /**
+ /**
* Get the direct children of the document - content in
* the prolog, the root content and content in the epilog.
*/
@@ -444,7 +402,7 @@ public:
NS_IMETHOD GetIndexOfStyleSheet(nsIStyleSheet* aSheet, PRInt32* aIndex);
virtual void AddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags);
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
-
+
NS_IMETHOD UpdateStyleSheets(nsCOMArray& aOldSheets,
nsCOMArray& aNewSheets);
virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
@@ -456,7 +414,7 @@ public:
/**
* Set the object from which a document can get a script context.
- * This is the context within which all scripts (during document
+ * This is the context within which all scripts (during document
* creation and during event handling) will run.
*/
NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject);
@@ -464,7 +422,7 @@ public:
/**
* Get the script loader for this document
- */
+ */
NS_IMETHOD GetScriptLoader(nsIScriptLoader** aScriptLoader);
/**
@@ -543,7 +501,7 @@ public:
nsIFormControl* aRadio);
NS_IMETHOD RemoveFromRadioGroup(const nsAString& aName,
nsIFormControl* aRadio);
-
+
// for radio group
nsresult GetRadioGroup(const nsAString& aName,
nsRadioGroupStruct **aRadioGroup);
@@ -599,15 +557,10 @@ public:
// nsIDOM3EventTarget
NS_DECL_NSIDOM3EVENTTARGET
- NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
- nsEvent* aEvent,
- nsIDOMEvent** aDOMEvent,
- PRUint32 aFlags,
+ NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
+ nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
nsEventStatus* aEventStatus);
- NS_IMETHOD_(PRBool) EventCaptureRegistration(PRInt32 aCapturerIncrement);
-
-
NS_IMETHOD SetDocumentURL(nsIURI* aURI);
virtual nsresult Init();
@@ -621,56 +574,74 @@ protected:
virtual already_AddRefed InternalGetStyleSheetAt(PRInt32 aIndex);
virtual PRInt32 InternalGetNumberOfStyleSheets();
- nsDocument();
- virtual ~nsDocument();
+ nsresult doCreateShell(nsIPresContext* aContext,
+ nsIViewManager* aViewManager, nsIStyleSet* aStyleSet,
+ nsCompatibility aCompatMode,
+ nsIPresShell** aInstancePtrResult);
- nsIArena* mArena;
+ nsDocument();
+ virtual ~nsDocument();
+
+ nsCOMPtr mArena;
nsString mDocumentTitle;
- nsIURI* mDocumentURL;
+ nsCOMPtr mDocumentURL;
nsCOMPtr mDocumentBaseURL;
nsCOMPtr mPrincipal;
- PRUint32 mLoadFlags; // load flags of the document's channel
+
nsWeakPtr mDocumentLoadGroup;
+
nsWeakPtr mDocumentContainer;
nsString mCharacterSet;
PRInt32 mCharacterSetSource;
-
+
nsVoidArray mCharSetObservers;
nsIDocument* mParentDocument;
PLDHashTable *mSubDocuments;
- nsVoidArray mPresShells;
- nsCOMArray mChildren; // contains owning references
- nsIContent* mRootContent; // a weak reference to the only element in
- // mChildren, or null if no such element exists.
+ nsSmallVoidArray mPresShells;
+
+ // Array of owning references to all children
+ nsCOMArray mChildren;
+
+ // A weak reference to the only element in mChildren, or null if no
+ // such element exists.
+ nsIContent* mRootContent;
+
nsCOMArray mStyleSheets;
- nsAutoVoidArray mObservers; // basically always has at least 1 entry
+
+ // Basically always has at least 1 entry
+ nsAutoVoidArray mObservers;
nsCOMPtr mScriptGlobalObject;
- nsIEventListenerManager* mListenerManager;
- PRBool mInDestructor;
+ nsCOMPtr mListenerManager;
nsCOMPtr mDOMStyleSheets;
nsCOMPtr mScriptLoader;
nsDocHeaderData* mHeaderData;
nsCOMPtr mLineBreaker;
nsCOMPtr mWordBreaker;
- nsDocumentChildNodes* mChildNodes;
- // A content ID counter used to give a monotonically increasing ID to the content
- // objects in the document's content model
+
+ nsRefPtr mChildNodes;
+
+ // A content ID counter used to give a monotonically increasing ID
+ // to the content objects in the document's content model
PRInt32 mNextContentID;
nsHashtable mRadioGroups;
- PRBool mBidiEnabled;
-
nsCOMPtr mBindingManager;
nsCOMPtr mNodeInfoManager;
- PRBool mIsGoingAway; // True if the document is being destroyed.
+ // True if the document is being destroyed.
+ PRPackedBool mIsGoingAway;
+
+ // True if BIDI is enabled.
+ PRPackedBool mBidiEnabled;
+
+ // True if the document is being destroyed.
+ PRPackedBool mInDestructor;
nsSupportsHashtable* mBoxObjectTable;
- PRInt32 mNumCapturers; //Number of capturing event handlers in doc. Used to optimize event delivery.
nsSupportsHashtable mContentWrapperHash;
diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp
index fe0a4835cef..a4f208ff357 100644
--- a/content/base/src/nsDocumentViewer.cpp
+++ b/content/base/src/nsDocumentViewer.cpp
@@ -1166,7 +1166,7 @@ NS_IMETHODIMP
DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
{
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
- return CallQueryInterface(mDocument.get(), aResult);
+ return CallQueryInterface(mDocument, aResult);
}
NS_IMETHODIMP
diff --git a/content/base/src/nsPrintEngine.cpp b/content/base/src/nsPrintEngine.cpp
index 3aab73eb849..1d5bfbc6e98 100644
--- a/content/base/src/nsPrintEngine.cpp
+++ b/content/base/src/nsPrintEngine.cpp
@@ -1873,9 +1873,10 @@ nsPrintEngine::GetWebShellTitleAndURL(nsIWebShell* aWebShell,
*aTitle = nsnull;
*aURLStr = nsnull;
- const nsString* docTitle = aDoc->GetDocumentTitle();
- if (docTitle && !docTitle->IsEmpty()) {
- *aTitle = ToNewUnicode(*docTitle);
+ nsAutoString docTitle;
+ aDoc->GetDocumentTitle(docTitle);
+ if (!docTitle.IsEmpty()) {
+ *aTitle = ToNewUnicode(docTitle);
}
nsCOMPtr url;
diff --git a/content/base/src/nsXMLContentSerializer.cpp b/content/base/src/nsXMLContentSerializer.cpp
index 0a3d04cd092..f6b52fc9e3b 100644
--- a/content/base/src/nsXMLContentSerializer.cpp
+++ b/content/base/src/nsXMLContentSerializer.cpp
@@ -444,7 +444,6 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
*getter_AddRefs(attrPrefix));
if (namespaceID == kNameSpaceID_XMLNS) {
- PRBool hasPrefix = attrPrefix ? PR_TRUE : PR_FALSE;
content->GetAttr(namespaceID, attrName, uriStr);
if (!attrPrefix) {
diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp
index ebe844b0f6c..869cfee9dd4 100644
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -1529,10 +1529,10 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return nsnull;
}
-nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
- nsIPresContext* aPresContext,
- const nsAString& aEventType,
- nsEvent *aEvent)
+nsresult
+NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
+ nsIPresContext* aPresContext, const nsAString& aEventType,
+ nsEvent *aEvent)
{
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent, aEventType);
@@ -1543,7 +1543,9 @@ nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
return CallQueryInterface(it, aInstancePtrResult);
}
-nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent)
+nsresult
+NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext,
+ nsEvent *aEvent)
{
return NS_ERROR_FAILURE;
}
diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp
index 1d46ee775d2..b869e892f1c 100644
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -493,19 +493,6 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
listeners->AppendElement((void*)ls);
NS_ADDREF(aListener);
}
-
- if (aFlags & NS_EVENT_FLAG_CAPTURE) {
- //If a capturer is set up on a content object it must register that with its doc
- nsCOMPtr document;
- nsCOMPtr content(do_QueryInterface(mTarget));
- if (content) {
- content->GetDocument(*getter_AddRefs(document));
- if (document) {
- //Increment capturers by 1
- document->EventCaptureRegistration(1);
- }
- }
- }
}
return NS_OK;
@@ -561,19 +548,6 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
}
}
- if (listenerRemoved && aFlags & NS_EVENT_FLAG_CAPTURE) {
- //If a capturer is set up on a content object it must register that with its doc
- nsCOMPtr document;
- nsCOMPtr content(do_QueryInterface(mTarget));
- if (content) {
- content->GetDocument(*getter_AddRefs(document));
- if (document) {
- //Decrement capturers by 1
- document->EventCaptureRegistration(-1);
- }
- }
- }
-
return NS_OK;
}
diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp
index 962b980ced4..aeb8626a50e 100644
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -90,7 +90,7 @@
#include "nsXULAtoms.h"
#include "nsIDOMXULElement.h"
-#include "nsIDOMXULDocument.h"
+#include "nsIDOMDocument.h"
#include "nsIDOMKeyEvent.h"
#include "nsIObserverService.h"
#include "nsIDocShell.h"
@@ -641,7 +641,6 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
nsCOMPtr focusController;
nsCOMPtr focusedElement;
nsCOMPtr focusedWindow;
- nsCOMPtr xulDoc = do_QueryInterface(mDocument);
nsCOMPtr globalObj;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
@@ -4479,7 +4478,7 @@ nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent,
}
}
- *aPreventDefault = status == nsEventStatus_eConsumeNoDefault ? PR_FALSE : PR_TRUE;
+ *aPreventDefault = status != nsEventStatus_eConsumeNoDefault;
}
}
diff --git a/content/html/document/src/Makefile.in b/content/html/document/src/Makefile.in
index f48f82c13f8..98e93e4edf0 100644
--- a/content/html/document/src/Makefile.in
+++ b/content/html/document/src/Makefile.in
@@ -68,7 +68,6 @@ CPPSRCS = \
nsMediaDocument.cpp \
nsPluginDocument.cpp \
nsImageDocument.cpp \
- nsMarkupDocument.cpp \
nsWyciwygChannel.cpp \
nsWyciwygProtocolHandler.cpp \
$(NULL)
diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index b07ab58f1c7..bfd3d88441a 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -54,14 +54,14 @@
#include "nsIStyleSet.h"
#include "nsHTMLAtoms.h"
#include "nsLayoutAtoms.h"
-#include "nsIPresShell.h"
-#include "nsIPresContext.h"
+#include "nsIPresShell.h"
+#include "nsIPresContext.h"
#include "nsIHTMLContent.h"
#include "nsIDOMNode.h" // for Find
#include "nsIDOMNodeList.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
-#include "nsIDOMComment.h"
+#include "nsIDOMComment.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMWindowInternal.h"
@@ -130,7 +130,7 @@
#include "nsIWyciwygChannel.h"
#include "nsIPrompt.h"
-//AHMED 12-2
+//AHMED 12-2
#include "nsBidiUtils.h"
#include "nsIEditingSession.h"
@@ -169,25 +169,34 @@ nsrefcnt nsHTMLDocument::gRefCntRDFService = 0;
static int PR_CALLBACK
MyPrefChangedCallback(const char*aPrefName, void* instance_data)
{
- nsresult rv;
- nsCOMPtr prefs =
- do_GetService(NS_PREF_CONTRACTID, &rv);
- PRUnichar* detector_name = nsnull;
- if(NS_SUCCEEDED(rv) && NS_SUCCEEDED(
- rv = prefs->GetLocalizedUnicharPref("intl.charset.detector",
- &detector_name)))
- {
- if(detector_name && *detector_name) {
- PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,DETECTOR_CONTRACTID_MAX);
- PL_strncat(g_detector_contractid, NS_ConvertUCS2toUTF8(detector_name).get(),DETECTOR_CONTRACTID_MAX);
- gPlugDetector = PR_TRUE;
- } else {
- g_detector_contractid[0]=0;
- gPlugDetector = PR_FALSE;
- }
- PR_FREEIF(detector_name);
- }
- return 0;
+ nsresult rv;
+ nsCOMPtr prefs =
+ do_GetService("@mozilla.org/preferences;1", &rv);
+ if (NS_FAILED(rv)) {
+ return 0;
+ }
+
+ nsXPIDLString detector_name;
+
+ rv = prefs->GetLocalizedUnicharPref("intl.charset.detector",
+ getter_Copies(detector_name));
+ if (NS_FAILED(rv)) {
+ return 0;
+ }
+
+ if (detector_name.Length() > 0) {
+ PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,
+ DETECTOR_CONTRACTID_MAX);
+ PL_strncat(g_detector_contractid,
+ NS_ConvertUCS2toUTF8(detector_name).get(),
+ DETECTOR_CONTRACTID_MAX);
+ gPlugDetector = PR_TRUE;
+ } else {
+ g_detector_contractid[0]=0;
+ gPlugDetector = PR_FALSE;
+ }
+
+ return 0;
}
// ==================================================================
@@ -264,7 +273,7 @@ IdAndNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
{
IdAndNameMapEntry *e = NS_STATIC_CAST(IdAndNameMapEntry *, entry);
- // An entry is being cleared, let the entry its own cleanup.
+ // An entry is being cleared, let the entry do its own cleanup.
e->~IdAndNameMapEntry();
}
@@ -278,34 +287,17 @@ IdAndNameHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
new (entry) IdAndNameMapEntry(*keyStr);
}
+ // NOTE! nsDocument::operator new() zeroes out all members, so don't
+ // bother initializing members to 0.
+
nsHTMLDocument::nsHTMLDocument()
- : nsMarkupDocument(),
- mBaseURL(nsnull),
- mBaseTarget(nsnull),
- mLastModified(nsnull),
- mReferrer(nsnull),
- mNumForms(0),
- mIsWriting(0),
- mDomainWasSet(PR_FALSE),
- mEditingIsOn(PR_FALSE)
+ : mCompatMode(eCompatibility_NavQuirks),
+ mTexttype(IBMBIDI_TEXTTYPE_LOGICAL)
{
- mImages = nsnull;
- mApplets = nsnull;
- mEmbeds = nsnull;
- mLinks = nsnull;
- mAnchors = nsnull;
- mLayers = nsnull;
- mParser = nsnull;
- mCompatMode = eCompatibility_NavQuirks;
- mCSSLoader = nsnull;
- mForms = nsnull;
- mIsWriting = 0;
- mWriteLevel = 0;
- mWyciwygSessionCnt = 0;
+ // NOTE! nsDocument::operator new() zeroes out all members, so don't
+ // bother initializing members to 0.
- mTexttype = IBMBIDI_TEXTTYPE_LOGICAL;
-
if (gRefCntRDFService++ == 0)
{
CallGetService(kRDFServiceCID, &gRDF);
@@ -314,43 +306,19 @@ nsHTMLDocument::nsHTMLDocument()
nsHTMLDocument::~nsHTMLDocument()
{
- NS_IF_RELEASE(mImages);
- NS_IF_RELEASE(mApplets);
- NS_IF_RELEASE(mEmbeds);
- NS_IF_RELEASE(mLinks);
- NS_IF_RELEASE(mAnchors);
- NS_IF_RELEASE(mLayers);
if (mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
}
+
if (mStyleAttrStyleSheet) {
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
}
- NS_IF_RELEASE(mBaseURL);
- if (nsnull != mBaseTarget) {
- delete mBaseTarget;
- mBaseTarget = nsnull;
- }
- if (nsnull != mLastModified) {
- delete mLastModified;
- mLastModified = nsnull;
- }
- if (nsnull != mReferrer) {
- delete mReferrer;
- mReferrer = nsnull;
- }
- NS_IF_RELEASE(mParser);
- mImageMaps->Clear();
- NS_IF_RELEASE(mForms);
- if (mCSSLoader) {
- mCSSLoader->DropDocumentReference(); // release weak ref
- }
if (--gRefCntRDFService == 0) {
NS_IF_RELEASE(gRDF);
}
- if (mIdAndNameHashIsLive) {
+ if (mIdAndNameHashTable.ops) {
PL_DHashTableFinish(&mIdAndNameHashTable);
}
}
@@ -375,9 +343,6 @@ nsHTMLDocument::Init()
nsresult rv = nsDocument::Init();
NS_ENSURE_SUCCESS(rv, rv);
- rv = NS_NewISupportsArray(getter_AddRefs(mImageMaps));
- NS_ENSURE_SUCCESS(rv, rv);
-
static PLDHashTableOps hash_table_ops =
{
PL_DHashAllocTable,
@@ -391,10 +356,13 @@ nsHTMLDocument::Init()
IdAndNameHashInitEntry
};
- mIdAndNameHashIsLive = PL_DHashTableInit(&mIdAndNameHashTable,
- &hash_table_ops, nsnull,
- sizeof(IdAndNameMapEntry), 16);
- NS_ENSURE_TRUE(mIdAndNameHashIsLive, NS_ERROR_OUT_OF_MEMORY);
+ PRBool ok = PL_DHashTableInit(&mIdAndNameHashTable, &hash_table_ops, nsnull,
+ sizeof(IdAndNameMapEntry), 16);
+ if (!ok) {
+ mIdAndNameHashTable.ops = nsnull;
+
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
PrePopulateHashTables();
@@ -402,70 +370,82 @@ nsHTMLDocument::Init()
}
+NS_IMETHODIMP
+nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
+{
+ nsresult rv = nsDocument::Reset(aChannel, aLoadGroup);
+
+ if (NS_SUCCEEDED(rv) && aChannel) {
+ aChannel->GetLoadFlags(&mLoadFlags);
+ }
+
+ return rv;
+}
+
NS_IMETHODIMP
nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
{
- nsresult result = nsDocument::ResetToURI(aURI, aLoadGroup);
+ mLoadFlags = nsIRequest::LOAD_NORMAL;
- if (NS_SUCCEEDED(result))
- result = BaseResetToURI(aURI);
+ nsresult rv = nsDocument::ResetToURI(aURI, aLoadGroup);
+ NS_ENSURE_SUCCESS(rv, rv);
- return result;
+ return BaseResetToURI(aURI);
}
nsresult
nsHTMLDocument::BaseResetToURI(nsIURI *aURL)
{
- nsresult result = NS_OK;
+ nsresult rv = NS_OK;
InvalidateHashTables();
PrePopulateHashTables();
- NS_IF_RELEASE(mImages);
- NS_IF_RELEASE(mApplets);
- NS_IF_RELEASE(mEmbeds);
- NS_IF_RELEASE(mLinks);
- NS_IF_RELEASE(mAnchors);
- NS_IF_RELEASE(mLayers);
+ mImages = nsnull;
+ mApplets = nsnull;
+ mEmbeds = nsnull;
+ mLinks = nsnull;
+ mAnchors = nsnull;
mBodyContent = nsnull;
- mImageMaps->Clear();
- NS_IF_RELEASE(mForms);
+ mImageMaps.Clear();
+ mForms = nsnull;
if (aURL) {
if (!mAttrStyleSheet) {
- result = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURL,
- this);
+ rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURL, this);
}
else {
- result = mAttrStyleSheet->Reset(aURL);
+ rv = mAttrStyleSheet->Reset(aURL);
}
- if (NS_SUCCEEDED(result)) {
- AddStyleSheet(mAttrStyleSheet, 0); // tell the world about our new style sheet
+ if (NS_SUCCEEDED(rv)) {
+ // tell the world about our new style sheet
+ AddStyleSheet(mAttrStyleSheet, 0);
if (!mStyleAttrStyleSheet) {
- result = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet),
- aURL, this);
+ rv = NS_NewHTMLCSSStyleSheet(getter_AddRefs(mStyleAttrStyleSheet),
+ aURL, this);
}
else {
- result = mStyleAttrStyleSheet->Reset(aURL);
+ rv = mStyleAttrStyleSheet->Reset(aURL);
}
- if (NS_SUCCEEDED(result)) {
- AddStyleSheet(mStyleAttrStyleSheet, 0); // tell the world about our new style sheet
+ if (NS_SUCCEEDED(rv)) {
+ // tell the world about our new style sheet
+ AddStyleSheet(mStyleAttrStyleSheet, 0);
}
}
}
- NS_ASSERTION(mWyciwygChannel == nsnull, "nsHTMLDocument::Reset() - Wyciwyg Channel still exists!");
+ NS_ASSERTION(!mWyciwygChannel,
+ "nsHTMLDocument::Reset() - Wyciwyg Channel still exists!");
+
mWyciwygChannel = nsnull;
- if (mBaseTarget) {
- mBaseTarget->Truncate();
- }
+ mBaseTarget.Truncate();
- return result;
+ return rv;
}
@@ -475,34 +455,36 @@ nsHTMLDocument::CreateShell(nsIPresContext* aContext,
nsIStyleSet* aStyleSet,
nsIPresShell** aInstancePtrResult)
{
- return doCreateShell(aContext, aViewManager, aStyleSet,
- mCompatMode, aInstancePtrResult);
+ return doCreateShell(aContext, aViewManager, aStyleSet, mCompatMode,
+ aInstancePtrResult);
}
-// The following Try*Charset will return PR_FALSE only if the charset source
-// should be considered (ie. aCharsetSource < thisCharsetSource) but we failed
-// to get the charset from this source.
+// The following Try*Charset will return PR_FALSE only if the charset source
+// should be considered (ie. aCharsetSource < thisCharsetSource) but we failed
+// to get the charset from this source.
-PRBool
+PRBool
nsHTMLDocument::TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
- PRInt32& aCharsetSource,
- nsAString& aCharset)
+ PRInt32& aCharsetSource, nsAString& aCharset)
{
- PRInt32 requestCharsetSource;
- nsresult rv;
-
if (aMarkupDV) {
- rv = aMarkupDV->GetHintCharacterSetSource(&requestCharsetSource);
+ PRInt32 requestCharsetSource;
+ nsresult rv = aMarkupDV->GetHintCharacterSetSource(&requestCharsetSource);
+
if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
PRUnichar* requestCharset;
rv = aMarkupDV->GetHintCharacterSet(&requestCharset);
aMarkupDV->SetHintCharacterSetSource((PRInt32)(kCharsetUninitialized));
- if(requestCharsetSource <= aCharsetSource)
+
+ if(requestCharsetSource <= aCharsetSource)
return PR_TRUE;
+
if(NS_SUCCEEDED(rv)) {
aCharsetSource = requestCharsetSource;
aCharset = requestCharset;
+
Recycle(requestCharset);
+
return PR_TRUE;
}
}
@@ -511,33 +493,33 @@ nsHTMLDocument::TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
}
-PRBool
+PRBool
nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
nsIDocumentCharsetInfo* aDocInfo,
- PRInt32& aCharsetSource,
+ PRInt32& aCharsetSource,
nsAString& aCharset)
{
nsresult rv = NS_OK;
- if(kCharsetFromUserForced <= aCharsetSource)
+ if(kCharsetFromUserForced <= aCharsetSource)
return PR_TRUE;
PRUnichar* forceCharsetFromWebShell = nsnull;
- if (aMarkupDV)
+ if (aMarkupDV) {
rv = aMarkupDV->GetForceCharacterSet(&forceCharsetFromWebShell);
+ }
- if(NS_SUCCEEDED(rv) && forceCharsetFromWebShell)
- {
+ if(NS_SUCCEEDED(rv) && forceCharsetFromWebShell) {
aCharset = forceCharsetFromWebShell;
Recycle(forceCharsetFromWebShell);
//TODO: we should define appropriate constant for force charset
- aCharsetSource = kCharsetFromUserForced;
+ aCharsetSource = kCharsetFromUserForced;
} else if (aDocInfo) {
nsCOMPtr csAtom;
aDocInfo->GetForcedCharset(getter_AddRefs(csAtom));
if (csAtom) {
csAtom->ToString(aCharset);
- aCharsetSource = kCharsetFromUserForced;
+ aCharsetSource = kCharsetFromUserForced;
aDocInfo->SetForcedCharset(nsnull);
return PR_TRUE;
}
@@ -546,15 +528,16 @@ nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
return PR_FALSE;
}
-PRBool
-nsHTMLDocument::TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor,
- PRInt32& aCharsetSource,
+PRBool
+nsHTMLDocument::TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor,
+ PRInt32& aCharsetSource,
nsAString& aCharset)
{
nsresult rv;
-
- if (kCharsetFromCache <= aCharsetSource)
+
+ if (kCharsetFromCache <= aCharsetSource) {
return PR_TRUE;
+ }
nsXPIDLCString cachedCharset;
rv = aCacheDescriptor->GetMetaDataElement("charset",
@@ -563,42 +546,53 @@ nsHTMLDocument::TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor,
{
aCharset.Assign(NS_ConvertASCIItoUCS2(cachedCharset));
aCharsetSource = kCharsetFromCache;
+
return PR_TRUE;
}
return PR_FALSE;
}
-PRBool
+PRBool
nsHTMLDocument::TryBookmarkCharset(nsAFlatCString* aUrlSpec,
- PRInt32& aCharsetSource,
+ PRInt32& aCharsetSource,
nsAString& aCharset)
{
- nsresult rv;
- if (kCharsetFromBookmarks <= aCharsetSource)
+ if (kCharsetFromBookmarks <= aCharsetSource) {
return PR_TRUE;
+ }
+
+ if (!gRDF) {
+ return PR_FALSE;
+ }
nsCOMPtr datasource;
- if (gRDF && NS_SUCCEEDED(rv = gRDF->GetDataSource("rdf:bookmarks", getter_AddRefs(datasource)))) {
- nsCOMPtr bookmarks = do_QueryInterface(datasource);
- if (bookmarks) {
- if (aUrlSpec) {
- nsXPIDLString pBookmarkedCharset;
- rv = bookmarks->GetLastCharset(aUrlSpec->get(), getter_Copies(pBookmarkedCharset));
- if (NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE)) {
- aCharset = pBookmarkedCharset;
- aCharsetSource = kCharsetFromBookmarks;
- return PR_TRUE;
- }
- }
+ nsresult rv = gRDF->GetDataSource("rdf:bookmarks",
+ getter_AddRefs(datasource));
+
+ if (NS_FAILED(rv)) {
+ return PR_FALSE;
+ }
+
+ nsCOMPtr bookmarks(do_QueryInterface(datasource));
+ if (bookmarks && aUrlSpec) {
+ nsXPIDLString pBookmarkedCharset;
+ rv = bookmarks->GetLastCharset(aUrlSpec->get(),
+ getter_Copies(pBookmarkedCharset));
+ if (NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE)) {
+ aCharset = pBookmarkedCharset;
+ aCharsetSource = kCharsetFromBookmarks;
+
+ return PR_TRUE;
}
}
+
return PR_FALSE;
}
-PRBool
+PRBool
nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
- PRInt32& aCharsetSource,
+ PRInt32& aCharsetSource,
nsAString& aCharset)
{
if (aDocInfo) {
@@ -613,7 +607,7 @@ nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
source = kCharsetFromHintPrevDoc;
else if (kCharsetFromCache <= parentSource)
source = kCharsetFromParentFrame;
- else
+ else
return PR_FALSE;
if (source < aCharsetSource)
@@ -622,25 +616,27 @@ nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
aDocInfo->GetParentCharset(getter_AddRefs(csAtom));
if (csAtom) {
csAtom->ToString(aCharset);
- aCharsetSource = source;
+ aCharsetSource = source;
return PR_TRUE;
}
}
return PR_FALSE;
}
-PRBool
-nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource,
+PRBool
+nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource,
nsAString& aCharset)
{
if (kCharsetFromWeakDocTypeDefault <= aCharsetSource)
return PR_TRUE;
-
- aCharset.Assign(NS_LITERAL_STRING("ISO-8859-1")); // fallback value in case webShell return error
+
+ // fallback value in case webShell return error
+ aCharset.Assign(NS_LITERAL_STRING("ISO-8859-1"));
nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
nsXPIDLString defCharset;
- nsresult rv = prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset));
+ nsresult rv = prefs->GetLocalizedUnicharPref("intl.charset.default",
+ getter_Copies(defCharset));
if (NS_SUCCEEDED(rv) && !defCharset.IsEmpty()) {
aCharset.Assign(defCharset);
aCharsetSource = kCharsetFromWeakDocTypeDefault;
@@ -649,44 +645,46 @@ nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource,
return PR_TRUE;
}
-PRBool
-nsHTMLDocument::TryChannelCharset(nsIChannel *aChannel,
- PRInt32& aCharsetSource,
- nsAString& aCharset)
+PRBool
+nsHTMLDocument::TryChannelCharset(nsIChannel *aChannel,
+ PRInt32& aCharsetSource, nsAString& aCharset)
{
- if(kCharsetFromChannel <= aCharsetSource)
+ if(kCharsetFromChannel <= aCharsetSource) {
return PR_TRUE;
+ }
if (aChannel) {
nsCAutoString charsetVal;
nsresult rv = aChannel->GetContentCharset(charsetVal);
if (NS_SUCCEEDED(rv)) {
- nsCOMPtr calias(do_CreateInstance(kCharsetAliasCID, &rv));
+ nsCOMPtr calias(do_CreateInstance(kCharsetAliasCID));
if (calias) {
nsAutoString preferred;
- rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal), preferred);
+ rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal),
+ preferred);
if(NS_SUCCEEDED(rv)) {
aCharset = preferred;
aCharsetSource = kCharsetFromChannel;
return PR_TRUE;
- }
+ }
}
- }
+ }
}
return PR_FALSE;
}
-PRBool
+PRBool
nsHTMLDocument::TryDefaultCharset( nsIMarkupDocumentViewer* aMarkupDV,
- PRInt32& aCharsetSource,
+ PRInt32& aCharsetSource,
nsAString& aCharset)
{
- if(kCharsetFromUserDefault <= aCharsetSource)
+ if(kCharsetFromUserDefault <= aCharsetSource)
return PR_TRUE;
PRUnichar* defaultCharsetFromWebShell = NULL;
if (aMarkupDV) {
- nsresult rv = aMarkupDV->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
+ nsresult rv =
+ aMarkupDV->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
if(NS_SUCCEEDED(rv)) {
aCharset = defaultCharsetFromWebShell;
Recycle(defaultCharsetFromWebShell);
@@ -697,9 +695,8 @@ nsHTMLDocument::TryDefaultCharset( nsIMarkupDocumentViewer* aMarkupDV,
return PR_FALSE;
}
-void
-nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell,
- nsAString& aCharset,
+void
+nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsAString& aCharset,
const char* aCommand)
{
nsCOMPtr cdetflt;
@@ -709,39 +706,47 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell,
nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID));
if(pref) {
PRUnichar* detector_name = nsnull;
- rv_detect = pref->GetLocalizedUnicharPref("intl.charset.detector", &detector_name);
+ rv_detect = pref->GetLocalizedUnicharPref("intl.charset.detector",
+ &detector_name);
if(NS_SUCCEEDED(rv_detect)) {
- PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,DETECTOR_CONTRACTID_MAX);
- PL_strncat(g_detector_contractid, NS_ConvertUCS2toUTF8(detector_name).get(),DETECTOR_CONTRACTID_MAX);
+ PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE,
+ DETECTOR_CONTRACTID_MAX);
+ PL_strncat(g_detector_contractid,
+ NS_ConvertUCS2toUTF8(detector_name).get(),
+ DETECTOR_CONTRACTID_MAX);
gPlugDetector = PR_TRUE;
PR_FREEIF(detector_name);
}
- pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull);
+ pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback,
+ nsnull);
}
gInitDetector = PR_TRUE;
}
if (gPlugDetector) {
- nsCOMPtr cdet = do_CreateInstance(g_detector_contractid, &rv_detect);
- if(NS_SUCCEEDED(rv_detect)) {
- cdetflt = do_CreateInstance(NS_CHARSET_DETECTION_ADAPTOR_CONTRACTID, &rv_detect);
- if(NS_SUCCEEDED(rv_detect)) {
- nsCOMPtr adp = do_QueryInterface(cdetflt, &rv_detect);
- if(cdetflt && NS_SUCCEEDED( rv_detect )) {
- nsCOMPtr wss = do_QueryInterface(aDocShell, &rv_detect);
- if( NS_SUCCEEDED( rv_detect )) {
- rv_detect = adp->Init(wss, cdet, this, mParser, PromiseFlatString(aCharset).get(), aCommand);
+ nsCOMPtr cdet =
+ do_CreateInstance(g_detector_contractid, &rv_detect);
+ if (NS_SUCCEEDED(rv_detect)) {
+ cdetflt = do_CreateInstance(NS_CHARSET_DETECTION_ADAPTOR_CONTRACTID,
+ &rv_detect);
- // The current implementation for SetParserFilter needs to
- // be changed to be more XPCOM friendly. See bug #40149
- if (mParser)
- nsCOMPtr oldFilter = getter_AddRefs(mParser->SetParserFilter(cdetflt));
- }
+ nsCOMPtr adp = do_QueryInterface(cdetflt);
+ if (adp) {
+ nsCOMPtr wss = do_QueryInterface(aDocShell);
+ if (wss) {
+ rv_detect = adp->Init(wss, cdet, this, mParser,
+ PromiseFlatString(aCharset).get(), aCommand);
+
+ // The current implementation for SetParserFilter needs to
+ // be changed to be more XPCOM friendly. See bug #40149
+ if (mParser)
+ nsCOMPtr oldFilter =
+ getter_AddRefs(mParser->SetParserFilter(cdetflt));
}
}
}
else {
- // IF we cannot create the detector, don't bother to
+ // IF we cannot create the detector, don't bother to
// create one next time.
gPlugDetector = PR_FALSE;
}
@@ -753,31 +758,22 @@ nsHTMLDocument::RetrieveRelevantHeaders(nsIChannel *aChannel)
{
nsAutoString lastModified;
mHttpChannel = do_QueryInterface(aChannel);
+ nsresult rv;
if (mHttpChannel) {
nsCAutoString lastModHeader;
- nsresult rv = mHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"),
- lastModHeader);
+ rv = mHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"),
+ lastModHeader);
if (NS_SUCCEEDED(rv)) {
CopyASCIItoUCS2(lastModHeader, lastModified);
SetLastModified(lastModified);
}
-
- nsCAutoString referrerHeader;
- // The misspelled key 'referer' is as per the HTTP spec
- rv = mHttpChannel->GetRequestHeader(NS_LITERAL_CSTRING("referer"),
- referrerHeader);
-
- if (NS_SUCCEEDED(rv)) {
- SetReferrer(NS_ConvertASCIItoUCS2(referrerHeader));
- }
}
nsCOMPtr fileChannel = do_QueryInterface(aChannel);
if (fileChannel) {
PRTime modDate, usecs;
-
nsCOMPtr file;
nsresult rv = fileChannel->GetFile(getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
@@ -811,7 +807,6 @@ nsHTMLDocument::RetrieveRelevantHeaders(nsIChannel *aChannel)
}
return NS_OK;
-
}
NS_IMETHODIMP
@@ -857,22 +852,24 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
if (needsParser) {
- rv = CallCreateInstance(kCParserCID, &mParser);
- if (NS_FAILED(rv)) { return rv; }
+ mParser = do_CreateInstance(kCParserCID, &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr sink;
#ifdef rickgdebug
- nsString outString; // added out. Redirect to stdout if desired -- gpk 04/01/99
+ // added out. Redirect to stdout if desired -- gpk 04/01/99
+ nsString outString;
rv = NS_New_HTML_ContentSinkStream(getter_AddRefs(sink),&outString,0);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(sink, "null sink in debug code variant.");
#else
+
NS_PRECONDITION(nsnull != aContainer, "No content viewer container");
nsCOMPtr docShell(do_QueryInterface(aContainer));
nsCOMPtr dcInfo;
- docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
+ docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
nsCOMPtr cx;
docShell->GetPresContext(getter_AddRefs(cx));
if(cx){
@@ -887,13 +884,14 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr cv;
docShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
- muCV = do_QueryInterface(cv);
+ muCV = do_QueryInterface(cv);
} else {
// in this block of code, if we get an error result, we return it
- // but if we get a null pointer, that's perfectly legal for parent and parentContentViewer
+ // but if we get a null pointer, that's perfectly legal for parent
+ // and parentContentViewer
nsCOMPtr docShellAsItem(do_QueryInterface(docShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
-
+
nsCOMPtr parentAsItem;
docShellAsItem->GetSameTypeParent(getter_AddRefs(parentAsItem));
@@ -915,19 +913,20 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
aURL->GetSpec(urlSpec);
PRInt32 charsetSource = kCharsetUninitialized;
- nsAutoString charset;
-
- // The following charset resolving calls has implied knowledge about
- // charset source priority order. Each try will return true if the
+ nsAutoString charset;
+
+ // The following charset resolving calls has implied knowledge about
+ // charset source priority order. Each try will return true if the
// source is higher or equal to the source as its name describes. Some
- // try call might change charset source to multiple values, like
- // TryHintCharset and TryParentCharset. It should be always safe to try more
- // sources.
- if (! TryUserForcedCharset(muCV, dcInfo, charsetSource, charset)) {
+ // try call might change charset source to multiple values, like
+ // TryHintCharset and TryParentCharset. It should be always safe to try more
+ // sources.
+ if (!TryUserForcedCharset(muCV, dcInfo, charsetSource, charset)) {
TryHintCharset(muCV, charsetSource, charset);
TryParentCharset(dcInfo, charsetSource, charset);
if (TryChannelCharset(aChannel, charsetSource, charset)) {
- // Use the channel's charset (e.g., charset from HTTP "Content-Type" header).
+ // Use the channel's charset (e.g., charset from HTTP
+ // "Content-Type" header).
}
else if (!scheme.Equals(NS_LITERAL_CSTRING("about")) && // don't try to access bookmarks for about:blank
TryBookmarkCharset(&urlSpec, charsetSource, charset)) {
@@ -948,8 +947,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
PRBool isPostPage = PR_FALSE;
- //check if current doc is from POST command
- if (mHttpChannel) {
+ // check if current doc is from POST command
+ if (mHttpChannel) {
nsCAutoString methodStr;
rv = mHttpChannel->GetRequestMethod(methodStr);
if (NS_SUCCEEDED(rv) && methodStr.Equals(NS_LITERAL_CSTRING("POST")))
@@ -968,20 +967,22 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if(kCharsetFromAutoDetection > charsetSource && !isPostPage) {
StartAutodetection(docShell, charset, aCommand);
}
-#endif
+#endif // rickgdebug
-//ahmed
+ // ahmed
// Check if 864 but in Implicit mode !
- if( (mTexttype == IBMBIDI_TEXTTYPE_LOGICAL)&&(charset.EqualsIgnoreCase("ibm864")) )
+ if ((mTexttype == IBMBIDI_TEXTTYPE_LOGICAL) &&
+ (charset.EqualsIgnoreCase("ibm864"))) {
charset.Assign(NS_LITERAL_STRING("IBM864i"));
+ }
SetDocumentCharacterSet(charset);
SetDocumentCharacterSetSource(charsetSource);
-
+
// set doc charset to muCV for next document.
if (muCV)
muCV->SetPrevDocCharacterSet(charset.get());
-
+
if(cacheDescriptor) {
rv = cacheDescriptor->SetMetaDataElement("charset",
NS_ConvertUCS2toUTF8(charset).get());
@@ -995,20 +996,11 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
- //The following lines were added by Rick.
- //These perform "dynamic" DTD registration, allowing
- //the caller total control over process, and decoupling
- //parser from any given grammar.
-
-// nsCOMPtr theDTD;
-// NS_NewNavHTMLDTD(getter_AddRefs(theDTD));
-// mParser->RegisterDTD(theDTD);
-
#ifdef DEBUG_charset
- char* cCharset = ToNewCString(charset);
- printf("set to parser charset = %s source %d\n",
- cCharset, charsetSource);
- Recycle(cCharset);
+ char* cCharset = ToNewCString(charset);
+ printf("set to parser charset = %s source %d\n",
+ cCharset, charsetSource);
+ Recycle(cCharset);
#endif
mParser->SetDocumentCharset( charset, charsetSource);
mParser->SetCommand(aCommand);
@@ -1018,12 +1010,16 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (aSink)
sink = do_QueryInterface(aSink);
else {
- rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aURL, webShell,aChannel);
- if (NS_FAILED(rv)) { return rv; }
- NS_ASSERTION(sink, "null sink with successful result from factory method");
+ rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aURL, webShell,
+ aChannel);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+ NS_ASSERTION(sink,
+ "null sink with successful result from factory method");
}
- mParser->SetContentSink(sink);
+ mParser->SetContentSink(sink);
// parser the content of the URL
mParser->Parse(aURL, nsnull, PR_FALSE, (void *)this);
}
@@ -1037,7 +1033,7 @@ nsHTMLDocument::StopDocumentLoad()
if (mParser) {
mParser->Terminate();
}
-
+
return NS_OK;
}
@@ -1062,7 +1058,7 @@ nsHTMLDocument::DocumentWriteTerminationFunc(nsISupports *aRef)
// Release the documents parser so that the call to EndLoad()
// doesn't just return early and set the termination function again.
- NS_IF_RELEASE(htmldoc->mParser);
+ htmldoc->mParser = nsnull;
}
htmldoc->EndLoad();
@@ -1108,7 +1104,7 @@ nsHTMLDocument::EndLoad()
}
}
- NS_IF_RELEASE(mParser);
+ mParser = nsnull;
return nsDocument::EndLoad();
}
@@ -1122,26 +1118,26 @@ NS_IMETHODIMP
nsHTMLDocument::AddImageMap(nsIDOMHTMLMapElement* aMap)
{
// XXX We should order the maps based on their order in the document.
- // XXX Otherwise scripts that add/remove maps with duplicate names
+ // XXX Otherwise scripts that add/remove maps with duplicate names
// XXX will cause problems
NS_PRECONDITION(nsnull != aMap, "null ptr");
if (nsnull == aMap) {
return NS_ERROR_NULL_POINTER;
}
- if (mImageMaps->AppendElement(aMap)) {
+ if (mImageMaps.AppendObject(aMap)) {
return NS_OK;
}
return NS_ERROR_OUT_OF_MEMORY;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::RemoveImageMap(nsIDOMHTMLMapElement* aMap)
{
NS_PRECONDITION(nsnull != aMap, "null ptr");
if (nsnull == aMap) {
return NS_ERROR_NULL_POINTER;
}
- mImageMaps->RemoveElement(aMap);
+ mImageMaps.RemoveObject(aMap);
return NS_OK;
}
@@ -1155,11 +1151,10 @@ nsHTMLDocument::GetImageMap(const nsAString& aMapName,
}
nsAutoString name;
- PRUint32 i, n;
- mImageMaps->Count(&n);
+ PRUint32 i, n = mImageMaps.Count();
+
for (i = 0; i < n; i++) {
- nsCOMPtr map;
- mImageMaps->QueryElementAt(i, NS_GET_IID(nsIDOMHTMLMapElement), getter_AddRefs(map));
+ nsCOMPtr map = mImageMaps[i];
if (map && NS_SUCCEEDED(map->GetName(name))) {
if (name.Equals(aMapName, nsCaseInsensitiveStringComparator())) {
*aResult = map;
@@ -1178,11 +1173,13 @@ nsHTMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult)
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mAttrStyleSheet;
- if (!mAttrStyleSheet) {
+
+ if (!*aResult) {
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
}
NS_ADDREF(*aResult);
+
return NS_OK;
}
@@ -1192,11 +1189,13 @@ nsHTMLDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult)
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mStyleAttrStyleSheet;
- if (!mStyleAttrStyleSheet) {
+
+ if (!*aResult) {
return NS_ERROR_NOT_AVAILABLE; // probably not the right error...
}
NS_ADDREF(*aResult);
+
return NS_OK;
}
@@ -1229,7 +1228,8 @@ nsHTMLDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet, PRUint32 aFlags)
}
void
-nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex)
+nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet,
+ PRInt32 aIndex)
{
NS_ASSERTION(0 <= aIndex &&
aIndex <= (
@@ -1244,7 +1244,8 @@ nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex
),
"index out of bounds");
- mStyleSheets.InsertObjectAt(aSheet, aIndex + 1); // offset one for the attr style sheet
+ // offset one for the attr style sheet
+ mStyleSheets.InsertObjectAt(aSheet, aIndex + 1);
}
already_AddRefed
@@ -1272,85 +1273,34 @@ nsHTMLDocument::InternalGetNumberOfStyleSheets()
return count;
}
-NS_IMETHODIMP
-nsHTMLDocument::GetBaseURL(nsIURI*& aURL) const
-{
- if (mDocumentBaseURL) {
- aURL = mDocumentBaseURL.get();
- NS_ADDREF(aURL);
- }
- else {
- GetDocumentURL(&aURL);
- }
- return NS_OK;
-}
-
NS_IMETHODIMP
nsHTMLDocument::GetBaseTarget(nsAString& aTarget)
{
- if (nsnull != mBaseTarget) {
- aTarget.Assign(*mBaseTarget);
- }
- else {
- aTarget.Truncate();
- }
+ aTarget.Assign(mBaseTarget);
+
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::SetBaseTarget(const nsAString& aTarget)
{
- if (!aTarget.IsEmpty()) {
- if (nsnull != mBaseTarget) {
- *mBaseTarget = aTarget;
- }
- else {
- mBaseTarget = new nsString(aTarget);
- }
- }
- else {
- if (nsnull != mBaseTarget) {
- delete mBaseTarget;
- mBaseTarget = nsnull;
- }
- }
+ mBaseTarget = aTarget;
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::SetLastModified(const nsAString& aLastModified)
{
- if (!aLastModified.IsEmpty()) {
- if (nsnull != mLastModified) {
- *mLastModified = aLastModified;
- }
- else {
- mLastModified = new nsString(aLastModified);
- }
- }
- else if (nsnull != mLastModified) {
- delete mLastModified;
- mLastModified = nsnull;
- }
+ mLastModified.Assign(aLastModified);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::SetReferrer(const nsAString& aReferrer)
{
- if (!aReferrer.IsEmpty()) {
- if (nsnull != mReferrer) {
- *mReferrer = aReferrer;
- }
- else {
- mReferrer = new nsString(aReferrer);
- }
- }
- else if (nsnull != mReferrer) {
- delete mReferrer;
- mReferrer = nsnull;
- }
+ mReferrer.Assign(aReferrer);
return NS_OK;
}
@@ -1358,17 +1308,18 @@ nsHTMLDocument::SetReferrer(const nsAString& aReferrer)
NS_IMETHODIMP
nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{
- nsresult result = NS_OK;
- if (! mCSSLoader) {
- result = NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader));
- }
- if (mCSSLoader) {
- mCSSLoader->SetCaseSensitive(PR_FALSE);
- mCSSLoader->SetCompatibilityMode(mCompatMode);
+ if (!mCSSLoader) {
+ nsresult rv = NS_NewCSSLoader(this, getter_AddRefs(mCSSLoader));
+ NS_ENSURE_SUCCESS(rv, rv);
}
+
+ mCSSLoader->SetCaseSensitive(PR_FALSE);
+ mCSSLoader->SetCompatibilityMode(mCompatMode);
+
aLoader = mCSSLoader;
- NS_IF_ADDREF(aLoader);
- return result;
+ NS_ADDREF(aLoader);
+
+ return NS_OK;
}
@@ -1398,7 +1349,7 @@ nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer)
{
@@ -1413,14 +1364,14 @@ nsHTMLDocument::ContentAppended(nsIContent* aContainer,
nsCOMPtr newChild;
for (i = aNewIndexInContainer; i < count; ++i) {
aContainer->ChildAt(i, *getter_AddRefs(newChild));
- if (newChild)
+ if (newChild)
RegisterNamedItems(newChild);
}
return nsDocument::ContentAppended(aContainer, aNewIndexInContainer);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::ContentInserted(nsIContent* aContainer, nsIContent* aContent,
PRInt32 aIndexInContainer)
{
@@ -1454,11 +1405,11 @@ nsHTMLDocument::ContentReplaced(nsIContent* aContainer, nsIContent* aOldChild,
return rv;
}
- return nsDocument::ContentReplaced(aContainer, aOldChild,
+ return nsDocument::ContentReplaced(aContainer, aOldChild,
aNewChild, aIndexInContainer);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::ContentRemoved(nsIContent* aContainer, nsIContent* aContent,
PRInt32 aIndexInContainer)
{
@@ -1540,11 +1491,11 @@ nsHTMLDocument::AttributeChanged(nsIContent* aContent, PRInt32 aNameSpaceID,
}
}
- return nsDocument::AttributeChanged(aContent, aNameSpaceID, aAttribute, aModType,
- aHint);
+ return nsDocument::AttributeChanged(aContent, aNameSpaceID, aAttribute,
+ aModType, aHint);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::FlushPendingNotifications(PRBool aFlushReflows,
PRBool aUpdateViews)
{
@@ -1566,7 +1517,7 @@ nsHTMLDocument::FlushPendingNotifications(PRBool aFlushReflows,
if (isSafeToFlush && mParser) {
nsCOMPtr sink;
-
+
// XXX Ack! Parser doesn't addref sink before passing it back
sink = mParser->GetContentSink();
if (sink) {
@@ -1617,8 +1568,8 @@ nsHTMLDocument::CreateElementNS(const nsAString& aNamespaceURI,
//
// nsIDOMDocument interface implementation
//
-NS_IMETHODIMP
-nsHTMLDocument::CreateElement(const nsAString& aTagName,
+NS_IMETHODIMP
+nsHTMLDocument::CreateElement(const nsAString& aTagName,
nsIDOMElement** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
@@ -1641,19 +1592,19 @@ nsHTMLDocument::CreateElement(const nsAString& aTagName,
return rv;
}
-NS_IMETHODIMP
-nsHTMLDocument::CreateProcessingInstruction(const nsAString& aTarget,
- const nsAString& aData,
+NS_IMETHODIMP
+nsHTMLDocument::CreateProcessingInstruction(const nsAString& aTarget,
+ const nsAString& aData,
nsIDOMProcessingInstruction** aReturn)
{
// There are no PIs for HTML
*aReturn = nsnull;
-
+
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
-NS_IMETHODIMP
-nsHTMLDocument::CreateCDATASection(const nsAString& aData,
+NS_IMETHODIMP
+nsHTMLDocument::CreateCDATASection(const nsAString& aData,
nsIDOMCDATASection** aReturn)
{
// There are no CDATASections in HTML
@@ -1661,9 +1612,9 @@ nsHTMLDocument::CreateCDATASection(const nsAString& aData,
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
-
-NS_IMETHODIMP
-nsHTMLDocument::CreateEntityReference(const nsAString& aName,
+
+NS_IMETHODIMP
+nsHTMLDocument::CreateEntityReference(const nsAString& aName,
nsIDOMEntityReference** aReturn)
{
// There are no EntityReferences in HTML
@@ -1672,144 +1623,145 @@ nsHTMLDocument::CreateEntityReference(const nsAString& aName,
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetDoctype(nsIDOMDocumentType** aDocumentType)
{
- return nsDocument::GetDoctype(aDocumentType);
+ return nsDocument::GetDoctype(aDocumentType);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
-{
- return nsDocument::GetImplementation(aImplementation);
+{
+ return nsDocument::GetImplementation(aImplementation);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
-{
- return nsDocument::GetDocumentElement(aDocumentElement);
+{
+ return nsDocument::GetDocumentElement(aDocumentElement);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
-{
- return nsDocument::CreateDocumentFragment(aReturn);
+{
+ return nsDocument::CreateDocumentFragment(aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn)
-{
- return nsDocument::CreateComment(aData, aReturn);
+{
+ return nsDocument::CreateComment(aData, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::CreateAttribute(const nsAString& aName, nsIDOMAttr** aReturn)
-{
- return nsDocument::CreateAttribute(aName, aReturn);
+{
+ return nsDocument::CreateAttribute(aName, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn)
-{
- return nsDocument::CreateTextNode(aData, aReturn);
+{
+ return nsDocument::CreateTextNode(aData, aReturn);
}
-NS_IMETHODIMP
-nsHTMLDocument::GetElementsByTagName(const nsAString& aTagname, nsIDOMNodeList** aReturn)
-{
+NS_IMETHODIMP
+nsHTMLDocument::GetElementsByTagName(const nsAString& aTagname,
+ nsIDOMNodeList** aReturn)
+{
nsAutoString tmp(aTagname);
ToLowerCase(tmp); // HTML elements are lower case internally.
- return nsDocument::GetElementsByTagName(tmp, aReturn);
+ return nsDocument::GetElementsByTagName(tmp, aReturn);
}
//
// nsIDOMNode interface implementation
//
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
return nsDocument::GetChildNodes(aChildNodes);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetFirstChild(nsIDOMNode** aFirstChild)
{
return nsDocument::GetFirstChild(aFirstChild);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetLastChild(nsIDOMNode** aLastChild)
{
return nsDocument::GetLastChild(aLastChild);
}
-NS_IMETHODIMP
-nsHTMLDocument::InsertBefore(nsIDOMNode* aNewChild,
- nsIDOMNode* aRefChild,
+NS_IMETHODIMP
+nsHTMLDocument::InsertBefore(nsIDOMNode* aNewChild,
+ nsIDOMNode* aRefChild,
nsIDOMNode** aReturn)
{
return nsDocument::InsertBefore(aNewChild, aRefChild, aReturn);
}
-NS_IMETHODIMP
-nsHTMLDocument::ReplaceChild(nsIDOMNode* aNewChild,
- nsIDOMNode* aOldChild,
+NS_IMETHODIMP
+nsHTMLDocument::ReplaceChild(nsIDOMNode* aNewChild,
+ nsIDOMNode* aOldChild,
nsIDOMNode** aReturn)
{
return nsDocument::ReplaceChild(aNewChild, aOldChild, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return nsDocument::RemoveChild(aOldChild, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
{
return nsDocument::AppendChild(aNewChild, aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::HasChildNodes(PRBool* aReturn)
{
return nsDocument::HasChildNodes(aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::HasAttributes(PRBool* aReturn)
{
return nsDocument::HasAttributes(aReturn);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetNodeName(nsAString& aNodeName)
-{
- return nsDocument::GetNodeName(aNodeName);
+{
+ return nsDocument::GetNodeName(aNodeName);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetNodeValue(nsAString& aNodeValue)
-{
- return nsDocument::GetNodeValue(aNodeValue);
+{
+ return nsDocument::GetNodeValue(aNodeValue);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::SetNodeValue(const nsAString& aNodeValue)
-{
- return nsDocument::SetNodeValue(aNodeValue);
+{
+ return nsDocument::SetNodeValue(aNodeValue);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetNodeType(PRUint16* aNodeType)
-{
- return nsDocument::GetNodeType(aNodeType);
+{
+ return nsDocument::GetNodeType(aNodeType);
}
NS_IMETHODIMP
nsHTMLDocument::GetNamespaceURI(nsAString& aNamespaceURI)
-{
+{
return nsDocument::GetNamespaceURI(aNamespaceURI);
}
@@ -1831,39 +1783,39 @@ nsHTMLDocument::GetLocalName(nsAString& aLocalName)
return nsDocument::GetLocalName(aLocalName);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetParentNode(nsIDOMNode** aParentNode)
-{
- return nsDocument::GetParentNode(aParentNode);
+{
+ return nsDocument::GetParentNode(aParentNode);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
-{
- return nsDocument::GetPreviousSibling(aPreviousSibling);
+{
+ return nsDocument::GetPreviousSibling(aPreviousSibling);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetNextSibling(nsIDOMNode** aNextSibling)
-{
- return nsDocument::GetNextSibling(aNextSibling);
+{
+ return nsDocument::GetNextSibling(aNextSibling);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
-{
- return nsDocument::GetAttributes(aAttributes);
+{
+ return nsDocument::GetAttributes(aAttributes);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
-{
- return nsDocument::GetOwnerDocument(aOwnerDocument);
+{
+ return nsDocument::GetOwnerDocument(aOwnerDocument);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
-{
+{
return nsDocument::CloneNode(aDeep, aReturn);
}
@@ -1885,12 +1837,20 @@ NS_IMETHODIMP
nsHTMLDocument::GetBaseURI(nsAString &aURI)
{
aURI.Truncate();
- nsCOMPtr uri(do_QueryInterface(mBaseURL ? mBaseURL : mDocumentURL));
+ nsIURI *uri = mDocumentBaseURL; // WEAK
+
+ if (!uri) {
+ uri = mDocumentURL;
+ }
+
if (uri) {
nsCAutoString spec;
uri->GetSpec(spec);
+
+ // XXX: CopyUTF8toUCS2()?
aURI = NS_ConvertUTF8toUCS2(spec);
}
+
return NS_OK;
}
@@ -1909,15 +1869,15 @@ nsHTMLDocument::IsSameNode(nsIDOMNode* aOther,
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::LookupNamespacePrefix(const nsAString& aNamespaceURI,
- nsAString& aPrefix)
+ nsAString& aPrefix)
{
aPrefix.Truncate();
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
@@ -1938,38 +1898,40 @@ nsHTMLDocument::GetTitle(nsAString& aTitle)
return nsDocument::GetTitle(aTitle);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetReferrer(nsAString& aReferrer)
{
- if (nsnull != mReferrer) {
- aReferrer.Assign(*mReferrer);
- }
- else {
- aReferrer.Truncate();
- }
+ aReferrer.Assign(mReferrer);
return NS_OK;
}
-NS_IMETHODIMP
-nsHTMLDocument::GetDomainURI(nsIURI **uri)
+void
+nsHTMLDocument::GetDomainURI(nsIURI **aURI)
{
+ *aURI = nsnull;
+
nsCOMPtr principal;
if (NS_FAILED(GetPrincipal(getter_AddRefs(principal))))
- return NS_ERROR_FAILURE;
+ return;
+
nsCOMPtr codebase = do_QueryInterface(principal);
if (!codebase)
- return NS_ERROR_FAILURE;
- return codebase->GetURI(uri);
+ return;
+
+ codebase->GetURI(aURI);
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetDomain(nsAString& aDomain)
{
nsCOMPtr uri;
- if (NS_FAILED(GetDomainURI(getter_AddRefs(uri))))
+ GetDomainURI(getter_AddRefs(uri));
+
+ if (!uri) {
return NS_ERROR_FAILURE;
+ }
nsCAutoString hostName;
if (NS_FAILED(uri->GetHost(hostName)))
@@ -1979,7 +1941,7 @@ nsHTMLDocument::GetDomain(nsAString& aDomain)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::SetDomain(const nsAString& aDomain)
{
// Check new domain - must be a superdomain of the current host
@@ -2003,11 +1965,15 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain)
// Error: illegal domain
return NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN;
}
-
+
// Create new URI
nsCOMPtr uri;
- if (NS_FAILED(GetDomainURI(getter_AddRefs(uri))))
+ GetDomainURI(getter_AddRefs(uri));
+
+ if (!uri) {
return NS_ERROR_FAILURE;
+ }
+
nsCAutoString scheme;
if (NS_FAILED(uri->GetScheme(scheme)))
return NS_ERROR_FAILURE;
@@ -2015,24 +1981,27 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain)
if (NS_FAILED(uri->GetPath(path)))
return NS_ERROR_FAILURE;
NS_ConvertUTF8toUCS2 newURIString(scheme);
- newURIString += NS_LITERAL_STRING("://") + aDomain + NS_ConvertUTF8toUCS2(path);
+ newURIString.Append(NS_LITERAL_STRING("://") + aDomain +
+ NS_ConvertUTF8toUCS2(path));
+
nsCOMPtr newURI;
if (NS_FAILED(NS_NewURI(getter_AddRefs(newURI), newURIString)))
return NS_ERROR_FAILURE;
// Get codebase principal
nsresult rv;
- nsCOMPtr securityManager =
+ nsCOMPtr securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
nsCOMPtr newCodebase;
- rv = securityManager->GetCodebasePrincipal(newURI, getter_AddRefs(newCodebase));
- if (NS_FAILED(rv))
+ rv = securityManager->GetCodebasePrincipal(newURI,
+ getter_AddRefs(newCodebase));
+ if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
nsCOMPtr agg = do_QueryInterface(mPrincipal, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Principal not an aggregate.");
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = agg->SetCodebase(newCodebase);
@@ -2052,18 +2021,21 @@ nsHTMLDocument::WasDomainSet(PRBool* aDomainWasSet)
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetURL(nsAString& aURL)
{
- if (nsnull != mDocumentURL) {
+ if (mDocumentURL) {
nsCAutoString str;
mDocumentURL->GetSpec(str);
aURL.Assign(NS_ConvertUTF8toUCS2(str));
+ } else {
+ aURL.Truncate();
}
+
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
{
NS_ENSURE_ARG_POINTER(aBody);
@@ -2098,7 +2070,7 @@ nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
return element ? CallQueryInterface(element, aBody) : NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
{
nsCOMPtr bodyElement(do_QueryInterface(aBody));
@@ -2111,7 +2083,7 @@ nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
nsCOMPtr root;
GetDocumentElement(getter_AddRefs(root));
- if (!root) {
+ if (!root) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
@@ -2146,7 +2118,7 @@ nsHTMLDocument::SetBody(nsIDOMHTMLElement* aBody)
return PR_FALSE;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
{
if (!mImages) {
@@ -2154,16 +2126,15 @@ nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
if (!mImages) {
return NS_ERROR_OUT_OF_MEMORY;
}
- NS_ADDREF(mImages);
}
- *aImages = (nsIDOMHTMLCollection *)mImages;
+ *aImages = mImages;
NS_ADDREF(*aImages);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
{
if (!mApplets) {
@@ -2172,10 +2143,9 @@ nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
if (!mApplets) {
return NS_ERROR_OUT_OF_MEMORY;
}
- NS_ADDREF(mApplets);
}
- *aApplets = (nsIDOMHTMLCollection *)mApplets;
+ *aApplets = mApplets;
NS_ADDREF(*aApplets);
return NS_OK;
@@ -2194,19 +2164,18 @@ nsHTMLDocument::MatchLinks(nsIContent *aContent, nsString* aData)
return PR_FALSE;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetLinks(nsIDOMHTMLCollection** aLinks)
{
- if (nsnull == mLinks) {
+ if (!mLinks) {
mLinks = new nsContentList(this, MatchLinks, nsString());
- if (nsnull == mLinks) {
+ if (!mLinks) {
return NS_ERROR_OUT_OF_MEMORY;
}
- NS_ADDREF(mLinks);
}
- *aLinks = (nsIDOMHTMLCollection *)mLinks;
- NS_ADDREF(mLinks);
+ *aLinks = mLinks;
+ NS_ADDREF(*aLinks);
return NS_OK;
}
@@ -2224,23 +2193,23 @@ nsHTMLDocument::MatchAnchors(nsIContent *aContent, nsString* aData)
return PR_FALSE;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetAnchors(nsIDOMHTMLCollection** aAnchors)
{
if (!mAnchors) {
mAnchors = new nsContentList(this, MatchAnchors, nsString());
- NS_ENSURE_TRUE(mAnchors, NS_ERROR_OUT_OF_MEMORY);
-
- NS_ADDREF(mAnchors);
+ if (!mAnchors) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
}
- *aAnchors = (nsIDOMHTMLCollection *)mAnchors;
+ *aAnchors = mAnchors;
NS_ADDREF(*aAnchors);
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::GetCookie(nsAString& aCookie)
{
aCookie.Truncate(); // clear current cookie in case service fails;
@@ -2258,40 +2227,39 @@ nsHTMLDocument::GetCookie(nsAString& aCookie)
}
}
- nsresult result = NS_OK;
+ nsresult rv = NS_OK;
nsAutoString str;
- nsCOMPtr service = do_GetService(kCookieServiceCID, &result);
- if (NS_SUCCEEDED(result) && service) {
-
- // Get a URI from the document principal
- // We use the original codebase in case the codebase was changed by SetDomain
- nsCOMPtr agg(do_QueryInterface(mPrincipal, &result));
+ nsCOMPtr service = do_GetService(kCookieServiceCID, &rv);
+ if (service) {
+ // Get a URI from the document principal. We use the original
+ // codebase in case the codebase was changed by SetDomain
+ nsCOMPtr agg(do_QueryInterface(mPrincipal, &rv));
// Document principal should always be an aggregate
- NS_ENSURE_SUCCESS(result, result);
+ NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr originalPrincipal;
- result = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
+ rv = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
nsCOMPtr originalCodebase(
- do_QueryInterface(originalPrincipal, &result));
- if (NS_FAILED(result)) {
+ do_QueryInterface(originalPrincipal, &rv));
+ if (NS_FAILED(rv)) {
// Document's principal is not a codebase, so can't get cookies
- return NS_OK;
+ return NS_OK;
}
nsCOMPtr codebaseURI;
- result = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
- NS_ENSURE_SUCCESS(result, result);
+ rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
+ NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString cookie;
- result = service->GetCookieString(codebaseURI, getter_Copies(cookie));
- if (NS_SUCCEEDED(result) && cookie)
+ rv = service->GetCookieString(codebaseURI, getter_Copies(cookie));
+ if (NS_SUCCEEDED(rv) && cookie)
CopyASCIItoUCS2(nsDependentCString(cookie), aCookie);
}
- return result;
+ return rv;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::SetCookie(const nsAString& aCookie)
{
// If caller is not chrome and dom.disable_cookie_get is true,
@@ -2305,9 +2273,9 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie)
}
}
- nsresult result = NS_OK;
- nsCOMPtr service = do_GetService(kCookieServiceCID, &result);
- if (NS_SUCCEEDED(result) && service && mDocumentURL) {
+ nsresult rv = NS_OK;
+ nsCOMPtr service = do_GetService(kCookieServiceCID, &rv);
+ if (service && mDocumentURL) {
nsCOMPtr globalObj;
nsCOMPtr prompt;
this->GetScriptGlobalObject(getter_AddRefs(globalObj));
@@ -2318,33 +2286,34 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie)
}
}
- // Get a URI from the document principal
- // We use the original codebase in case the codebase was changed by SetDomain
- nsCOMPtr agg(do_QueryInterface(mPrincipal, &result));
+ // Get a URI from the document principal. We use the original
+ // codebase in case the codebase was changed by SetDomain
+ nsCOMPtr agg(do_QueryInterface(mPrincipal, &rv));
// Document principal should always be an aggregate
- NS_ENSURE_SUCCESS(result, result);
+ NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr originalPrincipal;
- result = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
+ rv = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
nsCOMPtr originalCodebase(
- do_QueryInterface(originalPrincipal, &result));
- if (NS_FAILED(result)) {
+ do_QueryInterface(originalPrincipal, &rv));
+ if (NS_FAILED(rv)) {
// Document's principal is not a codebase, so can't set cookies
- return NS_OK;
+ return NS_OK;
}
nsCOMPtr codebaseURI;
- result = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
- NS_ENSURE_SUCCESS(result, result);
+ rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
+ NS_ENSURE_SUCCESS(rv, rv);
- result = NS_ERROR_OUT_OF_MEMORY;
+ rv = NS_ERROR_OUT_OF_MEMORY;
char* cookie = ToNewCString(aCookie);
if (cookie) {
- result = service->SetCookieString(codebaseURI, prompt, cookie, mHttpChannel);
+ rv = service->SetCookieString(codebaseURI, prompt, cookie,
+ mHttpChannel);
nsCRT::free(cookie);
}
}
- return result;
+ return rv;
}
// static
@@ -2367,22 +2336,21 @@ nsHTMLDocument::GetSourceDocumentURL(nsIURI** sourceURL)
return NS_OK; // No document in the window
}
- doc->GetDocumentURL(sourceURL);
+ doc->GetDocumentURL(sourceURL);
- return sourceURL ? NS_OK : NS_ERROR_FAILURE;
+ return sourceURL ? NS_OK : NS_ERROR_FAILURE;
}
-
// XXX TBI: accepting arguments to the open method.
nsresult
nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
{
- nsCOMPtr docshell;
-
// If we already have a parser we ignore the document.open call.
if (mParser)
return NS_OK;
+ nsCOMPtr docshell;
+
// Stop current loads targeted at the window this document is in.
if (mScriptGlobalObject) {
mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell));
@@ -2393,30 +2361,33 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
}
}
- nsresult result = NS_OK;
+ nsresult rv = NS_OK;
// The open occurred after the document finished loading.
// So we reset the document and create a new one.
nsCOMPtr channel;
nsCOMPtr group = do_QueryReferent(mDocumentLoadGroup);
- result = NS_NewChannel(getter_AddRefs(channel), aSourceURL, nsnull, group);
+ rv = NS_NewChannel(getter_AddRefs(channel), aSourceURL, nsnull, group);
- if (NS_FAILED(result)) return result;
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
- //Before we reset the doc notify the globalwindow of the change.
+ // Before we reset the doc notify the globalwindow of the change.
if (mScriptGlobalObject) {
- //Hold onto ourselves on the offchance that we're down to one ref
+ // Hold onto ourselves on the offchance that we're down to one ref
nsCOMPtr kungFuDeathGrip =
do_QueryInterface((nsIHTMLDocument*)this);
- result = mScriptGlobalObject->SetNewDocument(kungFuDeathGrip, PR_FALSE,
- PR_FALSE);
+ rv = mScriptGlobalObject->SetNewDocument(kungFuDeathGrip, PR_FALSE,
+ PR_FALSE);
- if (NS_FAILED(result))
- return result;
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
}
// XXX This is a nasty workaround for a scrollbar code bug
@@ -2461,9 +2432,10 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
// the anonymous content (i.e. scrollbar elements) is set to
// null.
- result = Reset(channel, group);
- if (NS_FAILED(result))
- return result;
+ rv = Reset(channel, group);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
if (root) {
// Tear down the frames for the root element.
@@ -2479,10 +2451,11 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
mRootContent = root;
}
- result = CallCreateInstance(kCParserCID, &mParser);
+ mParser = do_CreateInstance(kCParserCID, &rv);
+
mIsWriting = 1;
- if (NS_SUCCEEDED(result)) {
+ if (NS_SUCCEEDED(rv)) {
nsCOMPtr sink;
nsCOMPtr webShell;
@@ -2499,16 +2472,16 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
}
}
- result = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aSourceURL,
- webShell, channel);
+ rv = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aSourceURL,
+ webShell, channel);
- if (NS_OK == result) {
+ if (NS_OK == rv) {
static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID);
- nsCOMPtr theDTD(do_CreateInstance(kNavDTDCID, &result));
- if(NS_SUCCEEDED(result)) {
+ nsCOMPtr theDTD(do_CreateInstance(kNavDTDCID, &rv));
+ if(NS_SUCCEEDED(rv)) {
mParser->RegisterDTD(theDTD);
}
- mParser->SetContentSink(sink);
+ mParser->SetContentSink(sink);
}
}
@@ -2527,17 +2500,17 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL)
// Add a wyciwyg channel request into the document load group
NS_ASSERTION(mWyciwygChannel == nsnull, "nsHTMLDocument::OpenCommon(): wyciwyg channel already exists!");
CreateAndAddWyciwygChannel();
- return result;
+ return rv;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::Open()
{
nsCOMPtr doc;
return Open(getter_AddRefs(doc));
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::Open(nsIDOMDocument** aReturn)
{
// XXX The URL of the newly created document will match
@@ -2545,46 +2518,44 @@ nsHTMLDocument::Open(nsIDOMDocument** aReturn)
// XXX This will fail on non-DOM contexts :(
nsCOMPtr sourceURL;
- nsresult result = GetSourceDocumentURL(getter_AddRefs(sourceURL));
+ nsresult rv = GetSourceDocumentURL(getter_AddRefs(sourceURL));
// Recover if we had a problem obtaining the source URL
if (!sourceURL) {
- result = NS_NewURI(getter_AddRefs(sourceURL),
- NS_LITERAL_CSTRING("about:blank"));
+ rv = NS_NewURI(getter_AddRefs(sourceURL),
+ NS_LITERAL_CSTRING("about:blank"));
}
+ NS_ENSURE_SUCCESS(rv, rv);
- if (NS_SUCCEEDED(result)) {
- result = OpenCommon(sourceURL);
- }
+ rv = OpenCommon(sourceURL);
+ NS_ENSURE_SUCCESS(rv, rv);
- CallQueryInterface(this, aReturn);
-
- return result;
+ return CallQueryInterface(this, aReturn);
}
#define NS_GENERATE_PARSER_KEY() (void*)((mIsWriting << 31) | (mWriteLevel & 0x7fffffff))
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::Clear()
{
// This method has been deprecated
return NS_OK;
}
-NS_IMETHODIMP
+NS_IMETHODIMP
nsHTMLDocument::Close()
{
- nsresult result = NS_OK;
+ nsresult rv = NS_OK;
if (mParser && mIsWriting) {
mWriteLevel++;
- result = mParser->Parse(NS_LITERAL_STRING("