/src/mozilla-central/toolkit/components/places/nsNavHistory.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef nsNavHistory_h_ |
7 | | #define nsNavHistory_h_ |
8 | | |
9 | | #include "nsINavHistoryService.h" |
10 | | #include "nsINavBookmarksService.h" |
11 | | #include "nsIFaviconService.h" |
12 | | |
13 | | #include "nsIObserverService.h" |
14 | | #include "nsICollation.h" |
15 | | #include "nsIStringBundle.h" |
16 | | #include "nsITimer.h" |
17 | | #include "nsMaybeWeakPtr.h" |
18 | | #include "nsCategoryCache.h" |
19 | | #include "nsNetCID.h" |
20 | | #include "nsToolkitCompsCID.h" |
21 | | #include "nsURIHashKey.h" |
22 | | #include "nsTHashtable.h" |
23 | | |
24 | | #include "nsNavHistoryResult.h" |
25 | | #include "nsNavHistoryQuery.h" |
26 | | #include "Database.h" |
27 | | #include "mozilla/Attributes.h" |
28 | | #include "mozilla/Atomics.h" |
29 | | |
30 | | #ifdef XP_WIN |
31 | | #include "WinUtils.h" |
32 | | #include <wincrypt.h> |
33 | | #endif |
34 | | |
35 | 0 | #define QUERYUPDATE_TIME 0 |
36 | 0 | #define QUERYUPDATE_SIMPLE 1 |
37 | 0 | #define QUERYUPDATE_COMPLEX 2 |
38 | 0 | #define QUERYUPDATE_COMPLEX_WITH_BOOKMARKS 3 |
39 | 0 | #define QUERYUPDATE_HOST 4 |
40 | 0 | #define QUERYUPDATE_MOBILEPREF 5 |
41 | 0 | #define QUERYUPDATE_NONE 6 |
42 | | |
43 | | // Clamp title and URL to generously large, but not too large, length. |
44 | | // See bug 319004 for details. |
45 | 0 | #define URI_LENGTH_MAX 65536 |
46 | 0 | #define TITLE_LENGTH_MAX 4096 |
47 | | |
48 | | // Microsecond timeout for "recent" events such as typed and bookmark following. |
49 | | // If you typed it more than this time ago, it's not recent. |
50 | 0 | #define RECENT_EVENT_THRESHOLD PRTime((int64_t)15 * 60 * PR_USEC_PER_SEC) |
51 | | |
52 | | #ifdef MOZ_XUL |
53 | | // Fired after autocomplete feedback has been updated. |
54 | 0 | #define TOPIC_AUTOCOMPLETE_FEEDBACK_UPDATED "places-autocomplete-feedback-updated" |
55 | | #endif |
56 | | |
57 | | // The preference we watch to know when the mobile bookmarks folder is filled by |
58 | | // sync. |
59 | 0 | #define MOBILE_BOOKMARKS_PREF "browser.bookmarks.showMobileBookmarks" |
60 | | |
61 | | // The guid of the mobile bookmarks virtual query. |
62 | | #define MOBILE_BOOKMARKS_VIRTUAL_GUID "mobile____v" |
63 | | |
64 | 0 | #define ROOT_GUID "root________" |
65 | 0 | #define MENU_ROOT_GUID "menu________" |
66 | 0 | #define TOOLBAR_ROOT_GUID "toolbar_____" |
67 | 0 | #define UNFILED_ROOT_GUID "unfiled_____" |
68 | 0 | #define TAGS_ROOT_GUID "tags________" |
69 | 0 | #define MOBILE_ROOT_GUID "mobile______" |
70 | | |
71 | | class nsIAutoCompleteController; |
72 | | class nsIEffectiveTLDService; |
73 | | class nsIIDNService; |
74 | | class nsNavHistory; |
75 | | class PlacesSQLQueryBuilder; |
76 | | |
77 | | // nsNavHistory |
78 | | |
79 | | class nsNavHistory final : public nsSupportsWeakReference |
80 | | , public nsINavHistoryService |
81 | | , public nsIObserver |
82 | | , public mozIStorageVacuumParticipant |
83 | | { |
84 | | friend class PlacesSQLQueryBuilder; |
85 | | |
86 | | public: |
87 | | nsNavHistory(); |
88 | | |
89 | | NS_DECL_THREADSAFE_ISUPPORTS |
90 | | NS_DECL_NSINAVHISTORYSERVICE |
91 | | NS_DECL_NSIOBSERVER |
92 | | NS_DECL_MOZISTORAGEVACUUMPARTICIPANT |
93 | | |
94 | | /** |
95 | | * Obtains the nsNavHistory object. |
96 | | */ |
97 | | static already_AddRefed<nsNavHistory> GetSingleton(); |
98 | | |
99 | | /** |
100 | | * Initializes the nsNavHistory object. This should only be called once. |
101 | | */ |
102 | | nsresult Init(); |
103 | | |
104 | | /** |
105 | | * Used by other components in the places directory such as the annotation |
106 | | * service to get a reference to this history object. Returns a pointer to |
107 | | * the service if it exists. Otherwise creates one. Returns nullptr on error. |
108 | | */ |
109 | | static nsNavHistory* GetHistoryService() |
110 | 0 | { |
111 | 0 | if (!gHistoryService) { |
112 | 0 | nsCOMPtr<nsINavHistoryService> serv = |
113 | 0 | do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID); |
114 | 0 | NS_ENSURE_TRUE(serv, nullptr); |
115 | 0 | NS_ASSERTION(gHistoryService, "Should have static instance pointer now"); |
116 | 0 | } |
117 | 0 | return gHistoryService; |
118 | 0 | } |
119 | | |
120 | | /** |
121 | | * Used by other components in the places directory to get a reference to a |
122 | | * const version of this history object. |
123 | | * |
124 | | * @return A pointer to a const version of the service if it exists, |
125 | | * nullptr otherwise. |
126 | | */ |
127 | | static const nsNavHistory* GetConstHistoryService() |
128 | 0 | { |
129 | 0 | const nsNavHistory* const history = gHistoryService; |
130 | 0 | return history; |
131 | 0 | } |
132 | | |
133 | | /** |
134 | | * Fetches the database id and the GUID associated to the given URI. |
135 | | * |
136 | | * @param aURI |
137 | | * The page to look for. |
138 | | * @param _pageId |
139 | | * Will be set to the database id associated with the page. |
140 | | * If the page doesn't exist, this will be zero. |
141 | | * @param _GUID |
142 | | * Will be set to the unique id associated with the page. |
143 | | * If the page doesn't exist, this will be empty. |
144 | | * @note This DOES NOT check for bad URLs other than that they're nonempty. |
145 | | */ |
146 | | nsresult GetIdForPage(nsIURI* aURI, |
147 | | int64_t* _pageId, nsCString& _GUID); |
148 | | |
149 | | /** |
150 | | * Fetches the database id and the GUID associated to the given URI, creating |
151 | | * a new database entry if one doesn't exist yet. |
152 | | * |
153 | | * @param aURI |
154 | | * The page to look for or create. |
155 | | * @param _pageId |
156 | | * Will be set to the database id associated with the page. |
157 | | * @param _GUID |
158 | | * Will be set to the unique id associated with the page. |
159 | | * @note This DOES NOT check for bad URLs other than that they're nonempty. |
160 | | * @note This DOES NOT update frecency of the page. |
161 | | */ |
162 | | nsresult GetOrCreateIdForPage(nsIURI* aURI, |
163 | | int64_t* _pageId, nsCString& _GUID); |
164 | | |
165 | | /** |
166 | | * Asynchronously recalculates frecency for a given page. |
167 | | * |
168 | | * @param aPlaceId |
169 | | * Place id to recalculate the frecency for. |
170 | | * @note If the new frecency is a non-zero value it will also unhide the page, |
171 | | * otherwise will reuse the old hidden value. |
172 | | */ |
173 | | nsresult UpdateFrecency(int64_t aPlaceId); |
174 | | |
175 | | /** |
176 | | * These functions return non-owning references to the locale-specific |
177 | | * objects for places components. |
178 | | */ |
179 | | nsIStringBundle* GetBundle(); |
180 | | nsICollation* GetCollation(); |
181 | | void GetStringFromName(const char* aName, nsACString& aResult); |
182 | | void GetAgeInDaysString(int32_t aInt, const char* aName, nsACString& aResult); |
183 | | static void GetMonthName(const PRExplodedTime& aTime, nsACString& aResult); |
184 | | static void GetMonthYear(const PRExplodedTime& aTime, nsACString& aResult); |
185 | | |
186 | | // Returns whether history is enabled or not. |
187 | 0 | bool IsHistoryDisabled() { |
188 | 0 | return !mHistoryEnabled; |
189 | 0 | } |
190 | | |
191 | | // Constants for the columns returned by the above statement. |
192 | | static const int32_t kGetInfoIndex_PageID; |
193 | | static const int32_t kGetInfoIndex_URL; |
194 | | static const int32_t kGetInfoIndex_Title; |
195 | | static const int32_t kGetInfoIndex_RevHost; |
196 | | static const int32_t kGetInfoIndex_VisitCount; |
197 | | static const int32_t kGetInfoIndex_VisitDate; |
198 | | static const int32_t kGetInfoIndex_FaviconURL; |
199 | | static const int32_t kGetInfoIndex_ItemId; |
200 | | static const int32_t kGetInfoIndex_ItemDateAdded; |
201 | | static const int32_t kGetInfoIndex_ItemLastModified; |
202 | | static const int32_t kGetInfoIndex_ItemParentId; |
203 | | static const int32_t kGetInfoIndex_ItemTags; |
204 | | static const int32_t kGetInfoIndex_Frecency; |
205 | | static const int32_t kGetInfoIndex_Hidden; |
206 | | static const int32_t kGetInfoIndex_Guid; |
207 | | static const int32_t kGetInfoIndex_VisitId; |
208 | | static const int32_t kGetInfoIndex_FromVisitId; |
209 | | static const int32_t kGetInfoIndex_VisitType; |
210 | | |
211 | | int64_t GetTagsFolder(); |
212 | | |
213 | | // this actually executes a query and gives you results, it is used by |
214 | | // nsNavHistoryQueryResultNode |
215 | | nsresult GetQueryResults(nsNavHistoryQueryResultNode *aResultNode, |
216 | | const RefPtr<nsNavHistoryQuery>& aQuery, |
217 | | const RefPtr<nsNavHistoryQueryOptions>& aOptions, |
218 | | nsCOMArray<nsNavHistoryResultNode>* aResults); |
219 | | |
220 | | // Take a row of kGetInfoIndex_* columns and construct a ResultNode. |
221 | | // The row must contain the full set of columns. |
222 | | nsresult RowToResult(mozIStorageValueArray* aRow, |
223 | | nsNavHistoryQueryOptions* aOptions, |
224 | | nsNavHistoryResultNode** aResult); |
225 | | nsresult QueryRowToResult(int64_t aItemId, |
226 | | const nsACString& aBookmarkGuid, |
227 | | const nsACString& aURI, |
228 | | const nsACString& aTitle, |
229 | | uint32_t aAccessCount, |
230 | | PRTime aTime, |
231 | | nsNavHistoryResultNode** aNode); |
232 | | |
233 | | nsresult VisitIdToResultNode(int64_t visitId, |
234 | | nsNavHistoryQueryOptions* aOptions, |
235 | | nsNavHistoryResultNode** aResult); |
236 | | |
237 | | nsresult BookmarkIdToResultNode(int64_t aBookmarkId, |
238 | | nsNavHistoryQueryOptions* aOptions, |
239 | | nsNavHistoryResultNode** aResult); |
240 | | nsresult URIToResultNode(nsIURI* aURI, |
241 | | nsNavHistoryQueryOptions* aOptions, |
242 | | nsNavHistoryResultNode** aResult); |
243 | | |
244 | | // used by other places components to send history notifications (for example, |
245 | | // when the favicon has changed) |
246 | | void SendPageChangedNotification(nsIURI* aURI, uint32_t aChangedAttribute, |
247 | | const nsAString& aValue, |
248 | | const nsACString& aGUID); |
249 | | |
250 | | /** |
251 | | * Returns current number of days stored in history. |
252 | | */ |
253 | | int32_t GetDaysOfHistory(); |
254 | | |
255 | | void DomainNameFromURI(nsIURI* aURI, |
256 | | nsACString& aDomainName); |
257 | | static PRTime NormalizeTime(uint32_t aRelative, PRTime aOffset); |
258 | | |
259 | | typedef nsDataHashtable<nsCStringHashKey, nsCString> StringHash; |
260 | | |
261 | | /** |
262 | | * Indicates if it is OK to notify history observers or not. |
263 | | * |
264 | | * @return true if it is OK to notify, false otherwise. |
265 | | */ |
266 | 0 | bool canNotify() { return mCanNotify; } |
267 | | |
268 | | enum RecentEventFlags { |
269 | | RECENT_TYPED = 1 << 0, // User typed in URL recently |
270 | | RECENT_ACTIVATED = 1 << 1, // User tapped URL link recently |
271 | | RECENT_BOOKMARKED = 1 << 2 // User bookmarked URL recently |
272 | | }; |
273 | | |
274 | | /** |
275 | | * Returns any recent activity done with a URL. |
276 | | * @return Any recent events associated with this URI. Each bit is set |
277 | | * according to RecentEventFlags enum values. |
278 | | */ |
279 | | uint32_t GetRecentFlags(nsIURI *aURI); |
280 | | |
281 | | /** |
282 | | * Whether there are visits. |
283 | | * Note: This may cause synchronous I/O. |
284 | | */ |
285 | | bool hasHistoryEntries(); |
286 | | |
287 | | /** |
288 | | * Registers a TRANSITION_EMBED visit for the session. |
289 | | * |
290 | | * @param aURI |
291 | | * URI of the page. |
292 | | * @param aTime |
293 | | * Visit time. Only the last registered visit time is retained. |
294 | | */ |
295 | | void registerEmbedVisit(nsIURI* aURI, int64_t aTime); |
296 | | |
297 | | /** |
298 | | * Returns whether the specified url has a embed visit. |
299 | | * |
300 | | * @param aURI |
301 | | * URI of the page. |
302 | | * @return whether the page has a embed visit. |
303 | | */ |
304 | | bool hasEmbedVisit(nsIURI* aURI); |
305 | | |
306 | | int32_t GetFrecencyAgedWeight(int32_t aAgeInDays) const |
307 | 0 | { |
308 | 0 | if (aAgeInDays <= mFirstBucketCutoffInDays) { |
309 | 0 | return mFirstBucketWeight; |
310 | 0 | } |
311 | 0 | if (aAgeInDays <= mSecondBucketCutoffInDays) { |
312 | 0 | return mSecondBucketWeight; |
313 | 0 | } |
314 | 0 | if (aAgeInDays <= mThirdBucketCutoffInDays) { |
315 | 0 | return mThirdBucketWeight; |
316 | 0 | } |
317 | 0 | if (aAgeInDays <= mFourthBucketCutoffInDays) { |
318 | 0 | return mFourthBucketWeight; |
319 | 0 | } |
320 | 0 | return mDefaultWeight; |
321 | 0 | } |
322 | | |
323 | | int32_t GetFrecencyBucketWeight(int32_t aBucketIndex) const |
324 | | { |
325 | | switch(aBucketIndex) { |
326 | | case 1: |
327 | | return mFirstBucketWeight; |
328 | | case 2: |
329 | | return mSecondBucketWeight; |
330 | | case 3: |
331 | | return mThirdBucketWeight; |
332 | | case 4: |
333 | | return mFourthBucketWeight; |
334 | | default: |
335 | | return mDefaultWeight; |
336 | | } |
337 | | } |
338 | | |
339 | | int32_t GetFrecencyTransitionBonus(int32_t aTransitionType, |
340 | | bool aVisited, |
341 | | bool aRedirect = false) const |
342 | 0 | { |
343 | 0 | if (aRedirect) { |
344 | 0 | return mRedirectSourceVisitBonus; |
345 | 0 | } |
346 | 0 | |
347 | 0 | switch (aTransitionType) { |
348 | 0 | case nsINavHistoryService::TRANSITION_EMBED: |
349 | 0 | return mEmbedVisitBonus; |
350 | 0 | case nsINavHistoryService::TRANSITION_FRAMED_LINK: |
351 | 0 | return mFramedLinkVisitBonus; |
352 | 0 | case nsINavHistoryService::TRANSITION_LINK: |
353 | 0 | return mLinkVisitBonus; |
354 | 0 | case nsINavHistoryService::TRANSITION_TYPED: |
355 | 0 | return aVisited ? mTypedVisitBonus : mUnvisitedTypedBonus; |
356 | 0 | case nsINavHistoryService::TRANSITION_BOOKMARK: |
357 | 0 | return aVisited ? mBookmarkVisitBonus : mUnvisitedBookmarkBonus; |
358 | 0 | case nsINavHistoryService::TRANSITION_DOWNLOAD: |
359 | 0 | return mDownloadVisitBonus; |
360 | 0 | case nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT: |
361 | 0 | return mPermRedirectVisitBonus; |
362 | 0 | case nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY: |
363 | 0 | return mTempRedirectVisitBonus; |
364 | 0 | case nsINavHistoryService::TRANSITION_RELOAD: |
365 | 0 | return mReloadVisitBonus; |
366 | 0 | default: |
367 | 0 | // 0 == undefined (see bug #375777 for details) |
368 | 0 | NS_WARNING_ASSERTION(!aTransitionType, |
369 | 0 | "new transition but no bonus for frecency"); |
370 | 0 | return mDefaultVisitBonus; |
371 | 0 | } |
372 | 0 | } |
373 | | |
374 | | int32_t GetNumVisitsForFrecency() const |
375 | 0 | { |
376 | 0 | return mNumVisitsForFrecency; |
377 | 0 | } |
378 | | |
379 | | /** |
380 | | * Updates and invalidates the mDaysOfHistory cache. Should be |
381 | | * called whenever a visit is added. |
382 | | */ |
383 | | void UpdateDaysOfHistory(PRTime visitTime); |
384 | | |
385 | | /** |
386 | | * Fires onTitleChanged event to nsINavHistoryService observers |
387 | | */ |
388 | | void NotifyTitleChange(nsIURI* aURI, |
389 | | const nsString& title, |
390 | | const nsACString& aGUID); |
391 | | |
392 | | /** |
393 | | * Fires onFrecencyChanged event to nsINavHistoryService observers |
394 | | */ |
395 | | void NotifyFrecencyChanged(const nsACString& aSpec, |
396 | | int32_t aNewFrecency, |
397 | | const nsACString& aGUID, |
398 | | bool aHidden, |
399 | | PRTime aLastVisitDate); |
400 | | |
401 | | /** |
402 | | * Fires onManyFrecenciesChanged event to nsINavHistoryService observers |
403 | | */ |
404 | | void NotifyManyFrecenciesChanged(); |
405 | | |
406 | | /** |
407 | | * Posts a runnable to the main thread that calls NotifyFrecencyChanged. |
408 | | */ |
409 | | void DispatchFrecencyChangedNotification(const nsACString& aSpec, |
410 | | int32_t aNewFrecency, |
411 | | const nsACString& aGUID, |
412 | | bool aHidden, |
413 | | PRTime aLastVisitDate) const; |
414 | | |
415 | | /** |
416 | | * Returns true if frecency is currently being decayed. |
417 | | * |
418 | | * @return True if frecency is being decayed, false if not. |
419 | | */ |
420 | | bool IsFrecencyDecaying() const; |
421 | | |
422 | | /** |
423 | | * Store last insterted id for a table. |
424 | | */ |
425 | | static mozilla::Atomic<int64_t> sLastInsertedPlaceId; |
426 | | static mozilla::Atomic<int64_t> sLastInsertedVisitId; |
427 | | |
428 | | static void StoreLastInsertedId(const nsACString& aTable, |
429 | | const int64_t aLastInsertedId); |
430 | | |
431 | | #ifdef XP_WIN |
432 | | /** |
433 | | * Get the cached HCRYPTPROV initialized in the nsNavHistory constructor. |
434 | | */ |
435 | | nsresult GetCryptoProvider(HCRYPTPROV& aCryptoProvider) const { |
436 | | NS_ENSURE_STATE(mCryptoProviderInitialized); |
437 | | aCryptoProvider = mCryptoProvider; |
438 | | return NS_OK; |
439 | | } |
440 | | #endif |
441 | | |
442 | | |
443 | | static nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode, |
444 | | const nsCOMArray<nsNavHistoryResultNode>& aSet, |
445 | | nsCOMArray<nsNavHistoryResultNode>* aFiltered, |
446 | | const RefPtr<nsNavHistoryQuery>& aQuery, |
447 | | nsNavHistoryQueryOptions* aOptions); |
448 | | |
449 | | void DecayFrecencyCompleted(uint16_t reason); |
450 | | |
451 | | private: |
452 | | ~nsNavHistory(); |
453 | | |
454 | | // used by GetHistoryService |
455 | | static nsNavHistory *gHistoryService; |
456 | | |
457 | | protected: |
458 | | |
459 | | // Database handle. |
460 | | RefPtr<mozilla::places::Database> mDB; |
461 | | |
462 | | /** |
463 | | * Recalculates frecency for all pages where frecency < 0, then decays |
464 | | * frecency and inputhistory values. Pages can invalidate frecencies: |
465 | | * * After a "clear private data" |
466 | | * * After removing visits |
467 | | * * After migrating from older versions |
468 | | * This method runs on idle-daily. |
469 | | */ |
470 | | nsresult FixAndDecayFrecency(); |
471 | | |
472 | | /** |
473 | | * Loads all of the preferences that we use into member variables. |
474 | | * |
475 | | * @note If mPrefBranch is nullptr, this does nothing. |
476 | | */ |
477 | | void LoadPrefs(); |
478 | | |
479 | | /** |
480 | | * Calculates and returns value for mCachedNow. |
481 | | * This is an hack to avoid calling PR_Now() too often, as is the case when |
482 | | * we're asked the ageindays of many history entries in a row. A timer is |
483 | | * set which will clear our valid flag after a short timeout. |
484 | | */ |
485 | | PRTime GetNow(); |
486 | | PRTime mCachedNow; |
487 | | nsCOMPtr<nsITimer> mExpireNowTimer; |
488 | | /** |
489 | | * Called when the cached now value is expired and needs renewal. |
490 | | */ |
491 | | static void expireNowTimerCallback(nsITimer* aTimer, void* aClosure); |
492 | | |
493 | | nsresult ConstructQueryString(const RefPtr<nsNavHistoryQuery>& aQuery, |
494 | | const RefPtr<nsNavHistoryQueryOptions>& aOptions, |
495 | | nsCString& queryString, |
496 | | bool& aParamsPresent, |
497 | | StringHash& aAddParams); |
498 | | |
499 | | nsresult QueryToSelectClause(const RefPtr<nsNavHistoryQuery>& aQuery, |
500 | | const RefPtr<nsNavHistoryQueryOptions>& aOptions, |
501 | | nsCString* aClause); |
502 | | nsresult BindQueryClauseParameters(mozIStorageBaseStatement* statement, |
503 | | const RefPtr<nsNavHistoryQuery>& aQuery, |
504 | | const RefPtr<nsNavHistoryQueryOptions>& aOptions); |
505 | | |
506 | | nsresult ResultsAsList(mozIStorageStatement* statement, |
507 | | nsNavHistoryQueryOptions* aOptions, |
508 | | nsCOMArray<nsNavHistoryResultNode>* aResults); |
509 | | |
510 | | // observers |
511 | | nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers; |
512 | | |
513 | | // effective tld service |
514 | | nsCOMPtr<nsIEffectiveTLDService> mTLDService; |
515 | | nsCOMPtr<nsIIDNService> mIDNService; |
516 | | |
517 | | // localization |
518 | | nsCOMPtr<nsIStringBundle> mBundle; |
519 | | nsCOMPtr<nsICollation> mCollation; |
520 | | |
521 | | // recent events |
522 | | typedef nsDataHashtable<nsCStringHashKey, int64_t> RecentEventHash; |
523 | | RecentEventHash mRecentTyped; |
524 | | RecentEventHash mRecentLink; |
525 | | RecentEventHash mRecentBookmark; |
526 | | |
527 | | // Embed visits tracking. |
528 | | class VisitHashKey : public nsURIHashKey |
529 | | { |
530 | | public: |
531 | | explicit VisitHashKey(const nsIURI* aURI) |
532 | | : nsURIHashKey(aURI) |
533 | 0 | { |
534 | 0 | } |
535 | | VisitHashKey(VisitHashKey&& aOther) |
536 | | : nsURIHashKey(std::move(aOther)) |
537 | 0 | { |
538 | 0 | MOZ_ASSERT_UNREACHABLE("Do not call me!"); |
539 | 0 | } |
540 | | PRTime visitTime; |
541 | | }; |
542 | | |
543 | | nsTHashtable<VisitHashKey> mEmbedVisits; |
544 | | |
545 | | bool CheckIsRecentEvent(RecentEventHash* hashTable, |
546 | | const nsACString& url); |
547 | | void ExpireNonrecentEvents(RecentEventHash* hashTable); |
548 | | |
549 | | #ifdef MOZ_XUL |
550 | | nsresult AutoCompleteFeedback(int32_t aIndex, |
551 | | nsIAutoCompleteController *aController); |
552 | | #endif |
553 | | |
554 | | // Whether history is enabled or not. |
555 | | // Will mimic value of the places.history.enabled preference. |
556 | | bool mHistoryEnabled; |
557 | | |
558 | | // Frecency preferences. |
559 | | int32_t mNumVisitsForFrecency; |
560 | | int32_t mFirstBucketCutoffInDays; |
561 | | int32_t mSecondBucketCutoffInDays; |
562 | | int32_t mThirdBucketCutoffInDays; |
563 | | int32_t mFourthBucketCutoffInDays; |
564 | | int32_t mFirstBucketWeight; |
565 | | int32_t mSecondBucketWeight; |
566 | | int32_t mThirdBucketWeight; |
567 | | int32_t mFourthBucketWeight; |
568 | | int32_t mDefaultWeight; |
569 | | int32_t mEmbedVisitBonus; |
570 | | int32_t mFramedLinkVisitBonus; |
571 | | int32_t mLinkVisitBonus; |
572 | | int32_t mTypedVisitBonus; |
573 | | int32_t mBookmarkVisitBonus; |
574 | | int32_t mDownloadVisitBonus; |
575 | | int32_t mPermRedirectVisitBonus; |
576 | | int32_t mTempRedirectVisitBonus; |
577 | | int32_t mRedirectSourceVisitBonus; |
578 | | int32_t mDefaultVisitBonus; |
579 | | int32_t mUnvisitedBookmarkBonus; |
580 | | int32_t mUnvisitedTypedBonus; |
581 | | int32_t mReloadVisitBonus; |
582 | | |
583 | | uint32_t mDecayFrecencyPendingCount; |
584 | | |
585 | | nsresult RecalculateOriginFrecencyStatsInternal(); |
586 | | |
587 | | // in nsNavHistoryQuery.cpp |
588 | | nsresult TokensToQuery(const nsTArray<mozilla::places::QueryKeyValuePair>& aTokens, |
589 | | nsNavHistoryQuery* aQuery, |
590 | | nsNavHistoryQueryOptions* aOptions); |
591 | | |
592 | | int64_t mTagsFolder; |
593 | | |
594 | | int32_t mDaysOfHistory; |
595 | | int64_t mLastCachedStartOfDay; |
596 | | int64_t mLastCachedEndOfDay; |
597 | | |
598 | | // Used to enable and disable the observer notifications |
599 | | bool mCanNotify; |
600 | | |
601 | | // Used to cache the call to CryptAcquireContext, which is expensive |
602 | | // when called thousands of times |
603 | | #ifdef XP_WIN |
604 | | HCRYPTPROV mCryptoProvider; |
605 | | bool mCryptoProviderInitialized; |
606 | | #endif |
607 | | }; |
608 | | |
609 | | |
610 | | #define PLACES_URI_PREFIX "place:" |
611 | | |
612 | | /* Returns true if the given URI represents a history query. */ |
613 | | inline bool IsQueryURI(const nsCString &uri) |
614 | 0 | { |
615 | 0 | return StringBeginsWith(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX)); |
616 | 0 | } |
617 | | |
618 | | /* Extracts the query string from a query URI. */ |
619 | | inline const nsDependentCSubstring QueryURIToQuery(const nsCString &uri) |
620 | 0 | { |
621 | 0 | NS_ASSERTION(IsQueryURI(uri), "should only be called for query URIs"); |
622 | 0 | return Substring(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX).Length()); |
623 | 0 | } |
624 | | |
625 | | #endif // nsNavHistory_h_ |