2006-07-18 16:57:27 +00:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:01:45 +00:00
|
|
|
/**
|
|
|
|
* This file contains the definitions of nsNavHistoryQuery,
|
|
|
|
* nsNavHistoryQueryOptions, and those functions in nsINavHistory that directly
|
|
|
|
* support queries (specifically QueryStringToQueries and QueriesToQueryString).
|
|
|
|
*/
|
|
|
|
|
2012-12-14 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
#include "nsNavHistory.h"
|
2008-03-15 19:39:04 +00:00
|
|
|
#include "nsNavBookmarks.h"
|
2006-07-18 16:57:27 +00:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsCOMArray.h"
|
2006-07-18 17:02:16 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsTArray.h"
|
2006-07-18 16:57:27 +00:00
|
|
|
#include "prprf.h"
|
2011-05-10 01:10:25 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
class QueryKeyValuePair
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// QueryKeyValuePair
|
|
|
|
//
|
|
|
|
// 01234567890
|
|
|
|
// input : qwerty&key=value&qwerty
|
|
|
|
// ^ ^ ^
|
2013-10-10 20:38:05 +00:00
|
|
|
// aKeyBegin | aPastEnd (may point to null terminator)
|
2006-07-18 17:02:16 +00:00
|
|
|
// aEquals
|
|
|
|
//
|
|
|
|
// Special case: if aKeyBegin == aEquals, then there is only one string
|
|
|
|
// and no equal sign, so we treat the entire thing as a key with no value
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
QueryKeyValuePair(const nsCSubstring& aSource, int32_t aKeyBegin,
|
|
|
|
int32_t aEquals, int32_t aPastEnd)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
|
|
|
if (aEquals == aKeyBegin)
|
|
|
|
aEquals = aPastEnd;
|
|
|
|
key = Substring(aSource, aKeyBegin, aEquals - aKeyBegin);
|
|
|
|
if (aPastEnd - aEquals > 0)
|
|
|
|
value = Substring(aSource, aEquals + 1, aPastEnd - aEquals - 1);
|
|
|
|
}
|
|
|
|
nsCString key;
|
|
|
|
nsCString value;
|
|
|
|
};
|
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
static nsresult TokenizeQueryString(const nsACString& aQuery,
|
2006-07-18 17:02:16 +00:00
|
|
|
nsTArray<QueryKeyValuePair>* aTokens);
|
2006-07-18 16:57:27 +00:00
|
|
|
static nsresult ParseQueryBooleanString(const nsCString& aString,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aValue);
|
2006-07-18 17:02:16 +00:00
|
|
|
|
2006-07-18 17:02:55 +00:00
|
|
|
// query getters
|
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, BoolQueryGetter, nsINavHistoryQuery,
|
2011-09-29 06:19:26 +00:00
|
|
|
GetOnlyBookmarked, (bool*));
|
2006-07-18 17:02:55 +00:00
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, Uint32QueryGetter, nsINavHistoryQuery,
|
2012-08-22 15:56:38 +00:00
|
|
|
GetBeginTimeReference, (uint32_t*));
|
2006-07-18 17:02:55 +00:00
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, Int64QueryGetter, nsINavHistoryQuery,
|
2012-08-22 15:56:38 +00:00
|
|
|
GetBeginTime, (int64_t*));
|
2006-07-18 17:02:16 +00:00
|
|
|
static void AppendBoolKeyValueIfTrue(nsACString& aString,
|
|
|
|
const nsCString& aName,
|
|
|
|
nsINavHistoryQuery* aQuery,
|
2006-07-18 17:02:55 +00:00
|
|
|
BoolQueryGetter getter);
|
2006-07-18 17:02:16 +00:00
|
|
|
static void AppendUint32KeyValueIfNonzero(nsACString& aString,
|
|
|
|
const nsCString& aName,
|
|
|
|
nsINavHistoryQuery* aQuery,
|
2006-07-18 17:02:55 +00:00
|
|
|
Uint32QueryGetter getter);
|
2006-07-18 17:02:16 +00:00
|
|
|
static void AppendInt64KeyValueIfNonzero(nsACString& aString,
|
|
|
|
const nsCString& aName,
|
|
|
|
nsINavHistoryQuery* aQuery,
|
2006-07-18 17:02:55 +00:00
|
|
|
Int64QueryGetter getter);
|
|
|
|
|
|
|
|
// query setters
|
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, BoolQuerySetter, nsINavHistoryQuery,
|
2011-09-29 06:19:26 +00:00
|
|
|
SetOnlyBookmarked, (bool));
|
2006-07-18 17:02:55 +00:00
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, Uint32QuerySetter, nsINavHistoryQuery,
|
2012-08-22 15:56:38 +00:00
|
|
|
SetBeginTimeReference, (uint32_t));
|
2006-07-18 17:02:55 +00:00
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, Int64QuerySetter, nsINavHistoryQuery,
|
2012-08-22 15:56:38 +00:00
|
|
|
SetBeginTime, (int64_t));
|
2006-07-18 17:02:55 +00:00
|
|
|
static void SetQueryKeyBool(const nsCString& aValue, nsINavHistoryQuery* aQuery,
|
|
|
|
BoolQuerySetter setter);
|
|
|
|
static void SetQueryKeyUint32(const nsCString& aValue, nsINavHistoryQuery* aQuery,
|
|
|
|
Uint32QuerySetter setter);
|
|
|
|
static void SetQueryKeyInt64(const nsCString& aValue, nsINavHistoryQuery* aQuery,
|
|
|
|
Int64QuerySetter setter);
|
|
|
|
|
|
|
|
// options setters
|
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, BoolOptionsSetter,
|
|
|
|
nsINavHistoryQueryOptions,
|
2011-09-29 06:19:26 +00:00
|
|
|
SetExpandQueries, (bool));
|
2006-07-18 17:02:55 +00:00
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, Uint32OptionsSetter,
|
|
|
|
nsINavHistoryQueryOptions,
|
2012-08-22 15:56:38 +00:00
|
|
|
SetMaxResults, (uint32_t));
|
2007-04-25 21:03:29 +00:00
|
|
|
typedef NS_STDCALL_FUNCPROTO(nsresult, Uint16OptionsSetter,
|
|
|
|
nsINavHistoryQueryOptions,
|
2012-08-22 15:56:38 +00:00
|
|
|
SetResultType, (uint16_t));
|
2006-07-18 17:02:55 +00:00
|
|
|
static void SetOptionsKeyBool(const nsCString& aValue,
|
|
|
|
nsINavHistoryQueryOptions* aOptions,
|
|
|
|
BoolOptionsSetter setter);
|
2007-04-25 21:03:29 +00:00
|
|
|
static void SetOptionsKeyUint16(const nsCString& aValue,
|
|
|
|
nsINavHistoryQueryOptions* aOptions,
|
|
|
|
Uint16OptionsSetter setter);
|
2006-07-18 17:02:55 +00:00
|
|
|
static void SetOptionsKeyUint32(const nsCString& aValue,
|
|
|
|
nsINavHistoryQueryOptions* aOptions,
|
|
|
|
Uint32OptionsSetter setter);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// Components of a query string.
|
|
|
|
// Note that query strings are also generated in nsNavBookmarks::GetFolderURI
|
|
|
|
// for performance reasons, so if you change these values, change that, too.
|
2006-07-18 16:57:27 +00:00
|
|
|
#define QUERYKEY_BEGIN_TIME "beginTime"
|
2006-07-18 16:59:13 +00:00
|
|
|
#define QUERYKEY_BEGIN_TIME_REFERENCE "beginTimeRef"
|
2006-07-18 16:57:27 +00:00
|
|
|
#define QUERYKEY_END_TIME "endTime"
|
2006-07-18 16:59:13 +00:00
|
|
|
#define QUERYKEY_END_TIME_REFERENCE "endTimeRef"
|
2006-07-18 16:57:27 +00:00
|
|
|
#define QUERYKEY_SEARCH_TERMS "terms"
|
2007-02-16 22:55:10 +00:00
|
|
|
#define QUERYKEY_MIN_VISITS "minVisits"
|
|
|
|
#define QUERYKEY_MAX_VISITS "maxVisits"
|
2006-07-18 16:57:27 +00:00
|
|
|
#define QUERYKEY_ONLY_BOOKMARKED "onlyBookmarked"
|
|
|
|
#define QUERYKEY_DOMAIN_IS_HOST "domainIsHost"
|
|
|
|
#define QUERYKEY_DOMAIN "domain"
|
2006-07-18 17:04:51 +00:00
|
|
|
#define QUERYKEY_FOLDER "folder"
|
2006-07-18 17:04:27 +00:00
|
|
|
#define QUERYKEY_NOTANNOTATION "!annotation"
|
|
|
|
#define QUERYKEY_ANNOTATION "annotation"
|
2006-07-18 17:02:16 +00:00
|
|
|
#define QUERYKEY_URI "uri"
|
|
|
|
#define QUERYKEY_URIISPREFIX "uriIsPrefix"
|
2006-07-18 16:57:27 +00:00
|
|
|
#define QUERYKEY_SEPARATOR "OR"
|
|
|
|
#define QUERYKEY_GROUP "group"
|
|
|
|
#define QUERYKEY_SORT "sort"
|
2007-04-27 10:04:13 +00:00
|
|
|
#define QUERYKEY_SORTING_ANNOTATION "sortingAnnotation"
|
2006-07-18 16:57:27 +00:00
|
|
|
#define QUERYKEY_RESULT_TYPE "type"
|
2006-07-18 17:04:04 +00:00
|
|
|
#define QUERYKEY_EXCLUDE_ITEMS "excludeItems"
|
|
|
|
#define QUERYKEY_EXCLUDE_QUERIES "excludeQueries"
|
2006-07-18 17:06:01 +00:00
|
|
|
#define QUERYKEY_EXCLUDE_READ_ONLY_FOLDERS "excludeReadOnlyFolders"
|
2006-07-18 17:04:04 +00:00
|
|
|
#define QUERYKEY_EXPAND_QUERIES "expandQueries"
|
2006-07-18 17:00:59 +00:00
|
|
|
#define QUERYKEY_FORCE_ORIGINAL_TITLE "originalTitle"
|
2006-07-18 17:01:22 +00:00
|
|
|
#define QUERYKEY_INCLUDE_HIDDEN "includeHidden"
|
|
|
|
#define QUERYKEY_MAX_RESULTS "maxResults"
|
2007-04-25 21:03:29 +00:00
|
|
|
#define QUERYKEY_QUERY_TYPE "queryType"
|
2009-05-05 03:40:34 +00:00
|
|
|
#define QUERYKEY_TAG "tag"
|
|
|
|
#define QUERYKEY_NOTTAGS "!tags"
|
2010-04-09 18:30:29 +00:00
|
|
|
#define QUERYKEY_ASYNC_ENABLED "asyncEnabled"
|
2010-06-23 17:01:27 +00:00
|
|
|
#define QUERYKEY_TRANSITION "transition"
|
2006-07-18 16:57:27 +00:00
|
|
|
|
|
|
|
inline void AppendAmpersandIfNonempty(nsACString& aString)
|
|
|
|
{
|
|
|
|
if (! aString.IsEmpty())
|
|
|
|
aString.Append('&');
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
inline void AppendInt16(nsACString& str, int16_t i)
|
2007-04-25 21:03:29 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString tmp;
|
2007-04-25 21:03:29 +00:00
|
|
|
tmp.AppendInt(i);
|
|
|
|
str.Append(tmp);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
inline void AppendInt32(nsACString& str, int32_t i)
|
2006-07-18 16:57:27 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString tmp;
|
2006-07-18 16:57:27 +00:00
|
|
|
tmp.AppendInt(i);
|
|
|
|
str.Append(tmp);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
inline void AppendInt64(nsACString& str, int64_t i)
|
2006-07-18 16:57:27 +00:00
|
|
|
{
|
|
|
|
nsCString tmp;
|
|
|
|
tmp.AppendInt(i);
|
|
|
|
str.Append(tmp);
|
|
|
|
}
|
|
|
|
|
2008-03-15 19:39:04 +00:00
|
|
|
namespace PlacesFolderConversion {
|
|
|
|
#define PLACES_ROOT_FOLDER "PLACES_ROOT"
|
|
|
|
#define BOOKMARKS_MENU_FOLDER "BOOKMARKS_MENU"
|
|
|
|
#define TAGS_FOLDER "TAGS"
|
|
|
|
#define UNFILED_BOOKMARKS_FOLDER "UNFILED_BOOKMARKS"
|
|
|
|
#define TOOLBAR_FOLDER "TOOLBAR"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a folder name to a folder id.
|
|
|
|
*
|
|
|
|
* @param aName
|
|
|
|
* The name of the folder to convert to a folder id.
|
|
|
|
* @returns the folder id if aName is a recognizable name, -1 otherwise.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
inline int64_t DecodeFolder(const nsCString &aName)
|
2008-03-15 19:39:04 +00:00
|
|
|
{
|
|
|
|
nsNavBookmarks *bs = nsNavBookmarks::GetBookmarksService();
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(bs, false);
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t folderID = -1;
|
2008-03-15 19:39:04 +00:00
|
|
|
|
|
|
|
if (aName.EqualsLiteral(PLACES_ROOT_FOLDER))
|
|
|
|
(void)bs->GetPlacesRoot(&folderID);
|
|
|
|
else if (aName.EqualsLiteral(BOOKMARKS_MENU_FOLDER))
|
|
|
|
(void)bs->GetBookmarksMenuFolder(&folderID);
|
|
|
|
else if (aName.EqualsLiteral(TAGS_FOLDER))
|
|
|
|
(void)bs->GetTagsFolder(&folderID);
|
|
|
|
else if (aName.EqualsLiteral(UNFILED_BOOKMARKS_FOLDER))
|
|
|
|
(void)bs->GetUnfiledBookmarksFolder(&folderID);
|
|
|
|
else if (aName.EqualsLiteral(TOOLBAR_FOLDER))
|
|
|
|
(void)bs->GetToolbarFolder(&folderID);
|
|
|
|
|
|
|
|
return folderID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a folder id to a named constant, or a string representation of the
|
|
|
|
* folder id if there is no named constant for the folder, and appends it to
|
|
|
|
* aQuery.
|
|
|
|
*
|
|
|
|
* @param aQuery
|
|
|
|
* The string to append the folder string to. This is generally a
|
|
|
|
* query string, but could really be anything.
|
|
|
|
* @param aFolderID
|
|
|
|
* The folder ID to convert to the proper named constant.
|
|
|
|
*/
|
2012-12-17 14:03:49 +00:00
|
|
|
inline nsresult AppendFolder(nsCString &aQuery, int64_t aFolderID)
|
2008-03-15 19:39:04 +00:00
|
|
|
{
|
|
|
|
nsNavBookmarks *bs = nsNavBookmarks::GetBookmarksService();
|
2012-12-17 14:03:49 +00:00
|
|
|
NS_ENSURE_STATE(bs);
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t folderID;
|
2008-03-15 19:39:04 +00:00
|
|
|
|
2012-12-17 14:03:49 +00:00
|
|
|
if (NS_SUCCEEDED(bs->GetPlacesRoot(&folderID)) &&
|
|
|
|
aFolderID == folderID) {
|
2008-03-15 19:39:04 +00:00
|
|
|
aQuery.AppendLiteral(PLACES_ROOT_FOLDER);
|
|
|
|
}
|
2012-12-17 14:03:49 +00:00
|
|
|
else if (NS_SUCCEEDED(bs->GetBookmarksMenuFolder(&folderID)) &&
|
|
|
|
aFolderID == folderID) {
|
2008-03-15 19:39:04 +00:00
|
|
|
aQuery.AppendLiteral(BOOKMARKS_MENU_FOLDER);
|
|
|
|
}
|
2012-12-17 14:03:49 +00:00
|
|
|
else if (NS_SUCCEEDED(bs->GetTagsFolder(&folderID)) &&
|
|
|
|
aFolderID == folderID) {
|
2008-03-15 19:39:04 +00:00
|
|
|
aQuery.AppendLiteral(TAGS_FOLDER);
|
|
|
|
}
|
2012-12-17 14:03:49 +00:00
|
|
|
else if (NS_SUCCEEDED(bs->GetUnfiledBookmarksFolder(&folderID)) &&
|
|
|
|
aFolderID == folderID) {
|
2008-03-15 19:39:04 +00:00
|
|
|
aQuery.AppendLiteral(UNFILED_BOOKMARKS_FOLDER);
|
|
|
|
}
|
2012-12-17 14:03:49 +00:00
|
|
|
else if (NS_SUCCEEDED(bs->GetToolbarFolder(&folderID)) &&
|
|
|
|
aFolderID == folderID) {
|
2008-03-15 19:39:04 +00:00
|
|
|
aQuery.AppendLiteral(TOOLBAR_FOLDER);
|
2012-12-17 14:03:49 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// It wasn't one of our named constants, so just convert it to a string.
|
|
|
|
aQuery.AppendInt(aFolderID);
|
2008-03-15 19:39:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 14:03:49 +00:00
|
|
|
return NS_OK;
|
2008-03-15 19:39:04 +00:00
|
|
|
}
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace PlacesFolderConversion
|
2006-07-18 17:04:51 +00:00
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
// nsNavHistory::QueryStringToQueries
|
2006-07-18 17:04:51 +00:00
|
|
|
//
|
|
|
|
// From C++ places code, you should use QueryStringToQueryArray, this is
|
|
|
|
// the harder-to-use XPCOM version.
|
2006-07-18 16:57:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::QueryStringToQueries(const nsACString& aQueryString,
|
|
|
|
nsINavHistoryQuery*** aQueries,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t* aResultCount,
|
2006-07-18 16:57:27 +00:00
|
|
|
nsINavHistoryQueryOptions** aOptions)
|
|
|
|
{
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aQueries);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResultCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(aOptions);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aQueries = nullptr;
|
2006-07-18 16:57:27 +00:00
|
|
|
*aResultCount = 0;
|
2006-07-18 17:04:51 +00:00
|
|
|
nsCOMPtr<nsNavHistoryQueryOptions> options;
|
|
|
|
nsCOMArray<nsNavHistoryQuery> queries;
|
|
|
|
nsresult rv = QueryStringToQueryArray(aQueryString, &queries,
|
|
|
|
getter_AddRefs(options));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aResultCount = queries.Count();
|
|
|
|
if (queries.Count() > 0) {
|
|
|
|
// convert COM array to raw
|
2007-07-08 07:08:04 +00:00
|
|
|
*aQueries = static_cast<nsINavHistoryQuery**>
|
2015-03-27 00:01:12 +00:00
|
|
|
(moz_xmalloc(sizeof(nsINavHistoryQuery*) * queries.Count()));
|
2006-07-18 17:04:51 +00:00
|
|
|
NS_ENSURE_TRUE(*aQueries, NS_ERROR_OUT_OF_MEMORY);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = 0; i < queries.Count(); i ++) {
|
2006-07-18 17:04:51 +00:00
|
|
|
(*aQueries)[i] = queries[i];
|
|
|
|
NS_ADDREF((*aQueries)[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-03-31 14:03:49 +00:00
|
|
|
options.forget(aOptions);
|
2006-07-18 17:04:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::QueryStringToQueryArray
|
|
|
|
//
|
|
|
|
// An internal version of QueryStringToQueries that fills a COM array for
|
|
|
|
// ease-of-use.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::QueryStringToQueryArray(const nsACString& aQueryString,
|
|
|
|
nsCOMArray<nsNavHistoryQuery>* aQueries,
|
|
|
|
nsNavHistoryQueryOptions** aOptions)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
aQueries->Clear();
|
2012-07-30 14:20:58 +00:00
|
|
|
*aOptions = nullptr;
|
2006-07-18 16:57:27 +00:00
|
|
|
|
|
|
|
nsRefPtr<nsNavHistoryQueryOptions> options(new nsNavHistoryQueryOptions());
|
|
|
|
if (! options)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
nsTArray<QueryKeyValuePair> tokens;
|
2006-07-18 16:57:27 +00:00
|
|
|
rv = TokenizeQueryString(aQueryString, &tokens);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-01-21 11:39:07 +00:00
|
|
|
rv = TokensToQueries(tokens, aQueries, options);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Unable to parse the query string: ");
|
|
|
|
NS_WARNING(PromiseFlatCString(aQueryString).get());
|
|
|
|
return rv;
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 14:03:49 +00:00
|
|
|
options.forget(aOptions);
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// nsNavHistory::QueriesToQueryString
|
2006-07-18 16:57:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-07-18 16:58:50 +00:00
|
|
|
nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aQueryCount,
|
2006-07-18 16:57:27 +00:00
|
|
|
nsINavHistoryQueryOptions* aOptions,
|
|
|
|
nsACString& aQueryString)
|
|
|
|
{
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aQueries);
|
|
|
|
NS_ENSURE_ARG(aOptions);
|
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
nsCOMPtr<nsNavHistoryQueryOptions> options = do_QueryInterface(aOptions);
|
|
|
|
NS_ENSURE_TRUE(options, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString queryString;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t queryIndex = 0; queryIndex < aQueryCount; queryIndex ++) {
|
2009-05-05 03:40:34 +00:00
|
|
|
nsCOMPtr<nsNavHistoryQuery> query = do_QueryInterface(aQueries[queryIndex]);
|
2006-07-18 16:57:27 +00:00
|
|
|
if (queryIndex > 0) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_SEPARATOR);
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasIt;
|
2006-07-18 16:57:27 +00:00
|
|
|
|
|
|
|
// begin time
|
2006-07-18 17:02:16 +00:00
|
|
|
query->GetHasBeginTime(&hasIt);
|
2006-07-18 16:57:27 +00:00
|
|
|
if (hasIt) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendInt64KeyValueIfNonzero(queryString,
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_BEGIN_TIME),
|
|
|
|
query, &nsINavHistoryQuery::GetBeginTime);
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendUint32KeyValueIfNonzero(queryString,
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_BEGIN_TIME_REFERENCE),
|
|
|
|
query, &nsINavHistoryQuery::GetBeginTimeReference);
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end time
|
2006-07-18 17:02:16 +00:00
|
|
|
query->GetHasEndTime(&hasIt);
|
2006-07-18 16:57:27 +00:00
|
|
|
if (hasIt) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendInt64KeyValueIfNonzero(queryString,
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_END_TIME),
|
|
|
|
query, &nsINavHistoryQuery::GetEndTime);
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendUint32KeyValueIfNonzero(queryString,
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_END_TIME_REFERENCE),
|
|
|
|
query, &nsINavHistoryQuery::GetEndTimeReference);
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// search terms
|
2006-07-18 17:02:16 +00:00
|
|
|
query->GetHasSearchTerms(&hasIt);
|
2006-07-18 16:57:27 +00:00
|
|
|
if (hasIt) {
|
|
|
|
nsAutoString searchTerms;
|
2006-07-18 17:02:16 +00:00
|
|
|
query->GetSearchTerms(searchTerms);
|
2006-07-18 16:57:27 +00:00
|
|
|
nsCString escapedTerms;
|
|
|
|
if (! NS_Escape(NS_ConvertUTF16toUTF8(searchTerms), escapedTerms,
|
|
|
|
url_XAlphas))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_SEARCH_TERMS "=");
|
|
|
|
queryString += escapedTerms;
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
2007-02-16 22:55:10 +00:00
|
|
|
// min and max visits
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t minVisits;
|
2007-02-16 22:55:10 +00:00
|
|
|
if (NS_SUCCEEDED(query->GetMinVisits(&minVisits)) && minVisits >= 0) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
2014-05-22 03:48:50 +00:00
|
|
|
queryString.AppendLiteral(QUERYKEY_MIN_VISITS "=");
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendInt32(queryString, minVisits);
|
2007-02-16 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t maxVisits;
|
2007-02-16 22:55:10 +00:00
|
|
|
if (NS_SUCCEEDED(query->GetMaxVisits(&maxVisits)) && maxVisits >= 0) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
2014-05-22 03:48:50 +00:00
|
|
|
queryString.AppendLiteral(QUERYKEY_MAX_VISITS "=");
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendInt32(queryString, maxVisits);
|
2007-02-16 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
// only bookmarked
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendBoolKeyValueIfTrue(queryString,
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_ONLY_BOOKMARKED),
|
|
|
|
query, &nsINavHistoryQuery::GetOnlyBookmarked);
|
|
|
|
|
|
|
|
// domain (+ is host), only call if hasDomain, which means non-IsVoid
|
|
|
|
// this means we may get an empty string for the domain in the result,
|
|
|
|
// which is valid
|
|
|
|
query->GetHasDomain(&hasIt);
|
|
|
|
if (hasIt) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendBoolKeyValueIfTrue(queryString,
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_DOMAIN_IS_HOST),
|
|
|
|
query, &nsINavHistoryQuery::GetDomainIsHost);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString domain;
|
2006-07-18 17:02:16 +00:00
|
|
|
nsresult rv = query->GetDomain(domain);
|
2011-05-10 01:10:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 17:02:16 +00:00
|
|
|
nsCString escapedDomain;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool success = NS_Escape(domain, escapedDomain, url_XAlphas);
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
2014-05-22 03:48:50 +00:00
|
|
|
queryString.AppendLiteral(QUERYKEY_DOMAIN "=");
|
2007-04-10 00:30:52 +00:00
|
|
|
queryString.Append(escapedDomain);
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// uri
|
|
|
|
query->GetHasUri(&hasIt);
|
2006-07-18 16:57:27 +00:00
|
|
|
if (hasIt) {
|
2006-07-18 17:02:16 +00:00
|
|
|
AppendBoolKeyValueIfTrue(aQueryString,
|
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_URIISPREFIX),
|
|
|
|
query, &nsINavHistoryQuery::GetUriIsPrefix);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
query->GetUri(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); // hasURI should tell is if invalid
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString uriSpec;
|
2006-07-18 17:02:16 +00:00
|
|
|
nsresult rv = uri->GetSpec(uriSpec);
|
2006-07-18 16:57:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString escaped;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool success = NS_Escape(uriSpec, escaped, url_XAlphas);
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
2014-05-22 03:48:50 +00:00
|
|
|
queryString.AppendLiteral(QUERYKEY_URI "=");
|
2007-04-10 00:30:52 +00:00
|
|
|
queryString.Append(escaped);
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
2006-07-18 16:59:36 +00:00
|
|
|
|
2006-07-18 17:04:27 +00:00
|
|
|
// annotation
|
|
|
|
query->GetHasAnnotation(&hasIt);
|
|
|
|
if (hasIt) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool annotationIsNot;
|
2006-07-18 17:04:27 +00:00
|
|
|
query->GetAnnotationIsNot(&annotationIsNot);
|
|
|
|
if (annotationIsNot)
|
2007-04-10 00:30:52 +00:00
|
|
|
queryString.AppendLiteral(QUERYKEY_NOTANNOTATION "=");
|
2006-07-18 17:04:27 +00:00
|
|
|
else
|
2007-04-10 00:30:52 +00:00
|
|
|
queryString.AppendLiteral(QUERYKEY_ANNOTATION "=");
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString annot;
|
2006-07-18 17:04:27 +00:00
|
|
|
query->GetAnnotation(annot);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString escaped;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool success = NS_Escape(annot, escaped, url_XAlphas);
|
2006-07-18 17:04:27 +00:00
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
|
2007-04-10 00:30:52 +00:00
|
|
|
queryString.Append(escaped);
|
2006-07-18 17:04:27 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:59:36 +00:00
|
|
|
// folders
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t *folders = nullptr;
|
|
|
|
uint32_t folderCount = 0;
|
2006-07-18 17:02:16 +00:00
|
|
|
query->GetFolders(&folderCount, &folders);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < folderCount; ++i) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_FOLDER "=");
|
2012-12-17 14:03:49 +00:00
|
|
|
nsresult rv = PlacesFolderConversion::AppendFolder(queryString, folders[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:59:36 +00:00
|
|
|
}
|
2015-03-27 00:01:12 +00:00
|
|
|
free(folders);
|
2009-05-05 03:40:34 +00:00
|
|
|
|
|
|
|
// tags
|
|
|
|
const nsTArray<nsString> &tags = query->Tags();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < tags.Length(); ++i) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString escapedTag;
|
2009-05-05 03:40:34 +00:00
|
|
|
if (!NS_Escape(NS_ConvertUTF16toUTF8(tags[i]), escapedTag, url_XAlphas))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_TAG "=");
|
|
|
|
queryString += escapedTag;
|
|
|
|
}
|
|
|
|
AppendBoolKeyValueIfTrue(queryString,
|
|
|
|
NS_LITERAL_CSTRING(QUERYKEY_NOTTAGS),
|
|
|
|
query,
|
|
|
|
&nsINavHistoryQuery::GetTagsAreNot);
|
2010-06-23 17:01:27 +00:00
|
|
|
|
|
|
|
// transitions
|
2012-08-22 15:56:38 +00:00
|
|
|
const nsTArray<uint32_t>& transitions = query->Transitions();
|
|
|
|
for (uint32_t i = 0; i < transitions.Length(); ++i) {
|
2010-06-23 17:01:27 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_TRANSITION "=");
|
|
|
|
AppendInt64(queryString, transitions[i]);
|
|
|
|
}
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sorting
|
|
|
|
if (options->SortingMode() != nsINavHistoryQueryOptions::SORT_BY_NONE) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORT "=");
|
2007-04-25 21:03:29 +00:00
|
|
|
AppendInt16(queryString, options->SortingMode());
|
2007-04-27 10:04:13 +00:00
|
|
|
if (options->SortingMode() == nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING ||
|
|
|
|
options->SortingMode() == nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_ASCENDING) {
|
|
|
|
// sortingAnnotation
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString sortingAnnotation;
|
2007-04-27 10:04:13 +00:00
|
|
|
if (NS_SUCCEEDED(options->GetSortingAnnotation(sortingAnnotation))) {
|
|
|
|
nsCString escaped;
|
|
|
|
if (!NS_Escape(sortingAnnotation, escaped, url_XAlphas))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORTING_ANNOTATION "=");
|
|
|
|
queryString.Append(escaped);
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// result type
|
2006-07-18 17:04:04 +00:00
|
|
|
if (options->ResultType() != nsINavHistoryQueryOptions::RESULTS_AS_URI) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_RESULT_TYPE "=");
|
2007-04-25 21:03:29 +00:00
|
|
|
AppendInt16(queryString, options->ResultType());
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// exclude items
|
|
|
|
if (options->ExcludeItems()) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_EXCLUDE_ITEMS "=1");
|
2006-07-18 17:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// exclude queries
|
|
|
|
if (options->ExcludeQueries()) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_EXCLUDE_QUERIES "=1");
|
2006-07-18 17:04:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 17:06:01 +00:00
|
|
|
// exclude read only folders
|
|
|
|
if (options->ExcludeReadOnlyFolders()) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_EXCLUDE_READ_ONLY_FOLDERS "=1");
|
2006-07-18 17:06:01 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// expand queries
|
2007-09-01 21:23:36 +00:00
|
|
|
if (!options->ExpandQueries()) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
2007-09-01 21:23:36 +00:00
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_EXPAND_QUERIES "=0");
|
2006-07-18 17:04:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 17:01:22 +00:00
|
|
|
// include hidden
|
|
|
|
if (options->IncludeHidden()) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_INCLUDE_HIDDEN "=1");
|
2006-07-18 17:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// max results
|
|
|
|
if (options->MaxResults()) {
|
2007-04-10 00:30:52 +00:00
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_MAX_RESULTS "=");
|
|
|
|
AppendInt32(queryString, options->MaxResults());
|
2006-07-18 17:01:22 +00:00
|
|
|
}
|
|
|
|
|
2007-04-25 21:03:29 +00:00
|
|
|
// queryType
|
|
|
|
if (options->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) {
|
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_QUERY_TYPE "=");
|
|
|
|
AppendInt16(queryString, options->QueryType());
|
|
|
|
}
|
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
// async enabled
|
|
|
|
if (options->AsyncEnabled()) {
|
|
|
|
AppendAmpersandIfNonempty(queryString);
|
|
|
|
queryString += NS_LITERAL_CSTRING(QUERYKEY_ASYNC_ENABLED "=1");
|
|
|
|
}
|
|
|
|
|
2014-05-22 03:48:52 +00:00
|
|
|
aQueryString.AssignLiteral("place:");
|
|
|
|
aQueryString.Append(queryString);
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TokenizeQueryString
|
|
|
|
|
|
|
|
nsresult
|
2006-07-18 17:02:16 +00:00
|
|
|
TokenizeQueryString(const nsACString& aQuery,
|
|
|
|
nsTArray<QueryKeyValuePair>* aTokens)
|
2006-07-18 16:57:27 +00:00
|
|
|
{
|
2006-07-18 17:00:37 +00:00
|
|
|
// Strip off the "place:" prefix
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t prefixlen = 6; // = strlen("place:");
|
2006-07-18 17:00:37 +00:00
|
|
|
nsCString query;
|
2009-01-21 11:39:07 +00:00
|
|
|
if (aQuery.Length() >= prefixlen &&
|
2006-07-18 17:00:37 +00:00
|
|
|
Substring(aQuery, 0, prefixlen).EqualsLiteral("place:"))
|
|
|
|
query = Substring(aQuery, prefixlen);
|
|
|
|
else
|
|
|
|
query = aQuery;
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t keyFirstIndex = 0;
|
|
|
|
int32_t equalsIndex = 0;
|
|
|
|
for (uint32_t i = 0; i < query.Length(); i ++) {
|
2006-07-18 16:57:27 +00:00
|
|
|
if (query[i] == '&') {
|
|
|
|
// new clause, save last one
|
|
|
|
if (i - keyFirstIndex > 1) {
|
2006-07-18 17:02:16 +00:00
|
|
|
if (! aTokens->AppendElement(QueryKeyValuePair(query, keyFirstIndex,
|
|
|
|
equalsIndex, i)))
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
keyFirstIndex = equalsIndex = i + 1;
|
|
|
|
} else if (query[i] == '=') {
|
|
|
|
equalsIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle last pair, if any
|
|
|
|
if (query.Length() - keyFirstIndex > 1) {
|
2006-07-18 17:02:16 +00:00
|
|
|
if (! aTokens->AppendElement(QueryKeyValuePair(query, keyFirstIndex,
|
|
|
|
equalsIndex, query.Length())))
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// nsNavHistory::TokensToQueries
|
2006-07-18 16:57:27 +00:00
|
|
|
|
|
|
|
nsresult
|
2006-07-18 17:02:16 +00:00
|
|
|
nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
|
2006-07-18 17:04:51 +00:00
|
|
|
nsCOMArray<nsNavHistoryQuery>* aQueries,
|
2006-07-18 16:57:27 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2006-07-18 17:02:16 +00:00
|
|
|
|
2006-07-18 17:04:51 +00:00
|
|
|
nsCOMPtr<nsNavHistoryQuery> query(new nsNavHistoryQuery());
|
2006-07-18 16:57:27 +00:00
|
|
|
if (! query)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (! aQueries->AppendObject(query))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-01-21 11:39:07 +00:00
|
|
|
|
|
|
|
if (aTokens.Length() == 0)
|
|
|
|
return NS_OK; // nothing to do
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTArray<int64_t> folders;
|
2009-05-05 03:40:34 +00:00
|
|
|
nsTArray<nsString> tags;
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTArray<uint32_t> transitions;
|
|
|
|
for (uint32_t i = 0; i < aTokens.Length(); i ++) {
|
2006-07-18 17:02:16 +00:00
|
|
|
const QueryKeyValuePair& kvp = aTokens[i];
|
2006-07-18 16:59:13 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// begin time
|
|
|
|
if (kvp.key.EqualsLiteral(QUERYKEY_BEGIN_TIME)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyInt64(kvp.value, query, &nsINavHistoryQuery::SetBeginTime);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// begin time reference
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_BEGIN_TIME_REFERENCE)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyUint32(kvp.value, query, &nsINavHistoryQuery::SetBeginTimeReference);
|
2006-07-18 16:59:13 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// end time
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_END_TIME)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyInt64(kvp.value, query, &nsINavHistoryQuery::SetEndTime);
|
2006-07-18 16:59:13 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// end time reference
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_END_TIME_REFERENCE)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyUint32(kvp.value, query, &nsINavHistoryQuery::SetEndTimeReference);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// search terms
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_SEARCH_TERMS)) {
|
|
|
|
nsCString unescapedTerms = kvp.value;
|
2006-07-18 16:57:27 +00:00
|
|
|
NS_UnescapeURL(unescapedTerms); // modifies input
|
|
|
|
rv = query->SetSearchTerms(NS_ConvertUTF8toUTF16(unescapedTerms));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-02-16 22:55:10 +00:00
|
|
|
// min visits
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_MIN_VISITS)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t visits = kvp.value.ToInteger(&rv);
|
2007-02-16 22:55:10 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
query->SetMinVisits(visits);
|
|
|
|
else
|
|
|
|
NS_WARNING("Bad number for minVisits in query");
|
|
|
|
|
|
|
|
// max visits
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_MAX_VISITS)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t visits = kvp.value.ToInteger(&rv);
|
2007-02-16 22:55:10 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
query->SetMaxVisits(visits);
|
|
|
|
else
|
|
|
|
NS_WARNING("Bad number for maxVisits in query");
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// onlyBookmarked flag
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_ONLY_BOOKMARKED)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyBool(kvp.value, query, &nsINavHistoryQuery::SetOnlyBookmarked);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// domainIsHost flag
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_DOMAIN_IS_HOST)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyBool(kvp.value, query, &nsINavHistoryQuery::SetDomainIsHost);
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// domain string
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_DOMAIN)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString unescapedDomain(kvp.value);
|
2006-07-18 16:57:27 +00:00
|
|
|
NS_UnescapeURL(unescapedDomain); // modifies input
|
2006-07-18 17:02:16 +00:00
|
|
|
rv = query->SetDomain(unescapedDomain);
|
2006-07-18 16:57:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-10-11 06:42:38 +00:00
|
|
|
// folders
|
2006-07-18 17:04:51 +00:00
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_FOLDER)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t folder;
|
2006-07-18 17:03:41 +00:00
|
|
|
if (PR_sscanf(kvp.value.get(), "%lld", &folder) == 1) {
|
2006-07-18 16:59:36 +00:00
|
|
|
NS_ENSURE_TRUE(folders.AppendElement(folder), NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else {
|
2008-03-15 19:39:04 +00:00
|
|
|
folder = PlacesFolderConversion::DecodeFolder(kvp.value);
|
|
|
|
if (folder != -1)
|
|
|
|
NS_ENSURE_TRUE(folders.AppendElement(folder), NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
else
|
|
|
|
NS_WARNING("folders value in query is invalid, ignoring");
|
2006-07-18 16:59:36 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// uri
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_URI)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString unescapedUri(kvp.value);
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_UnescapeURL(unescapedUri); // modifies input
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), unescapedUri);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Unable to parse URI");
|
|
|
|
}
|
|
|
|
rv = query->SetUri(uri);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// URI is prefix
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_URIISPREFIX)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetQueryKeyBool(kvp.value, query, &nsINavHistoryQuery::SetUriIsPrefix);
|
2006-07-18 17:02:16 +00:00
|
|
|
|
2006-07-18 17:04:27 +00:00
|
|
|
// not annotation
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_NOTANNOTATION)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString unescaped(kvp.value);
|
2006-07-18 17:04:27 +00:00
|
|
|
NS_UnescapeURL(unescaped); // modifies input
|
2011-10-17 14:59:28 +00:00
|
|
|
query->SetAnnotationIsNot(true);
|
2006-07-18 17:04:27 +00:00
|
|
|
query->SetAnnotation(unescaped);
|
|
|
|
|
|
|
|
// annotation
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_ANNOTATION)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString unescaped(kvp.value);
|
2006-07-18 17:04:27 +00:00
|
|
|
NS_UnescapeURL(unescaped); // modifies input
|
2011-10-17 14:59:28 +00:00
|
|
|
query->SetAnnotationIsNot(false);
|
2006-07-18 17:04:27 +00:00
|
|
|
query->SetAnnotation(unescaped);
|
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
// tag
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_TAG)) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString unescaped(kvp.value);
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_UnescapeURL(unescaped); // modifies input
|
2012-03-23 04:18:59 +00:00
|
|
|
NS_ConvertUTF8toUTF16 tag(unescaped);
|
2009-05-05 03:40:34 +00:00
|
|
|
if (!tags.Contains(tag)) {
|
|
|
|
NS_ENSURE_TRUE(tags.AppendElement(tag), NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// not tags
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_NOTTAGS)) {
|
|
|
|
SetQueryKeyBool(kvp.value, query, &nsINavHistoryQuery::SetTagsAreNot);
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
// transition
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_TRANSITION)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t transition = kvp.value.ToInteger(&rv);
|
2010-06-23 17:01:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (!transitions.Contains(transition))
|
|
|
|
NS_ENSURE_TRUE(transitions.AppendElement(transition),
|
|
|
|
NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("Invalid Int32 transition value.");
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// new query component
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_SEPARATOR)) {
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2006-07-18 16:59:36 +00:00
|
|
|
if (folders.Length() != 0) {
|
|
|
|
query->SetFolders(folders.Elements(), folders.Length());
|
|
|
|
folders.Clear();
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
if (tags.Length() > 0) {
|
|
|
|
rv = query->SetTags(tags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
tags.Clear();
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
if (transitions.Length() > 0) {
|
|
|
|
rv = query->SetTransitions(transitions);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
transitions.Clear();
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
query = new nsNavHistoryQuery();
|
|
|
|
if (! query)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (! aQueries->AppendObject(query))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
// sorting mode
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORT)) {
|
2007-04-25 21:03:29 +00:00
|
|
|
SetOptionsKeyUint16(kvp.value, aOptions,
|
2006-07-18 17:02:55 +00:00
|
|
|
&nsINavHistoryQueryOptions::SetSortingMode);
|
2007-04-27 10:04:13 +00:00
|
|
|
// sorting annotation
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORTING_ANNOTATION)) {
|
|
|
|
nsCString sortingAnnotation = kvp.value;
|
|
|
|
NS_UnescapeURL(sortingAnnotation);
|
|
|
|
rv = aOptions->SetSortingAnnotation(sortingAnnotation);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 17:02:16 +00:00
|
|
|
// result type
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_RESULT_TYPE)) {
|
2007-04-25 21:03:29 +00:00
|
|
|
SetOptionsKeyUint16(kvp.value, aOptions,
|
2006-07-18 17:02:55 +00:00
|
|
|
&nsINavHistoryQueryOptions::SetResultType);
|
2006-07-18 17:02:16 +00:00
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// exclude items
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_EXCLUDE_ITEMS)) {
|
|
|
|
SetOptionsKeyBool(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetExcludeItems);
|
|
|
|
|
|
|
|
// exclude queries
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_EXCLUDE_QUERIES)) {
|
|
|
|
SetOptionsKeyBool(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetExcludeQueries);
|
|
|
|
|
2006-07-18 17:06:01 +00:00
|
|
|
// exclude read only folders
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_EXCLUDE_READ_ONLY_FOLDERS)) {
|
|
|
|
SetOptionsKeyBool(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetExcludeReadOnlyFolders);
|
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// expand queries
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_EXPAND_QUERIES)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetOptionsKeyBool(kvp.value, aOptions,
|
2006-07-18 17:04:04 +00:00
|
|
|
&nsINavHistoryQueryOptions::SetExpandQueries);
|
2006-07-18 17:02:16 +00:00
|
|
|
// include hidden
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_INCLUDE_HIDDEN)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetOptionsKeyBool(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetIncludeHidden);
|
2006-07-18 17:02:16 +00:00
|
|
|
// max results
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_MAX_RESULTS)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
SetOptionsKeyUint32(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetMaxResults);
|
2007-04-25 21:03:29 +00:00
|
|
|
// query type
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_QUERY_TYPE)) {
|
|
|
|
SetOptionsKeyUint16(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetQueryType);
|
2010-04-09 18:30:29 +00:00
|
|
|
// async enabled
|
|
|
|
} else if (kvp.key.EqualsLiteral(QUERYKEY_ASYNC_ENABLED)) {
|
|
|
|
SetOptionsKeyBool(kvp.value, aOptions,
|
|
|
|
&nsINavHistoryQueryOptions::SetAsyncEnabled);
|
2006-07-18 17:02:16 +00:00
|
|
|
// unknown key
|
2006-07-18 16:57:27 +00:00
|
|
|
} else {
|
2007-10-10 23:00:13 +00:00
|
|
|
NS_WARNING("TokensToQueries(), ignoring unknown key: ");
|
|
|
|
NS_WARNING(kvp.key.get());
|
2006-07-18 16:57:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
if (folders.Length() != 0)
|
2006-07-18 16:59:36 +00:00
|
|
|
query->SetFolders(folders.Elements(), folders.Length());
|
2006-07-18 16:57:27 +00:00
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
if (tags.Length() > 0) {
|
|
|
|
rv = query->SetTags(tags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
if (transitions.Length() > 0) {
|
|
|
|
rv = query->SetTransitions(transitions);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ParseQueryBooleanString
|
|
|
|
//
|
|
|
|
// Converts a 0/1 or true/false string into a bool
|
|
|
|
|
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
ParseQueryBooleanString(const nsCString& aString, bool* aValue)
|
2006-07-18 16:57:27 +00:00
|
|
|
{
|
|
|
|
if (aString.EqualsLiteral("1") || aString.EqualsLiteral("true")) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aValue = true;
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
} else if (aString.EqualsLiteral("0") || aString.EqualsLiteral("false")) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aValue = false;
|
2006-07-18 16:57:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2006-07-18 17:01:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
// nsINavHistoryQuery **********************************************************
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsNavHistoryQuery, nsNavHistoryQuery, nsINavHistoryQuery)
|
2006-07-18 17:01:45 +00:00
|
|
|
|
|
|
|
// nsINavHistoryQuery::nsNavHistoryQuery
|
|
|
|
//
|
|
|
|
// This must initialize the object such that the default values will cause
|
|
|
|
// all history to be returned if this query is used. Then the caller can
|
|
|
|
// just set the things it's interested in.
|
|
|
|
|
|
|
|
nsNavHistoryQuery::nsNavHistoryQuery()
|
2007-02-16 22:55:10 +00:00
|
|
|
: mMinVisits(-1), mMaxVisits(-1), mBeginTime(0),
|
|
|
|
mBeginTimeReference(TIME_RELATIVE_EPOCH),
|
2006-07-18 17:01:45 +00:00
|
|
|
mEndTime(0), mEndTimeReference(TIME_RELATIVE_EPOCH),
|
2011-10-17 14:59:28 +00:00
|
|
|
mOnlyBookmarked(false),
|
|
|
|
mDomainIsHost(false), mUriIsPrefix(false),
|
|
|
|
mAnnotationIsNot(false),
|
|
|
|
mTagsAreNot(false)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2006-07-18 17:02:16 +00:00
|
|
|
// differentiate not set (IsVoid) from empty string (local files)
|
2011-10-17 14:59:28 +00:00
|
|
|
mDomain.SetIsVoid(true);
|
2006-07-18 17:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetBeginTime(PRTime *aBeginTime)
|
|
|
|
{
|
|
|
|
*aBeginTime = mBeginTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetBeginTime(PRTime aBeginTime)
|
|
|
|
{
|
|
|
|
mBeginTime = aBeginTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetBeginTimeReference(uint32_t* _retval)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*_retval = mBeginTimeReference;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetBeginTimeReference(uint32_t aReference)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
if (aReference > TIME_RELATIVE_NOW)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
mBeginTimeReference = aReference;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetHasBeginTime(bool* _retval)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*_retval = ! (mBeginTimeReference == TIME_RELATIVE_EPOCH && mBeginTime == 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:05:14 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetAbsoluteBeginTime(PRTime* _retval)
|
|
|
|
{
|
|
|
|
*_retval = nsNavHistory::NormalizeTime(mBeginTimeReference, mBeginTime);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:01:45 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetEndTime(PRTime *aEndTime)
|
|
|
|
{
|
|
|
|
*aEndTime = mEndTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetEndTime(PRTime aEndTime)
|
|
|
|
{
|
|
|
|
mEndTime = aEndTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetEndTimeReference(uint32_t* _retval)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*_retval = mEndTimeReference;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetEndTimeReference(uint32_t aReference)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
if (aReference > TIME_RELATIVE_NOW)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
mEndTimeReference = aReference;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetHasEndTime(bool* _retval)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*_retval = ! (mEndTimeReference == TIME_RELATIVE_EPOCH && mEndTime == 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:05:14 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetAbsoluteEndTime(PRTime* _retval)
|
|
|
|
{
|
|
|
|
*_retval = nsNavHistory::NormalizeTime(mEndTimeReference, mEndTime);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:01:45 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetSearchTerms(nsAString& aSearchTerms)
|
|
|
|
{
|
|
|
|
aSearchTerms = mSearchTerms;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetSearchTerms(const nsAString& aSearchTerms)
|
|
|
|
{
|
|
|
|
mSearchTerms = aSearchTerms;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetHasSearchTerms(bool* _retval)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*_retval = (! mSearchTerms.IsEmpty());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetMinVisits(int32_t* _retval)
|
2007-02-16 22:55:10 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = mMinVisits;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetMinVisits(int32_t aVisits)
|
2007-02-16 22:55:10 +00:00
|
|
|
{
|
|
|
|
mMinVisits = aVisits;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetMaxVisits(int32_t* _retval)
|
2007-02-16 22:55:10 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = mMaxVisits;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetMaxVisits(int32_t aVisits)
|
2007-02-16 22:55:10 +00:00
|
|
|
{
|
|
|
|
mMaxVisits = aVisits;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetOnlyBookmarked(bool *aOnlyBookmarked)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aOnlyBookmarked = mOnlyBookmarked;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetOnlyBookmarked(bool aOnlyBookmarked)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
mOnlyBookmarked = aOnlyBookmarked;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetDomainIsHost(bool *aDomainIsHost)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aDomainIsHost = mDomainIsHost;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetDomainIsHost(bool aDomainIsHost)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
mDomainIsHost = aDomainIsHost;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetDomain(nsACString& aDomain)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
aDomain = mDomain;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetDomain(const nsACString& aDomain)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
mDomain = aDomain;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetHasDomain(bool* _retval)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2006-07-18 17:02:16 +00:00
|
|
|
// note that empty but not void is still a valid query (local files)
|
|
|
|
*_retval = (! mDomain.IsVoid());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetUriIsPrefix(bool* aIsPrefix)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
|
|
|
*aIsPrefix = mUriIsPrefix;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetUriIsPrefix(bool aIsPrefix)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
|
|
|
mUriIsPrefix = aIsPrefix;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetUri(nsIURI** aUri)
|
|
|
|
{
|
2009-04-17 12:42:39 +00:00
|
|
|
NS_IF_ADDREF(*aUri = mUri);
|
2006-07-18 17:02:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetUri(nsIURI* aUri)
|
|
|
|
{
|
|
|
|
mUri = aUri;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetHasUri(bool* aHasUri)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aHasUri = (mUri != nullptr);
|
2006-07-18 17:01:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetAnnotationIsNot(bool* aIsNot)
|
2006-07-18 17:04:27 +00:00
|
|
|
{
|
|
|
|
*aIsNot = mAnnotationIsNot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetAnnotationIsNot(bool aIsNot)
|
2006-07-18 17:04:27 +00:00
|
|
|
{
|
|
|
|
mAnnotationIsNot = aIsNot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetAnnotation(nsACString& aAnnotation)
|
|
|
|
{
|
|
|
|
aAnnotation = mAnnotation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetAnnotation(const nsACString& aAnnotation)
|
|
|
|
{
|
|
|
|
mAnnotation = aAnnotation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetHasAnnotation(bool* aHasIt)
|
2006-07-18 17:04:27 +00:00
|
|
|
{
|
|
|
|
*aHasIt = ! mAnnotation.IsEmpty();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetTags(nsIVariant **aTags)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTags);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWritableVariant> out = do_CreateInstance(NS_VARIANT_CONTRACTID,
|
|
|
|
&rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t arrayLen = mTags.Length();
|
2009-05-05 03:40:34 +00:00
|
|
|
|
|
|
|
if (arrayLen == 0)
|
|
|
|
rv = out->SetAsEmptyArray();
|
|
|
|
else {
|
|
|
|
// Note: The resulting nsIVariant dupes both the array and its elements.
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t **array = reinterpret_cast<const char16_t **>
|
2015-04-01 05:29:55 +00:00
|
|
|
(moz_xmalloc(arrayLen * sizeof(char16_t *)));
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < arrayLen; ++i) {
|
2009-05-05 03:40:34 +00:00
|
|
|
array[i] = mTags[i].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = out->SetAsArray(nsIDataType::VTYPE_WCHAR_STR,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr,
|
2009-05-05 03:40:34 +00:00
|
|
|
arrayLen,
|
|
|
|
reinterpret_cast<void *>(array));
|
2015-04-01 05:29:55 +00:00
|
|
|
free(array);
|
2009-05-05 03:40:34 +00:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-03-31 14:03:49 +00:00
|
|
|
out.forget(aTags);
|
2009-05-05 03:40:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetTags(nsIVariant *aTags)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aTags);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t dataType;
|
2009-05-05 03:40:34 +00:00
|
|
|
aTags->GetDataType(&dataType);
|
|
|
|
|
|
|
|
// Caller passed in empty array. Easy -- clear our mTags array and return.
|
|
|
|
if (dataType == nsIDataType::VTYPE_EMPTY_ARRAY) {
|
|
|
|
mTags.Clear();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before we go any further, make sure caller passed in an array.
|
|
|
|
NS_ENSURE_TRUE(dataType == nsIDataType::VTYPE_ARRAY, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t eltType;
|
2009-05-05 03:40:34 +00:00
|
|
|
nsIID eltIID;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t arrayLen;
|
2009-05-05 03:40:34 +00:00
|
|
|
void *array;
|
|
|
|
|
|
|
|
// Convert the nsIVariant to an array. We own the resulting buffer and its
|
|
|
|
// elements.
|
|
|
|
nsresult rv = aTags->GetAsArray(&eltType, &eltIID, &arrayLen, &array);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If element type is not wstring, thanks a lot. Your memory die now.
|
|
|
|
if (eltType != nsIDataType::VTYPE_WCHAR_STR) {
|
|
|
|
switch (eltType) {
|
|
|
|
case nsIDataType::VTYPE_ID:
|
|
|
|
case nsIDataType::VTYPE_CHAR_STR:
|
|
|
|
{
|
|
|
|
char **charArray = reinterpret_cast<char **>(array);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < arrayLen; ++i) {
|
2009-05-05 03:40:34 +00:00
|
|
|
if (charArray[i])
|
2015-04-01 05:29:55 +00:00
|
|
|
free(charArray[i]);
|
2009-05-05 03:40:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsIDataType::VTYPE_INTERFACE:
|
|
|
|
case nsIDataType::VTYPE_INTERFACE_IS:
|
|
|
|
{
|
|
|
|
nsISupports **supportsArray = reinterpret_cast<nsISupports **>(array);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < arrayLen; ++i) {
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_IF_RELEASE(supportsArray[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// The other types are primitives that do not need to be freed.
|
|
|
|
}
|
2015-04-01 05:29:55 +00:00
|
|
|
free(array);
|
2009-05-05 03:40:34 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t **tags = reinterpret_cast<char16_t **>(array);
|
2009-05-05 03:40:34 +00:00
|
|
|
mTags.Clear();
|
|
|
|
|
|
|
|
// Finally, add each passed-in tag to our mTags array and then sort it.
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < arrayLen; ++i) {
|
2009-05-05 03:40:34 +00:00
|
|
|
|
|
|
|
// Don't allow nulls.
|
|
|
|
if (!tags[i]) {
|
2015-04-01 05:29:55 +00:00
|
|
|
free(tags);
|
2009-05-05 03:40:34 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentString tag(tags[i]);
|
|
|
|
|
|
|
|
// Don't store duplicate tags. This isn't just to save memory or to be
|
|
|
|
// fancy; the SQL that's built from the tags relies on no dupes.
|
|
|
|
if (!mTags.Contains(tag)) {
|
|
|
|
if (!mTags.AppendElement(tag)) {
|
2015-04-01 05:29:55 +00:00
|
|
|
free(tags[i]);
|
|
|
|
free(tags);
|
2009-05-05 03:40:34 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 05:29:55 +00:00
|
|
|
free(tags[i]);
|
2009-05-05 03:40:34 +00:00
|
|
|
}
|
2015-04-01 05:29:55 +00:00
|
|
|
free(tags);
|
2009-05-05 03:40:34 +00:00
|
|
|
|
|
|
|
mTags.Sort();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetTagsAreNot(bool *aTagsAreNot)
|
2009-05-05 03:40:34 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTagsAreNot);
|
|
|
|
*aTagsAreNot = mTagsAreNot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetTagsAreNot(bool aTagsAreNot)
|
2009-05-05 03:40:34 +00:00
|
|
|
{
|
|
|
|
mTagsAreNot = aTagsAreNot;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetFolders(uint32_t *aCount,
|
|
|
|
int64_t **aFolders)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mFolders.Length();
|
|
|
|
int64_t *folders = nullptr;
|
2006-07-18 17:01:45 +00:00
|
|
|
if (count > 0) {
|
2012-08-22 15:56:38 +00:00
|
|
|
folders = static_cast<int64_t*>
|
2015-03-27 00:01:12 +00:00
|
|
|
(moz_xmalloc(count * sizeof(int64_t)));
|
2006-07-18 17:01:45 +00:00
|
|
|
NS_ENSURE_TRUE(folders, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2006-07-18 17:01:45 +00:00
|
|
|
folders[i] = mFolders[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aCount = count;
|
|
|
|
*aFolders = folders;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetFolderCount(uint32_t *aCount)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aCount = mFolders.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetFolders(const int64_t *aFolders,
|
|
|
|
uint32_t aFolderCount)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
if (!mFolders.ReplaceElementsAt(0, mFolders.Length(),
|
|
|
|
aFolders, aFolderCount)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetTransitions(uint32_t* aCount,
|
|
|
|
uint32_t** aTransitions)
|
2010-06-23 17:01:27 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mTransitions.Length();
|
|
|
|
uint32_t* transitions = nullptr;
|
2010-06-23 17:01:27 +00:00
|
|
|
if (count > 0) {
|
2012-08-22 15:56:38 +00:00
|
|
|
transitions = reinterpret_cast<uint32_t*>
|
2015-04-01 05:29:55 +00:00
|
|
|
(moz_xmalloc(count * sizeof(uint32_t)));
|
2010-06-23 17:01:27 +00:00
|
|
|
NS_ENSURE_TRUE(transitions, NS_ERROR_OUT_OF_MEMORY);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2010-06-23 17:01:27 +00:00
|
|
|
transitions[i] = mTransitions[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aCount = count;
|
|
|
|
*aTransitions = transitions;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::GetTransitionCount(uint32_t* aCount)
|
2010-06-23 17:01:27 +00:00
|
|
|
{
|
|
|
|
*aCount = mTransitions.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::SetTransitions(const uint32_t* aTransitions,
|
|
|
|
uint32_t aCount)
|
2010-06-23 17:01:27 +00:00
|
|
|
{
|
|
|
|
if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(), aTransitions,
|
|
|
|
aCount))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:01:45 +00:00
|
|
|
NS_IMETHODIMP nsNavHistoryQuery::Clone(nsINavHistoryQuery** _retval)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2006-07-18 17:01:45 +00:00
|
|
|
|
|
|
|
nsNavHistoryQuery *clone = new nsNavHistoryQuery(*this);
|
|
|
|
NS_ENSURE_TRUE(clone, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
clone->mRefCnt = 0; // the clone doesn't inherit our refcount
|
|
|
|
NS_ADDREF(*_retval = clone);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistoryQueryOptions
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsNavHistoryQueryOptions, nsNavHistoryQueryOptions, nsINavHistoryQueryOptions)
|
2006-07-18 17:01:45 +00:00
|
|
|
|
|
|
|
// sortingMode
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::GetSortingMode(uint16_t* aMode)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aMode = mSort;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::SetSortingMode(uint16_t aMode)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2011-04-13 20:15:41 +00:00
|
|
|
if (aMode > SORT_BY_FRECENCY_DESCENDING)
|
2006-07-18 17:01:45 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
mSort = aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-22 22:20:25 +00:00
|
|
|
// sortingAnnotation
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistoryQueryOptions::GetSortingAnnotation(nsACString& _result) {
|
|
|
|
_result.Assign(mSortingAnnotation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistoryQueryOptions::SetSortingAnnotation(const nsACString& aSortingAnnotation) {
|
|
|
|
mSortingAnnotation.Assign(aSortingAnnotation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:01:45 +00:00
|
|
|
// resultType
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::GetResultType(uint16_t* aType)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aType = mResultType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::SetResultType(uint16_t aType)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2008-04-11 16:22:01 +00:00
|
|
|
if (aType > RESULTS_AS_TAG_CONTENTS)
|
2006-07-18 17:01:45 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-12-04 15:01:19 +00:00
|
|
|
// Tag queries and containers are bookmarks related, so we set the QueryType
|
|
|
|
// accordingly.
|
|
|
|
if (aType == RESULTS_AS_TAG_QUERY || aType == RESULTS_AS_TAG_CONTENTS)
|
|
|
|
mQueryType = QUERY_TYPE_BOOKMARKS;
|
2006-07-18 17:01:45 +00:00
|
|
|
mResultType = aType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// excludeItems
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::GetExcludeItems(bool* aExclude)
|
2006-07-18 17:04:04 +00:00
|
|
|
{
|
|
|
|
*aExclude = mExcludeItems;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::SetExcludeItems(bool aExclude)
|
2006-07-18 17:04:04 +00:00
|
|
|
{
|
|
|
|
mExcludeItems = aExclude;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// excludeQueries
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::GetExcludeQueries(bool* aExclude)
|
2006-07-18 17:04:04 +00:00
|
|
|
{
|
|
|
|
*aExclude = mExcludeQueries;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::SetExcludeQueries(bool aExclude)
|
2006-07-18 17:04:04 +00:00
|
|
|
{
|
|
|
|
mExcludeQueries = aExclude;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:06:01 +00:00
|
|
|
// excludeReadOnlyFolders
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::GetExcludeReadOnlyFolders(bool* aExclude)
|
2006-07-18 17:06:01 +00:00
|
|
|
{
|
|
|
|
*aExclude = mExcludeReadOnlyFolders;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::SetExcludeReadOnlyFolders(bool aExclude)
|
2006-07-18 17:06:01 +00:00
|
|
|
{
|
|
|
|
mExcludeReadOnlyFolders = aExclude;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:04:04 +00:00
|
|
|
// expandQueries
|
2006-07-18 17:01:45 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::GetExpandQueries(bool* aExpand)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2006-07-18 17:04:04 +00:00
|
|
|
*aExpand = mExpandQueries;
|
2006-07-18 17:01:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::SetExpandQueries(bool aExpand)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
2006-07-18 17:04:04 +00:00
|
|
|
mExpandQueries = aExpand;
|
2006-07-18 17:01:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// includeHidden
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::GetIncludeHidden(bool* aIncludeHidden)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aIncludeHidden = mIncludeHidden;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::SetIncludeHidden(bool aIncludeHidden)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
mIncludeHidden = aIncludeHidden;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// maxResults
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::GetMaxResults(uint32_t* aMaxResults)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
*aMaxResults = mMaxResults;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::SetMaxResults(uint32_t aMaxResults)
|
2006-07-18 17:01:45 +00:00
|
|
|
{
|
|
|
|
mMaxResults = aMaxResults;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-25 21:03:29 +00:00
|
|
|
// queryType
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::GetQueryType(uint16_t* _retval)
|
2007-04-25 21:03:29 +00:00
|
|
|
{
|
|
|
|
*_retval = mQueryType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsNavHistoryQueryOptions::SetQueryType(uint16_t aQueryType)
|
2007-04-25 21:03:29 +00:00
|
|
|
{
|
2008-12-04 15:01:19 +00:00
|
|
|
// Tag query and containers are forced to QUERY_TYPE_BOOKMARKS when the
|
|
|
|
// resultType is set.
|
|
|
|
if (mResultType == RESULTS_AS_TAG_CONTENTS ||
|
|
|
|
mResultType == RESULTS_AS_TAG_QUERY)
|
|
|
|
return NS_OK;
|
2007-04-25 21:03:29 +00:00
|
|
|
mQueryType = aQueryType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
// asyncEnabled
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::GetAsyncEnabled(bool* _asyncEnabled)
|
2010-04-09 18:30:29 +00:00
|
|
|
{
|
|
|
|
*_asyncEnabled = mAsyncEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsNavHistoryQueryOptions::SetAsyncEnabled(bool aAsyncEnabled)
|
2010-04-09 18:30:29 +00:00
|
|
|
{
|
|
|
|
mAsyncEnabled = aAsyncEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 17:01:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistoryQueryOptions::Clone(nsINavHistoryQueryOptions** aResult)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
nsNavHistoryQueryOptions *clone = nullptr;
|
2006-07-18 17:01:45 +00:00
|
|
|
nsresult rv = Clone(&clone);
|
|
|
|
*aResult = clone;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistoryQueryOptions::Clone(nsNavHistoryQueryOptions **aResult)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2006-07-18 17:01:45 +00:00
|
|
|
nsNavHistoryQueryOptions *result = new nsNavHistoryQueryOptions();
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsRefPtr<nsNavHistoryQueryOptions> resultHolder(result);
|
|
|
|
result->mSort = mSort;
|
|
|
|
result->mResultType = mResultType;
|
2006-07-18 17:04:04 +00:00
|
|
|
result->mExcludeItems = mExcludeItems;
|
|
|
|
result->mExcludeQueries = mExcludeQueries;
|
|
|
|
result->mExpandQueries = mExpandQueries;
|
2007-04-25 21:03:29 +00:00
|
|
|
result->mMaxResults = mMaxResults;
|
|
|
|
result->mQueryType = mQueryType;
|
2007-10-11 06:42:38 +00:00
|
|
|
result->mParentAnnotationToExclude = mParentAnnotationToExclude;
|
2010-04-09 18:30:29 +00:00
|
|
|
result->mAsyncEnabled = mAsyncEnabled;
|
2006-07-18 17:01:45 +00:00
|
|
|
|
|
|
|
resultHolder.swap(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 17:02:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
// AppendBoolKeyValueIfTrue
|
|
|
|
|
|
|
|
void // static
|
|
|
|
AppendBoolKeyValueIfTrue(nsACString& aString, const nsCString& aName,
|
|
|
|
nsINavHistoryQuery* aQuery,
|
2006-07-18 17:02:55 +00:00
|
|
|
BoolQueryGetter getter)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool value;
|
2011-05-10 01:10:25 +00:00
|
|
|
DebugOnly<nsresult> rv = (aQuery->*getter)(&value);
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting boolean value");
|
|
|
|
if (value) {
|
|
|
|
AppendAmpersandIfNonempty(aString);
|
|
|
|
aString += aName;
|
|
|
|
aString.AppendLiteral("=1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// AppendUint32KeyValueIfNonzero
|
|
|
|
|
|
|
|
void // static
|
|
|
|
AppendUint32KeyValueIfNonzero(nsACString& aString,
|
|
|
|
const nsCString& aName,
|
|
|
|
nsINavHistoryQuery* aQuery,
|
2006-07-18 17:02:55 +00:00
|
|
|
Uint32QueryGetter getter)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t value;
|
2011-05-10 01:10:25 +00:00
|
|
|
DebugOnly<nsresult> rv = (aQuery->*getter)(&value);
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting value");
|
|
|
|
if (value) {
|
|
|
|
AppendAmpersandIfNonempty(aString);
|
|
|
|
aString += aName;
|
|
|
|
|
|
|
|
// AppendInt requires a concrete string
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString appendMe("=");
|
2006-07-18 17:02:16 +00:00
|
|
|
appendMe.AppendInt(value);
|
|
|
|
aString.Append(appendMe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// AppendInt64KeyValueIfNonzero
|
|
|
|
|
|
|
|
void // static
|
|
|
|
AppendInt64KeyValueIfNonzero(nsACString& aString,
|
|
|
|
const nsCString& aName,
|
|
|
|
nsINavHistoryQuery* aQuery,
|
2006-07-18 17:02:55 +00:00
|
|
|
Int64QueryGetter getter)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
2012-08-30 07:10:49 +00:00
|
|
|
PRTime value;
|
2011-05-10 01:10:25 +00:00
|
|
|
DebugOnly<nsresult> rv = (aQuery->*getter)(&value);
|
2006-07-18 17:02:16 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting value");
|
|
|
|
if (value) {
|
|
|
|
AppendAmpersandIfNonempty(aString);
|
2006-07-18 17:06:24 +00:00
|
|
|
aString += aName;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString appendMe("=");
|
2012-08-30 07:10:49 +00:00
|
|
|
appendMe.AppendInt(static_cast<int64_t>(value));
|
2006-07-18 17:02:16 +00:00
|
|
|
aString.Append(appendMe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 17:02:55 +00:00
|
|
|
// SetQuery/OptionsKeyBool
|
2006-07-18 17:02:16 +00:00
|
|
|
|
2006-07-18 17:02:55 +00:00
|
|
|
void // static
|
|
|
|
SetQueryKeyBool(const nsCString& aValue, nsINavHistoryQuery* aQuery,
|
|
|
|
BoolQuerySetter setter)
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool value;
|
2006-07-18 17:02:55 +00:00
|
|
|
nsresult rv = ParseQueryBooleanString(aValue, &value);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = (aQuery->*setter)(value);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error setting boolean key value");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Invalid boolean key value in query string.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void // static
|
|
|
|
SetOptionsKeyBool(const nsCString& aValue, nsINavHistoryQueryOptions* aOptions,
|
|
|
|
BoolOptionsSetter setter)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool value;
|
2006-07-18 17:02:16 +00:00
|
|
|
nsresult rv = ParseQueryBooleanString(aValue, &value);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
rv = (aOptions->*setter)(value);
|
2006-07-18 17:02:16 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error setting boolean key value");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Invalid boolean key value in query string.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 17:02:55 +00:00
|
|
|
// SetQuery/OptionsKeyUint32
|
2006-07-18 17:02:16 +00:00
|
|
|
|
2006-07-18 17:02:55 +00:00
|
|
|
void // static
|
|
|
|
SetQueryKeyUint32(const nsCString& aValue, nsINavHistoryQuery* aQuery,
|
|
|
|
Uint32QuerySetter setter)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t value = aValue.ToInteger(&rv);
|
2006-07-18 17:02:55 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = (aQuery->*setter)(value);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error setting Int32 key value");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Invalid Int32 key value in query string.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void // static
|
|
|
|
SetOptionsKeyUint32(const nsCString& aValue, nsINavHistoryQueryOptions* aOptions,
|
|
|
|
Uint32OptionsSetter setter)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t value = aValue.ToInteger(&rv);
|
2006-07-18 17:02:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-07-18 17:02:55 +00:00
|
|
|
rv = (aOptions->*setter)(value);
|
2006-07-18 17:02:16 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error setting Int32 key value");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Invalid Int32 key value in query string.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-25 21:03:29 +00:00
|
|
|
void // static
|
|
|
|
SetOptionsKeyUint16(const nsCString& aValue, nsINavHistoryQueryOptions* aOptions,
|
|
|
|
Uint16OptionsSetter setter)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t value = static_cast<uint16_t>(aValue.ToInteger(&rv));
|
2007-04-25 21:03:29 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = (aOptions->*setter)(value);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error setting Int16 key value");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Invalid Int16 key value in query string.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 17:02:16 +00:00
|
|
|
|
|
|
|
// SetQueryKeyInt64
|
|
|
|
|
2006-07-18 17:02:55 +00:00
|
|
|
void SetQueryKeyInt64(const nsCString& aValue, nsINavHistoryQuery* aQuery,
|
|
|
|
Int64QuerySetter setter)
|
2006-07-18 17:02:16 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t value;
|
2006-07-18 17:02:16 +00:00
|
|
|
if (PR_sscanf(aValue.get(), "%lld", &value) == 1) {
|
2006-07-18 17:02:55 +00:00
|
|
|
rv = (aQuery->*setter)(value);
|
2006-07-18 17:02:16 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Error setting Int64 key value");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Invalid Int64 value in query string.");
|
|
|
|
}
|
|
|
|
}
|