Skip to content

Commit

Permalink
Backed out changeset a81b4130ac14 (bug 1666485) for causing bustages …
Browse files Browse the repository at this point in the history
…on BrowsingContext. CLOSED TREE
  • Loading branch information
Butkovits Atila committed Sep 23, 2020
1 parent f8e1e72 commit 61225d6
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 56 deletions.
9 changes: 2 additions & 7 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ bool BrowsingContext::SameOriginWithTop() {
/* static */
already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
nsGlobalWindowInner* aParent, BrowsingContext* aOpener,
BrowsingContextGroup* aSpecificGroup, const nsAString& aName, Type aType,
bool aCreatedDynamically) {
BrowsingContextGroup* aSpecificGroup, const nsAString& aName, Type aType) {
if (aParent) {
MOZ_DIAGNOSTIC_ASSERT(aParent->GetWindowContext());
MOZ_DIAGNOSTIC_ASSERT(aParent->GetBrowsingContext()->mType == aType);
Expand Down Expand Up @@ -337,7 +336,6 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
}

context->mEmbeddedByThisProcess = XRE_IsParentProcess() || aParent;
context->mCreatedDynamically = aCreatedDynamically;
if (inherit) {
context->mPrivateBrowsingId = inherit->mPrivateBrowsingId;
context->mUseRemoteTabs = inherit->mUseRemoteTabs;
Expand Down Expand Up @@ -411,7 +409,6 @@ void BrowsingContext::CreateFromIPC(BrowsingContext::IPCInitializer&& aInit,
}

context->mWindowless = aInit.mWindowless;
context->mCreatedDynamically = aInit.mCreatedDynamically;
if (context->GetHasSessionHistory()) {
context->CreateChildSHistory();
if (StaticPrefs::fission_sessionHistoryInParent()) {
Expand Down Expand Up @@ -450,8 +447,7 @@ BrowsingContext::BrowsingContext(WindowContext* aParentWindow,
mDanglingRemoteOuterProxies(false),
mEmbeddedByThisProcess(false),
mUseRemoteTabs(false),
mUseRemoteSubframes(false),
mCreatedDynamically(false) {
mUseRemoteSubframes(false) {
MOZ_RELEASE_ASSERT(!mParentWindow || mParentWindow->Group() == mGroup);
MOZ_RELEASE_ASSERT(mBrowsingContextId != 0);
MOZ_RELEASE_ASSERT(mGroup);
Expand Down Expand Up @@ -2082,7 +2078,6 @@ BrowsingContext::IPCInitializer BrowsingContext::GetIPCInitializer() {
init.mWindowless = mWindowless;
init.mUseRemoteTabs = mUseRemoteTabs;
init.mUseRemoteSubframes = mUseRemoteSubframes;
init.mCreatedDynamically = mCreatedDynamically;
init.mOriginAttributes = mOriginAttributes;
if (mChildSessionHistory && StaticPrefs::fission_sessionHistoryInParent()) {
init.mSessionHistoryIndex = mChildSessionHistory->Index();
Expand Down
12 changes: 3 additions & 9 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class WindowProxyHolder;
FIELD(IsSingleToplevelInHistory, bool) \
FIELD(UseErrorPages, bool) \
FIELD(PlatformOverride, nsString) \
FIELD(HasLoadedNonInitialDocument, bool)
FIELD(HasLoadedNonInitialDocument, bool) \
FIELD(CreatedDynamically, bool)

// BrowsingContext, in this context, is the cross process replicated
// environment in which information about documents is stored. In
Expand Down Expand Up @@ -221,8 +222,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
// DocShell, BrowserParent, or BrowserBridgeChild.
static already_AddRefed<BrowsingContext> CreateDetached(
nsGlobalWindowInner* aParent, BrowsingContext* aOpener,
BrowsingContextGroup* aSpecificGroup, const nsAString& aName, Type aType,
bool aCreatedDynamically = false);
BrowsingContextGroup* aSpecificGroup, const nsAString& aName, Type aType);

void EnsureAttached();

Expand Down Expand Up @@ -599,7 +599,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool mWindowless = false;
bool mUseRemoteTabs = false;
bool mUseRemoteSubframes = false;
bool mCreatedDynamically = false;
int32_t mSessionHistoryIndex = -1;
int32_t mSessionHistoryCount = 0;
OriginAttributes mOriginAttributes;
Expand Down Expand Up @@ -636,8 +635,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
aPendingInitialization);
}

bool CreatedDynamically() const { return mCreatedDynamically; }

const OriginAttributes& OriginAttributesRef() { return mOriginAttributes; }
nsresult SetOriginAttributes(const OriginAttributes& aAttrs);

Expand Down Expand Up @@ -965,9 +962,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
// after this BrowsingContext is attached.
bool mUseRemoteSubframes : 1;

// True if this BrowsingContext is for a frame that was added dynamically.
bool mCreatedDynamically : 1;

// The start time of user gesture, this is only available if the browsing
// context is in process.
TimeStamp mUserGestureStart;
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad(
nsDocShell::ShouldAddToSessionHistory(aLoadState->URI(), aChannel));
}
entry->SetDocshellID(GetHistoryID());
entry->SetIsDynamicallyAdded(CreatedDynamically());
entry->SetIsDynamicallyAdded(GetCreatedDynamically());
entry->SetForInitialLoad(true);
}
MOZ_DIAGNOSTIC_ASSERT(entry);
Expand Down
17 changes: 16 additions & 1 deletion docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2943,7 +2943,8 @@ nsDocShell::AddChild(nsIDocShellTreeItem* aChild) {
"child list must not be empty after a successful add");

nsCOMPtr<nsIDocShell> childDocShell = do_QueryInterface(aChild);
bool dynamic = nsDocShell::Cast(childDocShell)->GetCreatedDynamically();
bool dynamic = false;
childDocShell->GetCreatedDynamically(&dynamic);
if (!dynamic) {
nsCOMPtr<nsISHEntry> currentSH;
bool oshe = false;
Expand Down Expand Up @@ -3124,6 +3125,20 @@ nsresult nsDocShell::AddChildSHEntryToParent(nsISHEntry* aNewEntry,
return rv;
}

NS_IMETHODIMP
nsDocShell::SetCreatedDynamically(bool aDynamic) {
if (mBrowsingContext) {
Unused << mBrowsingContext->SetCreatedDynamically(aDynamic);
}
return NS_OK;
}

NS_IMETHODIMP
nsDocShell::GetCreatedDynamically(bool* aDynamic) {
*aDynamic = mBrowsingContext && mBrowsingContext->GetCreatedDynamically();
return NS_OK;
}

NS_IMETHODIMP
nsDocShell::GetCurrentSHEntry(nsISHEntry** aEntry, bool* aOSHE) {
*aOSHE = false;
Expand Down
4 changes: 0 additions & 4 deletions docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ class nsDocShell final : public nsDocLoader,
// Update any pointers (mOSHE or mLSHE) to aOldEntry to point to aNewEntry
void SwapHistoryEntries(nsISHEntry* aOldEntry, nsISHEntry* aNewEntry);

bool GetCreatedDynamically() const {
return mBrowsingContext && mBrowsingContext->CreatedDynamically();
}

mozilla::gfx::Matrix5x4* GetColorMatrix() { return mColorMatrix.get(); }

static bool SandboxFlagsImplyCookies(const uint32_t& aSandboxFlags);
Expand Down
5 changes: 5 additions & 0 deletions docshell/base/nsIDocShell.idl
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ interface nsIDocShell : nsIDocShellTreeItem
*/
void makeEditable(in boolean inWaitForUriLoad);

/**
* Set when an iframe/frame is added dynamically.
*/
[infallible] attribute boolean createdDynamically;

/**
* Returns false for mLSHE, true for mOSHE
*/
Expand Down
13 changes: 8 additions & 5 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static bool IsTopContent(BrowsingContext* aParent, Element* aOwner) {

static already_AddRefed<BrowsingContext> CreateBrowsingContext(
Element* aOwner, nsIOpenWindowInfo* aOpenWindowInfo,
BrowsingContextGroup* aSpecificGroup, bool aNetworkCreated = false) {
BrowsingContextGroup* aSpecificGroup) {
MOZ_ASSERT(!aOpenWindowInfo || !aSpecificGroup,
"Only one of SpecificGroup and OpenWindowInfo may be provided!");

Expand Down Expand Up @@ -326,8 +326,7 @@ static already_AddRefed<BrowsingContext> CreateBrowsingContext(
MOZ_ASSERT(!aSpecificGroup,
"Can't force BrowsingContextGroup for non-toplevel context");
return BrowsingContext::CreateDetached(parentInner, nullptr, nullptr,
frameName, parentBC->GetType(),
!aNetworkCreated);
frameName, parentBC->GetType());
}

static bool InitialLoadIsRemote(Element* aOwner) {
Expand Down Expand Up @@ -411,7 +410,7 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Create(

RefPtr<BrowsingContextGroup> group = InitialBrowsingContextGroup(aOwner);
RefPtr<BrowsingContext> context =
CreateBrowsingContext(aOwner, aOpenWindowInfo, group, aNetworkCreated);
CreateBrowsingContext(aOwner, aOpenWindowInfo, group);
NS_ENSURE_TRUE(context, nullptr);

bool isRemoteFrame = InitialLoadIsRemote(aOwner);
Expand Down Expand Up @@ -2126,7 +2125,11 @@ nsresult nsFrameLoader::MaybeCreateDocShell() {

InvokeBrowsingContextReadyCallback();

mIsTopLevelContent = mPendingBrowsingContext->IsTopContent();
mIsTopLevelContent = mPendingBrowsingContext->IsContent() &&
!mPendingBrowsingContext->GetParent();
if (!mNetworkCreated && !mIsTopLevelContent) {
docShell->SetCreatedDynamically(true);
}

if (mIsTopLevelContent) {
// Manually add ourselves to our parent's docshell, as BrowsingContext won't
Expand Down
30 changes: 21 additions & 9 deletions toolkit/components/sessionstore/SessionStoreListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,22 @@ TabListener::HandleEvent(Event* aEvent) {
}

nsPIDOMWindowOuter* outer = target->GetOwnerGlobalForBindingsInternal();
if (!outer || !outer->GetDocShell()) {
if (!outer) {
return NS_OK;
}

RefPtr<BrowsingContext> context = outer->GetBrowsingContext();
if (!context || context->CreatedDynamically()) {
nsIDocShell* docShell = outer->GetDocShell();
if (!docShell) {
return NS_OK;
}

bool isDynamic = false;
nsresult rv = docShell->GetCreatedDynamically(&isDynamic);
if (NS_FAILED(rv)) {
return NS_OK;
}

if (isDynamic) {
return NS_OK;
}

Expand Down Expand Up @@ -447,12 +457,13 @@ nsCString CollectPosition(Document& aDocument) {
int CollectPositions(BrowsingContext* aBrowsingContext,
nsTArray<nsCString>& aPositions,
nsTArray<int32_t>& aPositionDescendants) {
if (aBrowsingContext->CreatedDynamically()) {
nsPIDOMWindowOuter* window = aBrowsingContext->GetDOMWindow();
if (!window) {
return 0;
}

nsPIDOMWindowOuter* window = aBrowsingContext->GetDOMWindow();
if (!window) {
nsIDocShell* docShell = window->GetDocShell();
if (!docShell || docShell->GetCreatedDynamically()) {
return 0;
}

Expand Down Expand Up @@ -531,12 +542,13 @@ int CollectInputs(BrowsingContext* aBrowsingContext,
nsTArray<InputFormData>& aInputs,
nsTArray<CollectedInputDataValue>& aIdVals,
nsTArray<CollectedInputDataValue>& aXPathVals) {
if (aBrowsingContext->CreatedDynamically()) {
nsPIDOMWindowOuter* window = aBrowsingContext->GetDOMWindow();
if (!window) {
return 0;
}

nsPIDOMWindowOuter* window = aBrowsingContext->GetDOMWindow();
if (!window || !window->GetDocShell()) {
nsIDocShell* docShell = window->GetDocShell();
if (!docShell || docShell->GetCreatedDynamically()) {
return 0;
}

Expand Down
55 changes: 35 additions & 20 deletions toolkit/components/sessionstore/SessionStoreUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ class DynamicFrameEventFilter final : public nsIDOMEventListener {
}

nsPIDOMWindowOuter* outer = target->GetOwnerGlobalForBindingsInternal();
if (!outer || !outer->GetDocShell()) {
if (!outer) {
return false;
}

RefPtr<BrowsingContext> context = outer->GetBrowsingContext();
return context && !context->CreatedDynamically();
nsIDocShell* docShell = outer->GetDocShell();
if (!docShell) {
return false;
}

bool isDynamic = false;
nsresult rv = docShell->GetCreatedDynamically(&isDynamic);
return NS_SUCCEEDED(rv) && !isDynamic;
}

RefPtr<EventListener> mListener;
Expand Down Expand Up @@ -114,24 +120,21 @@ void SessionStoreUtils::ForEachNonDynamicChildFrame(
return;
}

RefPtr<BrowsingContext> context = item->GetBrowsingContext();
if (!context) {
nsCOMPtr<nsIDocShell> childDocShell(do_QueryInterface(item));
if (!childDocShell) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}

if (context->CreatedDynamically()) {
bool isDynamic = false;
nsresult rv = childDocShell->GetCreatedDynamically(&isDynamic);
if (NS_SUCCEEDED(rv) && isDynamic) {
continue;
}

nsCOMPtr<nsIDocShell> childDocShell(do_QueryInterface(item));
if (!childDocShell) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}

int32_t childOffset = childDocShell->GetChildOffset();
aCallback.Call(WindowProxyHolder(context.forget()), childOffset);
aCallback.Call(WindowProxyHolder(item->GetWindow()->GetBrowsingContext()),
childOffset);
}
}

Expand Down Expand Up @@ -1161,16 +1164,27 @@ void SessionStoreUtils::CollectedSessionStorage(
ReadAllEntriesFromStorage(window, aOrigins, aKeys, aValues);

/* Collect session storage from all child frame */
if (!window->GetDocShell()) {
nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
if (!docShell) {
return;
}

// This is not going to work for fission. Bug 1572084 for tracking it.
for (BrowsingContext* child : aBrowsingContext->Children()) {
if (!child->CreatedDynamically()) {
SessionStoreUtils::CollectedSessionStorage(child, aOrigins, aKeys,
aValues);
window = child->GetDOMWindow();
if (!window) {
return;
}
docShell = window->GetDocShell();
if (!docShell) {
return;
}
bool isDynamic = false;
nsresult rv = docShell->GetCreatedDynamically(&isDynamic);
if (NS_SUCCEEDED(rv) && isDynamic) {
continue;
}
SessionStoreUtils::CollectedSessionStorage(child, aOrigins, aKeys, aValues);
}
}

Expand Down Expand Up @@ -1248,12 +1262,13 @@ static void CollectFrameTreeData(JSContext* aCx,
BrowsingContext* aBrowsingContext,
Nullable<CollectedData>& aRetVal,
CollectorFunc aFunc) {
if (aBrowsingContext->CreatedDynamically()) {
nsPIDOMWindowOuter* window = aBrowsingContext->GetDOMWindow();
if (!window) {
return;
}

nsPIDOMWindowOuter* window = aBrowsingContext->GetDOMWindow();
if (!window || !window->GetDocShell()) {
nsIDocShell* docShell = window->GetDocShell();
if (!docShell || docShell->GetCreatedDynamically()) {
return;
}

Expand Down

0 comments on commit 61225d6

Please sign in to comment.