Bug 1570773: Move browsingContext getter to nsIDocShellTreeItem and add notxpcom variant. r=nika

This also renames the existing infallible nsDocShell:GetBrowsingContext()
getter to BrowsingContextRef(), and changes the return type, since several
callers rely on it returning a raw pointer rather than an already_AddRefed.

Differential Revision: https://phabricator.services.mozilla.com/D40312

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kris Maglione 2019-08-07 16:59:30 +00:00
Родитель 91b38964c8
Коммит 64c062d570
12 изменённых файлов: 37 добавлений и 28 удалений

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

@ -206,7 +206,7 @@ BrowsingContext::BrowsingContext(BrowsingContext* aParent,
void BrowsingContext::SetDocShell(nsIDocShell* aDocShell) {
// XXX(nika): We should communicate that we are now an active BrowsingContext
// process to the parent & do other validation here.
MOZ_RELEASE_ASSERT(nsDocShell::Cast(aDocShell)->GetBrowsingContext() == this);
MOZ_RELEASE_ASSERT(aDocShell->GetBrowsingContext() == this);
mDocShell = aDocShell;
mIsInProcess = true;
}
@ -232,8 +232,7 @@ void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {
"cannot be in bfcache");
RefPtr<BrowsingContext> kungFuDeathGrip(this);
RefPtr<BrowsingContext> newParent;
container->GetBrowsingContext(getter_AddRefs(newParent));
RefPtr<BrowsingContext> newParent(container->GetBrowsingContext());
mParent->mChildren.RemoveElement(this);
if (newParent) {
newParent->mChildren.AppendElement(this);

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

@ -7842,7 +7842,7 @@ nsresult nsDocShell::RestoreFromHistory() {
// child inherits our mIsActive mPrivateBrowsingId, which is what we want.
AddChild(childItem);
contexts.AppendElement(nsDocShell::Cast(childShell)->GetBrowsingContext());
contexts.AppendElement(childShell->GetBrowsingContext());
childShell->SetAllowPlugins(allowPlugins);
childShell->SetAllowJavascript(allowJavascript);
@ -7861,7 +7861,7 @@ nsresult nsDocShell::RestoreFromHistory() {
}
if (!contexts.IsEmpty()) {
GetBrowsingContext()->RestoreChildren(std::move(contexts));
mBrowsingContext->RestoreChildren(std::move(contexts));
}
// Make sure to restore the window state after adding the child shells back
@ -13552,11 +13552,13 @@ nsDocShell::GetColorMatrix(nsTArray<float>& aMatrix) {
bool nsDocShell::IsForceReloading() { return IsForceReloadType(mLoadType); }
NS_IMETHODIMP
nsDocShell::GetBrowsingContext(BrowsingContext** aBrowsingContext) {
nsDocShell::GetBrowsingContextXPCOM(BrowsingContext** aBrowsingContext) {
*aBrowsingContext = do_AddRef(mBrowsingContext).take();
return NS_OK;
}
BrowsingContext* nsDocShell::GetBrowsingContext() { return mBrowsingContext; }
bool nsDocShell::GetIsAttemptingToNavigate() {
// XXXbz the document.open spec says to abort even if there's just a
// queued navigation task, sort of. It's not clear whether browsers

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

@ -449,9 +449,6 @@ class nsDocShell final : public nsDocLoader,
// shift while triggering reload)
bool IsForceReloading();
mozilla::dom::BrowsingContext* GetBrowsingContext() const {
return mBrowsingContext;
}
mozilla::dom::BrowsingContext* GetWindowProxy() {
EnsureScriptEnvironment();
return mBrowsingContext;

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

@ -1128,11 +1128,6 @@ interface nsIDocShell : nsIDocShellTreeItem
nsresult SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor);
%}
/**
* BrowsingContext associated with the DocShell.
*/
readonly attribute BrowsingContext browsingContext;
/**
* Allowed CSS display modes. This needs to be kept in
* sync with similar values in ServoStyleConsts.h

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

@ -206,6 +206,14 @@ interface nsIDocShellTreeItem : nsISupports
in nsIDocShellTreeItem aRequestor,
in nsIDocShellTreeItem aOriginalRequestor);
/**
* BrowsingContext associated with the DocShell.
*/
[binaryname(BrowsingContextXPCOM)]
readonly attribute BrowsingContext browsingContext;
[noscript,notxpcom,nostdcall] BrowsingContext getBrowsingContext();
/**
* Returns the DOM outer window for the content viewer.
*/

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

@ -267,7 +267,7 @@ BrowserElementParent::OpenWindowInProcess(BrowsingContext* aOpenerWindow,
nsCOMPtr<nsIDocShell> docshell = frameLoader->GetDocShell(IgnoreErrors());
NS_ENSURE_TRUE(docshell, BrowserElementParent::OPEN_WINDOW_IGNORED);
docshell->GetBrowsingContext(aReturnBC);
docshell->GetBrowsingContextXPCOM(aReturnBC);
return *aReturnBC ? opened : BrowserElementParent::OPEN_WINDOW_CANCELLED;
}

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

@ -3864,7 +3864,7 @@ Nullable<WindowProxyHolder> BrowserChildMessageManager::GetContent(
if (!docShell) {
return nullptr;
}
return WindowProxyHolder(nsDocShell::Cast(docShell)->GetBrowsingContext());
return WindowProxyHolder(docShell->GetBrowsingContext());
}
already_AddRefed<nsIDocShell> BrowserChildMessageManager::GetDocShell(

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

@ -1054,7 +1054,7 @@ void PresShell::Init(Document* aDocument, nsPresContext* aPresContext,
}
if (nsCOMPtr<nsIDocShell> docShell = mPresContext->GetDocShell()) {
BrowsingContext* bc = nsDocShell::Cast(docShell)->GetBrowsingContext();
BrowsingContext* bc = docShell->GetBrowsingContext();
bool embedderFrameIsHidden = true;
if (Element* embedderElement = bc->GetEmbedderElement()) {
if (auto embedderFrame = embedderElement->GetPrimaryFrame()) {
@ -10910,7 +10910,7 @@ void PresShell::SetIsUnderHiddenEmbedderElement(
mUnderHiddenEmbedderElement = aUnderHiddenEmbedderElement;
if (nsCOMPtr<nsIDocShell> docShell = mPresContext->GetDocShell()) {
BrowsingContext* bc = nsDocShell::Cast(docShell)->GetBrowsingContext();
BrowsingContext* bc = docShell->GetBrowsingContext();
// Propagate to children.
for (BrowsingContext* child : bc->GetChildren()) {

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

@ -829,9 +829,9 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
printData->mPrintObject->mFrameType =
printData->mIsParentAFrameSet ? eFrameSet : eDoc;
BuildNestedPrintObjects(nsDocShell::Cast(printData->mPrintObject->mDocShell)
->GetBrowsingContext(),
printData->mPrintObject, &printData->mPrintDocList);
BuildNestedPrintObjects(
printData->mPrintObject->mDocShell->GetBrowsingContext(),
printData->mPrintObject, &printData->mPrintDocList);
}
// The nsAutoScriptBlocker above will now have been destroyed, which may
@ -2656,8 +2656,7 @@ bool nsPrintJob::IsWindowsInOurSubTree(nsPIDOMWindowOuter* window) const {
if (window) {
nsCOMPtr<nsIDocShell> ourDocShell(do_QueryReferent(mDocShell));
if (ourDocShell) {
BrowsingContext* ourBC =
nsDocShell::Cast(ourDocShell)->GetBrowsingContext();
BrowsingContext* ourBC = ourDocShell->GetBrowsingContext();
BrowsingContext* bc = window->GetBrowsingContext();
while (bc) {
if (bc == ourBC) {

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

@ -416,6 +416,16 @@ nsPIDOMWindowOuter* nsWebBrowser::GetWindow() {
return mDocShell ? mDocShell->GetWindow() : nullptr;
}
NS_IMETHODIMP
nsWebBrowser::GetBrowsingContextXPCOM(dom::BrowsingContext** aBrowsingContext) {
NS_ENSURE_STATE(mDocShell);
return mDocShell->GetBrowsingContextXPCOM(aBrowsingContext);
}
dom::BrowsingContext* nsWebBrowser::GetBrowsingContext() {
return mDocShell->GetBrowsingContext();
}
NS_IMETHODIMP
nsWebBrowser::GetDomWindow(mozIDOMWindowProxy** aWindow) {
if (!mDocShell) return NS_ERROR_NOT_INITIALIZED;

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

@ -416,8 +416,8 @@ void ContentSessionStore::GetScrollPositions(
aPositionDescendants.AppendElement(0);
aPositions.AppendElement(EmptyCString());
} else {
CollectPositions(nsDocShell::Cast(mDocShell)->GetBrowsingContext(),
aPositions, aPositionDescendants);
CollectPositions(mDocShell->GetBrowsingContext(), aPositions,
aPositionDescendants);
}
mScrollChanged = NO_CHANGE;
}

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

@ -1189,9 +1189,8 @@ static void CollectedSessionStorageInternal(
if (NS_SUCCEEDED(rv) && isDynamic) {
continue;
}
CollectedSessionStorageInternal(
aCx, nsDocShell::Cast(childDocShell)->GetBrowsingContext(),
aVisitedOrigins, aRetVal);
CollectedSessionStorageInternal(aCx, childDocShell->GetBrowsingContext(),
aVisitedOrigins, aRetVal);
}
}