bug 842078 - fix iteration of mChildrenList r=smaug

This commit is contained in:
Trevor Saunders 2013-02-20 16:33:44 -05:00
Родитель 644deb6ac0
Коммит a0b7e3dddf
4 изменённых файлов: 55 добавлений и 83 удалений

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

@ -872,9 +872,9 @@ void
nsDocShell::DestroyChildren()
{
nsCOMPtr<nsIDocShellTreeItem> shell;
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; i++) {
shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
shell = do_QueryObject(iter.GetNext());
NS_ASSERTION(shell, "docshell has null child");
if (shell) {
@ -2080,9 +2080,9 @@ nsDocShell::SetPrivateBrowsing(bool aUsePrivateBrowsing)
}
}
uint32_t count = mChildList.Length();
for (uint32_t i = 0; i < count; ++i) {
nsCOMPtr<nsILoadContext> shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsILoadContext> shell = do_QueryObject(iter.GetNext());
if (shell) {
shell->SetPrivateBrowsing(aUsePrivateBrowsing);
}
@ -2116,9 +2116,9 @@ nsDocShell::SetAffectPrivateSessionLifetime(bool aAffectLifetime)
}
mAffectPrivateSessionLifetime = aAffectLifetime;
uint32_t count = mChildList.Length();
for (uint32_t i = 0; i < count; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext());
if (shell) {
shell->SetAffectPrivateSessionLifetime(aAffectLifetime);
}
@ -2488,9 +2488,9 @@ nsDocShell::HistoryPurged(int32_t aNumEntries)
mPreviousTransIndex = std::max(-1, mPreviousTransIndex - aNumEntries);
mLoadedTransIndex = std::max(0, mLoadedTransIndex - aNumEntries);
uint32_t count = mChildList.Length();
for (uint32_t i = 0; i < count; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext());
if (shell) {
shell->HistoryPurged(aNumEntries);
}
@ -2518,9 +2518,9 @@ nsDocShell::HistoryTransactionRemoved(int32_t aIndex)
--mLoadedTransIndex;
}
uint32_t count = mChildList.Length();
for (uint32_t i = 0; i < count; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext());
if (shell) {
static_cast<nsDocShell*>(shell.get())->
HistoryTransactionRemoved(aIndex);
@ -3403,9 +3403,9 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner)
mTreeOwner = aTreeOwner; // Weak reference per API
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; i++) {
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryObject(iter.GetNext());
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
int32_t childType = ~mItemType; // Set it to not us in case the get fails
child->GetItemType(&childType); // We don't care if this fails, if it does we won't set the owner
@ -3602,7 +3602,7 @@ nsDocShell::GetChildAt(int32_t aIndex, nsIDocShellTreeItem ** aChild)
}
#endif
nsIDocumentLoader* child = SafeChildAt(aIndex);
nsIDocumentLoader* child = ChildAt(aIndex);
NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
return CallQueryInterface(child, aChild);
@ -3624,9 +3624,9 @@ nsDocShell::FindChildWithName(const PRUnichar * aName,
return NS_OK;
nsXPIDLString childName;
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; i++) {
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryObject(iter.GetNext());
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
int32_t childType;
child->GetItemType(&childType);
@ -4676,9 +4676,9 @@ nsDocShell::Stop(uint32_t aStopFlags)
Stop();
}
uint32_t count = mChildList.Length();
for (uint32_t n = 0; n < count; n++) {
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryInterface(ChildAt(n)));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryObject(iter.GetNext()));
if (shellAsNav)
shellAsNav->Stop(aStopFlags);
}
@ -5290,9 +5290,9 @@ nsDocShell::SetIsActive(bool aIsActive)
// Recursively tell all of our children, but don't tell <iframe mozbrowser>
// children; they handle their state separately.
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> docshell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> docshell = do_QueryObject(iter.GetNext());
if (!docshell) {
continue;
}
@ -6213,9 +6213,9 @@ nsDocShell::SuspendRefreshURIs()
}
// Suspend refresh URIs for our child shells as well.
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext());
if (shell)
shell->SuspendRefreshURIs();
}
@ -6229,9 +6229,9 @@ nsDocShell::ResumeRefreshURIs()
RefreshURIFromQueue();
// Resume refresh URIs for our child shells as well.
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext());
if (shell)
shell->ResumeRefreshURIs();
}
@ -7276,9 +7276,9 @@ nsDocShell::BeginRestore(nsIContentViewer *aContentViewer, bool aTop)
nsresult
nsDocShell::BeginRestoreChildren()
{
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> child = do_QueryObject(iter.GetNext());
if (child) {
nsresult rv = child->BeginRestore(nullptr, false);
NS_ENSURE_SUCCESS(rv, rv);
@ -7293,9 +7293,9 @@ nsDocShell::FinishRestore()
// First we call finishRestore() on our children. In the simulated load,
// all of the child frames finish loading before the main document.
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> child = do_QueryObject(iter.GetNext());
if (child) {
child->FinishRestore();
}
@ -7798,9 +7798,9 @@ nsDocShell::RestoreFromHistory()
// Meta-refresh timers have been restarted for this shell, but not
// for our children. Walk the child shells and restart their timers.
uint32_t n = mChildList.Length();
for (uint32_t i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> child = do_QueryObject(iter.GetNext());
if (child)
child->ResumeRefreshURIs();
}
@ -10811,10 +10811,9 @@ nsDocShell::WalkHistoryEntries(nsISHEntry *aRootEntry,
// Walk the children of aRootShell and see if one of them
// has srcChild as a SHEntry.
uint32_t childCount = aRootShell->mChildList.Length();
for (uint32_t j = 0; j < childCount; ++j) {
nsDocShell *child =
static_cast<nsDocShell*>(aRootShell->ChildAt(j));
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(aRootShell->mChildList);
while (iter.HasMore()) {
nsDocShell *child = static_cast<nsDocShell*>(iter.GetNext());
if (child->HasHistoryEntry(childEntry)) {
childShell = child;

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

@ -267,16 +267,7 @@ nsDocLoader::Stop(void)
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: Stop() called\n", this));
uint32_t count = mChildList.Length();
nsCOMPtr<nsIDocumentLoader> loader;
for (uint32_t i=0; i < count; i++) {
loader = ChildAt(i);
if (loader) {
(void) loader->Stop();
}
}
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mChildList, nsDocLoader, Stop, ());
if (mLoadGroup)
rv = mLoadGroup->Cancel(NS_BINDING_ABORTED);
@ -1658,15 +1649,8 @@ NS_IMETHODIMP nsDocLoader::SetPriority(int32_t aPriority)
if (p)
p->SetPriority(aPriority);
uint32_t count = mChildList.Length();
nsDocLoader *loader;
for (uint32_t i=0; i < count; i++) {
loader = static_cast<nsDocLoader*>(ChildAt(i));
if (loader) {
loader->SetPriority(aPriority);
}
}
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mChildList, nsDocLoader,
SetPriority, (aPriority));
return NS_OK;
}
@ -1680,15 +1664,8 @@ NS_IMETHODIMP nsDocLoader::AdjustPriority(int32_t aDelta)
if (p)
p->AdjustPriority(aDelta);
uint32_t count = mChildList.Length();
nsDocLoader *loader;
for (uint32_t i=0; i < count; i++) {
loader = static_cast<nsDocLoader*>(ChildAt(i));
if (loader) {
loader->AdjustPriority(aDelta);
}
}
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mChildList, nsDocLoader,
AdjustPriority, (aDelta));
return NS_OK;
}

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

@ -16,7 +16,7 @@
#include "nsWeakReference.h"
#include "nsILoadGroup.h"
#include "nsCOMArray.h"
#include "nsTArrayForwardDeclare.h"
#include "nsTObserverArray.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsIChannel.h"
@ -109,11 +109,7 @@ protected:
virtual void DestroyChildren();
nsIDocumentLoader* ChildAt(int32_t i) {
return mChildList[i];
}
nsIDocumentLoader* SafeChildAt(int32_t i) {
return mChildList.SafeElementAt(i);
return mChildList.SafeElementAt(i, nullptr);
}
void FireOnProgressChange(nsDocLoader* aLoadInitiator,
@ -257,7 +253,7 @@ protected:
nsCOMPtr<nsILoadGroup> mLoadGroup;
// We hold weak refs to all our kids
nsTArray<nsDocLoader*> mChildList;
nsTObserverArray<nsDocLoader*> mChildList;
// The following member variables are related to the new nsIWebProgress
// feedback interfaces that travis cooked up.

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

@ -397,7 +397,7 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
#define NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(array_, obstype_, func_, params_) \
PR_BEGIN_MACRO \
nsTObserverArray<obstype_ *>::ForwardIterator iter_(array_); \
nsCOMPtr<obstype_> obs_; \
nsRefPtr<obstype_> obs_; \
while (iter_.HasMore()) { \
obs_ = iter_.GetNext(); \
obs_ -> func_ params_ ; \