mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 266174, serialize/deserialize, r=bryner
This commit is contained in:
parent
0e76f99bf3
commit
a9f42915f4
@ -638,8 +638,8 @@ nsNavBookmarks::GetBookmarks(nsINavHistoryResult **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
nsNavHistory *history = History();
|
||||
nsRefPtr<nsNavHistoryResult> result(History()->NewHistoryResult());
|
||||
nsRefPtr<nsNavHistoryResult> result(
|
||||
History()->NewHistoryResult(nsnull, 0, nsnull));
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsresult rv = result->Init();
|
||||
@ -665,7 +665,8 @@ nsNavBookmarks::GetFolderChildren(PRInt64 aFolder, PRUint32 aOptions,
|
||||
{
|
||||
*aChildren = nsnull;
|
||||
|
||||
nsRefPtr<nsNavHistoryResult> result = History()->NewHistoryResult();
|
||||
nsRefPtr<nsNavHistoryResult> result(
|
||||
History()->NewHistoryResult(nsnull, 0, nsnull));
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
result->SetBookmarkOptions(aOptions);
|
||||
|
@ -1062,7 +1062,8 @@ nsNavHistory::ExecuteQueries(const nsINavHistoryQuery** aQueries, PRUint32 aQuer
|
||||
|
||||
PRInt32 numParameters = 0;
|
||||
nsCAutoString conditions;
|
||||
for (PRUint32 i = 0; i < aQueryCount; i ++) {
|
||||
PRUint32 i;
|
||||
for (i = 0; i < aQueryCount; i ++) {
|
||||
nsCString queryClause;
|
||||
PRInt32 clauseParameters = 0;
|
||||
rv = QueryToSelectClause(NS_CONST_CAST(nsINavHistoryQuery*, aQueries[i]),
|
||||
@ -1139,7 +1140,8 @@ nsNavHistory::ExecuteQueries(const nsINavHistoryQuery** aQueries, PRUint32 aQuer
|
||||
}
|
||||
|
||||
// run query and put into result object
|
||||
nsRefPtr<nsNavHistoryResult> result(new nsNavHistoryResult(this, mBundle));
|
||||
nsRefPtr<nsNavHistoryResult> result(
|
||||
NewHistoryResult(aQueries, aQueryCount, aOptions));
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = result->Init();
|
||||
@ -3380,6 +3382,15 @@ NS_IMETHODIMP nsNavHistoryQuery::GetHasDomain(PRBool* _retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNavHistoryQuery::Clone(nsINavHistoryQuery** _retval)
|
||||
{
|
||||
*_retval = new nsNavHistoryQuery(*this);
|
||||
if (! (*_retval))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsNavHistoryQueryOptions
|
||||
NS_IMPL_ISUPPORTS2(nsNavHistoryQueryOptions, nsNavHistoryQueryOptions, nsINavHistoryQueryOptions)
|
||||
@ -3422,3 +3433,32 @@ nsNavHistoryQueryOptions::SetExpandPlaces(PRBool aExpand)
|
||||
mExpandPlaces = aExpand;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNavHistoryQueryOptions::Clone(nsINavHistoryQueryOptions** aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
nsNavHistoryQueryOptions* result = new nsNavHistoryQueryOptions();
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
result->mSort = mSort;
|
||||
result->mResultType = mResultType;
|
||||
result->mGroupCount = mGroupCount;
|
||||
if (mGroupCount) {
|
||||
result->mGroupings = new PRInt32[mGroupCount];
|
||||
if (! result->mGroupings) {
|
||||
delete result;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
for (PRUint32 i = 0; i < mGroupCount; i ++)
|
||||
result->mGroupings[i] = mGroupings[i];
|
||||
} else {
|
||||
result->mGroupCount = nsnull;
|
||||
}
|
||||
result->mExpandPlaces = mExpandPlaces;
|
||||
|
||||
*aResult = result;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ class nsNavHistoryQuery : public nsINavHistoryQuery
|
||||
{
|
||||
public:
|
||||
nsNavHistoryQuery();
|
||||
// note: we use a copy constructor in Clone(), the default is good enough
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSINAVHISTORYQUERY
|
||||
@ -109,11 +110,16 @@ protected:
|
||||
|
||||
// nsNavHistoryResultNode
|
||||
|
||||
#define NS_NAVHISTORYRESULTNODE_IID \
|
||||
{0x54b61d38, 0x57c1, 0x11da, {0x95, 0xb8, 0x00, 0x13, 0x21, 0xc9, 0xf6, 0x9e}}
|
||||
|
||||
class nsNavHistoryResultNode : public nsINavHistoryResultNode
|
||||
{
|
||||
public:
|
||||
nsNavHistoryResultNode();
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_NAVHISTORYRESULTNODE_IID)
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSINAVHISTORYRESULTNODE
|
||||
|
||||
@ -176,7 +182,10 @@ class nsNavHistoryResult : public nsINavHistoryResult,
|
||||
{
|
||||
public:
|
||||
nsNavHistoryResult(nsNavHistory* aHistoryService,
|
||||
nsIStringBundle* aHistoryBundle);
|
||||
nsIStringBundle* aHistoryBundle,
|
||||
const nsINavHistoryQuery** aQueries,
|
||||
PRUint32 aQueryCount,
|
||||
nsINavHistoryQueryOptions *aOptions);
|
||||
|
||||
// Two-stage init, MUST BE CALLED BEFORE ANYTHING ELSE
|
||||
nsresult Init();
|
||||
@ -202,13 +211,14 @@ protected:
|
||||
nsCOMPtr<nsITreeBoxObject> mTree; // may be null if no tree has bound itself
|
||||
nsCOMPtr<nsITreeSelection> mSelection; // may be null
|
||||
|
||||
// This is a COM ptr that MUST BE AddRef'ed and Release'd MANUALLY.
|
||||
// nsNavHistory has nsISupports as an ambiguous base class, so nsCOMPtr
|
||||
// won't work.
|
||||
nsRefPtr<nsNavHistory> mHistoryService;
|
||||
|
||||
PRBool mCollapseDuplicates;
|
||||
|
||||
// what generated this result set
|
||||
nsCOMArray<nsINavHistoryQuery> mSourceQueries;
|
||||
nsCOMPtr<nsINavHistoryQueryOptions> mSourceOptions;
|
||||
|
||||
// for locale-specific date formatting and string sorting
|
||||
nsCOMPtr<nsILocale> mLocale;
|
||||
nsCOMPtr<nsICollation> mCollation;
|
||||
@ -296,7 +306,7 @@ public:
|
||||
mGroupCount(0), mGroupings(nsnull), mExpandPlaces(PR_FALSE)
|
||||
{ }
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INAVHISTORYQUERYOPTIONS_IID)
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_NAVHISTORYQUERYOPTIONS_IID)
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSINAVHISTORYQUERYOPTIONS
|
||||
@ -309,6 +319,8 @@ public:
|
||||
PRBool ExpandPlaces() const { return mExpandPlaces; }
|
||||
|
||||
private:
|
||||
nsNavHistoryQueryOptions(const nsNavHistoryQueryOptions& other) {} // no copy
|
||||
|
||||
~nsNavHistoryQueryOptions() { delete[] mGroupings; }
|
||||
|
||||
PRInt32 mSort;
|
||||
@ -396,9 +408,14 @@ public:
|
||||
nsresult RowToResult(mozIStorageValueArray* aRow, PRBool aAsVisits,
|
||||
nsNavHistoryResultNode** aResult);
|
||||
|
||||
// Construct a new HistoryResult object.
|
||||
nsNavHistoryResult* NewHistoryResult()
|
||||
{ return new nsNavHistoryResult(this, mBundle); }
|
||||
// Construct a new HistoryResult object. You can give it null query/options.
|
||||
nsNavHistoryResult* NewHistoryResult(const nsINavHistoryQuery** aQueries,
|
||||
PRUint32 aQueryCount,
|
||||
nsINavHistoryQueryOptions* aOptions)
|
||||
{
|
||||
return new nsNavHistoryResult(this, mBundle, aQueries, aQueryCount,
|
||||
aOptions);
|
||||
}
|
||||
|
||||
private:
|
||||
~nsNavHistory();
|
||||
|
@ -173,13 +173,27 @@ NS_IMPL_ISUPPORTS2(nsNavHistoryResult,
|
||||
// nsNavHistoryResult::nsNavHistoryResult
|
||||
|
||||
nsNavHistoryResult::nsNavHistoryResult(nsNavHistory* aHistoryService,
|
||||
nsIStringBundle* aHistoryBundle)
|
||||
nsIStringBundle* aHistoryBundle,
|
||||
const nsINavHistoryQuery** aQueries,
|
||||
PRUint32 aQueryCount,
|
||||
nsINavHistoryQueryOptions* aOptions)
|
||||
: mBundle(aHistoryBundle), mHistoryService(aHistoryService),
|
||||
mCollapseDuplicates(PR_TRUE),
|
||||
mTimesIncludeDates(PR_TRUE),
|
||||
mCurrentSort(nsINavHistoryQueryOptions::SORT_BY_NONE),
|
||||
mBookmarkOptions(nsINavBookmarksService::ALL_CHILDREN)
|
||||
{
|
||||
// Fill saved source queries with copies of the original (the caller might
|
||||
// change their original objects, and we always want to reflect the source
|
||||
// parameters).
|
||||
for (PRUint32 i = 0; i < aQueryCount; i ++) {
|
||||
nsINavHistoryQuery* query = NS_CONST_CAST(nsINavHistoryQuery*, aQueries[i]);
|
||||
nsCOMPtr<nsINavHistoryQuery> queryClone;
|
||||
if (NS_SUCCEEDED(query->Clone(getter_AddRefs(queryClone))))
|
||||
mSourceQueries.AppendObject(queryClone);
|
||||
}
|
||||
if (aOptions)
|
||||
aOptions->Clone(getter_AddRefs(mSourceOptions));
|
||||
}
|
||||
|
||||
// nsNavHistoryResult::~nsNavHistoryResult
|
||||
@ -489,6 +503,52 @@ nsNavHistoryResult::NodeForTreeIndex(PRUint32 index,
|
||||
}
|
||||
|
||||
|
||||
// nsNavHistoryResult::TreeIndexForNode
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNavHistoryResult::TreeIndexForNode(nsINavHistoryResultNode* aNode,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsNavHistoryResultNode> node = do_QueryInterface(aNode, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (node->mVisibleIndex < 0)
|
||||
*aResult = nsINavHistoryResult::INDEX_INVISIBLE;
|
||||
else
|
||||
*aResult = node->mVisibleIndex;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsNavHistoryResult::GetSourceQuery
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNavHistoryResult::GetSourceQuery(nsINavHistoryQuery*** aQueries,
|
||||
PRUint32* aQueryCount,
|
||||
nsINavHistoryQueryOptions** aOptions)
|
||||
{
|
||||
*aQueries = nsnull;
|
||||
*aQueryCount = 0;
|
||||
if (mSourceQueries.Count() > 0) {
|
||||
*aQueries = NS_STATIC_CAST(nsINavHistoryQuery**,
|
||||
nsMemory::Alloc(sizeof(nsINavHistoryQuery*) * mSourceQueries.Count()));
|
||||
if (! *aQueries)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*aQueryCount = mSourceQueries.Count();
|
||||
|
||||
for (PRInt32 i = 0; i < mSourceQueries.Count(); i ++) {
|
||||
(*aQueries)[i] = mSourceQueries[i];
|
||||
NS_ADDREF((*aQueries)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
*aOptions = mSourceOptions;
|
||||
NS_IF_ADDREF(*aOptions);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsNavHistoryResult::SetTreeSortingIndicator
|
||||
//
|
||||
// This is called to assign the correct arrow to the column header. It is
|
||||
|
Loading…
Reference in New Issue
Block a user