2015-05-08 14:37:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
#include "nsSHEntryShared.h"
|
2013-08-22 10:30:55 +04:00
|
|
|
|
2017-04-27 13:16:46 +03:00
|
|
|
#include "nsArray.h"
|
|
|
|
#include "nsDocShellEditorData.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIDocument.h"
|
2013-08-22 10:30:55 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2017-04-27 13:16:46 +03:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2011-10-21 19:26:34 +04:00
|
|
|
#include "nsISHistory.h"
|
|
|
|
#include "nsISHistoryInternal.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2017-04-27 13:16:46 +03:00
|
|
|
|
2012-07-11 07:59:52 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-12-04 22:04:36 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
namespace dom = mozilla::dom;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t gSHEntrySharedID = 0;
|
2011-10-21 19:26:34 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::Shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSHEntryShared::nsSHEntryShared()
|
2016-11-17 00:42:35 +03:00
|
|
|
: mDocShellID({0})
|
2017-04-27 13:16:46 +03:00
|
|
|
, mLastTouched(0)
|
|
|
|
, mID(gSHEntrySharedID++)
|
|
|
|
, mViewerBounds(0, 0, 0, 0)
|
2011-10-21 19:26:34 +04:00
|
|
|
, mIsFrameNavigation(false)
|
|
|
|
, mSaveLayoutState(true)
|
|
|
|
, mSticky(true)
|
|
|
|
, mDynamicallyCreated(false)
|
|
|
|
, mExpired(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSHEntryShared::~nsSHEntryShared()
|
|
|
|
{
|
|
|
|
RemoveFromExpirationTracker();
|
|
|
|
if (mContentViewer) {
|
|
|
|
RemoveFromBFCacheSync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSHEntryShared, nsIBFCacheEntry, nsIMutationObserver)
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsSHEntryShared>
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHEntryShared::Duplicate(nsSHEntryShared* aEntry)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSHEntryShared> newEntry = new nsSHEntryShared();
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
newEntry->mDocShellID = aEntry->mDocShellID;
|
|
|
|
newEntry->mChildShells.AppendObjects(aEntry->mChildShells);
|
2016-07-28 10:20:41 +03:00
|
|
|
newEntry->mTriggeringPrincipal = aEntry->mTriggeringPrincipal;
|
2016-09-20 09:36:25 +03:00
|
|
|
newEntry->mPrincipalToInherit = aEntry->mPrincipalToInherit;
|
2011-10-21 19:26:34 +04:00
|
|
|
newEntry->mContentType.Assign(aEntry->mContentType);
|
|
|
|
newEntry->mIsFrameNavigation = aEntry->mIsFrameNavigation;
|
|
|
|
newEntry->mSaveLayoutState = aEntry->mSaveLayoutState;
|
|
|
|
newEntry->mSticky = aEntry->mSticky;
|
|
|
|
newEntry->mDynamicallyCreated = aEntry->mDynamicallyCreated;
|
|
|
|
newEntry->mCacheKey = aEntry->mCacheKey;
|
|
|
|
newEntry->mLastTouched = aEntry->mLastTouched;
|
|
|
|
|
|
|
|
return newEntry.forget();
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
void
|
|
|
|
nsSHEntryShared::RemoveFromExpirationTracker()
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
2017-04-27 13:59:11 +03:00
|
|
|
nsCOMPtr<nsISHistoryInternal> shistory = do_QueryReferent(mSHistory);
|
|
|
|
if (shistory && GetExpirationState()->IsTracked()) {
|
|
|
|
shistory->RemoveFromExpirationTracker(this);
|
2011-10-21 19:26:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSHEntryShared::SyncPresentationState()
|
|
|
|
{
|
|
|
|
if (mContentViewer && mWindowState) {
|
|
|
|
// If we have a content viewer and a window state, we should be ok.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DropPresentationState();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::DropPresentationState()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSHEntryShared> kungFuDeathGrip = this;
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
if (mDocument) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument->SetBFCacheEntry(nullptr);
|
2011-10-21 19:26:34 +04:00
|
|
|
mDocument->RemoveMutationObserver(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr;
|
2011-10-21 19:26:34 +04:00
|
|
|
}
|
|
|
|
if (mContentViewer) {
|
|
|
|
mContentViewer->ClearHistoryEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveFromExpirationTracker();
|
2012-07-30 18:20:58 +04:00
|
|
|
mContentViewer = nullptr;
|
2011-10-21 19:26:34 +04:00
|
|
|
mSticky = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mWindowState = nullptr;
|
2011-10-21 19:26:34 +04:00
|
|
|
mViewerBounds.SetRect(0, 0, 0, 0);
|
|
|
|
mChildShells.Clear();
|
2012-07-30 18:20:58 +04:00
|
|
|
mRefreshURIList = nullptr;
|
|
|
|
mEditorData = nullptr;
|
2011-10-21 19:26:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHEntryShared::SetContentViewer(nsIContentViewer* aViewer)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aViewer || !mContentViewer,
|
|
|
|
"SHEntryShared already contains viewer");
|
|
|
|
|
|
|
|
if (mContentViewer || !aViewer) {
|
|
|
|
DropPresentationState();
|
|
|
|
}
|
|
|
|
|
2017-05-16 05:54:01 +03:00
|
|
|
// If we're setting mContentViewer to null, state should already be cleared
|
|
|
|
// in the DropPresentationState() call above; If we're setting it to a
|
|
|
|
// non-null content viewer, the entry shouldn't have been tracked either.
|
2017-05-22 06:25:54 +03:00
|
|
|
MOZ_ASSERT(!GetExpirationState()->IsTracked());
|
2011-10-21 19:26:34 +04:00
|
|
|
mContentViewer = aViewer;
|
|
|
|
|
|
|
|
if (mContentViewer) {
|
2017-04-27 13:59:11 +03:00
|
|
|
// mSHistory is only set for root entries, but in general bfcache only
|
|
|
|
// applies to root entries as well. BFCache for subframe navigation has been
|
|
|
|
// disabled since 2005 in bug 304860.
|
|
|
|
nsCOMPtr<nsISHistoryInternal> shistory = do_QueryReferent(mSHistory);
|
|
|
|
if (shistory) {
|
|
|
|
shistory->AddToExpirationTracker(this);
|
|
|
|
}
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
mContentViewer->GetDOMDocument(getter_AddRefs(domDoc));
|
|
|
|
// Store observed document in strong pointer in case it is removed from
|
|
|
|
// the contentviewer
|
|
|
|
mDocument = do_QueryInterface(domDoc);
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->SetBFCacheEntry(this);
|
|
|
|
mDocument->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSHEntryShared::RemoveFromBFCacheSync()
|
|
|
|
{
|
2017-03-07 11:58:59 +03:00
|
|
|
MOZ_ASSERT(mContentViewer && mDocument, "we're not in the bfcache!");
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer = mContentViewer;
|
|
|
|
DropPresentationState();
|
|
|
|
|
2017-09-12 20:21:17 +03:00
|
|
|
// Warning! The call to DropPresentationState could have dropped the last
|
|
|
|
// reference to this object, so don't access members beyond here.
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
if (viewer) {
|
|
|
|
viewer->Destroy();
|
|
|
|
}
|
|
|
|
|
2017-08-24 10:17:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-09-07 17:49:39 +03:00
|
|
|
|
2017-09-12 20:21:17 +03:00
|
|
|
class DestroyViewerEvent : public mozilla::Runnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DestroyViewerEvent(nsIContentViewer* aViewer, nsIDocument* aDocument)
|
|
|
|
: mozilla::Runnable("DestroyViewerEvent")
|
|
|
|
, mViewer(aViewer)
|
|
|
|
, mDocument(aDocument)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override
|
|
|
|
{
|
|
|
|
if (mViewer) {
|
|
|
|
mViewer->Destroy();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> mViewer;
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
};
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
nsresult
|
|
|
|
nsSHEntryShared::RemoveFromBFCacheAsync()
|
|
|
|
{
|
2017-03-07 11:58:59 +03:00
|
|
|
MOZ_ASSERT(mContentViewer && mDocument, "we're not in the bfcache!");
|
2011-10-21 19:26:34 +04:00
|
|
|
|
2017-09-12 20:21:17 +03:00
|
|
|
// Release the reference to the contentviewer asynchronously so that the
|
|
|
|
// document doesn't get nuked mid-mutation.
|
|
|
|
|
2017-03-07 11:58:59 +03:00
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2017-09-12 20:21:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> evt = new DestroyViewerEvent(mContentViewer, mDocument);
|
|
|
|
nsresult rv = mDocument->Dispatch(mozilla::TaskCategory::Other, evt.forget());
|
2011-10-21 19:26:34 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2017-09-12 20:21:17 +03:00
|
|
|
NS_WARNING("failed to dispatch DestroyViewerEvent");
|
2011-10-21 19:26:34 +04:00
|
|
|
} else {
|
|
|
|
// Drop presentation. Only do this if we succeeded in posting the event
|
|
|
|
// since otherwise the document could be torn down mid-mutation, causing
|
|
|
|
// crashes.
|
|
|
|
DropPresentationState();
|
|
|
|
}
|
|
|
|
|
2017-09-12 20:21:17 +03:00
|
|
|
// Careful! The call to DropPresentationState could have dropped the last
|
|
|
|
// reference to this nsSHEntryShared, so don't access members beyond here.
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHEntryShared::GetID(uint64_t* aID)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
*aID = mID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::NodeWillBeDestroyed(const nsINode* aNode)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Document destroyed while we're holding a strong ref to it");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::CharacterDataWillChange(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
RemoveFromBFCacheAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::AttributeWillChange(nsIDocument* aDocument,
|
|
|
|
dom::Element* aContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2011-10-21 19:26:34 +04:00
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:05:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
void
|
|
|
|
nsSHEntryShared::NativeAnonymousChildListChange(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
bool aIsRemove)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
void
|
|
|
|
nsSHEntryShared::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
dom::Element* aElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNameSpaceID,
|
2011-10-21 19:26:34 +04:00
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
RemoveFromBFCacheAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t /* unused */)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
RemoveFromBFCacheAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t /* unused */)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
RemoveFromBFCacheAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSHEntryShared::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndexInContainer,
|
2011-10-21 19:26:34 +04:00
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
RemoveFromBFCacheAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHEntryShared::ParentChainChanged(nsIContent* aContent)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
}
|