# HG changeset patch # Parent d881d9a235fd01c312df8a0d36451b93405adca8 # User timeless@mozdev.org Bug 293047 selecting 4 space indentation for nsWebBrowser r=biesi diff --git a/embedding/browser/webBrowser/nsWebBrowser.cpp b/embedding/browser/webBrowser/nsWebBrowser.cpp --- a/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -103,20 +103,21 @@ static NS_DEFINE_CID(kLookAndFeelCID, NS //*** nsWebBrowser: Object Management //***************************************************************************** -nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull), - mInitInfo(nsnull), - mContentType(typeContentWrapper), - mActivating(PR_FALSE), - mShouldEnableHistory(PR_TRUE), - mParentNativeWindow(nsnull), - mProgressListener(nsnull), - mBackgroundColor(0), - mPersistCurrentState(nsIWebBrowserPersist::PERSIST_STATE_READY), - mPersistResult(NS_OK), - mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE), - mStream(nsnull), - mParentWidget(nsnull), - mListenerArray(nsnull) +nsWebBrowser::nsWebBrowser() + : mDocShellTreeOwner(nsnull), + mInitInfo(nsnull), + mContentType(typeContentWrapper), + mActivating(PR_FALSE), + mShouldEnableHistory(PR_TRUE), + mParentNativeWindow(nsnull), + mProgressListener(nsnull), + mBackgroundColor(0), + mPersistCurrentState(nsIWebBrowserPersist::PERSIST_STATE_READY), + mPersistResult(NS_OK), + mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE), + mStream(nsnull), + mParentWidget(nsnull), + mListenerArray(nsnull) { mInitInfo = new nsWebBrowserInitInfo(); mWWatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID); @@ -125,111 +126,112 @@ nsWebBrowser::nsWebBrowser() : mDocShell nsWebBrowser::~nsWebBrowser() { - InternalDestroy(); + InternalDestroy(); } NS_IMETHODIMP nsWebBrowser::InternalDestroy() { + if (mInternalWidget) { + mInternalWidget->SetClientData(0); + mInternalWidget->Destroy(); + mInternalWidget = nsnull; // Force release here. + } - if (mInternalWidget) { - mInternalWidget->SetClientData(0); - mInternalWidget->Destroy(); - mInternalWidget = nsnull; // Force release here. - } + SetDocShell(nsnull); - SetDocShell(nsnull); + if (mDocShellTreeOwner) + { + mDocShellTreeOwner->WebBrowser(nsnull); + NS_RELEASE(mDocShellTreeOwner); + } + if (mInitInfo) + { + delete mInitInfo; + mInitInfo = nsnull; + } - if(mDocShellTreeOwner) - { - mDocShellTreeOwner->WebBrowser(nsnull); - NS_RELEASE(mDocShellTreeOwner); - } - if(mInitInfo) - { - delete mInitInfo; - mInitInfo = nsnull; - } + if (mListenerArray) { + for (PRUint32 i = 0, end = mListenerArray->Length(); i < end; i++) { + nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); + NS_DELETEXPCOM(state); + } + delete mListenerArray; + mListenerArray = nsnull; + } - if (mListenerArray) { - for (PRUint32 i = 0, end = mListenerArray->Length(); i < end; i++) { - nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); - NS_DELETEXPCOM(state); - } - delete mListenerArray; - mListenerArray = nsnull; - } - - return NS_OK; + return NS_OK; } //***************************************************************************** // nsWebBrowser::nsISupports -//***************************************************************************** +//***************************************************************************** NS_IMPL_ADDREF(nsWebBrowser) NS_IMPL_RELEASE(nsWebBrowser) NS_INTERFACE_MAP_BEGIN(nsWebBrowser) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowser) - NS_INTERFACE_MAP_ENTRY(nsIWebBrowser) - NS_INTERFACE_MAP_ENTRY(nsIWebNavigation) - NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) - NS_INTERFACE_MAP_ENTRY(nsIScrollable) - NS_INTERFACE_MAP_ENTRY(nsITextScroll) - NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem) - NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode) - NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) - NS_INTERFACE_MAP_ENTRY(nsIWebBrowserSetup) - NS_INTERFACE_MAP_ENTRY(nsIWebBrowserPersist) - NS_INTERFACE_MAP_ENTRY(nsICancelable) - NS_INTERFACE_MAP_ENTRY(nsIWebBrowserFocus) - NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) - NS_INTERFACE_MAP_ENTRY(nsIWebBrowserStream) - NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) +NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowser) +NS_INTERFACE_MAP_ENTRY(nsIWebBrowser) +NS_INTERFACE_MAP_ENTRY(nsIWebNavigation) +NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) +NS_INTERFACE_MAP_ENTRY(nsIScrollable) +NS_INTERFACE_MAP_ENTRY(nsITextScroll) +NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem) +NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode) +NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) +NS_INTERFACE_MAP_ENTRY(nsIWebBrowserSetup) +NS_INTERFACE_MAP_ENTRY(nsIWebBrowserPersist) +NS_INTERFACE_MAP_ENTRY(nsICancelable) +NS_INTERFACE_MAP_ENTRY(nsIWebBrowserFocus) +NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) +NS_INTERFACE_MAP_ENTRY(nsIWebBrowserStream) +NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_END ///***************************************************************************** // nsWebBrowser::nsIInterfaceRequestor -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink) { - NS_ENSURE_ARG_POINTER(aSink); + NS_ENSURE_ARG_POINTER(aSink); - if(NS_SUCCEEDED(QueryInterface(aIID, aSink))) - return NS_OK; + if (NS_SUCCEEDED(QueryInterface(aIID, aSink))) + return NS_OK; - if (mDocShell) { + if (mDocShell) { #ifdef NS_PRINTING - if (aIID.Equals(NS_GET_IID(nsIWebBrowserPrint))) { - nsCOMPtr viewer; - mDocShell->GetContentViewer(getter_AddRefs(viewer)); - if (!viewer) - return NS_NOINTERFACE; + if (aIID.Equals(NS_GET_IID(nsIWebBrowserPrint))) { + nsCOMPtr viewer; + mDocShell->GetContentViewer(getter_AddRefs(viewer)); + if (!viewer) + return NS_NOINTERFACE; - nsCOMPtr webBrowserPrint(do_QueryInterface(viewer)); - nsIWebBrowserPrint* print = (nsIWebBrowserPrint*)webBrowserPrint.get(); - NS_ASSERTION(print, "This MUST support this interface!"); - NS_ADDREF(print); - *aSink = print; - return NS_OK; - } + nsCOMPtr webBrowserPrint(do_QueryInterface(viewer)); + nsIWebBrowserPrint* print = (nsIWebBrowserPrint*)webBrowserPrint.get(); + NS_ASSERTION(print, "This MUST support this interface!"); + NS_ADDREF(print); + *aSink = print; + return NS_OK; + } #endif - return mDocShellAsReq->GetInterface(aIID, aSink); - } + return mDocShellAsReq->GetInterface(aIID, aSink); + } - return NS_NOINTERFACE; + return NS_NOINTERFACE; } //***************************************************************************** // nsWebBrowser::nsIWebBrowser -//***************************************************************************** +//***************************************************************************** // listeners that currently support registration through AddWebBrowserListener: // - nsIWebProgressListener -NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID) -{ +NS_IMETHODIMP nsWebBrowser::AddWebBrowserListener( + nsIWeakReference *aListener, + const nsIID& aIID) +{ NS_ENSURE_ARG_POINTER(aListener); nsresult rv = NS_OK; @@ -261,13 +263,14 @@ NS_IMETHODIMP nsWebBrowser::AddWebBrowse if (!supports) return NS_ERROR_INVALID_ARG; rv = BindListener(supports, aIID); } - + return rv; } NS_IMETHODIMP nsWebBrowser::BindListener(nsISupports *aListener, const nsIID& aIID) { NS_ENSURE_ARG_POINTER(aListener); - NS_ASSERTION(mWebProgress, "this should only be called after we've retrieved a progress iface"); + NS_ASSERTION(mWebProgress, + "this should only be called after we've retrieved a progress iface"); nsresult rv = NS_OK; // register this listener for the specified interface id @@ -277,17 +280,19 @@ NS_IMETHODIMP nsWebBrowser::BindListener NS_ENSURE_STATE(mWebProgress); rv = mWebProgress->AddProgressListener(listener, nsIWebProgress::NOTIFY_ALL); } - else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { - nsCOMPtr shistory(do_GetInterface(mDocShell, &rv)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr listener(do_QueryInterface(aListener, &rv)); - if (NS_FAILED(rv)) return rv; - rv = shistory->AddSHistoryListener(listener); + else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { + nsCOMPtr shistory(do_GetInterface(mDocShell, &rv)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr listener(do_QueryInterface(aListener, &rv)); + if (NS_FAILED(rv)) return rv; + rv = shistory->AddSHistoryListener(listener); } return rv; } -NS_IMETHODIMP nsWebBrowser::RemoveWebBrowserListener(nsIWeakReference *aListener, const nsIID& aIID) +NS_IMETHODIMP nsWebBrowser::RemoveWebBrowserListener( + nsIWeakReference *aListener, + const nsIID& aIID) { NS_ENSURE_ARG_POINTER(aListener); @@ -308,14 +313,14 @@ NS_IMETHODIMP nsWebBrowser::RemoveWebBro mListenerArray->RemoveElementAt(count); break; } - count--; + count--; } // if we've emptied the array, get rid of it. if (0 >= mListenerArray->Length()) { for (PRUint32 i = 0, end = mListenerArray->Length(); i < end; i++) { - nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); - NS_DELETEXPCOM(state); + nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); + NS_DELETEXPCOM(state); } NS_DELETEXPCOM(mListenerArray); mListenerArray = nsnull; @@ -326,13 +331,14 @@ NS_IMETHODIMP nsWebBrowser::RemoveWebBro if (!supports) return NS_ERROR_INVALID_ARG; rv = UnBindListener(supports, aIID); } - + return rv; } NS_IMETHODIMP nsWebBrowser::UnBindListener(nsISupports *aListener, const nsIID& aIID) { NS_ENSURE_ARG_POINTER(aListener); - NS_ASSERTION(mWebProgress, "this should only be called after we've retrieved a progress iface"); + NS_ASSERTION(mWebProgress, + "this should only be called after we've retrieved a progress iface"); nsresult rv = NS_OK; // remove the listener for the specified interface id @@ -343,11 +349,11 @@ NS_IMETHODIMP nsWebBrowser::UnBindListen rv = mWebProgress->RemoveProgressListener(listener); } else if (aIID.Equals(NS_GET_IID(nsISHistoryListener))) { - nsCOMPtr shistory(do_GetInterface(mDocShell, &rv)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr listener(do_QueryInterface(aListener, &rv)); - if (NS_FAILED(rv)) return rv; - rv = shistory->RemoveSHistoryListener(listener); + nsCOMPtr shistory(do_GetInterface(mDocShell, &rv)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr listener(do_QueryInterface(aListener, &rv)); + if (NS_FAILED(rv)) return rv; + rv = shistory->RemoveSHistoryListener(listener); } return rv; } @@ -355,56 +361,56 @@ NS_IMETHODIMP nsWebBrowser::UnBindListen NS_IMETHODIMP nsWebBrowser::EnableGlobalHistory(PRBool aEnable) { nsresult rv; - + NS_ENSURE_STATE(mDocShell); nsCOMPtr dsHistory(do_QueryInterface(mDocShell, &rv)); if (NS_FAILED(rv)) return rv; - + return dsHistory->SetUseGlobalHistory(aEnable); } NS_IMETHODIMP nsWebBrowser::GetContainerWindow(nsIWebBrowserChrome** aTopWindow) { - NS_ENSURE_ARG_POINTER(aTopWindow); + NS_ENSURE_ARG_POINTER(aTopWindow); - if(mDocShellTreeOwner) { - *aTopWindow = mDocShellTreeOwner->GetWebBrowserChrome().get(); - } else { - *aTopWindow = nsnull; - } + if (mDocShellTreeOwner) { + *aTopWindow = mDocShellTreeOwner->GetWebBrowserChrome().get(); + } else { + *aTopWindow = nsnull; + } - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetContainerWindow(nsIWebBrowserChrome* aTopWindow) { - NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); - return mDocShellTreeOwner->SetWebBrowserChrome(aTopWindow); + NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); + return mDocShellTreeOwner->SetWebBrowserChrome(aTopWindow); } NS_IMETHODIMP nsWebBrowser::GetParentURIContentListener(nsIURIContentListener** - aParentContentListener) + aParentContentListener) { - NS_ENSURE_ARG_POINTER(aParentContentListener); - *aParentContentListener = nsnull; + NS_ENSURE_ARG_POINTER(aParentContentListener); + *aParentContentListener = nsnull; - // get the interface from the docshell - nsCOMPtr listener(do_GetInterface(mDocShell)); + // get the interface from the docshell + nsCOMPtr listener(do_GetInterface(mDocShell)); - if (listener) - return listener->GetParentContentListener(aParentContentListener); - return NS_OK; + if (listener) + return listener->GetParentContentListener(aParentContentListener); + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetParentURIContentListener(nsIURIContentListener* - aParentContentListener) + aParentContentListener) { - // get the interface from the docshell - nsCOMPtr listener(do_GetInterface(mDocShell)); + // get the interface from the docshell + nsCOMPtr listener(do_GetInterface(mDocShell)); - if (listener) - return listener->SetParentContentListener(aParentContentListener); - return NS_ERROR_FAILURE; + if (listener) + return listener->SetParentContentListener(aParentContentListener); + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsWebBrowser::GetContentDOMWindow(nsIDOMWindow **_retval) @@ -414,138 +420,142 @@ NS_IMETHODIMP nsWebBrowser::GetContentDO nsCOMPtr retval = do_GetInterface(mDocShell, &rv); if (NS_FAILED(rv)) return rv; - *_retval = retval; - NS_ADDREF(*_retval); + NS_ADDREF(*_retval = retval); return rv; } //***************************************************************************** // nsWebBrowser::nsIDocShellTreeItem -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP nsWebBrowser::GetName(PRUnichar** aName) { - NS_ENSURE_ARG_POINTER(aName); + NS_ENSURE_ARG_POINTER(aName); - if(mDocShell) - mDocShellAsItem->GetName(aName); - else - *aName = ToNewUnicode(mInitInfo->name); + if (mDocShell) + mDocShellAsItem->GetName(aName); + else + *aName = ToNewUnicode(mInitInfo->name); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetName(const PRUnichar* aName) { - if(mDocShell) - { - nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); - NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); + if (mDocShell) + { + nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); + NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); - return docShellAsItem->SetName(aName); - } - else - mInitInfo->name = aName; + return docShellAsItem->SetName(aName); + } - return NS_OK; + mInitInfo->name = aName; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::NameEquals(const PRUnichar *aName, PRBool *_retval) { NS_ENSURE_ARG_POINTER(aName); NS_ENSURE_ARG_POINTER(_retval); - if(mDocShell) + if (mDocShell) { nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); return docShellAsItem->NameEquals(aName, _retval); } - else - *_retval = mInitInfo->name.Equals(aName); + *_retval = mInitInfo->name.Equals(aName); return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetItemType(PRInt32* aItemType) { - NS_ENSURE_ARG_POINTER(aItemType); + NS_ENSURE_ARG_POINTER(aItemType); - *aItemType = mContentType; - return NS_OK; + *aItemType = mContentType; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetItemType(PRInt32 aItemType) { - NS_ENSURE_TRUE((aItemType == typeContentWrapper || aItemType == typeChromeWrapper), NS_ERROR_FAILURE); + NS_ENSURE_TRUE((aItemType == typeContentWrapper || aItemType == typeChromeWrapper), + NS_ERROR_FAILURE); mContentType = aItemType; if (mDocShellAsItem) - mDocShellAsItem->SetItemType(mContentType == typeChromeWrapper ? typeChrome : typeContent); + mDocShellAsItem->SetItemType(mContentType == typeChromeWrapper + ? typeChrome + : typeContent); + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetParent(nsIDocShellTreeItem** aParent) { - *aParent = nsnull; - return NS_OK; + *aParent = nsnull; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetSameTypeParent(nsIDocShellTreeItem** aParent) { - *aParent = nsnull; + *aParent = nsnull; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) { - NS_ENSURE_ARG_POINTER(aRootTreeItem); - *aRootTreeItem = static_cast(this); + NS_ENSURE_ARG_POINTER(aRootTreeItem); + *aRootTreeItem = static_cast(this); - nsCOMPtr parent; - NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); - while(parent) - { - *aRootTreeItem = parent; - NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); - } - NS_ADDREF(*aRootTreeItem); - return NS_OK; + nsCOMPtr parent; + NS_ENSURE_SUCCESS(GetParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); + while (parent) + { + *aRootTreeItem = parent; + NS_ENSURE_SUCCESS((*aRootTreeItem)->GetParent(getter_AddRefs(parent)), + NS_ERROR_FAILURE); + } + NS_ADDREF(*aRootTreeItem); + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetSameTypeRootTreeItem(nsIDocShellTreeItem** aRootTreeItem) { - NS_ENSURE_ARG_POINTER(aRootTreeItem); - *aRootTreeItem = static_cast(this); + NS_ENSURE_ARG_POINTER(aRootTreeItem); + *aRootTreeItem = static_cast(this); - nsCOMPtr parent; - NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); - while(parent) - { - *aRootTreeItem = parent; - NS_ENSURE_SUCCESS((*aRootTreeItem)->GetSameTypeParent(getter_AddRefs(parent)), - NS_ERROR_FAILURE); - } - NS_ADDREF(*aRootTreeItem); - return NS_OK; + nsCOMPtr parent; + NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parent)), NS_ERROR_FAILURE); + while (parent) + { + *aRootTreeItem = parent; + NS_ENSURE_SUCCESS((*aRootTreeItem)->GetSameTypeParent(getter_AddRefs(parent)), + NS_ERROR_FAILURE); + } + NS_ADDREF(*aRootTreeItem); + return NS_OK; } -NS_IMETHODIMP nsWebBrowser::FindItemWithName(const PRUnichar *aName, - nsISupports* aRequestor, nsIDocShellTreeItem* aOriginalRequestor, - nsIDocShellTreeItem **_retval) +NS_IMETHODIMP nsWebBrowser::FindItemWithName( + const PRUnichar *aName, + nsISupports* aRequestor, + nsIDocShellTreeItem* aOriginalRequestor, + nsIDocShellTreeItem **_retval) { - NS_ENSURE_STATE(mDocShell); - NS_ASSERTION(mDocShellTreeOwner, "This should always be set when in this situation"); + NS_ENSURE_STATE(mDocShell); + NS_ASSERTION(mDocShellTreeOwner, "This should always be set when in this situation"); - return mDocShellAsItem->FindItemWithName(aName, - static_cast(mDocShellTreeOwner), - aOriginalRequestor, _retval); + return mDocShellAsItem->FindItemWithName(aName, + static_cast(mDocShellTreeOwner), + aOriginalRequestor, _retval); } NS_IMETHODIMP nsWebBrowser::GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner) -{ +{ NS_ENSURE_ARG_POINTER(aTreeOwner); *aTreeOwner = nsnull; - if(mDocShellTreeOwner) + if (mDocShellTreeOwner) { if (mDocShellTreeOwner->mTreeOwner) { @@ -562,8 +572,8 @@ NS_IMETHODIMP nsWebBrowser::GetTreeOwner NS_IMETHODIMP nsWebBrowser::SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner) { - NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); - return mDocShellTreeOwner->SetTreeOwner(aTreeOwner); + NS_ENSURE_SUCCESS(EnsureDocShellTreeOwner(), NS_ERROR_FAILURE); + return mDocShellTreeOwner->SetTreeOwner(aTreeOwner); } //***************************************************************************** @@ -594,11 +604,11 @@ NS_IMETHODIMP nsWebBrowser::GetChildAt(P } NS_IMETHODIMP nsWebBrowser::FindChildWithName( - const PRUnichar * aName, - PRBool aRecurse, PRBool aSameType, - nsIDocShellTreeItem * aRequestor, - nsIDocShellTreeItem * aOriginalRequestor, - nsIDocShellTreeItem ** _retval) + const PRUnichar * aName, + PRBool aRecurse, PRBool aSameType, + nsIDocShellTreeItem * aRequestor, + nsIDocShellTreeItem * aOriginalRequestor, + nsIDocShellTreeItem ** _retval) { NS_ENSURE_ARG_POINTER(_retval); @@ -612,73 +622,74 @@ NS_IMETHODIMP nsWebBrowser::FindChildWit NS_IMETHODIMP nsWebBrowser::GetCanGoBack(PRBool* aCanGoBack) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GetCanGoBack(aCanGoBack); + return mDocShellAsNav->GetCanGoBack(aCanGoBack); } NS_IMETHODIMP nsWebBrowser::GetCanGoForward(PRBool* aCanGoForward) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GetCanGoForward(aCanGoForward); + return mDocShellAsNav->GetCanGoForward(aCanGoForward); } NS_IMETHODIMP nsWebBrowser::GoBack() { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GoBack(); + return mDocShellAsNav->GoBack(); } NS_IMETHODIMP nsWebBrowser::GoForward() { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GoForward(); + return mDocShellAsNav->GoForward(); } -NS_IMETHODIMP nsWebBrowser::LoadURI(const PRUnichar* aURI, - PRUint32 aLoadFlags, - nsIURI* aReferringURI, - nsIInputStream* aPostDataStream, - nsIInputStream* aExtraHeaderStream) +NS_IMETHODIMP nsWebBrowser::LoadURI( + const PRUnichar* aURI, + PRUint32 aLoadFlags, + nsIURI* aReferringURI, + nsIInputStream* aPostDataStream, + nsIInputStream* aExtraHeaderStream) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->LoadURI(aURI, - aLoadFlags, - aReferringURI, - aPostDataStream, - aExtraHeaderStream); + return mDocShellAsNav->LoadURI(aURI, + aLoadFlags, + aReferringURI, + aPostDataStream, + aExtraHeaderStream); } NS_IMETHODIMP nsWebBrowser::Reload(PRUint32 aReloadFlags) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->Reload(aReloadFlags); + return mDocShellAsNav->Reload(aReloadFlags); } NS_IMETHODIMP nsWebBrowser::GotoIndex(PRInt32 aIndex) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GotoIndex(aIndex); + return mDocShellAsNav->GotoIndex(aIndex); } NS_IMETHODIMP nsWebBrowser::Stop(PRUint32 aStopFlags) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->Stop(aStopFlags); + return mDocShellAsNav->Stop(aStopFlags); } NS_IMETHODIMP nsWebBrowser::GetCurrentURI(nsIURI** aURI) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GetCurrentURI(aURI); + return mDocShellAsNav->GetCurrentURI(aURI); } NS_IMETHODIMP nsWebBrowser::GetReferringURI(nsIURI** aURI) @@ -690,33 +701,31 @@ NS_IMETHODIMP nsWebBrowser::GetReferring NS_IMETHODIMP nsWebBrowser::SetSessionHistory(nsISHistory* aSessionHistory) { - if(mDocShell) - return mDocShellAsNav->SetSessionHistory(aSessionHistory); - else - mInitInfo->sessionHistory = aSessionHistory; + if (mDocShell) + return mDocShellAsNav->SetSessionHistory(aSessionHistory); - return NS_OK; + mInitInfo->sessionHistory = aSessionHistory; + + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetSessionHistory(nsISHistory** aSessionHistory) { - NS_ENSURE_ARG_POINTER(aSessionHistory); - if(mDocShell) - return mDocShellAsNav->GetSessionHistory(aSessionHistory); - else - *aSessionHistory = mInitInfo->sessionHistory; + NS_ENSURE_ARG_POINTER(aSessionHistory); + if (mDocShell) + return mDocShellAsNav->GetSessionHistory(aSessionHistory); - NS_IF_ADDREF(*aSessionHistory); + NS_IF_ADDREF(*aSessionHistory = mInitInfo->sessionHistory); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetDocument(nsIDOMDocument** aDocument) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsNav->GetDocument(aDocument); + return mDocShellAsNav->GetDocument(aDocument); } @@ -728,72 +737,72 @@ NS_IMETHODIMP nsWebBrowser::GetDocument( NS_IMETHODIMP nsWebBrowser::SetProperty(PRUint32 aId, PRUint32 aValue) { nsresult rv = NS_OK; - + switch (aId) { - case nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS: + case nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS: { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - mDocShell->SetAllowPlugins(!!aValue); + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + mDocShell->SetAllowPlugins(!!aValue); + break; } - break; - case nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT: + case nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT: { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - mDocShell->SetAllowJavascript(!!aValue); + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + mDocShell->SetAllowJavascript(!!aValue); + break; } - break; - case nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS: + case nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS: { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - mDocShell->SetAllowMetaRedirects(!!aValue); + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + mDocShell->SetAllowMetaRedirects(!!aValue); + break; } - break; - case nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES: + case nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES: { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - mDocShell->SetAllowSubframes(!!aValue); + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + mDocShell->SetAllowSubframes(!!aValue); + break; } - break; - case nsIWebBrowserSetup::SETUP_ALLOW_IMAGES: + case nsIWebBrowserSetup::SETUP_ALLOW_IMAGES: { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - mDocShell->SetAllowImages(!!aValue); + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + mDocShell->SetAllowImages(!!aValue); + break; } - break; - case nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH: + case nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH: { NS_ENSURE_STATE(mDocShell); NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); mDocShell->SetAllowDNSPrefetch(!!aValue); } - case nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY: + case nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY: { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - rv = EnableGlobalHistory(!!aValue); - mShouldEnableHistory = aValue; + NS_ENSURE_STATE(mDocShell); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + rv = EnableGlobalHistory(!!aValue); + mShouldEnableHistory = aValue; + break; } - break; - case nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT: + case nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT: { // obsolete + break; } - break; - case nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER: + case nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER: { - NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); - SetItemType(aValue ? typeChromeWrapper : typeContentWrapper); + NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG); + SetItemType(aValue ? typeChromeWrapper : typeContentWrapper); + break; } - break; - default: - rv = NS_ERROR_INVALID_ARG; - + default: + rv = NS_ERROR_INVALID_ARG; + } return rv; } @@ -804,7 +813,11 @@ NS_IMETHODIMP nsWebBrowser::SetProperty( //***************************************************************************** /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */ -NS_IMETHODIMP nsWebBrowser::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) +NS_IMETHODIMP nsWebBrowser::OnStateChange( + nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 aStateFlags, + nsresult aStatus) { if (mPersist) { @@ -822,7 +835,13 @@ NS_IMETHODIMP nsWebBrowser::OnStateChang } /* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP nsWebBrowser::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) +NS_IMETHODIMP nsWebBrowser::OnProgressChange( + nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) { if (mPersist) { @@ -830,13 +849,21 @@ NS_IMETHODIMP nsWebBrowser::OnProgressCh } if (mProgressListener) { - return mProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress); + return mProgressListener->OnProgressChange(aWebProgress, + aRequest, + aCurSelfProgress, + aMaxSelfProgress, + aCurTotalProgress, + aMaxTotalProgress); } return NS_OK; } /* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP nsWebBrowser::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) +NS_IMETHODIMP nsWebBrowser::OnLocationChange( + nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsIURI *location) { if (mProgressListener) { @@ -846,7 +873,11 @@ NS_IMETHODIMP nsWebBrowser::OnLocationCh } /* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP nsWebBrowser::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) +NS_IMETHODIMP nsWebBrowser::OnStatusChange( + nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsresult aStatus, + const PRUnichar *aMessage) { if (mProgressListener) { @@ -856,7 +887,10 @@ NS_IMETHODIMP nsWebBrowser::OnStatusChan } /* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP nsWebBrowser::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) +NS_IMETHODIMP nsWebBrowser::OnSecurityChange( + nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 state) { if (mProgressListener) { @@ -881,6 +915,7 @@ NS_IMETHODIMP nsWebBrowser::GetPersistFl *aPersistFlags = mPersistFlags; return rv; } + NS_IMETHODIMP nsWebBrowser::SetPersistFlags(PRUint32 aPersistFlags) { nsresult rv = NS_OK; @@ -922,11 +957,11 @@ NS_IMETHODIMP nsWebBrowser::GetResult(PR NS_IMETHODIMP nsWebBrowser::GetProgressListener(nsIWebProgressListener * *aProgressListener) { NS_ENSURE_ARG_POINTER(aProgressListener); - *aProgressListener = mProgressListener; - NS_IF_ADDREF(*aProgressListener); + + NS_IF_ADDREF(*aProgressListener = mProgressListener); return NS_OK; } - + NS_IMETHODIMP nsWebBrowser::SetProgressListener(nsIWebProgressListener * aProgressListener) { mProgressListener = aProgressListener; @@ -934,25 +969,25 @@ NS_IMETHODIMP nsWebBrowser::SetProgressL } /* void saveURI (in nsIURI aURI, in nsIURI aReferrer, - in nsISupports aCacheKey, in nsIInputStream aPostData, in wstring aExtraHeaders, - in nsISupports aFile); */ + in nsISupports aCacheKey, in nsIInputStream aPostData, in wstring aExtraHeaders, + in nsISupports aFile); */ NS_IMETHODIMP nsWebBrowser::SaveURI( - nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer, nsIInputStream *aPostData, - const char *aExtraHeaders, nsISupports *aFile) + nsIURI *aURI, nsISupports *aCacheKey, + nsIURI *aReferrer, + nsIInputStream *aPostData, + const char *aExtraHeaders, + nsISupports *aFile) { if (mPersist) { PRUint32 currentState; mPersist->GetCurrentState(¤tState); - if (currentState == PERSIST_STATE_FINISHED) - { - mPersist = nsnull; - } - else + if (currentState != PERSIST_STATE_FINISHED) { // You can't save again until the last save has completed return NS_ERROR_FAILURE; } + mPersist = nsnull; } nsCOMPtr uri; @@ -986,21 +1021,19 @@ NS_IMETHODIMP nsWebBrowser::SaveURI( /* void saveChannel (in nsIChannel aChannel, in nsISupports aFile); */ NS_IMETHODIMP nsWebBrowser::SaveChannel( - nsIChannel* aChannel, nsISupports *aFile) + nsIChannel* aChannel, + nsISupports *aFile) { if (mPersist) { PRUint32 currentState; mPersist->GetCurrentState(¤tState); - if (currentState == PERSIST_STATE_FINISHED) - { - mPersist = nsnull; - } - else + if (currentState != PERSIST_STATE_FINISHED) { // You can't save again until the last save has completed return NS_ERROR_FAILURE; } + mPersist = nsnull; } // Create a throwaway persistence object to do the work @@ -1020,8 +1053,12 @@ NS_IMETHODIMP nsWebBrowser::SaveChannel( /* void saveDocument (in nsIDOMDocument document, in nsISupports aFile, in nsISupports aDataPath); */ NS_IMETHODIMP nsWebBrowser::SaveDocument( - nsIDOMDocument *aDocument, nsISupports *aFile, nsISupports *aDataPath, - const char *aOutputContentType, PRUint32 aEncodingFlags, PRUint32 aWrapColumn) + nsIDOMDocument *aDocument, + nsISupports *aFile, + nsISupports *aDataPath, + const char *aOutputContentType, + PRUint32 aEncodingFlags, + PRUint32 aWrapColumn) { if (mPersist) { @@ -1029,13 +1066,10 @@ NS_IMETHODIMP nsWebBrowser::SaveDocument mPersist->GetCurrentState(¤tState); if (currentState == PERSIST_STATE_FINISHED) { - mPersist = nsnull; - } - else - { // You can't save again until the last save has completed return NS_ERROR_FAILURE; } + mPersist = nsnull; } // Use the specified DOM document, or if none is specified, the one @@ -1062,7 +1096,12 @@ NS_IMETHODIMP nsWebBrowser::SaveDocument mPersist->SetProgressListener(this); mPersist->SetPersistFlags(mPersistFlags); mPersist->GetCurrentState(&mPersistCurrentState); - rv = mPersist->SaveDocument(doc, aFile, aDataPath, aOutputContentType, aEncodingFlags, aWrapColumn); + rv = mPersist->SaveDocument(doc, + aFile, + aDataPath, + aOutputContentType, + aEncodingFlags, + aWrapColumn); if (NS_FAILED(rv)) { mPersist = nsnull; @@ -1090,808 +1129,854 @@ NS_IMETHODIMP nsWebBrowser::Cancel(nsres return NS_OK; } - - - //***************************************************************************** // nsWebBrowser::nsIBaseWindow //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::InitWindow(nativeWindow aParentNativeWindow, - nsIWidget* aParentWidget, PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY) +NS_IMETHODIMP nsWebBrowser::InitWindow( + nativeWindow aParentNativeWindow, + nsIWidget* aParentWidget, + PRInt32 aX, + PRInt32 aY, + PRInt32 aCX, + PRInt32 aCY) { - NS_ENSURE_ARG(aParentNativeWindow || aParentWidget); - NS_ENSURE_STATE(!mDocShell || mInitInfo); + NS_ENSURE_ARG(aParentNativeWindow || aParentWidget); + NS_ENSURE_STATE(!mDocShell || mInitInfo); - if(aParentWidget) - NS_ENSURE_SUCCESS(SetParentWidget(aParentWidget), NS_ERROR_FAILURE); - else - NS_ENSURE_SUCCESS(SetParentNativeWindow(aParentNativeWindow), - NS_ERROR_FAILURE); + if (aParentWidget) { + NS_ENSURE_SUCCESS(SetParentWidget(aParentWidget), NS_ERROR_FAILURE); + } else { + NS_ENSURE_SUCCESS(SetParentNativeWindow(aParentNativeWindow), + NS_ERROR_FAILURE); + } - NS_ENSURE_SUCCESS(SetPositionAndSize(aX, aY, aCX, aCY, PR_FALSE), - NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(SetPositionAndSize(aX, aY, aCX, aCY, PR_FALSE), + NS_ERROR_FAILURE); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::Create() { - NS_ENSURE_STATE(!mDocShell && (mParentNativeWindow || mParentWidget)); + NS_ENSURE_STATE(!mDocShell && (mParentNativeWindow || mParentWidget)); nsresult rv = EnsureDocShellTreeOwner(); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr docShellParentWidget(mParentWidget); - if(!mParentWidget) // We need to create a widget - { - // Create the widget + nsCOMPtr docShellParentWidget(mParentWidget); + if (!mParentWidget) // We need to create a widget + { + // Create the widget mInternalWidget = do_CreateInstance(kChildCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - docShellParentWidget = mInternalWidget; - nsWidgetInitData widgetInit; + docShellParentWidget = mInternalWidget; + nsWidgetInitData widgetInit; - widgetInit.clipChildren = PR_TRUE; - widgetInit.mContentType = (mContentType == typeChrome || - mContentType == typeChromeWrapper)? eContentTypeUI: eContentTypeContent; + widgetInit.clipChildren = PR_TRUE; + widgetInit.mContentType = (mContentType == typeChrome || + mContentType == typeChromeWrapper) + ? eContentTypeUI + : eContentTypeContent; - widgetInit.mWindowType = eWindowType_child; - nsIntRect bounds(mInitInfo->x, mInitInfo->y, mInitInfo->cx, mInitInfo->cy); - - mInternalWidget->SetClientData(static_cast(this)); - mInternalWidget->Create(nsnull, mParentNativeWindow, bounds, nsWebBrowser::HandleEvent, - nsnull, nsnull, nsnull, &widgetInit); - } + widgetInit.mWindowType = eWindowType_child; + nsIntRect bounds(mInitInfo->x, mInitInfo->y, mInitInfo->cx, mInitInfo->cy); + + mInternalWidget->SetClientData(static_cast(this)); + mInternalWidget->Create(nsnull, + mParentNativeWindow, + bounds, + nsWebBrowser::HandleEvent, + nsnull, + nsnull, + nsnull, + &widgetInit); + } nsCOMPtr docShell(do_CreateInstance("@mozilla.org/docshell;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); rv = SetDocShell(docShell); NS_ENSURE_SUCCESS(rv, rv); - // get the system default window background colour - { - nsCOMPtr laf = do_GetService(kLookAndFeelCID); + // get the system default window background colour + { + nsCOMPtr laf = do_GetService(kLookAndFeelCID); if (laf) - laf->GetColor(nsILookAndFeel::eColor_WindowBackground, mBackgroundColor); - } + laf->GetColor(nsILookAndFeel::eColor_WindowBackground, mBackgroundColor); + } - // the docshell has been set so we now have our listener registrars. - if (mListenerArray) { - // we had queued up some listeners, let's register them now. - PRUint32 count = mListenerArray->Length(); - PRUint32 i = 0; - NS_ASSERTION(count > 0, "array construction problem"); - while (i < count) { - nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); - NS_ASSERTION(state, "array construction problem"); - nsCOMPtr listener = do_QueryReferent(state->mWeakPtr); - NS_ASSERTION(listener, "bad listener"); - (void)BindListener(listener, state->mID); - i++; - } - for (PRUint32 i = 0, end = mListenerArray->Length(); i < end; i++) { - nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); - NS_DELETEXPCOM(state); - } - NS_DELETEXPCOM(mListenerArray); - mListenerArray = nsnull; - } + // the docshell has been set so we now have our listener registrars. + if (mListenerArray) { + // we had queued up some listeners, let's register them now. + PRUint32 count = mListenerArray->Length(); + PRUint32 i = 0; + NS_ASSERTION(count > 0, "array construction problem"); + while (i < count) { + nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); + NS_ASSERTION(state, "array construction problem"); + nsCOMPtr listener = do_QueryReferent(state->mWeakPtr); + NS_ASSERTION(listener, "bad listener"); + (void)BindListener(listener, state->mID); + i++; + } + for (PRUint32 i = 0, end = mListenerArray->Length(); i < end; i++) { + nsWebBrowserListenerState *state = mListenerArray->ElementAt(i); + NS_DELETEXPCOM(state); + } + NS_DELETEXPCOM(mListenerArray); + mListenerArray = nsnull; + } - // HACK ALERT - this registration registers the nsDocShellTreeOwner as a - // nsIWebBrowserListener so it can setup its MouseListener in one of the - // progress callbacks. If we can register the MouseListener another way, this - // registration can go away, and nsDocShellTreeOwner can stop implementing - // nsIWebProgressListener. - nsCOMPtr supports = nsnull; - (void)mDocShellTreeOwner->QueryInterface(NS_GET_IID(nsIWebProgressListener), - static_cast(getter_AddRefs(supports))); - (void)BindListener(supports, NS_GET_IID(nsIWebProgressListener)); + // HACK ALERT - this registration registers the nsDocShellTreeOwner as a + // nsIWebBrowserListener so it can setup its MouseListener in one of the + // progress callbacks. If we can register the MouseListener another way, this + // registration can go away, and nsDocShellTreeOwner can stop implementing + // nsIWebProgressListener. + nsCOMPtr supports = nsnull; + (void)mDocShellTreeOwner->QueryInterface(NS_GET_IID(nsIWebProgressListener), + static_cast(getter_AddRefs(supports))); + (void)BindListener(supports, NS_GET_IID(nsIWebProgressListener)); - NS_ENSURE_SUCCESS(mDocShellAsWin->InitWindow(nsnull, - docShellParentWidget, mInitInfo->x, mInitInfo->y, mInitInfo->cx, - mInitInfo->cy), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mDocShellAsWin->InitWindow(nsnull, + docShellParentWidget, + mInitInfo->x, + mInitInfo->y, + mInitInfo->cx, + mInitInfo->cy), + NS_ERROR_FAILURE); - mDocShellAsItem->SetName(mInitInfo->name.get()); - if (mContentType == typeChromeWrapper) - { - mDocShellAsItem->SetItemType(nsIDocShellTreeItem::typeChrome); - } - else - { - mDocShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent); - } - mDocShellAsItem->SetTreeOwner(mDocShellTreeOwner); - - // If the webbrowser is a content docshell item then we won't hear any - // events from subframes. To solve that we install our own chrome event handler - // that always gets called (even for subframes) for any bubbling event. + mDocShellAsItem->SetName(mInitInfo->name.get()); + if (mContentType == typeChromeWrapper) + { + mDocShellAsItem->SetItemType(nsIDocShellTreeItem::typeChrome); + } + else + { + mDocShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent); + } + mDocShellAsItem->SetTreeOwner(mDocShellTreeOwner); + + // If the webbrowser is a content docshell item then we won't hear any + // events from subframes. To solve that we install our own chrome event handler + // that always gets called (even for subframes) for any bubbling event. if (!mInitInfo->sessionHistory) { mInitInfo->sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); } - mDocShellAsNav->SetSessionHistory(mInitInfo->sessionHistory); - - // Hook up global history. Do not fail if we can't - just warn. + mDocShellAsNav->SetSessionHistory(mInitInfo->sessionHistory); + + // Hook up global history. Do not fail if we can't - just warn. rv = EnableGlobalHistory(mShouldEnableHistory); - NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "EnableGlobalHistory() failed"); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "EnableGlobalHistory() failed"); - NS_ENSURE_SUCCESS(mDocShellAsWin->Create(), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mDocShellAsWin->Create(), NS_ERROR_FAILURE); // Hook into the OnSecurityChange() notification for lock/unlock icon - // updates - nsCOMPtr domWindow; - rv = GetContentDOMWindow(getter_AddRefs(domWindow)); - if (NS_SUCCEEDED(rv)) - { - // this works because the implementation of nsISecureBrowserUI - // (nsSecureBrowserUIImpl) gets a docShell from the domWindow, - // and calls docShell->SetSecurityUI(this); - nsCOMPtr securityUI = - do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); + // updates + nsCOMPtr domWindow; + rv = GetContentDOMWindow(getter_AddRefs(domWindow)); + if (NS_SUCCEEDED(rv)) + { + // this works because the implementation of nsISecureBrowserUI + // (nsSecureBrowserUIImpl) gets a docShell from the domWindow, + // and calls docShell->SetSecurityUI(this); + nsCOMPtr securityUI = + do_CreateInstance(NS_SECURE_BROWSER_UI_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) securityUI->Init(domWindow); - } + } - mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0) - mDocShellTreeOwner->AddChromeListeners(); + mDocShellTreeOwner->AddToWatcher(); // evil twin of Remove in SetDocShell(0) + mDocShellTreeOwner->AddChromeListeners(); - delete mInitInfo; - mInitInfo = nsnull; + delete mInitInfo; + mInitInfo = nsnull; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::Destroy() { - InternalDestroy(); + InternalDestroy(); - if(!mInitInfo) - mInitInfo = new nsWebBrowserInitInfo(); + if (!mInitInfo) + mInitInfo = new nsWebBrowserInitInfo(); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetPosition(PRInt32 aX, PRInt32 aY) { - PRInt32 cx = 0; - PRInt32 cy = 0; + PRInt32 cx = 0; + PRInt32 cy = 0; - GetSize(&cx, &cy); + GetSize(&cx, &cy); - return SetPositionAndSize(aX, aY, cx, cy, PR_FALSE); + return SetPositionAndSize(aX, aY, cx, cy, PR_FALSE); } NS_IMETHODIMP nsWebBrowser::GetPosition(PRInt32* aX, PRInt32* aY) { - return GetPositionAndSize(aX, aY, nsnull, nsnull); + return GetPositionAndSize(aX, aY, nsnull, nsnull); } NS_IMETHODIMP nsWebBrowser::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint) { - PRInt32 x = 0; - PRInt32 y = 0; + PRInt32 x = 0; + PRInt32 y = 0; - GetPosition(&x, &y); + GetPosition(&x, &y); - return SetPositionAndSize(x, y, aCX, aCY, aRepaint); + return SetPositionAndSize(x, y, aCX, aCY, aRepaint); } NS_IMETHODIMP nsWebBrowser::GetSize(PRInt32* aCX, PRInt32* aCY) { - return GetPositionAndSize(nsnull, nsnull, aCX, aCY); + return GetPositionAndSize(nsnull, nsnull, aCX, aCY); } -NS_IMETHODIMP nsWebBrowser::SetPositionAndSize(PRInt32 aX, PRInt32 aY, - PRInt32 aCX, PRInt32 aCY, PRBool aRepaint) +NS_IMETHODIMP nsWebBrowser::SetPositionAndSize( + PRInt32 aX, + PRInt32 aY, + PRInt32 aCX, + PRInt32 aCY, + PRBool aRepaint) { - if(!mDocShell) - { - mInitInfo->x = aX; - mInitInfo->y = aY; - mInitInfo->cx = aCX; - mInitInfo->cy = aCY; - } - else - { - PRInt32 doc_x = aX; - PRInt32 doc_y = aY; + if (!mDocShell) + { + mInitInfo->x = aX; + mInitInfo->y = aY; + mInitInfo->cx = aCX; + mInitInfo->cy = aCY; + } + else + { + PRInt32 doc_x = aX; + PRInt32 doc_y = aY; - // If there is an internal widget we need to make the docShell coordinates - // relative to the internal widget rather than the calling app's parent. - // We also need to resize our widget then. - if(mInternalWidget) - { - doc_x = doc_y = 0; - NS_ENSURE_SUCCESS(mInternalWidget->Resize(aX, aY, aCX, aCY, aRepaint), - NS_ERROR_FAILURE); - } - // Now reposition/ resize the doc - NS_ENSURE_SUCCESS(mDocShellAsWin->SetPositionAndSize(doc_x, doc_y, aCX, aCY, - aRepaint), NS_ERROR_FAILURE); - } + // If there is an internal widget we need to make the docShell coordinates + // relative to the internal widget rather than the calling app's parent. + // We also need to resize our widget then. + if (mInternalWidget) + { + doc_x = doc_y = 0; + NS_ENSURE_SUCCESS(mInternalWidget->Resize(aX, aY, aCX, aCY, aRepaint), + NS_ERROR_FAILURE); + } + // Now reposition/ resize the doc + NS_ENSURE_SUCCESS(mDocShellAsWin->SetPositionAndSize(doc_x, + doc_y, + aCX, + aCY, + aRepaint), + NS_ERROR_FAILURE); + } - return NS_OK; + return NS_OK; } -NS_IMETHODIMP nsWebBrowser::GetPositionAndSize(PRInt32* aX, PRInt32* aY, - PRInt32* aCX, PRInt32* aCY) +NS_IMETHODIMP nsWebBrowser::GetPositionAndSize(PRInt32* aX, PRInt32* aY, + PRInt32* aCX, PRInt32* aCY) { - if(!mDocShell) - { - if(aX) - *aX = mInitInfo->x; - if(aY) - *aY = mInitInfo->y; - if(aCX) - *aCX = mInitInfo->cx; - if(aCY) - *aCY = mInitInfo->cy; - } - else - { - if(mInternalWidget) - { - nsIntRect bounds; - NS_ENSURE_SUCCESS(mInternalWidget->GetBounds(bounds), NS_ERROR_FAILURE); + if (mDocShell) + { + if (!mInternalWidget) + return mDocShellAsWin->GetPositionAndSize(aX, aY, aCX, aCY); // Can directly return this as it is the - if(aX) + nsIntRect bounds; + NS_ENSURE_SUCCESS(mInternalWidget->GetBounds(bounds), NS_ERROR_FAILURE); + + if (aX) *aX = bounds.x; - if(aY) + if (aY) *aY = bounds.y; - if(aCX) + if (aCX) *aCX = bounds.width; - if(aCY) + if (aCY) *aCY = bounds.height; - return NS_OK; - } - else - return mDocShellAsWin->GetPositionAndSize(aX, aY, aCX, aCY); // Can directly return this as it is the - } - return NS_OK; + return NS_OK; + } + + if (aX) + *aX = mInitInfo->x; + if (aY) + *aY = mInitInfo->y; + if (aCX) + *aCX = mInitInfo->cx; + if (aCY) + *aCY = mInitInfo->cy; + + return NS_OK; } NS_IMETHODIMP nsWebBrowser::Repaint(PRBool aForce) { - NS_ENSURE_STATE(mDocShell); - return mDocShellAsWin->Repaint(aForce); // Can directly return this as it is the + NS_ENSURE_STATE(mDocShell); + return mDocShellAsWin->Repaint(aForce); // Can directly return this as it is the } // same interface, thus same returns. NS_IMETHODIMP nsWebBrowser::GetParentWidget(nsIWidget** aParentWidget) { - NS_ENSURE_ARG_POINTER(aParentWidget); + NS_ENSURE_ARG_POINTER(aParentWidget); - *aParentWidget = mParentWidget; + *aParentWidget = mParentWidget; - NS_IF_ADDREF(*aParentWidget); + NS_IF_ADDREF(*aParentWidget); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetParentWidget(nsIWidget* aParentWidget) { - NS_ENSURE_STATE(!mDocShell); + NS_ENSURE_STATE(!mDocShell); - mParentWidget = aParentWidget; - if(mParentWidget) - mParentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET); - else - mParentNativeWindow = nsnull; + mParentWidget = aParentWidget; + if (mParentWidget) + mParentNativeWindow = mParentWidget->GetNativeData(NS_NATIVE_WIDGET); + else + mParentNativeWindow = nsnull; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetParentNativeWindow(nativeWindow* aParentNativeWindow) { - NS_ENSURE_ARG_POINTER(aParentNativeWindow); - - *aParentNativeWindow = mParentNativeWindow; + NS_ENSURE_ARG_POINTER(aParentNativeWindow); - return NS_OK; + *aParentNativeWindow = mParentNativeWindow; + + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetParentNativeWindow(nativeWindow aParentNativeWindow) { - NS_ENSURE_STATE(!mDocShell); + NS_ENSURE_STATE(!mDocShell); - mParentNativeWindow = aParentNativeWindow; + mParentNativeWindow = aParentNativeWindow; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetVisibility(PRBool* visibility) { - NS_ENSURE_ARG_POINTER(visibility); + NS_ENSURE_ARG_POINTER(visibility); - if(!mDocShell) - *visibility = mInitInfo->visible; - else - NS_ENSURE_SUCCESS(mDocShellAsWin->GetVisibility(visibility), NS_ERROR_FAILURE); + if (!mDocShell) + *visibility = mInitInfo->visible; + else { + NS_ENSURE_SUCCESS(mDocShellAsWin->GetVisibility(visibility), NS_ERROR_FAILURE); + } - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetVisibility(PRBool aVisibility) { - if(!mDocShell) - mInitInfo->visible = aVisibility; - else - { - NS_ENSURE_SUCCESS(mDocShellAsWin->SetVisibility(aVisibility), NS_ERROR_FAILURE); - if(mInternalWidget) - mInternalWidget->Show(aVisibility); - } + if (!mDocShell) + mInitInfo->visible = aVisibility; + else + { + NS_ENSURE_SUCCESS(mDocShellAsWin->SetVisibility(aVisibility), NS_ERROR_FAILURE); + if (mInternalWidget) + mInternalWidget->Show(aVisibility); + } - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::GetEnabled(PRBool *aEnabled) { - if (mInternalWidget) - return mInternalWidget->IsEnabled(aEnabled); - return NS_ERROR_FAILURE; + if (mInternalWidget) + return mInternalWidget->IsEnabled(aEnabled); + + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsWebBrowser::SetEnabled(PRBool aEnabled) { - if (mInternalWidget) - return mInternalWidget->Enable(aEnabled); - return NS_ERROR_FAILURE; + if (mInternalWidget) + return mInternalWidget->Enable(aEnabled); + + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsWebBrowser::GetBlurSuppression(PRBool *aBlurSuppression) { - NS_ENSURE_ARG_POINTER(aBlurSuppression); - *aBlurSuppression = PR_FALSE; - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_ARG_POINTER(aBlurSuppression); + *aBlurSuppression = PR_FALSE; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsWebBrowser::SetBlurSuppression(PRBool aBlurSuppression) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsWebBrowser::GetMainWidget(nsIWidget** mainWidget) { - NS_ENSURE_ARG_POINTER(mainWidget); + NS_ENSURE_ARG_POINTER(mainWidget); - if(mInternalWidget) - *mainWidget = mInternalWidget; - else - *mainWidget = mParentWidget; + if (mInternalWidget) + *mainWidget = mInternalWidget; + else + *mainWidget = mParentWidget; - NS_IF_ADDREF(*mainWidget); + NS_IF_ADDREF(*mainWidget); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetFocus() { - nsCOMPtr window = do_GetInterface(mDocShell); - NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + nsCOMPtr window = do_GetInterface(mDocShell); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - return fm ? fm->SetFocusedWindow(window) : NS_OK; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + if (!fm) + return NS_OK; + + return fm->SetFocusedWindow(window); } NS_IMETHODIMP nsWebBrowser::GetTitle(PRUnichar** aTitle) { - NS_ENSURE_ARG_POINTER(aTitle); - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_ARG_POINTER(aTitle); + NS_ENSURE_STATE(mDocShell); - NS_ENSURE_SUCCESS(mDocShellAsWin->GetTitle(aTitle), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mDocShellAsWin->GetTitle(aTitle), NS_ERROR_FAILURE); - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsWebBrowser::SetTitle(const PRUnichar* aTitle) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - NS_ENSURE_SUCCESS(mDocShellAsWin->SetTitle(aTitle), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mDocShellAsWin->SetTitle(aTitle), NS_ERROR_FAILURE); - return NS_OK; + return NS_OK; } //***************************************************************************** // nsWebBrowser::nsIScrollable //***************************************************************************** -NS_IMETHODIMP nsWebBrowser::GetCurScrollPos(PRInt32 aScrollOrientation, - PRInt32* aCurPos) +NS_IMETHODIMP nsWebBrowser::GetCurScrollPos(PRInt32 aScrollOrientation, + PRInt32* aCurPos) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->GetCurScrollPos(aScrollOrientation, aCurPos); + return mDocShellAsScrollable->GetCurScrollPos(aScrollOrientation, aCurPos); } -NS_IMETHODIMP nsWebBrowser::SetCurScrollPos(PRInt32 aScrollOrientation, - PRInt32 aCurPos) +NS_IMETHODIMP nsWebBrowser::SetCurScrollPos(PRInt32 aScrollOrientation, + PRInt32 aCurPos) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->SetCurScrollPos(aScrollOrientation, aCurPos); + return mDocShellAsScrollable->SetCurScrollPos(aScrollOrientation, aCurPos); } -NS_IMETHODIMP nsWebBrowser::SetCurScrollPosEx(PRInt32 aCurHorizontalPos, - PRInt32 aCurVerticalPos) +NS_IMETHODIMP nsWebBrowser::SetCurScrollPosEx(PRInt32 aCurHorizontalPos, + PRInt32 aCurVerticalPos) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->SetCurScrollPosEx(aCurHorizontalPos, - aCurVerticalPos); + return mDocShellAsScrollable->SetCurScrollPosEx(aCurHorizontalPos, + aCurVerticalPos); } NS_IMETHODIMP nsWebBrowser::GetScrollRange(PRInt32 aScrollOrientation, - PRInt32* aMinPos, PRInt32* aMaxPos) + PRInt32* aMinPos, PRInt32* aMaxPos) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->GetScrollRange(aScrollOrientation, aMinPos, - aMaxPos); + return mDocShellAsScrollable->GetScrollRange(aScrollOrientation, aMinPos, + aMaxPos); } NS_IMETHODIMP nsWebBrowser::SetScrollRange(PRInt32 aScrollOrientation, - PRInt32 aMinPos, PRInt32 aMaxPos) + PRInt32 aMinPos, PRInt32 aMaxPos) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->SetScrollRange(aScrollOrientation, aMinPos, - aMaxPos); + return mDocShellAsScrollable->SetScrollRange(aScrollOrientation, aMinPos, + aMaxPos); } -NS_IMETHODIMP nsWebBrowser::SetScrollRangeEx(PRInt32 aMinHorizontalPos, - PRInt32 aMaxHorizontalPos, PRInt32 aMinVerticalPos, PRInt32 aMaxVerticalPos) +NS_IMETHODIMP nsWebBrowser::SetScrollRangeEx( + PRInt32 aMinHorizontalPos, + PRInt32 aMaxHorizontalPos, + PRInt32 aMinVerticalPos, + PRInt32 aMaxVerticalPos) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->SetScrollRangeEx(aMinHorizontalPos, - aMaxHorizontalPos, aMinVerticalPos, aMaxVerticalPos); + return mDocShellAsScrollable->SetScrollRangeEx(aMinHorizontalPos, + aMaxHorizontalPos, + aMinVerticalPos, + aMaxVerticalPos); } -NS_IMETHODIMP nsWebBrowser::GetDefaultScrollbarPreferences(PRInt32 aScrollOrientation, - PRInt32* aScrollbarPref) +NS_IMETHODIMP nsWebBrowser::GetDefaultScrollbarPreferences( + PRInt32 aScrollOrientation, + PRInt32* aScrollbarPref) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->GetDefaultScrollbarPreferences(aScrollOrientation, - aScrollbarPref); + return mDocShellAsScrollable->GetDefaultScrollbarPreferences(aScrollOrientation, + aScrollbarPref); } -NS_IMETHODIMP nsWebBrowser::SetDefaultScrollbarPreferences(PRInt32 aScrollOrientation, - PRInt32 aScrollbarPref) +NS_IMETHODIMP nsWebBrowser::SetDefaultScrollbarPreferences( + PRInt32 aScrollOrientation, + PRInt32 aScrollbarPref) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->SetDefaultScrollbarPreferences(aScrollOrientation, - aScrollbarPref); + return mDocShellAsScrollable->SetDefaultScrollbarPreferences(aScrollOrientation, + aScrollbarPref); } -NS_IMETHODIMP nsWebBrowser::GetScrollbarVisibility(PRBool* aVerticalVisible, - PRBool* aHorizontalVisible) +NS_IMETHODIMP nsWebBrowser::GetScrollbarVisibility( + PRBool* aVerticalVisible, + PRBool* aHorizontalVisible) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsScrollable->GetScrollbarVisibility(aVerticalVisible, - aHorizontalVisible); + return mDocShellAsScrollable->GetScrollbarVisibility(aVerticalVisible, + aHorizontalVisible); } //***************************************************************************** // nsWebBrowser::nsITextScroll -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP nsWebBrowser::ScrollByLines(PRInt32 aNumLines) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsTextScroll->ScrollByLines(aNumLines); + return mDocShellAsTextScroll->ScrollByLines(aNumLines); } NS_IMETHODIMP nsWebBrowser::ScrollByPages(PRInt32 aNumPages) { - NS_ENSURE_STATE(mDocShell); + NS_ENSURE_STATE(mDocShell); - return mDocShellAsTextScroll->ScrollByPages(aNumPages); + return mDocShellAsTextScroll->ScrollByPages(aNumPages); } //***************************************************************************** // nsWebBrowser: Listener Helpers -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP nsWebBrowser::SetDocShell(nsIDocShell* aDocShell) { - nsCOMPtr kungFuDeathGrip(mDocShell); - if(aDocShell) - { - NS_ENSURE_TRUE(!mDocShell, NS_ERROR_FAILURE); - - nsCOMPtr req(do_QueryInterface(aDocShell)); - nsCOMPtr baseWin(do_QueryInterface(aDocShell)); - nsCOMPtr item(do_QueryInterface(aDocShell)); - nsCOMPtr nav(do_QueryInterface(aDocShell)); - nsCOMPtr scrollable(do_QueryInterface(aDocShell)); - nsCOMPtr textScroll(do_QueryInterface(aDocShell)); - nsCOMPtr progress(do_GetInterface(aDocShell)); - NS_ENSURE_TRUE(req && baseWin && item && nav && scrollable && textScroll && progress, - NS_ERROR_FAILURE); - - mDocShell = aDocShell; - mDocShellAsReq = req; - mDocShellAsWin = baseWin; - mDocShellAsItem = item; - mDocShellAsNav = nav; - mDocShellAsScrollable = scrollable; - mDocShellAsTextScroll = textScroll; - mWebProgress = progress; + nsCOMPtr kungFuDeathGrip(mDocShell); + if (aDocShell) + { + NS_ENSURE_TRUE(!mDocShell, NS_ERROR_FAILURE); - // By default, do not allow DNS prefetch, so we don't break our frozen - // API. Embeddors who decide to enable it should do so manually. - mDocShell->SetAllowDNSPrefetch(PR_FALSE); - } - else - { - if (mDocShellTreeOwner) - mDocShellTreeOwner->RemoveFromWatcher(); // evil twin of Add in Create() - if (mDocShellAsWin) - mDocShellAsWin->Destroy(); + nsCOMPtr req(do_QueryInterface(aDocShell)); + nsCOMPtr baseWin(do_QueryInterface(aDocShell)); + nsCOMPtr item(do_QueryInterface(aDocShell)); + nsCOMPtr nav(do_QueryInterface(aDocShell)); + nsCOMPtr scrollable(do_QueryInterface(aDocShell)); + nsCOMPtr textScroll(do_QueryInterface(aDocShell)); + nsCOMPtr progress(do_GetInterface(aDocShell)); + NS_ENSURE_TRUE(req && baseWin && item && nav && scrollable && textScroll && progress, + NS_ERROR_FAILURE); - mDocShell = nsnull; - mDocShellAsReq = nsnull; - mDocShellAsWin = nsnull; - mDocShellAsItem = nsnull; - mDocShellAsNav = nsnull; - mDocShellAsScrollable = nsnull; - mDocShellAsTextScroll = nsnull; - mWebProgress = nsnull; - } + mDocShell = aDocShell; + mDocShellAsReq = req; + mDocShellAsWin = baseWin; + mDocShellAsItem = item; + mDocShellAsNav = nav; + mDocShellAsScrollable = scrollable; + mDocShellAsTextScroll = textScroll; + mWebProgress = progress; - return NS_OK; + // By default, do not allow DNS prefetch, so we don't break our frozen + // API. Embeddors who decide to enable it should do so manually. + mDocShell->SetAllowDNSPrefetch(PR_FALSE); + } + else + { + if (mDocShellTreeOwner) + mDocShellTreeOwner->RemoveFromWatcher(); // evil twin of Add in Create() + if (mDocShellAsWin) + mDocShellAsWin->Destroy(); + + mDocShell = nsnull; + mDocShellAsReq = nsnull; + mDocShellAsWin = nsnull; + mDocShellAsItem = nsnull; + mDocShellAsNav = nsnull; + mDocShellAsScrollable = nsnull; + mDocShellAsTextScroll = nsnull; + mWebProgress = nsnull; + } + + return NS_OK; } NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner() { - if(mDocShellTreeOwner) - return NS_OK; + if (mDocShellTreeOwner) + return NS_OK; - mDocShellTreeOwner = new nsDocShellTreeOwner(); - NS_ENSURE_TRUE(mDocShellTreeOwner, NS_ERROR_OUT_OF_MEMORY); + mDocShellTreeOwner = new nsDocShellTreeOwner(); + NS_ENSURE_TRUE(mDocShellTreeOwner, NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(mDocShellTreeOwner); - mDocShellTreeOwner->WebBrowser(this); - - return NS_OK; + NS_ADDREF(mDocShellTreeOwner); + mDocShellTreeOwner->WebBrowser(this); + + return NS_OK; } /* static */ nsEventStatus nsWebBrowser::HandleEvent(nsGUIEvent *aEvent) { - nsWebBrowser *browser = nsnull; - void *data = nsnull; - nsIWidget *widget = aEvent->widget; + nsWebBrowser *browser = nsnull; + void *data = nsnull; + nsIWidget *widget = aEvent->widget; - if (!widget) - return nsEventStatus_eIgnore; + if (!widget) + return nsEventStatus_eIgnore; - widget->GetClientData(data); - if (!data) - return nsEventStatus_eIgnore; + widget->GetClientData(data); + if (!data) + return nsEventStatus_eIgnore; - browser = static_cast(data); + browser = static_cast(data); - switch(aEvent->message) { + switch(aEvent->message) { + case NS_PAINT: { + LayerManager* layerManager = widget->GetLayerManager(); + NS_ASSERTION(layerManager, "Must be in paint event"); - case NS_PAINT: { - LayerManager* layerManager = widget->GetLayerManager(); - NS_ASSERTION(layerManager, "Must be in paint event"); - - layerManager->BeginTransaction(); - nsRefPtr root = layerManager->CreateThebesLayer(); - nsPaintEvent* paintEvent = static_cast(aEvent); - nsIntRect dirtyRect = paintEvent->region.GetBounds(); - if (root) { - root->SetVisibleRegion(dirtyRect); - layerManager->SetRoot(root); - } - layerManager->EndConstruction(); - if (root) { - nsIntRegion toDraw; - gfxContext* ctx = root->BeginDrawing(&toDraw); - if (ctx) { - ctx->NewPath(); - ctx->SetColor(gfxRGBA(browser->mBackgroundColor)); - ctx->Rectangle(gfxRect(dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height)); - ctx->Fill(); - } - } - root->EndDrawing(); - layerManager->EndTransaction(); - return nsEventStatus_eConsumeDoDefault; + layerManager->BeginTransaction(); + nsRefPtr root = layerManager->CreateThebesLayer(); + nsPaintEvent* paintEvent = static_cast(aEvent); + nsIntRect dirtyRect = paintEvent->region.GetBounds(); + if (root) { + root->SetVisibleRegion(dirtyRect); + layerManager->SetRoot(root); + } + layerManager->EndConstruction(); + if (root) { + nsIntRegion toDraw; + gfxContext* ctx = root->BeginDrawing(&toDraw); + if (ctx) { + ctx->NewPath(); + ctx->SetColor(gfxRGBA(browser->mBackgroundColor)); + ctx->Rectangle(gfxRect(dirtyRect.x, + dirtyRect.y, + dirtyRect.width, + dirtyRect.height)); + ctx->Fill(); + } + } + root->EndDrawing(); + layerManager->EndTransaction(); + return nsEventStatus_eConsumeDoDefault; } - case NS_ACTIVATE: { + case NS_ACTIVATE: { #if defined(DEBUG_smaug) - nsCOMPtr domDocument = do_GetInterface(browser->mDocShell); - nsAutoString documentURI; - if (domDocument) { - nsCOMPtr d3 = do_QueryInterface(domDocument); - d3->GetDocumentURI(documentURI); + nsCOMPtr domDocument = do_GetInterface(browser->mDocShell); + nsAutoString documentURI; + if (domDocument) { + nsCOMPtr d3 = do_QueryInterface(domDocument); + d3->GetDocumentURI(documentURI); + } + printf("nsWebBrowser::NS_ACTIVATE %p %s\n", (void*)browser, + NS_ConvertUTF16toUTF8(documentURI).get()); +#endif + browser->Activate(); + break; } - printf("nsWebBrowser::NS_ACTIVATE %p %s\n", (void*)browser, - NS_ConvertUTF16toUTF8(documentURI).get()); + + case NS_DEACTIVATE: { +#if defined(DEBUG_smaug) + nsCOMPtr domDocument = do_GetInterface(browser->mDocShell); + nsAutoString documentURI; + if (domDocument) { + nsCOMPtr d3 = do_QueryInterface(domDocument); + d3->GetDocumentURI(documentURI); + } + printf("nsWebBrowser::NS_DEACTIVATE %p %s\n", (void*)browser, + NS_ConvertUTF16toUTF8(documentURI).get()); #endif - browser->Activate(); - break; - } + browser->Deactivate(); + break; + } - case NS_DEACTIVATE: { -#if defined(DEBUG_smaug) - nsCOMPtr domDocument = do_GetInterface(browser->mDocShell); - nsAutoString documentURI; - if (domDocument) { - nsCOMPtr d3 = do_QueryInterface(domDocument); - d3->GetDocumentURI(documentURI); + default: + break; } - printf("nsWebBrowser::NS_DEACTIVATE %p %s\n", (void*)browser, - NS_ConvertUTF16toUTF8(documentURI).get()); -#endif - browser->Deactivate(); - break; - } - default: - break; - } - - return nsEventStatus_eIgnore; + return nsEventStatus_eIgnore; } NS_IMETHODIMP nsWebBrowser::GetPrimaryContentWindow(nsIDOMWindowInternal **aDOMWindow) { - *aDOMWindow = 0; + *aDOMWindow = 0; - nsCOMPtr item; - NS_ENSURE_TRUE(mDocShellTreeOwner, NS_ERROR_FAILURE); - mDocShellTreeOwner->GetPrimaryContentShell(getter_AddRefs(item)); - NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); + nsCOMPtr item; + NS_ENSURE_TRUE(mDocShellTreeOwner, NS_ERROR_FAILURE); + mDocShellTreeOwner->GetPrimaryContentShell(getter_AddRefs(item)); + NS_ENSURE_TRUE(item, NS_ERROR_FAILURE); - nsCOMPtr docShell; - docShell = do_QueryInterface(item); - NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); - - nsCOMPtr domWindow; - domWindow = do_GetInterface(docShell); - NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE); + nsCOMPtr docShell; + docShell = do_QueryInterface(item); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); - *aDOMWindow = domWindow; - NS_ADDREF(*aDOMWindow); - return NS_OK; - + nsCOMPtr domWindow; + domWindow = do_GetInterface(docShell); + NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE); + + NS_ADDREF(*aDOMWindow = domWindow); + return NS_OK; + } //***************************************************************************** // nsWebBrowser::nsIWebBrowserFocus -//***************************************************************************** +//***************************************************************************** /* void activate (); */ NS_IMETHODIMP nsWebBrowser::Activate(void) { - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - nsCOMPtr window = do_GetInterface(mDocShell); - if (fm && window) - return fm->WindowRaised(window); - return NS_OK; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + nsCOMPtr window = do_GetInterface(mDocShell); + if (fm && window) + return fm->WindowRaised(window); + + return NS_OK; } /* void deactivate (); */ NS_IMETHODIMP nsWebBrowser::Deactivate(void) { - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - nsCOMPtr window = do_GetInterface(mDocShell); - if (fm && window) - return fm->WindowLowered(window); - return NS_OK; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + nsCOMPtr window = do_GetInterface(mDocShell); + if (fm && window) + return fm->WindowLowered(window); + + return NS_OK; } /* void setFocusAtFirstElement (); */ NS_IMETHODIMP nsWebBrowser::SetFocusAtFirstElement(void) { - return NS_OK; + return NS_OK; } /* void setFocusAtLastElement (); */ NS_IMETHODIMP nsWebBrowser::SetFocusAtLastElement(void) { - return NS_OK; + return NS_OK; } /* attribute nsIDOMWindow focusedWindow; */ NS_IMETHODIMP nsWebBrowser::GetFocusedWindow(nsIDOMWindow * *aFocusedWindow) { - NS_ENSURE_ARG_POINTER(aFocusedWindow); - *aFocusedWindow = nsnull; + NS_ENSURE_ARG_POINTER(aFocusedWindow); + *aFocusedWindow = nsnull; - nsCOMPtr window = do_GetInterface(mDocShell); - NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + nsCOMPtr window = do_GetInterface(mDocShell); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - nsCOMPtr focusedElement; - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - return fm ? fm->GetFocusedElementForWindow(window, PR_TRUE, aFocusedWindow, - getter_AddRefs(focusedElement)) : NS_OK; + nsCOMPtr focusedElement; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + if (!fm) + return NS_OK; + + return fm->GetFocusedElementForWindow(window, PR_TRUE, aFocusedWindow, + getter_AddRefs(focusedElement)); } NS_IMETHODIMP nsWebBrowser::SetFocusedWindow(nsIDOMWindow * aFocusedWindow) { - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - return fm ? fm->SetFocusedWindow(aFocusedWindow) : NS_OK; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + return fm ? fm->SetFocusedWindow(aFocusedWindow) : NS_OK; } /* attribute nsIDOMElement focusedElement; */ NS_IMETHODIMP nsWebBrowser::GetFocusedElement(nsIDOMElement * *aFocusedElement) { - NS_ENSURE_ARG_POINTER(aFocusedElement); + NS_ENSURE_ARG_POINTER(aFocusedElement); - nsCOMPtr window = do_GetInterface(mDocShell); - NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + nsCOMPtr window = do_GetInterface(mDocShell); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - return fm ? fm->GetFocusedElementForWindow(window, PR_TRUE, nsnull, aFocusedElement) : NS_OK; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + if (!fm) + return NS_OK; + + return fm->GetFocusedElementForWindow(window, PR_TRUE, nsnull, aFocusedElement); } NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement) { - nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); - return fm ? fm->SetFocus(aFocusedElement, 0) : NS_OK; + nsCOMPtr fm = do_GetService(FOCUSMANAGER_CONTRACTID); + if (!fm) + return NS_OK; + + return fm->SetFocus(aFocusedElement, 0); } //***************************************************************************** // nsWebBrowser::nsIWebBrowserStream -//***************************************************************************** +//***************************************************************************** /* void openStream(in nsIURI aBaseURI, in ACString aContentType); */ NS_IMETHODIMP nsWebBrowser::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType) { - nsresult rv; + nsresult rv; - if (!mStream) { - mStream = new nsEmbedStream(); + if (!mStream) { + mStream = new nsEmbedStream(); if (!mStream) - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_OUT_OF_MEMORY; - mStreamGuard = do_QueryInterface(mStream); - mStream->InitOwner(this); - rv = mStream->Init(); - if (NS_FAILED(rv)) - return rv; - } + mStreamGuard = do_QueryInterface(mStream); + mStream->InitOwner(this); + rv = mStream->Init(); + if (NS_FAILED(rv)) + return rv; + } - return mStream->OpenStream(aBaseURI, aContentType); + return mStream->OpenStream(aBaseURI, aContentType); } /* void appendToStream([const, array, size_is(aLen)] in octet aData, * in unsigned long aLen); */ NS_IMETHODIMP nsWebBrowser::AppendToStream(const PRUint8 *aData, PRUint32 aLen) { - if (!mStream) - return NS_ERROR_FAILURE; + if (!mStream) + return NS_ERROR_FAILURE; - return mStream->AppendToStream(aData, aLen); + return mStream->AppendToStream(aData, aLen); } /* void closeStream (); */ NS_IMETHODIMP nsWebBrowser::CloseStream() { - nsresult rv; + nsresult rv; + if (!mStream) + return NS_ERROR_FAILURE; - if (!mStream) - return NS_ERROR_FAILURE; - rv = mStream->CloseStream(); + rv = mStream->CloseStream(); - // release - mStream = 0; - mStreamGuard = 0; + // release + mStream = 0; + mStreamGuard = 0; - return rv; + return rv; } diff --git a/embedding/browser/webBrowser/nsWebBrowser.h b/embedding/browser/webBrowser/nsWebBrowser.h --- a/embedding/browser/webBrowser/nsWebBrowser.h +++ b/embedding/browser/webBrowser/nsWebBrowser.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -78,14 +78,14 @@ class nsIContentViewerFile; class nsWebBrowserInitInfo { public: - //nsIBaseWindow Stuff - PRInt32 x; - PRInt32 y; - PRInt32 cx; - PRInt32 cy; - PRBool visible; - nsCOMPtr sessionHistory; - nsString name; + //nsIBaseWindow Stuff + PRInt32 x; + PRInt32 y; + PRInt32 cx; + PRInt32 cy; + PRBool visible; + nsCOMPtr sessionHistory; + nsString name; }; class nsWebBrowserListenerState @@ -100,7 +100,7 @@ public: nsIID mID; }; -// {F1EAC761-87E9-11d3-AF80-00A024FFC08C} - +// {F1EAC761-87E9-11d3-AF80-00A024FFC08C} - #define NS_WEBBROWSER_CID \ {0xf1eac761, 0x87e9, 0x11d3, { 0xaf, 0x80, 0x00, 0xa0, 0x24, 0xff, 0xc0, 0x8c }} @@ -110,8 +110,8 @@ class nsWebBrowser : public nsIWebBrowse public nsIWebBrowserSetup, public nsIDocShellTreeItem, public nsIBaseWindow, - public nsIScrollable, - public nsITextScroll, + public nsIScrollable, + public nsITextScroll, public nsIInterfaceRequestor, public nsIWebBrowserPersist, public nsIWebBrowserFocus, @@ -129,7 +129,7 @@ public: NS_DECL_NSIDOCSHELLTREEITEM NS_DECL_NSIDOCSHELLTREENODE NS_DECL_NSIINTERFACEREQUESTOR - NS_DECL_NSISCROLLABLE + NS_DECL_NSISCROLLABLE NS_DECL_NSITEXTSCROLL NS_DECL_NSIWEBBROWSER NS_DECL_NSIWEBNAVIGATION @@ -155,42 +155,41 @@ protected: static nsEventStatus HandleEvent(nsGUIEvent *aEvent); protected: - nsDocShellTreeOwner* mDocShellTreeOwner; - nsCOMPtr mDocShell; - nsCOMPtr mDocShellAsReq; - nsCOMPtr mDocShellAsWin; - nsCOMPtr mDocShellAsItem; - nsCOMPtr mDocShellAsNav; - nsCOMPtr mDocShellAsScrollable; - nsCOMPtr mDocShellAsTextScroll; - nsCOMPtr mInternalWidget; - nsCOMPtr mWWatch; - nsWebBrowserInitInfo* mInitInfo; - PRUint32 mContentType; - PRPackedBool mActivating; - PRPackedBool mShouldEnableHistory; - nativeWindow mParentNativeWindow; - nsIWebProgressListener *mProgressListener; - nsCOMPtr mWebProgress; + nsDocShellTreeOwner *mDocShellTreeOwner; + nsCOMPtr mDocShell; + nsCOMPtr mDocShellAsReq; + nsCOMPtr mDocShellAsWin; + nsCOMPtr mDocShellAsItem; + nsCOMPtr mDocShellAsNav; + nsCOMPtr mDocShellAsScrollable; + nsCOMPtr mDocShellAsTextScroll; + nsCOMPtr mInternalWidget; + nsCOMPtr mWWatch; + nsWebBrowserInitInfo* mInitInfo; + PRUint32 mContentType; + PRPackedBool mActivating; + PRPackedBool mShouldEnableHistory; + nativeWindow mParentNativeWindow; + nsIWebProgressListener *mProgressListener; + nsCOMPtr mWebProgress; + nsCOMPtr mPrintSettings; - nsCOMPtr mPrintSettings; + // cached background color + nscolor mBackgroundColor; - // cached background color - nscolor mBackgroundColor; + // persistence object + nsCOMPtr mPersist; + PRUint32 mPersistCurrentState; + PRUint32 mPersistResult; + PRUint32 mPersistFlags; - // persistence object - nsCOMPtr mPersist; - PRUint32 mPersistCurrentState; - PRUint32 mPersistResult; - PRUint32 mPersistFlags; + // stream + nsEmbedStream *mStream; + nsCOMPtr mStreamGuard; - // stream - nsEmbedStream *mStream; - nsCOMPtr mStreamGuard; - - //Weak Reference interfaces... - nsIWidget* mParentWidget; - nsTArray* mListenerArray; + //Weak Reference interfaces... + nsIWidget* mParentWidget; + nsTArray* mListenerArray; }; #endif /* nsWebBrowser_h__ */