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: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2005-08-18 15:15:08 +04:00
|
|
|
|
|
|
|
#include "nsSHistory.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2005-08-18 15:15:08 +04:00
|
|
|
|
2005-08-18 15:15:33 +04:00
|
|
|
// Helper Classes
|
2011-06-25 05:55:46 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2015-04-17 16:19:00 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2005-08-18 15:15:08 +04:00
|
|
|
|
2005-08-18 15:15:33 +04:00
|
|
|
// Interfaces Needed
|
|
|
|
#include "nsILayoutHistoryState.h"
|
2005-08-18 15:16:44 +04:00
|
|
|
#include "nsIDocShell.h"
|
2005-08-18 15:15:34 +04:00
|
|
|
#include "nsIDocShellLoadInfo.h"
|
|
|
|
#include "nsISHContainer.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2005-08-18 15:17:00 +04:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2005-09-30 00:24:27 +04:00
|
|
|
#include "nsIObserverService.h"
|
2005-09-23 22:16:40 +04:00
|
|
|
#include "prclist.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
#include "mozilla/Services.h"
|
2010-08-17 18:13:55 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsCOMArray.h"
|
2010-09-05 22:10:35 +04:00
|
|
|
#include "nsDocShell.h"
|
2012-07-11 07:59:52 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-04 19:26:20 +04:00
|
|
|
#include "nsISHEntry.h"
|
|
|
|
#include "nsISHTransaction.h"
|
|
|
|
#include "nsISHistoryListener.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2016-11-29 12:31:17 +03:00
|
|
|
#include "nsNetUtil.h"
|
2005-09-23 22:16:40 +04:00
|
|
|
|
|
|
|
// For calculating max history entries and max cachable contentviewers
|
2013-09-04 19:26:20 +04:00
|
|
|
#include "prsystem.h"
|
2013-02-16 07:55:36 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2005-08-18 15:15:59 +04:00
|
|
|
|
2011-06-25 05:55:46 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
#define PREF_SHISTORY_SIZE "browser.sessionhistory.max_entries"
|
2005-09-23 22:16:40 +04:00
|
|
|
#define PREF_SHISTORY_MAX_TOTAL_VIEWERS "browser.sessionhistory.max_total_viewers"
|
2005-08-18 15:17:00 +04:00
|
|
|
|
2011-06-25 05:55:46 +04:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
PREF_SHISTORY_SIZE,
|
|
|
|
PREF_SHISTORY_MAX_TOTAL_VIEWERS,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2011-06-25 05:55:46 +04:00
|
|
|
};
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
static int32_t gHistoryMaxSize = 50;
|
2005-09-23 22:16:40 +04:00
|
|
|
// Max viewers allowed per SHistory objects
|
2015-05-06 20:57:23 +03:00
|
|
|
static const int32_t gHistoryMaxViewers = 3;
|
2005-09-23 22:16:40 +04:00
|
|
|
// List of all SHistory objects, used for content viewer cache eviction
|
|
|
|
static PRCList gSHistoryList;
|
|
|
|
// Max viewers allowed total, across all SHistory objects - negative default
|
|
|
|
// means we will calculate how many viewers to cache based on total memory
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nsSHistory::sHistoryMaxTotalViewers = -1;
|
2005-08-18 15:15:08 +04:00
|
|
|
|
2011-01-19 22:57:36 +03:00
|
|
|
// A counter that is used to be able to know the order in which
|
|
|
|
// entries were touched, so that we can evict older entries first.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t gTouchCounter = 0;
|
2011-01-19 22:57:36 +03:00
|
|
|
|
2016-01-28 21:35:00 +03:00
|
|
|
static LazyLogModule gSHistoryLog("nsSHistory");
|
|
|
|
|
|
|
|
#define LOG(format) MOZ_LOG(gSHistoryLog, mozilla::LogLevel::Debug, format)
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
// This macro makes it easier to print a log message which includes a URI's
|
|
|
|
// spec. Example use:
|
|
|
|
//
|
|
|
|
// nsIURI *uri = [...];
|
|
|
|
// LOG_SPEC(("The URI is %s.", _spec), uri);
|
|
|
|
//
|
|
|
|
#define LOG_SPEC(format, uri) \
|
|
|
|
PR_BEGIN_MACRO \
|
2016-01-28 21:35:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gSHistoryLog, LogLevel::Debug)) { \
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString _specStr(NS_LITERAL_CSTRING("(null)"));\
|
2011-10-21 19:26:34 +04:00
|
|
|
if (uri) { \
|
2016-08-26 09:02:31 +03:00
|
|
|
_specStr = uri->GetSpecOrDefault(); \
|
2011-10-21 19:26:34 +04:00
|
|
|
} \
|
|
|
|
const char* _spec = _specStr.get(); \
|
|
|
|
LOG(format); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
// This macro makes it easy to log a message including an SHEntry's URI.
|
|
|
|
// For example:
|
|
|
|
//
|
|
|
|
// nsCOMPtr<nsISHEntry> shentry = [...];
|
|
|
|
// LOG_SHENTRY_SPEC(("shentry %p has uri %s.", shentry.get(), _spec), shentry);
|
|
|
|
//
|
|
|
|
#define LOG_SHENTRY_SPEC(format, shentry) \
|
|
|
|
PR_BEGIN_MACRO \
|
2016-01-28 21:35:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gSHistoryLog, LogLevel::Debug)) { \
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsIURI> uri; \
|
|
|
|
shentry->GetURI(getter_AddRefs(uri)); \
|
|
|
|
LOG_SPEC(format, uri); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2012-09-20 18:41:18 +04:00
|
|
|
// Iterates over all registered session history listeners.
|
|
|
|
#define ITERATE_LISTENERS(body) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
{ \
|
|
|
|
nsAutoTObserverArray<nsWeakPtr, 2>::EndLimitedIterator \
|
|
|
|
iter(mListeners); \
|
|
|
|
while (iter.HasMore()) { \
|
|
|
|
nsCOMPtr<nsISHistoryListener> listener = \
|
|
|
|
do_QueryReferent(iter.GetNext()); \
|
|
|
|
if (listener) { \
|
2012-09-21 15:11:25 +04:00
|
|
|
body \
|
2012-09-20 18:41:18 +04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
// Calls a given method on all registered session history listeners.
|
|
|
|
#define NOTIFY_LISTENERS(method, args) \
|
|
|
|
ITERATE_LISTENERS( \
|
|
|
|
listener->method args; \
|
|
|
|
);
|
|
|
|
|
|
|
|
// Calls a given method on all registered session history listeners.
|
|
|
|
// Listeners may return 'false' to cancel an action so make sure that we
|
|
|
|
// set the return value to 'false' if one of the listeners wants to cancel.
|
|
|
|
#define NOTIFY_LISTENERS_CANCELABLE(method, retval, args) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
{ \
|
|
|
|
bool canceled = false; \
|
|
|
|
retval = true; \
|
|
|
|
ITERATE_LISTENERS( \
|
|
|
|
listener->method args; \
|
|
|
|
if (!retval) { \
|
|
|
|
canceled = true; \
|
|
|
|
} \
|
|
|
|
); \
|
|
|
|
if (canceled) { \
|
|
|
|
retval = false; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
enum HistCmd
|
|
|
|
{
|
2005-08-18 15:16:17 +04:00
|
|
|
HIST_CMD_BACK,
|
|
|
|
HIST_CMD_FORWARD,
|
|
|
|
HIST_CMD_GOTOINDEX,
|
|
|
|
HIST_CMD_RELOAD
|
2015-05-06 20:57:23 +03:00
|
|
|
};
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsSHistoryObserver final : public nsIObserver
|
2005-09-23 22:16:40 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2005-09-30 00:24:27 +04:00
|
|
|
nsSHistoryObserver() {}
|
2005-09-23 22:16:40 +04:00
|
|
|
|
|
|
|
protected:
|
2005-09-30 00:24:27 +04:00
|
|
|
~nsSHistoryObserver() {}
|
2005-09-23 22:16:40 +04:00
|
|
|
};
|
|
|
|
|
2015-04-17 16:19:00 +03:00
|
|
|
StaticRefPtr<nsSHistoryObserver> gObserver;
|
2011-06-25 05:55:46 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSHistoryObserver, nsIObserver)
|
2005-09-23 22:16:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistoryObserver::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData)
|
2005-09-23 22:16:40 +04:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
2011-06-25 05:55:46 +04:00
|
|
|
nsSHistory::UpdatePrefs();
|
2011-10-21 19:26:34 +04:00
|
|
|
nsSHistory::GloballyEvictContentViewers();
|
2014-06-05 22:14:07 +04:00
|
|
|
} else if (!strcmp(aTopic, "cacheservice:empty-cache") ||
|
2006-06-23 22:09:24 +04:00
|
|
|
!strcmp(aTopic, "memory-pressure")) {
|
2011-10-21 19:26:34 +04:00
|
|
|
nsSHistory::GloballyEvictAllContentViewers();
|
2005-09-23 22:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
already_AddRefed<nsIContentViewer>
|
2015-05-06 20:57:23 +03:00
|
|
|
GetContentViewerForTransaction(nsISHTransaction* aTrans)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
aTrans->GetSHEntry(getter_AddRefs(entry));
|
|
|
|
if (!entry) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-10-21 19:26:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHEntry> ownerEntry;
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
entry->GetAnyContentViewer(getter_AddRefs(ownerEntry),
|
|
|
|
getter_AddRefs(viewer));
|
|
|
|
return viewer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-06 20:57:23 +03:00
|
|
|
EvictContentViewerForTransaction(nsISHTransaction* aTrans)
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
aTrans->GetSHEntry(getter_AddRefs(entry));
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
nsCOMPtr<nsISHEntry> ownerEntry;
|
|
|
|
entry->GetAnyContentViewer(getter_AddRefs(ownerEntry),
|
|
|
|
getter_AddRefs(viewer));
|
|
|
|
if (viewer) {
|
2015-05-06 20:57:23 +03:00
|
|
|
NS_ASSERTION(ownerEntry, "Content viewer exists but its SHEntry is null");
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
LOG_SHENTRY_SPEC(("Evicting content viewer 0x%p for "
|
|
|
|
"owning SHEntry 0x%p at %s.",
|
2015-05-06 20:57:23 +03:00
|
|
|
viewer.get(), ownerEntry.get(), _spec),
|
|
|
|
ownerEntry);
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
// Drop the presentation state before destroying the viewer, so that
|
|
|
|
// document teardown is able to correctly persist the state.
|
2012-07-30 18:20:58 +04:00
|
|
|
ownerEntry->SetContentViewer(nullptr);
|
2011-10-21 19:26:34 +04:00
|
|
|
ownerEntry->SyncPresentationState();
|
|
|
|
viewer->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2011-10-21 19:26:34 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::nsSHistory()
|
|
|
|
: mIndex(-1)
|
|
|
|
, mLength(0)
|
|
|
|
, mRequestedIndex(-1)
|
2016-10-14 10:18:29 +03:00
|
|
|
, mIsPartial(false)
|
|
|
|
, mGlobalIndexOffset(0)
|
|
|
|
, mEntriesInFollowingPartialHistories(0)
|
2016-01-12 21:16:59 +03:00
|
|
|
, mRootDocShell(nullptr)
|
2005-08-18 15:15:08 +04:00
|
|
|
{
|
2005-09-23 22:16:40 +04:00
|
|
|
// Add this new SHistory object to the list
|
|
|
|
PR_APPEND_LINK(this, &gSHistoryList);
|
2005-08-18 15:15:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSHistory::~nsSHistory()
|
|
|
|
{
|
2005-09-23 22:16:40 +04:00
|
|
|
// Remove this SHistory object from the list
|
|
|
|
PR_REMOVE_LINK(this);
|
2005-08-18 15:15:08 +04:00
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:33 +04:00
|
|
|
NS_IMPL_ADDREF(nsSHistory)
|
|
|
|
NS_IMPL_RELEASE(nsSHistory)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSHistory)
|
2015-05-06 20:57:23 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISHistory)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISHistory)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebNavigation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISHistoryInternal)
|
2005-08-18 15:15:33 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2005-09-23 22:16:40 +04:00
|
|
|
// static
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2005-10-02 00:38:47 +04:00
|
|
|
nsSHistory::CalcMaxTotalViewers()
|
2005-09-23 22:16:40 +04:00
|
|
|
{
|
|
|
|
// Calculate an estimate of how many ContentViewers we should cache based
|
|
|
|
// on RAM. This assumes that the average ContentViewer is 4MB (conservative)
|
|
|
|
// and caps the max at 8 ContentViewers
|
|
|
|
//
|
|
|
|
// TODO: Should we split the cache memory betw. ContentViewer caching and
|
|
|
|
// nsCacheService?
|
|
|
|
//
|
|
|
|
// RAM ContentViewers
|
|
|
|
// -----------------------
|
|
|
|
// 32 Mb 0
|
|
|
|
// 64 Mb 1
|
|
|
|
// 128 Mb 2
|
|
|
|
// 256 Mb 3
|
|
|
|
// 512 Mb 5
|
|
|
|
// 1024 Mb 8
|
|
|
|
// 2048 Mb 8
|
|
|
|
// 4096 Mb 8
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t bytes = PR_GetPhysicalMemorySize();
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (bytes == 0) {
|
2005-09-23 22:16:40 +04:00
|
|
|
return 0;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2012-10-12 03:38:04 +04:00
|
|
|
// Conversion from unsigned int64_t to double doesn't work on all platforms.
|
2012-09-28 23:55:23 +04:00
|
|
|
// We need to truncate the value at INT64_MAX to make sure we don't
|
2005-09-23 22:16:40 +04:00
|
|
|
// overflow.
|
2015-05-06 20:57:23 +03:00
|
|
|
if (bytes > INT64_MAX) {
|
2012-09-28 23:55:23 +04:00
|
|
|
bytes = INT64_MAX;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2013-07-19 00:50:05 +04:00
|
|
|
double kBytesD = (double)(bytes >> 10);
|
2005-09-23 22:16:40 +04:00
|
|
|
|
|
|
|
// This is essentially the same calculation as for nsCacheService,
|
|
|
|
// except that we divide the final memory calculation by 4, since
|
|
|
|
// we assume each ContentViewer takes on average 4MB
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t viewers = 0;
|
2015-05-06 20:57:23 +03:00
|
|
|
double x = std::log(kBytesD) / std::log(2.0) - 14;
|
2005-09-23 22:16:40 +04:00
|
|
|
if (x > 0) {
|
2015-05-06 20:57:23 +03:00
|
|
|
viewers = (uint32_t)(x * x - x + 2.001); // add .001 for rounding
|
|
|
|
viewers /= 4;
|
2005-09-23 22:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cap it off at 8 max
|
|
|
|
if (viewers > 8) {
|
|
|
|
viewers = 8;
|
|
|
|
}
|
|
|
|
return viewers;
|
|
|
|
}
|
|
|
|
|
2010-05-02 08:59:08 +04:00
|
|
|
// static
|
|
|
|
void
|
2011-06-25 05:55:46 +04:00
|
|
|
nsSHistory::UpdatePrefs()
|
2010-05-02 08:59:08 +04:00
|
|
|
{
|
2011-06-25 05:55:46 +04:00
|
|
|
Preferences::GetInt(PREF_SHISTORY_SIZE, &gHistoryMaxSize);
|
|
|
|
Preferences::GetInt(PREF_SHISTORY_MAX_TOTAL_VIEWERS,
|
|
|
|
&sHistoryMaxTotalViewers);
|
2010-05-02 08:59:08 +04:00
|
|
|
// If the pref is negative, that means we calculate how many viewers
|
|
|
|
// we think we should cache, based on total memory
|
|
|
|
if (sHistoryMaxTotalViewers < 0) {
|
|
|
|
sHistoryMaxTotalViewers = CalcMaxTotalViewers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-23 22:16:40 +04:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
nsSHistory::Startup()
|
2005-08-18 15:15:59 +04:00
|
|
|
{
|
2011-06-25 05:55:46 +04:00
|
|
|
UpdatePrefs();
|
|
|
|
|
|
|
|
// The goal of this is to unbreak users who have inadvertently set their
|
|
|
|
// session history size to less than the default value.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t defaultHistoryMaxSize =
|
2011-06-25 05:55:46 +04:00
|
|
|
Preferences::GetDefaultInt(PREF_SHISTORY_SIZE, 50);
|
|
|
|
if (gHistoryMaxSize < defaultHistoryMaxSize) {
|
|
|
|
gHistoryMaxSize = defaultHistoryMaxSize;
|
|
|
|
}
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2011-06-25 05:55:46 +04:00
|
|
|
// Allow the user to override the max total number of cached viewers,
|
|
|
|
// but keep the per SHistory cached viewer limit constant
|
|
|
|
if (!gObserver) {
|
|
|
|
gObserver = new nsSHistoryObserver();
|
|
|
|
Preferences::AddStrongObservers(gObserver, kObservedPrefs);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsSvc) {
|
|
|
|
// Observe empty-cache notifications so tahat clearing the disk/memory
|
|
|
|
// cache will also evict all content viewers.
|
2015-05-06 20:57:23 +03:00
|
|
|
obsSvc->AddObserver(gObserver, "cacheservice:empty-cache", false);
|
2011-06-25 05:55:46 +04:00
|
|
|
|
|
|
|
// Same for memory-pressure notifications
|
2011-10-17 18:59:28 +04:00
|
|
|
obsSvc->AddObserver(gObserver, "memory-pressure", false);
|
2005-09-23 22:16:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the global list of all SHistory objects
|
|
|
|
PR_INIT_CLIST(&gSHistoryList);
|
2005-09-14 11:28:05 +04:00
|
|
|
return NS_OK;
|
2005-09-14 07:38:40 +04:00
|
|
|
}
|
2005-08-18 15:15:59 +04:00
|
|
|
|
2011-06-25 05:55:46 +04:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsSHistory::Shutdown()
|
|
|
|
{
|
|
|
|
if (gObserver) {
|
|
|
|
Preferences::RemoveObservers(gObserver, kObservedPrefs);
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsSvc) {
|
2014-06-05 22:14:07 +04:00
|
|
|
obsSvc->RemoveObserver(gObserver, "cacheservice:empty-cache");
|
2011-06-25 05:55:46 +04:00
|
|
|
obsSvc->RemoveObserver(gObserver, "memory-pressure");
|
|
|
|
}
|
2015-04-17 16:19:00 +03:00
|
|
|
gObserver = nullptr;
|
2011-06-25 05:55:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
/* Add an entry to the History list at mIndex and
|
2005-08-18 15:15:08 +04:00
|
|
|
* increment the index to point to the new entry
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist)
|
2005-08-18 15:15:08 +04:00
|
|
|
{
|
2005-08-18 15:15:59 +04:00
|
|
|
NS_ENSURE_ARG(aSHEntry);
|
2005-08-18 15:15:28 +04:00
|
|
|
|
2016-11-17 00:42:35 +03:00
|
|
|
// If we have a root docshell, update the docshell id of the root shentry to
|
|
|
|
// match the id of that docshell
|
|
|
|
if (mRootDocShell) {
|
|
|
|
nsID docshellID = mRootDocShell->HistoryID();
|
|
|
|
aSHEntry->SetDocshellID(&docshellID);
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> currentTxn;
|
2005-08-18 15:15:28 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mListRoot) {
|
2005-08-18 15:15:59 +04:00
|
|
|
GetTransactionAtIndex(mIndex, getter_AddRefs(currentTxn));
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:28 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool currentPersist = true;
|
2015-05-06 20:57:23 +03:00
|
|
|
if (currentTxn) {
|
2005-08-18 15:15:59 +04:00
|
|
|
currentTxn->GetPersist(¤tPersist);
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:28 +04:00
|
|
|
|
2014-04-24 23:12:15 +04:00
|
|
|
int32_t currentIndex = mIndex;
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!currentPersist) {
|
2014-04-24 23:12:15 +04:00
|
|
|
NOTIFY_LISTENERS(OnHistoryReplaceEntry, (currentIndex));
|
2015-05-06 20:57:23 +03:00
|
|
|
NS_ENSURE_SUCCESS(currentTxn->SetSHEntry(aSHEntry), NS_ERROR_FAILURE);
|
2005-08-18 15:15:59 +04:00
|
|
|
currentTxn->SetPersist(aPersist);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-18 15:15:28 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> txn(
|
|
|
|
do_CreateInstance(NS_SHTRANSACTION_CONTRACTID));
|
2005-08-18 15:15:59 +04:00
|
|
|
NS_ENSURE_TRUE(txn, NS_ERROR_FAILURE);
|
2005-08-18 15:15:28 +04:00
|
|
|
|
2012-09-20 18:41:18 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2013-08-30 08:14:59 +04:00
|
|
|
aSHEntry->GetURI(getter_AddRefs(uri));
|
2016-05-23 13:15:15 +03:00
|
|
|
NOTIFY_LISTENERS(OnHistoryNewEntry, (uri, currentIndex));
|
2013-08-30 08:14:59 +04:00
|
|
|
|
|
|
|
// If a listener has changed mIndex, we need to get currentTxn again,
|
|
|
|
// otherwise we'll be left at an inconsistent state (see bug 320742)
|
|
|
|
if (currentIndex != mIndex) {
|
|
|
|
GetTransactionAtIndex(mIndex, getter_AddRefs(currentTxn));
|
2005-08-18 15:16:00 +04:00
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
// Set the ShEntry and parent for the transaction. setting the
|
2005-08-18 15:15:59 +04:00
|
|
|
// parent will properly set the parent child relationship
|
|
|
|
txn->SetPersist(aPersist);
|
|
|
|
NS_ENSURE_SUCCESS(txn->Create(aSHEntry, currentTxn), NS_ERROR_FAILURE);
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
// A little tricky math here... Basically when adding an object regardless of
|
|
|
|
// what the length was before, it should always be set back to the current and
|
|
|
|
// lop off the forward.
|
|
|
|
mLength = (++mIndex + 1);
|
2016-10-14 10:18:29 +03:00
|
|
|
NOTIFY_LISTENERS(OnLengthChange, (mLength));
|
|
|
|
|
|
|
|
// Much like how mLength works above, when changing our entries, all following
|
|
|
|
// partial histories should be purged, so we just reset the number to zero.
|
|
|
|
mEntriesInFollowingPartialHistories = 0;
|
2005-08-18 15:15:59 +04:00
|
|
|
|
|
|
|
// If this is the very first transaction, initialize the list
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!mListRoot) {
|
2005-08-18 15:15:59 +04:00
|
|
|
mListRoot = txn;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:59 +04:00
|
|
|
|
2006-01-27 23:34:43 +03:00
|
|
|
// Purge History list if it is too long
|
2015-05-06 20:57:23 +03:00
|
|
|
if (gHistoryMaxSize >= 0 && mLength > gHistoryMaxSize) {
|
|
|
|
PurgeHistory(mLength - gHistoryMaxSize);
|
|
|
|
}
|
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
RemoveDynEntries(mIndex - 1, mIndex);
|
2005-08-18 15:15:59 +04:00
|
|
|
return NS_OK;
|
2005-08-18 15:15:08 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetIsPartial(bool* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = mIsPartial;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:18 +04:00
|
|
|
/* Get size of the history list */
|
2005-08-18 15:15:08 +04:00
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetCount(int32_t* aResult)
|
2005-08-18 15:15:08 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = mLength;
|
|
|
|
return NS_OK;
|
2005-08-18 15:15:08 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetGlobalCount(int32_t* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = mGlobalIndexOffset + mLength + mEntriesInFollowingPartialHistories;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetGlobalIndexOffset(int32_t* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = mGlobalIndexOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::OnPartialSessionHistoryActive(int32_t aGlobalLength, int32_t aTargetIndex)
|
|
|
|
{
|
2016-11-29 12:31:17 +03:00
|
|
|
NS_ENSURE_TRUE(mRootDocShell && mIsPartial, NS_ERROR_UNEXPECTED);
|
2016-10-14 10:18:29 +03:00
|
|
|
|
|
|
|
int32_t extraLength = aGlobalLength - mLength - mGlobalIndexOffset;
|
|
|
|
NS_ENSURE_TRUE(extraLength >= 0, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
if (extraLength != mEntriesInFollowingPartialHistories) {
|
|
|
|
mEntriesInFollowingPartialHistories = extraLength;
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
return RestoreToEntryAtIndex(aTargetIndex);
|
2016-10-14 10:18:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::OnPartialSessionHistoryDeactive()
|
|
|
|
{
|
2016-11-29 12:31:17 +03:00
|
|
|
NS_ENSURE_TRUE(mRootDocShell && mIsPartial, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// Ensure the deactive docshell loads about:blank.
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mRootDocShell);
|
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
webNav->GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
if (NS_IsAboutBlank(currentURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(mRootDocShell->CreateAboutBlankContentViewer(nullptr))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-10-14 10:18:29 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:08 +04:00
|
|
|
/* Get index of the history list */
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetIndex(int32_t* aResult)
|
2005-08-18 15:15:08 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_PRECONDITION(aResult, "null out param?");
|
|
|
|
*aResult = mIndex;
|
|
|
|
return NS_OK;
|
2005-08-18 15:15:08 +04:00
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetGlobalIndex(int32_t* aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null out param?");
|
|
|
|
*aResult = mIndex + mGlobalIndexOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-19 20:33:31 +03:00
|
|
|
/* Get the requestedIndex */
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetRequestedIndex(int32_t* aResult)
|
2006-02-19 20:33:31 +03:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_PRECONDITION(aResult, "null out param?");
|
|
|
|
*aResult = mRequestedIndex;
|
|
|
|
return NS_OK;
|
2006-02-19 20:33:31 +03:00
|
|
|
}
|
|
|
|
|
2013-08-30 08:14:59 +04:00
|
|
|
/* Get the entry at a given index */
|
2005-08-18 15:15:14 +04:00
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetEntryAtIndex(int32_t aIndex, bool aModifyIndex,
|
|
|
|
nsISHEntry** aResult)
|
2005-08-18 15:15:14 +04:00
|
|
|
{
|
2005-08-18 15:16:01 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHTransaction> txn;
|
|
|
|
|
|
|
|
/* GetTransactionAtIndex ensures aResult is valid and validates aIndex */
|
|
|
|
rv = GetTransactionAtIndex(aIndex, getter_AddRefs(txn));
|
|
|
|
if (NS_SUCCEEDED(rv) && txn) {
|
2015-05-06 20:57:23 +03:00
|
|
|
// Get the Entry from the transaction
|
2005-08-18 15:16:03 +04:00
|
|
|
rv = txn->GetSHEntry(aResult);
|
2005-08-18 15:16:01 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && (*aResult)) {
|
|
|
|
// Set mIndex to the requested index, if asked to do so..
|
|
|
|
if (aModifyIndex) {
|
|
|
|
mIndex = aIndex;
|
|
|
|
}
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
|
|
|
}
|
2005-08-18 15:16:01 +04:00
|
|
|
return rv;
|
2005-08-18 15:15:14 +04:00
|
|
|
}
|
2005-08-18 15:15:08 +04:00
|
|
|
|
2005-08-18 15:15:14 +04:00
|
|
|
/* Get the transaction at a given index */
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetTransactionAtIndex(int32_t aIndex, nsISHTransaction** aResult)
|
2005-08-18 15:15:14 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
nsresult rv;
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mLength <= 0 || aIndex < 0 || aIndex >= mLength) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!mListRoot) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (aIndex == 0) {
|
2006-04-17 11:50:02 +04:00
|
|
|
*aResult = mListRoot;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
int32_t cnt = 0;
|
|
|
|
nsCOMPtr<nsISHTransaction> tempPtr;
|
2006-04-17 11:50:02 +04:00
|
|
|
rv = GetRootTransaction(getter_AddRefs(tempPtr));
|
2015-05-06 20:57:23 +03:00
|
|
|
if (NS_FAILED(rv) || !tempPtr) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
while (true) {
|
2006-04-17 11:50:02 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> ptr;
|
|
|
|
rv = tempPtr->GetNext(getter_AddRefs(ptr));
|
|
|
|
if (NS_SUCCEEDED(rv) && ptr) {
|
|
|
|
cnt++;
|
|
|
|
if (cnt == aIndex) {
|
2015-04-17 16:19:00 +03:00
|
|
|
ptr.forget(aResult);
|
2006-04-17 11:50:02 +04:00
|
|
|
break;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else {
|
2006-04-17 11:50:02 +04:00
|
|
|
tempPtr = ptr;
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-06 20:57:23 +03:00
|
|
|
} else {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_OK;
|
2005-08-18 15:15:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-24 23:12:15 +04:00
|
|
|
/* Get the index of a given entry */
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetIndexOfEntry(nsISHEntry* aSHEntry, int32_t* aResult)
|
|
|
|
{
|
2014-04-24 23:12:15 +04:00
|
|
|
NS_ENSURE_ARG(aSHEntry);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = -1;
|
|
|
|
|
|
|
|
if (mLength <= 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHTransaction> currentTxn;
|
|
|
|
int32_t cnt = 0;
|
|
|
|
|
|
|
|
nsresult rv = GetRootTransaction(getter_AddRefs(currentTxn));
|
|
|
|
if (NS_FAILED(rv) || !currentTxn) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
rv = currentTxn->GetSHEntry(getter_AddRefs(entry));
|
|
|
|
if (NS_FAILED(rv) || !entry) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSHEntry == entry) {
|
|
|
|
*aResult = cnt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = currentTxn->GetNext(getter_AddRefs(currentTxn));
|
|
|
|
if (NS_FAILED(rv) || !currentTxn) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult
|
2005-08-18 15:15:14 +04:00
|
|
|
nsSHistory::PrintHistory()
|
|
|
|
{
|
2015-05-06 20:57:23 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> txn;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2006-04-17 11:50:02 +04:00
|
|
|
nsresult rv;
|
2005-08-18 15:15:14 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!mListRoot) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:14 +04:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
txn = mListRoot;
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
while (1) {
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!txn) {
|
2006-04-17 11:50:02 +04:00
|
|
|
break;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
2006-04-17 11:50:02 +04:00
|
|
|
rv = txn->GetSHEntry(getter_AddRefs(entry));
|
2015-05-06 20:57:23 +03:00
|
|
|
if (NS_FAILED(rv) && !entry) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> layoutHistoryState;
|
2015-05-06 20:57:23 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2006-04-17 12:37:23 +04:00
|
|
|
nsXPIDLString title;
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
entry->GetLayoutHistoryState(getter_AddRefs(layoutHistoryState));
|
2013-08-30 08:14:59 +04:00
|
|
|
entry->GetURI(getter_AddRefs(uri));
|
|
|
|
entry->GetTitle(getter_Copies(title));
|
2006-04-17 11:50:02 +04:00
|
|
|
|
2005-08-18 15:16:35 +04:00
|
|
|
#if 0
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString url;
|
2015-05-06 20:57:23 +03:00
|
|
|
if (uri) {
|
|
|
|
uri->GetSpec(url);
|
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
|
|
|
|
printf("**** SH Transaction #%d, Entry = %x\n", index, entry.get());
|
2009-09-01 20:45:05 +04:00
|
|
|
printf("\t\t URL = %s\n", url.get());
|
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
printf("\t\t Title = %s\n", NS_LossyConvertUTF16toASCII(title).get());
|
2009-09-01 20:45:05 +04:00
|
|
|
printf("\t\t layout History Data = %x\n", layoutHistoryState.get());
|
2005-08-18 15:16:28 +04:00
|
|
|
#endif
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> next;
|
|
|
|
rv = txn->GetNext(getter_AddRefs(next));
|
|
|
|
if (NS_SUCCEEDED(rv) && next) {
|
|
|
|
txn = next;
|
|
|
|
index++;
|
|
|
|
continue;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else {
|
2006-04-17 11:50:02 +04:00
|
|
|
break;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2006-04-17 11:50:02 +04:00
|
|
|
}
|
2005-08-18 15:15:14 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-18 15:16:52 +04:00
|
|
|
#endif
|
2005-08-18 15:15:14 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetRootTransaction(nsISHTransaction** aResult)
|
2005-08-18 15:15:14 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2015-05-06 20:57:23 +03:00
|
|
|
*aResult = mListRoot;
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
2005-08-18 15:15:14 +04:00
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
/* Get the max size of the history list */
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetMaxLength(int32_t* aResult)
|
2005-08-18 15:15:59 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
*aResult = gHistoryMaxSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the max size of the history list */
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::SetMaxLength(int32_t aMaxSize)
|
2005-08-18 15:15:59 +04:00
|
|
|
{
|
2015-05-06 20:57:23 +03:00
|
|
|
if (aMaxSize < 0) {
|
2005-08-18 15:15:59 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:59 +04:00
|
|
|
|
|
|
|
gHistoryMaxSize = aMaxSize;
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mLength > aMaxSize) {
|
|
|
|
PurgeHistory(mLength - aMaxSize);
|
|
|
|
}
|
2005-08-18 15:15:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::PurgeHistory(int32_t aEntries)
|
2005-08-18 15:15:59 +04:00
|
|
|
{
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mLength <= 0 || aEntries <= 0) {
|
2005-08-18 15:15:59 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:16:51 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
aEntries = std::min(aEntries, mLength);
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool purgeHistory = true;
|
2012-09-20 18:41:18 +04:00
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryPurge, purgeHistory,
|
|
|
|
(aEntries, &purgeHistory));
|
2005-08-18 15:16:00 +04:00
|
|
|
|
|
|
|
if (!purgeHistory) {
|
|
|
|
// Listener asked us not to purge
|
2005-08-18 15:16:59 +04:00
|
|
|
return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;
|
2005-08-18 15:16:00 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t cnt = 0;
|
2005-08-18 15:15:59 +04:00
|
|
|
while (cnt < aEntries) {
|
|
|
|
nsCOMPtr<nsISHTransaction> nextTxn;
|
2010-11-26 13:29:22 +03:00
|
|
|
if (mListRoot) {
|
2005-08-18 15:15:59 +04:00
|
|
|
mListRoot->GetNext(getter_AddRefs(nextTxn));
|
2012-07-30 18:20:58 +04:00
|
|
|
mListRoot->SetNext(nullptr);
|
2010-11-26 13:29:22 +03:00
|
|
|
}
|
2005-08-18 15:15:59 +04:00
|
|
|
mListRoot = nextTxn;
|
2010-11-26 13:29:22 +03:00
|
|
|
if (mListRoot) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListRoot->SetPrev(nullptr);
|
2010-11-26 13:29:22 +03:00
|
|
|
}
|
2015-05-06 20:57:23 +03:00
|
|
|
cnt++;
|
2005-08-18 15:15:59 +04:00
|
|
|
}
|
|
|
|
mLength -= cnt;
|
|
|
|
mIndex -= cnt;
|
2016-10-14 10:18:29 +03:00
|
|
|
NOTIFY_LISTENERS(OnLengthChange, (mLength));
|
|
|
|
|
|
|
|
// All following partial histories will be deleted in this case.
|
|
|
|
mEntriesInFollowingPartialHistories = 0;
|
2005-08-18 15:16:51 +04:00
|
|
|
|
|
|
|
// Now if we were not at the end of the history, mIndex could have
|
|
|
|
// become far too negative. If so, just set it to -1.
|
|
|
|
if (mIndex < -1) {
|
|
|
|
mIndex = -1;
|
|
|
|
}
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mRootDocShell) {
|
2008-09-12 01:54:40 +04:00
|
|
|
mRootDocShell->HistoryPurged(cnt);
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2008-09-12 01:54:40 +04:00
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:00 +04:00
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::AddSHistoryListener(nsISHistoryListener* aListener)
|
2005-08-18 15:16:00 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
|
|
|
|
|
|
|
// Check if the listener supports Weak Reference. This is a must.
|
2015-05-06 20:57:23 +03:00
|
|
|
// This listener functionality is used by embedders and we want to
|
2005-08-18 15:16:00 +04:00
|
|
|
// have the right ownership with who ever listens to SHistory
|
2005-08-18 15:16:50 +04:00
|
|
|
nsWeakPtr listener = do_GetWeakReference(aListener);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!listener) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-09-20 18:41:18 +04:00
|
|
|
|
|
|
|
return mListeners.AppendElementUnlessExists(listener) ?
|
|
|
|
NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2005-08-18 15:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::RemoveSHistoryListener(nsISHistoryListener* aListener)
|
2005-08-18 15:16:00 +04:00
|
|
|
{
|
2005-08-18 15:16:22 +04:00
|
|
|
// Make sure the listener that wants to be removed is the
|
2015-05-06 20:57:23 +03:00
|
|
|
// one we have in store.
|
2012-09-20 18:41:18 +04:00
|
|
|
nsWeakPtr listener = do_GetWeakReference(aListener);
|
|
|
|
mListeners.RemoveElement(listener);
|
|
|
|
return NS_OK;
|
2005-08-18 15:16:00 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::SetPartialSHistoryListener(nsIPartialSHistoryListener* aListener)
|
|
|
|
{
|
|
|
|
mPartialHistoryListener = do_GetWeakReference(aListener);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:24 +04:00
|
|
|
/* Replace an entry in the History list at a particular index.
|
|
|
|
* Do not update index or count.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::ReplaceEntry(int32_t aIndex, nsISHEntry* aReplaceEntry)
|
2005-08-18 15:16:24 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aReplaceEntry);
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISHTransaction> currentTxn;
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!mListRoot) {
|
|
|
|
// Session History is not initialised.
|
2005-08-18 15:16:24 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:16:24 +04:00
|
|
|
|
|
|
|
rv = GetTransactionAtIndex(aIndex, getter_AddRefs(currentTxn));
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
if (currentTxn) {
|
2014-04-24 23:12:15 +04:00
|
|
|
NOTIFY_LISTENERS(OnHistoryReplaceEntry, (aIndex));
|
|
|
|
|
2005-08-18 15:16:24 +04:00
|
|
|
// Set the replacement entry in the transaction
|
|
|
|
rv = currentTxn->SetSHEntry(aReplaceEntry);
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = currentTxn->SetPersist(true);
|
2005-08-18 15:16:24 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:30 +04:00
|
|
|
NS_IMETHODIMP
|
2012-09-20 18:41:18 +04:00
|
|
|
nsSHistory::NotifyOnHistoryReload(nsIURI* aReloadURI, uint32_t aReloadFlags,
|
|
|
|
bool* aCanReload)
|
2005-08-18 15:16:30 +04:00
|
|
|
{
|
2012-09-20 18:41:18 +04:00
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryReload, *aCanReload,
|
|
|
|
(aReloadURI, aReloadFlags, aCanReload));
|
2005-08-18 15:16:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:17:00 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::EvictOutOfRangeContentViewers(int32_t aIndex)
|
2005-08-18 15:17:00 +04:00
|
|
|
{
|
2008-09-12 01:54:40 +04:00
|
|
|
// Check our per SHistory object limit in the currently navigated SHistory
|
2011-10-21 19:26:34 +04:00
|
|
|
EvictOutOfRangeWindowContentViewers(aIndex);
|
2005-09-23 22:16:40 +04:00
|
|
|
// Check our total limit across all SHistory objects
|
2011-10-21 19:26:34 +04:00
|
|
|
GloballyEvictContentViewers();
|
2005-08-18 15:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-13 22:32:30 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::EvictAllContentViewers()
|
|
|
|
{
|
|
|
|
// XXXbz we don't actually do a good job of evicting things as we should, so
|
|
|
|
// we might have viewers quite far from mIndex. So just evict everything.
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> trans = mListRoot;
|
|
|
|
while (trans) {
|
|
|
|
EvictContentViewerForTransaction(trans);
|
|
|
|
|
2016-07-30 02:08:06 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> temp = trans;
|
2011-10-21 19:26:34 +04:00
|
|
|
temp->GetNext(getter_AddRefs(trans));
|
|
|
|
}
|
|
|
|
|
2009-01-13 22:32:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetCanGoBack(bool* aCanGoBack)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanGoBack);
|
2016-10-14 10:18:29 +03:00
|
|
|
|
|
|
|
if (mGlobalIndexOffset) {
|
|
|
|
*aCanGoBack = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = -1;
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_ENSURE_SUCCESS(GetIndex(&index), NS_ERROR_FAILURE);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (index > 0) {
|
|
|
|
*aCanGoBack = true;
|
2016-10-14 10:18:29 +03:00
|
|
|
return NS_OK;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
*aCanGoBack = false;
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_OK;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::GetCanGoForward(bool* aCanGoForward)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aCanGoForward);
|
2016-10-14 10:18:29 +03:00
|
|
|
|
|
|
|
if (mEntriesInFollowingPartialHistories) {
|
|
|
|
*aCanGoForward = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = -1;
|
|
|
|
int32_t count = -1;
|
2006-04-17 11:50:02 +04:00
|
|
|
NS_ENSURE_SUCCESS(GetIndex(&index), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(GetCount(&count), NS_ERROR_FAILURE);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (index >= 0 && index < (count - 1)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanGoForward = true;
|
2016-10-14 10:18:29 +03:00
|
|
|
return NS_OK;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
*aCanGoForward = false;
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_OK;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
2005-08-18 15:15:37 +04:00
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GoBack()
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canGoBack = false;
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
GetCanGoBack(&canGoBack);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!canGoBack) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
|
|
|
return LoadEntry(mIndex - 1, nsIDocShellLoadInfo::loadHistory, HIST_CMD_BACK);
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GoForward()
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canGoForward = false;
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
GetCanGoForward(&canGoForward);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!canGoForward) {
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
|
|
|
return LoadEntry(mIndex + 1, nsIDocShellLoadInfo::loadHistory,
|
|
|
|
HIST_CMD_FORWARD);
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::Reload(uint32_t aReloadFlags)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
nsDocShellInfoLoadType loadType;
|
2015-05-06 20:57:23 +03:00
|
|
|
if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY &&
|
|
|
|
aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE) {
|
2006-04-17 11:50:02 +04:00
|
|
|
loadType = nsIDocShellLoadInfo::loadReloadBypassProxyAndCache;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY) {
|
2006-04-17 11:50:02 +04:00
|
|
|
loadType = nsIDocShellLoadInfo::loadReloadBypassProxy;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE) {
|
2006-04-17 11:50:02 +04:00
|
|
|
loadType = nsIDocShellLoadInfo::loadReloadBypassCache;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE) {
|
2006-04-17 11:50:02 +04:00
|
|
|
loadType = nsIDocShellLoadInfo::loadReloadCharsetChange;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_ALLOW_MIXED_CONTENT) {
|
2013-09-05 21:59:13 +04:00
|
|
|
loadType = nsIDocShellLoadInfo::loadReloadMixedContent;
|
2015-05-06 20:57:23 +03:00
|
|
|
} else {
|
2006-04-17 11:50:02 +04:00
|
|
|
loadType = nsIDocShellLoadInfo::loadReloadNormal;
|
|
|
|
}
|
2013-01-30 12:04:31 +04:00
|
|
|
|
2012-09-20 18:41:18 +04:00
|
|
|
// We are reloading. Send Reload notifications.
|
|
|
|
// nsDocShellLoadFlagType is not public, where as nsIWebNavigation
|
|
|
|
// is public. So send the reload notifications with the
|
|
|
|
// nsIWebNavigation flags.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canNavigate = true;
|
2012-09-20 18:41:18 +04:00
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
2013-02-05 12:39:24 +04:00
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
2012-09-20 18:41:18 +04:00
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryReload, canNavigate,
|
|
|
|
(currentURI, aReloadFlags, &canNavigate));
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!canNavigate) {
|
2005-08-18 15:16:00 +04:00
|
|
|
return NS_OK;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:16:00 +04:00
|
|
|
|
2006-04-17 11:50:02 +04:00
|
|
|
return LoadEntry(mIndex, loadType, HIST_CMD_RELOAD);
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 00:22:46 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::ReloadCurrentEntry()
|
|
|
|
{
|
|
|
|
// Notify listeners
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canNavigate = true;
|
2012-09-20 18:41:18 +04:00
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryGotoIndex, canNavigate,
|
|
|
|
(mIndex, currentURI, &canNavigate));
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!canNavigate) {
|
2010-12-28 00:22:46 +03:00
|
|
|
return NS_OK;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2010-12-28 00:22:46 +03:00
|
|
|
|
|
|
|
return LoadEntry(mIndex, nsIDocShellLoadInfo::loadHistory, HIST_CMD_RELOAD);
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::RestoreToEntryAtIndex(int32_t aIndex)
|
|
|
|
{
|
|
|
|
mRequestedIndex = aIndex;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHEntry> nextEntry;
|
|
|
|
GetEntryAtIndex(mRequestedIndex, false, getter_AddRefs(nextEntry));
|
|
|
|
if (!nextEntry) {
|
|
|
|
mRequestedIndex = -1;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX We may want to ensure docshell is currently holding about:blank
|
|
|
|
return InitiateLoad(nextEntry, mRootDocShell, nsIDocShellLoadInfo::loadHistory);
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:17:00 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::EvictOutOfRangeWindowContentViewers(int32_t aIndex)
|
2005-08-18 15:17:00 +04:00
|
|
|
{
|
2011-10-21 19:26:34 +04:00
|
|
|
// XXX rename method to EvictContentViewersExceptAroundIndex, or something.
|
|
|
|
|
|
|
|
// We need to release all content viewers that are no longer in the range
|
|
|
|
//
|
|
|
|
// aIndex - gHistoryMaxViewers to aIndex + gHistoryMaxViewers
|
|
|
|
//
|
|
|
|
// to ensure that this SHistory object isn't responsible for more than
|
|
|
|
// gHistoryMaxViewers content viewers. But our job is complicated by the
|
|
|
|
// fact that two transactions which are related by either hash navigations or
|
|
|
|
// history.pushState will have the same content viewer.
|
|
|
|
//
|
|
|
|
// To illustrate the issue, suppose gHistoryMaxViewers = 3 and we have four
|
|
|
|
// linked transactions in our history. Suppose we then add a new content
|
|
|
|
// viewer and call into this function. So the history looks like:
|
|
|
|
//
|
|
|
|
// A A A A B
|
|
|
|
// + *
|
|
|
|
//
|
|
|
|
// where the letters are content viewers and + and * denote the beginning and
|
|
|
|
// end of the range aIndex +/- gHistoryMaxViewers.
|
2011-05-13 23:42:36 +04:00
|
|
|
//
|
2011-10-21 19:26:34 +04:00
|
|
|
// Although one copy of the content viewer A exists outside the range, we
|
|
|
|
// don't want to evict A, because it has other copies in range!
|
|
|
|
//
|
|
|
|
// We therefore adjust our eviction strategy to read:
|
|
|
|
//
|
|
|
|
// Evict each content viewer outside the range aIndex -/+
|
|
|
|
// gHistoryMaxViewers, unless that content viewer also appears within the
|
|
|
|
// range.
|
|
|
|
//
|
|
|
|
// (Note that it's entirely legal to have two copies of one content viewer
|
|
|
|
// separated by a different content viewer -- call pushState twice, go back
|
|
|
|
// once, and refresh -- so we can't rely on identical viewers only appearing
|
|
|
|
// adjacent to one another.)
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
if (aIndex < 0) {
|
2005-09-23 22:16:40 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-09-30 23:24:33 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(aIndex < mLength);
|
2005-08-18 15:17:00 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
// Calculate the range that's safe from eviction.
|
2013-01-15 16:22:03 +04:00
|
|
|
int32_t startSafeIndex = std::max(0, aIndex - gHistoryMaxViewers);
|
|
|
|
int32_t endSafeIndex = std::min(mLength, aIndex + gHistoryMaxViewers);
|
2011-10-13 04:15:28 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
LOG(("EvictOutOfRangeWindowContentViewers(index=%d), "
|
|
|
|
"mLength=%d. Safe range [%d, %d]",
|
2015-05-06 20:57:23 +03:00
|
|
|
aIndex, mLength, startSafeIndex, endSafeIndex));
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
// The content viewers in range aIndex -/+ gHistoryMaxViewers will not be
|
|
|
|
// evicted. Collect a set of them so we don't accidentally evict one of them
|
|
|
|
// if it appears outside this range.
|
|
|
|
nsCOMArray<nsIContentViewer> safeViewers;
|
2011-10-13 04:15:28 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> trans;
|
2011-10-21 19:26:34 +04:00
|
|
|
GetTransactionAtIndex(startSafeIndex, getter_AddRefs(trans));
|
2012-12-20 01:12:48 +04:00
|
|
|
for (int32_t i = startSafeIndex; trans && i <= endSafeIndex; i++) {
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> viewer = GetContentViewerForTransaction(trans);
|
|
|
|
safeViewers.AppendObject(viewer);
|
2016-07-30 02:08:06 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> temp = trans;
|
2011-10-21 19:26:34 +04:00
|
|
|
temp->GetNext(getter_AddRefs(trans));
|
|
|
|
}
|
2011-10-13 04:15:28 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
// Walk the SHistory list and evict any content viewers that aren't safe.
|
|
|
|
GetTransactionAtIndex(0, getter_AddRefs(trans));
|
|
|
|
while (trans) {
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer = GetContentViewerForTransaction(trans);
|
|
|
|
if (safeViewers.IndexOf(viewer) == -1) {
|
|
|
|
EvictContentViewerForTransaction(trans);
|
2007-11-17 09:28:56 +03:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:08:06 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> temp = trans;
|
2007-11-17 09:28:56 +03:00
|
|
|
temp->GetNext(getter_AddRefs(trans));
|
|
|
|
}
|
2011-10-13 04:15:28 +04:00
|
|
|
}
|
2011-10-18 05:09:17 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TransactionAndDistance
|
2007-09-21 13:19:59 +04:00
|
|
|
{
|
2011-10-21 19:26:34 +04:00
|
|
|
public:
|
2015-05-06 20:57:23 +03:00
|
|
|
TransactionAndDistance(nsISHTransaction* aTrans, uint32_t aDist)
|
2011-10-21 19:26:34 +04:00
|
|
|
: mTransaction(aTrans)
|
2016-01-12 21:16:59 +03:00
|
|
|
, mLastTouched(0)
|
2011-10-21 19:26:34 +04:00
|
|
|
, mDistance(aDist)
|
|
|
|
{
|
|
|
|
mViewer = GetContentViewerForTransaction(aTrans);
|
|
|
|
NS_ASSERTION(mViewer, "Transaction should have a content viewer");
|
2005-08-18 15:17:00 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsISHEntry> shentry;
|
|
|
|
mTransaction->GetSHEntry(getter_AddRefs(shentry));
|
2005-08-18 15:17:00 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsISHEntryInternal> shentryInternal = do_QueryInterface(shentry);
|
|
|
|
if (shentryInternal) {
|
|
|
|
shentryInternal->GetLastTouched(&mLastTouched);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Can't cast to nsISHEntryInternal?");
|
|
|
|
}
|
|
|
|
}
|
2005-08-18 15:17:00 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
bool operator<(const TransactionAndDistance& aOther) const
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
// Compare distances first, and fall back to last-accessed times.
|
|
|
|
if (aOther.mDistance != this->mDistance) {
|
|
|
|
return this->mDistance < aOther.mDistance;
|
2005-08-18 15:17:00 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
return this->mLastTouched < aOther.mLastTouched;
|
2011-10-18 05:09:17 +04:00
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
bool operator==(const TransactionAndDistance& aOther) const
|
2011-10-21 19:26:34 +04:00
|
|
|
{
|
|
|
|
// This is a little silly; we need == so the default comaprator can be
|
|
|
|
// instantiated, but this function is never actually called when we sort
|
|
|
|
// the list of TransactionAndDistance objects.
|
|
|
|
return aOther.mDistance == this->mDistance &&
|
|
|
|
aOther.mLastTouched == this->mLastTouched;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHTransaction> mTransaction;
|
|
|
|
nsCOMPtr<nsIContentViewer> mViewer;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mLastTouched;
|
|
|
|
int32_t mDistance;
|
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
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
// static
|
2005-09-23 22:16:40 +04:00
|
|
|
void
|
2011-10-21 19:26:34 +04:00
|
|
|
nsSHistory::GloballyEvictContentViewers()
|
2005-09-23 22:16:40 +04:00
|
|
|
{
|
2011-10-21 19:26:34 +04:00
|
|
|
// First, collect from each SHistory object the transactions which have a
|
|
|
|
// cached content viewer. Associate with each transaction its distance from
|
|
|
|
// its SHistory's current index.
|
|
|
|
|
|
|
|
nsTArray<TransactionAndDistance> transactions;
|
|
|
|
|
2014-10-28 00:23:06 +03:00
|
|
|
PRCList* listEntry = PR_LIST_HEAD(&gSHistoryList);
|
|
|
|
while (listEntry != &gSHistoryList) {
|
|
|
|
nsSHistory* shist = static_cast<nsSHistory*>(listEntry);
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
// Maintain a list of the transactions which have viewers and belong to
|
|
|
|
// this particular shist object. We'll add this list to the global list,
|
|
|
|
// |transactions|, eventually.
|
|
|
|
nsTArray<TransactionAndDistance> shTransactions;
|
|
|
|
|
|
|
|
// Content viewers are likely to exist only within shist->mIndex -/+
|
|
|
|
// gHistoryMaxViewers, so only search within that range.
|
|
|
|
//
|
|
|
|
// A content viewer might exist outside that range due to either:
|
|
|
|
//
|
|
|
|
// * history.pushState or hash navigations, in which case a copy of the
|
|
|
|
// content viewer should exist within the range, or
|
|
|
|
//
|
|
|
|
// * bugs which cause us not to call nsSHistory::EvictContentViewers()
|
|
|
|
// often enough. Once we do call EvictContentViewers() for the
|
|
|
|
// SHistory object in question, we'll do a full search of its history
|
|
|
|
// and evict the out-of-range content viewers, so we don't bother here.
|
|
|
|
//
|
2013-01-15 16:22:03 +04:00
|
|
|
int32_t startIndex = std::max(0, shist->mIndex - gHistoryMaxViewers);
|
|
|
|
int32_t endIndex = std::min(shist->mLength - 1,
|
2015-05-06 20:57:23 +03:00
|
|
|
shist->mIndex + gHistoryMaxViewers);
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> trans;
|
|
|
|
shist->GetTransactionAtIndex(startIndex, getter_AddRefs(trans));
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = startIndex; trans && i <= endIndex; i++) {
|
2011-10-21 19:26:34 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer =
|
|
|
|
GetContentViewerForTransaction(trans);
|
|
|
|
|
|
|
|
if (contentViewer) {
|
|
|
|
// Because one content viewer might belong to multiple SHEntries, we
|
|
|
|
// have to search through shTransactions to see if we already know
|
|
|
|
// about this content viewer. If we find the viewer, update its
|
|
|
|
// distance from the SHistory's index and continue.
|
|
|
|
bool found = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = 0; j < shTransactions.Length(); j++) {
|
2015-05-06 20:57:23 +03:00
|
|
|
TransactionAndDistance& container = shTransactions[j];
|
2011-10-21 19:26:34 +04:00
|
|
|
if (container.mViewer == contentViewer) {
|
2015-05-06 20:57:23 +03:00
|
|
|
container.mDistance = std::min(container.mDistance,
|
|
|
|
DeprecatedAbs(i - shist->mIndex));
|
2011-10-21 19:26:34 +04:00
|
|
|
found = true;
|
|
|
|
break;
|
2011-01-19 22:57:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
// If we didn't find a TransactionAndDistance for this content viewer,
|
|
|
|
// make a new one.
|
2011-10-21 19:26:34 +04:00
|
|
|
if (!found) {
|
2015-05-06 20:57:23 +03:00
|
|
|
TransactionAndDistance container(trans,
|
|
|
|
DeprecatedAbs(i - shist->mIndex));
|
2011-10-21 19:26:34 +04:00
|
|
|
shTransactions.AppendElement(container);
|
2011-10-13 04:15:28 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-21 19:26:34 +04:00
|
|
|
|
2016-07-30 02:08:06 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> temp = trans;
|
2011-10-21 19:26:34 +04:00
|
|
|
temp->GetNext(getter_AddRefs(trans));
|
2011-10-13 04:15:28 +04:00
|
|
|
}
|
2011-05-13 23:42:36 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
// We've found all the transactions belonging to shist which have viewers.
|
|
|
|
// Add those transactions to our global list and move on.
|
|
|
|
transactions.AppendElements(shTransactions);
|
2014-10-28 00:23:06 +03:00
|
|
|
listEntry = PR_NEXT_LINK(shist);
|
2011-10-21 19:26:34 +04:00
|
|
|
}
|
2011-05-13 23:42:36 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
// We now have collected all cached content viewers. First check that we
|
|
|
|
// have enough that we actually need to evict some.
|
2012-08-22 19:56:38 +04:00
|
|
|
if ((int32_t)transactions.Length() <= sHistoryMaxTotalViewers) {
|
2011-10-21 19:26:34 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-10-18 05:09:17 +04:00
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
// If we need to evict, sort our list of transactions and evict the largest
|
|
|
|
// ones. (We could of course get better algorithmic complexity here by using
|
|
|
|
// a heap or something more clever. But sHistoryMaxTotalViewers isn't large,
|
|
|
|
// so let's not worry about it.)
|
|
|
|
transactions.Sort();
|
2011-10-18 05:09:17 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
for (int32_t i = transactions.Length() - 1; i >= sHistoryMaxTotalViewers;
|
|
|
|
--i) {
|
2011-10-21 19:26:34 +04:00
|
|
|
EvictContentViewerForTransaction(transactions[i].mTransaction);
|
|
|
|
}
|
2005-09-23 22:16:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
nsresult
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::EvictExpiredContentViewerForEntry(nsIBFCacheEntry* aEntry)
|
2007-09-21 13:19:59 +04:00
|
|
|
{
|
2013-01-15 16:22:03 +04:00
|
|
|
int32_t startIndex = std::max(0, mIndex - gHistoryMaxViewers);
|
2015-05-06 20:57:23 +03:00
|
|
|
int32_t endIndex = std::min(mLength - 1, mIndex + gHistoryMaxViewers);
|
2007-09-21 13:19:59 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> trans;
|
|
|
|
GetTransactionAtIndex(startIndex, getter_AddRefs(trans));
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i;
|
2011-06-22 20:52:41 +04:00
|
|
|
for (i = startIndex; trans && i <= endIndex; ++i) {
|
2007-09-21 13:19:59 +04:00
|
|
|
nsCOMPtr<nsISHEntry> entry;
|
|
|
|
trans->GetSHEntry(getter_AddRefs(entry));
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
// Does entry have the same BFCacheEntry as the argument to this method?
|
|
|
|
if (entry->HasBFCacheEntry(aEntry)) {
|
2007-09-21 13:19:59 +04:00
|
|
|
break;
|
2011-10-21 19:26:34 +04:00
|
|
|
}
|
2007-09-21 13:19:59 +04:00
|
|
|
|
2016-07-30 02:08:06 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> temp = trans;
|
2007-09-21 13:19:59 +04:00
|
|
|
temp->GetNext(getter_AddRefs(trans));
|
|
|
|
}
|
2015-05-06 20:57:23 +03:00
|
|
|
if (i > endIndex) {
|
2007-09-21 13:19:59 +04:00
|
|
|
return NS_OK;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
if (i == mIndex) {
|
|
|
|
NS_WARNING("How did the current SHEntry expire?");
|
2007-09-21 13:19:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-21 19:26:34 +04:00
|
|
|
|
|
|
|
EvictContentViewerForTransaction(trans);
|
|
|
|
|
2007-09-21 13:19:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-30 00:24:27 +04:00
|
|
|
// Evicts all content viewers in all history objects. This is very
|
|
|
|
// inefficient, because it requires a linear search through all SHistory
|
|
|
|
// objects for each viewer to be evicted. However, this method is called
|
|
|
|
// infrequently -- only when the disk or memory cache is cleared.
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
// static
|
2005-09-30 00:24:27 +04:00
|
|
|
void
|
2011-10-21 19:26:34 +04:00
|
|
|
nsSHistory::GloballyEvictAllContentViewers()
|
2005-09-30 00:24:27 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t maxViewers = sHistoryMaxTotalViewers;
|
2005-09-30 00:24:27 +04:00
|
|
|
sHistoryMaxTotalViewers = 0;
|
2011-10-21 19:26:34 +04:00
|
|
|
GloballyEvictContentViewers();
|
2005-09-30 00:24:27 +04:00
|
|
|
sHistoryMaxTotalViewers = maxViewers;
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
void
|
|
|
|
GetDynamicChildren(nsISHContainer* aContainer,
|
2016-11-17 00:42:35 +03:00
|
|
|
nsTArray<nsID>& aDocshellIDs,
|
2015-05-06 20:57:23 +03:00
|
|
|
bool aOnlyTopLevelDynamic)
|
2010-08-17 18:13:55 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2010-08-17 18:13:55 +04:00
|
|
|
aContainer->GetChildCount(&count);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < count; ++i) {
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsISHEntry> child;
|
|
|
|
aContainer->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
if (child) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dynAdded = false;
|
2010-08-17 18:13:55 +04:00
|
|
|
child->IsDynamicallyAdded(&dynAdded);
|
|
|
|
if (dynAdded) {
|
2016-11-17 00:42:35 +03:00
|
|
|
nsID docshellID = child->DocshellID();
|
2010-08-17 18:13:55 +04:00
|
|
|
aDocshellIDs.AppendElement(docshellID);
|
|
|
|
}
|
|
|
|
if (!dynAdded || !aOnlyTopLevelDynamic) {
|
|
|
|
nsCOMPtr<nsISHContainer> childAsContainer = do_QueryInterface(child);
|
|
|
|
if (childAsContainer) {
|
|
|
|
GetDynamicChildren(childAsContainer, aDocshellIDs,
|
|
|
|
aOnlyTopLevelDynamic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-17 18:13:55 +04:00
|
|
|
RemoveFromSessionHistoryContainer(nsISHContainer* aContainer,
|
2016-11-17 00:42:35 +03:00
|
|
|
nsTArray<nsID>& aDocshellIDs)
|
2010-08-17 18:13:55 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISHEntry> root = do_QueryInterface(aContainer);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(root, false);
|
2010-08-17 18:13:55 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool didRemove = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t childCount = 0;
|
2010-08-17 18:13:55 +04:00
|
|
|
aContainer->GetChildCount(&childCount);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = childCount - 1; i >= 0; --i) {
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsISHEntry> child;
|
|
|
|
aContainer->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
if (child) {
|
2016-11-17 00:42:35 +03:00
|
|
|
nsID docshelldID = child->DocshellID();
|
2010-08-17 18:13:55 +04:00
|
|
|
if (aDocshellIDs.Contains(docshelldID)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
didRemove = true;
|
2010-08-17 18:13:55 +04:00
|
|
|
aContainer->RemoveChild(child);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsISHContainer> container = do_QueryInterface(child);
|
|
|
|
if (container) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool childRemoved =
|
2010-08-17 18:13:55 +04:00
|
|
|
RemoveFromSessionHistoryContainer(container, aDocshellIDs);
|
|
|
|
if (childRemoved) {
|
2011-10-17 18:59:28 +04:00
|
|
|
didRemove = true;
|
2010-08-17 18:13:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return didRemove;
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
bool
|
|
|
|
RemoveChildEntries(nsISHistory* aHistory, int32_t aIndex,
|
2016-11-17 00:42:35 +03:00
|
|
|
nsTArray<nsID>& aEntryIDs)
|
2010-08-17 18:13:55 +04:00
|
|
|
{
|
2013-08-30 08:14:59 +04:00
|
|
|
nsCOMPtr<nsISHEntry> rootHE;
|
2011-10-17 18:59:28 +04:00
|
|
|
aHistory->GetEntryAtIndex(aIndex, false, getter_AddRefs(rootHE));
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsISHContainer> root = do_QueryInterface(rootHE);
|
2011-10-17 18:59:28 +04:00
|
|
|
return root ? RemoveFromSessionHistoryContainer(root, aEntryIDs) : false;
|
2010-08-17 18:13:55 +04:00
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
bool
|
|
|
|
IsSameTree(nsISHEntry* aEntry1, nsISHEntry* aEntry2)
|
2010-09-05 22:10:35 +04:00
|
|
|
{
|
|
|
|
if (!aEntry1 && !aEntry2) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
|
|
|
if ((!aEntry1 && aEntry2) || (aEntry1 && !aEntry2)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t id1, id2;
|
2010-09-05 22:10:35 +04:00
|
|
|
aEntry1->GetID(&id1);
|
|
|
|
aEntry2->GetID(&id2);
|
|
|
|
if (id1 != id2) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISHContainer> container1 = do_QueryInterface(aEntry1);
|
|
|
|
nsCOMPtr<nsISHContainer> container2 = do_QueryInterface(aEntry2);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count1, count2;
|
2010-09-05 22:10:35 +04:00
|
|
|
container1->GetChildCount(&count1);
|
|
|
|
container2->GetChildCount(&count2);
|
|
|
|
// We allow null entries in the end of the child list.
|
2013-01-15 16:22:03 +04:00
|
|
|
int32_t count = std::max(count1, count2);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < count; ++i) {
|
2010-09-05 22:10:35 +04:00
|
|
|
nsCOMPtr<nsISHEntry> child1, child2;
|
|
|
|
container1->GetChildAt(i, getter_AddRefs(child1));
|
|
|
|
container2->GetChildAt(i, getter_AddRefs(child2));
|
|
|
|
if (!IsSameTree(child1, child2)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::RemoveDuplicate(int32_t aIndex, bool aKeepNext)
|
2010-09-05 22:10:35 +04:00
|
|
|
{
|
2010-11-15 13:11:51 +03:00
|
|
|
NS_ASSERTION(aIndex >= 0, "aIndex must be >= 0!");
|
2011-08-24 16:48:17 +04:00
|
|
|
NS_ASSERTION(aIndex != 0 || aKeepNext,
|
|
|
|
"If we're removing index 0 we must be keeping the next");
|
2010-11-15 13:11:51 +03:00
|
|
|
NS_ASSERTION(aIndex != mIndex, "Shouldn't remove mIndex!");
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t compareIndex = aKeepNext ? aIndex + 1 : aIndex - 1;
|
2013-08-30 08:14:59 +04:00
|
|
|
nsCOMPtr<nsISHEntry> root1, root2;
|
|
|
|
GetEntryAtIndex(aIndex, false, getter_AddRefs(root1));
|
|
|
|
GetEntryAtIndex(compareIndex, false, getter_AddRefs(root2));
|
2010-09-05 22:10:35 +04:00
|
|
|
if (IsSameTree(root1, root2)) {
|
2010-11-15 13:11:51 +03:00
|
|
|
nsCOMPtr<nsISHTransaction> txToRemove, txToKeep, txNext, txPrev;
|
2010-09-05 22:10:35 +04:00
|
|
|
GetTransactionAtIndex(aIndex, getter_AddRefs(txToRemove));
|
2010-11-15 13:11:51 +03:00
|
|
|
GetTransactionAtIndex(compareIndex, getter_AddRefs(txToKeep));
|
2015-07-15 23:18:57 +03:00
|
|
|
if (!txToRemove) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(txToKeep, false);
|
2010-09-05 22:10:35 +04:00
|
|
|
txToRemove->GetNext(getter_AddRefs(txNext));
|
2010-11-15 13:11:51 +03:00
|
|
|
txToRemove->GetPrev(getter_AddRefs(txPrev));
|
2012-07-30 18:20:58 +04:00
|
|
|
txToRemove->SetNext(nullptr);
|
|
|
|
txToRemove->SetPrev(nullptr);
|
2010-11-15 13:11:51 +03:00
|
|
|
if (aKeepNext) {
|
|
|
|
if (txPrev) {
|
|
|
|
txPrev->SetNext(txToKeep);
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
txToKeep->SetPrev(nullptr);
|
2010-11-15 13:11:51 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
txToKeep->SetNext(txNext);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIndex == 0 && aKeepNext) {
|
|
|
|
NS_ASSERTION(txToRemove == mListRoot,
|
|
|
|
"Transaction at index 0 should be mListRoot!");
|
|
|
|
// We're removing the very first session history transaction!
|
|
|
|
mListRoot = txToKeep;
|
|
|
|
}
|
2010-11-19 15:01:10 +03:00
|
|
|
if (mRootDocShell) {
|
|
|
|
static_cast<nsDocShell*>(mRootDocShell)->HistoryTransactionRemoved(aIndex);
|
|
|
|
}
|
2011-08-24 16:48:17 +04:00
|
|
|
|
|
|
|
// Adjust our indices to reflect the removed transaction
|
2010-11-15 13:11:51 +03:00
|
|
|
if (mIndex > aIndex) {
|
2010-09-05 22:10:35 +04:00
|
|
|
mIndex = mIndex - 1;
|
|
|
|
}
|
2011-08-24 16:48:17 +04:00
|
|
|
|
|
|
|
// NB: If the transaction we are removing is the transaction currently
|
|
|
|
// being navigated to (mRequestedIndex) then we adjust the index
|
|
|
|
// only if we're not keeping the next entry (because if we are keeping
|
|
|
|
// the next entry (because the current is a duplicate of the next), then
|
|
|
|
// that entry slides into the spot that we're currently pointing to.
|
|
|
|
// We don't do this adjustment for mIndex because mIndex cannot equal
|
|
|
|
// aIndex.
|
|
|
|
|
|
|
|
// NB: We don't need to guard on mRequestedIndex being nonzero here,
|
|
|
|
// because either they're strictly greater than aIndex which is at least
|
|
|
|
// zero, or they are equal to aIndex in which case aKeepNext must be true
|
|
|
|
// if aIndex is zero.
|
|
|
|
if (mRequestedIndex > aIndex || (mRequestedIndex == aIndex && !aKeepNext)) {
|
2011-08-02 01:45:45 +04:00
|
|
|
mRequestedIndex = mRequestedIndex - 1;
|
|
|
|
}
|
2010-09-05 22:10:35 +04:00
|
|
|
--mLength;
|
2016-10-14 10:18:29 +03:00
|
|
|
mEntriesInFollowingPartialHistories = 0;
|
|
|
|
NOTIFY_LISTENERS(OnLengthChange, (mLength));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2016-11-17 00:42:35 +03:00
|
|
|
nsSHistory::RemoveEntries(nsTArray<nsID>& aIDs, int32_t aStartIndex)
|
2010-08-17 18:13:55 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = aStartIndex;
|
2015-05-06 20:57:23 +03:00
|
|
|
while (index >= 0 && RemoveChildEntries(this, --index, aIDs)) {
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t minIndex = index;
|
2010-08-17 18:13:55 +04:00
|
|
|
index = aStartIndex;
|
2015-05-06 20:57:23 +03:00
|
|
|
while (index >= 0 && RemoveChildEntries(this, index++, aIDs)) {
|
|
|
|
}
|
|
|
|
|
2010-09-05 22:10:35 +04:00
|
|
|
// We need to remove duplicate nsSHEntry trees.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool didRemove = false;
|
2010-11-15 13:11:51 +03:00
|
|
|
while (index > minIndex) {
|
|
|
|
if (index != mIndex) {
|
|
|
|
didRemove = RemoveDuplicate(index, index < mIndex) || didRemove;
|
|
|
|
}
|
|
|
|
--index;
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
|
|
|
if (didRemove && mRootDocShell) {
|
2016-05-05 11:45:00 +03:00
|
|
|
NS_DispatchToCurrentThread(NewRunnableMethod(static_cast<nsDocShell*>(mRootDocShell),
|
|
|
|
&nsDocShell::FireDummyOnLocationChange));
|
2010-09-05 22:10:35 +04:00
|
|
|
}
|
2010-08-17 18:13:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::RemoveDynEntries(int32_t aOldIndex, int32_t aNewIndex)
|
2010-08-17 18:13:55 +04:00
|
|
|
{
|
|
|
|
// Search for the entries which are in the current index,
|
|
|
|
// but not in the new one.
|
|
|
|
nsCOMPtr<nsISHEntry> originalSH;
|
2011-10-17 18:59:28 +04:00
|
|
|
GetEntryAtIndex(aOldIndex, false, getter_AddRefs(originalSH));
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsISHContainer> originalContainer = do_QueryInterface(originalSH);
|
2016-11-17 00:42:35 +03:00
|
|
|
AutoTArray<nsID, 16> toBeRemovedEntries;
|
2010-08-17 18:13:55 +04:00
|
|
|
if (originalContainer) {
|
2016-11-17 00:42:35 +03:00
|
|
|
nsTArray<nsID> originalDynDocShellIDs;
|
2011-10-17 18:59:28 +04:00
|
|
|
GetDynamicChildren(originalContainer, originalDynDocShellIDs, true);
|
2010-08-17 18:13:55 +04:00
|
|
|
if (originalDynDocShellIDs.Length()) {
|
|
|
|
nsCOMPtr<nsISHEntry> currentSH;
|
2011-10-17 18:59:28 +04:00
|
|
|
GetEntryAtIndex(aNewIndex, false, getter_AddRefs(currentSH));
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsISHContainer> newContainer = do_QueryInterface(currentSH);
|
|
|
|
if (newContainer) {
|
2016-11-17 00:42:35 +03:00
|
|
|
nsTArray<nsID> newDynDocShellIDs;
|
2011-10-17 18:59:28 +04:00
|
|
|
GetDynamicChildren(newContainer, newDynDocShellIDs, false);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < originalDynDocShellIDs.Length(); ++i) {
|
2010-08-17 18:13:55 +04:00
|
|
|
if (!newDynDocShellIDs.Contains(originalDynDocShellIDs[i])) {
|
|
|
|
toBeRemovedEntries.AppendElement(originalDynDocShellIDs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (toBeRemovedEntries.Length()) {
|
|
|
|
RemoveEntries(toBeRemovedEntries, aOldIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::UpdateIndex()
|
|
|
|
{
|
2015-05-06 20:57:23 +03:00
|
|
|
// Update the actual index with the right value.
|
2005-08-18 15:17:00 +04:00
|
|
|
if (mIndex != mRequestedIndex && mRequestedIndex != -1) {
|
2010-08-17 18:13:55 +04:00
|
|
|
RemoveDynEntries(mIndex, mRequestedIndex);
|
2005-08-18 15:16:23 +04:00
|
|
|
mIndex = mRequestedIndex;
|
2005-08-18 15:17:00 +04:00
|
|
|
}
|
|
|
|
|
2008-04-14 05:36:04 +04:00
|
|
|
mRequestedIndex = -1;
|
2005-08-18 15:16:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::Stop(uint32_t aStopFlags)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2015-05-06 20:57:23 +03:00
|
|
|
// Not implemented
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_OK;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetDocument(nsIDOMDocument** aDocument)
|
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
// Not implemented
|
2005-08-18 15:15:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-08-18 15:16:00 +04:00
|
|
|
nsSHistory::GetCurrentURI(nsIURI** aResultURI)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2005-08-18 15:16:00 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aResultURI);
|
2005-08-18 15:16:01 +04:00
|
|
|
nsresult rv;
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2013-08-30 08:14:59 +04:00
|
|
|
nsCOMPtr<nsISHEntry> currentEntry;
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = GetEntryAtIndex(mIndex, false, getter_AddRefs(currentEntry));
|
2015-05-06 20:57:23 +03:00
|
|
|
if (NS_FAILED(rv) && !currentEntry) {
|
|
|
|
return rv;
|
|
|
|
}
|
2005-08-18 15:16:01 +04:00
|
|
|
rv = currentEntry->GetURI(aResultURI);
|
|
|
|
return rv;
|
2005-08-18 15:16:00 +04:00
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2005-08-18 15:16:29 +04:00
|
|
|
NS_IMETHODIMP
|
2005-08-18 15:16:40 +04:00
|
|
|
nsSHistory::GetReferringURI(nsIURI** aURI)
|
2005-08-18 15:16:29 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2006-04-17 11:50:02 +04:00
|
|
|
// Not implemented
|
|
|
|
return NS_OK;
|
2005-08-18 15:16:29 +04:00
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::SetSessionHistory(nsISHistory* aSessionHistory)
|
|
|
|
{
|
2006-04-17 11:50:02 +04:00
|
|
|
// Not implemented
|
|
|
|
return NS_OK;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetSessionHistory(nsISHistory** aSessionHistory)
|
|
|
|
{
|
|
|
|
// Not implemented
|
2006-04-17 11:50:02 +04:00
|
|
|
return NS_OK;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
2014-02-20 17:43:53 +04:00
|
|
|
NS_IMETHODIMP
|
2015-01-05 20:42:31 +03:00
|
|
|
nsSHistory::LoadURIWithOptions(const char16_t* aURI,
|
|
|
|
uint32_t aLoadFlags,
|
|
|
|
nsIURI* aReferringURI,
|
|
|
|
uint32_t aReferrerPolicy,
|
|
|
|
nsIInputStream* aPostStream,
|
|
|
|
nsIInputStream* aExtraHeaderStream,
|
|
|
|
nsIURI* aBaseURI)
|
2014-02-20 17:43:53 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-06-07 20:59:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::SetOriginAttributesBeforeLoading(JS::HandleValue aOriginAttributes)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsSHistory::LoadURI(const char16_t* aURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLoadFlags,
|
2005-08-18 15:16:40 +04:00
|
|
|
nsIURI* aReferringURI,
|
2005-08-18 15:16:29 +04:00
|
|
|
nsIInputStream* aPostStream,
|
|
|
|
nsIInputStream* aExtraHeaderStream)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-10-14 10:18:29 +03:00
|
|
|
nsSHistory::GotoIndex(int32_t aGlobalIndex)
|
2005-08-18 15:15:37 +04:00
|
|
|
{
|
2016-10-14 10:18:29 +03:00
|
|
|
// We provide abstraction of grouped session history for nsIWebNavigation
|
|
|
|
// functions, so the index passed in here is global index.
|
|
|
|
return LoadEntry(aGlobalIndex - mGlobalIndexOffset, nsIDocShellLoadInfo::loadHistory,
|
2015-05-06 20:57:23 +03:00
|
|
|
HIST_CMD_GOTOINDEX);
|
2005-08-18 15:15:37 +04:00
|
|
|
}
|
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
nsresult
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType,
|
|
|
|
uint32_t aHistCmd)
|
2010-08-17 18:13:55 +04:00
|
|
|
{
|
|
|
|
mRequestedIndex = -1;
|
|
|
|
if (aNewIndex < mIndex) {
|
|
|
|
return LoadEntry(aNewIndex - 1, aLoadType, aHistCmd);
|
|
|
|
}
|
|
|
|
if (aNewIndex > mIndex) {
|
|
|
|
return LoadEntry(aNewIndex + 1, aLoadType, aHistCmd);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:37 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSHistory::LoadEntry(int32_t aIndex, long aLoadType, uint32_t aHistCmd)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2016-10-20 12:33:22 +03:00
|
|
|
if (!mRootDocShell) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
nsCOMPtr<nsIURI> nextURI;
|
|
|
|
nsCOMPtr<nsISHEntry> prevEntry;
|
|
|
|
nsCOMPtr<nsISHEntry> nextEntry;
|
|
|
|
bool isCrossBrowserNavigation = false;
|
2016-10-14 10:18:29 +03:00
|
|
|
if (aIndex < 0 || aIndex >= mLength) {
|
|
|
|
if (aIndex + mGlobalIndexOffset < 0) {
|
|
|
|
// The global index is negative.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIndex - mLength >= mEntriesInFollowingPartialHistories) {
|
|
|
|
// The global index exceeds max possible value.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
// The global index is valid. Mark that we're going to navigate to another
|
|
|
|
// partial history, but wait until we've notified all listeners before
|
|
|
|
// actually do so.
|
|
|
|
isCrossBrowserNavigation = true;
|
|
|
|
} else {
|
|
|
|
// This is a normal local history navigation.
|
|
|
|
// Keep note of requested history index in mRequestedIndex.
|
|
|
|
mRequestedIndex = aIndex;
|
|
|
|
|
|
|
|
GetEntryAtIndex(mIndex, false, getter_AddRefs(prevEntry));
|
|
|
|
GetEntryAtIndex(mRequestedIndex, false, getter_AddRefs(nextEntry));
|
|
|
|
if (!nextEntry || !prevEntry) {
|
|
|
|
mRequestedIndex = -1;
|
2016-10-14 10:18:29 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
// Remember that this entry is getting loaded at this point in the sequence
|
|
|
|
nsCOMPtr<nsISHEntryInternal> entryInternal = do_QueryInterface(nextEntry);
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
if (entryInternal) {
|
|
|
|
entryInternal->SetLastTouched(++gTouchCounter);
|
|
|
|
}
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
// Get the uri for the entry we are about to visit
|
|
|
|
nextEntry->GetURI(getter_AddRefs(nextURI));
|
2005-08-18 15:16:07 +04:00
|
|
|
}
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
MOZ_ASSERT(isCrossBrowserNavigation || (prevEntry && nextEntry && nextURI),
|
|
|
|
"prevEntry, nextEntry and nextURI can be null only if isCrossBrowserNavigation is set");
|
2011-01-19 22:57:36 +03:00
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
// Send appropriate listener notifications. Note nextURI could be null in case
|
|
|
|
// of grouped session history navigation.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canNavigate = true;
|
2012-09-20 18:41:18 +04:00
|
|
|
if (aHistCmd == HIST_CMD_BACK) {
|
|
|
|
// We are going back one entry. Send GoBack notifications
|
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryGoBack, canNavigate,
|
|
|
|
(nextURI, &canNavigate));
|
|
|
|
} else if (aHistCmd == HIST_CMD_FORWARD) {
|
|
|
|
// We are going forward. Send GoForward notification
|
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryGoForward, canNavigate,
|
|
|
|
(nextURI, &canNavigate));
|
|
|
|
} else if (aHistCmd == HIST_CMD_GOTOINDEX) {
|
|
|
|
// We are going somewhere else. This is not reload either
|
|
|
|
NOTIFY_LISTENERS_CANCELABLE(OnHistoryGotoIndex, canNavigate,
|
|
|
|
(aIndex, nextURI, &canNavigate));
|
2005-08-18 15:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!canNavigate) {
|
2015-05-06 20:57:23 +03:00
|
|
|
// If the listener asked us not to proceed with
|
|
|
|
// the operation, simply return.
|
2011-07-09 01:30:36 +04:00
|
|
|
mRequestedIndex = -1;
|
2005-08-18 15:16:00 +04:00
|
|
|
return NS_OK; // XXX Maybe I can return some other error code?
|
|
|
|
}
|
|
|
|
|
2016-11-29 12:31:17 +03:00
|
|
|
if (isCrossBrowserNavigation) {
|
|
|
|
nsCOMPtr<nsIPartialSHistoryListener> listener =
|
|
|
|
do_QueryReferent(mPartialHistoryListener);
|
|
|
|
if (!listener) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateAboutBlankContentViewer would check for permit unload, fire proper
|
|
|
|
// pagehide / unload events and transfer content viewer ownership to SHEntry.
|
|
|
|
if (NS_FAILED(mRootDocShell->CreateAboutBlankContentViewer(nullptr))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return listener->OnRequestCrossBrowserNavigation(aIndex +
|
|
|
|
mGlobalIndexOffset);
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:15 +04:00
|
|
|
if (mRequestedIndex == mIndex) {
|
2015-05-06 20:57:23 +03:00
|
|
|
// Possibly a reload case
|
2016-10-20 12:33:22 +03:00
|
|
|
return InitiateLoad(nextEntry, mRootDocShell, aLoadType);
|
2010-08-17 18:13:55 +04:00
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-10-20 12:33:22 +03:00
|
|
|
// Going back or forward.
|
|
|
|
bool differenceFound = false;
|
|
|
|
nsresult rv = LoadDifferingEntries(prevEntry, nextEntry, mRootDocShell,
|
|
|
|
aLoadType, differenceFound);
|
|
|
|
if (!differenceFound) {
|
|
|
|
// We did not find any differences. Go further in the history.
|
|
|
|
return LoadNextPossibleEntry(aIndex, aLoadType, aHistCmd);
|
2005-08-18 15:16:07 +04:00
|
|
|
}
|
2005-08-18 15:16:01 +04:00
|
|
|
|
2016-10-20 12:33:22 +03:00
|
|
|
return rv;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:33 +04:00
|
|
|
nsresult
|
2016-10-20 12:33:22 +03:00
|
|
|
nsSHistory::LoadDifferingEntries(nsISHEntry* aPrevEntry, nsISHEntry* aNextEntry,
|
|
|
|
nsIDocShell* aParent, long aLoadType,
|
|
|
|
bool& aDifferenceFound)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
2015-05-06 20:57:23 +03:00
|
|
|
if (!aPrevEntry || !aNextEntry || !aParent) {
|
2010-08-17 18:13:55 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2010-08-17 18:13:55 +04:00
|
|
|
|
2005-08-18 15:16:33 +04:00
|
|
|
nsresult result = NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t prevID, nextID;
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2005-08-18 15:16:33 +04:00
|
|
|
aPrevEntry->GetID(&prevID);
|
|
|
|
aNextEntry->GetID(&nextID);
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2005-08-18 15:16:33 +04:00
|
|
|
// Check the IDs to verify if the pages are different.
|
|
|
|
if (prevID != nextID) {
|
2016-10-20 12:33:22 +03:00
|
|
|
aDifferenceFound = true;
|
|
|
|
|
|
|
|
// Set the Subframe flag if not navigating the root docshell.
|
|
|
|
aNextEntry->SetIsSubFrame(aParent != mRootDocShell);
|
|
|
|
return InitiateLoad(aNextEntry, aParent, aLoadType);
|
2005-08-18 15:16:33 +04:00
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-10-20 12:33:22 +03:00
|
|
|
// The entries are the same, so compare any child frames
|
2015-05-06 20:57:23 +03:00
|
|
|
int32_t pcnt = 0;
|
|
|
|
int32_t ncnt = 0;
|
|
|
|
int32_t dsCount = 0;
|
|
|
|
nsCOMPtr<nsISHContainer> prevContainer(do_QueryInterface(aPrevEntry));
|
|
|
|
nsCOMPtr<nsISHContainer> nextContainer(do_QueryInterface(aNextEntry));
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2016-10-20 12:33:22 +03:00
|
|
|
if (!prevContainer || !nextContainer) {
|
2005-08-18 15:16:33 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2005-08-18 15:16:02 +04:00
|
|
|
prevContainer->GetChildCount(&pcnt);
|
|
|
|
nextContainer->GetChildCount(&ncnt);
|
2014-01-07 02:34:15 +04:00
|
|
|
aParent->GetChildCount(&dsCount);
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
// Create an array for child docshells.
|
|
|
|
nsCOMArray<nsIDocShell> docshells;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < dsCount; ++i) {
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem;
|
2014-01-07 02:34:15 +04:00
|
|
|
aParent->GetChildAt(i, getter_AddRefs(treeItem));
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(treeItem);
|
|
|
|
if (shell) {
|
2016-06-21 01:38:10 +03:00
|
|
|
docshells.AppendElement(shell.forget());
|
2010-08-17 18:13:55 +04:00
|
|
|
}
|
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
// Search for something to load next.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < ncnt; ++i) {
|
2010-08-17 18:13:55 +04:00
|
|
|
// First get an entry which may cause a new page to be loaded.
|
|
|
|
nsCOMPtr<nsISHEntry> nChild;
|
|
|
|
nextContainer->GetChildAt(i, getter_AddRefs(nChild));
|
|
|
|
if (!nChild) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-17 00:42:35 +03:00
|
|
|
nsID docshellID = nChild->DocshellID();
|
2010-08-17 18:13:55 +04:00
|
|
|
|
|
|
|
// Then find the associated docshell.
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIDocShell* dsChild = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = docshells.Count();
|
|
|
|
for (int32_t j = 0; j < count; ++j) {
|
2010-08-17 18:13:55 +04:00
|
|
|
nsIDocShell* shell = docshells[j];
|
2016-11-17 00:42:35 +03:00
|
|
|
nsID shellID = shell->HistoryID();
|
2010-08-17 18:13:55 +04:00
|
|
|
if (shellID == docshellID) {
|
|
|
|
dsChild = shell;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dsChild) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-08-18 15:15:39 +04:00
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
// Then look at the previous entries to see if there was
|
|
|
|
// an entry for the docshell.
|
|
|
|
nsCOMPtr<nsISHEntry> pChild;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t k = 0; k < pcnt; ++k) {
|
2010-08-17 18:13:55 +04:00
|
|
|
nsCOMPtr<nsISHEntry> child;
|
|
|
|
prevContainer->GetChildAt(k, getter_AddRefs(child));
|
|
|
|
if (child) {
|
2016-11-17 00:42:35 +03:00
|
|
|
nsID dID = child->DocshellID();
|
2010-08-17 18:13:55 +04:00
|
|
|
if (dID == docshellID) {
|
|
|
|
pChild = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-18 15:15:34 +04:00
|
|
|
|
2010-08-17 18:13:55 +04:00
|
|
|
// Finally recursively call this method.
|
|
|
|
// This will either load a new page to shell or some subshell or
|
|
|
|
// do nothing.
|
2016-10-20 12:33:22 +03:00
|
|
|
LoadDifferingEntries(pChild, nChild, dsChild, aLoadType, aDifferenceFound);
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:16:33 +04:00
|
|
|
return result;
|
2005-08-18 15:15:34 +04:00
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
nsresult
|
|
|
|
nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry, nsIDocShell* aFrameDS,
|
|
|
|
long aLoadType)
|
2005-08-18 15:16:33 +04:00
|
|
|
{
|
2010-11-19 15:01:10 +03:00
|
|
|
NS_ENSURE_STATE(aFrameDS && aFrameEntry);
|
|
|
|
|
2005-08-18 15:16:33 +04:00
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
|
|
|
|
|
|
|
/* Set the loadType in the SHEntry too to what was passed on.
|
|
|
|
* This will be passed on to child subframes later in nsDocShell,
|
|
|
|
* so that proper loadType is maintained through out a frameset
|
|
|
|
*/
|
2015-05-06 20:57:23 +03:00
|
|
|
aFrameEntry->SetLoadType(aLoadType);
|
|
|
|
aFrameDS->CreateLoadInfo(getter_AddRefs(loadInfo));
|
2005-08-18 15:16:33 +04:00
|
|
|
|
|
|
|
loadInfo->SetLoadType(aLoadType);
|
|
|
|
loadInfo->SetSHEntry(aFrameEntry);
|
|
|
|
|
2015-09-30 09:54:39 +03:00
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
aFrameEntry->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
loadInfo->SetOriginalURI(originalURI);
|
|
|
|
|
2016-06-28 11:03:25 +03:00
|
|
|
bool loadReplace;
|
|
|
|
aFrameEntry->GetLoadReplace(&loadReplace);
|
|
|
|
loadInfo->SetLoadReplace(loadReplace);
|
|
|
|
|
2005-08-18 15:16:33 +04:00
|
|
|
nsCOMPtr<nsIURI> nextURI;
|
2013-08-30 08:14:59 +04:00
|
|
|
aFrameEntry->GetURI(getter_AddRefs(nextURI));
|
2005-08-18 15:16:33 +04:00
|
|
|
// Time to initiate a document load
|
2015-05-06 20:57:23 +03:00
|
|
|
return aFrameDS->LoadURI(nextURI, loadInfo,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE, false);
|
2005-08-18 15:16:33 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHistory::SetRootDocShell(nsIDocShell* aDocShell)
|
2005-08-18 15:15:34 +04:00
|
|
|
{
|
|
|
|
mRootDocShell = aDocShell;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-18 15:16:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::GetSHistoryEnumerator(nsISimpleEnumerator** aEnumerator)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEnumerator);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSHEnumerator> iterator = new nsSHEnumerator(this);
|
2015-03-12 20:20:29 +03:00
|
|
|
iterator.forget(aEnumerator);
|
|
|
|
return NS_OK;
|
2005-08-18 15:16:01 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHistory::OnAttachGroupedSessionHistory(int32_t aOffset)
|
|
|
|
{
|
2016-11-29 12:31:17 +03:00
|
|
|
NS_ENSURE_TRUE(!mIsPartial && mRootDocShell, NS_ERROR_UNEXPECTED);
|
2016-10-14 10:18:29 +03:00
|
|
|
NS_ENSURE_TRUE(aOffset >= 0, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
|
|
|
mIsPartial = true;
|
|
|
|
mGlobalIndexOffset = aOffset;
|
|
|
|
|
|
|
|
// The last attached history is always at the end of the group.
|
|
|
|
mEntriesInFollowingPartialHistories = 0;
|
|
|
|
|
|
|
|
// Setting grouped history info may change canGoBack / canGoForward.
|
|
|
|
// Send a location change to update these values.
|
|
|
|
NS_DispatchToCurrentThread(NewRunnableMethod(static_cast<nsDocShell*>(mRootDocShell),
|
|
|
|
&nsDocShell::FireDummyOnLocationChange));
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHEnumerator::nsSHEnumerator(nsSHistory* aSHistory) : mIndex(-1)
|
2005-08-18 15:16:01 +04:00
|
|
|
{
|
|
|
|
mSHistory = aSHistory;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSHEnumerator::~nsSHEnumerator()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mSHistory = nullptr;
|
2005-08-18 15:16:01 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSHEnumerator, nsISimpleEnumerator)
|
2005-08-18 15:16:01 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-06 20:57:23 +03:00
|
|
|
nsSHEnumerator::HasMoreElements(bool* aReturn)
|
2005-08-18 15:16:01 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t cnt;
|
2011-10-17 18:59:28 +04:00
|
|
|
*aReturn = false;
|
2005-08-18 15:16:01 +04:00
|
|
|
mSHistory->GetCount(&cnt);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mIndex >= -1 && mIndex < (cnt - 1)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aReturn = true;
|
2005-08-18 15:16:01 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSHEnumerator::GetNext(nsISupports** aItem)
|
2005-08-18 15:16:01 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aItem);
|
2015-05-06 20:57:23 +03:00
|
|
|
int32_t cnt = 0;
|
2005-08-18 15:16:01 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
2005-08-18 15:16:01 +04:00
|
|
|
mSHistory->GetCount(&cnt);
|
2015-05-06 20:57:23 +03:00
|
|
|
if (mIndex < (cnt - 1)) {
|
2005-08-18 15:16:01 +04:00
|
|
|
mIndex++;
|
2013-08-30 08:14:59 +04:00
|
|
|
nsCOMPtr<nsISHEntry> hEntry;
|
2011-10-17 18:59:28 +04:00
|
|
|
result = mSHistory->GetEntryAtIndex(mIndex, false, getter_AddRefs(hEntry));
|
2015-05-06 20:57:23 +03:00
|
|
|
if (hEntry) {
|
2005-08-18 15:16:01 +04:00
|
|
|
result = CallQueryInterface(hEntry, aItem);
|
2015-05-06 20:57:23 +03:00
|
|
|
}
|
2005-08-18 15:16:01 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|