2013-01-17 16:45:11 -08: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 04:12:37 -07: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/. */
|
2009-08-20 11:56:10 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-12-14 15:58:45 -08:00
|
|
|
|
2010-07-02 08:50:41 -07:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
#include "History.h"
|
|
|
|
#include "nsNavHistory.h"
|
2010-07-13 18:00:33 -07:00
|
|
|
#include "nsNavBookmarks.h"
|
2012-01-20 04:48:20 -08:00
|
|
|
#include "nsAnnotationService.h"
|
2010-04-27 04:24:56 -07:00
|
|
|
#include "Helpers.h"
|
2011-01-14 14:38:34 -08:00
|
|
|
#include "PlaceInfo.h"
|
|
|
|
#include "VisitInfo.h"
|
2012-02-17 22:40:10 -08:00
|
|
|
#include "nsPlacesMacros.h"
|
2009-08-20 11:56:10 -07:00
|
|
|
|
|
|
|
#include "mozilla/storage.h"
|
|
|
|
#include "mozilla/dom/Link.h"
|
|
|
|
#include "nsDocShellCID.h"
|
2010-04-27 04:24:56 -07:00
|
|
|
#include "mozilla/Services.h"
|
2010-11-12 14:24:25 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2010-12-16 00:10:27 -08:00
|
|
|
#include "nsNetUtil.h"
|
2011-01-28 00:07:46 -08:00
|
|
|
#include "nsIXPConnect.h"
|
2011-08-02 12:35:42 -07:00
|
|
|
#include "mozilla/unused.h"
|
2013-08-13 23:56:21 -07:00
|
|
|
#include "nsContentUtils.h" // for nsAutoScriptBlocker
|
2014-07-12 00:43:08 -07:00
|
|
|
#include "nsJSUtils.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2013-01-05 01:21:04 -08:00
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "nsTHashtable.h"
|
2013-08-23 19:42:42 -07:00
|
|
|
#include "jsapi.h"
|
2010-11-12 14:24:25 -08:00
|
|
|
|
|
|
|
// Initial size for the cache holding visited status observers.
|
2014-08-06 06:31:21 -07:00
|
|
|
#define VISIT_OBSERVERS_INITIAL_CACHE_LENGTH 64
|
2009-08-20 11:56:10 -07:00
|
|
|
|
2014-08-06 06:31:21 -07:00
|
|
|
// Initial length for the visits removal hash.
|
|
|
|
#define VISITS_REMOVAL_INITIAL_HASH_LENGTH 64
|
2013-01-05 01:21:04 -08:00
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
using namespace mozilla::dom;
|
2012-08-23 12:33:46 -07:00
|
|
|
using namespace mozilla::ipc;
|
2011-08-02 12:35:42 -07:00
|
|
|
using mozilla::unused;
|
2009-08-20 11:56:10 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
2010-02-24 08:37:02 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Global Defines
|
|
|
|
|
|
|
|
#define URI_VISITED "visited"
|
|
|
|
#define URI_NOT_VISITED "not visited"
|
|
|
|
#define URI_VISITED_RESOLUTION_TOPIC "visited-status-resolution"
|
2010-07-13 18:00:33 -07:00
|
|
|
// Observer event fired after a visit has been registered in the DB.
|
|
|
|
#define URI_VISIT_SAVED "uri-visit-saved"
|
|
|
|
|
2012-01-20 04:48:20 -08:00
|
|
|
#define DESTINATIONFILEURI_ANNO \
|
|
|
|
NS_LITERAL_CSTRING("downloads/destinationFileURI")
|
|
|
|
#define DESTINATIONFILENAME_ANNO \
|
|
|
|
NS_LITERAL_CSTRING("downloads/destinationFileName")
|
|
|
|
|
2011-01-11 10:48:14 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// VisitData
|
|
|
|
|
|
|
|
struct VisitData {
|
|
|
|
VisitData()
|
|
|
|
: placeId(0)
|
|
|
|
, visitId(0)
|
|
|
|
, hidden(true)
|
|
|
|
, typed(false)
|
2012-09-27 23:57:33 -07:00
|
|
|
, transitionType(UINT32_MAX)
|
2011-01-11 10:48:14 -08:00
|
|
|
, visitTime(0)
|
2012-04-06 16:17:49 -07:00
|
|
|
, frecency(-1)
|
2011-01-25 09:01:14 -08:00
|
|
|
, titleChanged(false)
|
2013-07-16 06:36:08 -07:00
|
|
|
, shouldUpdateFrecency(true)
|
2011-01-11 10:48:14 -08:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
guid.SetIsVoid(true);
|
|
|
|
title.SetIsVoid(true);
|
2011-01-11 10:48:14 -08:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:25:36 -07:00
|
|
|
explicit VisitData(nsIURI* aURI,
|
|
|
|
nsIURI* aReferrer = nullptr)
|
2011-01-11 10:48:14 -08:00
|
|
|
: placeId(0)
|
|
|
|
, visitId(0)
|
|
|
|
, hidden(true)
|
|
|
|
, typed(false)
|
2012-09-27 23:57:33 -07:00
|
|
|
, transitionType(UINT32_MAX)
|
2011-01-11 10:48:14 -08:00
|
|
|
, visitTime(0)
|
2012-04-06 16:17:49 -07:00
|
|
|
, frecency(-1)
|
2011-01-25 09:01:14 -08:00
|
|
|
, titleChanged(false)
|
2013-07-16 06:36:08 -07:00
|
|
|
, shouldUpdateFrecency(true)
|
2011-01-11 10:48:14 -08:00
|
|
|
{
|
|
|
|
(void)aURI->GetSpec(spec);
|
|
|
|
(void)GetReversedHostname(aURI, revHost);
|
2011-01-11 11:01:26 -08:00
|
|
|
if (aReferrer) {
|
|
|
|
(void)aReferrer->GetSpec(referrerSpec);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
guid.SetIsVoid(true);
|
|
|
|
title.SetIsVoid(true);
|
2011-01-11 10:48:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-06 16:17:49 -07:00
|
|
|
* Sets the transition type of the visit, as well as if it was typed.
|
2011-01-11 10:48:14 -08:00
|
|
|
*
|
|
|
|
* @param aTransitionType
|
|
|
|
* The transition type constant to set. Must be one of the
|
|
|
|
* TRANSITION_ constants on nsINavHistoryService.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetTransitionType(uint32_t aTransitionType)
|
2011-01-11 10:48:14 -08:00
|
|
|
{
|
|
|
|
typed = aTransitionType == nsINavHistoryService::TRANSITION_TYPED;
|
|
|
|
transitionType = aTransitionType;
|
|
|
|
}
|
|
|
|
|
2011-01-11 11:13:17 -08:00
|
|
|
/**
|
2011-01-12 10:22:55 -08:00
|
|
|
* Determines if this refers to the same url as aOther, and updates aOther
|
|
|
|
* with missing information if so.
|
2011-01-11 11:13:17 -08:00
|
|
|
*
|
|
|
|
* @param aOther
|
|
|
|
* The other place to check against.
|
|
|
|
* @return true if this is a visit for the same place as aOther, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2011-01-12 10:22:55 -08:00
|
|
|
bool IsSamePlaceAs(VisitData& aOther)
|
2011-01-11 11:13:17 -08:00
|
|
|
{
|
2011-01-12 10:22:55 -08:00
|
|
|
if (!spec.Equals(aOther.spec)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aOther.placeId = placeId;
|
|
|
|
aOther.guid = guid;
|
|
|
|
return true;
|
2011-01-11 11:13:17 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t placeId;
|
2011-01-11 11:01:26 -08:00
|
|
|
nsCString guid;
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t visitId;
|
2011-01-11 10:48:14 -08:00
|
|
|
nsCString spec;
|
|
|
|
nsString revHost;
|
|
|
|
bool hidden;
|
|
|
|
bool typed;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t transitionType;
|
2011-01-11 10:48:14 -08:00
|
|
|
PRTime visitTime;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t frecency;
|
2011-01-26 15:56:24 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the title. If this is empty (IsEmpty() returns true), then the
|
|
|
|
* title should be removed from the Place. If the title is void (IsVoid()
|
|
|
|
* returns true), then no title has been set on this object, and titleChanged
|
|
|
|
* should remain false.
|
|
|
|
*/
|
2011-01-11 10:48:53 -08:00
|
|
|
nsString title;
|
2011-01-26 15:56:24 -08:00
|
|
|
|
2011-01-11 11:01:26 -08:00
|
|
|
nsCString referrerSpec;
|
2011-01-25 09:01:14 -08:00
|
|
|
|
|
|
|
// TODO bug 626836 hook up hidden and typed change tracking too!
|
|
|
|
bool titleChanged;
|
2013-07-16 06:36:08 -07:00
|
|
|
|
|
|
|
// Indicates whether frecency should be updated for this visit.
|
|
|
|
bool shouldUpdateFrecency;
|
2011-01-11 10:48:14 -08:00
|
|
|
};
|
|
|
|
|
2013-01-05 01:21:04 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// RemoveVisitsFilter
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to store visit filters for RemoveVisits.
|
|
|
|
*/
|
|
|
|
struct RemoveVisitsFilter {
|
|
|
|
RemoveVisitsFilter()
|
|
|
|
: transitionType(UINT32_MAX)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t transitionType;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// PlaceHashKey
|
|
|
|
|
|
|
|
class PlaceHashKey : public nsCStringHashKey
|
|
|
|
{
|
2014-09-04 15:20:00 -07:00
|
|
|
public:
|
|
|
|
explicit PlaceHashKey(const nsACString& aSpec)
|
2013-01-05 01:21:04 -08:00
|
|
|
: nsCStringHashKey(&aSpec)
|
2014-09-04 15:21:00 -07:00
|
|
|
, mVisitCount(0)
|
|
|
|
, mBookmarked(false)
|
2014-09-04 15:19:00 -07:00
|
|
|
#ifdef DEBUG
|
2014-09-04 15:21:00 -07:00
|
|
|
, mIsInitialized(false)
|
2014-09-04 15:19:00 -07:00
|
|
|
#endif
|
2014-09-04 15:20:00 -07:00
|
|
|
{
|
|
|
|
}
|
2013-01-05 01:21:04 -08:00
|
|
|
|
2014-09-04 15:20:00 -07:00
|
|
|
explicit PlaceHashKey(const nsACString* aSpec)
|
2013-01-05 01:21:04 -08:00
|
|
|
: nsCStringHashKey(aSpec)
|
2014-09-04 15:21:00 -07:00
|
|
|
, mVisitCount(0)
|
|
|
|
, mBookmarked(false)
|
2014-09-04 15:19:00 -07:00
|
|
|
#ifdef DEBUG
|
2014-09-04 15:21:00 -07:00
|
|
|
, mIsInitialized(false)
|
2014-09-04 15:19:00 -07:00
|
|
|
#endif
|
2014-09-04 15:20:00 -07:00
|
|
|
{
|
|
|
|
}
|
2013-01-05 01:21:04 -08:00
|
|
|
|
2014-09-04 15:20:00 -07:00
|
|
|
PlaceHashKey(const PlaceHashKey& aOther)
|
2013-01-05 01:21:04 -08:00
|
|
|
: nsCStringHashKey(&aOther.GetKey())
|
2014-09-04 15:20:00 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(false, "Do not call me!");
|
|
|
|
}
|
2013-01-05 01:21:04 -08:00
|
|
|
|
2014-09-04 15:19:00 -07:00
|
|
|
void SetProperties(uint32_t aVisitCount, bool aBookmarked)
|
|
|
|
{
|
2014-09-04 15:21:00 -07:00
|
|
|
mVisitCount = aVisitCount;
|
|
|
|
mBookmarked = aBookmarked;
|
2014-09-04 15:19:00 -07:00
|
|
|
#ifdef DEBUG
|
2014-09-04 15:21:00 -07:00
|
|
|
mIsInitialized = true;
|
2014-09-04 15:19:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t VisitCount() const
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2014-09-04 15:21:00 -07:00
|
|
|
MOZ_ASSERT(mIsInitialized, "PlaceHashKey::mVisitCount not set");
|
2014-09-04 15:19:00 -07:00
|
|
|
#endif
|
2014-09-04 15:21:00 -07:00
|
|
|
return mVisitCount;
|
2014-09-04 15:19:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsBookmarked() const
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2014-09-04 15:21:00 -07:00
|
|
|
MOZ_ASSERT(mIsInitialized, "PlaceHashKey::mBookmarked not set");
|
2014-09-04 15:19:00 -07:00
|
|
|
#endif
|
2014-09-04 15:21:00 -07:00
|
|
|
return mBookmarked;
|
2014-09-04 15:19:00 -07:00
|
|
|
}
|
|
|
|
|
2014-09-04 15:20:00 -07:00
|
|
|
// Array of VisitData objects.
|
2014-09-04 15:21:00 -07:00
|
|
|
nsTArray<VisitData> mVisits;
|
2014-09-04 15:19:00 -07:00
|
|
|
private:
|
2014-09-04 15:20:00 -07:00
|
|
|
// Visit count for this place.
|
2014-09-04 15:21:00 -07:00
|
|
|
uint32_t mVisitCount;
|
2014-09-04 15:20:00 -07:00
|
|
|
// Whether this place is bookmarked.
|
2014-09-04 15:21:00 -07:00
|
|
|
bool mBookmarked;
|
2014-09-04 15:19:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Whether previous attributes are set.
|
2014-09-04 15:21:00 -07:00
|
|
|
bool mIsInitialized;
|
2014-09-04 15:19:00 -07:00
|
|
|
#endif
|
2013-01-05 01:21:04 -08:00
|
|
|
};
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Anonymous Helpers
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
/**
|
|
|
|
* Convert the given js value to a js array.
|
|
|
|
*
|
|
|
|
* @param [in] aValue
|
|
|
|
* the JS value to convert.
|
|
|
|
* @param [in] aCtx
|
|
|
|
* The JSContext for aValue.
|
|
|
|
* @param [out] _array
|
|
|
|
* the JS array.
|
|
|
|
* @param [out] _arrayLength
|
|
|
|
* _array's length.
|
|
|
|
*/
|
|
|
|
nsresult
|
2014-01-17 10:08:51 -08:00
|
|
|
GetJSArrayFromJSValue(JS::Handle<JS::Value> aValue,
|
2013-06-19 00:18:38 -07:00
|
|
|
JSContext* aCtx,
|
2014-01-17 10:08:51 -08:00
|
|
|
JS::MutableHandle<JSObject*> _array,
|
2013-06-19 00:18:38 -07:00
|
|
|
uint32_t* _arrayLength) {
|
|
|
|
if (aValue.isObjectOrNull()) {
|
|
|
|
JS::Rooted<JSObject*> val(aCtx, aValue.toObjectOrNull());
|
|
|
|
if (JS_IsArrayObject(aCtx, val)) {
|
2014-01-17 10:08:51 -08:00
|
|
|
_array.set(val);
|
|
|
|
(void)JS_GetArrayLength(aCtx, _array, _arrayLength);
|
2013-06-19 00:18:38 -07:00
|
|
|
NS_ENSURE_ARG(*_arrayLength > 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2014-01-17 10:08:51 -08:00
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
// Build a temporary array to store this one item so the code below can
|
|
|
|
// just loop.
|
|
|
|
*_arrayLength = 1;
|
2014-02-12 02:50:46 -08:00
|
|
|
_array.set(JS_NewArrayObject(aCtx, 0));
|
2014-01-17 10:08:51 -08:00
|
|
|
NS_ENSURE_TRUE(_array, NS_ERROR_OUT_OF_MEMORY);
|
2013-06-19 00:18:38 -07:00
|
|
|
|
2014-04-30 02:10:33 -07:00
|
|
|
bool rc = JS_DefineElement(aCtx, _array, 0, aValue, 0);
|
2013-06-19 00:18:38 -07:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attemps to convert a given js value to a nsIURI object.
|
|
|
|
* @param aCtx
|
|
|
|
* The JSContext for aValue.
|
|
|
|
* @param aValue
|
|
|
|
* The JS value to convert.
|
|
|
|
* @return the nsIURI object, or null if aValue is not a nsIURI object.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
GetJSValueAsURI(JSContext* aCtx,
|
|
|
|
const JS::Value& aValue) {
|
2014-04-27 20:27:54 -07:00
|
|
|
if (!aValue.isPrimitive()) {
|
2013-06-19 00:18:38 -07:00
|
|
|
nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXPConnectWrappedNative> wrappedObj;
|
2014-04-27 19:58:52 -07:00
|
|
|
nsresult rv = xpc->GetWrappedNativeOfJSObject(aCtx, aValue.toObjectOrNull(),
|
2013-06-19 00:18:38 -07:00
|
|
|
getter_AddRefs(wrappedObj));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryWrappedNative(wrappedObj);
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-01-21 20:09:10 -08:00
|
|
|
/**
|
|
|
|
* Obtains an nsIURI from the "uri" property of a JSObject.
|
|
|
|
*
|
|
|
|
* @param aCtx
|
|
|
|
* The JSContext for aObject.
|
|
|
|
* @param aObject
|
|
|
|
* The JSObject to get the URI from.
|
|
|
|
* @param aProperty
|
|
|
|
* The name of the property to get the URI from.
|
|
|
|
* @return the URI if it exists.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
GetURIFromJSObject(JSContext* aCtx,
|
2014-01-31 01:55:20 -08:00
|
|
|
JS::Handle<JSObject *> aObject,
|
2011-01-21 20:09:10 -08:00
|
|
|
const char* aProperty)
|
|
|
|
{
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JS::Value> uriVal(aCtx);
|
2013-08-08 15:53:04 -07:00
|
|
|
bool rc = JS_GetProperty(aCtx, aObject, aProperty, &uriVal);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(rc, nullptr);
|
2013-06-19 00:18:38 -07:00
|
|
|
return GetJSValueAsURI(aCtx, uriVal);
|
|
|
|
}
|
2011-01-28 00:07:46 -08:00
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
/**
|
|
|
|
* Attemps to convert a JS value to a string.
|
|
|
|
* @param aCtx
|
|
|
|
* The JSContext for aObject.
|
|
|
|
* @param aValue
|
|
|
|
* The JS value to convert.
|
|
|
|
* @param _string
|
|
|
|
* The string to populate with the value, or set it to void.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
GetJSValueAsString(JSContext* aCtx,
|
|
|
|
const JS::Value& aValue,
|
|
|
|
nsString& _string) {
|
2014-04-27 19:32:05 -07:00
|
|
|
if (aValue.isUndefined() ||
|
2014-04-27 19:41:01 -07:00
|
|
|
!(aValue.isNull() || aValue.isString())) {
|
2013-06-19 00:18:38 -07:00
|
|
|
_string.SetIsVoid(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-01-28 00:07:46 -08:00
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
// |null| in JS maps to the empty string.
|
2014-04-27 19:30:51 -07:00
|
|
|
if (aValue.isNull()) {
|
2013-06-19 00:18:38 -07:00
|
|
|
_string.Truncate();
|
|
|
|
return;
|
2013-06-18 09:24:31 -07:00
|
|
|
}
|
2014-07-12 00:43:08 -07:00
|
|
|
|
|
|
|
if (!AssignJSString(aCtx, _string, aValue.toString())) {
|
2013-06-19 00:18:38 -07:00
|
|
|
_string.SetIsVoid(true);
|
|
|
|
}
|
2011-01-21 20:09:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the specified property of a JSObject.
|
|
|
|
*
|
|
|
|
* @param aCtx
|
|
|
|
* The JSContext for aObject.
|
|
|
|
* @param aObject
|
|
|
|
* The JSObject to get the string from.
|
|
|
|
* @param aProperty
|
|
|
|
* The property to get the value from.
|
|
|
|
* @param _string
|
|
|
|
* The string to populate with the value, or set it to void.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
GetStringFromJSObject(JSContext* aCtx,
|
2014-01-31 01:55:20 -08:00
|
|
|
JS::Handle<JSObject *> aObject,
|
2011-01-21 20:09:10 -08:00
|
|
|
const char* aProperty,
|
|
|
|
nsString& _string)
|
|
|
|
{
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JS::Value> val(aCtx);
|
2013-08-08 15:53:04 -07:00
|
|
|
bool rc = JS_GetProperty(aCtx, aObject, aProperty, &val);
|
2013-06-19 00:18:38 -07:00
|
|
|
if (!rc) {
|
2011-10-17 07:59:28 -07:00
|
|
|
_string.SetIsVoid(true);
|
2011-01-21 20:09:10 -08:00
|
|
|
return;
|
|
|
|
}
|
2013-06-19 00:18:38 -07:00
|
|
|
else {
|
|
|
|
GetJSValueAsString(aCtx, val, _string);
|
2013-06-18 11:46:00 -07:00
|
|
|
}
|
2011-01-21 20:09:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the specified property of a JSObject.
|
|
|
|
*
|
|
|
|
* @param aCtx
|
|
|
|
* The JSContext for aObject.
|
|
|
|
* @param aObject
|
|
|
|
* The JSObject to get the int from.
|
|
|
|
* @param aProperty
|
|
|
|
* The property to get the value from.
|
|
|
|
* @param _int
|
|
|
|
* The integer to populate with the value on success.
|
|
|
|
*/
|
|
|
|
template <typename IntType>
|
|
|
|
nsresult
|
|
|
|
GetIntFromJSObject(JSContext* aCtx,
|
2014-01-31 01:55:20 -08:00
|
|
|
JS::Handle<JSObject *> aObject,
|
2011-01-21 20:09:10 -08:00
|
|
|
const char* aProperty,
|
|
|
|
IntType* _int)
|
|
|
|
{
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JS::Value> value(aCtx);
|
2013-08-08 15:53:04 -07:00
|
|
|
bool rc = JS_GetProperty(aCtx, aObject, aProperty, &value);
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
2014-04-27 19:32:05 -07:00
|
|
|
if (value.isUndefined()) {
|
2011-01-21 20:09:10 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-04-27 20:27:54 -07:00
|
|
|
NS_ENSURE_ARG(value.isPrimitive());
|
2014-04-27 19:48:45 -07:00
|
|
|
NS_ENSURE_ARG(value.isNumber());
|
2011-01-21 20:09:10 -08:00
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double num;
|
2013-10-19 09:39:52 -07:00
|
|
|
rc = JS::ToNumber(aCtx, value, &num);
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
|
|
|
NS_ENSURE_ARG(IntType(num) == num);
|
|
|
|
|
|
|
|
*_int = IntType(num);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the specified property of a JSObject.
|
|
|
|
*
|
|
|
|
* @pre aArray must be an Array object.
|
|
|
|
*
|
|
|
|
* @param aCtx
|
|
|
|
* The JSContext for aArray.
|
|
|
|
* @param aArray
|
|
|
|
* The JSObject to get the object from.
|
|
|
|
* @param aIndex
|
|
|
|
* The index to get the object from.
|
2014-01-29 02:00:40 -08:00
|
|
|
* @param objOut
|
|
|
|
* Set to the JSObject pointer on success.
|
2011-01-21 20:09:10 -08:00
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
GetJSObjectFromArray(JSContext* aCtx,
|
2014-01-29 02:00:40 -08:00
|
|
|
JS::Handle<JSObject*> aArray,
|
2012-03-06 15:52:55 -08:00
|
|
|
uint32_t aIndex,
|
2014-01-29 02:00:40 -08:00
|
|
|
JS::MutableHandle<JSObject*> objOut)
|
2011-01-21 20:09:10 -08:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(JS_IsArrayObject(aCtx, aArray),
|
|
|
|
"Must provide an object that is an array!");
|
|
|
|
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JS::Value> value(aCtx);
|
2013-08-08 15:53:04 -07:00
|
|
|
bool rc = JS_GetElement(aCtx, aArray, aIndex, &value);
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
2014-01-29 02:00:40 -08:00
|
|
|
NS_ENSURE_ARG(!value.isPrimitive());
|
|
|
|
objOut.set(&value.toObject());
|
2011-01-21 20:09:10 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-27 11:52:19 -07:00
|
|
|
class VisitedQuery final : public AsyncStatementCallback,
|
|
|
|
public mozIStorageCompletionCallback
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-12 01:59:11 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2011-11-29 15:48:47 -08:00
|
|
|
static nsresult Start(nsIURI* aURI,
|
2012-07-30 07:20:58 -07:00
|
|
|
mozIVisitedStatusCallback* aCallback=nullptr)
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_PRECONDITION(aURI, "Null URI");
|
2009-08-20 11:56:10 -07:00
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
// If we are a content process, always remote the request to the
|
|
|
|
// parent process.
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(aURI, uri);
|
2012-08-23 12:33:46 -07:00
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
mozilla::dom::ContentChild* cpc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
NS_ASSERTION(cpc, "Content Protocol is NULL!");
|
|
|
|
(void)cpc->SendStartVisitedQuery(uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMainThreadPtrHandle<mozIVisitedStatusCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitedStatusCallback>(aCallback));
|
2010-07-02 08:50:41 -07:00
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_STATE(navHistory);
|
|
|
|
if (navHistory->hasEmbedVisit(aURI)) {
|
2014-09-16 05:17:31 -07:00
|
|
|
nsRefPtr<VisitedQuery> cb = new VisitedQuery(aURI, callback, true);
|
|
|
|
NS_ENSURE_TRUE(cb, NS_ERROR_OUT_OF_MEMORY);
|
2010-11-12 14:24:25 -08:00
|
|
|
// As per IHistory contract, we must notify asynchronously.
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2014-09-16 05:17:31 -07:00
|
|
|
NS_NewRunnableMethod(cb, &VisitedQuery::NotifyVisitedStatus);
|
2010-11-12 14:24:25 -08:00
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-11 13:39:24 -08:00
|
|
|
History* history = History::GetService();
|
|
|
|
NS_ENSURE_STATE(history);
|
2014-09-16 05:17:31 -07:00
|
|
|
nsRefPtr<VisitedQuery> cb = new VisitedQuery(aURI, callback);
|
|
|
|
NS_ENSURE_TRUE(cb, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsresult rv = history->GetIsVisitedStatement(cb);
|
2014-08-12 01:59:11 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-08-20 11:56:10 -07:00
|
|
|
|
2014-08-12 01:59:11 -07:00
|
|
|
// Note: the return value matters here. We call into this method, it's not
|
|
|
|
// just xpcom boilerplate.
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Complete(nsresult aResult, nsISupports* aStatement) override
|
2014-08-12 01:59:11 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(aResult, aResult);
|
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> stmt = do_QueryInterface(aStatement);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
2010-04-27 04:24:56 -07:00
|
|
|
// Bind by index for performance.
|
2014-08-12 01:59:11 -07:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, 0, mURI);
|
2009-08-20 11:56:10 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStoragePendingStatement> handle;
|
2014-08-12 01:59:11 -07:00
|
|
|
return stmt->ExecuteAsync(this, getter_AddRefs(handle));
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD HandleResult(mozIStorageResultSet* aResults) override
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
|
|
|
// If this method is called, we've gotten results, which means we have a
|
|
|
|
// visit.
|
|
|
|
mIsVisited = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD HandleError(mozIStorageError* aError) override
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
|
|
|
// mIsVisited is already set to false, and that's the assumption we will
|
|
|
|
// make if an error occurred.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD HandleCompletion(uint16_t aReason) override
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
2010-08-06 08:42:53 -07:00
|
|
|
if (aReason != mozIStorageStatementCallback::REASON_FINISHED) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
nsresult rv = NotifyVisitedStatus();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NotifyVisitedStatus()
|
|
|
|
{
|
2011-11-29 15:48:47 -08:00
|
|
|
// If an external handling callback is provided, just notify through it.
|
2014-09-16 05:17:31 -07:00
|
|
|
if (!!mCallback) {
|
2011-11-29 15:48:47 -08:00
|
|
|
mCallback->IsVisited(mURI, mIsVisited);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
if (mIsVisited) {
|
2011-11-11 13:39:24 -08:00
|
|
|
History* history = History::GetService();
|
|
|
|
NS_ENSURE_STATE(history);
|
|
|
|
history->NotifyVisited(mURI);
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
2010-02-24 08:37:02 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2010-04-27 04:24:56 -07:00
|
|
|
mozilla::services::GetObserverService();
|
2010-02-24 08:37:02 -08:00
|
|
|
if (observerService) {
|
|
|
|
nsAutoString status;
|
|
|
|
if (mIsVisited) {
|
|
|
|
status.AssignLiteral(URI_VISITED);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
status.AssignLiteral(URI_NOT_VISITED);
|
|
|
|
}
|
|
|
|
(void)observerService->NotifyObservers(mURI,
|
|
|
|
URI_VISITED_RESOLUTION_TOPIC,
|
|
|
|
status.get());
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-12 14:24:25 -08:00
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
private:
|
2014-09-03 15:25:36 -07:00
|
|
|
explicit VisitedQuery(nsIURI* aURI,
|
2014-09-16 05:17:31 -07:00
|
|
|
const nsMainThreadPtrHandle<mozIVisitedStatusCallback>& aCallback,
|
2014-09-03 15:25:36 -07:00
|
|
|
bool aIsVisited=false)
|
2009-08-20 11:56:10 -07:00
|
|
|
: mURI(aURI)
|
2011-11-29 15:48:47 -08:00
|
|
|
, mCallback(aCallback)
|
2010-11-12 14:24:25 -08:00
|
|
|
, mIsVisited(aIsVisited)
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-12 01:59:11 -07:00
|
|
|
~VisitedQuery()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitedStatusCallback> mCallback;
|
2009-08-20 11:56:10 -07:00
|
|
|
bool mIsVisited;
|
|
|
|
};
|
|
|
|
|
2014-08-12 01:59:11 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(
|
|
|
|
VisitedQuery
|
|
|
|
, AsyncStatementCallback
|
|
|
|
, mozIStorageCompletionCallback
|
|
|
|
)
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
/**
|
2010-11-08 11:42:08 -08:00
|
|
|
* Notifies observers about a visit.
|
2010-07-13 18:00:33 -07:00
|
|
|
*/
|
2010-11-08 11:42:08 -08:00
|
|
|
class NotifyVisitObservers : public nsRunnable
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-11-08 11:42:08 -08:00
|
|
|
NotifyVisitObservers(VisitData& aPlace,
|
|
|
|
VisitData& aReferrer)
|
|
|
|
: mPlace(aPlace)
|
|
|
|
, mReferrer(aReferrer)
|
2012-02-01 02:59:27 -08:00
|
|
|
, mHistory(History::GetService())
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_IMETHOD Run()
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
|
2012-02-01 02:59:27 -08:00
|
|
|
// We are in the main thread, no need to lock.
|
|
|
|
if (mHistory->IsShuttingDown()) {
|
|
|
|
// If we are shutting down, we cannot notify the observers.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-12 14:24:25 -08:00
|
|
|
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
if (!navHistory) {
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_WARNING("Trying to notify about a visit but cannot get the history service!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-17 16:15:49 -08:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
(void)NS_NewURI(getter_AddRefs(uri), mPlace.spec);
|
|
|
|
|
2012-12-20 14:45:00 -08:00
|
|
|
// Notify the visit. Note that TRANSITION_EMBED visits are never added
|
|
|
|
// to the database, thus cannot be queried and we don't notify them.
|
|
|
|
if (mPlace.transitionType != nsINavHistoryService::TRANSITION_EMBED) {
|
2010-11-17 16:15:49 -08:00
|
|
|
navHistory->NotifyOnVisit(uri, mPlace.visitId, mPlace.visitTime,
|
2013-03-25 06:44:41 -07:00
|
|
|
mReferrer.visitId, mPlace.transitionType,
|
|
|
|
mPlace.guid, mPlace.hidden);
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
2011-05-09 18:10:25 -07:00
|
|
|
DebugOnly<nsresult> rv =
|
2012-07-30 07:20:58 -07:00
|
|
|
obsService->NotifyObservers(uri, URI_VISIT_SAVED, nullptr);
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Could not notify observers");
|
|
|
|
}
|
|
|
|
|
2011-11-11 13:39:24 -08:00
|
|
|
History* history = History::GetService();
|
|
|
|
NS_ENSURE_STATE(history);
|
2012-03-28 12:50:59 -07:00
|
|
|
history->AppendToRecentlyVisitedURIs(uri);
|
2011-11-11 13:39:24 -08:00
|
|
|
history->NotifyVisited(uri);
|
2010-11-08 11:47:07 -08:00
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-08 11:42:08 -08:00
|
|
|
private:
|
2010-11-08 11:47:07 -08:00
|
|
|
VisitData mPlace;
|
|
|
|
VisitData mReferrer;
|
2012-02-01 02:59:27 -08:00
|
|
|
nsRefPtr<History> mHistory;
|
2010-07-13 18:00:33 -07:00
|
|
|
};
|
|
|
|
|
2011-01-25 09:01:14 -08:00
|
|
|
/**
|
|
|
|
* Notifies observers about a pages title changing.
|
|
|
|
*/
|
|
|
|
class NotifyTitleObservers : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Notifies observers on the main thread.
|
|
|
|
*
|
|
|
|
* @param aSpec
|
|
|
|
* The spec of the URI to notify about.
|
|
|
|
* @param aTitle
|
|
|
|
* The new title to notify about.
|
|
|
|
*/
|
|
|
|
NotifyTitleObservers(const nsCString& aSpec,
|
2011-06-30 13:05:49 -07:00
|
|
|
const nsString& aTitle,
|
|
|
|
const nsCString& aGUID)
|
2011-01-25 09:01:14 -08:00
|
|
|
: mSpec(aSpec)
|
|
|
|
, mTitle(aTitle)
|
2011-06-30 13:05:49 -07:00
|
|
|
, mGUID(aGUID)
|
2011-01-25 09:01:14 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
2011-01-25 09:01:14 -08:00
|
|
|
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(navHistory, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
(void)NS_NewURI(getter_AddRefs(uri), mSpec);
|
2011-06-30 13:05:49 -07:00
|
|
|
navHistory->NotifyTitleChange(uri, mTitle, mGUID);
|
2011-01-25 09:01:14 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
const nsCString mSpec;
|
|
|
|
const nsString mTitle;
|
2011-06-30 13:05:49 -07:00
|
|
|
const nsCString mGUID;
|
2011-01-25 09:01:14 -08:00
|
|
|
};
|
|
|
|
|
2011-01-14 10:42:41 -08:00
|
|
|
/**
|
2013-06-19 00:18:38 -07:00
|
|
|
* Helper class for methods which notify their callers through the
|
|
|
|
* mozIVisitInfoCallback interface.
|
2011-01-14 10:42:41 -08:00
|
|
|
*/
|
2013-06-19 00:18:38 -07:00
|
|
|
class NotifyPlaceInfoCallback : public nsRunnable
|
2011-01-14 10:42:41 -08:00
|
|
|
{
|
|
|
|
public:
|
2014-09-16 05:17:31 -07:00
|
|
|
NotifyPlaceInfoCallback(const nsMainThreadPtrHandle<mozIVisitInfoCallback>& aCallback,
|
2011-08-19 10:08:49 -07:00
|
|
|
const VisitData& aPlace,
|
2013-06-19 00:18:38 -07:00
|
|
|
bool aIsSingleVisit,
|
2011-08-19 10:08:49 -07:00
|
|
|
nsresult aResult)
|
2011-01-14 10:42:41 -08:00
|
|
|
: mCallback(aCallback)
|
|
|
|
, mPlace(aPlace)
|
|
|
|
, mResult(aResult)
|
2013-06-19 00:18:38 -07:00
|
|
|
, mIsSingleVisit(aIsSingleVisit)
|
2011-01-14 10:42:41 -08:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(aCallback, "Must pass a non-null callback!");
|
2011-01-14 10:42:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
2011-01-14 10:42:41 -08:00
|
|
|
|
2011-01-14 14:38:34 -08:00
|
|
|
nsCOMPtr<nsIURI> referrerURI;
|
|
|
|
if (!mPlace.referrerSpec.IsEmpty()) {
|
|
|
|
(void)NS_NewURI(getter_AddRefs(referrerURI), mPlace.referrerSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
(void)NS_NewURI(getter_AddRefs(uri), mPlace.spec);
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
nsCOMPtr<mozIPlaceInfo> place;
|
|
|
|
if (mIsSingleVisit) {
|
|
|
|
nsCOMPtr<mozIVisitInfo> visit =
|
|
|
|
new VisitInfo(mPlace.visitId, mPlace.visitTime, mPlace.transitionType,
|
|
|
|
referrerURI.forget());
|
|
|
|
PlaceInfo::VisitsArray visits;
|
|
|
|
(void)visits.AppendElement(visit);
|
|
|
|
|
|
|
|
// The frecency isn't exposed because it may not reflect the updated value
|
|
|
|
// in the case of InsertVisitedURIs.
|
|
|
|
place =
|
|
|
|
new PlaceInfo(mPlace.placeId, mPlace.guid, uri.forget(), mPlace.title,
|
|
|
|
-1, visits);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Same as above.
|
|
|
|
place =
|
|
|
|
new PlaceInfo(mPlace.placeId, mPlace.guid, uri.forget(), mPlace.title,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
2011-08-04 16:50:17 -07:00
|
|
|
if (NS_SUCCEEDED(mResult)) {
|
|
|
|
(void)mCallback->HandleResult(place);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(void)mCallback->HandleError(mResult, place);
|
|
|
|
}
|
2011-01-14 14:38:34 -08:00
|
|
|
|
2011-01-14 10:42:41 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback> mCallback;
|
2011-01-14 10:42:41 -08:00
|
|
|
VisitData mPlace;
|
|
|
|
const nsresult mResult;
|
2013-06-19 00:18:38 -07:00
|
|
|
bool mIsSingleVisit;
|
2011-01-14 10:42:41 -08:00
|
|
|
};
|
|
|
|
|
2011-08-19 10:11:41 -07:00
|
|
|
/**
|
|
|
|
* Notifies a callback object when the operation is complete.
|
|
|
|
*/
|
|
|
|
class NotifyCompletion : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2014-09-16 05:17:31 -07:00
|
|
|
explicit NotifyCompletion(const nsMainThreadPtrHandle<mozIVisitInfoCallback>& aCallback)
|
2011-08-19 10:11:41 -07:00
|
|
|
: mCallback(aCallback)
|
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(aCallback, "Must pass a non-null callback!");
|
2011-08-19 10:11:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
(void)mCallback->HandleCompletion();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(void)NS_DispatchToMainThread(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback> mCallback;
|
2011-08-19 10:11:41 -07:00
|
|
|
};
|
|
|
|
|
2011-01-24 14:13:24 -08:00
|
|
|
/**
|
|
|
|
* Checks to see if we can add aURI to history, and dispatches an error to
|
|
|
|
* aCallback (if provided) if we cannot.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* The URI to check.
|
|
|
|
* @param [optional] aGUID
|
|
|
|
* The guid of the URI to check. This is passed back to the callback.
|
|
|
|
* @param [optional] aCallback
|
|
|
|
* The callback to notify if the URI cannot be added to history.
|
|
|
|
* @return true if the URI can be added to history, false otherwise.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
CanAddURI(nsIURI* aURI,
|
|
|
|
const nsCString& aGUID = EmptyCString(),
|
2013-10-10 13:38:05 -07:00
|
|
|
mozIVisitInfoCallback* aCallback = nullptr)
|
2011-01-24 14:13:24 -08:00
|
|
|
{
|
2014-09-16 05:17:31 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-01-24 14:13:24 -08:00
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(navHistory, false);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canAdd;
|
2011-01-24 14:13:24 -08:00
|
|
|
nsresult rv = navHistory->CanAddURI(aURI, &canAdd);
|
|
|
|
if (NS_SUCCEEDED(rv) && canAdd) {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// We cannot add the URI. Notify the callback, if we were given one.
|
|
|
|
if (aCallback) {
|
|
|
|
VisitData place(aURI);
|
|
|
|
place.guid = aGUID;
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitInfoCallback>(aCallback));
|
2011-01-24 14:13:24 -08:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2014-09-16 05:17:31 -07:00
|
|
|
new NotifyPlaceInfoCallback(callback, place, true, NS_ERROR_INVALID_ARG);
|
2011-01-24 14:13:24 -08:00
|
|
|
(void)NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
/**
|
2010-11-08 11:42:08 -08:00
|
|
|
* Adds a visit to the database.
|
2010-07-13 18:00:33 -07:00
|
|
|
*/
|
2015-03-21 09:28:04 -07:00
|
|
|
class InsertVisitedURIs final: public nsRunnable
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-11-08 11:42:08 -08:00
|
|
|
/**
|
|
|
|
* Adds a visit to the database asynchronously.
|
|
|
|
*
|
2010-11-08 11:43:46 -08:00
|
|
|
* @param aConnection
|
|
|
|
* The database connection to use for these operations.
|
2011-01-11 11:13:17 -08:00
|
|
|
* @param aPlaces
|
|
|
|
* The locations to record visits.
|
2011-01-14 10:42:41 -08:00
|
|
|
* @param [optional] aCallback
|
|
|
|
* The callback to notify about the visit.
|
2010-11-08 11:42:08 -08:00
|
|
|
*/
|
2010-11-08 11:43:46 -08:00
|
|
|
static nsresult Start(mozIStorageConnection* aConnection,
|
2011-01-14 10:42:41 -08:00
|
|
|
nsTArray<VisitData>& aPlaces,
|
2013-10-10 13:38:05 -07:00
|
|
|
mozIVisitInfoCallback* aCallback = nullptr)
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
MOZ_ASSERT(aPlaces.Length() > 0, "Must pass a non-empty array!");
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2014-08-10 14:26:52 -07:00
|
|
|
// Make sure nsNavHistory service is up before proceeding:
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
MOZ_ASSERT(navHistory, "Could not get nsNavHistory?!");
|
|
|
|
if (!navHistory) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitInfoCallback>(aCallback));
|
2011-01-11 11:13:17 -08:00
|
|
|
nsRefPtr<InsertVisitedURIs> event =
|
2014-09-16 05:17:31 -07:00
|
|
|
new InsertVisitedURIs(aConnection, aPlaces, callback);
|
2010-11-08 11:42:08 -08:00
|
|
|
|
|
|
|
// Get the target thread, and then start the work!
|
2010-11-08 11:43:46 -08:00
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetInterface(aConnection);
|
|
|
|
NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
|
|
|
|
nsresult rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_IMETHOD Run()
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "This should not be called on the main thread");
|
2010-11-08 11:42:08 -08:00
|
|
|
|
2012-02-01 02:59:27 -08:00
|
|
|
// Prevent the main thread from shutting down while this is running.
|
|
|
|
MutexAutoLock lockedScope(mHistory->GetShutdownMutex());
|
2013-01-05 01:21:04 -08:00
|
|
|
if (mHistory->IsShuttingDown()) {
|
2012-02-01 02:59:27 -08:00
|
|
|
// If we were already shutting down, we cannot insert the URIs.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mozStorageTransaction transaction(mDBConn, false,
|
2010-11-16 04:44:05 -08:00
|
|
|
mozIStorageConnection::TRANSACTION_IMMEDIATE);
|
2011-01-11 11:13:17 -08:00
|
|
|
|
2015-01-27 09:36:40 -08:00
|
|
|
VisitData* lastFetchedPlace = nullptr;
|
2011-01-11 11:13:17 -08:00
|
|
|
for (nsTArray<VisitData>::size_type i = 0; i < mPlaces.Length(); i++) {
|
|
|
|
VisitData& place = mPlaces.ElementAt(i);
|
|
|
|
VisitData& referrer = mReferrers.ElementAt(i);
|
|
|
|
|
2015-01-27 09:36:40 -08:00
|
|
|
// Fetching from the database can overwrite this information, so save it
|
|
|
|
// apart.
|
|
|
|
bool typed = place.typed;
|
|
|
|
bool hidden = place.hidden;
|
|
|
|
|
2011-01-11 11:13:17 -08:00
|
|
|
// We can avoid a database lookup if it's the same place as the last
|
|
|
|
// visit we added.
|
2015-01-27 09:36:40 -08:00
|
|
|
bool known = lastFetchedPlace && lastFetchedPlace->IsSamePlaceAs(place);
|
2013-06-19 00:18:38 -07:00
|
|
|
if (!known) {
|
|
|
|
nsresult rv = mHistory->FetchPageInfo(place, &known);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-09-16 05:17:31 -07:00
|
|
|
if (!!mCallback) {
|
2013-06-24 10:59:36 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new NotifyPlaceInfoCallback(mCallback, place, true, rv);
|
|
|
|
return NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2013-06-19 00:18:38 -07:00
|
|
|
}
|
2015-01-27 09:36:40 -08:00
|
|
|
lastFetchedPlace = &mPlaces.ElementAt(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If any transition is typed, ensure the page is marked as typed.
|
|
|
|
if (typed != lastFetchedPlace->typed) {
|
|
|
|
place.typed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If any transition is visible, ensure the page is marked as visible.
|
|
|
|
if (hidden != lastFetchedPlace->hidden) {
|
|
|
|
place.hidden = false;
|
2013-06-19 00:18:38 -07:00
|
|
|
}
|
2011-01-11 11:13:17 -08:00
|
|
|
|
|
|
|
FetchReferrerInfo(referrer, place);
|
|
|
|
|
2011-01-14 10:42:41 -08:00
|
|
|
nsresult rv = DoDatabaseInserts(known, place, referrer);
|
2014-09-16 05:17:31 -07:00
|
|
|
if (!!mCallback) {
|
2011-01-14 10:42:41 -08:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2013-06-19 00:18:38 -07:00
|
|
|
new NotifyPlaceInfoCallback(mCallback, place, true, rv);
|
2011-01-14 10:42:41 -08:00
|
|
|
nsresult rv2 = NS_DispatchToMainThread(event);
|
|
|
|
NS_ENSURE_SUCCESS(rv2, rv2);
|
2011-01-11 11:13:17 -08:00
|
|
|
}
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2011-01-11 11:13:17 -08:00
|
|
|
nsCOMPtr<nsIRunnable> event = new NotifyVisitObservers(place, referrer);
|
|
|
|
rv = NS_DispatchToMainThread(event);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-08 11:42:08 -08:00
|
|
|
|
2011-01-25 09:01:14 -08:00
|
|
|
// Notify about title change if needed.
|
|
|
|
if ((!known && !place.title.IsVoid()) || place.titleChanged) {
|
2011-06-30 13:05:49 -07:00
|
|
|
event = new NotifyTitleObservers(place.spec, place.title, place.guid);
|
2011-01-25 09:01:14 -08:00
|
|
|
rv = NS_DispatchToMainThread(event);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-01-11 11:13:17 -08:00
|
|
|
}
|
2010-11-08 11:42:08 -08:00
|
|
|
|
2011-01-14 10:42:41 -08:00
|
|
|
nsresult rv = transaction.Commit();
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-11-08 11:42:08 -08:00
|
|
|
private:
|
2011-01-11 11:13:17 -08:00
|
|
|
InsertVisitedURIs(mozIStorageConnection* aConnection,
|
2011-01-14 10:42:41 -08:00
|
|
|
nsTArray<VisitData>& aPlaces,
|
2014-09-16 05:17:31 -07:00
|
|
|
const nsMainThreadPtrHandle<mozIVisitInfoCallback>& aCallback)
|
2010-11-08 11:43:46 -08:00
|
|
|
: mDBConn(aConnection)
|
2011-01-14 10:42:41 -08:00
|
|
|
, mCallback(aCallback)
|
2010-11-08 11:43:46 -08:00
|
|
|
, mHistory(History::GetService())
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
2011-01-11 11:13:17 -08:00
|
|
|
|
|
|
|
(void)mPlaces.SwapElements(aPlaces);
|
|
|
|
(void)mReferrers.SetLength(mPlaces.Length());
|
|
|
|
|
|
|
|
for (nsTArray<VisitData>::size_type i = 0; i < mPlaces.Length(); i++) {
|
|
|
|
mReferrers[i].spec = mPlaces[i].referrerSpec;
|
|
|
|
|
2011-01-24 14:13:24 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
(void)NS_NewURI(getter_AddRefs(uri), mPlaces[i].spec);
|
|
|
|
NS_ASSERTION(CanAddURI(uri),
|
|
|
|
"Passed a VisitData with a URI we cannot add to history!");
|
|
|
|
#endif
|
2011-01-11 11:13:17 -08:00
|
|
|
}
|
2011-01-14 10:42:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts or updates the entry in moz_places for this visit, adds the visit,
|
|
|
|
* and updates the frecency of the place.
|
|
|
|
*
|
|
|
|
* @param aKnown
|
|
|
|
* True if we already have an entry for this place in moz_places, false
|
|
|
|
* otherwise.
|
|
|
|
* @param aPlace
|
|
|
|
* The place we are adding a visit for.
|
|
|
|
* @param aReferrer
|
|
|
|
* The referrer for aPlace.
|
|
|
|
*/
|
|
|
|
nsresult DoDatabaseInserts(bool aKnown,
|
|
|
|
VisitData& aPlace,
|
|
|
|
VisitData& aReferrer)
|
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "This should not be called on the main thread");
|
2011-01-14 10:42:41 -08:00
|
|
|
|
|
|
|
// If the page was in moz_places, we need to update the entry.
|
|
|
|
nsresult rv;
|
|
|
|
if (aKnown) {
|
|
|
|
rv = mHistory->UpdatePlace(aPlace);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
// Otherwise, the page was not in moz_places, so now we have to add it.
|
|
|
|
else {
|
|
|
|
rv = mHistory->InsertPlace(aPlace);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-20 06:35:40 -08:00
|
|
|
|
|
|
|
// We need the place id and guid of the page we just inserted when we
|
2011-06-08 08:10:29 -07:00
|
|
|
// have a callback or when the GUID isn't known. No point in doing the
|
|
|
|
// disk I/O if we do not need it.
|
2014-09-16 05:17:31 -07:00
|
|
|
if (!!mCallback || aPlace.guid.IsEmpty()) {
|
2013-06-19 00:18:38 -07:00
|
|
|
bool exists;
|
|
|
|
rv = mHistory->FetchPageInfo(aPlace, &exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-01-20 06:35:40 -08:00
|
|
|
if (!exists) {
|
|
|
|
NS_NOTREACHED("should have an entry in moz_places");
|
|
|
|
}
|
|
|
|
}
|
2011-01-14 10:42:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
rv = AddVisit(aPlace, aReferrer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// TODO (bug 623969) we shouldn't update this after each visit, but
|
|
|
|
// rather only for each unique place to save disk I/O.
|
2013-07-16 06:36:08 -07:00
|
|
|
|
|
|
|
// Don't update frecency if the page should not appear in autocomplete.
|
|
|
|
if (aPlace.shouldUpdateFrecency) {
|
|
|
|
rv = UpdateFrecency(aPlace);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-01-14 10:42:41 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
/**
|
|
|
|
* Loads visit information about the page into _place.
|
|
|
|
*
|
|
|
|
* @param _place
|
|
|
|
* The VisitData for the place we need to know visit information about.
|
|
|
|
* @param [optional] aThresholdStart
|
|
|
|
* The timestamp of a new visit (not represented by _place) used to
|
|
|
|
* determine if the page was recently visited or not.
|
|
|
|
* @return true if the page was recently (determined with aThresholdStart)
|
|
|
|
* visited, false otherwise.
|
|
|
|
*/
|
|
|
|
bool FetchVisitInfo(VisitData& _place,
|
|
|
|
PRTime aThresholdStart = 0)
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2010-11-17 16:15:49 -08:00
|
|
|
NS_PRECONDITION(!_place.spec.IsEmpty(), "must have a non-empty spec!");
|
2010-11-08 11:42:08 -08:00
|
|
|
|
2011-01-20 06:35:40 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
// If we have a visitTime, we want information on that specific visit.
|
|
|
|
if (_place.visitTime) {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2013-03-25 06:44:41 -07:00
|
|
|
"SELECT id, visit_date "
|
2011-01-20 06:35:40 -08:00
|
|
|
"FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) "
|
|
|
|
"AND visit_date = :visit_date "
|
|
|
|
);
|
|
|
|
NS_ENSURE_TRUE(stmt, false);
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("visit_date"),
|
|
|
|
_place.visitTime);
|
2012-08-14 02:10:42 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2011-01-20 06:35:40 -08:00
|
|
|
|
|
|
|
scoper.Abandon();
|
|
|
|
}
|
|
|
|
// Otherwise, we want information about the most recent visit.
|
|
|
|
else {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2013-03-25 06:44:41 -07:00
|
|
|
"SELECT id, visit_date "
|
2010-11-08 11:43:46 -08:00
|
|
|
"FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) "
|
|
|
|
"ORDER BY visit_date DESC "
|
|
|
|
);
|
2011-01-20 06:35:40 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, false);
|
|
|
|
}
|
2010-11-08 11:43:46 -08:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
2010-11-08 11:42:08 -08:00
|
|
|
|
2010-11-08 11:43:46 -08:00
|
|
|
nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"),
|
2010-11-17 16:15:49 -08:00
|
|
|
_place.spec);
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResult;
|
2010-11-08 11:42:08 -08:00
|
|
|
rv = stmt->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
if (!hasResult) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = stmt->GetInt64(0, &_place.visitId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2013-03-25 06:44:41 -07:00
|
|
|
rv = stmt->GetInt64(1, reinterpret_cast<int64_t*>(&_place.visitTime));
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
// If we have been given a visit threshold start time, go ahead and
|
|
|
|
// calculate if we have been recently visited.
|
|
|
|
if (aThresholdStart &&
|
|
|
|
aThresholdStart - _place.visitTime <= RECENT_EVENT_THRESHOLD) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 11:03:22 -08:00
|
|
|
/**
|
2013-03-25 06:44:41 -07:00
|
|
|
* Fetches information about a referrer for aPlace if it was a recent
|
|
|
|
* visit or not.
|
2011-01-11 11:03:22 -08:00
|
|
|
*
|
|
|
|
* @param aReferrer
|
|
|
|
* The VisitData for the referrer. This will be populated with
|
|
|
|
* FetchVisitInfo.
|
|
|
|
* @param aPlace
|
|
|
|
* The VisitData for the visit we will eventually add.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void FetchReferrerInfo(VisitData& aReferrer,
|
|
|
|
VisitData& aPlace)
|
|
|
|
{
|
|
|
|
if (aReferrer.spec.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-25 06:44:41 -07:00
|
|
|
if (!FetchVisitInfo(aReferrer, aPlace.visitTime)) {
|
2011-02-16 12:19:09 -08:00
|
|
|
// We must change both the place and referrer to indicate that we will
|
|
|
|
// not be using the referrer's data. This behavior has test coverage, so
|
|
|
|
// if this invariant changes, we'll know.
|
|
|
|
aPlace.referrerSpec.Truncate();
|
2011-01-11 11:03:22 -08:00
|
|
|
aReferrer.visitId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
/**
|
|
|
|
* Adds a visit for _place and updates it with the right visit id.
|
|
|
|
*
|
|
|
|
* @param _place
|
|
|
|
* The VisitData for the place we need to know visit information about.
|
|
|
|
* @param aReferrer
|
|
|
|
* A reference to the referrer's visit data.
|
|
|
|
*/
|
|
|
|
nsresult AddVisit(VisitData& _place,
|
|
|
|
const VisitData& aReferrer)
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2010-11-16 04:44:05 -08:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
if (_place.placeId) {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2010-11-08 11:43:46 -08:00
|
|
|
"INSERT INTO moz_historyvisits "
|
|
|
|
"(from_visit, place_id, visit_date, visit_type, session) "
|
2013-03-25 06:44:41 -07:00
|
|
|
"VALUES (:from_visit, :page_id, :visit_date, :visit_type, 0) "
|
2010-11-08 11:43:46 -08:00
|
|
|
);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2011-01-11 11:13:17 -08:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), _place.placeId);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2010-11-16 04:44:05 -08:00
|
|
|
"INSERT INTO moz_historyvisits "
|
|
|
|
"(from_visit, place_id, visit_date, visit_type, session) "
|
2013-03-25 06:44:41 -07:00
|
|
|
"VALUES (:from_visit, (SELECT id FROM moz_places WHERE url = :page_url), :visit_date, :visit_type, 0) "
|
2010-11-16 04:44:05 -08:00
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
2010-11-17 16:15:49 -08:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), _place.spec);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("from_visit"),
|
|
|
|
aReferrer.visitId);
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("visit_date"),
|
|
|
|
_place.visitTime);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t transitionType = _place.transitionType;
|
2010-11-08 11:42:08 -08:00
|
|
|
NS_ASSERTION(transitionType >= nsINavHistoryService::TRANSITION_LINK &&
|
|
|
|
transitionType <= nsINavHistoryService::TRANSITION_FRAMED_LINK,
|
|
|
|
"Invalid transition type!");
|
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("visit_type"),
|
|
|
|
transitionType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-11-16 04:44:05 -08:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
2010-11-08 11:42:08 -08:00
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
// Now that it should be in the database, we need to obtain the id of the
|
2011-01-20 06:35:40 -08:00
|
|
|
// visit we just added.
|
|
|
|
(void)FetchVisitInfo(_place);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
return NS_OK;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
/**
|
|
|
|
* Updates the frecency, and possibly the hidden-ness of aPlace.
|
|
|
|
*
|
|
|
|
* @param aPlace
|
|
|
|
* The VisitData for the place we want to update.
|
|
|
|
*/
|
|
|
|
nsresult UpdateFrecency(const VisitData& aPlace)
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
2013-07-16 06:36:08 -07:00
|
|
|
MOZ_ASSERT(aPlace.shouldUpdateFrecency);
|
2012-04-06 16:17:49 -07:00
|
|
|
|
2010-11-16 04:44:05 -08:00
|
|
|
nsresult rv;
|
2010-11-08 11:43:46 -08:00
|
|
|
{ // First, set our frecency to the proper value.
|
2010-11-16 04:44:05 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
if (aPlace.placeId) {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2010-11-08 11:43:46 -08:00
|
|
|
"UPDATE moz_places "
|
2014-03-28 23:30:04 -07:00
|
|
|
"SET frecency = NOTIFY_FRECENCY("
|
|
|
|
"CALCULATE_FRECENCY(:page_id), "
|
|
|
|
"url, guid, hidden, last_visit_date"
|
|
|
|
") "
|
2010-11-08 11:43:46 -08:00
|
|
|
"WHERE id = :page_id"
|
|
|
|
);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2011-01-11 11:13:17 -08:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlace.placeId);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2010-11-16 04:44:05 -08:00
|
|
|
"UPDATE moz_places "
|
2014-03-28 23:30:04 -07:00
|
|
|
"SET frecency = NOTIFY_FRECENCY("
|
|
|
|
"CALCULATE_FRECENCY(id), url, guid, hidden, last_visit_date"
|
|
|
|
") "
|
2010-11-16 04:44:05 -08:00
|
|
|
"WHERE url = :page_url"
|
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
2010-11-17 16:15:49 -08:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aPlace.spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-16 04:44:05 -08:00
|
|
|
}
|
2010-11-08 11:43:46 -08:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2012-04-06 16:17:49 -07:00
|
|
|
if (!aPlace.hidden) {
|
2012-04-06 16:17:51 -07:00
|
|
|
// Mark the page as not hidden if the frecency is now nonzero.
|
2010-11-16 04:44:05 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
if (aPlace.placeId) {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2010-11-08 11:43:46 -08:00
|
|
|
"UPDATE moz_places "
|
|
|
|
"SET hidden = 0 "
|
|
|
|
"WHERE id = :page_id AND frecency <> 0"
|
|
|
|
);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2011-01-11 11:13:17 -08:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlace.placeId);
|
2010-11-16 04:44:05 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-27 02:11:34 -07:00
|
|
|
stmt = mHistory->GetStatement(
|
2010-11-16 04:44:05 -08:00
|
|
|
"UPDATE moz_places "
|
|
|
|
"SET hidden = 0 "
|
|
|
|
"WHERE url = :page_url AND frecency <> 0"
|
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
2010-11-17 16:15:49 -08:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aPlace.spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-16 04:44:05 -08:00
|
|
|
}
|
2010-11-08 11:43:46 -08:00
|
|
|
|
2010-11-16 04:44:05 -08:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
2010-11-08 11:43:46 -08:00
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-07-13 18:00:33 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:43:46 -08:00
|
|
|
mozIStorageConnection* mDBConn;
|
2010-11-08 11:42:08 -08:00
|
|
|
|
2011-01-11 11:13:17 -08:00
|
|
|
nsTArray<VisitData> mPlaces;
|
|
|
|
nsTArray<VisitData> mReferrers;
|
2010-11-08 11:43:46 -08:00
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback> mCallback;
|
2011-01-14 10:42:41 -08:00
|
|
|
|
2010-11-08 11:43:46 -08:00
|
|
|
/**
|
|
|
|
* Strong reference to the History object because we do not want it to
|
|
|
|
* disappear out from under us.
|
|
|
|
*/
|
|
|
|
nsRefPtr<History> mHistory;
|
2010-07-13 18:00:33 -07:00
|
|
|
};
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class GetPlaceInfo final : public nsRunnable {
|
2013-06-19 00:18:38 -07:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the place info for a given place (by GUID or URI) asynchronously.
|
|
|
|
*/
|
|
|
|
static nsresult Start(mozIStorageConnection* aConnection,
|
|
|
|
VisitData& aPlace,
|
|
|
|
mozIVisitInfoCallback* aCallback) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitInfoCallback>(aCallback));
|
|
|
|
nsRefPtr<GetPlaceInfo> event = new GetPlaceInfo(aPlace, callback);
|
2013-06-19 00:18:38 -07:00
|
|
|
|
|
|
|
// Get the target thread, and then start the work!
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetInterface(aConnection);
|
|
|
|
NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
|
|
|
|
nsresult rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "This should not be called on the main thread");
|
|
|
|
|
|
|
|
bool exists;
|
|
|
|
nsresult rv = mHistory->FetchPageInfo(mPlace, &exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new NotifyPlaceInfoCallback(mCallback, mPlace, false, rv);
|
|
|
|
|
|
|
|
rv = NS_DispatchToMainThread(event);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
GetPlaceInfo(VisitData& aPlace,
|
2014-09-16 05:17:31 -07:00
|
|
|
const nsMainThreadPtrHandle<mozIVisitInfoCallback>& aCallback)
|
2013-06-19 00:18:38 -07:00
|
|
|
: mPlace(aPlace)
|
|
|
|
, mCallback(aCallback)
|
|
|
|
, mHistory(History::GetService())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitData mPlace;
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback> mCallback;
|
2013-06-19 00:18:38 -07:00
|
|
|
nsRefPtr<History> mHistory;
|
|
|
|
};
|
|
|
|
|
2010-07-13 18:00:41 -07:00
|
|
|
/**
|
2010-11-08 11:45:46 -08:00
|
|
|
* Sets the page title for a page in moz_places (if necessary).
|
2010-07-13 18:00:41 -07:00
|
|
|
*/
|
2010-11-08 11:45:46 -08:00
|
|
|
class SetPageTitle : public nsRunnable
|
2010-07-13 18:00:41 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-11-08 11:45:46 -08:00
|
|
|
/**
|
|
|
|
* Sets a pages title in the database asynchronously.
|
|
|
|
*
|
|
|
|
* @param aConnection
|
|
|
|
* The database connection to use for this operation.
|
|
|
|
* @param aURI
|
|
|
|
* The URI to set the page title on.
|
|
|
|
* @param aTitle
|
|
|
|
* The title to set for the page, if the page exists.
|
|
|
|
*/
|
|
|
|
static nsresult Start(mozIStorageConnection* aConnection,
|
|
|
|
nsIURI* aURI,
|
2011-01-25 09:01:14 -08:00
|
|
|
const nsAString& aTitle)
|
2010-07-13 18:00:41 -07:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
MOZ_ASSERT(aURI, "Must pass a non-null URI object!");
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2010-11-17 16:15:49 -08:00
|
|
|
nsCString spec;
|
|
|
|
nsresult rv = aURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsRefPtr<SetPageTitle> event = new SetPageTitle(spec, aTitle);
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
// Get the target thread, and then start the work!
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetInterface(aConnection);
|
|
|
|
NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
|
2010-11-17 16:15:49 -08:00
|
|
|
rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
|
2010-11-08 11:45:46 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
return NS_OK;
|
2010-07-13 18:00:41 -07:00
|
|
|
}
|
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
NS_IMETHOD Run()
|
2010-07-13 18:00:41 -07:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread(), "This should not be called on the main thread");
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
// First, see if the page exists in the database (we'll need its id later).
|
2013-06-19 00:18:38 -07:00
|
|
|
bool exists;
|
|
|
|
nsresult rv = mHistory->FetchPageInfo(mPlace, &exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-01-25 09:01:14 -08:00
|
|
|
if (!exists || !mPlace.titleChanged) {
|
|
|
|
// We have no record of this page, or we have no title change, so there
|
|
|
|
// is no need to do any further work.
|
2011-01-11 10:48:53 -08:00
|
|
|
return NS_OK;
|
2010-11-08 11:45:46 -08:00
|
|
|
}
|
|
|
|
|
2011-01-11 10:48:53 -08:00
|
|
|
NS_ASSERTION(mPlace.placeId > 0,
|
|
|
|
"We somehow have an invalid place id here!");
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
// Now we can update our database record.
|
2011-01-11 10:48:53 -08:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
2011-10-27 02:11:34 -07:00
|
|
|
mHistory->GetStatement(
|
2010-11-08 11:45:46 -08:00
|
|
|
"UPDATE moz_places "
|
|
|
|
"SET title = :page_title "
|
|
|
|
"WHERE id = :page_id "
|
2010-07-13 18:00:41 -07:00
|
|
|
);
|
2010-11-08 11:45:46 -08:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
{
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), mPlace.placeId);
|
2010-11-08 11:45:46 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-25 09:01:14 -08:00
|
|
|
// Empty strings should clear the title, just like
|
|
|
|
// nsNavHistory::SetPageTitle.
|
|
|
|
if (mPlace.title.IsEmpty()) {
|
2010-11-08 11:45:46 -08:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("page_title"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("page_title"),
|
2011-01-25 09:01:14 -08:00
|
|
|
StringHead(mPlace.title, TITLE_LENGTH_MAX));
|
2010-11-08 11:45:46 -08:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2011-01-25 09:01:14 -08:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2011-06-30 13:05:49 -07:00
|
|
|
new NotifyTitleObservers(mPlace.spec, mPlace.title, mPlace.guid);
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = NS_DispatchToMainThread(event);
|
2010-07-13 18:00:41 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
private:
|
2010-11-17 16:15:49 -08:00
|
|
|
SetPageTitle(const nsCString& aSpec,
|
2011-01-25 09:01:14 -08:00
|
|
|
const nsAString& aTitle)
|
|
|
|
: mHistory(History::GetService())
|
2010-07-13 18:00:41 -07:00
|
|
|
{
|
2011-01-11 10:48:53 -08:00
|
|
|
mPlace.spec = aSpec;
|
2011-01-25 09:01:14 -08:00
|
|
|
mPlace.title = aTitle;
|
2010-07-13 18:00:41 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 10:48:53 -08:00
|
|
|
VisitData mPlace;
|
2010-11-08 11:45:46 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Strong reference to the History object because we do not want it to
|
|
|
|
* disappear out from under us.
|
|
|
|
*/
|
|
|
|
nsRefPtr<History> mHistory;
|
2010-07-13 18:00:41 -07:00
|
|
|
};
|
|
|
|
|
2012-01-20 04:48:20 -08:00
|
|
|
/**
|
|
|
|
* Adds download-specific annotations to a download page.
|
|
|
|
*/
|
2015-03-21 09:28:04 -07:00
|
|
|
class SetDownloadAnnotations final : public mozIVisitInfoCallback
|
2012-01-20 04:48:20 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2014-09-03 15:25:36 -07:00
|
|
|
explicit SetDownloadAnnotations(nsIURI* aDestination)
|
2012-01-20 04:48:20 -08:00
|
|
|
: mDestination(aDestination)
|
|
|
|
, mHistory(History::GetService())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mDestination);
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD HandleError(nsresult aResultCode, mozIPlaceInfo *aPlaceInfo) override
|
2012-01-20 04:48:20 -08:00
|
|
|
{
|
|
|
|
// Just don't add the annotations in case the visit isn't added.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD HandleResult(mozIPlaceInfo *aPlaceInfo) override
|
2012-01-20 04:48:20 -08:00
|
|
|
{
|
|
|
|
// Exit silently if the download destination is not a local file.
|
|
|
|
nsCOMPtr<nsIFileURL> destinationFileURL = do_QueryInterface(mDestination);
|
|
|
|
if (!destinationFileURL) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> source;
|
|
|
|
nsresult rv = aPlaceInfo->GetUri(getter_AddRefs(source));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> destinationFile;
|
|
|
|
rv = destinationFileURL->GetFile(getter_AddRefs(destinationFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString destinationFileName;
|
|
|
|
rv = destinationFile->GetLeafName(destinationFileName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString destinationURISpec;
|
2012-01-20 04:48:20 -08:00
|
|
|
rv = destinationFileURL->GetSpec(destinationURISpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Use annotations for storing the additional download metadata.
|
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
rv = annosvc->SetPageAnnotationString(
|
|
|
|
source,
|
|
|
|
DESTINATIONFILEURI_ANNO,
|
|
|
|
NS_ConvertUTF8toUTF16(destinationURISpec),
|
|
|
|
0,
|
|
|
|
nsIAnnotationService::EXPIRE_WITH_HISTORY
|
|
|
|
);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = annosvc->SetPageAnnotationString(
|
|
|
|
source,
|
|
|
|
DESTINATIONFILENAME_ANNO,
|
|
|
|
destinationFileName,
|
|
|
|
0,
|
|
|
|
nsIAnnotationService::EXPIRE_WITH_HISTORY
|
|
|
|
);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
rv = aPlaceInfo->GetTitle(title);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// In case we are downloading a file that does not correspond to a web
|
|
|
|
// page for which the title is present, we populate the otherwise empty
|
|
|
|
// history title with the name of the destination file, to allow it to be
|
|
|
|
// visible and searchable in history results.
|
|
|
|
if (title.IsEmpty()) {
|
|
|
|
rv = mHistory->SetURITitle(source, destinationFileName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD HandleCompletion() override
|
2012-01-20 04:48:20 -08:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-23 15:40:02 -07:00
|
|
|
~SetDownloadAnnotations() {}
|
|
|
|
|
2012-01-20 04:48:20 -08:00
|
|
|
nsCOMPtr<nsIURI> mDestination;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strong reference to the History object because we do not want it to
|
|
|
|
* disappear out from under us.
|
|
|
|
*/
|
|
|
|
nsRefPtr<History> mHistory;
|
|
|
|
};
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2012-01-20 04:48:20 -08:00
|
|
|
SetDownloadAnnotations,
|
|
|
|
mozIVisitInfoCallback
|
|
|
|
)
|
|
|
|
|
2013-01-05 01:21:04 -08:00
|
|
|
/**
|
|
|
|
* Enumerator used by NotifyRemoveVisits to transfer the hash entries.
|
|
|
|
*/
|
|
|
|
static PLDHashOperator TransferHashEntries(PlaceHashKey* aEntry,
|
|
|
|
void* aHash)
|
|
|
|
{
|
|
|
|
nsTHashtable<PlaceHashKey>* hash =
|
|
|
|
static_cast<nsTHashtable<PlaceHashKey> *>(aHash);
|
|
|
|
PlaceHashKey* copy = hash->PutEntry(aEntry->GetKey());
|
2014-09-04 15:19:00 -07:00
|
|
|
copy->SetProperties(aEntry->VisitCount(), aEntry->IsBookmarked());
|
2014-09-04 15:21:00 -07:00
|
|
|
aEntry->mVisits.SwapElements(copy->mVisits);
|
2013-01-05 01:21:04 -08:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enumerator used by NotifyRemoveVisits to notify removals.
|
|
|
|
*/
|
|
|
|
static PLDHashOperator NotifyVisitRemoval(PlaceHashKey* aEntry,
|
|
|
|
void* aHistory)
|
|
|
|
{
|
|
|
|
nsNavHistory* history = static_cast<nsNavHistory *>(aHistory);
|
2014-09-04 15:21:00 -07:00
|
|
|
const nsTArray<VisitData>& visits = aEntry->mVisits;
|
2013-01-05 01:21:04 -08:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
(void)NS_NewURI(getter_AddRefs(uri), visits[0].spec);
|
2014-08-06 22:40:43 -07:00
|
|
|
bool removingPage =
|
2014-09-04 15:19:00 -07:00
|
|
|
visits.Length() == aEntry->VisitCount() &&
|
|
|
|
!aEntry->IsBookmarked();
|
2013-01-05 01:21:04 -08:00
|
|
|
// FindRemovableVisits only sets the transition type on the VisitData objects
|
|
|
|
// it collects if the visits were filtered by transition type.
|
|
|
|
// RemoveVisitsFilter currently only supports filtering by transition type, so
|
|
|
|
// FindRemovableVisits will either find all visits, or all visits of a given
|
|
|
|
// type. Therefore, if transitionType is set on this visit, we pass the
|
|
|
|
// transition type to NotifyOnPageExpired which in turns passes it to
|
|
|
|
// OnDeleteVisits to indicate that all visits of a given type were removed.
|
|
|
|
uint32_t transition = visits[0].transitionType < UINT32_MAX ?
|
|
|
|
visits[0].transitionType : 0;
|
|
|
|
history->NotifyOnPageExpired(uri, visits[0].visitTime, removingPage,
|
|
|
|
visits[0].guid,
|
|
|
|
nsINavHistoryObserver::REASON_DELETED,
|
|
|
|
transition);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify removed visits to observers.
|
|
|
|
*/
|
|
|
|
class NotifyRemoveVisits : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-09-03 15:25:36 -07:00
|
|
|
explicit NotifyRemoveVisits(nsTHashtable<PlaceHashKey>& aPlaces)
|
2014-08-06 06:31:21 -07:00
|
|
|
: mPlaces(VISITS_REMOVAL_INITIAL_HASH_LENGTH)
|
2013-09-02 01:41:57 -07:00
|
|
|
, mHistory(History::GetService())
|
2013-01-05 01:21:04 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(),
|
|
|
|
"This should not be called on the main thread");
|
|
|
|
aPlaces.EnumerateEntries(TransferHashEntries, &mPlaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
|
|
|
|
// We are in the main thread, no need to lock.
|
|
|
|
if (mHistory->IsShuttingDown()) {
|
|
|
|
// If we are shutting down, we cannot notify the observers.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
if (!navHistory) {
|
|
|
|
NS_WARNING("Cannot notify without the history service!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrap all notifications in a batch, so the view can handle changes in a
|
|
|
|
// more performant way, by initiating a refresh after a limited number of
|
|
|
|
// single changes.
|
|
|
|
(void)navHistory->BeginUpdateBatch();
|
|
|
|
mPlaces.EnumerateEntries(NotifyVisitRemoval, navHistory);
|
|
|
|
(void)navHistory->EndUpdateBatch();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsTHashtable<PlaceHashKey> mPlaces;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strong reference to the History object because we do not want it to
|
|
|
|
* disappear out from under us.
|
|
|
|
*/
|
|
|
|
nsRefPtr<History> mHistory;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enumerator used by RemoveVisits to populate list of removed place ids.
|
|
|
|
*/
|
|
|
|
static PLDHashOperator ListToBeRemovedPlaceIds(PlaceHashKey* aEntry,
|
|
|
|
void* aIdsList)
|
|
|
|
{
|
2014-09-04 15:21:00 -07:00
|
|
|
const nsTArray<VisitData>& visits = aEntry->mVisits;
|
2013-01-05 01:21:04 -08:00
|
|
|
// Only orphan ids should be listed.
|
2014-09-04 15:19:00 -07:00
|
|
|
if (visits.Length() == aEntry->VisitCount() &&
|
|
|
|
!aEntry->IsBookmarked()) {
|
2013-01-05 01:21:04 -08:00
|
|
|
nsCString* list = static_cast<nsCString*>(aIdsList);
|
|
|
|
if (!list->IsEmpty())
|
2014-05-21 20:48:51 -07:00
|
|
|
list->Append(',');
|
2013-01-05 01:21:04 -08:00
|
|
|
list->AppendInt(visits[0].placeId);
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove visits from history.
|
|
|
|
*/
|
|
|
|
class RemoveVisits : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Asynchronously removes visits from history.
|
|
|
|
*
|
|
|
|
* @param aConnection
|
|
|
|
* The database connection to use for these operations.
|
|
|
|
* @param aFilter
|
|
|
|
* Filter to remove visits.
|
|
|
|
*/
|
|
|
|
static nsresult Start(mozIStorageConnection* aConnection,
|
|
|
|
RemoveVisitsFilter& aFilter)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
|
|
|
|
nsRefPtr<RemoveVisits> event = new RemoveVisits(aConnection, aFilter);
|
|
|
|
|
|
|
|
// Get the target thread, and then start the work!
|
|
|
|
nsCOMPtr<nsIEventTarget> target = do_GetInterface(aConnection);
|
|
|
|
NS_ENSURE_TRUE(target, NS_ERROR_UNEXPECTED);
|
|
|
|
nsresult rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(),
|
|
|
|
"This should not be called on the main thread");
|
|
|
|
|
|
|
|
// Prevent the main thread from shutting down while this is running.
|
|
|
|
MutexAutoLock lockedScope(mHistory->GetShutdownMutex());
|
|
|
|
if (mHistory->IsShuttingDown()) {
|
|
|
|
// If we were already shutting down, we cannot remove the visits.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all the visits relative to the current filters and whether their
|
|
|
|
// pages will be removed or not.
|
2014-08-06 06:31:21 -07:00
|
|
|
nsTHashtable<PlaceHashKey> places(VISITS_REMOVAL_INITIAL_HASH_LENGTH);
|
2013-01-05 01:21:04 -08:00
|
|
|
nsresult rv = FindRemovableVisits(places);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (places.Count() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mozStorageTransaction transaction(mDBConn, false,
|
|
|
|
mozIStorageConnection::TRANSACTION_IMMEDIATE);
|
|
|
|
|
|
|
|
rv = RemoveVisitsFromDatabase();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = RemovePagesFromDatabase(places);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event = new NotifyRemoveVisits(places);
|
|
|
|
rv = NS_DispatchToMainThread(event);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RemoveVisits(mozIStorageConnection* aConnection,
|
|
|
|
RemoveVisitsFilter& aFilter)
|
|
|
|
: mDBConn(aConnection)
|
|
|
|
, mHasTransitionType(false)
|
|
|
|
, mHistory(History::GetService())
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
|
|
|
|
|
|
|
|
// Build query conditions.
|
|
|
|
nsTArray<nsCString> conditions;
|
|
|
|
// TODO: add support for binding params when adding further stuff here.
|
|
|
|
if (aFilter.transitionType < UINT32_MAX) {
|
|
|
|
conditions.AppendElement(nsPrintfCString("visit_type = %d", aFilter.transitionType));
|
|
|
|
mHasTransitionType = true;
|
|
|
|
}
|
|
|
|
if (conditions.Length() > 0) {
|
|
|
|
mWhereClause.AppendLiteral (" WHERE ");
|
|
|
|
for (uint32_t i = 0; i < conditions.Length(); ++i) {
|
|
|
|
if (i > 0)
|
|
|
|
mWhereClause.AppendLiteral(" AND ");
|
|
|
|
mWhereClause.Append(conditions[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
/**
|
|
|
|
* Find the list of entries that may be removed from `moz_places`.
|
|
|
|
*
|
|
|
|
* Calling this method makes sense only if we are not clearing the entire history.
|
|
|
|
*/
|
2013-01-05 01:21:04 -08:00
|
|
|
nsresult
|
|
|
|
FindRemovableVisits(nsTHashtable<PlaceHashKey>& aPlaces)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(),
|
|
|
|
"This should not be called on the main thread");
|
|
|
|
|
|
|
|
nsCString query("SELECT h.id, url, guid, visit_date, visit_type, "
|
|
|
|
"(SELECT count(*) FROM moz_historyvisits WHERE place_id = h.id) as full_visit_count, "
|
|
|
|
"EXISTS(SELECT 1 FROM moz_bookmarks WHERE fk = h.id) as bookmarked "
|
|
|
|
"FROM moz_historyvisits "
|
|
|
|
"JOIN moz_places h ON place_id = h.id");
|
|
|
|
query.Append(mWhereClause);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mHistory->GetStatement(query);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
bool hasResult;
|
|
|
|
nsresult rv;
|
|
|
|
while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&hasResult))) && hasResult) {
|
|
|
|
VisitData visit;
|
|
|
|
rv = stmt->GetInt64(0, &visit.placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->GetUTF8String(1, visit.spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->GetUTF8String(2, visit.guid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->GetInt64(3, &visit.visitTime);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (mHasTransitionType) {
|
|
|
|
int32_t transition;
|
|
|
|
rv = stmt->GetInt32(4, &transition);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
visit.transitionType = static_cast<uint32_t>(transition);
|
|
|
|
}
|
|
|
|
int32_t visitCount, bookmarked;
|
|
|
|
rv = stmt->GetInt32(5, &visitCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->GetInt32(6, &bookmarked);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PlaceHashKey* entry = aPlaces.GetEntry(visit.spec);
|
|
|
|
if (!entry) {
|
|
|
|
entry = aPlaces.PutEntry(visit.spec);
|
|
|
|
}
|
2014-09-04 15:19:00 -07:00
|
|
|
entry->SetProperties(static_cast<uint32_t>(visitCount), static_cast<bool>(bookmarked));
|
2014-09-04 15:21:00 -07:00
|
|
|
entry->mVisits.AppendElement(visit);
|
2013-01-05 01:21:04 -08:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RemoveVisitsFromDatabase()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(),
|
|
|
|
"This should not be called on the main thread");
|
|
|
|
|
|
|
|
nsCString query("DELETE FROM moz_historyvisits");
|
|
|
|
query.Append(mWhereClause);
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mHistory->GetStatement(query);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
nsresult rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RemovePagesFromDatabase(nsTHashtable<PlaceHashKey>& aPlaces)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread(),
|
|
|
|
"This should not be called on the main thread");
|
|
|
|
|
|
|
|
nsCString placeIdsToRemove;
|
|
|
|
aPlaces.EnumerateEntries(ListToBeRemovedPlaceIds, &placeIdsToRemove);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
// Ensure that we are not removing any problematic entry.
|
|
|
|
nsCString query("SELECT id FROM moz_places h WHERE id IN (");
|
|
|
|
query.Append(placeIdsToRemove);
|
|
|
|
query.AppendLiteral(") AND ("
|
|
|
|
"EXISTS(SELECT 1 FROM moz_bookmarks WHERE fk = h.id) OR "
|
|
|
|
"EXISTS(SELECT 1 FROM moz_historyvisits WHERE place_id = h.id) OR "
|
|
|
|
"SUBSTR(h.url, 1, 6) = 'place:' "
|
|
|
|
")");
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mHistory->GetStatement(query);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
bool hasResult;
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && !hasResult,
|
|
|
|
"Trying to remove a non-oprhan place from the database");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCString query("DELETE FROM moz_places "
|
|
|
|
"WHERE id IN (");
|
|
|
|
query.Append(placeIdsToRemove);
|
2014-05-21 20:48:51 -07:00
|
|
|
query.Append(')');
|
2013-01-05 01:21:04 -08:00
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = mHistory->GetStatement(query);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
nsresult rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozIStorageConnection* mDBConn;
|
|
|
|
bool mHasTransitionType;
|
|
|
|
nsCString mWhereClause;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strong reference to the History object because we do not want it to
|
|
|
|
* disappear out from under us.
|
|
|
|
*/
|
|
|
|
nsRefPtr<History> mHistory;
|
|
|
|
};
|
|
|
|
|
2011-01-12 10:22:39 -08:00
|
|
|
/**
|
|
|
|
* Stores an embed visit, and notifies observers.
|
|
|
|
*
|
|
|
|
* @param aPlace
|
|
|
|
* The VisitData of the visit to store as an embed visit.
|
2011-01-14 10:42:41 -08:00
|
|
|
* @param [optional] aCallback
|
|
|
|
* The mozIVisitInfoCallback to notify, if provided.
|
2011-01-12 10:22:39 -08:00
|
|
|
*/
|
|
|
|
void
|
2011-01-14 10:42:41 -08:00
|
|
|
StoreAndNotifyEmbedVisit(VisitData& aPlace,
|
2013-10-10 13:38:05 -07:00
|
|
|
mozIVisitInfoCallback* aCallback = nullptr)
|
2011-01-12 10:22:39 -08:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
MOZ_ASSERT(aPlace.transitionType == nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
"Must only pass TRANSITION_EMBED visits to this!");
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be called on the main thread!");
|
2011-01-12 10:22:39 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
(void)NS_NewURI(getter_AddRefs(uri), aPlace.spec);
|
|
|
|
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
if (!navHistory || !uri) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
navHistory->registerEmbedVisit(uri, aPlace.visitTime);
|
2011-01-14 10:42:41 -08:00
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
if (!!aCallback) {
|
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitInfoCallback>(aCallback));
|
2011-01-14 10:42:41 -08:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2014-09-16 05:17:31 -07:00
|
|
|
new NotifyPlaceInfoCallback(callback, aPlace, true, NS_OK);
|
2011-01-14 10:42:41 -08:00
|
|
|
(void)NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
|
2011-01-12 10:22:39 -08:00
|
|
|
VisitData noReferrer;
|
|
|
|
nsCOMPtr<nsIRunnable> event = new NotifyVisitObservers(aPlace, noReferrer);
|
|
|
|
(void)NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// History
|
|
|
|
|
2013-10-10 13:38:05 -07:00
|
|
|
History* History::gService = nullptr;
|
2009-08-20 11:56:10 -07:00
|
|
|
|
|
|
|
History::History()
|
2013-12-07 22:09:10 -08:00
|
|
|
: mShuttingDown(false)
|
2012-02-01 02:59:27 -08:00
|
|
|
, mShutdownMutex("History::mShutdownMutex")
|
2014-08-06 06:31:21 -07:00
|
|
|
, mObservers(VISIT_OBSERVERS_INITIAL_CACHE_LENGTH)
|
2012-03-28 12:50:59 -07:00
|
|
|
, mRecentlyVisitedURIsNextIndex(0)
|
2009-08-20 11:56:10 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!gService, "Ruh-roh! This service has already been created!");
|
|
|
|
gService = this;
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-12-21 15:03:01 -08:00
|
|
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_WARN_IF_FALSE(os, "Observer service was not found!");
|
|
|
|
if (os) {
|
2011-10-17 07:59:28 -07:00
|
|
|
(void)os->AddObserver(this, TOPIC_PLACES_SHUTDOWN, false);
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
History::~History()
|
|
|
|
{
|
2013-11-06 21:35:30 -08:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2013-01-17 16:45:11 -08:00
|
|
|
|
|
|
|
gService = nullptr;
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
NS_ASSERTION(mObservers.Count() == 0,
|
|
|
|
"Not all Links were removed before we disappear!");
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
void
|
|
|
|
History::InitMemoryReporter()
|
|
|
|
{
|
|
|
|
RegisterWeakMemoryReporter(this);
|
|
|
|
}
|
|
|
|
|
2012-11-09 01:55:48 -08:00
|
|
|
NS_IMETHODIMP
|
2009-08-20 11:56:10 -07:00
|
|
|
History::NotifyVisited(nsIURI* aURI)
|
|
|
|
{
|
2012-11-09 01:55:48 -08:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2009-08-20 11:56:10 -07:00
|
|
|
|
2011-07-13 14:28:37 -07:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
2010-07-02 08:50:41 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2011-08-02 12:35:42 -07:00
|
|
|
nsTArray<ContentParent*> cplist;
|
|
|
|
ContentParent::GetAll(cplist);
|
2012-10-05 13:11:08 -07:00
|
|
|
|
|
|
|
if (!cplist.IsEmpty()) {
|
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(aURI, uri);
|
|
|
|
for (uint32_t i = 0; i < cplist.Length(); ++i) {
|
|
|
|
unused << cplist[i]->SendNotifyVisited(uri);
|
|
|
|
}
|
2011-08-02 12:35:42 -07:00
|
|
|
}
|
2010-07-02 08:50:41 -07:00
|
|
|
}
|
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
// If we have no observers for this URI, we have nothing to notify about.
|
2009-08-20 11:56:10 -07:00
|
|
|
KeyClass* key = mObservers.GetEntry(aURI);
|
|
|
|
if (!key) {
|
2012-11-09 01:55:48 -08:00
|
|
|
return NS_OK;
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
|
|
|
|
2011-07-13 14:28:37 -07:00
|
|
|
// Update status of each Link node.
|
|
|
|
{
|
|
|
|
// RemoveEntry will destroy the array, this iterator should not survive it.
|
|
|
|
ObserverArray::ForwardIterator iter(key->array);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
Link* link = iter.GetNext();
|
|
|
|
link->SetLinkState(eLinkState_Visited);
|
|
|
|
// Verify that the observers hash doesn't mutate while looping through
|
|
|
|
// the links associated with this URI.
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(key == mObservers.GetEntry(aURI),
|
|
|
|
"The URIs hash mutated!");
|
2011-07-13 14:28:37 -07:00
|
|
|
}
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// All the registered nodes can now be removed for this URI.
|
|
|
|
mObservers.RemoveEntry(aURI);
|
2012-11-09 01:55:48 -08:00
|
|
|
return NS_OK;
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class ConcurrentStatementsHolder final : public mozIStorageCompletionCallback {
|
2014-08-12 01:59:11 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2014-09-03 15:25:36 -07:00
|
|
|
explicit ConcurrentStatementsHolder(mozIStorageConnection* aDBConn)
|
2014-08-12 01:59:11 -07:00
|
|
|
{
|
|
|
|
DebugOnly<nsresult> rv = aDBConn->AsyncClone(true, this);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2010-10-06 08:21:31 -07:00
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Complete(nsresult aStatus, nsISupports* aConnection) override {
|
2014-08-12 01:59:11 -07:00
|
|
|
if (NS_FAILED(aStatus))
|
|
|
|
return NS_OK;
|
|
|
|
mReadOnlyDBConn = do_QueryInterface(aConnection);
|
|
|
|
|
|
|
|
// Now we can create our cached statements.
|
|
|
|
|
|
|
|
if (!mIsVisitedStatement) {
|
|
|
|
(void)mReadOnlyDBConn->CreateAsyncStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT 1 FROM moz_places h "
|
|
|
|
"WHERE url = ?1 AND last_visit_date NOTNULL "
|
|
|
|
), getter_AddRefs(mIsVisitedStatement));
|
|
|
|
MOZ_ASSERT(mIsVisitedStatement);
|
|
|
|
nsresult result = mIsVisitedStatement ? NS_OK : NS_ERROR_NOT_AVAILABLE;
|
|
|
|
for (int32_t i = 0; i < mIsVisitedCallbacks.Count(); ++i) {
|
|
|
|
DebugOnly<nsresult> rv;
|
|
|
|
rv = mIsVisitedCallbacks[i]->Complete(result, mIsVisitedStatement);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
mIsVisitedCallbacks.Clear();
|
|
|
|
}
|
2010-10-06 08:21:31 -07:00
|
|
|
|
2014-08-12 01:59:11 -07:00
|
|
|
return NS_OK;
|
2010-10-06 08:21:31 -07:00
|
|
|
}
|
|
|
|
|
2014-08-12 01:59:11 -07:00
|
|
|
void GetIsVisitedStatement(mozIStorageCompletionCallback* aCallback)
|
|
|
|
{
|
|
|
|
if (mIsVisitedStatement) {
|
|
|
|
DebugOnly<nsresult> rv;
|
|
|
|
rv = aCallback->Complete(NS_OK, mIsVisitedStatement);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
} else {
|
|
|
|
DebugOnly<bool> added = mIsVisitedCallbacks.AppendObject(aCallback);
|
|
|
|
MOZ_ASSERT(added);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown() {
|
|
|
|
if (mReadOnlyDBConn) {
|
|
|
|
mIsVisitedCallbacks.Clear();
|
|
|
|
DebugOnly<nsresult> rv;
|
|
|
|
if (mIsVisitedStatement) {
|
|
|
|
rv = mIsVisitedStatement->Finalize();
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
rv = mReadOnlyDBConn->AsyncClose(nullptr);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~ConcurrentStatementsHolder()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageAsyncConnection> mReadOnlyDBConn;
|
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> mIsVisitedStatement;
|
|
|
|
nsCOMArray<mozIStorageCompletionCallback> mIsVisitedCallbacks;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(
|
|
|
|
ConcurrentStatementsHolder
|
|
|
|
, mozIStorageCompletionCallback
|
|
|
|
)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
History::GetIsVisitedStatement(mozIStorageCompletionCallback* aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mShuttingDown)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
if (!mConcurrentStatementsHolder) {
|
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
|
|
|
mConcurrentStatementsHolder = new ConcurrentStatementsHolder(dbConn);
|
|
|
|
}
|
|
|
|
mConcurrentStatementsHolder->GetIsVisitedStatement(aCallback);
|
|
|
|
return NS_OK;
|
2010-10-06 08:21:31 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 10:48:14 -08:00
|
|
|
nsresult
|
|
|
|
History::InsertPlace(const VisitData& aPlace)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPlace.placeId == 0, "should not have a valid place id!");
|
|
|
|
NS_PRECONDITION(!NS_IsMainThread(), "must be called off of the main thread!");
|
|
|
|
|
2011-10-27 02:11:34 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = GetStatement(
|
2011-01-11 10:48:14 -08:00
|
|
|
"INSERT INTO moz_places "
|
2012-04-06 16:17:49 -07:00
|
|
|
"(url, title, rev_host, hidden, typed, frecency, guid) "
|
|
|
|
"VALUES (:url, :title, :rev_host, :hidden, :typed, :frecency, :guid) "
|
2011-01-11 10:48:14 -08:00
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = stmt->BindStringByName(NS_LITERAL_CSTRING("rev_host"),
|
|
|
|
aPlace.revHost);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-13 18:31:34 -08:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("url"), aPlace.spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-03-28 23:30:04 -07:00
|
|
|
nsString title = aPlace.title;
|
2011-01-25 09:01:14 -08:00
|
|
|
// Empty strings should have no title, just like nsNavHistory::SetPageTitle.
|
2014-03-28 23:30:04 -07:00
|
|
|
if (title.IsEmpty()) {
|
2011-01-13 18:31:34 -08:00
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("title"));
|
|
|
|
}
|
|
|
|
else {
|
2014-03-28 23:30:04 -07:00
|
|
|
title.Assign(StringHead(aPlace.title, TITLE_LENGTH_MAX));
|
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("title"), title);
|
2011-01-13 18:31:34 -08:00
|
|
|
}
|
2011-01-11 10:48:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("typed"), aPlace.typed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-07-16 06:36:08 -07:00
|
|
|
// When inserting a page for a first visit that should not appear in
|
|
|
|
// autocomplete, for example an error page, use a zero frecency.
|
|
|
|
int32_t frecency = aPlace.shouldUpdateFrecency ? aPlace.frecency : 0;
|
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("frecency"), frecency);
|
2012-04-06 16:17:49 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-11 10:48:14 -08:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("hidden"), aPlace.hidden);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString guid(aPlace.guid);
|
2011-01-13 18:31:34 -08:00
|
|
|
if (aPlace.guid.IsVoid()) {
|
|
|
|
rv = GenerateGUID(guid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("guid"), guid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-11 10:48:14 -08:00
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-28 23:30:04 -07:00
|
|
|
// Post an onFrecencyChanged observer notification.
|
|
|
|
const nsNavHistory* navHistory = nsNavHistory::GetConstHistoryService();
|
|
|
|
NS_ENSURE_STATE(navHistory);
|
|
|
|
navHistory->DispatchFrecencyChangedNotification(aPlace.spec, frecency, guid,
|
|
|
|
aPlace.hidden,
|
|
|
|
aPlace.visitTime);
|
|
|
|
|
2011-01-11 10:48:14 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
History::UpdatePlace(const VisitData& aPlace)
|
|
|
|
{
|
2011-01-18 11:49:39 -08:00
|
|
|
NS_PRECONDITION(!NS_IsMainThread(), "must be called off of the main thread!");
|
2011-01-20 06:35:37 -08:00
|
|
|
NS_PRECONDITION(aPlace.placeId > 0, "must have a valid place id!");
|
|
|
|
NS_PRECONDITION(!aPlace.guid.IsVoid(), "must have a guid!");
|
2011-01-11 10:48:14 -08:00
|
|
|
|
2011-10-27 02:11:34 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt = GetStatement(
|
2011-01-11 10:48:14 -08:00
|
|
|
"UPDATE moz_places "
|
2011-01-20 06:35:37 -08:00
|
|
|
"SET title = :title, "
|
|
|
|
"hidden = :hidden, "
|
|
|
|
"typed = :typed, "
|
|
|
|
"guid = :guid "
|
2011-01-11 10:48:14 -08:00
|
|
|
"WHERE id = :page_id "
|
|
|
|
);
|
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2011-01-20 06:35:37 -08:00
|
|
|
nsresult rv;
|
2011-01-25 09:01:14 -08:00
|
|
|
// Empty strings should clear the title, just like nsNavHistory::SetPageTitle.
|
|
|
|
if (aPlace.title.IsEmpty()) {
|
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("title"));
|
|
|
|
}
|
|
|
|
else {
|
2011-01-20 06:35:37 -08:00
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("title"),
|
|
|
|
StringHead(aPlace.title, TITLE_LENGTH_MAX));
|
|
|
|
}
|
2011-01-25 09:01:14 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-11 10:48:14 -08:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("typed"), aPlace.typed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("hidden"), aPlace.hidden);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-20 06:35:37 -08:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("guid"), aPlace.guid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("page_id"),
|
|
|
|
aPlace.placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-11 10:48:14 -08:00
|
|
|
rv = stmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
nsresult
|
|
|
|
History::FetchPageInfo(VisitData& _place, bool* _exists)
|
2011-01-11 10:48:53 -08:00
|
|
|
{
|
2013-06-19 00:18:38 -07:00
|
|
|
NS_PRECONDITION(!_place.spec.IsEmpty() || !_place.guid.IsEmpty(), "must have either a non-empty spec or guid!");
|
2011-01-11 10:48:53 -08:00
|
|
|
NS_PRECONDITION(!NS_IsMainThread(), "must be called off of the main thread!");
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// URI takes precedence.
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
bool selectByURI = !_place.spec.IsEmpty();
|
|
|
|
if (selectByURI) {
|
|
|
|
stmt = GetStatement(
|
|
|
|
"SELECT guid, id, title, hidden, typed, frecency "
|
2011-01-11 10:48:53 -08:00
|
|
|
"FROM moz_places "
|
|
|
|
"WHERE url = :page_url "
|
|
|
|
);
|
2013-07-03 04:54:31 -07:00
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), _place.spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stmt = GetStatement(
|
|
|
|
"SELECT url, id, title, hidden, typed, frecency "
|
|
|
|
"FROM moz_places "
|
|
|
|
"WHERE guid = :guid "
|
|
|
|
);
|
2013-07-03 04:54:31 -07:00
|
|
|
NS_ENSURE_STATE(stmt);
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("guid"), _place.guid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-01-11 10:48:53 -08:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = stmt->ExecuteStep(_exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-06-18 09:24:31 -07:00
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
if (!*_exists) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectByURI) {
|
|
|
|
if (_place.guid.IsEmpty()) {
|
|
|
|
rv = stmt->GetUTF8String(0, _place.guid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsAutoCString spec;
|
|
|
|
rv = stmt->GetUTF8String(0, spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
_place.spec = spec;
|
2011-01-11 10:48:53 -08:00
|
|
|
}
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = stmt->GetInt64(1, &_place.placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-11 10:48:53 -08:00
|
|
|
|
2011-01-25 09:01:14 -08:00
|
|
|
nsAutoString title;
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = stmt->GetString(2, title);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-25 09:01:14 -08:00
|
|
|
|
2011-01-26 15:56:24 -08:00
|
|
|
// If the title we were given was void, that means we did not bother to set
|
|
|
|
// it to anything. As a result, ignore the fact that we may have changed the
|
|
|
|
// title (because we don't want to, that would be empty), and set the title
|
|
|
|
// to what is currently stored in the datbase.
|
2011-01-20 06:35:37 -08:00
|
|
|
if (_place.title.IsVoid()) {
|
2011-01-25 09:01:14 -08:00
|
|
|
_place.title = title;
|
2011-01-11 10:48:53 -08:00
|
|
|
}
|
2011-01-26 15:56:24 -08:00
|
|
|
// Otherwise, just indicate if the title has changed.
|
|
|
|
else {
|
|
|
|
_place.titleChanged = !(_place.title.Equals(title) ||
|
|
|
|
(_place.title.IsEmpty() && title.IsVoid()));
|
|
|
|
}
|
2011-01-11 10:48:53 -08:00
|
|
|
|
2015-01-27 09:36:40 -08:00
|
|
|
int32_t hidden;
|
|
|
|
rv = stmt->GetInt32(3, &hidden);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
_place.hidden = !!hidden;
|
2011-01-11 10:48:53 -08:00
|
|
|
|
2015-01-27 09:36:40 -08:00
|
|
|
int32_t typed;
|
|
|
|
rv = stmt->GetInt32(4, &typed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
_place.typed = !!typed;
|
2013-06-18 11:46:00 -07:00
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
rv = stmt->GetInt32(5, &_place.frecency);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2011-01-11 10:48:53 -08:00
|
|
|
}
|
|
|
|
|
2013-12-07 22:09:10 -08:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(HistoryMallocSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
History::CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-20 23:06:54 -07:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-11-06 21:35:30 -08:00
|
|
|
{
|
2013-12-07 22:09:10 -08:00
|
|
|
return MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/history-links-hashtable", KIND_HEAP, UNITS_BYTES,
|
|
|
|
SizeOfIncludingThis(HistoryMallocSizeOf),
|
|
|
|
"Memory used by the hashtable that records changes to the visited state "
|
|
|
|
"of links.");
|
2013-11-06 21:35:30 -08:00
|
|
|
}
|
|
|
|
|
2011-12-15 14:59:53 -08:00
|
|
|
size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
History::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOfThis)
|
2011-09-14 17:37:45 -07:00
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOfThis(this) +
|
2014-08-05 13:27:41 -07:00
|
|
|
mObservers.SizeOfExcludingThis(aMallocSizeOfThis);
|
2011-09-14 17:37:45 -07:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
/* static */
|
|
|
|
History*
|
|
|
|
History::GetService()
|
|
|
|
{
|
|
|
|
if (gService) {
|
|
|
|
return gService;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<IHistory> service(do_GetService(NS_IHISTORY_CONTRACTID));
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(service, "Cannot obtain IHistory service!");
|
2009-08-20 11:56:10 -07:00
|
|
|
NS_ASSERTION(gService, "Our constructor was not run?!");
|
|
|
|
|
|
|
|
return gService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
History*
|
|
|
|
History::GetSingleton()
|
|
|
|
{
|
|
|
|
if (!gService) {
|
|
|
|
gService = new History();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(gService, nullptr);
|
2013-11-06 21:35:30 -08:00
|
|
|
gService->InitMemoryReporter();
|
2009-08-20 11:56:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(gService);
|
|
|
|
return gService;
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:43:46 -08:00
|
|
|
mozIStorageConnection*
|
|
|
|
History::GetDBConn()
|
|
|
|
{
|
2014-08-12 01:59:11 -07:00
|
|
|
if (mShuttingDown)
|
|
|
|
return nullptr;
|
2011-10-27 02:11:34 -07:00
|
|
|
if (!mDB) {
|
|
|
|
mDB = Database::GetDatabase();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(mDB, nullptr);
|
2010-11-08 11:43:46 -08:00
|
|
|
}
|
2011-10-27 02:11:34 -07:00
|
|
|
return mDB->MainConn();
|
2010-11-08 11:43:46 -08:00
|
|
|
}
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
void
|
|
|
|
History::Shutdown()
|
|
|
|
{
|
2012-01-24 06:16:33 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-02-01 02:59:27 -08:00
|
|
|
|
|
|
|
// Prevent other threads from scheduling uses of the DB while we mark
|
|
|
|
// ourselves as shutting down.
|
|
|
|
MutexAutoLock lockedScope(mShutdownMutex);
|
2012-01-24 06:16:33 -08:00
|
|
|
MOZ_ASSERT(!mShuttingDown && "Shutdown was called more than once!");
|
2010-11-17 17:23:29 -08:00
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
mShuttingDown = true;
|
|
|
|
|
2014-08-12 01:59:11 -07:00
|
|
|
if (mConcurrentStatementsHolder) {
|
|
|
|
mConcurrentStatementsHolder->Shutdown();
|
2010-10-06 08:21:31 -07:00
|
|
|
}
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2012-03-28 12:50:59 -07:00
|
|
|
void
|
|
|
|
History::AppendToRecentlyVisitedURIs(nsIURI* aURI) {
|
|
|
|
if (mRecentlyVisitedURIs.Length() < RECENTLY_VISITED_URI_SIZE) {
|
|
|
|
// Append a new element while the array is not full.
|
|
|
|
mRecentlyVisitedURIs.AppendElement(aURI);
|
|
|
|
} else {
|
|
|
|
// Otherwise, replace the oldest member.
|
|
|
|
mRecentlyVisitedURIsNextIndex %= RECENTLY_VISITED_URI_SIZE;
|
|
|
|
mRecentlyVisitedURIs.ElementAt(mRecentlyVisitedURIsNextIndex) = aURI;
|
|
|
|
mRecentlyVisitedURIsNextIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
History::IsRecentlyVisitedURI(nsIURI* aURI) {
|
|
|
|
bool equals = false;
|
|
|
|
RecentlyVisitedArray::index_type i;
|
|
|
|
for (i = 0; i < mRecentlyVisitedURIs.Length() && !equals; ++i) {
|
|
|
|
aURI->Equals(mRecentlyVisitedURIs.ElementAt(i), &equals);
|
|
|
|
}
|
|
|
|
return equals;
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// IHistory
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
History::VisitURI(nsIURI* aURI,
|
|
|
|
nsIURI* aLastVisitedURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURI, "URI should not be NULL.");
|
|
|
|
if (mShuttingDown) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:50:24 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
2012-08-23 12:33:46 -07:00
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(aURI, uri);
|
|
|
|
|
|
|
|
OptionalURIParams lastVisitedURI;
|
|
|
|
SerializeURI(aLastVisitedURI, lastVisitedURI);
|
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
mozilla::dom::ContentChild* cpc =
|
2010-07-02 08:50:24 -07:00
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
NS_ASSERTION(cpc, "Content Protocol is NULL!");
|
2012-08-23 12:33:46 -07:00
|
|
|
(void)cpc->SendVisitURI(uri, lastVisitedURI, aFlags);
|
2010-07-02 08:50:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(navHistory, NS_ERROR_OUT_OF_MEMORY);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
|
|
|
// Silently return if URI is something we shouldn't add to DB.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canAdd;
|
2010-11-12 14:24:25 -08:00
|
|
|
nsresult rv = navHistory->CanAddURI(aURI, &canAdd);
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!canAdd) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLastVisitedURI) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool same;
|
2010-11-08 11:42:08 -08:00
|
|
|
rv = aURI->Equals(aLastVisitedURI, &same);
|
2010-07-13 18:00:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-03-28 12:50:59 -07:00
|
|
|
if (same && IsRecentlyVisitedURI(aURI)) {
|
|
|
|
// Do not save refresh visits if we have visited this URI recently.
|
2010-11-08 11:42:08 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 11:13:17 -08:00
|
|
|
nsTArray<VisitData> placeArray(1);
|
|
|
|
NS_ENSURE_TRUE(placeArray.AppendElement(VisitData(aURI, aLastVisitedURI)),
|
|
|
|
NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
VisitData& place = placeArray.ElementAt(0);
|
2011-01-11 10:34:04 -08:00
|
|
|
NS_ENSURE_FALSE(place.spec.IsEmpty(), NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
place.visitTime = PR_Now();
|
2010-07-13 18:00:33 -07:00
|
|
|
|
|
|
|
// Assigns a type to the edge in the visit linked list. Each type will be
|
|
|
|
// considered differently when weighting the frecency of a location.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t recentFlags = navHistory->GetRecentFlags(aURI);
|
2010-11-12 14:24:25 -08:00
|
|
|
bool isFollowedLink = recentFlags & nsNavHistory::RECENT_ACTIVATED;
|
|
|
|
|
|
|
|
// Embed visits should never be added to the database, and the same is valid
|
|
|
|
// for redirects across frames.
|
|
|
|
// For the above reasoning non-toplevel transitions are handled at first.
|
|
|
|
// if the visit is toplevel or a non-toplevel followed link, then it can be
|
|
|
|
// handled as usual and stored on disk.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t transitionType = nsINavHistoryService::TRANSITION_LINK;
|
2012-04-06 16:17:49 -07:00
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
if (!(aFlags & IHistory::TOP_LEVEL) && !isFollowedLink) {
|
|
|
|
// A frame redirected to a new site without user interaction.
|
2012-04-06 16:17:49 -07:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_EMBED;
|
2010-11-12 14:24:25 -08:00
|
|
|
}
|
|
|
|
else if (aFlags & IHistory::REDIRECT_TEMPORARY) {
|
2012-04-06 16:17:49 -07:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
else if (aFlags & IHistory::REDIRECT_PERMANENT) {
|
2012-04-06 16:17:49 -07:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
2013-06-10 14:59:15 -07:00
|
|
|
else if ((recentFlags & nsNavHistory::RECENT_TYPED) &&
|
|
|
|
!(aFlags & IHistory::UNRECOVERABLE_ERROR)) {
|
|
|
|
// Don't mark error pages as typed, even if they were actually typed by
|
|
|
|
// the user. This is useful to limit their score in autocomplete.
|
2012-04-06 16:17:49 -07:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_TYPED;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
else if (recentFlags & nsNavHistory::RECENT_BOOKMARKED) {
|
2012-04-06 16:17:49 -07:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_BOOKMARK;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
2010-11-12 14:24:25 -08:00
|
|
|
else if (!(aFlags & IHistory::TOP_LEVEL) && isFollowedLink) {
|
2010-07-13 18:00:33 -07:00
|
|
|
// User activated a link in a frame.
|
2012-04-06 16:17:49 -07:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_FRAMED_LINK;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
2012-04-06 16:17:49 -07:00
|
|
|
|
|
|
|
place.SetTransitionType(transitionType);
|
|
|
|
place.hidden = GetHiddenState(aFlags & IHistory::REDIRECT_SOURCE,
|
|
|
|
transitionType);
|
|
|
|
|
|
|
|
// Error pages should never be autocompleted.
|
|
|
|
if (aFlags & IHistory::UNRECOVERABLE_ERROR) {
|
2013-07-16 06:36:08 -07:00
|
|
|
place.shouldUpdateFrecency = false;
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
// EMBED visits are session-persistent and should not go through the database.
|
|
|
|
// They exist only to keep track of isVisited status during the session.
|
|
|
|
if (place.transitionType == nsINavHistoryService::TRANSITION_EMBED) {
|
2011-01-12 10:22:39 -08:00
|
|
|
StoreAndNotifyEmbedVisit(place);
|
2010-11-12 14:24:25 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
2010-11-08 11:43:46 -08:00
|
|
|
|
2011-01-11 11:13:17 -08:00
|
|
|
rv = InsertVisitedURIs::Start(dbConn, placeArray);
|
2010-11-12 14:24:25 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-11-08 11:42:08 -08:00
|
|
|
// Finally, notify that we've been visited.
|
2010-07-13 18:00:33 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
2012-07-30 07:20:58 -07:00
|
|
|
obsService->NotifyObservers(aURI, NS_LINK_VISITED_EVENT_TOPIC, nullptr);
|
2010-07-13 18:00:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
History::RegisterVisitedCallback(nsIURI* aURI,
|
|
|
|
Link* aLink)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aURI, "Must pass a non-null URI!");
|
2010-07-02 08:50:41 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
2010-08-01 23:38:10 -07:00
|
|
|
NS_PRECONDITION(aLink, "Must pass a non-null Link!");
|
2010-07-02 08:50:41 -07:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
// Obtain our array of observers for this URI.
|
2010-03-03 12:55:37 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool keyAlreadyExists = !!mObservers.GetEntry(aURI);
|
|
|
|
#endif
|
2009-08-20 11:56:10 -07:00
|
|
|
KeyClass* key = mObservers.PutEntry(aURI);
|
|
|
|
NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
ObserverArray& observers = key->array;
|
|
|
|
|
|
|
|
if (observers.IsEmpty()) {
|
2010-03-03 12:55:37 -08:00
|
|
|
NS_ASSERTION(!keyAlreadyExists,
|
|
|
|
"An empty key was kept around in our hashtable!");
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
// We are the first Link node to ask about this URI, or there are no pending
|
|
|
|
// Links wanting to know about this URI. Therefore, we should query the
|
|
|
|
// database now.
|
|
|
|
nsresult rv = VisitedQuery::Start(aURI);
|
2010-10-27 13:14:16 -07:00
|
|
|
|
2013-10-10 13:38:05 -07:00
|
|
|
// In IPC builds, we are passed a nullptr Link from
|
|
|
|
// ContentParent::RecvStartVisitedQuery. Since we won't be adding a
|
|
|
|
// nullptr entry to our list of observers, and the code after this point
|
|
|
|
// assumes that aLink is non-nullptr, we will need to return now.
|
2010-07-02 08:50:41 -07:00
|
|
|
if (NS_FAILED(rv) || !aLink) {
|
2010-03-03 12:55:37 -08:00
|
|
|
// Remove our array from the hashtable so we don't keep it around.
|
|
|
|
mObservers.RemoveEntry(aURI);
|
2009-08-20 11:56:10 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2013-10-10 13:38:05 -07:00
|
|
|
// In IPC builds, we are passed a nullptr Link from
|
2010-10-27 13:14:16 -07:00
|
|
|
// ContentParent::RecvStartVisitedQuery. All of our code after this point
|
2013-10-10 13:38:05 -07:00
|
|
|
// assumes aLink is non-nullptr, so we have to return now.
|
2010-10-27 13:14:16 -07:00
|
|
|
else if (!aLink) {
|
|
|
|
NS_ASSERTION(XRE_GetProcessType() == GeckoProcessType_Default,
|
|
|
|
"We should only ever get a null Link in the default process!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-08-20 11:56:10 -07:00
|
|
|
|
|
|
|
// Sanity check that Links are not registered more than once for a given URI.
|
|
|
|
// This will not catch a case where it is registered for two different URIs.
|
|
|
|
NS_ASSERTION(!observers.Contains(aLink),
|
|
|
|
"Already tracking this Link object!");
|
|
|
|
|
|
|
|
// Start tracking our Link.
|
|
|
|
if (!observers.AppendElement(aLink)) {
|
|
|
|
// Curses - unregister and return failure.
|
|
|
|
(void)UnregisterVisitedCallback(aURI, aLink);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
History::UnregisterVisitedCallback(nsIURI* aURI,
|
|
|
|
Link* aLink)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aURI, "Must pass a non-null URI!");
|
|
|
|
NS_ASSERTION(aLink, "Must pass a non-null Link object!");
|
|
|
|
|
|
|
|
// Get the array, and remove the item from it.
|
|
|
|
KeyClass* key = mObservers.GetEntry(aURI);
|
|
|
|
if (!key) {
|
|
|
|
NS_ERROR("Trying to unregister for a URI that wasn't registered!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
ObserverArray& observers = key->array;
|
|
|
|
if (!observers.RemoveElement(aLink)) {
|
|
|
|
NS_ERROR("Trying to unregister a node that wasn't registered!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the array is now empty, we should remove it from the hashtable.
|
|
|
|
if (observers.IsEmpty()) {
|
|
|
|
mObservers.RemoveEntry(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-13 18:00:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
History::SetURITitle(nsIURI* aURI, const nsAString& aTitle)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURI, "Must pass a non-null URI!");
|
|
|
|
if (mShuttingDown) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:53:42 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
2012-08-23 12:33:46 -07:00
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(aURI, uri);
|
|
|
|
|
2010-07-02 08:53:42 -07:00
|
|
|
mozilla::dom::ContentChild * cpc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
NS_ASSERTION(cpc, "Content Protocol is NULL!");
|
2012-12-22 12:40:37 -08:00
|
|
|
(void)cpc->SendSetURITitle(uri, PromiseFlatString(aTitle));
|
2010-07-02 08:53:42 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
2010-07-13 18:00:41 -07:00
|
|
|
|
|
|
|
// At first, it seems like nav history should always be available here, no
|
|
|
|
// matter what.
|
|
|
|
//
|
|
|
|
// nsNavHistory fails to register as a service if there is no profile in
|
|
|
|
// place (for instance, if user is choosing a profile).
|
|
|
|
//
|
|
|
|
// Maybe the correct thing to do is to not register this service if no
|
|
|
|
// profile has been selected?
|
|
|
|
//
|
2010-11-12 14:24:25 -08:00
|
|
|
NS_ENSURE_TRUE(navHistory, NS_ERROR_FAILURE);
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canAdd;
|
2010-11-12 14:24:25 -08:00
|
|
|
nsresult rv = navHistory->CanAddURI(aURI, &canAdd);
|
2010-07-13 18:00:41 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!canAdd) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
// Embed visits don't have a database entry, thus don't set a title on them.
|
|
|
|
if (navHistory->hasEmbedVisit(aURI)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:45:46 -08:00
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
|
|
|
|
2011-01-25 09:01:14 -08:00
|
|
|
rv = SetPageTitle::Start(dbConn, aURI, aTitle);
|
2010-11-08 11:45:46 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-07-13 18:00:41 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-20 04:48:20 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIDownloadHistory
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
History::AddDownload(nsIURI* aSource, nsIURI* aReferrer,
|
|
|
|
PRTime aStartTime, nsIURI* aDestination)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
NS_ENSURE_ARG(aSource);
|
|
|
|
|
|
|
|
if (mShuttingDown) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
NS_ERROR("Cannot add downloads to history from content process!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(navHistory, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Silently return if URI is something we shouldn't add to DB.
|
|
|
|
bool canAdd;
|
|
|
|
nsresult rv = navHistory->CanAddURI(aSource, &canAdd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!canAdd) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<VisitData> placeArray(1);
|
|
|
|
NS_ENSURE_TRUE(placeArray.AppendElement(VisitData(aSource, aReferrer)),
|
|
|
|
NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
VisitData& place = placeArray.ElementAt(0);
|
|
|
|
NS_ENSURE_FALSE(place.spec.IsEmpty(), NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
place.visitTime = aStartTime;
|
|
|
|
place.SetTransitionType(nsINavHistoryService::TRANSITION_DOWNLOAD);
|
2012-04-06 16:17:49 -07:00
|
|
|
place.hidden = false;
|
2012-01-20 04:48:20 -08:00
|
|
|
|
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback> callback;
|
|
|
|
if (aDestination) {
|
|
|
|
callback = new nsMainThreadPtrHolder<mozIVisitInfoCallback>(new SetDownloadAnnotations(aDestination));
|
|
|
|
}
|
2012-01-20 04:48:20 -08:00
|
|
|
|
|
|
|
rv = InsertVisitedURIs::Start(dbConn, placeArray, callback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Finally, notify that we've been visited.
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obsService) {
|
2012-07-30 07:20:58 -07:00
|
|
|
obsService->NotifyObservers(aSource, NS_LINK_VISITED_EVENT_TOPIC, nullptr);
|
2012-01-20 04:48:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-05 01:21:04 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
History::RemoveAllDownloads()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mShuttingDown) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
NS_ERROR("Cannot remove downloads to history from content process!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure navHistory is initialized.
|
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
|
|
|
NS_ENSURE_TRUE(navHistory, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
|
|
|
|
|
|
|
RemoveVisitsFilter filter;
|
|
|
|
filter.transitionType = nsINavHistoryService::TRANSITION_DOWNLOAD;
|
|
|
|
|
|
|
|
nsresult rv = RemoveVisits::Start(dbConn, filter);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-13 13:37:04 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// mozIAsyncHistory
|
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
History::GetPlacesInfo(JS::Handle<JS::Value> aPlaceIdentifiers,
|
2013-06-19 00:18:38 -07:00
|
|
|
mozIVisitInfoCallback* aCallback,
|
2014-08-10 14:26:52 -07:00
|
|
|
JSContext* aCtx)
|
|
|
|
{
|
|
|
|
// Make sure nsNavHistory service is up before proceeding:
|
2013-06-19 00:18:38 -07:00
|
|
|
nsNavHistory* navHistory = nsNavHistory::GetHistoryService();
|
2014-08-10 14:26:52 -07:00
|
|
|
MOZ_ASSERT(navHistory, "Could not get nsNavHistory?!");
|
|
|
|
if (!navHistory) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-06-19 00:18:38 -07:00
|
|
|
|
|
|
|
uint32_t placesIndentifiersLength;
|
|
|
|
JS::Rooted<JSObject*> placesIndentifiers(aCtx);
|
|
|
|
nsresult rv = GetJSArrayFromJSValue(aPlaceIdentifiers, aCtx,
|
2014-01-17 10:08:51 -08:00
|
|
|
&placesIndentifiers,
|
2013-06-19 00:18:38 -07:00
|
|
|
&placesIndentifiersLength);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsTArray<VisitData> placesInfo;
|
|
|
|
placesInfo.SetCapacity(placesIndentifiersLength);
|
|
|
|
for (uint32_t i = 0; i < placesIndentifiersLength; i++) {
|
2013-08-05 06:02:47 -07:00
|
|
|
JS::Rooted<JS::Value> placeIdentifier(aCtx);
|
2013-08-08 15:53:04 -07:00
|
|
|
bool rc = JS_GetElement(aCtx, placesIndentifiers, i, &placeIdentifier);
|
2013-06-19 00:18:38 -07:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// GUID
|
|
|
|
nsAutoString fatGUID;
|
|
|
|
GetJSValueAsString(aCtx, placeIdentifier, fatGUID);
|
|
|
|
if (!fatGUID.IsVoid()) {
|
|
|
|
NS_ConvertUTF16toUTF8 guid(fatGUID);
|
|
|
|
if (!IsValidGUID(guid))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
VisitData& placeInfo = *placesInfo.AppendElement(VisitData());
|
|
|
|
placeInfo.guid = guid;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIURI> uri = GetJSValueAsURI(aCtx, placeIdentifier);
|
|
|
|
if (!uri)
|
|
|
|
return NS_ERROR_INVALID_ARG; // neither a guid, nor a uri.
|
2013-06-28 11:04:14 -07:00
|
|
|
placesInfo.AppendElement(VisitData(uri));
|
2013-06-19 00:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
|
|
|
|
|
|
|
for (nsTArray<VisitData>::size_type i = 0; i < placesInfo.Length(); i++) {
|
|
|
|
nsresult rv = GetPlaceInfo::Start(dbConn, placesInfo.ElementAt(i), aCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Be sure to notify that all of our operations are complete. This
|
|
|
|
// is dispatched to the background thread first and redirected to the
|
|
|
|
// main thread from there to make sure that all database notifications
|
|
|
|
// and all embed or canAddURI notifications have finished.
|
|
|
|
if (aCallback) {
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitInfoCallback>(aCallback));
|
2013-06-19 00:18:38 -07:00
|
|
|
nsCOMPtr<nsIEventTarget> backgroundThread = do_GetInterface(dbConn);
|
|
|
|
NS_ENSURE_TRUE(backgroundThread, NS_ERROR_UNEXPECTED);
|
2014-09-16 05:17:31 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event = new NotifyCompletion(callback);
|
2013-06-19 00:18:38 -07:00
|
|
|
return backgroundThread->Dispatch(event, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-13 13:37:04 -08:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 09:39:36 -08:00
|
|
|
History::UpdatePlaces(JS::Handle<JS::Value> aPlaceInfos,
|
2011-01-13 13:37:04 -08:00
|
|
|
mozIVisitInfoCallback* aCallback,
|
|
|
|
JSContext* aCtx)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_UNEXPECTED);
|
2014-04-27 20:27:54 -07:00
|
|
|
NS_ENSURE_TRUE(!aPlaceInfos.isPrimitive(), NS_ERROR_INVALID_ARG);
|
2011-01-13 13:37:04 -08:00
|
|
|
|
2013-06-19 00:18:38 -07:00
|
|
|
uint32_t infosLength;
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JSObject*> infos(aCtx);
|
2014-01-17 10:08:51 -08:00
|
|
|
nsresult rv = GetJSArrayFromJSValue(aPlaceInfos, aCtx, &infos, &infosLength);
|
2013-06-19 00:18:38 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-21 20:09:10 -08:00
|
|
|
|
|
|
|
nsTArray<VisitData> visitData;
|
2012-03-06 15:52:55 -08:00
|
|
|
for (uint32_t i = 0; i < infosLength; i++) {
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JSObject*> info(aCtx);
|
2014-01-29 02:00:40 -08:00
|
|
|
nsresult rv = GetJSObjectFromArray(aCtx, infos, i, &info);
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = GetURIFromJSObject(aCtx, info, "uri");
|
|
|
|
nsCString guid;
|
|
|
|
{
|
|
|
|
nsString fatGUID;
|
|
|
|
GetStringFromJSObject(aCtx, info, "guid", fatGUID);
|
|
|
|
if (fatGUID.IsVoid()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
guid.SetIsVoid(true);
|
2011-01-21 20:09:10 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
guid = NS_ConvertUTF16toUTF8(fatGUID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-24 14:13:24 -08:00
|
|
|
// Make sure that any uri we are given can be added to history, and if not,
|
|
|
|
// skip it (CanAddURI will notify our callback for us).
|
2011-02-03 14:09:37 -08:00
|
|
|
if (uri && !CanAddURI(uri, guid, aCallback)) {
|
2011-01-24 14:13:24 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-03 14:09:37 -08:00
|
|
|
// We must have at least one of uri or guid.
|
|
|
|
NS_ENSURE_ARG(uri || !guid.IsVoid());
|
2011-01-21 20:09:10 -08:00
|
|
|
|
|
|
|
// If we were given a guid, make sure it is valid.
|
|
|
|
bool isValidGUID = IsValidGUID(guid);
|
|
|
|
NS_ENSURE_ARG(guid.IsVoid() || isValidGUID);
|
|
|
|
|
|
|
|
nsString title;
|
|
|
|
GetStringFromJSObject(aCtx, info, "title", title);
|
|
|
|
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JSObject*> visits(aCtx, nullptr);
|
2011-01-21 20:09:10 -08:00
|
|
|
{
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JS::Value> visitsVal(aCtx);
|
2013-08-08 15:53:04 -07:00
|
|
|
bool rc = JS_GetProperty(aCtx, info, "visits", &visitsVal);
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
|
2014-04-27 20:27:54 -07:00
|
|
|
if (!visitsVal.isPrimitive()) {
|
2014-04-27 19:58:52 -07:00
|
|
|
visits = visitsVal.toObjectOrNull();
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_ARG(JS_IsArrayObject(aCtx, visits));
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 11:25:37 -08:00
|
|
|
NS_ENSURE_ARG(visits);
|
2011-01-21 20:09:10 -08:00
|
|
|
|
2012-03-06 15:52:55 -08:00
|
|
|
uint32_t visitsLength = 0;
|
2011-01-21 20:09:10 -08:00
|
|
|
if (visits) {
|
|
|
|
(void)JS_GetArrayLength(aCtx, visits, &visitsLength);
|
|
|
|
}
|
2011-01-25 11:25:37 -08:00
|
|
|
NS_ENSURE_ARG(visitsLength > 0);
|
2011-01-21 20:09:10 -08:00
|
|
|
|
|
|
|
// Check each visit, and build our array of VisitData objects.
|
|
|
|
visitData.SetCapacity(visitData.Length() + visitsLength);
|
2012-03-06 15:52:55 -08:00
|
|
|
for (uint32_t j = 0; j < visitsLength; j++) {
|
2013-05-01 15:43:53 -07:00
|
|
|
JS::Rooted<JSObject*> visit(aCtx);
|
2014-01-29 02:00:40 -08:00
|
|
|
rv = GetJSObjectFromArray(aCtx, visits, j, &visit);
|
2011-01-21 20:09:10 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
VisitData& data = *visitData.AppendElement(VisitData(uri));
|
|
|
|
data.title = title;
|
|
|
|
data.guid = guid;
|
|
|
|
|
|
|
|
// We must have a date and a transaction type!
|
|
|
|
rv = GetIntFromJSObject(aCtx, visit, "visitDate", &data.visitTime);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t transitionType = 0;
|
2011-01-21 20:09:10 -08:00
|
|
|
rv = GetIntFromJSObject(aCtx, visit, "transitionType", &transitionType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_ARG_RANGE(transitionType,
|
|
|
|
nsINavHistoryService::TRANSITION_LINK,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK);
|
|
|
|
data.SetTransitionType(transitionType);
|
2012-04-06 16:17:49 -07:00
|
|
|
data.hidden = GetHiddenState(false, transitionType);
|
2011-01-21 20:09:10 -08:00
|
|
|
|
|
|
|
// If the visit is an embed visit, we do not actually add it to the
|
|
|
|
// database.
|
|
|
|
if (transitionType == nsINavHistoryService::TRANSITION_EMBED) {
|
|
|
|
StoreAndNotifyEmbedVisit(data, aCallback);
|
|
|
|
visitData.RemoveElementAt(visitData.Length() - 1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The referrer is optional.
|
|
|
|
nsCOMPtr<nsIURI> referrer = GetURIFromJSObject(aCtx, visit,
|
|
|
|
"referrerURI");
|
|
|
|
if (referrer) {
|
|
|
|
(void)referrer->GetSpec(data.referrerSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-25 09:41:42 -08:00
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_STATE(dbConn);
|
|
|
|
|
2014-09-16 05:17:31 -07:00
|
|
|
nsMainThreadPtrHandle<mozIVisitInfoCallback>
|
|
|
|
callback(new nsMainThreadPtrHolder<mozIVisitInfoCallback>(aCallback));
|
|
|
|
|
2011-01-24 14:13:24 -08:00
|
|
|
// It is possible that all of the visits we were passed were dissallowed by
|
|
|
|
// CanAddURI, which isn't an error. If we have no visits to add, however,
|
|
|
|
// we should not call InsertVisitedURIs::Start.
|
|
|
|
if (visitData.Length()) {
|
2014-09-16 05:17:31 -07:00
|
|
|
nsresult rv = InsertVisitedURIs::Start(dbConn, visitData, callback);
|
2011-01-24 14:13:24 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-01-21 20:09:10 -08:00
|
|
|
|
2011-08-19 10:11:41 -07:00
|
|
|
// Be sure to notify that all of our operations are complete. This
|
|
|
|
// is dispatched to the background thread first and redirected to the
|
|
|
|
// main thread from there to make sure that all database notifications
|
|
|
|
// and all embed or canAddURI notifications have finished.
|
|
|
|
if (aCallback) {
|
|
|
|
nsCOMPtr<nsIEventTarget> backgroundThread = do_GetInterface(dbConn);
|
|
|
|
NS_ENSURE_TRUE(backgroundThread, NS_ERROR_UNEXPECTED);
|
2014-09-16 05:17:31 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event = new NotifyCompletion(callback);
|
2013-06-19 00:18:38 -07:00
|
|
|
return backgroundThread->Dispatch(event, NS_DISPATCH_NORMAL);
|
2011-08-19 10:11:41 -07:00
|
|
|
}
|
2011-01-25 09:41:42 -08:00
|
|
|
|
2011-01-21 20:09:10 -08:00
|
|
|
return NS_OK;
|
2011-01-13 13:37:04 -08:00
|
|
|
}
|
|
|
|
|
2011-11-29 15:48:47 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
History::IsURIVisited(nsIURI* aURI,
|
|
|
|
mozIVisitedStatusCallback* aCallback)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(NS_IsMainThread());
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG(aCallback);
|
|
|
|
|
|
|
|
nsresult rv = VisitedQuery::Start(aURI, aCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
History::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aData)
|
2010-07-13 18:00:33 -07:00
|
|
|
{
|
|
|
|
if (strcmp(aTopic, TOPIC_PLACES_SHUTDOWN) == 0) {
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
(void)os->RemoveObserver(this, TOPIC_PLACES_SHUTDOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-20 11:56:10 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsISupports
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(
|
2010-07-13 18:00:33 -07:00
|
|
|
History
|
|
|
|
, IHistory
|
2012-01-20 04:48:20 -08:00
|
|
|
, nsIDownloadHistory
|
2011-01-13 13:37:04 -08:00
|
|
|
, mozIAsyncHistory
|
2010-07-13 18:00:33 -07:00
|
|
|
, nsIObserver
|
2013-12-07 22:09:10 -08:00
|
|
|
, nsIMemoryReporter
|
2009-08-20 11:56:10 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|