bug 882079 - merge nsIDocShellHistory into nsIDocShell r=smaug

This commit is contained in:
Trevor Saunders 2013-02-15 11:07:29 -05:00
parent 56c9fd466f
commit a2966f198d
9 changed files with 114 additions and 152 deletions

View File

@ -805,7 +805,7 @@ var gBrowserInit = {
// enable global history
try {
if (!gMultiProcessBrowser)
gBrowser.docShell.QueryInterface(Ci.nsIDocShellHistory).useGlobalHistory = true;
gBrowser.docShell.useGlobalHistory = true;
} catch(ex) {
Cu.reportError("Places database may be locked: " + ex);
}

View File

@ -49,7 +49,6 @@
#include "nsEventDispatcher.h"
#include "nsISHistory.h"
#include "nsISHistoryInternal.h"
#include "nsIDocShellHistory.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIXULWindow.h"
#include "nsIEditor.h"
@ -1337,9 +1336,8 @@ nsFrameLoader::Destroy()
// Seems like this is a dynamic frame removal.
if (dynamicSubframeRemoval) {
nsCOMPtr<nsIDocShellHistory> dhistory = do_QueryInterface(mDocShell);
if (dhistory) {
dhistory->RemoveFromSessionHistory();
if (mDocShell) {
mDocShell->RemoveFromSessionHistory();
}
}
@ -1546,9 +1544,8 @@ nsFrameLoader::MaybeCreateDocShell()
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
if (!mNetworkCreated) {
nsCOMPtr<nsIDocShellHistory> history = do_QueryInterface(mDocShell);
if (history) {
history->SetCreatedDynamically(true);
if (mDocShell) {
mDocShell->SetCreatedDynamically(true);
}
}

View File

@ -13,7 +13,6 @@ XPIDL_SOURCES += [
'nsIContentViewerFile.idl',
'nsIDocCharset.idl',
'nsIDocShell.idl',
'nsIDocShellHistory.idl',
'nsIDocShellLoadInfo.idl',
'nsIDocShellTreeItem.idl',
'nsIDocShellTreeNode.idl',

View File

@ -900,7 +900,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIDocShell)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode)
NS_INTERFACE_MAP_ENTRY(nsIDocShellHistory)
NS_INTERFACE_MAP_ENTRY(nsIWebNavigation)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_ENTRY(nsIScrollable)
@ -1317,82 +1316,75 @@ nsDocShell::LoadURI(nsIURI * aURI,
// Get the parent's load type
parentDS->GetLoadType(&parentLoadType);
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(parentAsItem));
if (parent) {
// Get the ShEntry for the child from the parent
nsCOMPtr<nsISHEntry> currentSH;
bool oshe = false;
parent->GetCurrentSHEntry(getter_AddRefs(currentSH), &oshe);
bool dynamicallyAddedChild = mDynamicallyCreated;
if (!dynamicallyAddedChild && !oshe && currentSH) {
currentSH->HasDynamicallyAddedChild(&dynamicallyAddedChild);
}
if (!dynamicallyAddedChild) {
// Only use the old SHEntry, if we're sure enough that
// it wasn't originally for some other frame.
parent->GetChildSHEntry(mChildOffset, getter_AddRefs(shEntry));
}
// Get the ShEntry for the child from the parent
nsCOMPtr<nsISHEntry> currentSH;
bool oshe = false;
parentDS->GetCurrentSHEntry(getter_AddRefs(currentSH), &oshe);
bool dynamicallyAddedChild = mDynamicallyCreated;
if (!dynamicallyAddedChild && !oshe && currentSH) {
currentSH->HasDynamicallyAddedChild(&dynamicallyAddedChild);
}
if (!dynamicallyAddedChild) {
// Only use the old SHEntry, if we're sure enough that
// it wasn't originally for some other frame.
parentDS->GetChildSHEntry(mChildOffset, getter_AddRefs(shEntry));
}
// Make some decisions on the child frame's loadType based on the
// parent's loadType.
if (mCurrentURI == nullptr) {
// This is a newly created frame. Check for exception cases first.
// By default the subframe will inherit the parent's loadType.
if (shEntry && (parentLoadType == LOAD_NORMAL ||
parentLoadType == LOAD_LINK ||
parentLoadType == LOAD_NORMAL_EXTERNAL)) {
// The parent was loaded normally. In this case, this *brand new* child really shouldn't
// have a SHEntry. If it does, it could be because the parent is replacing an
// existing frame with a new frame, in the onLoadHandler. We don't want this
// url to get into session history. Clear off shEntry, and set load type to
// LOAD_BYPASS_HISTORY.
bool inOnLoadHandler=false;
parentDS->GetIsExecutingOnLoadHandler(&inOnLoadHandler);
if (inOnLoadHandler) {
loadType = LOAD_NORMAL_REPLACE;
shEntry = nullptr;
}
}
else if (parentLoadType == LOAD_REFRESH) {
// Clear shEntry. For refresh loads, we have to load
// what comes thro' the pipe, not what's in history.
// Make some decisions on the child frame's loadType based on the
// parent's loadType.
if (mCurrentURI == nullptr) {
// This is a newly created frame. Check for exception cases first.
// By default the subframe will inherit the parent's loadType.
if (shEntry && (parentLoadType == LOAD_NORMAL ||
parentLoadType == LOAD_LINK ||
parentLoadType == LOAD_NORMAL_EXTERNAL)) {
// The parent was loaded normally. In this case, this *brand new* child really shouldn't
// have a SHEntry. If it does, it could be because the parent is replacing an
// existing frame with a new frame, in the onLoadHandler. We don't want this
// url to get into session history. Clear off shEntry, and set load type to
// LOAD_BYPASS_HISTORY.
bool inOnLoadHandler=false;
parentDS->GetIsExecutingOnLoadHandler(&inOnLoadHandler);
if (inOnLoadHandler) {
loadType = LOAD_NORMAL_REPLACE;
shEntry = nullptr;
}
else if ((parentLoadType == LOAD_BYPASS_HISTORY) ||
(shEntry &&
((parentLoadType & LOAD_CMD_HISTORY) ||
(parentLoadType == LOAD_RELOAD_NORMAL) ||
(parentLoadType == LOAD_RELOAD_CHARSET_CHANGE)))) {
// If the parent url, bypassed history or was loaded from
// history, pass on the parent's loadType to the new child
// frame too, so that the child frame will also
// avoid getting into history.
loadType = parentLoadType;
}
else if (parentLoadType == LOAD_ERROR_PAGE) {
// If the parent document is an error page, we don't
// want to update global/session history. However,
// this child frame is not an error page.
loadType = LOAD_BYPASS_HISTORY;
}
} else if (parentLoadType == LOAD_REFRESH) {
// Clear shEntry. For refresh loads, we have to load
// what comes thro' the pipe, not what's in history.
shEntry = nullptr;
} else if ((parentLoadType == LOAD_BYPASS_HISTORY) ||
(shEntry &&
((parentLoadType & LOAD_CMD_HISTORY) ||
(parentLoadType == LOAD_RELOAD_NORMAL) ||
(parentLoadType == LOAD_RELOAD_CHARSET_CHANGE)))) {
// If the parent url, bypassed history or was loaded from
// history, pass on the parent's loadType to the new child
// frame too, so that the child frame will also
// avoid getting into history.
loadType = parentLoadType;
} else if (parentLoadType == LOAD_ERROR_PAGE) {
// If the parent document is an error page, we don't
// want to update global/session history. However,
// this child frame is not an error page.
loadType = LOAD_BYPASS_HISTORY;
}
else {
// This is a pre-existing subframe. If the load was not originally initiated
// by session history, (if (!shEntry) condition succeeded) and mCurrentURI is not null,
// it is possible that a parent's onLoadHandler or even self's onLoadHandler is loading
// a new page in this child. Check parent's and self's busy flag and if it is set,
// we don't want this onLoadHandler load to get in to session history.
uint32_t parentBusy = BUSY_FLAGS_NONE;
uint32_t selfBusy = BUSY_FLAGS_NONE;
parentDS->GetBusyFlags(&parentBusy);
GetBusyFlags(&selfBusy);
if (parentBusy & BUSY_FLAGS_BUSY ||
} else {
// This is a pre-existing subframe. If the load was not originally initiated
// by session history, (if (!shEntry) condition succeeded) and mCurrentURI is not null,
// it is possible that a parent's onLoadHandler or even self's onLoadHandler is loading
// a new page in this child. Check parent's and self's busy flag and if it is set,
// we don't want this onLoadHandler load to get in to session history.
uint32_t parentBusy = BUSY_FLAGS_NONE;
uint32_t selfBusy = BUSY_FLAGS_NONE;
parentDS->GetBusyFlags(&parentBusy);
GetBusyFlags(&selfBusy);
if (parentBusy & BUSY_FLAGS_BUSY ||
selfBusy & BUSY_FLAGS_BUSY) {
loadType = LOAD_NORMAL_REPLACE;
shEntry = nullptr;
}
loadType = LOAD_NORMAL_REPLACE;
shEntry = nullptr;
}
} // parent
}
} //parentDS
else {
// This is the root docshell. If we got here while
@ -3461,9 +3453,9 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
NS_ASSERTION(!mChildList.IsEmpty(),
"child list must not be empty after a successful add");
nsCOMPtr<nsIDocShellHistory> docshellhistory = do_QueryInterface(aChild);
nsCOMPtr<nsIDocShell> childDocShell = do_QueryInterface(aChild);
bool dynamic = false;
docshellhistory->GetCreatedDynamically(&dynamic);
childDocShell->GetCreatedDynamically(&dynamic);
if (!dynamic) {
nsCOMPtr<nsISHEntry> currentSH;
bool oshe = false;
@ -3472,15 +3464,11 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
currentSH->HasDynamicallyAddedChild(&dynamic);
}
}
nsCOMPtr<nsIDocShell> childDocShell = do_QueryInterface(aChild);
childDocShell->SetChildOffset(dynamic ? -1 : mChildList.Length() - 1);
/* Set the child's global history if the parent has one */
if (mUseGlobalHistory) {
nsCOMPtr<nsIDocShellHistory>
dsHistoryChild(do_QueryInterface(aChild));
if (dsHistoryChild)
dsHistoryChild->SetUseGlobalHistory(true);
childDocShell->SetUseGlobalHistory(true);
}
@ -3643,9 +3631,6 @@ nsDocShell::FindChildWithName(const PRUnichar * aName,
return NS_OK;
}
//*****************************************************************************
// nsDocShell::nsIDocShellHistory
//*****************************************************************************
NS_IMETHODIMP
nsDocShell::GetChildSHEntry(int32_t aChildOffset, nsISHEntry ** aResult)
{
@ -3759,7 +3744,7 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry,
}
else {
/* Just pass this along */
nsCOMPtr<nsIDocShellHistory> parent =
nsCOMPtr<nsIDocShell> parent =
do_QueryInterface(GetAsSupports(mParent), &rv);
if (parent) {
rv = parent->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset,
@ -3789,7 +3774,7 @@ nsDocShell::DoAddChildSHEntry(nsISHEntry* aNewEntry, int32_t aChildOffset,
}
nsresult rv;
nsCOMPtr<nsIDocShellHistory> parent =
nsCOMPtr<nsIDocShell> parent =
do_QueryInterface(GetAsSupports(mParent), &rv);
if (parent) {
rv = parent->AddChildSHEntry(mOSHE, aNewEntry, aChildOffset, mLoadType,
@ -6388,7 +6373,7 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
// Need to clear the session history for all child
// docshells so that we can handle them like they would
// all be added dynamically.
nsCOMPtr<nsIDocShellHistory> parent =
nsCOMPtr<nsIDocShell> parent =
do_QueryInterface(parentAsItem);
if (parent) {
bool oshe = false;

View File

@ -61,7 +61,6 @@
#include "nsIWebProgressListener.h"
#include "nsISHContainer.h"
#include "nsIDocShellLoadInfo.h"
#include "nsIDocShellHistory.h"
#include "nsIURIFixup.h"
#include "nsIWebBrowserFind.h"
#include "nsIHttpChannel.h"
@ -136,7 +135,6 @@ typedef enum {
class nsDocShell : public nsDocLoader,
public nsIDocShell,
public nsIDocShellHistory,
public nsIWebNavigation,
public nsIBaseWindow,
public nsIScrollable,
@ -170,7 +168,6 @@ public:
NS_DECL_NSIDOCSHELL
NS_DECL_NSIDOCSHELLTREEITEM
NS_DECL_NSIDOCSHELLTREENODE
NS_DECL_NSIDOCSHELLHISTORY
NS_DECL_NSIWEBNAVIGATION
NS_DECL_NSIBASEWINDOW
NS_DECL_NSISCROLLABLE

View File

@ -42,7 +42,7 @@ interface nsIVariant;
interface nsIPrivacyTransitionObserver;
interface nsIReflowObserver;
[scriptable, builtinclass, uuid(d15b07e0-c604-11e2-8bdc-651679957a39)]
[scriptable, builtinclass, uuid(bb1a1c98-4deb-44ea-b607-aa7a1ad8abae)]
interface nsIDocShell : nsIDocShellTreeItem
{
/**
@ -824,4 +824,41 @@ interface nsIDocShell : nsIDocShellTreeItem
* creating the editor.
*/
void makeEditable(in boolean inWaitForUriLoad);
/**
* Get the SHEntry associated with a child docshell
*/
nsISHEntry getChildSHEntry(in long aChildOffset);
/**
* Add a Child SHEntry for a frameset page, given the child's loadtype.
* If aCloneChildren is true, then aCloneReference's children will be
* cloned onto aHistoryEntry.
*/
void addChildSHEntry(in nsISHEntry aCloneReference,
in nsISHEntry aHistoryEntry,
in long aChildOffset,
in unsigned long aLoadType,
in boolean aCloneChilden);
/**
* Whether this docshell should save entries in global history.
*/
attribute boolean useGlobalHistory;
/**
* Removes nsISHEntry objects related to this docshell from session history.
* Use this only with subdocuments, like iframes.
*/
void removeFromSessionHistory();
/**
* Set when an iframe/frame is added dynamically.
*/
attribute boolean createdDynamically;
/**
* Returns false for mLSHE, true for mOSHE
*/
boolean getCurrentSHEntry(out nsISHEntry aEntry);
};

View File

@ -1,50 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsISHEntry;
[scriptable, uuid(077af5fd-7450-48db-8f03-16617d441141)]
interface nsIDocShellHistory : nsISupports
{
/**
* Get the SHEntry associated with a child docshell
*/
nsISHEntry getChildSHEntry(in long aChildOffset);
/**
* Add a Child SHEntry for a frameset page, given the child's loadtype.
* If aCloneChildren is true, then aCloneReference's children will be
* cloned onto aHistoryEntry.
*/
void addChildSHEntry(in nsISHEntry aCloneReference,
in nsISHEntry aHistoryEntry,
in long aChildOffset,
in unsigned long aLoadType,
in boolean aCloneChilden);
/**
* Whether this docshell should save entries in global history.
*/
attribute boolean useGlobalHistory;
/**
* Removes nsISHEntry objects related to this docshell from session history.
* Use this only with subdocuments, like iframes.
*/
void removeFromSessionHistory();
/**
* Set when an iframe/frame is added dynamically.
*/
attribute boolean createdDynamically;
/**
* Returns false for mLSHE, true for mOSHE
*/
boolean getCurrentSHEntry(out nsISHEntry aEntry);
};

View File

@ -25,7 +25,6 @@
#include "nsIWebBrowserFocus.h"
#include "nsIWebBrowserStream.h"
#include "nsIPresShell.h"
#include "nsIDocShellHistory.h"
#include "nsIURIContentListener.h"
#include "nsGUIEvent.h"
#include "nsISHistoryListener.h"
@ -317,10 +316,8 @@ NS_IMETHODIMP nsWebBrowser::EnableGlobalHistory(bool aEnable)
nsresult rv;
NS_ENSURE_STATE(mDocShell);
nsCOMPtr<nsIDocShellHistory> dsHistory(do_QueryInterface(mDocShell, &rv));
if (NS_FAILED(rv)) return rv;
return dsHistory->SetUseGlobalHistory(aEnable);
return mDocShell->SetUseGlobalHistory(aEnable);
}
NS_IMETHODIMP nsWebBrowser::GetContainerWindow(nsIWebBrowserChrome** aTopWindow)

View File

@ -724,7 +724,7 @@
.createInstance(Components.interfaces.nsISHistory);
// enable global history if we weren't told otherwise
if (this.docShell && !this.hasAttribute("disableglobalhistory"))
this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).useGlobalHistory = true;
this.docShell.useGlobalHistory = true;
}
}
catch (e) {