2019-10-25 16:02:08 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_BaseHistory_h
|
|
|
|
#define mozilla_BaseHistory_h
|
|
|
|
|
|
|
|
#include "IHistory.h"
|
2019-10-25 16:02:18 +03:00
|
|
|
#include "mozilla/Result.h"
|
2019-10-25 16:02:08 +03:00
|
|
|
|
|
|
|
/* A base class for history implementations that implement link coloring. */
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class BaseHistory : public IHistory {
|
2019-10-25 16:02:20 +03:00
|
|
|
public:
|
|
|
|
NS_IMETHODIMP RegisterVisitedCallback(nsIURI*, dom::Link*) final;
|
|
|
|
NS_IMETHODIMP UnregisterVisitedCallback(nsIURI*, dom::Link*) final;
|
|
|
|
NS_IMETHODIMP NotifyVisited(nsIURI* aURI) final;
|
|
|
|
|
2019-10-25 16:02:08 +03:00
|
|
|
protected:
|
|
|
|
static constexpr const size_t kTrackedUrisInitialSize = 64;
|
|
|
|
|
2019-10-25 16:02:20 +03:00
|
|
|
BaseHistory() : mTrackedURIs(kTrackedUrisInitialSize) {}
|
2019-10-25 16:02:18 +03:00
|
|
|
|
|
|
|
// Starts a visited query, that eventually could call NotifyVisited if
|
|
|
|
// appropriate.
|
|
|
|
virtual Result<Ok, nsresult> StartVisitedQuery(nsIURI*) = 0;
|
|
|
|
|
|
|
|
// Cancels a visited query, if it is at all possible, because we know we won't
|
|
|
|
// use the results anymore.
|
|
|
|
virtual void CancelVisitedQueryIfPossible(nsIURI*) = 0;
|
2019-10-25 16:02:16 +03:00
|
|
|
|
2019-10-25 16:02:08 +03:00
|
|
|
using ObserverArray = nsTObserverArray<dom::Link*>;
|
|
|
|
struct TrackedURI {
|
|
|
|
ObserverArray mLinks;
|
|
|
|
bool mVisited = false;
|
|
|
|
|
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
return mLinks.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-25 16:02:20 +03:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Mark all links for the given URI in the given document as visited. Used
|
|
|
|
* within NotifyVisited.
|
|
|
|
*/
|
|
|
|
void NotifyVisitedForDocument(nsIURI*, dom::Document*);
|
2019-10-25 16:02:08 +03:00
|
|
|
|
2019-10-25 16:02:20 +03:00
|
|
|
/**
|
|
|
|
* Dispatch a runnable for the document passed in which will call
|
|
|
|
* NotifyVisitedForDocument with the correct URI and Document.
|
|
|
|
*/
|
|
|
|
void DispatchNotifyVisited(nsIURI*, dom::Document*);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsDataHashtable<nsURIHashKey, TrackedURI> mTrackedURIs;
|
2019-10-25 16:02:08 +03:00
|
|
|
};
|
|
|
|
|
2019-10-25 16:02:20 +03:00
|
|
|
} // namespace mozilla
|
2019-10-25 16:02:08 +03:00
|
|
|
|
|
|
|
#endif
|