nsINavHistoryService
From MDC
This article covers features introduced in Firefox 3
The nsINavHistoryService interface provides complex query functions, more fine-grained getters and setters.
nsINavHistoryService is defined in toolkit/components/places/public/nsINavHistoryService.idl. It is scriptable and
unfrozen (hasn't changed since Mozilla 1.9).
Inherits from: nsISupports
Implemented by: "@mozilla.org/browser/nav-history-service;1". To use this service, use:
var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
[edit] Method overview
AString getPageTitle(in nsIURI aURI);
|
void markPageAsFollowedBookmark(in nsIURI aURI);
|
boolean canAddURI(in nsIURI aURI);
|
void setPageDetails(in nsIURI aURI, in AString aTitle, in unsigned long aVisitCount, in boolean aHidden, in boolean aTyped);
|
long long addVisit(in nsIURI aURI, in PRTime aTime, in long long aReferringVisit, in long aTransitionType, in boolean aIsRedirect, in long long aSessionID);
|
nsINavHistoryQuery getNewQuery();
|
nsINavHistoryQueryOptions getNewQueryOptions();
|
nsINavHistoryResult executeQuery(in nsINavHistoryQuery aQuery, in nsINavHistoryQueryOptions options);
|
nsINavHistoryResult executeQueries([array,size_is(aQueryCount)] in nsINavHistoryQuery aQueries, in unsigned long aQueryCount, in nsINavHistoryQueryOptions options);
|
void queryStringToQueries(in AUTF8String aQueryString, [array, size_is(aResultCount)] out nsINavHistoryQuery aQueries, out unsigned long aResultCount, out nsINavHistoryQueryOptions options);
|
AUTF8String queriesToQueryString([array, size_is(aQueryCount)] in nsINavHistoryQuery aQueries, in unsigned long aQueryCount, in nsINavHistoryQueryOptions options);
|
void addObserver(in nsINavHistoryObserver observer, in boolean ownsWeak);
|
void removeObserver(in nsINavHistoryObserver observer);
|
void runInBatchMode(in nsINavHistoryBatchCallback aCallback, in nsISupports aClosure);
|
void importHistory(in nsIFile file);
|
[edit] Attributes
| Attribute | Type | Description |
hasHistoryEntries
| boolean
| True if there is any history. This can be used in UI to determine whether the "clear history" button should be enabled or not. This is much better than using BrowserHistory.count since that can be very slow if there is a lot of history (it must enumerate each item). This is pretty fast.
|
historyDisabled
| boolean
| True if history is disabled. currently, history is disabled if the browser.history_expire_days pref is "0".
|
[edit] Constants
| Constant | Value | Description |
TRANSITION_LINK
| 1 | This transition type means the user followed a link and got a new toplevel window. |
TRANSITION_TYPED
| 2 | This transition is set when the user followed a bookmark to get to the page. |
TRANSITION_BOOKMARK
| 3 | This transition is set when the user followed a bookmark to get to the page. |
TRANSITION_EMBED
| 4 | This transition type is set when some inner content is loaded. This is true of all images on a page, and the contents of the iframe. It is also true of any content in a frame, regardless if whether or not the user clicked something to get there. |
TRANSITION_REDIRECT_PERMANENT
| 5 | This transition is set when the transition was a permanent redirect. |
TRANSITION_REDIRECT_TEMPORARY
| 6 | This transition is set when the transition was a temporary redirect. |
TRANSITION_DOWNLOAD
| 7 | This transition is set when the transition is a download. |
[edit] Methods
[edit] getPageTitle()
This method retrieves the original title of the page.
AString getPageTitle( in nsIURI aURI );
[edit] Parameters
- aURI
- The page whose title needs to be retrieved.
[edit] Return value
Returns the original title of the page.
[edit] markPageAsFollowedBookmark()
This method is just like markPageAsTyped (in nsIBrowserHistory, also implemented by the history service), but for bookmarks. It declares that the given URI is being opened as a result of following a bookmark. If this URI is loaded soon after this message has been received, that transition will be marked as following a bookmark.
void markPageAsFollowedBookmark( in nsIURI aURI );
[edit] Parameters
- aURI
- The page that is to be marked as followed by a bookmark.
[edit] canAddURI()
This method checks if the given URI would be added to the history or not. Many types of URIs, such as "chrome:" URIs, are not stored when addURI is called. This function allows you to determine whether it will be or not.
You don't have to worry about calling this, addPageToSession/addURI will always check before actually adding the page. This function is public because some components may want to check if this page would go in the history (i.e. for annotations).
boolean canAddURI( in nsIURI aURI );
[edit] Parameters
- aURI
- The URI that needs to be added to the history system.
[edit] Return value
Returns true if this URI would be added to the history, otherwise returns false.
[edit] setPageDetails()
This method sets the full information for a given page. If the page does not exist, it will be added to the database. If it does, the existing values will be overwritten. This is an updated version of addPageWithDetails for backup/restore type operations.
void setPageDetails( in nsIURI aURI, in AString aTitle, in unsigned long aVisitCount, in boolean aHidden, in boolean aTyped );
[edit] Parameters
- aURI
- The page to be added or changed.
- aTitle
- The title as specified by the page.
- aVisitCount
- The number of times this page has been visited. Setting this to
"0"may make the page invisible in some views. - aHidden
- Whether the page is hidden or not. If the page has only
TRANSITION_EMBEDvisits, this will betrue, otherwise it will befalse. - aTyped
Trueif this URI has ever been typed, otherwisefalse.
[edit] addVisit()
This method adds a visit for a specific page. This will probably not be commonly used other than for backup/restore type operations. If the URI does not have an entry in the history database already, one will be created with no visits, no title, hidden, not typed. Adding a visit will automatically increment the visit count for the visited page and will unhide it and/or mark it typed according to the transition type.
long long addVisit( in nsIURI aURI, in PRTime aTime, in long long aReferringVisit, in long aTransitionType, in boolean aIsRedirect, in long long aSessionID );
[edit] Parameters
- aURI
- The visited page.
- aTime
- The time page was visited (microseconds).
- aReferringVisit
- The ID of the visit that generated this one. Use
"0"for no referrer. This must be a valid visit already in the Database or"0". - aTransitionType
- The type of transition: one of
TRANSITION_*defined above. - aIsRedirect
Trueif the given visit redirects to somewhere else (i.e you will create a visit out of here that is a redirect transition). This causes this page to be hidden in normal history views (unless it has been unhidden by visiting it with a non-redirect).- aSessionID
- The session ID that this page belongs to. Use
"0"for no session.
[edit] Return value
Returns the ID of the created visit. This will be "0" if the URI is not valid for adding to history (canAddURI = false).
[edit] getNewQuery()
This method returns a new query object that you can pass to executeQuer[y/ies] methods. It will be initialized to all empty (so using it will give you all history).
nsINavHistoryQuery getNewQuery();
[edit] Parameters
None.
[edit] Return value
Returns a new query object.
[edit] getNewQueryOptions()
This method returns a new options object that you can pass to executeQuer[y/ies] methods after setting the desired options.
nsINavHistoryQueryOptions getNewQueryOptions();
[edit] Parameters
None.
[edit] Return value
Returns a new options object.
[edit] executeQuery()
This method executes a query with a single query object and options. All the parameters set on the query object will be ANDed together.
nsINavHistoryResult executeQuery( in nsINavHistoryQuery aQuery, in nsINavHistoryQueryOptions options );
[edit] Parameters
- aQuery
- The query object.
- options
- The options object.
[edit] Return value
Returns a new result object.
[edit] executeQueries()
This method is similar to executeQuery method. It executes an array of queries. All of the query objects are ORed together. Within a query, all the terms are ANDed together as in executeQuery method.
nsINavHistoryResult executeQueries( [array,size_is(aQueryCount)] in nsINavHistoryQuery aQueries, in unsigned long aQueryCount, in nsINavHistoryQueryOptions options );
[edit] Parameters
- aQueries
- The queries object.
- aQueryCount
- The count of queries.
- options
- The options object.
[edit] Return value
Returns a new result object.
[edit] queryStringToQueries()
This method converts a query URI-like string to an array of actual query objects for use to executeQueries method. The output query array may be empty if there is no information. However, there will always be an options structure returned (if nothing is defined, it will just have the default values).
void queryStringToQueries( in AUTF8String aQueryString, [array, size_is(aResultCount)] out nsINavHistoryQuery aQueries, out unsigned long aResultCount, out nsINavHistoryQueryOptions options );
[edit] Parameters
- aQueryString
- The query URI-like string.
- aQueries
- The queries object.
- aResultCount
- The count of converted queries.
- options
- The options object.
[edit] queriesToQueryString()
This method converts a query into an equivalent string that can be persisted. Inverse of queryStringToQueries method.
AUTF8String queriesToQueryString( [array, size_is(aQueryCount)] in nsINavHistoryQuery aQueries, in unsigned long aQueryCount, in nsINavHistoryQueryOptions options );
[edit] Parameters
- aQueries
- The queries object.
- aQueryCount
- The count queries.
- options
- The options object.
[edit] Return value
Returns the converted query into an equivalent string query.
[edit] addObserver()
This method adds a history observer. If ownsWeak is false, the history service will keep an owning reference to the observer. If ownsWeak is true, then aObserver must implement nsISupportsWeakReference, and the history service will keep a weak reference to the observer.
void addObserver( in nsINavHistoryObserver observer, in boolean ownsWeak );
[edit] Parameters
- observer
- The history observer to be added.
- ownsWeak
- The owning reference state
(boolean).
[edit] removeObserver()
This method removes a history observer.
void removeObserver( in nsINavHistoryObserver observer );
[edit] Parameters
- observer
- The history observer to be removed.
[edit] runInBatchMode()
This method runs the passed callback in batch mode. Use this when a lot of things are about to change. Calls can be nested, observers will only be notified when all batches begin/end.
void runInBatchMode( in nsINavHistoryBatchCallback aCallback, in nsISupports aClosure );
[edit] Parameters
- aCallback
nsINavHistoryBatchCallbackinterface to call.- aClosure
- Opaque parameter passed to
nsINavBookmarksBatchCallback.
[edit] importHistory()
This method imports the given Mork history file.
void importHistory( in nsIFile file );
[edit] Parameters
- file
- The Mork history file to import.
[edit] See also
- Places
- Using the Places history service
- Querying Places
- nsINavHistoryBatchCallback
- nsINavHistoryContainerResultNode
- nsINavHistoryFullVisitResultNode
- nsINavHistoryObserver
- nsINavHistoryQuery
- nsINavHistoryQueryOptions
- nsINavHistoryQueryResultNode
- nsINavHistoryResult
- nsINavHistoryResultNode
- nsINavHistoryResultTreeViewer
- nsINavHistoryResultViewObserver
- nsINavHistoryResultViewer
- nsINavHistoryVisitResultNode