зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1592599 - Switch nsIDocShell.getDocShellEnumerator() away from using nsISimpleEnumerator; r=bzbarsky
Differential Revision: https://phabricator.services.mozilla.com/D51100 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
ce2d2224ef
Коммит
dc998c5c5a
|
@ -56,7 +56,7 @@ function getDialogDoc() {
|
|||
|
||||
// var enumerator = wm.getEnumerator("navigator:browser");
|
||||
for (let { docShell } of Services.wm.getEnumerator(null)) {
|
||||
var containedDocShells = docShell.getDocShellEnumerator(
|
||||
var containedDocShells = docShell.getAllDocShellsInSubtree(
|
||||
docShell.typeChrome,
|
||||
docShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
|
|
@ -94,13 +94,13 @@ function getDocShellChromeEventHandler(docShell) {
|
|||
}
|
||||
|
||||
function getChildDocShells(parentDocShell) {
|
||||
const docShellsEnum = parentDocShell.getDocShellEnumerator(
|
||||
const allDocShells = parentDocShell.getAllDocShellsInSubtree(
|
||||
Ci.nsIDocShellTreeItem.typeAll,
|
||||
Ci.nsIDocShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
||||
const docShells = [];
|
||||
for (const docShell of docShellsEnum) {
|
||||
for (const docShell of allDocShells) {
|
||||
docShell
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebProgress);
|
||||
|
|
|
@ -101,12 +101,12 @@ Timeline.prototype = {
|
|||
return [];
|
||||
}
|
||||
|
||||
const docShellsEnum = originalDocShell.getDocShellEnumerator(
|
||||
const docShells = originalDocShell.getAllDocShellsInSubtree(
|
||||
Ci.nsIDocShellTreeItem.typeAll,
|
||||
Ci.nsIDocShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
||||
return Array.from(docShellsEnum);
|
||||
return docShells;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1940,38 +1940,23 @@ nsDocShell::GetCharsetAutodetected(bool* aCharsetAutodetected) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetDocShellEnumerator(int32_t aItemType,
|
||||
DocShellEnumeratorDirection aDirection,
|
||||
nsISimpleEnumerator** aResult) {
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = nullptr;
|
||||
nsDocShell::GetAllDocShellsInSubtree(int32_t aItemType,
|
||||
DocShellEnumeratorDirection aDirection,
|
||||
nsTArray<RefPtr<nsIDocShell>>& aResult) {
|
||||
aResult.Clear();
|
||||
|
||||
RefPtr<nsDocShellEnumerator> docShellEnum;
|
||||
if (aDirection == ENUMERATE_FORWARDS) {
|
||||
docShellEnum = new nsDocShellForwardsEnumerator;
|
||||
} else {
|
||||
docShellEnum = new nsDocShellBackwardsEnumerator;
|
||||
}
|
||||
nsDocShellEnumerator docShellEnum(
|
||||
(aDirection == ENUMERATE_FORWARDS)
|
||||
? nsDocShellEnumerator::EnumerationDirection::Forwards
|
||||
: nsDocShellEnumerator::EnumerationDirection::Backwards,
|
||||
aItemType, *this);
|
||||
|
||||
nsresult rv = docShellEnum->SetEnumDocShellType(aItemType);
|
||||
nsresult rv = docShellEnum.BuildDocShellArray(aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = docShellEnum->SetEnumerationRootItem((nsIDocShellTreeItem*)this);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = docShellEnum->First();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = docShellEnum->QueryInterface(NS_GET_IID(nsISimpleEnumerator),
|
||||
(void**)aResult);
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -3205,6 +3190,15 @@ NS_IMETHODIMP
|
|||
nsDocShell::GetInProcessChildAt(int32_t aIndex, nsIDocShellTreeItem** aChild) {
|
||||
NS_ENSURE_ARG_POINTER(aChild);
|
||||
|
||||
RefPtr<nsDocShell> child = GetInProcessChildAt(aIndex);
|
||||
NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
|
||||
|
||||
child.forget(aChild);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsDocShell* nsDocShell::GetInProcessChildAt(int32_t aIndex) {
|
||||
#ifdef DEBUG
|
||||
if (aIndex < 0) {
|
||||
NS_WARNING("Negative index passed to GetChildAt");
|
||||
|
@ -3214,9 +3208,9 @@ nsDocShell::GetInProcessChildAt(int32_t aIndex, nsIDocShellTreeItem** aChild) {
|
|||
#endif
|
||||
|
||||
nsIDocumentLoader* child = ChildAt(aIndex);
|
||||
NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
|
||||
|
||||
return CallQueryInterface(child, aChild);
|
||||
// child may be nullptr here.
|
||||
return static_cast<nsDocShell*>(child);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -493,6 +493,8 @@ class nsDocShell final : public nsDocLoader,
|
|||
static void MaybeNotifyKeywordSearchLoading(const nsString& aProvider,
|
||||
const nsString& aKeyword);
|
||||
|
||||
nsDocShell* GetInProcessChildAt(int32_t aIndex);
|
||||
|
||||
private: // member functions
|
||||
friend class nsDSURIContentListener;
|
||||
friend class FramingChecker;
|
||||
|
|
|
@ -6,135 +6,47 @@
|
|||
|
||||
#include "nsDocShellEnumerator.h"
|
||||
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsDocShell.h"
|
||||
|
||||
nsDocShellEnumerator::nsDocShellEnumerator(int32_t aEnumerationDirection)
|
||||
: mRootItem(nullptr),
|
||||
mCurIndex(0),
|
||||
mDocShellType(nsIDocShellTreeItem::typeAll),
|
||||
mArrayValid(false),
|
||||
mEnumerationDirection(aEnumerationDirection) {}
|
||||
|
||||
nsDocShellEnumerator::~nsDocShellEnumerator() {}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShellEnumerator::GetNext(nsISupports** aResult) {
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = nullptr;
|
||||
|
||||
nsresult rv = EnsureDocShellArray();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (mCurIndex >= mItemArray.Length()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// post-increment is important here
|
||||
nsCOMPtr<nsISupports> item = do_QueryReferent(mItemArray[mCurIndex++], &rv);
|
||||
item.forget(aResult);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShellEnumerator::HasMoreElements(bool* aResult) {
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = false;
|
||||
|
||||
nsresult rv = EnsureDocShellArray();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aResult = (mCurIndex < mItemArray.Length());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::GetEnumerationRootItem(
|
||||
nsIDocShellTreeItem** aEnumerationRootItem) {
|
||||
NS_ENSURE_ARG_POINTER(aEnumerationRootItem);
|
||||
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryReferent(mRootItem);
|
||||
item.forget(aEnumerationRootItem);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::SetEnumerationRootItem(
|
||||
nsIDocShellTreeItem* aEnumerationRootItem) {
|
||||
mRootItem = do_GetWeakReference(aEnumerationRootItem);
|
||||
ClearState();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::GetEnumDocShellType(
|
||||
int32_t* aEnumerationItemType) {
|
||||
NS_ENSURE_ARG_POINTER(aEnumerationItemType);
|
||||
*aEnumerationItemType = mDocShellType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::SetEnumDocShellType(
|
||||
int32_t aEnumerationItemType) {
|
||||
mDocShellType = aEnumerationItemType;
|
||||
ClearState();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::First() {
|
||||
mCurIndex = 0;
|
||||
return EnsureDocShellArray();
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::EnsureDocShellArray() {
|
||||
if (!mArrayValid) {
|
||||
mArrayValid = true;
|
||||
return BuildDocShellArray(mItemArray);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellEnumerator::ClearState() {
|
||||
mItemArray.Clear();
|
||||
mArrayValid = false;
|
||||
mCurIndex = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
nsDocShellEnumerator::nsDocShellEnumerator(
|
||||
nsDocShellEnumerator::EnumerationDirection aDirection,
|
||||
int32_t aDocShellType, nsDocShell& aRootItem)
|
||||
: mRootItem(&aRootItem),
|
||||
mDocShellType(aDocShellType),
|
||||
mDirection(aDirection) {}
|
||||
|
||||
nsresult nsDocShellEnumerator::BuildDocShellArray(
|
||||
nsTArray<nsWeakPtr>& aItemArray) {
|
||||
NS_ENSURE_TRUE(mRootItem, NS_ERROR_NOT_INITIALIZED);
|
||||
nsTArray<RefPtr<nsIDocShell>>& aItemArray) {
|
||||
MOZ_ASSERT(mRootItem);
|
||||
|
||||
aItemArray.Clear();
|
||||
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryReferent(mRootItem);
|
||||
return BuildArrayRecursive(item, aItemArray);
|
||||
|
||||
if (mDirection == EnumerationDirection::Forwards) {
|
||||
return BuildArrayRecursiveForwards(mRootItem, aItemArray);
|
||||
}
|
||||
MOZ_ASSERT(mDirection == EnumerationDirection::Backwards);
|
||||
return BuildArrayRecursiveBackwards(mRootItem, aItemArray);
|
||||
}
|
||||
|
||||
nsresult nsDocShellForwardsEnumerator::BuildArrayRecursive(
|
||||
nsIDocShellTreeItem* aItem, nsTArray<nsWeakPtr>& aItemArray) {
|
||||
nsresult nsDocShellEnumerator::BuildArrayRecursiveForwards(
|
||||
nsDocShell* aItem, nsTArray<RefPtr<nsIDocShell>>& aItemArray) {
|
||||
nsresult rv;
|
||||
|
||||
// add this item to the array
|
||||
if (mDocShellType == nsIDocShellTreeItem::typeAll ||
|
||||
aItem->ItemType() == mDocShellType) {
|
||||
if (!aItemArray.AppendElement(do_GetWeakReference(aItem))) {
|
||||
if (!aItemArray.AppendElement(aItem, fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t numChildren;
|
||||
rv = aItem->GetInProcessChildCount(&numChildren);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
int32_t numChildren = aItem->ChildCount();
|
||||
|
||||
for (int32_t i = 0; i < numChildren; ++i) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> curChild;
|
||||
rv = aItem->GetInProcessChildAt(i, getter_AddRefs(curChild));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
RefPtr<nsDocShell> curChild = aItem->GetInProcessChildAt(i);
|
||||
MOZ_ASSERT(curChild);
|
||||
|
||||
rv = BuildArrayRecursive(curChild, aItemArray);
|
||||
rv = BuildArrayRecursiveForwards(curChild, aItemArray);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -143,24 +55,17 @@ nsresult nsDocShellForwardsEnumerator::BuildArrayRecursive(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocShellBackwardsEnumerator::BuildArrayRecursive(
|
||||
nsIDocShellTreeItem* aItem, nsTArray<nsWeakPtr>& aItemArray) {
|
||||
nsresult nsDocShellEnumerator::BuildArrayRecursiveBackwards(
|
||||
nsDocShell* aItem, nsTArray<RefPtr<nsIDocShell>>& aItemArray) {
|
||||
nsresult rv;
|
||||
|
||||
int32_t numChildren;
|
||||
rv = aItem->GetInProcessChildCount(&numChildren);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
uint32_t numChildren = aItem->ChildCount();
|
||||
|
||||
for (int32_t i = numChildren - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> curChild;
|
||||
rv = aItem->GetInProcessChildAt(i, getter_AddRefs(curChild));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
RefPtr<nsDocShell> curChild = aItem->GetInProcessChildAt(i);
|
||||
MOZ_ASSERT(curChild);
|
||||
|
||||
rv = BuildArrayRecursive(curChild, aItemArray);
|
||||
rv = BuildArrayRecursiveBackwards(curChild, aItemArray);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -169,7 +74,7 @@ nsresult nsDocShellBackwardsEnumerator::BuildArrayRecursive(
|
|||
// add this item to the array
|
||||
if (mDocShellType == nsIDocShellTreeItem::typeAll ||
|
||||
aItem->ItemType() == mDocShellType) {
|
||||
if (!aItemArray.AppendElement(do_GetWeakReference(aItem))) {
|
||||
if (!aItemArray.AppendElement(aItem)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,89 +7,33 @@
|
|||
#ifndef nsDocShellEnumerator_h___
|
||||
#define nsDocShellEnumerator_h___
|
||||
|
||||
#include "nsSimpleEnumerator.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
|
||||
class nsIDocShellTreeItem;
|
||||
class nsDocShell;
|
||||
class nsIDocShell;
|
||||
|
||||
/*
|
||||
// {13cbc281-35ae-11d5-be5b-bde0edece43c}
|
||||
#define NS_DOCSHELL_FORWARDS_ENUMERATOR_CID \
|
||||
{ 0x13cbc281, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c }
|
||||
}
|
||||
class MOZ_STACK_CLASS nsDocShellEnumerator {
|
||||
public:
|
||||
enum class EnumerationDirection : uint8_t { Forwards, Backwards };
|
||||
|
||||
#define NS_DOCSHELL_FORWARDS_ENUMERATOR_CONTRACTID \
|
||||
"@mozilla.org/docshell/enumerator-forwards;1"
|
||||
|
||||
// {13cbc282-35ae-11d5-be5b-bde0edece43c}
|
||||
#define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CID \
|
||||
{ 0x13cbc282, 0x35ae, 0x11d5, { 0xbe, 0x5b, 0xbd, 0xe0, 0xed, 0xec, 0xe4, 0x3c }
|
||||
}
|
||||
|
||||
#define NS_DOCSHELL_BACKWARDS_ENUMERATOR_CONTRACTID \
|
||||
"@mozilla.org/docshell/enumerator-backwards;1"
|
||||
*/
|
||||
|
||||
class nsDocShellEnumerator : public nsSimpleEnumerator {
|
||||
protected:
|
||||
enum { enumerateForwards, enumerateBackwards };
|
||||
|
||||
virtual ~nsDocShellEnumerator();
|
||||
nsDocShellEnumerator(EnumerationDirection aDirection, int32_t aDocShellType,
|
||||
nsDocShell& aRootItem);
|
||||
|
||||
public:
|
||||
explicit nsDocShellEnumerator(int32_t aEnumerationDirection);
|
||||
nsresult BuildDocShellArray(nsTArray<RefPtr<nsIDocShell>>& aItemArray);
|
||||
|
||||
// nsISimpleEnumerator
|
||||
NS_DECL_NSISIMPLEENUMERATOR
|
||||
private:
|
||||
nsresult BuildArrayRecursiveForwards(
|
||||
nsDocShell* aItem, nsTArray<RefPtr<nsIDocShell>>& aItemArray);
|
||||
nsresult BuildArrayRecursiveBackwards(
|
||||
nsDocShell* aItem, nsTArray<RefPtr<nsIDocShell>>& aItemArray);
|
||||
|
||||
const nsID& DefaultInterface() override { return NS_GET_IID(nsIDocShell); }
|
||||
private:
|
||||
const RefPtr<nsDocShell> mRootItem;
|
||||
|
||||
public:
|
||||
nsresult GetEnumerationRootItem(nsIDocShellTreeItem** aEnumerationRootItem);
|
||||
nsresult SetEnumerationRootItem(nsIDocShellTreeItem* aEnumerationRootItem);
|
||||
const int32_t mDocShellType; // only want shells of this type
|
||||
|
||||
nsresult GetEnumDocShellType(int32_t* aEnumerationItemType);
|
||||
nsresult SetEnumDocShellType(int32_t aEnumerationItemType);
|
||||
|
||||
nsresult First();
|
||||
|
||||
protected:
|
||||
nsresult EnsureDocShellArray();
|
||||
nsresult ClearState();
|
||||
|
||||
nsresult BuildDocShellArray(nsTArray<nsWeakPtr>& aItemArray);
|
||||
virtual nsresult BuildArrayRecursive(nsIDocShellTreeItem* aItem,
|
||||
nsTArray<nsWeakPtr>& aItemArray) = 0;
|
||||
|
||||
protected:
|
||||
nsWeakPtr mRootItem; // weak ref!
|
||||
|
||||
nsTArray<nsWeakPtr> mItemArray; // flattened list of items with matching type
|
||||
uint32_t mCurIndex;
|
||||
|
||||
int32_t mDocShellType; // only want shells of this type
|
||||
bool mArrayValid; // is mItemArray up to date?
|
||||
|
||||
const int8_t mEnumerationDirection;
|
||||
};
|
||||
|
||||
class nsDocShellForwardsEnumerator : public nsDocShellEnumerator {
|
||||
public:
|
||||
nsDocShellForwardsEnumerator() : nsDocShellEnumerator(enumerateForwards) {}
|
||||
|
||||
protected:
|
||||
virtual nsresult BuildArrayRecursive(
|
||||
nsIDocShellTreeItem* aItem, nsTArray<nsWeakPtr>& aItemArray) override;
|
||||
};
|
||||
|
||||
class nsDocShellBackwardsEnumerator : public nsDocShellEnumerator {
|
||||
public:
|
||||
nsDocShellBackwardsEnumerator() : nsDocShellEnumerator(enumerateBackwards) {}
|
||||
|
||||
protected:
|
||||
virtual nsresult BuildArrayRecursive(
|
||||
nsIDocShellTreeItem* aItem, nsTArray<nsWeakPtr>& aItemArray) override;
|
||||
const EnumerationDirection mDirection;
|
||||
};
|
||||
|
||||
#endif // nsDocShellEnumerator_h___
|
||||
|
|
|
@ -47,7 +47,6 @@ interface nsIContentSecurityPolicy;
|
|||
interface nsIDocShellLoadInfo;
|
||||
interface nsIEditor;
|
||||
interface nsIEditingSession;
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsIInputStream;
|
||||
interface nsIRequest;
|
||||
interface nsISHEntry;
|
||||
|
@ -254,7 +253,7 @@ interface nsIDocShell : nsIDocShellTreeItem
|
|||
[infallible] attribute boolean inheritPrivateBrowsingId;
|
||||
|
||||
/**
|
||||
* Get an enumerator over this docShell and its children.
|
||||
* Get an array of this docShell and its children.
|
||||
*
|
||||
* @param aItemType - Only include docShells of this type, or if typeAll,
|
||||
* include all child shells.
|
||||
|
@ -267,8 +266,8 @@ interface nsIDocShell : nsIDocShellTreeItem
|
|||
ENUMERATE_BACKWARDS = 1
|
||||
};
|
||||
|
||||
nsISimpleEnumerator getDocShellEnumerator(in long aItemType,
|
||||
in nsIDocShell_DocShellEnumeratorDirection aDirection);
|
||||
Array<nsIDocShell> getAllDocShellsInSubtree(in long aItemType,
|
||||
in nsIDocShell_DocShellEnumeratorDirection aDirection);
|
||||
|
||||
/**
|
||||
* The type of application that created this window.
|
||||
|
|
|
@ -31,10 +31,8 @@ addEventListener("unload", e => {
|
|||
});
|
||||
|
||||
function getChildDocShells() {
|
||||
let docShellsEnum = docShell.getDocShellEnumerator(
|
||||
return docShell.getAllDocShellsInSubtree(
|
||||
Ci.nsIDocShellTreeItem.typeAll,
|
||||
Ci.nsIDocShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
||||
return Array.from(docShellsEnum);
|
||||
}
|
||||
|
|
|
@ -32,12 +32,10 @@ void OnPrefChange(const char* aPrefName, void*) {
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> rootDocShell = window->GetDocShell();
|
||||
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
|
||||
rootDocShell->GetDocShellEnumerator(nsIDocShell::typeAll,
|
||||
nsIDocShell::ENUMERATE_FORWARDS,
|
||||
getter_AddRefs(docShellEnumerator));
|
||||
NS_ENSURE_TRUE_VOID(docShellEnumerator);
|
||||
for (auto& docShell : SimpleEnumerator<nsIDocShell>(docShellEnumerator)) {
|
||||
nsTArray<RefPtr<nsIDocShell>> docShells;
|
||||
rootDocShell->GetAllDocShellsInSubtree(
|
||||
nsIDocShell::typeAll, nsIDocShell::ENUMERATE_FORWARDS, docShells);
|
||||
for (auto& docShell : docShells) {
|
||||
if (nsCOMPtr<nsPIDOMWindowOuter> win = do_GetInterface(docShell)) {
|
||||
if (dom::Document* doc = win->GetExtantDoc()) {
|
||||
doc->ResetDocumentDirection();
|
||||
|
|
|
@ -3776,16 +3776,12 @@ static void ResetFocusState(nsIDocShell* aDocShell) {
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
|
||||
aDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent,
|
||||
nsIDocShell::ENUMERATE_FORWARDS,
|
||||
getter_AddRefs(docShellEnumerator));
|
||||
nsTArray<RefPtr<nsIDocShell>> docShells;
|
||||
aDocShell->GetAllDocShellsInSubtree(nsIDocShellTreeItem::typeContent,
|
||||
nsIDocShell::ENUMERATE_FORWARDS,
|
||||
docShells);
|
||||
|
||||
nsCOMPtr<nsISupports> currentContainer;
|
||||
bool hasMoreDocShells;
|
||||
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) &&
|
||||
hasMoreDocShells) {
|
||||
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
|
||||
for (const auto& currentContainer : docShells) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = do_GetInterface(currentContainer);
|
||||
if (win) {
|
||||
fm->ClearFocus(win);
|
||||
|
|
|
@ -1550,23 +1550,17 @@ static void GetProfileTimelineSubDocShells(nsDocShell* aRootDocShell,
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
||||
nsresult rv = aRootDocShell->GetDocShellEnumerator(
|
||||
nsTArray<RefPtr<nsIDocShell>> docShells;
|
||||
nsresult rv = aRootDocShell->GetAllDocShellsInSubtree(
|
||||
nsIDocShellTreeItem::typeAll, nsIDocShell::ENUMERATE_BACKWARDS,
|
||||
getter_AddRefs(enumerator));
|
||||
docShells);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> curItem;
|
||||
bool hasMore = false;
|
||||
while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
|
||||
nsCOMPtr<nsISupports> curSupports;
|
||||
enumerator->GetNext(getter_AddRefs(curSupports));
|
||||
curItem = do_QueryInterface(curSupports);
|
||||
|
||||
if (!curItem || !curItem->GetRecordProfileTimelineMarkers()) {
|
||||
for (const auto& curItem : docShells) {
|
||||
if (!curItem->GetRecordProfileTimelineMarkers()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1294,12 +1294,12 @@ var ExtensionContent = {
|
|||
// Helpers
|
||||
|
||||
*enumerateWindows(docShell) {
|
||||
let enum_ = docShell.getDocShellEnumerator(
|
||||
let docShells = docShell.getAllDocShellsInSubtree(
|
||||
docShell.typeContent,
|
||||
docShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
||||
for (let docShell of enum_) {
|
||||
for (let docShell of docShells) {
|
||||
try {
|
||||
yield docShell.domWindow;
|
||||
} catch (e) {
|
||||
|
|
|
@ -292,12 +292,11 @@ nsresult ExtensionPolicyService::HandleEvent(dom::Event* aEvent) {
|
|||
nsresult ForEachDocShell(
|
||||
nsIDocShell* aDocShell,
|
||||
const std::function<nsresult(nsIDocShell*)>& aCallback) {
|
||||
nsCOMPtr<nsISimpleEnumerator> iter;
|
||||
MOZ_TRY(aDocShell->GetDocShellEnumerator(nsIDocShell::typeContent,
|
||||
nsIDocShell::ENUMERATE_FORWARDS,
|
||||
getter_AddRefs(iter)));
|
||||
nsTArray<RefPtr<nsIDocShell>> docShells;
|
||||
MOZ_TRY(aDocShell->GetAllDocShellsInSubtree(
|
||||
nsIDocShell::typeContent, nsIDocShell::ENUMERATE_FORWARDS, docShells));
|
||||
|
||||
for (auto& docShell : SimpleEnumerator<nsIDocShell>(iter)) {
|
||||
for (auto& docShell : docShells) {
|
||||
MOZ_TRY(aCallback(docShell));
|
||||
}
|
||||
return NS_OK;
|
||||
|
|
|
@ -27,7 +27,7 @@ const EXPORTED_SYMBOLS = ["WebNavigationFrames"];
|
|||
* @returns {Iterator<nsIDocShell>}
|
||||
*/
|
||||
function iterateDocShellTree(docShell) {
|
||||
return docShell.getDocShellEnumerator(
|
||||
return docShell.getAllDocShellsInSubtree(
|
||||
docShell.typeContent,
|
||||
docShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
|
|
@ -127,10 +127,9 @@ nsWebBrowserFind::FindNext(bool* aResult) {
|
|||
auto enumDirection = mFindBackwards ? nsIDocShell::ENUMERATE_BACKWARDS
|
||||
: nsIDocShell::ENUMERATE_FORWARDS;
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
|
||||
rv = rootDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeAll,
|
||||
enumDirection,
|
||||
getter_AddRefs(docShellEnumerator));
|
||||
nsTArray<RefPtr<nsIDocShell>> docShells;
|
||||
rv = rootDocShell->GetAllDocShellsInSubtree(nsIDocShellTreeItem::typeAll,
|
||||
enumDirection, docShells);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -138,23 +137,10 @@ nsWebBrowserFind::FindNext(bool* aResult) {
|
|||
// remember where we started
|
||||
nsCOMPtr<nsIDocShellTreeItem> startingItem = searchFrame->GetDocShell();
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> curItem;
|
||||
|
||||
// XXX We should avoid searching in frameset documents here.
|
||||
// We also need to honour mSearchSubFrames and mSearchParentFrames.
|
||||
bool hasMore, doFind = false;
|
||||
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
nsCOMPtr<nsISupports> curSupports;
|
||||
rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports));
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
curItem = do_QueryInterface(curSupports, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool doFind = false;
|
||||
for (const auto& curItem : docShells) {
|
||||
if (doFind) {
|
||||
searchFrame = curItem->GetWindow();
|
||||
if (!searchFrame) {
|
||||
|
@ -192,26 +178,13 @@ nsWebBrowserFind::FindNext(bool* aResult) {
|
|||
|
||||
// because nsISimpleEnumerator is bad and isn't resettable, I have to
|
||||
// make a new one
|
||||
docShellEnumerator = nullptr;
|
||||
rv = rootDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeAll,
|
||||
enumDirection,
|
||||
getter_AddRefs(docShellEnumerator));
|
||||
rv = rootDocShell->GetAllDocShellsInSubtree(nsIDocShellTreeItem::typeAll,
|
||||
enumDirection, docShells);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
nsCOMPtr<nsISupports> curSupports;
|
||||
rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports));
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
curItem = do_QueryInterface(curSupports, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto& curItem : docShells) {
|
||||
searchFrame = curItem->GetWindow();
|
||||
if (!searchFrame) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
|
|
@ -22,7 +22,7 @@ function getDialogDoc() {
|
|||
// that has either commonDialog.xul or selectDialog.xul loaded.
|
||||
// var enumerator = Services.wm.getEnumerator("navigator:browser");
|
||||
for (let { docShell } of Services.wm.getEnumerator(null)) {
|
||||
var containedDocShells = docShell.getDocShellEnumerator(
|
||||
var containedDocShells = docShell.getAllDocShellsInSubtree(
|
||||
docShell.typeChrome,
|
||||
docShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
|
|
@ -9,7 +9,7 @@ function getSelectDialogDoc() {
|
|||
// that has selectDialog.xul loaded.
|
||||
// var enumerator = Services.wm.getEnumerator("navigator:browser");
|
||||
for (let { docShell } of Services.wm.getEnumerator(null)) {
|
||||
var containedDocShells = docShell.getDocShellEnumerator(
|
||||
var containedDocShells = docShell.getAllDocShellsInSubtree(
|
||||
docShell.typeChrome,
|
||||
docShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
|
|
@ -222,7 +222,7 @@ function getDialogDoc() {
|
|||
// that has either commonDialog.xul or selectDialog.xul loaded.
|
||||
// var enumerator = Services.wm.getEnumerator("navigator:browser");
|
||||
for (let { docShell } of Services.wm.getEnumerator(null)) {
|
||||
var containedDocShells = docShell.getDocShellEnumerator(
|
||||
var containedDocShells = docShell.getAllDocShellsInSubtree(
|
||||
docShell.typeChrome,
|
||||
docShell.ENUMERATE_FORWARDS
|
||||
);
|
||||
|
|
|
@ -371,9 +371,11 @@ nsresult nsTypeAheadFind::FindItNow(uint32_t aMode, bool aIsLinksOnly,
|
|||
|
||||
nsCOMPtr<nsIDocShell> currentDocShell;
|
||||
nsCOMPtr<nsISupports> currentContainer;
|
||||
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootContentTreeItem;
|
||||
nsCOMPtr<nsIDocShell> rootContentDocShell;
|
||||
typedef nsTArray<RefPtr<nsIDocShell>> DocShells;
|
||||
DocShells docShells;
|
||||
DocShells::const_iterator it, it_end;
|
||||
if (!aDontIterateFrames) {
|
||||
// The use of GetInProcessSameTypeRootTreeItem (and later in this method) is
|
||||
// OK here as out-of-process frames are handled externally by
|
||||
|
@ -385,22 +387,17 @@ nsresult nsTypeAheadFind::FindItNow(uint32_t aMode, bool aIsLinksOnly,
|
|||
|
||||
if (!rootContentDocShell) return NS_ERROR_FAILURE;
|
||||
|
||||
rootContentDocShell->GetDocShellEnumerator(
|
||||
rootContentDocShell->GetAllDocShellsInSubtree(
|
||||
nsIDocShellTreeItem::typeContent, nsIDocShell::ENUMERATE_FORWARDS,
|
||||
getter_AddRefs(docShellEnumerator));
|
||||
docShells);
|
||||
|
||||
// Default: can start at the current document
|
||||
currentContainer = do_QueryInterface(rootContentDocShell);
|
||||
|
||||
// Iterate up to current shell, if there's more than 1 that we're
|
||||
// dealing with
|
||||
bool hasMoreDocShells;
|
||||
|
||||
while (
|
||||
NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) &&
|
||||
hasMoreDocShells) {
|
||||
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
|
||||
currentDocShell = do_QueryInterface(currentContainer);
|
||||
for (it = docShells.begin(), it_end = docShells.end(); it != it_end; ++it) {
|
||||
currentDocShell = *it;
|
||||
if (!currentDocShell || currentDocShell == startingDocShell ||
|
||||
aIsFirstVisiblePreferred)
|
||||
break;
|
||||
|
@ -650,12 +647,10 @@ nsresult nsTypeAheadFind::FindItNow(uint32_t aMode, bool aIsLinksOnly,
|
|||
bool hasTriedFirstDoc = false;
|
||||
do {
|
||||
// ==== Second inner loop - get another while ====
|
||||
bool hasMoreDocShells;
|
||||
if (NS_SUCCEEDED(
|
||||
docShellEnumerator->HasMoreElements(&hasMoreDocShells)) &&
|
||||
hasMoreDocShells) {
|
||||
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
|
||||
NS_ASSERTION(currentContainer, "HasMoreElements lied to us!");
|
||||
if (it != it_end) {
|
||||
currentContainer = *it;
|
||||
++it;
|
||||
NS_ASSERTION(currentContainer, "We're not at the end yet!");
|
||||
currentDocShell = do_QueryInterface(currentContainer);
|
||||
|
||||
if (currentDocShell) break;
|
||||
|
@ -663,11 +658,13 @@ nsresult nsTypeAheadFind::FindItNow(uint32_t aMode, bool aIsLinksOnly,
|
|||
return NS_ERROR_FAILURE; // No content doc shells
|
||||
|
||||
// Reached last doc shell, loop around back to first doc shell
|
||||
rootContentDocShell->GetDocShellEnumerator(
|
||||
rootContentDocShell->GetAllDocShellsInSubtree(
|
||||
nsIDocShellTreeItem::typeContent, nsIDocShell::ENUMERATE_FORWARDS,
|
||||
getter_AddRefs(docShellEnumerator));
|
||||
docShells);
|
||||
it = docShells.begin();
|
||||
it_end = docShells.end();
|
||||
hasTriedFirstDoc = true;
|
||||
} while (docShellEnumerator); // ==== end second inner while ===
|
||||
} while (it != it_end); // ==== end second inner while ===
|
||||
|
||||
bool continueLoop = false;
|
||||
if (currentDocShell != startingDocShell)
|
||||
|
|
|
@ -163,6 +163,8 @@ class nsDocLoader : public nsIDocumentLoader,
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t ChildCount() const { return mChildList.Length(); }
|
||||
|
||||
protected:
|
||||
virtual ~nsDocLoader();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче