Bug 1446951 - 2 - Change nsINavHistoryQueryResultNode::GetQueries to a query attribute. r=standard8
MozReview-Commit-ID: 77xEeAE13xW
--- a/browser/components/places/content/controller.js
+++ b/browser/components/places/content/controller.js
@@ -218,22 +218,22 @@ PlacesController.prototype = {
case "placesCmd_paste":
this.paste().catch(Cu.reportError);
break;
case "cmd_delete":
case "placesCmd_delete":
this.remove("Remove Selection").catch(Cu.reportError);
break;
case "placesCmd_deleteDataHost":
- var host;
+ let host;
if (PlacesUtils.nodeIsHost(this._view.selectedNode)) {
- var queries = this._view.selectedNode.getQueries();
- host = queries[0].domain;
- } else
+ host = this._view.selectedNode.query.domain;
+ } else {
host = Services.io.newURI(this._view.selectedNode.uri).host;
+ }
let {ForgetAboutSite} = ChromeUtils.import("resource://gre/modules/ForgetAboutSite.jsm", {});
ForgetAboutSite.removeDataFromDomain(host)
.catch(Cu.reportError);
break;
case "cmd_selectAll":
this.selectAll();
break;
case "placesCmd_open":
@@ -914,17 +914,17 @@ PlacesController.prototype = {
* @note history deletes are not undoable.
*/
_removeHistoryContainer: function PC__removeHistoryContainer(aContainerNode) {
if (PlacesUtils.nodeIsHost(aContainerNode)) {
// Site container.
PlacesUtils.history.removePagesFromHost(aContainerNode.title, true);
} else if (PlacesUtils.nodeIsDay(aContainerNode)) {
// Day container.
- let query = aContainerNode.getQueries()[0];
+ let query = aContainerNode.query;
let beginTime = query.beginTime;
let endTime = query.endTime;
if (!query || !beginTime || !endTime)
throw new Error("A valid date container query should exist!");
// We want to exclude beginTime from the removal because
// removePagesByTimeframe includes both extremes, while date containers
// exclude the lower extreme. So, if we would not exclude it, we would
// end up removing more history than requested.
--- a/browser/components/places/content/places.js
+++ b/browser/components/places/content/places.js
@@ -378,23 +378,16 @@ var PlacesOrganizer = {
/**
* Returns the options associated with the query currently loaded in the
* main places pane.
*/
getCurrentOptions: function PO_getCurrentOptions() {
return PlacesUtils.asQuery(ContentArea.currentView.result.root).queryOptions;
},
- /**
- * Returns the queries associated with the query currently loaded in the
- * main places pane.
- */
- getCurrentQueries: function PO_getCurrentQueries() {
- return PlacesUtils.asQuery(ContentArea.currentView.result.root).getQueries();
- },
/**
* Show the migration wizard for importing passwords,
* cookies, history, preferences, and bookmarks.
*/
importFromBrowser: function PO_importFromBrowser() {
// We pass in the type of source we're using for use in telemetry:
MigrationUtils.showMigrationWizard(window, [MigrationUtils.MIGRATION_ENTRYPOINT_PLACES]);
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -793,18 +793,17 @@ var PlacesUtils = {
* node.itemId, but for folder-shortcuts that's node.folderItemId.
*/
getConcreteItemId: function PU_getConcreteItemId(aNode) {
if (aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT)
return asQuery(aNode).folderItemId;
else if (PlacesUtils.nodeIsTagQuery(aNode)) {
// RESULTS_AS_TAG_CONTENTS queries are similar to folder shortcuts
// so we can still get the concrete itemId for them.
- var queries = aNode.getQueries();
- var folders = queries[0].getFolders();
+ let folders = aNode.query.getFolders();
return folders[0];
}
return aNode.itemId;
},
/**
* Gets the concrete item-guid for the given node. For everything but folder
* shortcuts, this is just node.bookmarkGuid. For folder shortcuts, this is
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -323,21 +323,20 @@ interface nsINavHistoryContainerResultNo
* Note that if you request places to *not* be expanded in the options that
* generated this node, this item will report it has no children and never try
* to populate itself.
*/
[scriptable, uuid(62817759-4FEE-44A3-B58C-3E2F5AFC9D0A)]
interface nsINavHistoryQueryResultNode : nsINavHistoryContainerResultNode
{
/**
- * Get the queries which build this node's children.
+ * Get the query which builds this node's children.
* Only valid for RESULT_TYPE_QUERY nodes.
*/
- void getQueries([optional] out unsigned long queryCount,
- [retval,array,size_is(queryCount)] out nsINavHistoryQuery queries);
+ readonly attribute nsINavHistoryQuery query;
/**
* Get the options which group this node's children.
* Only valid for RESULT_TYPE_QUERY nodes.
*/
readonly attribute nsINavHistoryQueryOptions queryOptions;
/**
--- a/toolkit/components/places/nsNavHistoryResult.cpp
+++ b/toolkit/components/places/nsNavHistoryResult.cpp
@@ -1950,30 +1950,24 @@ nsNavHistoryQueryResultNode::GetFolderIt
NS_IMETHODIMP
nsNavHistoryQueryResultNode::GetTargetFolderGuid(nsACString& aGuid) {
aGuid = EmptyCString();
return NS_OK;
}
NS_IMETHODIMP
-nsNavHistoryQueryResultNode::GetQueries(uint32_t* queryCount,
- nsINavHistoryQuery*** queries)
+nsNavHistoryQueryResultNode::GetQuery(nsINavHistoryQuery** _query)
{
nsresult rv = VerifyQueriesParsed();
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(mQueries.Count() > 0, "Must have >= 1 query");
- *queries = static_cast<nsINavHistoryQuery**>
- (moz_xmalloc(mQueries.Count() * sizeof(nsINavHistoryQuery*)));
- NS_ENSURE_TRUE(*queries, NS_ERROR_OUT_OF_MEMORY);
-
- for (int32_t i = 0; i < mQueries.Count(); ++i)
- NS_ADDREF((*queries)[i] = mQueries[i]);
- *queryCount = mQueries.Count();
+ nsCOMPtr<nsINavHistoryQuery> query = mQueries[0];
+ query.forget(_query);
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryResultNode::GetQueryOptions(
nsINavHistoryQueryOptions** aQueryOptions)
{
@@ -3092,60 +3086,50 @@ nsNavHistoryFolderResultNode::GetTargetF
NS_IMETHODIMP
nsNavHistoryFolderResultNode::GetUri(nsACString& aURI)
{
if (!mURI.IsEmpty()) {
aURI = mURI;
return NS_OK;
}
- uint32_t queryCount;
- nsINavHistoryQuery** queries;
- nsresult rv = GetQueries(&queryCount, &queries);
+ nsCOMPtr<nsINavHistoryQuery> query;
+ nsresult rv = GetQuery(getter_AddRefs(query));
NS_ENSURE_SUCCESS(rv, rv);
+ // make array of our 1 query
+ nsCOMArray<nsINavHistoryQuery> queries;
+ queries.AppendObject(query);
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
-
- rv = history->QueriesToQueryString(queries, queryCount, mOriginalOptions, mURI);
- for (uint32_t queryIndex = 0; queryIndex < queryCount; ++queryIndex) {
- NS_RELEASE(queries[queryIndex]);
- }
- free(queries);
+ rv = history->QueriesToQueryString(queries.Elements(), 1, mOriginalOptions, mURI);
NS_ENSURE_SUCCESS(rv, rv);
aURI = mURI;
return NS_OK;
}
/**
* @return the queries that give you this bookmarks folder
*/
NS_IMETHODIMP
-nsNavHistoryFolderResultNode::GetQueries(uint32_t* queryCount,
- nsINavHistoryQuery*** queries)
+nsNavHistoryFolderResultNode::GetQuery(nsINavHistoryQuery** _query)
{
// get the query object
nsCOMPtr<nsINavHistoryQuery> query;
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = history->GetNewQuery(getter_AddRefs(query));
NS_ENSURE_SUCCESS(rv, rv);
// query just has the folder ID set and nothing else
rv = query->SetFolders(&mTargetFolderItemId, 1);
NS_ENSURE_SUCCESS(rv, rv);
- // make array of our 1 query
- *queries = static_cast<nsINavHistoryQuery**>
- (moz_xmalloc(sizeof(nsINavHistoryQuery*)));
- if (!*queries)
- return NS_ERROR_OUT_OF_MEMORY;
- (*queries)[0] = query.forget().take();
- *queryCount = 1;
+ query.forget(_query);
return NS_OK;
}
/**
* Options for the query that gives you this bookmarks folder. This is just
* the options for the folder with the current folder ID set.
*/
--- a/toolkit/components/places/tests/queries/test_sort-date-site-grouping.js
+++ b/toolkit/components/places/tests/queries/test_sort-date-site-grouping.js
@@ -166,22 +166,19 @@ add_task(async function test_sort_date_s
root.containerOpen = false;
});
function checkFirstLevel(index, node, roots) {
PlacesUtils.asContainer(node).containerOpen = true;
Assert.ok(PlacesUtils.nodeIsDay(node));
PlacesUtils.asQuery(node);
- let queries = node.getQueries();
+ let query = node.query;
let options = node.queryOptions;
- Assert.equal(queries.length, 1);
- let query = queries[0];
-
Assert.ok(query.hasBeginTime && query.hasEndTime);
// Here we check the second level of results.
let root = PlacesUtils.history.executeQuery(query, options).root;
roots.push([]);
root.containerOpen = true;
Assert.equal(root.childCount, leveledTestData[index].length);
@@ -189,22 +186,19 @@ function checkFirstLevel(index, node, ro
let child = PlacesUtils.asQuery(root.getChild(secondIndex));
checkSecondLevel(index, secondIndex, child, roots);
}
root.containerOpen = false;
node.containerOpen = false;
}
function checkSecondLevel(index, secondIndex, child, roots) {
- let queries = child.getQueries();
+ let query = child.query;
let options = child.queryOptions;
- Assert.equal(queries.length, 1);
- let query = queries[0];
-
Assert.ok(query.hasDomain);
Assert.ok(query.hasBeginTime && query.hasEndTime);
let root = PlacesUtils.history.executeQuery(query, options).root;
// We should now have that roots[index][secondIndex] is set to the second
// level's results root.
roots[index].push(root);
--- a/toolkit/components/places/tests/unit/test_485442_crash_bug_nsNavHistoryQuery_GetUri.js
+++ b/toolkit/components/places/tests/unit/test_485442_crash_bug_nsNavHistoryQuery_GetUri.js
@@ -1,21 +1,16 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* 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/. */
-var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
- getService(Ci.nsINavHistoryService);
-
function run_test() {
- var query = hs.getNewQuery();
- var options = hs.getNewQueryOptions();
+ let query = PlacesUtils.history.getNewQuery();
+ let options = PlacesUtils.history.getNewQueryOptions();
options.resultType = options.RESULT_TYPE_QUERY;
- var result = hs.executeQuery(query, options);
- result.root.containerOpen = true;
- var rootNode = result.root;
- rootNode.QueryInterface(Ci.nsINavHistoryQueryResultNode);
- var queries = rootNode.getQueries();
- Assert.equal(queries[0].uri, null); // Should be null, instead of crashing the browser
- rootNode.containerOpen = false;
+ let root = PlacesUtils.history.executeQuery(query, options).root;
+ root.containerOpen = true;
+ Assert.equal(PlacesUtils.asQuery(root).query.uri, null,
+ "Should be null and not crash the browser");
+ root.containerOpen = false;
}