| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/toolkit/components/places/./../../../../toolkit/components/places/nsNavHistory.cpp |
| Warning: | line 2551, column 5 Value stored to 'rv' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #include "mozilla/Components.h" |
| 8 | #include "mozilla/IntegerPrintfMacros.h" |
| 9 | #include "mozilla/intl/LocaleService.h" |
| 10 | #include "mozilla/StaticPrefs_places.h" |
| 11 | |
| 12 | #include "nsNavHistory.h" |
| 13 | |
| 14 | #include "mozIPlacesAutoComplete.h" |
| 15 | #include "nsNavBookmarks.h" |
| 16 | #include "nsFaviconService.h" |
| 17 | #include "nsPlacesMacros.h" |
| 18 | #include "nsPlacesTriggers.h" |
| 19 | #include "mozilla/intl/AppDateTimeFormat.h" |
| 20 | #include "History.h" |
| 21 | #include "Helpers.h" |
| 22 | #include "NotifyRankingChanged.h" |
| 23 | |
| 24 | #include "mozIStorageValueArray.h" |
| 25 | #include "nsTArray.h" |
| 26 | #include "nsNetUtil.h" |
| 27 | #include "nsPrintfCString.h" |
| 28 | #include "nsPromiseFlatString.h" |
| 29 | #include "nsString.h" |
| 30 | #include "nsUnicharUtils.h" |
| 31 | #include "prsystem.h" |
| 32 | #include "prtime.h" |
| 33 | #include "nsEscape.h" |
| 34 | #include "nsIEffectiveTLDService.h" |
| 35 | #include "nsIClassInfoImpl.h" |
| 36 | #include "nsIIDNService.h" |
| 37 | #include "nsQueryObject.h" |
| 38 | #include "nsThreadUtils.h" |
| 39 | #include "nsAppDirectoryServiceDefs.h" |
| 40 | #include "nsMathUtils.h" |
| 41 | #include "nsReadableUtils.h" |
| 42 | #include "mozilla/storage.h" |
| 43 | #include "mozilla/Preferences.h" |
| 44 | #include <algorithm> |
| 45 | #include <numbers> |
| 46 | |
| 47 | using namespace mozilla; |
| 48 | using namespace mozilla::places; |
| 49 | |
| 50 | // The maximum number of things that we will store in the recent events list |
| 51 | // before calling ExpireNonrecentEvents. This number should be big enough so it |
| 52 | // is very difficult to get that many unconsumed events (for example, typed but |
| 53 | // never visited) in the RECENT_EVENT_THRESHOLD. Otherwise, we'll start |
| 54 | // checking each one for every page visit, which will be somewhat slower. |
| 55 | #define RECENT_EVENT_QUEUE_MAX_LENGTH128 128 |
| 56 | |
| 57 | // preference ID strings |
| 58 | #define PREF_HISTORY_ENABLED"places.history.enabled" "places.history.enabled" |
| 59 | #define PREF_MATCH_DIACRITICS"places.search.matchDiacritics" "places.search.matchDiacritics" |
| 60 | |
| 61 | // In order to avoid calling PR_now() too often we use a cached "now" value |
| 62 | // for repeating stuff. These are milliseconds between "now" cache refreshes. |
| 63 | #define RENEW_CACHED_NOW_TIMEOUT((int32_t)3 * 1000L) ((int32_t)3 * PR_MSEC_PER_SEC1000L) |
| 64 | |
| 65 | // These macros are used when splitting history by date. |
| 66 | // These are the day containers and catch-all final container. |
| 67 | #define HISTORY_ADDITIONAL_DATE_CONT_NUM3 3 |
| 68 | // We use a guess of the number of months considering all of them 30 days |
| 69 | // long, but we split only the last 6 months. |
| 70 | #define HISTORY_DATE_CONT_NUM(_daysFromOldestVisit)(3 + std::min(6, (int32_t)ceilf((float)_daysFromOldestVisit / 30))) \ |
| 71 | (HISTORY_ADDITIONAL_DATE_CONT_NUM3 + \ |
| 72 | std::min(6, (int32_t)ceilf((float)_daysFromOldestVisit / 30))) |
| 73 | // Max number of containers, used to initialize the params hash. |
| 74 | #define HISTORY_DATE_CONT_LENGTH8 8 |
| 75 | |
| 76 | // Initial length of the recent events cache. |
| 77 | #define RECENT_EVENTS_INITIAL_CACHE_LENGTH64 64 |
| 78 | |
| 79 | // Observed topics. |
| 80 | #define TOPIC_IDLE_DAILY"idle-daily" "idle-daily" |
| 81 | #define TOPIC_PREF_CHANGED"nsPref:changed" "nsPref:changed" |
| 82 | #define TOPIC_PROFILE_TEARDOWN"profile-change-teardown" "profile-change-teardown" |
| 83 | #define TOPIC_PROFILE_CHANGE"profile-before-change" "profile-before-change" |
| 84 | #define TOPIC_APP_LOCALES_CHANGED"intl:app-locales-changed" "intl:app-locales-changed" |
| 85 | |
| 86 | #define USEC_PER_DAY86400000000LL 86400000000LL |
| 87 | |
| 88 | static const char* kObservedPrefs[] = {PREF_HISTORY_ENABLED"places.history.enabled", |
| 89 | PREF_MATCH_DIACRITICS"places.search.matchDiacritics", nullptr}; |
| 90 | |
| 91 | NS_IMPL_ADDREF(nsNavHistory)MozExternalRefCountType nsNavHistory::AddRef(void) { static_assert (!std::is_destructible_v<nsNavHistory>, "Reference-counted class " "nsNavHistory" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 91); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 91 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsNavHistory" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("nsNavHistory" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsNavHistory\" != nullptr" " (" "Must specify a name" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 91); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsNavHistory\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 91); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("nsNavHistory" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("nsNavHistory"), (uint32_t)( sizeof(*this))); return count; } |
| 92 | NS_IMPL_RELEASE(nsNavHistory)MozExternalRefCountType nsNavHistory::Release(void) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 92); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 92) ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsNavHistory" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("nsNavHistory" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"nsNavHistory\" != nullptr" " (" "Must specify a name" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 92); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsNavHistory\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 92); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("nsNavHistory" " not thread-safe"); const char* const nametmp = "nsNavHistory"; nsrefcnt count = --mRefCnt; NS_LogRelease( (this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } |
| 93 | |
| 94 | NS_IMPL_CLASSINFO(nsNavHistory, nullptr, nsIClassInfo::SINGLETON,extern nsresult nsNavHistory_GetInterfacesHelper(nsTArray< nsIID> & array); static const GenericClassInfo::ClassInfoData knsNavHistoryClassInfoData = { nsNavHistory_GetInterfacesHelper , nullptr, nsIClassInfo::SINGLETON | nsIClassInfo::SINGLETON_CLASSINFO , {0x88cecbb7, 0x6c63, 0x4b3b, {0x8c, 0xd4, 0x84, 0xf3, 0xb8, 0x22, 0x8c, 0x69}}, }; mozilla::AlignedStorage2<GenericClassInfo > knsNavHistoryClassInfoDataPlace; nsIClassInfo* gnsNavHistory_classInfoGlobal = nullptr; |
| 95 | NS_NAVHISTORYSERVICE_CID)extern nsresult nsNavHistory_GetInterfacesHelper(nsTArray< nsIID> & array); static const GenericClassInfo::ClassInfoData knsNavHistoryClassInfoData = { nsNavHistory_GetInterfacesHelper , nullptr, nsIClassInfo::SINGLETON | nsIClassInfo::SINGLETON_CLASSINFO , {0x88cecbb7, 0x6c63, 0x4b3b, {0x8c, 0xd4, 0x84, 0xf3, 0xb8, 0x22, 0x8c, 0x69}}, }; mozilla::AlignedStorage2<GenericClassInfo > knsNavHistoryClassInfoDataPlace; nsIClassInfo* gnsNavHistory_classInfoGlobal = nullptr; |
| 96 | NS_INTERFACE_MAP_BEGIN(nsNavHistory)nsresult nsNavHistory::QueryInterface(const nsIID& aIID, void ** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak( NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 96); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface ; |
| 97 | NS_INTERFACE_MAP_ENTRY(nsINavHistoryService)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsINavHistoryService>)) foundInterface = static_cast<nsINavHistoryService*>(this); else |
| 98 | NS_INTERFACE_MAP_ENTRY(nsIObserver)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsIObserver>)) foundInterface = static_cast <nsIObserver*>(this); else |
| 99 | NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsISupportsWeakReference>)) foundInterface = static_cast<nsISupportsWeakReference*>(this); else |
| 100 | NS_INTERFACE_MAP_ENTRY(mozIStorageVacuumParticipant)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, mozIStorageVacuumParticipant>)) foundInterface = static_cast<mozIStorageVacuumParticipant*>(this); else |
| 101 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINavHistoryService)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsISupports>)) foundInterface = static_cast <nsISupports*>(static_cast<nsINavHistoryService*> (this)); else |
| 102 | NS_IMPL_QUERY_CLASSINFO(nsNavHistory)if (aIID.Equals((nsIClassInfo::kIID))) { if (!gnsNavHistory_classInfoGlobal ) gnsNavHistory_classInfoGlobal = new (knsNavHistoryClassInfoDataPlace .addr()) GenericClassInfo(&knsNavHistoryClassInfoData); foundInterface = gnsNavHistory_classInfoGlobal; } else |
| 103 | NS_INTERFACE_MAP_ENDfoundInterface = 0; nsresult status; if (!foundInterface) { do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aIID.Equals((nsISupports::kIID)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aIID.Equals((nsISupports::kIID ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!aIID.Equals((nsISupports::kIID))", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 103); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::kIID))" ")"); do { MOZ_CrashSequence(__null, 103); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE ; } else { (foundInterface)->AddRef(); status = NS_OK; } * aInstancePtr = foundInterface; return status; } |
| 104 | |
| 105 | // We don't care about flattening everything |
| 106 | NS_IMPL_CI_INTERFACE_GETTER(nsNavHistory, nsINavHistoryService)static_assert(1 > 0, "Need more arguments to NS_IMPL_CI_INTERFACE_GETTER" ); nsresult nsNavHistory_GetInterfacesHelper(nsTArray<nsIID > & array) { array.Clear(); array.SetCapacity(1); array .AppendElement((nsINavHistoryService::kIID)); return NS_OK; } |
| 107 | |
| 108 | namespace { |
| 109 | |
| 110 | static Maybe<nsCString> GetSimpleBookmarksQueryParent( |
| 111 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 112 | const RefPtr<nsNavHistoryQueryOptions>& aOptions); |
| 113 | static void ParseSearchTermsFromQuery(const RefPtr<nsNavHistoryQuery>& aQuery, |
| 114 | nsTArray<nsString>* aTerms); |
| 115 | |
| 116 | nsresult FetchInfo(const RefPtr<mozilla::places::Database>& aDB, |
| 117 | const nsCString& aGUID, int32_t& aType, int64_t& aId, |
| 118 | nsCString& aTitle, PRTime& aDateAdded, |
| 119 | PRTime& aLastModified) { |
| 120 | nsCOMPtr<mozIStorageStatement> statement = aDB->GetStatement( |
| 121 | "SELECT type, id, title, dateAdded, lastModified FROM moz_bookmarks " |
| 122 | "WHERE guid = :guid"); |
| 123 | NS_ENSURE_STATE(statement)do { if ((__builtin_expect(!!(!(statement)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "statement" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 123); return NS_ERROR_UNEXPECTED; } } while (false); |
| 124 | mozStorageStatementScoper scoper(statement); |
| 125 | nsresult rv = statement->BindUTF8StringByName("guid"_ns, aGUID); |
| 126 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 126); return rv; } } while (false); |
| 127 | |
| 128 | bool hasResult; |
| 129 | rv = statement->ExecuteStep(&hasResult); |
| 130 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 130); return rv; } } while (false); |
| 131 | if (!hasResult) { |
| 132 | return NS_ERROR_INVALID_ARG; |
| 133 | } |
| 134 | |
| 135 | aType = statement->AsInt32(0); |
| 136 | aId = statement->AsInt64(1); |
| 137 | |
| 138 | bool isNull; |
| 139 | rv = statement->GetIsNull(2, &isNull); |
| 140 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 140); return rv; } } while (false); |
| 141 | if (isNull) { |
| 142 | aTitle.SetIsVoid(true); |
| 143 | } else { |
| 144 | rv = statement->GetUTF8String(2, aTitle); |
| 145 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 145); return rv; } } while (false); |
| 146 | } |
| 147 | |
| 148 | aDateAdded = statement->AsInt64(3); |
| 149 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 149); return rv; } } while (false); |
| 150 | aLastModified = statement->AsInt64(4); |
| 151 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 151); return rv; } } while (false); |
| 152 | |
| 153 | return NS_OK; |
| 154 | } |
| 155 | |
| 156 | } // namespace |
| 157 | |
| 158 | // Queries rows indexes to bind or get values, if adding a new one, be sure to |
| 159 | // update nsNavBookmarks statements and its kGetChildrenIndex_* constants |
| 160 | const int32_t nsNavHistory::kGetInfoIndex_PageID = 0; |
| 161 | const int32_t nsNavHistory::kGetInfoIndex_URL = 1; |
| 162 | const int32_t nsNavHistory::kGetInfoIndex_Title = 2; |
| 163 | const int32_t nsNavHistory::kGetInfoIndex_RevHost = 3; |
| 164 | const int32_t nsNavHistory::kGetInfoIndex_VisitCount = 4; |
| 165 | const int32_t nsNavHistory::kGetInfoIndex_VisitDate = 5; |
| 166 | const int32_t nsNavHistory::kGetInfoIndex_FaviconURL = 6; |
| 167 | const int32_t nsNavHistory::kGetInfoIndex_ItemId = 7; |
| 168 | const int32_t nsNavHistory::kGetInfoIndex_ItemDateAdded = 8; |
| 169 | const int32_t nsNavHistory::kGetInfoIndex_ItemLastModified = 9; |
| 170 | const int32_t nsNavHistory::kGetInfoIndex_ItemParentId = 10; |
| 171 | const int32_t nsNavHistory::kGetInfoIndex_ItemTags = 11; |
| 172 | const int32_t nsNavHistory::kGetInfoIndex_Frecency = 12; |
| 173 | const int32_t nsNavHistory::kGetInfoIndex_Hidden = 13; |
| 174 | const int32_t nsNavHistory::kGetInfoIndex_Guid = 14; |
| 175 | const int32_t nsNavHistory::kGetInfoIndex_VisitId = 15; |
| 176 | const int32_t nsNavHistory::kGetInfoIndex_FromVisitId = 16; |
| 177 | const int32_t nsNavHistory::kGetInfoIndex_VisitType = 17; |
| 178 | // These columns are followed by corresponding constants in nsNavBookmarks.cpp, |
| 179 | // which must be kept in sync: |
| 180 | // nsNavBookmarks::kGetChildrenIndex_Guid = 18; |
| 181 | // nsNavBookmarks::kGetChildrenIndex_Position = 19; |
| 182 | // nsNavBookmarks::kGetChildrenIndex_Type = 20; |
| 183 | // nsNavBookmarks::kGetChildrenIndex_PlaceID = 21; |
| 184 | const int32_t nsNavHistory::kGetTargetFolder_Guid = 22; |
| 185 | const int32_t nsNavHistory::kGetTargetFolder_ItemId = 23; |
| 186 | const int32_t nsNavHistory::kGetTargetFolder_Title = 24; |
| 187 | |
| 188 | PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavHistory, gHistoryService)nsNavHistory* nsNavHistory::gHistoryService = nullptr; already_AddRefed <nsNavHistory> nsNavHistory::GetSingleton() { if (!XRE_IsParentProcess ()) { return nullptr; } if (gHistoryService) { RefPtr<nsNavHistory > ret = gHistoryService; return ret.forget(); } if (!NS_IsMainThread ()) { return nullptr; } gHistoryService = new nsNavHistory(); RefPtr<nsNavHistory> ret = gHistoryService; if (((bool )(__builtin_expect(!!(NS_FAILED_impl(gHistoryService->Init ())), 0)))) { ret = nullptr; gHistoryService = nullptr; return nullptr; } return ret.forget(); } |
| 189 | |
| 190 | nsNavHistory::nsNavHistory() |
| 191 | : mCachedNow(0), |
| 192 | mRecentTyped(RECENT_EVENTS_INITIAL_CACHE_LENGTH64), |
| 193 | mRecentLink(RECENT_EVENTS_INITIAL_CACHE_LENGTH64), |
| 194 | mRecentBookmark(RECENT_EVENTS_INITIAL_CACHE_LENGTH64), |
| 195 | mHistoryEnabled(true), |
| 196 | mMatchDiacritics(false), |
| 197 | mTagsFolder(-1), |
| 198 | mLastCachedStartOfDay(INT64_MAX(9223372036854775807L)), |
| 199 | mLastCachedEndOfDay(0) { |
| 200 | NS_ASSERTION(!gHistoryService,do { if (!(!gHistoryService)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Attempting to create two instances of the service!", "!gHistoryService" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 201); MOZ_PretendNoReturn(); } } while (0) |
| 201 | "Attempting to create two instances of the service!")do { if (!(!gHistoryService)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Attempting to create two instances of the service!", "!gHistoryService" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 201); MOZ_PretendNoReturn(); } } while (0); |
| 202 | gHistoryService = this; |
| 203 | } |
| 204 | |
| 205 | nsNavHistory::~nsNavHistory() { |
| 206 | MOZ_ASSERT(NS_IsMainThread(), "Must be called on the main thread")do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" " (" "Must be called on the main thread" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 206); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ") (" "Must be called on the main thread" ")"); do { MOZ_CrashSequence (__null, 206); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 207 | |
| 208 | // remove the static reference to the service. Check to make sure its us |
| 209 | // in case somebody creates an extra instance of the service. |
| 210 | NS_ASSERTION(gHistoryService == this,do { if (!(gHistoryService == this)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Deleting a non-singleton instance of the service", "gHistoryService == this" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 211); MOZ_PretendNoReturn(); } } while (0) |
| 211 | "Deleting a non-singleton instance of the service")do { if (!(gHistoryService == this)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Deleting a non-singleton instance of the service", "gHistoryService == this" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 211); MOZ_PretendNoReturn(); } } while (0); |
| 212 | |
| 213 | if (gHistoryService == this) gHistoryService = nullptr; |
| 214 | } |
| 215 | |
| 216 | nsresult nsNavHistory::Init() { |
| 217 | LoadPrefs(); |
| 218 | |
| 219 | mDB = Database::GetDatabase(); |
| 220 | NS_ENSURE_STATE(mDB)do { if ((__builtin_expect(!!(!(mDB)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING , "NS_ENSURE_TRUE(" "mDB" ") failed", nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 220); return NS_ERROR_UNEXPECTED; } } while (false); |
| 221 | |
| 222 | /***************************************************************************** |
| 223 | *** IMPORTANT NOTICE! |
| 224 | *** |
| 225 | *** Nothing after these add observer calls should return anything but NS_OK. |
| 226 | *** If a failure code is returned, this nsNavHistory object will be held onto |
| 227 | *** by the observer service and the preference service. |
| 228 | ****************************************************************************/ |
| 229 | |
| 230 | // Observe preferences changes. |
| 231 | Preferences::AddWeakObservers(this, kObservedPrefs); |
| 232 | |
| 233 | nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService(); |
| 234 | if (obsSvc) { |
| 235 | (void)obsSvc->AddObserver(this, TOPIC_PLACES_CONNECTION_CLOSED"places-connection-closed", true); |
| 236 | (void)obsSvc->AddObserver(this, TOPIC_IDLE_DAILY"idle-daily", true); |
| 237 | (void)obsSvc->AddObserver(this, TOPIC_APP_LOCALES_CHANGED"intl:app-locales-changed", true); |
| 238 | } |
| 239 | |
| 240 | // Don't add code that can fail here! Do it up above, before we add our |
| 241 | // observers. |
| 242 | |
| 243 | return NS_OK; |
| 244 | } |
| 245 | |
| 246 | NS_IMETHODIMPnsresult |
| 247 | nsNavHistory::GetDatabaseStatus(uint16_t* aDatabaseStatus) { |
| 248 | NS_ENSURE_ARG_POINTER(aDatabaseStatus)do { if ((__builtin_expect(!!(!(aDatabaseStatus)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aDatabaseStatus" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 248); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 249 | *aDatabaseStatus = mDB->GetDatabaseStatus(); |
| 250 | return NS_OK; |
| 251 | } |
| 252 | |
| 253 | uint32_t nsNavHistory::GetRecentFlags(nsIURI* aURI) { |
| 254 | uint32_t result = 0; |
| 255 | nsAutoCString spec; |
| 256 | nsresult rv = aURI->GetSpec(spec); |
| 257 | NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Unable to get aURI's spec")do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1 ))))) { NS_DebugBreak(NS_DEBUG_WARNING, "Unable to get aURI's spec" , "NS_SUCCEEDED(rv)", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 257); } } while (false); |
| 258 | |
| 259 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 260 | if (CheckIsRecentEvent(&mRecentTyped, spec)) result |= RECENT_TYPED; |
| 261 | if (CheckIsRecentEvent(&mRecentLink, spec)) result |= RECENT_ACTIVATED; |
| 262 | if (CheckIsRecentEvent(&mRecentBookmark, spec)) result |= RECENT_BOOKMARKED; |
| 263 | } |
| 264 | |
| 265 | return result; |
| 266 | } |
| 267 | |
| 268 | nsresult nsNavHistory::GetIdForPage(nsIURI* aURI, int64_t* _pageId, |
| 269 | nsCString& _GUID) { |
| 270 | *_pageId = 0; |
| 271 | |
| 272 | nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement( |
| 273 | "SELECT id, url, title, rev_host, visit_count, guid " |
| 274 | "FROM moz_places " |
| 275 | "WHERE url_hash = hash(:page_url) AND url = :page_url "); |
| 276 | NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 276); return NS_ERROR_UNEXPECTED; } } while (false); |
| 277 | mozStorageStatementScoper scoper(stmt); |
| 278 | |
| 279 | nsresult rv = URIBinder::Bind(stmt, "page_url"_ns, aURI); |
| 280 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 280); return rv; } } while (false); |
| 281 | |
| 282 | bool hasEntry = false; |
| 283 | rv = stmt->ExecuteStep(&hasEntry); |
| 284 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 284); return rv; } } while (false); |
| 285 | |
| 286 | if (hasEntry) { |
| 287 | rv = stmt->GetInt64(0, _pageId); |
| 288 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 288); return rv; } } while (false); |
| 289 | rv = stmt->GetUTF8String(5, _GUID); |
| 290 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 290); return rv; } } while (false); |
| 291 | } |
| 292 | |
| 293 | return NS_OK; |
| 294 | } |
| 295 | |
| 296 | nsresult nsNavHistory::GetOrCreateIdForPage(nsIURI* aURI, int64_t* _pageId, |
| 297 | nsCString& _GUID) { |
| 298 | nsresult rv = GetIdForPage(aURI, _pageId, _GUID); |
| 299 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 299); return rv; } } while (false); |
| 300 | |
| 301 | if (*_pageId != 0) { |
| 302 | return NS_OK; |
| 303 | } |
| 304 | |
| 305 | { |
| 306 | // Create a new hidden, untyped and unvisited entry. |
| 307 | nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement( |
| 308 | "INSERT INTO moz_places (url, url_hash, rev_host, hidden, frecency, " |
| 309 | "guid) " |
| 310 | "VALUES (:page_url, hash(:page_url), :rev_host, :hidden, :frecency, " |
| 311 | ":guid) "); |
| 312 | NS_ENSURE_STATE(stmt)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 312); return NS_ERROR_UNEXPECTED; } } while (false); |
| 313 | mozStorageStatementScoper scoper(stmt); |
| 314 | |
| 315 | rv = URIBinder::Bind(stmt, "page_url"_ns, aURI); |
| 316 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 316); return rv; } } while (false); |
| 317 | // host (reversed with trailing period) |
| 318 | nsAutoString revHost; |
| 319 | rv = GetReversedHostname(aURI, revHost); |
| 320 | // Not all URI types have hostnames, so this is optional. |
| 321 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 322 | rv = stmt->BindStringByName("rev_host"_ns, revHost); |
| 323 | } else { |
| 324 | rv = stmt->BindNullByName("rev_host"_ns); |
| 325 | } |
| 326 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 326); return rv; } } while (false); |
| 327 | rv = stmt->BindInt32ByName("hidden"_ns, 1); |
| 328 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 328); return rv; } } while (false); |
| 329 | nsAutoCString spec; |
| 330 | rv = aURI->GetSpec(spec); |
| 331 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 331); return rv; } } while (false); |
| 332 | rv = stmt->BindInt32ByName("frecency"_ns, IsQueryURI(spec) ? 0 : -1); |
| 333 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 333); return rv; } } while (false); |
| 334 | rv = GenerateGUID(_GUID); |
| 335 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 335); return rv; } } while (false); |
| 336 | rv = stmt->BindUTF8StringByName("guid"_ns, _GUID); |
| 337 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 337); return rv; } } while (false); |
| 338 | |
| 339 | rv = stmt->Execute(); |
| 340 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 340); return rv; } } while (false); |
| 341 | |
| 342 | *_pageId = sLastInsertedPlaceId; |
| 343 | } |
| 344 | |
| 345 | return NS_OK; |
| 346 | } |
| 347 | |
| 348 | void nsNavHistory::LoadPrefs() { |
| 349 | // History preferences. |
| 350 | mHistoryEnabled = Preferences::GetBool(PREF_HISTORY_ENABLED"places.history.enabled", true); |
| 351 | mMatchDiacritics = Preferences::GetBool(PREF_MATCH_DIACRITICS"places.search.matchDiacritics", false); |
| 352 | } |
| 353 | |
| 354 | void nsNavHistory::UpdateDaysOfHistory(PRTime visitTime) { |
| 355 | if (sDaysOfHistory == 0) { |
| 356 | sDaysOfHistory = 1; |
| 357 | } |
| 358 | |
| 359 | if (visitTime > mLastCachedEndOfDay || visitTime < mLastCachedStartOfDay) { |
| 360 | InvalidateDaysOfHistory(); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** static */ |
| 365 | nsLiteralCString nsNavHistory::GetTagsSqlFragment(const uint16_t aQueryType, |
| 366 | bool aExcludeItems) { |
| 367 | if (aQueryType != nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS || |
| 368 | aExcludeItems) { |
| 369 | return "WITH tagged(place_id, tags) AS (VALUES(NULL, NULL)) "_ns; |
| 370 | } |
| 371 | return "WITH tagged(place_id, tags) AS ( " |
| 372 | " SELECT b.fk, group_concat(p.title ORDER BY p.title) " |
| 373 | " FROM moz_bookmarks b " |
| 374 | " JOIN moz_bookmarks p ON p.id = b.parent " |
| 375 | " JOIN moz_bookmarks g ON g.id = p.parent " |
| 376 | " WHERE g.guid = " SQL_QUOTE(TAGS_ROOT_GUID)"'" "tags________" "'" |
| 377 | " GROUP BY b.fk " |
| 378 | ") "_ns; |
| 379 | } |
| 380 | |
| 381 | /* static */ |
| 382 | mozilla::Maybe<nsCString> nsNavHistory::GetTargetFolderGuid( |
| 383 | const nsACString& aQueryURI) { |
| 384 | nsCOMPtr<nsINavHistoryQuery> query; |
| 385 | nsCOMPtr<nsINavHistoryQueryOptions> options; |
| 386 | if (!IsQueryURI(aQueryURI) || |
| 387 | NS_FAILED(nsNavHistoryQuery::QueryStringToQuery(((bool)(__builtin_expect(!!(NS_FAILED_impl(nsNavHistoryQuery:: QueryStringToQuery( aQueryURI, getter_AddRefs(query), getter_AddRefs (options)))), 0))) |
| 388 | aQueryURI, getter_AddRefs(query), getter_AddRefs(options)))((bool)(__builtin_expect(!!(NS_FAILED_impl(nsNavHistoryQuery:: QueryStringToQuery( aQueryURI, getter_AddRefs(query), getter_AddRefs (options)))), 0)))) { |
| 389 | return Nothing(); |
| 390 | } |
| 391 | |
| 392 | RefPtr<nsNavHistoryQuery> queryObj = do_QueryObject(query); |
| 393 | RefPtr<nsNavHistoryQueryOptions> optionsObj = do_QueryObject(options); |
| 394 | if (!queryObj || !optionsObj) { |
| 395 | return Nothing(); |
| 396 | } |
| 397 | |
| 398 | return GetSimpleBookmarksQueryParent(queryObj, optionsObj); |
| 399 | } |
| 400 | |
| 401 | Atomic<int64_t> nsNavHistory::sLastInsertedPlaceId(0); |
| 402 | Atomic<int64_t> nsNavHistory::sLastInsertedVisitId(0); |
| 403 | Atomic<bool> nsNavHistory::sShouldStartFrecencyRecalculation(false); |
| 404 | |
| 405 | void // static |
| 406 | nsNavHistory::StoreLastInsertedId(const nsACString& aTable, |
| 407 | const int64_t aLastInsertedId) { |
| 408 | if (aTable.EqualsLiteral("moz_places")) { |
| 409 | nsNavHistory::sLastInsertedPlaceId = aLastInsertedId; |
| 410 | } else if (aTable.EqualsLiteral("moz_historyvisits")) { |
| 411 | nsNavHistory::sLastInsertedVisitId = aLastInsertedId; |
| 412 | } else { |
| 413 | MOZ_ASSERT(false, "Trying to store the insert id for an unknown table?")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Trying to store the insert id for an unknown table?" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 413); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Trying to store the insert id for an unknown table?" ")"); do { MOZ_CrashSequence(__null, 413); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | Atomic<int32_t> nsNavHistory::sDaysOfHistory(-1); |
| 418 | |
| 419 | void // static |
| 420 | nsNavHistory::InvalidateDaysOfHistory() { |
| 421 | sDaysOfHistory = -1; |
| 422 | } |
| 423 | |
| 424 | int32_t nsNavHistory::GetDaysOfHistory() { |
| 425 | MOZ_ASSERT(NS_IsMainThread(), "This can only be called on the main thread")do { static_assert( mozilla::detail::AssertionConditionType< decltype(NS_IsMainThread())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()" " (" "This can only be called on the main thread" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 425); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ") (" "This can only be called on the main thread" ")"); do { MOZ_CrashSequence(__null, 425); __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 426 | |
| 427 | if (sDaysOfHistory != -1) return sDaysOfHistory; |
| 428 | |
| 429 | // SQLite doesn't have a CEIL() function, so we must do that later. |
| 430 | // We should also take into account timers resolution, that may be as bad as |
| 431 | // 16ms on Windows, so in some cases the difference may be 0, if the |
| 432 | // check is done near the visit. Thus remember to check for NULL separately. |
| 433 | nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement( |
| 434 | "SELECT CAST(( " |
| 435 | "strftime('%s','now','localtime','utc') - " |
| 436 | "(SELECT MIN(visit_date)/1000000 FROM moz_historyvisits) " |
| 437 | ") AS DOUBLE) " |
| 438 | "/86400, " |
| 439 | "strftime('%s','now','localtime','+1 day','start of day','utc') * " |
| 440 | "1000000"); |
| 441 | NS_ENSURE_TRUE(stmt, 0)do { if ((__builtin_expect(!!(!(stmt)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "stmt" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 441); return 0; } } while (false); |
| 442 | mozStorageStatementScoper scoper(stmt); |
| 443 | |
| 444 | bool hasResult; |
| 445 | if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult))((bool)(__builtin_expect(!!(!NS_FAILED_impl(stmt->ExecuteStep (&hasResult))), 1))) && hasResult) { |
| 446 | // If we get NULL, then there are no visits, otherwise there must always be |
| 447 | // at least 1 day of history. |
| 448 | bool hasNoVisits; |
| 449 | (void)stmt->GetIsNull(0, &hasNoVisits); |
| 450 | sDaysOfHistory = |
| 451 | hasNoVisits |
| 452 | ? 0 |
| 453 | : std::max(1, static_cast<int32_t>(ceil(stmt->AsDouble(0)))); |
| 454 | mLastCachedStartOfDay = |
| 455 | NormalizeTime(nsINavHistoryQuery::TIME_RELATIVE_TODAY, 0); |
| 456 | mLastCachedEndOfDay = stmt->AsInt64(1) - 1; // Start of tomorrow - 1. |
| 457 | } |
| 458 | |
| 459 | return sDaysOfHistory; |
| 460 | } |
| 461 | |
| 462 | PRTime nsNavHistory::GetNow() { |
| 463 | if (!mCachedNow) { |
| 464 | mCachedNow = PR_Now(); |
| 465 | if (!mExpireNowTimer) mExpireNowTimer = NS_NewTimer(); |
| 466 | if (mExpireNowTimer) |
| 467 | mExpireNowTimer->InitWithNamedFuncCallback( |
| 468 | expireNowTimerCallback, this, RENEW_CACHED_NOW_TIMEOUT((int32_t)3 * 1000L), |
| 469 | nsITimer::TYPE_ONE_SHOT, "nsNavHistory::GetNow"_ns); |
| 470 | } |
| 471 | return mCachedNow; |
| 472 | } |
| 473 | |
| 474 | void nsNavHistory::expireNowTimerCallback(nsITimer* aTimer, void* aClosure) { |
| 475 | nsNavHistory* history = static_cast<nsNavHistory*>(aClosure); |
| 476 | if (history) { |
| 477 | history->mCachedNow = 0; |
| 478 | history->mExpireNowTimer = nullptr; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Code borrowed from mozilla/xpfe/components/history/src/nsGlobalHistory.cpp |
| 484 | * Pass in a pre-normalized now and a date, and we'll find the difference since |
| 485 | * midnight on each of the days. |
| 486 | */ |
| 487 | static PRTime NormalizeTimeRelativeToday(PRTime aTime) { |
| 488 | // round to midnight this morning |
| 489 | PRExplodedTime explodedTime; |
| 490 | PR_ExplodeTime(aTime, PR_LocalTimeParameters, &explodedTime); |
| 491 | |
| 492 | // set to midnight (0:00) |
| 493 | explodedTime.tm_min = explodedTime.tm_hour = explodedTime.tm_sec = |
| 494 | explodedTime.tm_usec = 0; |
| 495 | |
| 496 | return PR_ImplodeTime(&explodedTime); |
| 497 | } |
| 498 | |
| 499 | // nsNavHistory::NormalizeTime |
| 500 | // |
| 501 | // Converts a nsINavHistoryQuery reference+offset time into a PRTime |
| 502 | // relative to the epoch. |
| 503 | // |
| 504 | // It is important that this function NOT use the current time optimization. |
| 505 | // It is called to update queries, and we really need to know what right |
| 506 | // now is because those incoming values will also have current times that |
| 507 | // we will have to compare against. |
| 508 | |
| 509 | PRTime // static |
| 510 | nsNavHistory::NormalizeTime(uint32_t aRelative, PRTime aOffset) { |
| 511 | PRTime ref; |
| 512 | switch (aRelative) { |
| 513 | case nsINavHistoryQuery::TIME_RELATIVE_EPOCH: |
| 514 | return aOffset; |
| 515 | case nsINavHistoryQuery::TIME_RELATIVE_TODAY: |
| 516 | ref = NormalizeTimeRelativeToday(PR_Now()); |
| 517 | break; |
| 518 | case nsINavHistoryQuery::TIME_RELATIVE_NOW: |
| 519 | ref = PR_Now(); |
| 520 | break; |
| 521 | default: |
| 522 | MOZ_ASSERT_UNREACHABLE("Invalid relative time")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "Invalid relative time" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 522); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Invalid relative time" ")"); do { MOZ_CrashSequence(__null, 522); __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 523 | return 0; |
| 524 | } |
| 525 | return ref + aOffset; |
| 526 | } |
| 527 | |
| 528 | // nsNavHistory::DomainNameFromURI |
| 529 | // |
| 530 | // This does the www.mozilla.org -> mozilla.org and |
| 531 | // foo.theregister.co.uk -> theregister.co.uk conversion |
| 532 | void nsNavHistory::DomainNameFromURI(nsIURI* aURI, nsACString& aDomainName) { |
| 533 | // lazily get the effective tld service |
| 534 | if (!mTLDService) |
| 535 | mTLDService = do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID"@mozilla.org/network/effective-tld-service;1"); |
| 536 | |
| 537 | if (mTLDService) { |
| 538 | // get the base domain for a given hostname. |
| 539 | // e.g. for "images.bbc.co.uk", this would be "bbc.co.uk". |
| 540 | nsresult rv = mTLDService->GetBaseDomain(aURI, 0, aDomainName); |
| 541 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) return; |
| 542 | } |
| 543 | |
| 544 | // just return the original hostname |
| 545 | // (it's also possible the host is an IP address) |
| 546 | aURI->GetAsciiHost(aDomainName); |
| 547 | } |
| 548 | |
| 549 | bool nsNavHistory::hasHistoryEntries() { return GetDaysOfHistory() > 0; } |
| 550 | |
| 551 | // Call this method before visiting a URL in order to help determine the |
| 552 | // transition type of the visit. |
| 553 | // |
| 554 | // @see MarkPageAsTyped |
| 555 | |
| 556 | NS_IMETHODIMPnsresult |
| 557 | nsNavHistory::MarkPageAsFollowedBookmark(nsIURI* aURI) { |
| 558 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 558); MOZ_PretendNoReturn(); } } while (0); |
| 559 | NS_ENSURE_ARG(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 559); return NS_ERROR_INVALID_ARG; } } while (false); |
| 560 | |
| 561 | // don't add when history is disabled |
| 562 | if (IsHistoryDisabled()) return NS_OK; |
| 563 | |
| 564 | nsAutoCString uriString; |
| 565 | nsresult rv = aURI->GetSpec(uriString); |
| 566 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 566); return rv; } } while (false); |
| 567 | |
| 568 | mRecentBookmark.InsertOrUpdate(uriString, GetNow()); |
| 569 | |
| 570 | if (mRecentBookmark.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH128) |
| 571 | ExpireNonrecentEvents(&mRecentBookmark); |
| 572 | |
| 573 | return NS_OK; |
| 574 | } |
| 575 | |
| 576 | // nsNavHistory::CanAddURI |
| 577 | // |
| 578 | // Filter out unwanted URIs such as "chrome:", "mailbox:", etc. |
| 579 | // |
| 580 | // The model is if we don't know differently then add which basically means |
| 581 | // we are suppose to try all the things we know not to allow in and then if |
| 582 | // we don't bail go on and allow it in. |
| 583 | |
| 584 | NS_IMETHODIMPnsresult |
| 585 | nsNavHistory::CanAddURI(nsIURI* aURI, bool* canAdd) { |
| 586 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 586); MOZ_PretendNoReturn(); } } while (0); |
| 587 | NS_ENSURE_ARG(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 587); return NS_ERROR_INVALID_ARG; } } while (false); |
| 588 | NS_ENSURE_ARG_POINTER(canAdd)do { if ((__builtin_expect(!!(!(canAdd)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "canAdd" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 588); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 589 | |
| 590 | // If history is disabled, don't add any entry. |
| 591 | *canAdd = !IsHistoryDisabled() && BaseHistory::CanStore(aURI); |
| 592 | return NS_OK; |
| 593 | } |
| 594 | |
| 595 | NS_IMETHODIMPnsresult |
| 596 | nsNavHistory::GetNewQuery(nsINavHistoryQuery** _retval) { |
| 597 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 597); MOZ_PretendNoReturn(); } } while (0); |
| 598 | NS_ENSURE_ARG_POINTER(_retval)do { if ((__builtin_expect(!!(!(_retval)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_retval" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 598); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 599 | |
| 600 | RefPtr<nsNavHistoryQuery> query = new nsNavHistoryQuery(); |
| 601 | query.forget(_retval); |
| 602 | return NS_OK; |
| 603 | } |
| 604 | |
| 605 | // nsNavHistory::GetNewQueryOptions |
| 606 | |
| 607 | NS_IMETHODIMPnsresult |
| 608 | nsNavHistory::GetNewQueryOptions(nsINavHistoryQueryOptions** _retval) { |
| 609 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 609); MOZ_PretendNoReturn(); } } while (0); |
| 610 | NS_ENSURE_ARG_POINTER(_retval)do { if ((__builtin_expect(!!(!(_retval)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_retval" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 610); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 611 | |
| 612 | RefPtr<nsNavHistoryQueryOptions> queryOptions = |
| 613 | new nsNavHistoryQueryOptions(); |
| 614 | queryOptions.forget(_retval); |
| 615 | return NS_OK; |
| 616 | } |
| 617 | |
| 618 | NS_IMETHODIMPnsresult |
| 619 | nsNavHistory::ExecuteQuery(nsINavHistoryQuery* aQuery, |
| 620 | nsINavHistoryQueryOptions* aOptions, |
| 621 | nsINavHistoryResult** _retval) { |
| 622 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 622); MOZ_PretendNoReturn(); } } while (0); |
| 623 | NS_ENSURE_ARG(aQuery)do { if ((__builtin_expect(!!(!(aQuery)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aQuery" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 623); return NS_ERROR_INVALID_ARG; } } while (false); |
| 624 | NS_ENSURE_ARG(aOptions)do { if ((__builtin_expect(!!(!(aOptions)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aOptions" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 624); return NS_ERROR_INVALID_ARG; } } while (false); |
| 625 | NS_ENSURE_ARG_POINTER(_retval)do { if ((__builtin_expect(!!(!(_retval)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_retval" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 625); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 626 | |
| 627 | // Clone the input query and options, because the caller might change the |
| 628 | // objects, but we always want to reflect the original parameters. |
| 629 | nsCOMPtr<nsINavHistoryQuery> queryClone; |
| 630 | aQuery->Clone(getter_AddRefs(queryClone)); |
| 631 | NS_ENSURE_STATE(queryClone)do { if ((__builtin_expect(!!(!(queryClone)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "queryClone" ") failed", nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 631); return NS_ERROR_UNEXPECTED; } } while (false); |
| 632 | RefPtr<nsNavHistoryQuery> query = do_QueryObject(queryClone); |
| 633 | NS_ENSURE_STATE(query)do { if ((__builtin_expect(!!(!(query)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "query" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 633); return NS_ERROR_UNEXPECTED; } } while (false); |
| 634 | nsCOMPtr<nsINavHistoryQueryOptions> optionsClone; |
| 635 | aOptions->Clone(getter_AddRefs(optionsClone)); |
| 636 | NS_ENSURE_STATE(optionsClone)do { if ((__builtin_expect(!!(!(optionsClone)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "optionsClone" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 636); return NS_ERROR_UNEXPECTED; } } while (false); |
| 637 | RefPtr<nsNavHistoryQueryOptions> options = do_QueryObject(optionsClone); |
| 638 | NS_ENSURE_STATE(options)do { if ((__builtin_expect(!!(!(options)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "options" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 638); return NS_ERROR_UNEXPECTED; } } while (false); |
| 639 | |
| 640 | // Create the root node. |
| 641 | RefPtr<nsNavHistoryContainerResultNode> rootNode; |
| 642 | |
| 643 | Maybe<nsCString> targetFolderGuid = |
| 644 | GetSimpleBookmarksQueryParent(query, options); |
| 645 | if (targetFolderGuid.isSome()) { |
| 646 | int32_t targetFolderType = 0; |
| 647 | int64_t targetFolderId = -1; |
| 648 | nsCString targetFolderTitle; |
| 649 | PRTime dateAdded; |
| 650 | PRTime lastModified; |
| 651 | nsresult rv = |
| 652 | FetchInfo(mDB, *targetFolderGuid, targetFolderType, targetFolderId, |
| 653 | targetFolderTitle, dateAdded, lastModified); |
| 654 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && |
| 655 | targetFolderType == nsINavBookmarksService::TYPE_FOLDER) { |
| 656 | auto* node = new nsNavHistoryFolderResultNode( |
| 657 | targetFolderId, *targetFolderGuid, targetFolderId, *targetFolderGuid, |
| 658 | targetFolderTitle, options); |
| 659 | node->mDateAdded = dateAdded; |
| 660 | node->mLastModified = lastModified; |
| 661 | rootNode = node->GetAsContainer(); |
| 662 | } else { |
| 663 | NS_WARNING("Generating a generic empty node for a broken query!")NS_DebugBreak(NS_DEBUG_WARNING, "Generating a generic empty node for a broken query!" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 663); |
| 664 | // This is a perf hack to generate an empty query that skips filtering. |
| 665 | options->SetExcludeItems(true); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | if (!rootNode) { |
| 670 | // Either this is not a folder shortcut, or is a broken one. In both cases |
| 671 | // just generate a query node. |
| 672 | nsAutoCString queryUri; |
| 673 | nsresult rv = QueryToQueryString(query, options, queryUri); |
| 674 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 674); return rv; } } while (false); |
| 675 | rootNode = |
| 676 | new nsNavHistoryQueryResultNode(""_ns, 0, queryUri, query, options); |
| 677 | } |
| 678 | |
| 679 | // Create the result that will hold nodes. Inject batching status into it. |
| 680 | RefPtr<nsNavHistoryResult> result = |
| 681 | new nsNavHistoryResult(rootNode, query, options); |
| 682 | result.forget(_retval); |
| 683 | return NS_OK; |
| 684 | } |
| 685 | |
| 686 | // determine from our nsNavHistoryQuery array and nsNavHistoryQueryOptions |
| 687 | // if this is the place query from the history menu. |
| 688 | // from browser-menubar.inc.xhtml, our history menu query is: |
| 689 | // place:sort=4&maxResults=10 |
| 690 | // note, any maxResult > 0 will still be considered a history menu query |
| 691 | // or if this is the place query from the old "Most Visited" item in some |
| 692 | // profiles: folder: place:sort=8&maxResults=10 note, any maxResult > 0 will |
| 693 | // still be considered a Most Visited menu query |
| 694 | static bool IsOptimizableHistoryQuery( |
| 695 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 696 | const RefPtr<nsNavHistoryQueryOptions>& aOptions, uint16_t aSortMode) { |
| 697 | if (aOptions->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) |
| 698 | return false; |
| 699 | |
| 700 | if (aOptions->ResultType() != nsINavHistoryQueryOptions::RESULTS_AS_URI) |
| 701 | return false; |
| 702 | |
| 703 | if (aOptions->SortingMode() != aSortMode) return false; |
| 704 | |
| 705 | if (aOptions->MaxResults() <= 0) return false; |
| 706 | |
| 707 | if (aOptions->ExcludeItems()) return false; |
| 708 | |
| 709 | if (aOptions->IncludeHidden()) return false; |
| 710 | |
| 711 | if (aQuery->MinVisits() != -1 || aQuery->MaxVisits() != -1) return false; |
| 712 | |
| 713 | if (aQuery->BeginTime() || aQuery->BeginTimeReference()) return false; |
| 714 | |
| 715 | if (aQuery->EndTime() || aQuery->EndTimeReference()) return false; |
| 716 | |
| 717 | if (!aQuery->SearchTerms().IsEmpty()) return false; |
| 718 | |
| 719 | if (aQuery->DomainIsHost() || !aQuery->Domain().IsEmpty()) return false; |
| 720 | |
| 721 | if (aQuery->Parents().Length() > 0) return false; |
| 722 | |
| 723 | if (aQuery->Tags().Length() > 0) return false; |
| 724 | |
| 725 | if (aQuery->Transitions().Length() > 0) return false; |
| 726 | |
| 727 | return true; |
| 728 | } |
| 729 | |
| 730 | static bool NeedToFilterResultSet(const RefPtr<nsNavHistoryQuery>& aQuery, |
| 731 | nsNavHistoryQueryOptions* aOptions) { |
| 732 | return aOptions->ExcludeQueries(); |
| 733 | } |
| 734 | |
| 735 | // ** Helper class for ConstructQueryString **/ |
| 736 | |
| 737 | class PlacesSQLQueryBuilder { |
| 738 | public: |
| 739 | PlacesSQLQueryBuilder(const nsCString& aConditions, |
| 740 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 741 | const RefPtr<nsNavHistoryQueryOptions>& aOptions, |
| 742 | bool aUseLimit, nsNavHistory::StringHash& aAddParams); |
| 743 | |
| 744 | nsresult GetQueryString(nsCString& aQueryString); |
| 745 | |
| 746 | private: |
| 747 | nsresult Select(); |
| 748 | |
| 749 | nsresult SelectAsURI(); |
| 750 | nsresult SelectAsVisit(); |
| 751 | nsresult SelectAsDay(); |
| 752 | nsresult SelectAsSite(); |
| 753 | nsresult SelectAsTag(); |
| 754 | nsresult SelectAsRoots(); |
| 755 | nsresult SelectAsLeftPane(); |
| 756 | |
| 757 | nsresult Where(); |
| 758 | nsresult GroupBy(); |
| 759 | nsresult OrderBy(); |
| 760 | nsresult Limit(); |
| 761 | |
| 762 | void OrderByColumnIndexAsc(int32_t aIndex); |
| 763 | void OrderByColumnIndexDesc(int32_t aIndex); |
| 764 | // Use these if you want a case insensitive sorting. |
| 765 | void OrderByTextColumnIndexAsc(int32_t aIndex); |
| 766 | void OrderByTextColumnIndexDesc(int32_t aIndex); |
| 767 | |
| 768 | const nsCString& mConditions; |
| 769 | bool mUseLimit; |
| 770 | |
| 771 | uint16_t mResultType; |
| 772 | uint16_t mQueryType; |
| 773 | bool mExcludeItems; |
| 774 | bool mIncludeHidden; |
| 775 | uint16_t mSortingMode; |
| 776 | uint32_t mMaxResults; |
| 777 | |
| 778 | nsCString mQueryString; |
| 779 | nsCString mGroupBy; |
| 780 | bool mHasDateColumns; |
| 781 | bool mSkipOrderBy; |
| 782 | |
| 783 | nsNavHistory::StringHash& mAddParams; |
| 784 | }; |
| 785 | |
| 786 | PlacesSQLQueryBuilder::PlacesSQLQueryBuilder( |
| 787 | const nsCString& aConditions, const RefPtr<nsNavHistoryQuery>& aQuery, |
| 788 | const RefPtr<nsNavHistoryQueryOptions>& aOptions, bool aUseLimit, |
| 789 | nsNavHistory::StringHash& aAddParams) |
| 790 | : mConditions(aConditions), |
| 791 | mUseLimit(aUseLimit), |
| 792 | mResultType(aOptions->ResultType()), |
| 793 | mQueryType(aOptions->QueryType()), |
| 794 | mExcludeItems(aOptions->ExcludeItems()), |
| 795 | mIncludeHidden(aOptions->IncludeHidden()), |
| 796 | mSortingMode(aOptions->SortingMode()), |
| 797 | mMaxResults(aOptions->MaxResults()), |
| 798 | mSkipOrderBy(false), |
| 799 | mAddParams(aAddParams) { |
| 800 | mHasDateColumns = |
| 801 | (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS); |
| 802 | // Force the default sorting mode for tag queries. |
| 803 | if (mSortingMode == nsINavHistoryQueryOptions::SORT_BY_NONE && |
| 804 | aQuery->Tags().Length() > 0) { |
| 805 | mSortingMode = nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | nsresult PlacesSQLQueryBuilder::GetQueryString(nsCString& aQueryString) { |
| 810 | nsresult rv = Select(); |
| 811 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 811); return rv; } } while (false); |
| 812 | rv = Where(); |
| 813 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 813); return rv; } } while (false); |
| 814 | rv = GroupBy(); |
| 815 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 815); return rv; } } while (false); |
| 816 | rv = OrderBy(); |
| 817 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 817); return rv; } } while (false); |
| 818 | rv = Limit(); |
| 819 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 819); return rv; } } while (false); |
| 820 | |
| 821 | aQueryString = mQueryString; |
| 822 | return NS_OK; |
| 823 | } |
| 824 | |
| 825 | nsresult PlacesSQLQueryBuilder::Select() { |
| 826 | nsresult rv; |
| 827 | |
| 828 | switch (mResultType) { |
| 829 | case nsINavHistoryQueryOptions::RESULTS_AS_URI: |
| 830 | rv = SelectAsURI(); |
| 831 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 831); return rv; } } while (false); |
| 832 | break; |
| 833 | |
| 834 | case nsINavHistoryQueryOptions::RESULTS_AS_VISIT: |
| 835 | rv = SelectAsVisit(); |
| 836 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 836); return rv; } } while (false); |
| 837 | break; |
| 838 | |
| 839 | case nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY: |
| 840 | case nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY: |
| 841 | rv = SelectAsDay(); |
| 842 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 842); return rv; } } while (false); |
| 843 | break; |
| 844 | |
| 845 | case nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY: |
| 846 | rv = SelectAsSite(); |
| 847 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 847); return rv; } } while (false); |
| 848 | break; |
| 849 | |
| 850 | case nsINavHistoryQueryOptions::RESULTS_AS_TAGS_ROOT: |
| 851 | rv = SelectAsTag(); |
| 852 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 852); return rv; } } while (false); |
| 853 | break; |
| 854 | |
| 855 | case nsINavHistoryQueryOptions::RESULTS_AS_ROOTS_QUERY: |
| 856 | rv = SelectAsRoots(); |
| 857 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 857); return rv; } } while (false); |
| 858 | break; |
| 859 | |
| 860 | case nsINavHistoryQueryOptions::RESULTS_AS_LEFT_PANE_QUERY: |
| 861 | rv = SelectAsLeftPane(); |
| 862 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 862); return rv; } } while (false); |
| 863 | break; |
| 864 | |
| 865 | default: |
| 866 | MOZ_ASSERT_UNREACHABLE("Invalid result type")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "Invalid result type" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 866); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Invalid result type" ")"); do { MOZ_CrashSequence (__null, 866); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); |
| 867 | } |
| 868 | return NS_OK; |
| 869 | } |
| 870 | |
| 871 | nsresult PlacesSQLQueryBuilder::SelectAsURI() { |
| 872 | nsNavHistory* history = nsNavHistory::GetHistoryService(); |
| 873 | NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY)do { if ((__builtin_expect(!!(!(history)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "history" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 873); return NS_ERROR_OUT_OF_MEMORY; } } while (false); |
| 874 | |
| 875 | switch (mQueryType) { |
| 876 | case nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY: { |
| 877 | mQueryString = |
| 878 | nsNavHistory::GetTagsSqlFragment(mQueryType, mExcludeItems) + |
| 879 | "SELECT h.id, h.url, h.title AS page_title, h.rev_host, " |
| 880 | " h.visit_count, h.last_visit_date, null, null, null, null, null, " |
| 881 | " (SELECT tags FROM tagged WHERE place_id = h.id) AS tags, " |
| 882 | " h.frecency, h.hidden, h.guid, null, null, null, " |
| 883 | " null, null, null, null, null, null, null " |
| 884 | "FROM moz_places h " |
| 885 | // WHERE 1 is a no-op since additonal conditions will |
| 886 | // start with AND. |
| 887 | "WHERE 1 " |
| 888 | "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " |
| 889 | "{ADDITIONAL_CONDITIONS} "_ns; |
| 890 | break; |
| 891 | } |
| 892 | case nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS: { |
| 893 | mQueryString = |
| 894 | nsNavHistory::GetTagsSqlFragment(mQueryType, mExcludeItems) + |
| 895 | "SELECT b.fk, h.url, b.title AS page_title, " |
| 896 | " h.rev_host, h.visit_count, h.last_visit_date, null, b.id, " |
| 897 | " b.dateAdded, b.lastModified, b.parent, " |
| 898 | " (SELECT tags FROM tagged WHERE place_id = h.id) AS tags, " |
| 899 | " h.frecency, h.hidden, h.guid, null, null, null, b.guid, " |
| 900 | " b.position, b.type, b.fk, t.guid, t.id, t.title " |
| 901 | "FROM moz_bookmarks b " |
| 902 | "JOIN moz_places h ON b.fk = h.id " |
| 903 | "LEFT JOIN moz_bookmarks t ON t.guid = target_folder_guid(h.url) " |
| 904 | "WHERE NOT EXISTS " |
| 905 | "(SELECT id FROM moz_bookmarks " |
| 906 | "WHERE id = b.parent AND parent = "_ns + |
| 907 | nsPrintfCString("%" PRId64"l" "d", history->GetTagsFolder()) + |
| 908 | ") " |
| 909 | "AND NOT h.url_hash BETWEEN hash('place', 'prefix_lo') " |
| 910 | " AND hash('place', 'prefix_hi') " |
| 911 | "{ADDITIONAL_CONDITIONS}"_ns; |
| 912 | break; |
| 913 | } |
| 914 | default: { |
| 915 | return NS_ERROR_NOT_IMPLEMENTED; |
| 916 | } |
| 917 | } |
| 918 | return NS_OK; |
| 919 | } |
| 920 | |
| 921 | nsresult PlacesSQLQueryBuilder::SelectAsVisit() { |
| 922 | mQueryString = |
| 923 | nsNavHistory::GetTagsSqlFragment(mQueryType, mExcludeItems) + |
| 924 | "SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, " |
| 925 | " v.visit_date, null, null, null, null, null, " |
| 926 | " (SELECT tags FROM tagged WHERE place_id = h.id) AS tags, " |
| 927 | " h.frecency, h.hidden, h.guid, v.id, v.from_visit, v.visit_type, " |
| 928 | " null, null, null, null, null, null, null " |
| 929 | "FROM moz_places h " |
| 930 | "JOIN moz_historyvisits v ON h.id = v.place_id " |
| 931 | // WHERE 1 is a no-op since additonal conditions will start with AND. |
| 932 | "WHERE 1 " |
| 933 | "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " |
| 934 | "{ADDITIONAL_CONDITIONS} "_ns; |
| 935 | |
| 936 | return NS_OK; |
| 937 | } |
| 938 | |
| 939 | nsresult PlacesSQLQueryBuilder::SelectAsDay() { |
| 940 | mSkipOrderBy = true; |
| 941 | |
| 942 | // Sort child queries based on sorting mode if it's provided, otherwise |
| 943 | // fallback to default sort by title ascending. |
| 944 | uint16_t sortingMode = nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING; |
| 945 | if (mSortingMode != nsINavHistoryQueryOptions::SORT_BY_NONE && |
| 946 | mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY) |
| 947 | sortingMode = mSortingMode; |
| 948 | |
| 949 | uint16_t resultType = |
| 950 | mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY |
| 951 | ? (uint16_t)nsINavHistoryQueryOptions::RESULTS_AS_URI |
| 952 | : (uint16_t)nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY; |
| 953 | |
| 954 | // beginTime will become the node's time property, we don't use endTime |
| 955 | // because it could overlap, and we use time to sort containers and find |
| 956 | // insert position in a result. |
| 957 | mQueryString = nsPrintfCString( |
| 958 | "SELECT null, " |
| 959 | "'place:type=%d&sort=%d&beginTime='||beginTime||'&endTime='||endTime, " |
| 960 | "dayTitle, null, null, beginTime, null, null, null, null, null, null, " |
| 961 | "null, null, null, null, null, null, null, null, null, null, " |
| 962 | "null, null, null " |
| 963 | "FROM (", // TOUTER BEGIN |
| 964 | resultType, sortingMode); |
| 965 | |
| 966 | nsNavHistory* history = nsNavHistory::GetHistoryService(); |
| 967 | NS_ENSURE_STATE(history)do { if ((__builtin_expect(!!(!(history)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "history" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 967); return NS_ERROR_UNEXPECTED; } } while (false); |
| 968 | |
| 969 | int32_t daysOfHistory = history->GetDaysOfHistory(); |
| 970 | for (int32_t i = 0; i <= HISTORY_DATE_CONT_NUM(daysOfHistory)(3 + std::min(6, (int32_t)ceilf((float)daysOfHistory / 30))); i++) { |
| 971 | nsAutoCString dateName; |
| 972 | // Timeframes are calculated as BeginTime <= container < EndTime. |
| 973 | // Notice times can't be relative to now, since to recognize a query we |
| 974 | // must ensure it won't change based on the time it is built. |
| 975 | // So, to select till now, we really select till start of tomorrow, that is |
| 976 | // a fixed timestamp. |
| 977 | // These are used as limits for the inside containers. |
| 978 | nsAutoCString sqlFragmentContainerBeginTime, sqlFragmentContainerEndTime; |
| 979 | // These are used to query if the container should be visible. |
| 980 | nsAutoCString sqlFragmentSearchBeginTime, sqlFragmentSearchEndTime; |
| 981 | switch (i) { |
| 982 | case 0: |
| 983 | // Today |
| 984 | history->GetStringFromName("finduri-AgeInDays-is-0", dateName); |
| 985 | // From start of today |
| 986 | sqlFragmentContainerBeginTime = nsLiteralCString( |
| 987 | "(strftime('%s','now','localtime','start of day','utc')*1000000)"); |
| 988 | // To now (tomorrow) |
| 989 | sqlFragmentContainerEndTime = nsLiteralCString( |
| 990 | "(strftime('%s','now','localtime','start of day','+1 " |
| 991 | "day','utc')*1000000)"); |
| 992 | // Search for the same timeframe. |
| 993 | sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime; |
| 994 | sqlFragmentSearchEndTime = sqlFragmentContainerEndTime; |
| 995 | break; |
| 996 | case 1: |
| 997 | // Yesterday |
| 998 | history->GetStringFromName("finduri-AgeInDays-is-1", dateName); |
| 999 | // From start of yesterday |
| 1000 | sqlFragmentContainerBeginTime = nsLiteralCString( |
| 1001 | "(strftime('%s','now','localtime','start of day','-1 " |
| 1002 | "day','utc')*1000000)"); |
| 1003 | // To start of today |
| 1004 | sqlFragmentContainerEndTime = nsLiteralCString( |
| 1005 | "(strftime('%s','now','localtime','start of day','utc')*1000000)"); |
| 1006 | // Search for the same timeframe. |
| 1007 | sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime; |
| 1008 | sqlFragmentSearchEndTime = sqlFragmentContainerEndTime; |
| 1009 | break; |
| 1010 | case 2: |
| 1011 | // Last 7 days |
| 1012 | history->GetAgeInDaysString(7, "finduri-AgeInDays-last-is", dateName); |
| 1013 | // From start of 7 days ago |
| 1014 | sqlFragmentContainerBeginTime = nsLiteralCString( |
| 1015 | "(strftime('%s','now','localtime','start of day','-7 " |
| 1016 | "days','utc')*1000000)"); |
| 1017 | // To now (tomorrow) |
| 1018 | sqlFragmentContainerEndTime = nsLiteralCString( |
| 1019 | "(strftime('%s','now','localtime','start of day','+1 " |
| 1020 | "day','utc')*1000000)"); |
| 1021 | // This is an overlapped container, but we show it only if there are |
| 1022 | // visits older than yesterday. |
| 1023 | sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime; |
| 1024 | sqlFragmentSearchEndTime = nsLiteralCString( |
| 1025 | "(strftime('%s','now','localtime','start of day','-1 " |
| 1026 | "day','utc')*1000000)"); |
| 1027 | break; |
| 1028 | case 3: |
| 1029 | // This month |
| 1030 | history->GetStringFromName("finduri-AgeInMonths-is-0", dateName); |
| 1031 | // From start of this month |
| 1032 | sqlFragmentContainerBeginTime = nsLiteralCString( |
| 1033 | "(strftime('%s','now','localtime','start of " |
| 1034 | "month','utc')*1000000)"); |
| 1035 | // To now (tomorrow) |
| 1036 | sqlFragmentContainerEndTime = nsLiteralCString( |
| 1037 | "(strftime('%s','now','localtime','start of day','+1 " |
| 1038 | "day','utc')*1000000)"); |
| 1039 | // This is an overlapped container, but we show it only if there are |
| 1040 | // visits older than 7 days ago. |
| 1041 | sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime; |
| 1042 | sqlFragmentSearchEndTime = nsLiteralCString( |
| 1043 | "(strftime('%s','now','localtime','start of day','-7 " |
| 1044 | "days','utc')*1000000)"); |
| 1045 | break; |
| 1046 | default: |
| 1047 | if (i == HISTORY_ADDITIONAL_DATE_CONT_NUM3 + 6) { |
| 1048 | // Older than 6 months |
| 1049 | history->GetAgeInDaysString(6, "finduri-AgeInMonths-isgreater", |
| 1050 | dateName); |
| 1051 | // From start of epoch |
| 1052 | sqlFragmentContainerBeginTime = |
| 1053 | "(datetime(0, 'unixepoch')*1000000)"_ns; |
| 1054 | // To start of 6 months ago ( 5 months + this month). |
| 1055 | sqlFragmentContainerEndTime = nsLiteralCString( |
| 1056 | "(strftime('%s','now','localtime','start of month','-5 " |
| 1057 | "months','utc')*1000000)"); |
| 1058 | // Search for the same timeframe. |
| 1059 | sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime; |
| 1060 | sqlFragmentSearchEndTime = sqlFragmentContainerEndTime; |
| 1061 | break; |
| 1062 | } |
| 1063 | int32_t MonthIndex = i - HISTORY_ADDITIONAL_DATE_CONT_NUM3; |
| 1064 | // Previous months' titles are month's name if inside this year, |
| 1065 | // month's name and year for previous years. |
| 1066 | PRExplodedTime tm; |
| 1067 | PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &tm); |
| 1068 | uint16_t currentYear = tm.tm_year; |
| 1069 | // Set day before month, setting month without day could cause issues. |
| 1070 | // For example setting month to February when today is 30, since |
| 1071 | // February has not 30 days, will return March instead. |
| 1072 | // Also, we use day 2 instead of day 1, so that the GMT month is always |
| 1073 | // the same as the local month. (Bug 603002) |
| 1074 | tm.tm_mday = 2; |
| 1075 | tm.tm_month -= MonthIndex; |
| 1076 | // Notice we use GMTParameters because we just want to get the first |
| 1077 | // day of each month. Using LocalTimeParameters would instead force us |
| 1078 | // to apply a DST correction that we don't really need here. |
| 1079 | PR_NormalizeTime(&tm, PR_GMTParameters); |
| 1080 | // If the container is for a past year, add the year to its title, |
| 1081 | // otherwise just show the month name. |
| 1082 | if (tm.tm_year < currentYear) { |
| 1083 | nsNavHistory::GetMonthYear(tm, dateName); |
| 1084 | } else { |
| 1085 | nsNavHistory::GetMonthName(tm, dateName); |
| 1086 | } |
| 1087 | |
| 1088 | // From start of MonthIndex + 1 months ago |
| 1089 | sqlFragmentContainerBeginTime = nsLiteralCString( |
| 1090 | "(strftime('%s','now','localtime','start of month','-"); |
| 1091 | sqlFragmentContainerBeginTime.AppendInt(MonthIndex); |
| 1092 | sqlFragmentContainerBeginTime.AppendLiteral(" months','utc')*1000000)"); |
| 1093 | // To start of MonthIndex months ago |
| 1094 | sqlFragmentContainerEndTime = nsLiteralCString( |
| 1095 | "(strftime('%s','now','localtime','start of month','-"); |
| 1096 | sqlFragmentContainerEndTime.AppendInt(MonthIndex - 1); |
| 1097 | sqlFragmentContainerEndTime.AppendLiteral(" months','utc')*1000000)"); |
| 1098 | // Search for the same timeframe. |
| 1099 | sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime; |
| 1100 | sqlFragmentSearchEndTime = sqlFragmentContainerEndTime; |
| 1101 | break; |
| 1102 | } |
| 1103 | |
| 1104 | nsPrintfCString dateParam("dayTitle%d", i); |
| 1105 | mAddParams.InsertOrUpdate(dateParam, dateName); |
| 1106 | |
| 1107 | nsPrintfCString dayRange( |
| 1108 | "SELECT :%s AS dayTitle, " |
| 1109 | "%s AS beginTime, " |
| 1110 | "%s AS endTime " |
| 1111 | "WHERE EXISTS ( " |
| 1112 | "SELECT id FROM moz_historyvisits " |
| 1113 | "WHERE visit_date >= %s " |
| 1114 | "AND visit_date < %s " |
| 1115 | "AND visit_type NOT IN (0,%d,%d) " |
| 1116 | "{QUERY_OPTIONS_VISITS} " |
| 1117 | "LIMIT 1 " |
| 1118 | ") ", |
| 1119 | dateParam.get(), sqlFragmentContainerBeginTime.get(), |
| 1120 | sqlFragmentContainerEndTime.get(), sqlFragmentSearchBeginTime.get(), |
| 1121 | sqlFragmentSearchEndTime.get(), nsINavHistoryService::TRANSITION_EMBED, |
| 1122 | nsINavHistoryService::TRANSITION_FRAMED_LINK); |
| 1123 | |
| 1124 | mQueryString.Append(dayRange); |
| 1125 | |
| 1126 | if (i < HISTORY_DATE_CONT_NUM(daysOfHistory)(3 + std::min(6, (int32_t)ceilf((float)daysOfHistory / 30)))) |
| 1127 | mQueryString.AppendLiteral(" UNION ALL "); |
| 1128 | } |
| 1129 | |
| 1130 | mQueryString.AppendLiteral(") "); // TOUTER END |
| 1131 | |
| 1132 | return NS_OK; |
| 1133 | } |
| 1134 | |
| 1135 | nsresult PlacesSQLQueryBuilder::SelectAsSite() { |
| 1136 | nsAutoCString localFiles; |
| 1137 | |
| 1138 | nsNavHistory* history = nsNavHistory::GetHistoryService(); |
| 1139 | NS_ENSURE_STATE(history)do { if ((__builtin_expect(!!(!(history)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "history" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1139); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1140 | |
| 1141 | history->GetStringFromName("localhost", localFiles); |
| 1142 | mAddParams.InsertOrUpdate("localhost"_ns, localFiles); |
| 1143 | |
| 1144 | // If there are additional conditions the query has to join on visits too. |
| 1145 | nsAutoCString visitsJoin; |
| 1146 | nsAutoCString additionalConditions; |
| 1147 | nsAutoCString timeConstraints; |
| 1148 | if (!mConditions.IsEmpty()) { |
| 1149 | visitsJoin.AssignLiteral("JOIN moz_historyvisits v ON v.place_id = h.id "); |
| 1150 | additionalConditions.AssignLiteral( |
| 1151 | "{QUERY_OPTIONS_VISITS} " |
| 1152 | "{QUERY_OPTIONS_PLACES} " |
| 1153 | "{ADDITIONAL_CONDITIONS} "); |
| 1154 | timeConstraints.AssignLiteral( |
| 1155 | "||'&beginTime='||:begin_time||" |
| 1156 | "'&endTime='||:end_time"); |
| 1157 | } |
| 1158 | |
| 1159 | mQueryString = nsPrintfCString( |
| 1160 | "SELECT null, 'place:type=%d&sort=%d&domain=&domainIsHost=true'%s, " |
| 1161 | ":localhost, :localhost, null, null, null, null, null, null, null, " |
| 1162 | "null, null, null, null, null, null, null, null, null, null, " |
| 1163 | "null, null, null, null " |
| 1164 | "WHERE EXISTS ( " |
| 1165 | "SELECT h.id FROM moz_places h " |
| 1166 | "%s " |
| 1167 | "WHERE h.hidden = 0 " |
| 1168 | "AND h.visit_count > 0 " |
| 1169 | "AND h.url_hash BETWEEN hash('file', 'prefix_lo') AND " |
| 1170 | "hash('file', 'prefix_hi') " |
| 1171 | "%s " |
| 1172 | "LIMIT 1 " |
| 1173 | ") " |
| 1174 | "UNION ALL " |
| 1175 | "SELECT null, " |
| 1176 | "'place:type=%d&sort=%d&domain='||host||'&domainIsHost=true'%s, " |
| 1177 | "host, host, null, null, null, null, null, null, null, " |
| 1178 | "null, null, null, null, null, null, null, null, null, null, " |
| 1179 | "null, null, null, null " |
| 1180 | "FROM ( " |
| 1181 | "SELECT get_unreversed_host(h.rev_host) AS host " |
| 1182 | "FROM moz_places h " |
| 1183 | "%s " |
| 1184 | "WHERE h.hidden = 0 " |
| 1185 | "AND h.rev_host <> '.' " |
| 1186 | "AND h.visit_count > 0 " |
| 1187 | "%s " |
| 1188 | "GROUP BY h.rev_host " |
| 1189 | "ORDER BY host ASC " |
| 1190 | ") ", |
| 1191 | nsINavHistoryQueryOptions::RESULTS_AS_URI, mSortingMode, |
| 1192 | timeConstraints.get(), visitsJoin.get(), additionalConditions.get(), |
| 1193 | nsINavHistoryQueryOptions::RESULTS_AS_URI, mSortingMode, |
| 1194 | timeConstraints.get(), visitsJoin.get(), additionalConditions.get()); |
| 1195 | |
| 1196 | return NS_OK; |
| 1197 | } |
| 1198 | |
| 1199 | nsresult PlacesSQLQueryBuilder::SelectAsTag() { |
| 1200 | nsNavHistory* history = nsNavHistory::GetHistoryService(); |
| 1201 | NS_ENSURE_STATE(history)do { if ((__builtin_expect(!!(!(history)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "history" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1201); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1202 | |
| 1203 | // This allows sorting by date fields what is not possible with |
| 1204 | // other history queries. |
| 1205 | mHasDateColumns = true; |
| 1206 | |
| 1207 | // TODO (Bug 1449939): This is likely wrong, since the tag name should |
| 1208 | // probably be urlencoded, and we have no util for that in SQL, yet. |
| 1209 | // We could encode the tag when the user sets it though. |
| 1210 | mQueryString = nsPrintfCString( |
| 1211 | "SELECT null, 'place:tag=' || title, " |
| 1212 | "title, null, null, null, null, null, dateAdded, " |
| 1213 | "lastModified, null, null, null, null, null, null, " |
| 1214 | "null, null, null, null, null, null, null, null, null " |
| 1215 | "FROM moz_bookmarks " |
| 1216 | "WHERE parent = %" PRId64"l" "d", |
| 1217 | history->GetTagsFolder()); |
| 1218 | |
| 1219 | return NS_OK; |
| 1220 | } |
| 1221 | |
| 1222 | nsresult PlacesSQLQueryBuilder::SelectAsRoots() { |
| 1223 | nsNavHistory* history = nsNavHistory::GetHistoryService(); |
| 1224 | NS_ENSURE_STATE(history)do { if ((__builtin_expect(!!(!(history)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "history" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1224); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1225 | |
| 1226 | nsAutoCString toolbarTitle; |
| 1227 | nsAutoCString menuTitle; |
| 1228 | nsAutoCString unfiledTitle; |
| 1229 | |
| 1230 | history->GetStringFromName("BookmarksToolbarFolderTitle", toolbarTitle); |
| 1231 | mAddParams.InsertOrUpdate("BookmarksToolbarFolderTitle"_ns, toolbarTitle); |
| 1232 | history->GetStringFromName("BookmarksMenuFolderTitle", menuTitle); |
| 1233 | mAddParams.InsertOrUpdate("BookmarksMenuFolderTitle"_ns, menuTitle); |
| 1234 | history->GetStringFromName("OtherBookmarksFolderTitle", unfiledTitle); |
| 1235 | mAddParams.InsertOrUpdate("OtherBookmarksFolderTitle"_ns, unfiledTitle); |
| 1236 | |
| 1237 | nsAutoCString mobileString; |
| 1238 | |
| 1239 | if (Preferences::GetBool(MOBILE_BOOKMARKS_PREF"browser.bookmarks.showMobileBookmarks", false)) { |
| 1240 | nsAutoCString mobileTitle; |
| 1241 | history->GetStringFromName("MobileBookmarksFolderTitle", mobileTitle); |
| 1242 | mAddParams.InsertOrUpdate("MobileBookmarksFolderTitle"_ns, mobileTitle); |
| 1243 | |
| 1244 | mobileString = nsLiteralCString( |
| 1245 | "," |
| 1246 | "(null, 'place:parent=" MOBILE_ROOT_GUID"mobile______" |
| 1247 | "', :MobileBookmarksFolderTitle, null, null, null, " |
| 1248 | "null, null, 0, 0, null, null, null, null, " |
| 1249 | SQL_QUOTE(MOBILE_BOOKMARKS_VIRTUAL_GUID)"'" "mobile_____v" "'" ", null, " |
| 1250 | "null, null, null, null, null, null, " SQL_QUOTE(MOBILE_ROOT_GUID)"'" "mobile______" "'" ", " |
| 1251 | "(SELECT id FROM moz_bookmarks WHERE guid = " SQL_QUOTE(MOBILE_ROOT_GUID)"'" "mobile______" "'" "), " |
| 1252 | ":MobileBookmarksFolderTitle)"); |
| 1253 | } |
| 1254 | |
| 1255 | mQueryString = |
| 1256 | nsLiteralCString( |
| 1257 | "SELECT * FROM (" |
| 1258 | "VALUES(null, 'place:parent=" TOOLBAR_ROOT_GUID"toolbar_____" |
| 1259 | "', :BookmarksToolbarFolderTitle, null, null, null, " |
| 1260 | "null, null, 0, 0, null, null, null, null, 'toolbar____v', null, " |
| 1261 | "null, null, null, null, null, null, " SQL_QUOTE(TOOLBAR_ROOT_GUID)"'" "toolbar_____" "'" ", " |
| 1262 | "(SELECT id FROM moz_bookmarks WHERE guid = " SQL_QUOTE(TOOLBAR_ROOT_GUID)"'" "toolbar_____" "'" "), " |
| 1263 | ":BookmarksToolbarFolderTitle), " |
| 1264 | "(null, 'place:parent=" MENU_ROOT_GUID"menu________" |
| 1265 | "', :BookmarksMenuFolderTitle, null, null, null, " |
| 1266 | "null, null, 0, 0, null, null, null, null, 'menu_______v', null, " |
| 1267 | "null, null, null, null, null, null, " SQL_QUOTE(MENU_ROOT_GUID)"'" "menu________" "'" ", " |
| 1268 | "(SELECT id FROM moz_bookmarks WHERE guid = " SQL_QUOTE(MENU_ROOT_GUID)"'" "menu________" "'" "), " |
| 1269 | ":BookmarksMenuFolderTitle), " |
| 1270 | "(null, 'place:parent=" UNFILED_ROOT_GUID"unfiled_____" |
| 1271 | "', :OtherBookmarksFolderTitle, null, null, null, " |
| 1272 | "null, null, 0, 0, null, null, null, null, 'unfiled____v', null, " |
| 1273 | "null, null, null, null, null, null, " SQL_QUOTE(UNFILED_ROOT_GUID)"'" "unfiled_____" "'" ", " |
| 1274 | "(SELECT id FROM moz_bookmarks WHERE guid = " SQL_QUOTE(UNFILED_ROOT_GUID)"'" "unfiled_____" "'" "), " |
| 1275 | ":OtherBookmarksFolderTitle)") + |
| 1276 | mobileString + ")"_ns; |
| 1277 | |
| 1278 | return NS_OK; |
| 1279 | } |
| 1280 | |
| 1281 | nsresult PlacesSQLQueryBuilder::SelectAsLeftPane() { |
| 1282 | nsNavHistory* history = nsNavHistory::GetHistoryService(); |
| 1283 | NS_ENSURE_STATE(history)do { if ((__builtin_expect(!!(!(history)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "history" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1283); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1284 | |
| 1285 | nsAutoCString historyTitle; |
| 1286 | nsAutoCString downloadsTitle; |
| 1287 | nsAutoCString tagsTitle; |
| 1288 | nsAutoCString allBookmarksTitle; |
| 1289 | |
| 1290 | history->GetStringFromName("OrganizerQueryHistory", historyTitle); |
| 1291 | mAddParams.InsertOrUpdate("OrganizerQueryHistory"_ns, historyTitle); |
| 1292 | history->GetStringFromName("OrganizerQueryDownloads", downloadsTitle); |
| 1293 | mAddParams.InsertOrUpdate("OrganizerQueryDownloads"_ns, downloadsTitle); |
| 1294 | history->GetStringFromName("TagsFolderTitle", tagsTitle); |
| 1295 | mAddParams.InsertOrUpdate("TagsFolderTitle"_ns, tagsTitle); |
| 1296 | history->GetStringFromName("OrganizerQueryAllBookmarks", allBookmarksTitle); |
| 1297 | mAddParams.InsertOrUpdate("OrganizerQueryAllBookmarks"_ns, allBookmarksTitle); |
| 1298 | |
| 1299 | mQueryString = nsPrintfCString( |
| 1300 | "SELECT * FROM (" |
| 1301 | "VALUES" |
| 1302 | "(null, 'place:type=%d&sort=%d', :OrganizerQueryHistory, null, null, " |
| 1303 | "null, " |
| 1304 | "null, null, 0, 0, null, null, null, null, 'history____v', null, " |
| 1305 | "null, null, null, null, null, null, null), " |
| 1306 | "(null, 'place:transition=%d&sort=%d', :OrganizerQueryDownloads, null, " |
| 1307 | "null, null, " |
| 1308 | "null, null, 0, 0, null, null, null, null, 'downloads__v', null, " |
| 1309 | "null, null, null, null, null, null, null), " |
| 1310 | "(null, 'place:type=%d&sort=%d', :TagsFolderTitle, null, null, null, " |
| 1311 | "null, null, 0, 0, null, null, null, null, 'tags_______v', null, " |
| 1312 | "null, null, null, null, null, null, null), " |
| 1313 | "(null, 'place:type=%d', :OrganizerQueryAllBookmarks, null, null, null, " |
| 1314 | "null, null, 0, 0, null, null, null, null, 'allbms_____v', null, " |
| 1315 | "null, null, null, null, null, null, null) " |
| 1316 | ")", |
| 1317 | nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY, |
| 1318 | nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING, |
| 1319 | nsINavHistoryService::TRANSITION_DOWNLOAD, |
| 1320 | nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING, |
| 1321 | nsINavHistoryQueryOptions::RESULTS_AS_TAGS_ROOT, |
| 1322 | nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING, |
| 1323 | nsINavHistoryQueryOptions::RESULTS_AS_ROOTS_QUERY); |
| 1324 | return NS_OK; |
| 1325 | } |
| 1326 | |
| 1327 | nsresult PlacesSQLQueryBuilder::Where() { |
| 1328 | // Set query options |
| 1329 | nsAutoCString additionalVisitsConditions; |
| 1330 | nsAutoCString additionalPlacesConditions; |
| 1331 | |
| 1332 | if (!mIncludeHidden) { |
| 1333 | additionalPlacesConditions += "AND hidden = 0 "_ns; |
| 1334 | } |
| 1335 | |
| 1336 | if (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) { |
| 1337 | // last_visit_date is updated for any kind of visit, so it's a good |
| 1338 | // indicator whether the page has visits. |
| 1339 | additionalPlacesConditions += "AND last_visit_date NOTNULL "_ns; |
| 1340 | } |
| 1341 | |
| 1342 | if (mResultType == nsINavHistoryQueryOptions::RESULTS_AS_URI && |
| 1343 | !additionalVisitsConditions.IsEmpty()) { |
| 1344 | // URI results don't join on visits. |
| 1345 | nsAutoCString tmp = additionalVisitsConditions; |
| 1346 | additionalVisitsConditions = |
| 1347 | "AND EXISTS (SELECT 1 FROM moz_historyvisits WHERE place_id = h.id "; |
| 1348 | additionalVisitsConditions.Append(tmp); |
| 1349 | additionalVisitsConditions.AppendLiteral("LIMIT 1)"); |
| 1350 | } |
| 1351 | |
| 1352 | mQueryString.ReplaceSubstring("{QUERY_OPTIONS_VISITS}", |
| 1353 | additionalVisitsConditions.get()); |
| 1354 | mQueryString.ReplaceSubstring("{QUERY_OPTIONS_PLACES}", |
| 1355 | additionalPlacesConditions.get()); |
| 1356 | |
| 1357 | // If we used WHERE already, we inject the conditions |
| 1358 | // in place of {ADDITIONAL_CONDITIONS} |
| 1359 | if (mQueryString.Find("{ADDITIONAL_CONDITIONS}") != kNotFound) { |
| 1360 | nsAutoCString innerCondition; |
| 1361 | // If we have condition AND it |
| 1362 | if (!mConditions.IsEmpty()) { |
| 1363 | innerCondition = " AND ("; |
| 1364 | innerCondition += mConditions; |
| 1365 | innerCondition += ")"; |
| 1366 | } |
| 1367 | mQueryString.ReplaceSubstring("{ADDITIONAL_CONDITIONS}", |
| 1368 | innerCondition.get()); |
| 1369 | |
| 1370 | } else if (!mConditions.IsEmpty()) { |
| 1371 | mQueryString += "WHERE "; |
| 1372 | mQueryString += mConditions; |
| 1373 | } |
| 1374 | return NS_OK; |
| 1375 | } |
| 1376 | |
| 1377 | nsresult PlacesSQLQueryBuilder::GroupBy() { |
| 1378 | mQueryString += mGroupBy; |
| 1379 | return NS_OK; |
| 1380 | } |
| 1381 | |
| 1382 | nsresult PlacesSQLQueryBuilder::OrderBy() { |
| 1383 | if (mSkipOrderBy) return NS_OK; |
| 1384 | |
| 1385 | // Sort clause: we will sort later, but if it comes out of the DB sorted, |
| 1386 | // our later sort will be basically free. The DB can sort these for free |
| 1387 | // most of the time anyway, because it has indices over these items. |
| 1388 | switch (mSortingMode) { |
| 1389 | case nsINavHistoryQueryOptions::SORT_BY_NONE: |
| 1390 | // Ensure sorting does not change based on tables status. |
| 1391 | if (mResultType == nsINavHistoryQueryOptions::RESULTS_AS_URI) { |
| 1392 | if (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS) |
| 1393 | mQueryString += " ORDER BY b.id ASC "_ns; |
| 1394 | else if (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) |
| 1395 | mQueryString += " ORDER BY h.id ASC "_ns; |
| 1396 | } |
| 1397 | break; |
| 1398 | case nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING: |
| 1399 | case nsINavHistoryQueryOptions::SORT_BY_TITLE_DESCENDING: |
| 1400 | // If the user wants few results, we limit them by date, necessitating |
| 1401 | // a sort by date here (see the IDL definition for maxResults). |
| 1402 | // Otherwise we will do actual sorting by title, but since we could need |
| 1403 | // to special sort for some locale we will repeat a second sorting at the |
| 1404 | // end in nsNavHistoryResult, that should be faster since the list will be |
| 1405 | // almost ordered. |
| 1406 | if (mMaxResults > 0) |
| 1407 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_VisitDate); |
| 1408 | else if (mSortingMode == |
| 1409 | nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING) |
| 1410 | OrderByTextColumnIndexAsc(nsNavHistory::kGetInfoIndex_Title); |
| 1411 | else |
| 1412 | OrderByTextColumnIndexDesc(nsNavHistory::kGetInfoIndex_Title); |
| 1413 | break; |
| 1414 | case nsINavHistoryQueryOptions::SORT_BY_DATE_ASCENDING: |
| 1415 | OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_VisitDate); |
| 1416 | break; |
| 1417 | case nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING: |
| 1418 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_VisitDate); |
| 1419 | break; |
| 1420 | case nsINavHistoryQueryOptions::SORT_BY_URI_ASCENDING: |
| 1421 | OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_URL); |
| 1422 | break; |
| 1423 | case nsINavHistoryQueryOptions::SORT_BY_URI_DESCENDING: |
| 1424 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_URL); |
| 1425 | break; |
| 1426 | case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_ASCENDING: |
| 1427 | OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_VisitCount); |
| 1428 | break; |
| 1429 | case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING: |
| 1430 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_VisitCount); |
| 1431 | break; |
| 1432 | case nsINavHistoryQueryOptions::SORT_BY_DATEADDED_ASCENDING: |
| 1433 | if (mHasDateColumns) |
| 1434 | OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_ItemDateAdded); |
| 1435 | break; |
| 1436 | case nsINavHistoryQueryOptions::SORT_BY_DATEADDED_DESCENDING: |
| 1437 | if (mHasDateColumns) |
| 1438 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_ItemDateAdded); |
| 1439 | break; |
| 1440 | case nsINavHistoryQueryOptions::SORT_BY_LASTMODIFIED_ASCENDING: |
| 1441 | if (mHasDateColumns) |
| 1442 | OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_ItemLastModified); |
| 1443 | break; |
| 1444 | case nsINavHistoryQueryOptions::SORT_BY_LASTMODIFIED_DESCENDING: |
| 1445 | if (mHasDateColumns) |
| 1446 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_ItemLastModified); |
| 1447 | break; |
| 1448 | case nsINavHistoryQueryOptions::SORT_BY_TAGS_ASCENDING: |
| 1449 | case nsINavHistoryQueryOptions::SORT_BY_TAGS_DESCENDING: |
| 1450 | break; // Sort later in nsNavHistoryQueryResultNode::FillChildren() |
| 1451 | case nsINavHistoryQueryOptions::SORT_BY_FRECENCY_ASCENDING: |
| 1452 | OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_Frecency); |
| 1453 | break; |
| 1454 | case nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING: |
| 1455 | OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_Frecency); |
| 1456 | break; |
| 1457 | default: |
| 1458 | MOZ_ASSERT_UNREACHABLE("Invalid sorting mode")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "Invalid sorting mode" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1458); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Invalid sorting mode" ")"); do { MOZ_CrashSequence(__null, 1458); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 1459 | } |
| 1460 | return NS_OK; |
| 1461 | } |
| 1462 | |
| 1463 | void PlacesSQLQueryBuilder::OrderByColumnIndexAsc(int32_t aIndex) { |
| 1464 | mQueryString += nsPrintfCString(" ORDER BY %d ASC", aIndex + 1); |
| 1465 | } |
| 1466 | |
| 1467 | void PlacesSQLQueryBuilder::OrderByColumnIndexDesc(int32_t aIndex) { |
| 1468 | mQueryString += nsPrintfCString(" ORDER BY %d DESC", aIndex + 1); |
| 1469 | } |
| 1470 | |
| 1471 | void PlacesSQLQueryBuilder::OrderByTextColumnIndexAsc(int32_t aIndex) { |
| 1472 | mQueryString += |
| 1473 | nsPrintfCString(" ORDER BY %d COLLATE NOCASE ASC", aIndex + 1); |
| 1474 | } |
| 1475 | |
| 1476 | void PlacesSQLQueryBuilder::OrderByTextColumnIndexDesc(int32_t aIndex) { |
| 1477 | mQueryString += |
| 1478 | nsPrintfCString(" ORDER BY %d COLLATE NOCASE DESC", aIndex + 1); |
| 1479 | } |
| 1480 | |
| 1481 | nsresult PlacesSQLQueryBuilder::Limit() { |
| 1482 | if (mUseLimit && mMaxResults > 0) { |
| 1483 | mQueryString += " LIMIT "_ns; |
| 1484 | mQueryString.AppendInt(mMaxResults); |
| 1485 | mQueryString.Append(' '); |
| 1486 | } |
| 1487 | return NS_OK; |
| 1488 | } |
| 1489 | |
| 1490 | nsresult nsNavHistory::ConstructQueryString( |
| 1491 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 1492 | const RefPtr<nsNavHistoryQueryOptions>& aOptions, nsCString& queryString, |
| 1493 | bool& aParamsPresent, nsNavHistory::StringHash& aAddParams) { |
| 1494 | // For information about visit_type see nsINavHistoryService.idl. |
| 1495 | // visitType == 0 is undefined (see bug #375777 for details). |
| 1496 | // Some sites, especially Javascript-heavy ones, load things in frames to |
| 1497 | // display them, resulting in a lot of these entries. This is the reason |
| 1498 | // why such visits are filtered out. |
| 1499 | nsresult rv; |
| 1500 | aParamsPresent = false; |
| 1501 | |
| 1502 | int32_t sortingMode = aOptions->SortingMode(); |
| 1503 | NS_ASSERTION(do { if (!(sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Invalid sortingMode found while building query!" , "sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1506); MOZ_PretendNoReturn(); } } while (0) |
| 1504 | sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE &&do { if (!(sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Invalid sortingMode found while building query!" , "sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1506); MOZ_PretendNoReturn(); } } while (0) |
| 1505 | sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING,do { if (!(sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Invalid sortingMode found while building query!" , "sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1506); MOZ_PretendNoReturn(); } } while (0) |
| 1506 | "Invalid sortingMode found while building query!")do { if (!(sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Invalid sortingMode found while building query!" , "sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE && sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1506); MOZ_PretendNoReturn(); } } while (0); |
| 1507 | |
| 1508 | if (IsOptimizableHistoryQuery( |
| 1509 | aQuery, aOptions, |
| 1510 | nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING) || |
| 1511 | IsOptimizableHistoryQuery( |
| 1512 | aQuery, aOptions, |
| 1513 | nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING)) { |
| 1514 | // Generate an optimized query for the history menu and the old most visited |
| 1515 | // bookmark that was inserted into profiles. |
| 1516 | queryString = |
| 1517 | GetTagsSqlFragment(aOptions->QueryType(), aOptions->ExcludeItems()) + |
| 1518 | "SELECT h.id, h.url, h.title AS page_title, h.rev_host, " |
| 1519 | " h.visit_count, h.last_visit_date, null, null, null, null, null, " |
| 1520 | " (SELECT tags FROM tagged WHERE place_id = h.id) AS tags, " |
| 1521 | " h.frecency, h.hidden, h.guid, null, null, null, " |
| 1522 | " null, null, null, null, null, null, null " |
| 1523 | "FROM moz_places h " |
| 1524 | "WHERE h.hidden = 0 " |
| 1525 | "AND EXISTS (SELECT id FROM moz_historyvisits WHERE place_id = " |
| 1526 | "h.id " |
| 1527 | "AND visit_type NOT IN "_ns + |
| 1528 | nsPrintfCString("(0,%d,%d) ", nsINavHistoryService::TRANSITION_EMBED, |
| 1529 | nsINavHistoryService::TRANSITION_FRAMED_LINK) + |
| 1530 | "LIMIT 1) " |
| 1531 | "{QUERY_OPTIONS} "_ns; |
| 1532 | |
| 1533 | queryString.AppendLiteral("ORDER BY "); |
| 1534 | if (sortingMode == nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING) |
| 1535 | queryString.AppendLiteral("last_visit_date DESC "); |
| 1536 | else |
| 1537 | queryString.AppendLiteral("visit_count DESC "); |
| 1538 | |
| 1539 | queryString.AppendLiteral("LIMIT "); |
| 1540 | queryString.AppendInt(aOptions->MaxResults()); |
| 1541 | |
| 1542 | nsAutoCString additionalQueryOptions; |
| 1543 | |
| 1544 | queryString.ReplaceSubstring("{QUERY_OPTIONS}", |
| 1545 | additionalQueryOptions.get()); |
| 1546 | return NS_OK; |
| 1547 | } |
| 1548 | |
| 1549 | // If the query is a tag query, the type is bookmarks. |
| 1550 | if (!aQuery->Tags().IsEmpty()) { |
| 1551 | aOptions->SetQueryType(nsNavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS); |
| 1552 | } |
| 1553 | |
| 1554 | nsAutoCString conditions; |
| 1555 | nsCString queryClause; |
| 1556 | rv = QueryToSelectClause(aQuery, aOptions, &queryClause); |
| 1557 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1557); return rv; } } while (false); |
| 1558 | if (!queryClause.IsEmpty()) { |
| 1559 | // TODO: This should be set on a case basis, not blindly. |
| 1560 | aParamsPresent = true; |
| 1561 | conditions += queryClause; |
| 1562 | } |
| 1563 | |
| 1564 | // Determine whether we can push maxResults constraints into the query |
| 1565 | // as LIMIT, or if we need to do result count clamping later |
| 1566 | // using FilterResultSet() |
| 1567 | bool useLimitClause = !NeedToFilterResultSet(aQuery, aOptions); |
| 1568 | |
| 1569 | PlacesSQLQueryBuilder queryStringBuilder(conditions, aQuery, aOptions, |
| 1570 | useLimitClause, aAddParams); |
| 1571 | rv = queryStringBuilder.GetQueryString(queryString); |
| 1572 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1572); return rv; } } while (false); |
| 1573 | |
| 1574 | return NS_OK; |
| 1575 | } |
| 1576 | |
| 1577 | // nsNavHistory::GetQueryResults |
| 1578 | // |
| 1579 | // Call this to get the results from a complex query. This is used by |
| 1580 | // nsNavHistoryQueryResultNode to populate its children. For simple bookmark |
| 1581 | // queries, use nsNavBookmarks::QueryFolderChildren. |
| 1582 | // |
| 1583 | // THIS DOES NOT DO SORTING. You will need to sort the container yourself |
| 1584 | // when you get the results. This is because sorting depends on tree |
| 1585 | // statistics that will be built from the perspective of the tree. See |
| 1586 | // nsNavHistoryQueryResultNode::FillChildren |
| 1587 | // |
| 1588 | // FIXME: This only does keyword searching for the first query, and does |
| 1589 | // it ANDed with the all the rest of the queries. |
| 1590 | |
| 1591 | nsresult nsNavHistory::GetQueryResults( |
| 1592 | nsNavHistoryQueryResultNode* aResultNode, |
| 1593 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 1594 | const RefPtr<nsNavHistoryQueryOptions>& aOptions, |
| 1595 | nsCOMArray<nsNavHistoryResultNode>* aResults) { |
| 1596 | NS_ENSURE_ARG_POINTER(aQuery)do { if ((__builtin_expect(!!(!(aQuery)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aQuery" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1596); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1597 | NS_ENSURE_ARG_POINTER(aOptions)do { if ((__builtin_expect(!!(!(aOptions)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aOptions" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1597); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1598 | NS_ASSERTION(aResults->Count() == 0, "Initial result array must be empty")do { if (!(aResults->Count() == 0)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "Initial result array must be empty", "aResults->Count() == 0" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1598); MOZ_PretendNoReturn(); } } while (0); |
| 1599 | |
| 1600 | nsCString queryString; |
| 1601 | bool paramsPresent = false; |
| 1602 | nsNavHistory::StringHash addParams(HISTORY_DATE_CONT_LENGTH8); |
| 1603 | nsresult rv = ConstructQueryString(aQuery, aOptions, queryString, |
| 1604 | paramsPresent, addParams); |
| 1605 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1605); return rv; } } while (false); |
| 1606 | |
| 1607 | // create statement |
| 1608 | nsCOMPtr<mozIStorageStatement> statement = mDB->GetStatement(queryString); |
| 1609 | #ifdef DEBUG1 |
| 1610 | if (!statement) { |
| 1611 | nsCOMPtr<mozIStorageConnection> conn = mDB->MainConn(); |
| 1612 | if (conn) { |
| 1613 | nsAutoCString lastErrorString; |
| 1614 | (void)conn->GetLastErrorString(lastErrorString); |
| 1615 | int32_t lastError = 0; |
| 1616 | (void)conn->GetLastError(&lastError); |
| 1617 | printf( |
| 1618 | "Places failed to create a statement from this query:\n%s\nStorage " |
| 1619 | "error (%d): %s\n", |
| 1620 | queryString.get(), lastError, lastErrorString.get()); |
| 1621 | } |
| 1622 | } |
| 1623 | #endif |
| 1624 | NS_ENSURE_STATE(statement)do { if ((__builtin_expect(!!(!(statement)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "statement" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1624); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1625 | mozStorageStatementScoper scoper(statement); |
| 1626 | |
| 1627 | if (paramsPresent) { |
| 1628 | rv = BindQueryClauseParameters(statement, aQuery, aOptions); |
| 1629 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1629); return rv; } } while (false); |
| 1630 | } |
| 1631 | |
| 1632 | for (const auto& entry : addParams) { |
| 1633 | nsresult rv = |
| 1634 | statement->BindUTF8StringByName(entry.GetKey(), entry.GetData()); |
| 1635 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1636 | break; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | // Optimize the case where there is no need for any post-query filtering. |
| 1641 | if (NeedToFilterResultSet(aQuery, aOptions)) { |
| 1642 | // Generate the top-level results. |
| 1643 | nsCOMArray<nsNavHistoryResultNode> toplevel; |
| 1644 | rv = ResultsAsList(statement, aOptions, &toplevel); |
| 1645 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1645); return rv; } } while (false); |
| 1646 | |
| 1647 | FilterResultSet(aResultNode, toplevel, aResults, aQuery, aOptions); |
| 1648 | } else { |
| 1649 | rv = ResultsAsList(statement, aOptions, aResults); |
| 1650 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1650); return rv; } } while (false); |
| 1651 | } |
| 1652 | |
| 1653 | return NS_OK; |
| 1654 | } |
| 1655 | |
| 1656 | NS_IMETHODIMPnsresult |
| 1657 | nsNavHistory::GetHistoryDisabled(bool* _retval) { |
| 1658 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1658); MOZ_PretendNoReturn(); } } while (0); |
| 1659 | NS_ENSURE_ARG_POINTER(_retval)do { if ((__builtin_expect(!!(!(_retval)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_retval" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1659); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1660 | |
| 1661 | *_retval = IsHistoryDisabled(); |
| 1662 | return NS_OK; |
| 1663 | } |
| 1664 | |
| 1665 | // Call this method before visiting a URL in order to help determine the |
| 1666 | // transition type of the visit. |
| 1667 | // |
| 1668 | // @see MarkPageAsFollowedBookmark |
| 1669 | |
| 1670 | NS_IMETHODIMPnsresult |
| 1671 | nsNavHistory::MarkPageAsTyped(nsIURI* aURI) { |
| 1672 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1672); MOZ_PretendNoReturn(); } } while (0); |
| 1673 | NS_ENSURE_ARG(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1673); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1674 | |
| 1675 | // don't add when history is disabled |
| 1676 | if (IsHistoryDisabled()) return NS_OK; |
| 1677 | |
| 1678 | nsAutoCString uriString; |
| 1679 | nsresult rv = aURI->GetSpec(uriString); |
| 1680 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1680); return rv; } } while (false); |
| 1681 | |
| 1682 | mRecentTyped.InsertOrUpdate(uriString, GetNow()); |
| 1683 | |
| 1684 | if (mRecentTyped.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH128) |
| 1685 | ExpireNonrecentEvents(&mRecentTyped); |
| 1686 | |
| 1687 | return NS_OK; |
| 1688 | } |
| 1689 | |
| 1690 | // Call this method before visiting a URL in order to help determine the |
| 1691 | // transition type of the visit. |
| 1692 | // |
| 1693 | // @see MarkPageAsTyped |
| 1694 | |
| 1695 | NS_IMETHODIMPnsresult |
| 1696 | nsNavHistory::MarkPageAsFollowedLink(nsIURI* aURI) { |
| 1697 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1697); MOZ_PretendNoReturn(); } } while (0); |
| 1698 | NS_ENSURE_ARG(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1698); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1699 | |
| 1700 | // don't add when history is disabled |
| 1701 | if (IsHistoryDisabled()) return NS_OK; |
| 1702 | |
| 1703 | nsAutoCString uriString; |
| 1704 | nsresult rv = aURI->GetSpec(uriString); |
| 1705 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1705); return rv; } } while (false); |
| 1706 | |
| 1707 | mRecentLink.InsertOrUpdate(uriString, GetNow()); |
| 1708 | |
| 1709 | if (mRecentLink.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH128) |
| 1710 | ExpireNonrecentEvents(&mRecentLink); |
| 1711 | |
| 1712 | return NS_OK; |
| 1713 | } |
| 1714 | |
| 1715 | NS_IMETHODIMPnsresult |
| 1716 | nsNavHistory::GetIsAlternativeFrecencyEnabled(bool* _out) { |
| 1717 | *_out = |
| 1718 | StaticPrefs::places_frecency_pages_alternative_featureGate_AtStartup(); |
| 1719 | return NS_OK; |
| 1720 | } |
| 1721 | |
| 1722 | NS_IMETHODIMPnsresult |
| 1723 | nsNavHistory::GetShouldStartFrecencyRecalculation(bool* _out) { |
| 1724 | NS_ENSURE_ARG_POINTER(_out)do { if ((__builtin_expect(!!(!(_out)), 0))) { NS_DebugBreak( NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_out" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1724); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1725 | *_out = nsNavHistory::sShouldStartFrecencyRecalculation; |
| 1726 | return NS_OK; |
| 1727 | } |
| 1728 | |
| 1729 | NS_IMETHODIMPnsresult |
| 1730 | nsNavHistory::SetShouldStartFrecencyRecalculation(bool aVal) { |
| 1731 | nsNavHistory::sShouldStartFrecencyRecalculation = aVal; |
| 1732 | return NS_OK; |
| 1733 | } |
| 1734 | |
| 1735 | NS_IMETHODIMPnsresult |
| 1736 | nsNavHistory::PageFrecencyThreshold(int32_t aVisitAgeInDays, int32_t aNumVisits, |
| 1737 | bool aBookmarked, int64_t* aFrecency) { |
| 1738 | NS_ENSURE_ARG_POINTER(aFrecency)do { if ((__builtin_expect(!!(!(aFrecency)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aFrecency" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1738); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1739 | NS_ENSURE_TRUE(aNumVisits >= 0, NS_ERROR_INVALID_ARG)do { if ((__builtin_expect(!!(!(aNumVisits >= 0)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aNumVisits >= 0" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1739); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1740 | NS_ENSURE_TRUE(aVisitAgeInDays >= 0, NS_ERROR_INVALID_ARG)do { if ((__builtin_expect(!!(!(aVisitAgeInDays >= 0)), 0) )) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aVisitAgeInDays >= 0" ") failed", nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1740); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1741 | |
| 1742 | // Calculate the frecency threshold based on the input parameters. |
| 1743 | *aFrecency = CalculateFrecency(aVisitAgeInDays, aNumVisits, aBookmarked); |
| 1744 | return NS_OK; |
| 1745 | } |
| 1746 | |
| 1747 | int64_t nsNavHistory::CalculateFrecency(int32_t aVisitAgeInDays, |
| 1748 | int32_t aNumVisits, |
| 1749 | bool aBookmarked) const { |
| 1750 | bool useAlternative = |
| 1751 | StaticPrefs::places_frecency_pages_alternative_featureGate_AtStartup(); |
| 1752 | int32_t halfLifeDays = |
| 1753 | (useAlternative |
| 1754 | ? StaticPrefs:: |
| 1755 | places_frecency_pages_alternative_halfLifeDays_AtStartup() |
| 1756 | : StaticPrefs::places_frecency_pages_halfLifeDays_AtStartup()); |
| 1757 | int32_t maxSamples = |
| 1758 | (useAlternative |
| 1759 | ? StaticPrefs:: |
| 1760 | places_frecency_pages_alternative_numSampledVisits_AtStartup() |
| 1761 | : StaticPrefs::places_frecency_pages_numSampledVisits_AtStartup()); |
| 1762 | int32_t highWeight = |
| 1763 | (useAlternative |
| 1764 | ? StaticPrefs:: |
| 1765 | places_frecency_pages_alternative_highWeight_AtStartup() |
| 1766 | : StaticPrefs::places_frecency_pages_highWeight_AtStartup()); |
| 1767 | int32_t mediumWeight = |
| 1768 | (useAlternative |
| 1769 | ? StaticPrefs:: |
| 1770 | places_frecency_pages_alternative_mediumWeight_AtStartup() |
| 1771 | : StaticPrefs::places_frecency_pages_mediumWeight_AtStartup()); |
| 1772 | |
| 1773 | int32_t samplesCount = 0; |
| 1774 | if (aNumVisits > 0) { |
| 1775 | // The frecency algorithm only samples a maximum number of visits. |
| 1776 | samplesCount = std::min(aNumVisits, maxSamples); |
| 1777 | } else if (aBookmarked) { |
| 1778 | // An unvisited bookmark is considered a single sample. |
| 1779 | samplesCount = 1; |
| 1780 | } |
| 1781 | |
| 1782 | if (samplesCount == 0) { |
| 1783 | return 0; |
| 1784 | } |
| 1785 | |
| 1786 | PRTime now = PR_Now(); |
| 1787 | int32_t todayInDaysFromEpoch = static_cast<int32_t>(now / USEC_PER_DAY86400000000LL); |
| 1788 | int32_t refTimeInDaysFromEpoch = todayInDaysFromEpoch - aVisitAgeInDays; |
| 1789 | |
| 1790 | int32_t visitWeight = aBookmarked ? highWeight : mediumWeight; |
| 1791 | double lambda = std::numbers::ln2 / static_cast<double>(halfLifeDays); |
| 1792 | double decayedWeight = |
| 1793 | static_cast<double>(visitWeight) * |
| 1794 | exp(-lambda * |
| 1795 | static_cast<double>(todayInDaysFromEpoch - refTimeInDaysFromEpoch)); |
| 1796 | |
| 1797 | // Note: Since all samples have equal weight in this simplified version, |
| 1798 | // we can use decayedWeight directly instead of computing the average. |
| 1799 | double logCountAdjustedScore = |
| 1800 | log(decayedWeight * std::max(samplesCount, aNumVisits)); |
| 1801 | // The future date when the score would decay to a value of 1. |
| 1802 | int32_t frecency = refTimeInDaysFromEpoch + |
| 1803 | static_cast<int32_t>(logCountAdjustedScore / lambda); |
| 1804 | |
| 1805 | return static_cast<int64_t>(std::max(frecency, 0)); |
| 1806 | } |
| 1807 | |
| 1808 | //////////////////////////////////////////////////////////////////////////////// |
| 1809 | //// mozIStorageVacuumParticipant |
| 1810 | |
| 1811 | NS_IMETHODIMPnsresult |
| 1812 | nsNavHistory::GetDatabaseConnection( |
| 1813 | mozIStorageAsyncConnection** _DBConnection) { |
| 1814 | NS_ENSURE_ARG_POINTER(_DBConnection)do { if ((__builtin_expect(!!(!(_DBConnection)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_DBConnection" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1814); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1815 | nsCOMPtr<mozIStorageAsyncConnection> connection = mDB->MainConn(); |
| 1816 | connection.forget(_DBConnection); |
| 1817 | return NS_OK; |
| 1818 | } |
| 1819 | |
| 1820 | NS_IMETHODIMPnsresult |
| 1821 | nsNavHistory::GetUseIncrementalVacuum(bool* _useIncremental) { |
| 1822 | *_useIncremental = false; |
| 1823 | return NS_OK; |
| 1824 | } |
| 1825 | |
| 1826 | NS_IMETHODIMPnsresult |
| 1827 | nsNavHistory::GetExpectedDatabasePageSize(int32_t* _expectedPageSize) { |
| 1828 | NS_ENSURE_STATE(mDB)do { if ((__builtin_expect(!!(!(mDB)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING , "NS_ENSURE_TRUE(" "mDB" ") failed", nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1828); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1829 | NS_ENSURE_STATE(mDB->MainConn())do { if ((__builtin_expect(!!(!(mDB->MainConn())), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "mDB->MainConn()" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1829); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1830 | return mDB->MainConn()->GetDefaultPageSize(_expectedPageSize); |
| 1831 | } |
| 1832 | |
| 1833 | NS_IMETHODIMPnsresult |
| 1834 | nsNavHistory::OnBeginVacuum(bool* _vacuumGranted) { |
| 1835 | // TODO: Check if we have to deny the vacuum in some heavy-load case. |
| 1836 | // We could maybe want to do that during batches? |
| 1837 | *_vacuumGranted = true; |
| 1838 | return NS_OK; |
| 1839 | } |
| 1840 | |
| 1841 | NS_IMETHODIMPnsresult |
| 1842 | nsNavHistory::OnEndVacuum(bool aSucceeded) { |
| 1843 | NS_WARNING_ASSERTION(aSucceeded, "Places.sqlite vacuum failed.")do { if (!(aSucceeded)) { NS_DebugBreak(NS_DEBUG_WARNING, "Places.sqlite vacuum failed." , "aSucceeded", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1843); } } while (false); |
| 1844 | return NS_OK; |
| 1845 | } |
| 1846 | |
| 1847 | NS_IMETHODIMPnsresult |
| 1848 | nsNavHistory::GetDBConnection(mozIStorageConnection** _DBConnection) { |
| 1849 | NS_ENSURE_ARG_POINTER(_DBConnection)do { if ((__builtin_expect(!!(!(_DBConnection)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_DBConnection" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1849); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1850 | nsCOMPtr<mozIStorageConnection> connection = mDB->MainConn(); |
| 1851 | connection.forget(_DBConnection); |
| 1852 | |
| 1853 | return NS_OK; |
| 1854 | } |
| 1855 | |
| 1856 | NS_IMETHODIMPnsresult |
| 1857 | nsNavHistory::GetShutdownClient(nsIAsyncShutdownClient** _shutdownClient) { |
| 1858 | NS_ENSURE_ARG_POINTER(_shutdownClient)do { if ((__builtin_expect(!!(!(_shutdownClient)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_shutdownClient" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1858); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1859 | nsCOMPtr<nsIAsyncShutdownClient> client = mDB->GetClientsShutdown(); |
| 1860 | if (!client) { |
| 1861 | return NS_ERROR_UNEXPECTED; |
| 1862 | } |
| 1863 | client.forget(_shutdownClient); |
| 1864 | return NS_OK; |
| 1865 | } |
| 1866 | |
| 1867 | NS_IMETHODIMPnsresult |
| 1868 | nsNavHistory::GetConnectionShutdownClient( |
| 1869 | nsIAsyncShutdownClient** _shutdownClient) { |
| 1870 | NS_ENSURE_ARG_POINTER(_shutdownClient)do { if ((__builtin_expect(!!(!(_shutdownClient)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_shutdownClient" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1870); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1871 | nsCOMPtr<nsIAsyncShutdownClient> client = mDB->GetConnectionShutdown(); |
| 1872 | if (!client) { |
| 1873 | return NS_ERROR_UNEXPECTED; |
| 1874 | } |
| 1875 | client.forget(_shutdownClient); |
| 1876 | return NS_OK; |
| 1877 | } |
| 1878 | |
| 1879 | NS_IMETHODIMPnsresult |
| 1880 | nsNavHistory::AsyncExecuteLegacyQuery(nsINavHistoryQuery* aQuery, |
| 1881 | nsINavHistoryQueryOptions* aOptions, |
| 1882 | mozIStorageStatementCallback* aCallback, |
| 1883 | mozIStoragePendingStatement** _stmt) { |
| 1884 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1884); MOZ_PretendNoReturn(); } } while (0); |
| 1885 | NS_ENSURE_ARG(aQuery)do { if ((__builtin_expect(!!(!(aQuery)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aQuery" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1885); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1886 | NS_ENSURE_ARG(aOptions)do { if ((__builtin_expect(!!(!(aOptions)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aOptions" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1886); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1887 | NS_ENSURE_ARG(aCallback)do { if ((__builtin_expect(!!(!(aCallback)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aCallback" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1887); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1888 | NS_ENSURE_ARG_POINTER(_stmt)do { if ((__builtin_expect(!!(!(_stmt)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "_stmt" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1888); return NS_ERROR_INVALID_POINTER; } } while (false); |
| 1889 | |
| 1890 | RefPtr<nsNavHistoryQuery> query = do_QueryObject(aQuery); |
| 1891 | NS_ENSURE_STATE(query)do { if ((__builtin_expect(!!(!(query)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "query" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1891); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1892 | RefPtr<nsNavHistoryQueryOptions> options = do_QueryObject(aOptions); |
| 1893 | NS_ENSURE_ARG(options)do { if ((__builtin_expect(!!(!(options)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "options" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1893); return NS_ERROR_INVALID_ARG; } } while (false); |
| 1894 | |
| 1895 | nsCString queryString; |
| 1896 | bool paramsPresent = false; |
| 1897 | nsNavHistory::StringHash addParams(HISTORY_DATE_CONT_LENGTH8); |
| 1898 | nsresult rv = ConstructQueryString(query, options, queryString, paramsPresent, |
| 1899 | addParams); |
| 1900 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1900); return rv; } } while (false); |
| 1901 | |
| 1902 | nsCOMPtr<mozIStorageAsyncStatement> statement = |
| 1903 | mDB->GetAsyncStatement(queryString); |
| 1904 | NS_ENSURE_STATE(statement)do { if ((__builtin_expect(!!(!(statement)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "statement" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1904); return NS_ERROR_UNEXPECTED; } } while (false); |
| 1905 | |
| 1906 | #ifdef DEBUG1 |
| 1907 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1908 | nsCOMPtr<mozIStorageConnection> conn = mDB->MainConn(); |
| 1909 | if (conn) { |
| 1910 | nsAutoCString lastErrorString; |
| 1911 | (void)mDB->MainConn()->GetLastErrorString(lastErrorString); |
| 1912 | int32_t lastError = 0; |
| 1913 | (void)mDB->MainConn()->GetLastError(&lastError); |
| 1914 | printf( |
| 1915 | "Places failed to create a statement from this query:\n%s\nStorage " |
| 1916 | "error (%d): %s\n", |
| 1917 | queryString.get(), lastError, lastErrorString.get()); |
| 1918 | } |
| 1919 | } |
| 1920 | #endif |
| 1921 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1921); return rv; } } while (false); |
| 1922 | |
| 1923 | if (paramsPresent) { |
| 1924 | rv = BindQueryClauseParameters(statement, query, options); |
| 1925 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1925); return rv; } } while (false); |
| 1926 | } |
| 1927 | |
| 1928 | for (const auto& entry : addParams) { |
| 1929 | nsresult rv = |
| 1930 | statement->BindUTF8StringByName(entry.GetKey(), entry.GetData()); |
| 1931 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 1932 | break; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | rv = statement->ExecuteAsync(aCallback, _stmt); |
| 1937 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 1937); return rv; } } while (false); |
| 1938 | |
| 1939 | return NS_OK; |
| 1940 | } |
| 1941 | |
| 1942 | //////////////////////////////////////////////////////////////////////////////// |
| 1943 | //// nsIObserver |
| 1944 | |
| 1945 | NS_IMETHODIMPnsresult |
| 1946 | nsNavHistory::Observe(nsISupports* aSubject, const char* aTopic, |
| 1947 | const char16_t* aData) { |
| 1948 | NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread")do { if (!(NS_IsMainThread())) { NS_DebugBreak(NS_DEBUG_ASSERTION , "This can only be called on the main thread", "NS_IsMainThread()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 1948); MOZ_PretendNoReturn(); } } while (0); |
| 1949 | if (strcmp(aTopic, TOPIC_PROFILE_TEARDOWN"profile-change-teardown") == 0 || |
| 1950 | strcmp(aTopic, TOPIC_PROFILE_CHANGE"profile-before-change") == 0 || |
| 1951 | strcmp(aTopic, TOPIC_SIMULATE_PLACES_SHUTDOWN"test-simulate-places-shutdown") == 0) { |
| 1952 | // These notifications are used by tests to simulate a Places shutdown. |
| 1953 | // They should just be forwarded to the Database handle. |
| 1954 | mDB->Observe(aSubject, aTopic, aData); |
| 1955 | } |
| 1956 | |
| 1957 | else if (strcmp(aTopic, TOPIC_PREF_CHANGED"nsPref:changed") == 0) { |
| 1958 | LoadPrefs(); |
| 1959 | } |
| 1960 | |
| 1961 | else if (strcmp(aTopic, TOPIC_APP_LOCALES_CHANGED"intl:app-locales-changed") == 0) { |
| 1962 | mBundle = nullptr; |
| 1963 | } |
| 1964 | |
| 1965 | return NS_OK; |
| 1966 | } |
| 1967 | |
| 1968 | // Query stuff ***************************************************************** |
| 1969 | |
| 1970 | // Helper class for QueryToSelectClause |
| 1971 | // |
| 1972 | // This class helps to build part of the WHERE clause. |
| 1973 | |
| 1974 | class ConditionBuilder { |
| 1975 | public: |
| 1976 | ConditionBuilder& Condition(const char* aStr) { |
| 1977 | if (!mClause.IsEmpty()) mClause.AppendLiteral(" AND "); |
| 1978 | Str(aStr); |
| 1979 | return *this; |
| 1980 | } |
| 1981 | |
| 1982 | ConditionBuilder& Str(const char* aStr) { |
| 1983 | mClause.Append(' '); |
| 1984 | mClause.Append(aStr); |
| 1985 | mClause.Append(' '); |
| 1986 | return *this; |
| 1987 | } |
| 1988 | |
| 1989 | ConditionBuilder& Param(const char* aParam) { |
| 1990 | mClause.Append(' '); |
| 1991 | mClause.Append(aParam); |
| 1992 | mClause.Append(' '); |
| 1993 | return *this; |
| 1994 | } |
| 1995 | |
| 1996 | void GetClauseString(nsCString& aResult) { aResult = mClause; } |
| 1997 | |
| 1998 | private: |
| 1999 | nsCString mClause; |
| 2000 | }; |
| 2001 | |
| 2002 | // nsNavHistory::QueryToSelectClause |
| 2003 | // |
| 2004 | // THE BEHAVIOR SHOULD BE IN SYNC WITH BindQueryClauseParameters |
| 2005 | // |
| 2006 | // I don't check return values from the query object getters because there's |
| 2007 | // no way for those to fail. |
| 2008 | |
| 2009 | nsresult nsNavHistory::QueryToSelectClause( |
| 2010 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 2011 | const RefPtr<nsNavHistoryQueryOptions>& aOptions, nsCString* aClause) { |
| 2012 | bool hasIt; |
| 2013 | // We don't use the value from options here - we post filter if that |
| 2014 | // is set. |
| 2015 | bool excludeQueries = false; |
| 2016 | |
| 2017 | ConditionBuilder clause; |
| 2018 | |
| 2019 | if ((NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasBeginTime (&hasIt))), 1))) && hasIt) || |
| 2020 | (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasEndTime (&hasIt))), 1))) && hasIt)) { |
| 2021 | clause.Condition( |
| 2022 | "EXISTS (SELECT 1 FROM moz_historyvisits " |
| 2023 | "WHERE place_id = h.id"); |
| 2024 | // begin time |
| 2025 | if (NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasBeginTime (&hasIt))), 1))) && hasIt) |
| 2026 | clause.Condition("visit_date >=").Param(":begin_time"); |
| 2027 | // end time |
| 2028 | if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasEndTime (&hasIt))), 1))) && hasIt) |
| 2029 | clause.Condition("visit_date <=").Param(":end_time"); |
| 2030 | clause.Str(" LIMIT 1)"); |
| 2031 | } |
| 2032 | |
| 2033 | // search terms |
| 2034 | int32_t searchBehavior = mozIPlacesAutoComplete::BEHAVIOR_HISTORY | |
| 2035 | mozIPlacesAutoComplete::BEHAVIOR_BOOKMARK; |
| 2036 | if (!aQuery->SearchTerms().IsEmpty()) { |
| 2037 | // Re-use the autocomplete_match function. Setting the behavior to match |
| 2038 | // history or typed history or bookmarks or open pages will match almost |
| 2039 | // everything. |
| 2040 | clause.Condition("AUTOCOMPLETE_MATCH(") |
| 2041 | .Param(":search_string") |
| 2042 | .Str(", h.url, page_title, tags, ") |
| 2043 | .Str(nsPrintfCString("1, 1, 1, 1, %d, %d", |
| 2044 | mozIPlacesAutoComplete::MATCH_ANYWHERE_UNMODIFIED, |
| 2045 | searchBehavior) |
| 2046 | .get()) |
| 2047 | .Str(", NULL)"); |
| 2048 | // Serching by terms implicitly exclude queries. |
| 2049 | excludeQueries = true; |
| 2050 | } |
| 2051 | |
| 2052 | // min and max visit count |
| 2053 | if (aQuery->MinVisits() >= 0) |
| 2054 | clause.Condition("h.visit_count >=").Param(":min_visits"); |
| 2055 | |
| 2056 | if (aQuery->MaxVisits() >= 0) |
| 2057 | clause.Condition("h.visit_count <=").Param(":max_visits"); |
| 2058 | |
| 2059 | // domain |
| 2060 | if (!aQuery->Domain().IsVoid()) { |
| 2061 | bool domainIsHost = false; |
| 2062 | aQuery->GetDomainIsHost(&domainIsHost); |
| 2063 | if (domainIsHost) |
| 2064 | clause.Condition("h.rev_host =").Param(":domain_lower"); |
| 2065 | else |
| 2066 | // see domain setting in BindQueryClauseParameters for why we do this |
| 2067 | clause.Condition("h.rev_host >=") |
| 2068 | .Param(":domain_lower") |
| 2069 | .Condition("h.rev_host <") |
| 2070 | .Param(":domain_upper"); |
| 2071 | } |
| 2072 | |
| 2073 | // URI |
| 2074 | if (aQuery->Uri()) { |
| 2075 | clause.Condition("h.url_hash = hash(") |
| 2076 | .Param(":uri") |
| 2077 | .Str(")") |
| 2078 | .Condition("h.url =") |
| 2079 | .Param(":uri"); |
| 2080 | } |
| 2081 | |
| 2082 | // tags |
| 2083 | const nsTArray<nsString>& tags = aQuery->Tags(); |
| 2084 | if (tags.Length() > 0) { |
| 2085 | clause.Condition("h.id"); |
| 2086 | if (aQuery->TagsAreNot()) clause.Str("NOT"); |
| 2087 | clause |
| 2088 | .Str( |
| 2089 | "IN " |
| 2090 | "(SELECT bms.fk " |
| 2091 | "FROM moz_bookmarks bms " |
| 2092 | "JOIN moz_bookmarks tags ON bms.parent = tags.id " |
| 2093 | "WHERE tags.parent =") |
| 2094 | .Param(":tags_folder") |
| 2095 | .Str("AND lower(tags.title) IN ("); |
| 2096 | for (uint32_t i = 0; i < tags.Length(); ++i) { |
| 2097 | nsPrintfCString param(":tag%d_", i); |
| 2098 | clause.Param(param.get()); |
| 2099 | if (i < tags.Length() - 1) clause.Str(","); |
| 2100 | } |
| 2101 | clause.Str(")"); |
| 2102 | if (!aQuery->TagsAreNot()) { |
| 2103 | clause.Str("GROUP BY bms.fk HAVING count(*) >=").Param(":tag_count"); |
| 2104 | } |
| 2105 | clause.Str(")"); |
| 2106 | } |
| 2107 | |
| 2108 | // transitions |
| 2109 | const nsTArray<uint32_t>& transitions = aQuery->Transitions(); |
| 2110 | for (uint32_t i = 0; i < transitions.Length(); ++i) { |
| 2111 | nsPrintfCString param(":transition%d_", i); |
| 2112 | clause |
| 2113 | .Condition( |
| 2114 | "h.id IN (SELECT place_id FROM moz_historyvisits " |
| 2115 | "WHERE visit_type = ") |
| 2116 | .Param(param.get()) |
| 2117 | .Str(")"); |
| 2118 | } |
| 2119 | |
| 2120 | // parents |
| 2121 | const nsTArray<nsCString>& parents = aQuery->Parents(); |
| 2122 | if (parents.Length() > 0) { |
| 2123 | aOptions->SetQueryType(nsNavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS); |
| 2124 | clause.Condition( |
| 2125 | "b.parent IN( " |
| 2126 | "WITH RECURSIVE parents(id) AS ( " |
| 2127 | "SELECT id FROM moz_bookmarks WHERE GUID IN ("); |
| 2128 | |
| 2129 | for (uint32_t i = 0; i < parents.Length(); ++i) { |
| 2130 | nsPrintfCString param(":parentguid%d_", i); |
| 2131 | clause.Param(param.get()); |
| 2132 | if (i < parents.Length() - 1) { |
| 2133 | clause.Str(","); |
| 2134 | } |
| 2135 | } |
| 2136 | clause.Str( |
| 2137 | ") " |
| 2138 | "UNION ALL " |
| 2139 | "SELECT b2.id " |
| 2140 | "FROM moz_bookmarks b2 " |
| 2141 | "JOIN parents p ON b2.parent = p.id " |
| 2142 | "WHERE b2.type = 2 " |
| 2143 | ") " |
| 2144 | "SELECT id FROM parents " |
| 2145 | ")"); |
| 2146 | } |
| 2147 | |
| 2148 | if (excludeQueries) { |
| 2149 | // Serching by terms implicitly exclude queries and folder shortcuts. |
| 2150 | clause.Condition( |
| 2151 | "NOT h.url_hash BETWEEN hash('place', 'prefix_lo') AND " |
| 2152 | "hash('place', 'prefix_hi')"); |
| 2153 | } |
| 2154 | |
| 2155 | clause.GetClauseString(*aClause); |
| 2156 | return NS_OK; |
| 2157 | } |
| 2158 | |
| 2159 | // nsNavHistory::BindQueryClauseParameters |
| 2160 | // |
| 2161 | // THE BEHAVIOR SHOULD BE IN SYNC WITH QueryToSelectClause |
| 2162 | |
| 2163 | nsresult nsNavHistory::BindQueryClauseParameters( |
| 2164 | mozIStorageBaseStatement* statement, |
| 2165 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 2166 | const RefPtr<nsNavHistoryQueryOptions>& aOptions) { |
| 2167 | nsresult rv; |
| 2168 | |
| 2169 | bool hasIt; |
| 2170 | // begin time |
| 2171 | if (NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasBeginTime (&hasIt))), 1))) && hasIt) { |
| 2172 | PRTime time = |
| 2173 | NormalizeTime(aQuery->BeginTimeReference(), aQuery->BeginTime()); |
| 2174 | rv = statement->BindInt64ByName("begin_time"_ns, time); |
| 2175 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2175); return rv; } } while (false); |
| 2176 | } |
| 2177 | |
| 2178 | // end time |
| 2179 | if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasEndTime (&hasIt))), 1))) && hasIt) { |
| 2180 | PRTime time = NormalizeTime(aQuery->EndTimeReference(), aQuery->EndTime()); |
| 2181 | rv = statement->BindInt64ByName("end_time"_ns, time); |
| 2182 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2182); return rv; } } while (false); |
| 2183 | } |
| 2184 | |
| 2185 | // search terms |
| 2186 | if (!aQuery->SearchTerms().IsEmpty()) { |
| 2187 | rv = statement->BindStringByName("search_string"_ns, aQuery->SearchTerms()); |
| 2188 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2188); return rv; } } while (false); |
| 2189 | } |
| 2190 | |
| 2191 | // min and max visit count |
| 2192 | int32_t visits = aQuery->MinVisits(); |
| 2193 | if (visits >= 0) { |
| 2194 | rv = statement->BindInt32ByName("min_visits"_ns, visits); |
| 2195 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2195); return rv; } } while (false); |
| 2196 | } |
| 2197 | |
| 2198 | visits = aQuery->MaxVisits(); |
| 2199 | if (visits >= 0) { |
| 2200 | rv = statement->BindInt32ByName("max_visits"_ns, visits); |
| 2201 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2201); return rv; } } while (false); |
| 2202 | } |
| 2203 | |
| 2204 | // domain (see GetReversedHostname for more info on reversed host names) |
| 2205 | if (!aQuery->Domain().IsVoid()) { |
| 2206 | nsString revDomain; |
| 2207 | GetReversedHostname(NS_ConvertUTF8toUTF16(aQuery->Domain()), revDomain); |
| 2208 | |
| 2209 | if (aQuery->DomainIsHost()) { |
| 2210 | rv = statement->BindStringByName("domain_lower"_ns, revDomain); |
| 2211 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2211); return rv; } } while (false); |
| 2212 | } else { |
| 2213 | // for "mozilla.org" do query >= "gro.allizom." AND < "gro.allizom/" |
| 2214 | // which will get everything starting with "gro.allizom." while using the |
| 2215 | // index (using SUBSTRING() causes indexes to be discarded). |
| 2216 | NS_ASSERTION(revDomain[revDomain.Length() - 1] == '.',do { if (!(revDomain[revDomain.Length() - 1] == '.')) { NS_DebugBreak (NS_DEBUG_ASSERTION, "Invalid rev. host", "revDomain[revDomain.Length() - 1] == '.'" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2217); MOZ_PretendNoReturn(); } } while (0) |
| 2217 | "Invalid rev. host")do { if (!(revDomain[revDomain.Length() - 1] == '.')) { NS_DebugBreak (NS_DEBUG_ASSERTION, "Invalid rev. host", "revDomain[revDomain.Length() - 1] == '.'" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2217); MOZ_PretendNoReturn(); } } while (0); |
| 2218 | rv = statement->BindStringByName("domain_lower"_ns, revDomain); |
| 2219 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2219); return rv; } } while (false); |
| 2220 | revDomain.Truncate(revDomain.Length() - 1); |
| 2221 | revDomain.Append(char16_t('/')); |
| 2222 | rv = statement->BindStringByName("domain_upper"_ns, revDomain); |
| 2223 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2223); return rv; } } while (false); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | // URI |
| 2228 | if (aQuery->Uri()) { |
| 2229 | rv = URIBinder::Bind(statement, "uri"_ns, aQuery->Uri()); |
| 2230 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2230); return rv; } } while (false); |
| 2231 | } |
| 2232 | |
| 2233 | // tags |
| 2234 | const nsTArray<nsString>& tags = aQuery->Tags(); |
| 2235 | if (tags.Length() > 0) { |
| 2236 | for (uint32_t i = 0; i < tags.Length(); ++i) { |
| 2237 | nsPrintfCString paramName("tag%d_", i); |
| 2238 | nsString utf16Tag = tags[i]; |
| 2239 | ToLowerCase(utf16Tag); |
| 2240 | NS_ConvertUTF16toUTF8 tag(utf16Tag); |
| 2241 | rv = statement->BindUTF8StringByName(paramName, tag); |
| 2242 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2242); return rv; } } while (false); |
| 2243 | } |
| 2244 | int64_t tagsFolder = GetTagsFolder(); |
| 2245 | rv = statement->BindInt64ByName("tags_folder"_ns, tagsFolder); |
| 2246 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2246); return rv; } } while (false); |
| 2247 | if (!aQuery->TagsAreNot()) { |
| 2248 | rv = statement->BindInt32ByName("tag_count"_ns, tags.Length()); |
| 2249 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2249); return rv; } } while (false); |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | // transitions |
| 2254 | const nsTArray<uint32_t>& transitions = aQuery->Transitions(); |
| 2255 | for (uint32_t i = 0; i < transitions.Length(); ++i) { |
| 2256 | nsPrintfCString paramName("transition%d_", i); |
| 2257 | rv = statement->BindInt64ByName(paramName, transitions[i]); |
| 2258 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2258); return rv; } } while (false); |
| 2259 | } |
| 2260 | |
| 2261 | // parents |
| 2262 | const nsTArray<nsCString>& parents = aQuery->Parents(); |
| 2263 | for (uint32_t i = 0; i < parents.Length(); ++i) { |
| 2264 | nsPrintfCString paramName("parentguid%d_", i); |
| 2265 | rv = statement->BindUTF8StringByName(paramName, parents[i]); |
| 2266 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2266); return rv; } } while (false); |
| 2267 | } |
| 2268 | |
| 2269 | return NS_OK; |
| 2270 | } |
| 2271 | |
| 2272 | // nsNavHistory::ResultsAsList |
| 2273 | // |
| 2274 | |
| 2275 | nsresult nsNavHistory::ResultsAsList( |
| 2276 | mozIStorageStatement* statement, nsNavHistoryQueryOptions* aOptions, |
| 2277 | nsCOMArray<nsNavHistoryResultNode>* aResults) { |
| 2278 | nsresult rv; |
| 2279 | nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(statement, &rv); |
| 2280 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2280); return rv; } } while (false); |
| 2281 | |
| 2282 | bool hasMore = false; |
| 2283 | while (NS_SUCCEEDED(statement->ExecuteStep(&hasMore))((bool)(__builtin_expect(!!(!NS_FAILED_impl(statement->ExecuteStep (&hasMore))), 1))) && hasMore) { |
| 2284 | RefPtr<nsNavHistoryResultNode> result; |
| 2285 | rv = RowToResult(row, aOptions, getter_AddRefs(result)); |
| 2286 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2286); return rv; } } while (false); |
| 2287 | aResults->AppendElement(result.forget()); |
| 2288 | } |
| 2289 | return NS_OK; |
| 2290 | } |
| 2291 | |
| 2292 | int64_t nsNavHistory::GetTagsFolder() { |
| 2293 | // cache our tags folder |
| 2294 | // note, we can't do this in nsNavHistory::Init(), |
| 2295 | // as getting the bookmarks service would initialize it. |
| 2296 | if (mTagsFolder == -1) { |
| 2297 | nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService(); |
| 2298 | NS_ENSURE_TRUE(bookmarks, -1)do { if ((__builtin_expect(!!(!(bookmarks)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "bookmarks" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2298); return -1; } } while (false); |
| 2299 | |
| 2300 | nsresult rv = bookmarks->GetTagsFolder(&mTagsFolder); |
| 2301 | NS_ENSURE_SUCCESS(rv, -1)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "-1", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2301); return -1; } } while (false); |
| 2302 | } |
| 2303 | return mTagsFolder; |
| 2304 | } |
| 2305 | |
| 2306 | // nsNavHistory::FilterResultSet |
| 2307 | // |
| 2308 | // This does some post-query-execution filtering: |
| 2309 | // - searching on title, url and tags |
| 2310 | // - limit count |
| 2311 | // |
| 2312 | // Note: changes to filtering in FilterResultSet() |
| 2313 | // may require changes to NeedToFilterResultSet() |
| 2314 | |
| 2315 | // static |
| 2316 | nsresult nsNavHistory::FilterResultSet( |
| 2317 | nsNavHistoryQueryResultNode* aQueryNode, |
| 2318 | const nsCOMArray<nsNavHistoryResultNode>& aSet, |
| 2319 | nsCOMArray<nsNavHistoryResultNode>* aFiltered, |
| 2320 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 2321 | nsNavHistoryQueryOptions* aOptions) { |
| 2322 | // parse the search terms |
| 2323 | nsTArray<nsString> terms; |
| 2324 | ParseSearchTermsFromQuery(aQuery, &terms); |
| 2325 | |
| 2326 | bool excludeQueries = aOptions->ExcludeQueries(); |
| 2327 | for (int32_t nodeIndex = 0; nodeIndex < aSet.Count(); nodeIndex++) { |
| 2328 | if (excludeQueries && aSet[nodeIndex]->IsQuery()) { |
| 2329 | continue; |
| 2330 | } |
| 2331 | |
| 2332 | if (aSet[nodeIndex]->mItemId != -1 && aQueryNode && |
| 2333 | aQueryNode->mItemId == aSet[nodeIndex]->mItemId) { |
| 2334 | continue; |
| 2335 | } |
| 2336 | |
| 2337 | // If there are search terms, we are already getting only uri nodes, |
| 2338 | // thus we don't need to filter node types. Though, we must check for |
| 2339 | // matching terms. |
| 2340 | if (terms.Length()) { |
| 2341 | // Filter based on search terms. |
| 2342 | // Convert title and url for the current node to UTF16 strings. |
| 2343 | NS_ConvertUTF8toUTF16 nodeTitle(aSet[nodeIndex]->mTitle); |
| 2344 | // Unescape the URL for search terms matching. |
| 2345 | nsAutoCString cNodeURL(aSet[nodeIndex]->mURI); |
| 2346 | NS_ConvertUTF8toUTF16 nodeURL(NS_UnescapeURL(cNodeURL)); |
| 2347 | |
| 2348 | // Determine if every search term matches anywhere in the title, url or |
| 2349 | // tag. |
| 2350 | bool matchAllTerms = true; |
| 2351 | for (int32_t termIndex = terms.Length() - 1; |
| 2352 | termIndex >= 0 && matchAllTerms; termIndex--) { |
| 2353 | nsString& term = terms.ElementAt(termIndex); |
| 2354 | // True if any of them match; false makes us quit the loop |
| 2355 | matchAllTerms = |
| 2356 | CaseInsensitiveFindInReadable(term, nodeTitle) || |
| 2357 | CaseInsensitiveFindInReadable(term, nodeURL) || |
| 2358 | CaseInsensitiveFindInReadable(term, aSet[nodeIndex]->mTags); |
| 2359 | } |
| 2360 | // Skip the node if we don't match all terms in the title, url or tag |
| 2361 | if (!matchAllTerms) { |
| 2362 | continue; |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | aFiltered->AppendObject(aSet[nodeIndex]); |
| 2367 | |
| 2368 | // Stop once we have reached max results. |
| 2369 | if (aOptions->MaxResults() > 0 && |
| 2370 | (uint32_t)aFiltered->Count() >= aOptions->MaxResults()) |
| 2371 | break; |
| 2372 | } |
| 2373 | |
| 2374 | return NS_OK; |
| 2375 | } |
| 2376 | |
| 2377 | NS_IMETHODIMPnsresult |
| 2378 | nsNavHistory::MakeGuid(nsACString& aGuid) { |
| 2379 | if (NS_FAILED(GenerateGUID(aGuid))((bool)(__builtin_expect(!!(NS_FAILED_impl(GenerateGUID(aGuid ))), 0)))) { |
| 2380 | MOZ_ASSERT(false, "Shouldn't fail to create a guid!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Shouldn't fail to create a guid!" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2380); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Shouldn't fail to create a guid!" ")"); do { MOZ_CrashSequence (__null, 2380); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2381 | aGuid.SetIsVoid(true); |
| 2382 | } |
| 2383 | return NS_OK; |
| 2384 | } |
| 2385 | |
| 2386 | NS_IMETHODIMPnsresult |
| 2387 | nsNavHistory::HashURL(const nsACString& aSpec, const nsACString& aMode, |
| 2388 | uint64_t* _hash) { |
| 2389 | return places::HashURL(aSpec, aMode, _hash); |
| 2390 | } |
| 2391 | |
| 2392 | // nsNavHistory::CheckIsRecentEvent |
| 2393 | // |
| 2394 | // Sees if this URL happened "recently." |
| 2395 | // |
| 2396 | // It is always removed from our recent list no matter what. It only counts |
| 2397 | // as "recent" if the event happened more recently than our event |
| 2398 | // threshold ago. |
| 2399 | |
| 2400 | bool nsNavHistory::CheckIsRecentEvent(RecentEventHash* hashTable, |
| 2401 | const nsACString& url) { |
| 2402 | PRTime eventTime; |
| 2403 | if (hashTable->Get(url, reinterpret_cast<int64_t*>(&eventTime))) { |
| 2404 | hashTable->Remove(url); |
| 2405 | if (eventTime > GetNow() - RECENT_EVENT_THRESHOLDPRTime((int64_t)15 * 60 * 1000000L)) return true; |
| 2406 | return false; |
| 2407 | } |
| 2408 | return false; |
| 2409 | } |
| 2410 | |
| 2411 | // nsNavHistory::ExpireNonrecentEvents |
| 2412 | // |
| 2413 | // This goes through our |
| 2414 | |
| 2415 | void nsNavHistory::ExpireNonrecentEvents(RecentEventHash* hashTable) { |
| 2416 | int64_t threshold = GetNow() - RECENT_EVENT_THRESHOLDPRTime((int64_t)15 * 60 * 1000000L); |
| 2417 | for (auto iter = hashTable->Iter(); !iter.Done(); iter.Next()) { |
| 2418 | if (iter.Data() < threshold) { |
| 2419 | iter.Remove(); |
| 2420 | } |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | // nsNavHistory::RowToResult |
| 2425 | // |
| 2426 | // Here, we just have a generic row. It could be a query, URL, visit, |
| 2427 | // or full visit. |
| 2428 | |
| 2429 | nsresult nsNavHistory::RowToResult(mozIStorageValueArray* aRow, |
| 2430 | nsNavHistoryQueryOptions* aOptions, |
| 2431 | nsNavHistoryResultNode** aResult) { |
| 2432 | NS_ASSERTION(aRow && aOptions && aResult, "Null pointer in RowToResult")do { if (!(aRow && aOptions && aResult)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "Null pointer in RowToResult", "aRow && aOptions && aResult" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2432); MOZ_PretendNoReturn(); } } while (0); |
| 2433 | |
| 2434 | // URL |
| 2435 | nsAutoCString url; |
| 2436 | nsresult rv = aRow->GetUTF8String(kGetInfoIndex_URL, url); |
| 2437 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2437); return rv; } } while (false); |
| 2438 | // In case of data corruption URL may be null, but our UI code prefers an |
| 2439 | // empty string. |
| 2440 | if (url.IsVoid()) { |
| 2441 | MOZ_ASSERT(false, "Found a NULL url in moz_places")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "Found a NULL url in moz_places" ")", "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2441); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "Found a NULL url in moz_places" ")"); do { MOZ_CrashSequence (__null, 2441); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); |
| 2442 | url.SetIsVoid(false); |
| 2443 | } |
| 2444 | |
| 2445 | // title |
| 2446 | nsAutoCString title; |
| 2447 | bool isNull; |
| 2448 | rv = aRow->GetIsNull(kGetInfoIndex_Title, &isNull); |
| 2449 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2449); return rv; } } while (false); |
| 2450 | if (!isNull) { |
| 2451 | rv = aRow->GetUTF8String(kGetInfoIndex_Title, title); |
| 2452 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2452); return rv; } } while (false); |
| 2453 | } |
| 2454 | |
| 2455 | uint32_t accessCount = aRow->AsInt32(kGetInfoIndex_VisitCount); |
| 2456 | PRTime time = aRow->AsInt64(kGetInfoIndex_VisitDate); |
| 2457 | |
| 2458 | // itemId |
| 2459 | int64_t itemId = aRow->AsInt64(kGetInfoIndex_ItemId); |
| 2460 | if (itemId == 0) { |
| 2461 | // This is not a bookmark. For non-bookmarks we use a -1 itemId value. |
| 2462 | // Notice ids in sqlite tables start from 1, so itemId cannot ever be 0. |
| 2463 | itemId = -1; |
| 2464 | } |
| 2465 | |
| 2466 | if (IsQueryURI(url)) { |
| 2467 | // Special case "place:" URIs: turn them into containers. |
| 2468 | nsAutoCString guid; |
| 2469 | if (itemId != -1) { |
| 2470 | rv = aRow->GetUTF8String(nsNavBookmarks::kGetChildrenIndex_Guid, guid); |
| 2471 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2471); return rv; } } while (false); |
| 2472 | } |
| 2473 | |
| 2474 | if (aOptions->ResultType() == |
| 2475 | nsNavHistoryQueryOptions::RESULTS_AS_ROOTS_QUERY || |
| 2476 | aOptions->ResultType() == |
| 2477 | nsNavHistoryQueryOptions::RESULTS_AS_LEFT_PANE_QUERY) { |
| 2478 | rv = aRow->GetUTF8String(kGetInfoIndex_Guid, guid); |
| 2479 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2479); return rv; } } while (false); |
| 2480 | } |
| 2481 | |
| 2482 | int64_t targetFolderItemId = -1; |
| 2483 | nsAutoCString targetFolderGuid; |
| 2484 | nsAutoCString targetFolderTitle; |
| 2485 | rv = aRow->GetIsNull(kGetTargetFolder_Guid, &isNull); |
| 2486 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2486); return rv; } } while (false); |
| 2487 | if (!isNull) { |
| 2488 | targetFolderItemId = aRow->AsInt64(kGetTargetFolder_ItemId); |
| 2489 | rv = aRow->GetUTF8String(kGetTargetFolder_Guid, targetFolderGuid); |
| 2490 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2490); return rv; } } while (false); |
| 2491 | rv = aRow->GetUTF8String(kGetTargetFolder_Title, targetFolderTitle); |
| 2492 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2492); return rv; } } while (false); |
| 2493 | } |
| 2494 | |
| 2495 | RefPtr<nsNavHistoryResultNode> resultNode; |
| 2496 | rv = QueryUriToResult(url, itemId, guid, title, targetFolderItemId, |
| 2497 | targetFolderGuid, targetFolderTitle, accessCount, |
| 2498 | time, getter_AddRefs(resultNode)); |
| 2499 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2499); return rv; } } while (false); |
| 2500 | |
| 2501 | if (itemId != -1 || aOptions->ResultType() == |
| 2502 | nsNavHistoryQueryOptions::RESULTS_AS_TAGS_ROOT) { |
| 2503 | // RESULTS_AS_TAGS_ROOT has date columns |
| 2504 | resultNode->mDateAdded = aRow->AsInt64(kGetInfoIndex_ItemDateAdded); |
| 2505 | resultNode->mLastModified = aRow->AsInt64(kGetInfoIndex_ItemLastModified); |
| 2506 | if (resultNode->IsFolderOrShortcut()) { |
| 2507 | // If it's a simple folder node (i.e. a shortcut to another folder), |
| 2508 | // apply our options for it. However, if the parent type was tag query, |
| 2509 | // we do not apply them, because it would not yield any results. |
| 2510 | resultNode->GetAsContainer()->mOptions = aOptions; |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | resultNode.forget(aResult); |
| 2515 | return rv; |
| 2516 | } else if (aOptions->ResultType() == |
| 2517 | nsNavHistoryQueryOptions::RESULTS_AS_URI) { |
| 2518 | RefPtr<nsNavHistoryResultNode> resultNode = |
| 2519 | new nsNavHistoryResultNode(url, title, accessCount, time); |
| 2520 | |
| 2521 | if (itemId != -1) { |
| 2522 | resultNode->mItemId = itemId; |
| 2523 | resultNode->mDateAdded = aRow->AsInt64(kGetInfoIndex_ItemDateAdded); |
| 2524 | resultNode->mLastModified = aRow->AsInt64(kGetInfoIndex_ItemLastModified); |
| 2525 | |
| 2526 | rv = aRow->GetUTF8String(nsNavBookmarks::kGetChildrenIndex_Guid, |
| 2527 | resultNode->mBookmarkGuid); |
| 2528 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2528); return rv; } } while (false); |
| 2529 | } |
| 2530 | |
| 2531 | resultNode->mFrecency = aRow->AsInt32(kGetInfoIndex_Frecency); |
| 2532 | resultNode->mHidden = !!aRow->AsInt32(kGetInfoIndex_Hidden); |
| 2533 | |
| 2534 | nsAutoString tags; |
| 2535 | rv = aRow->GetString(kGetInfoIndex_ItemTags, tags); |
| 2536 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2536); return rv; } } while (false); |
| 2537 | resultNode->SetTags(tags); |
| 2538 | |
| 2539 | rv = aRow->GetUTF8String(kGetInfoIndex_Guid, resultNode->mPageGuid); |
| 2540 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2540); return rv; } } while (false); |
| 2541 | |
| 2542 | resultNode.forget(aResult); |
| 2543 | return NS_OK; |
| 2544 | } |
| 2545 | |
| 2546 | if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_VISIT) { |
| 2547 | RefPtr<nsNavHistoryResultNode> resultNode = |
| 2548 | new nsNavHistoryResultNode(url, title, accessCount, time); |
| 2549 | |
| 2550 | nsAutoString tags; |
| 2551 | rv = aRow->GetString(kGetInfoIndex_ItemTags, tags); |
Value stored to 'rv' is never read | |
| 2552 | resultNode->SetTags(tags); |
| 2553 | rv = aRow->GetUTF8String(kGetInfoIndex_Guid, resultNode->mPageGuid); |
| 2554 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2554); return rv; } } while (false); |
| 2555 | |
| 2556 | rv = aRow->GetInt64(kGetInfoIndex_VisitId, &resultNode->mVisitId); |
| 2557 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2557); return rv; } } while (false); |
| 2558 | |
| 2559 | resultNode->mTransitionType = aRow->AsInt32(kGetInfoIndex_VisitType); |
| 2560 | |
| 2561 | resultNode.forget(aResult); |
| 2562 | return NS_OK; |
| 2563 | } |
| 2564 | |
| 2565 | return NS_ERROR_FAILURE; |
| 2566 | } |
| 2567 | |
| 2568 | // When the URI is a place: URI, generate the proper folder or query node. |
| 2569 | nsresult nsNavHistory::QueryUriToResult( |
| 2570 | const nsACString& aQueryURI, int64_t aItemId, |
| 2571 | const nsACString& aBookmarkGuid, const nsACString& aTitle, |
| 2572 | int64_t aTargetFolderItemId, const nsACString& aTargetFolderGuid, |
| 2573 | const nsACString& aTargetFolderTitle, uint32_t aAccessCount, PRTime aTime, |
| 2574 | nsNavHistoryResultNode** aNode) { |
| 2575 | // Only assert if the aItemId is set. In some cases (e.g. virtual queries), we |
| 2576 | // have a guid, but not an aItemId. |
| 2577 | if (aItemId != -1) { |
| 2578 | MOZ_ASSERT(!aBookmarkGuid.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aBookmarkGuid.IsEmpty())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aBookmarkGuid.IsEmpty()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!aBookmarkGuid.IsEmpty()" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2578); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aBookmarkGuid.IsEmpty()" ")"); do { MOZ_CrashSequence(__null, 2578); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2579 | } |
| 2580 | |
| 2581 | nsCOMPtr<nsINavHistoryQuery> query; |
| 2582 | nsCOMPtr<nsINavHistoryQueryOptions> options; |
| 2583 | nsresult rv = QueryStringToQuery(aQueryURI, getter_AddRefs(query), |
| 2584 | getter_AddRefs(options)); |
| 2585 | RefPtr<nsNavHistoryResultNode> resultNode; |
| 2586 | RefPtr<nsNavHistoryQuery> queryObj = do_QueryObject(query); |
| 2587 | NS_ENSURE_STATE(queryObj)do { if ((__builtin_expect(!!(!(queryObj)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "queryObj" ") failed", nullptr , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2587); return NS_ERROR_UNEXPECTED; } } while (false); |
| 2588 | RefPtr<nsNavHistoryQueryOptions> optionsObj = do_QueryObject(options); |
| 2589 | NS_ENSURE_STATE(optionsObj)do { if ((__builtin_expect(!!(!(optionsObj)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "optionsObj" ") failed", nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2589); return NS_ERROR_UNEXPECTED; } } while (false); |
| 2590 | // If this failed the query does not parse correctly, let the error pass and |
| 2591 | // handle it later. |
| 2592 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 2593 | if (!aTargetFolderGuid.IsEmpty()) { |
| 2594 | MOZ_ASSERT(aTargetFolderItemId >= 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aTargetFolderItemId >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aTargetFolderItemId >= 0) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aTargetFolderItemId >= 0" , "./../../../../toolkit/components/places/nsNavHistory.cpp", 2594); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aTargetFolderItemId >= 0" ")"); do { MOZ_CrashSequence(__null, 2594); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 2595 | resultNode = new nsNavHistoryFolderResultNode( |
| 2596 | aItemId, aBookmarkGuid, aTargetFolderItemId, aTargetFolderGuid, |
| 2597 | !aTitle.IsEmpty() ? aTitle : aTargetFolderTitle, optionsObj); |
| 2598 | } else { |
| 2599 | // This is a regular query. |
| 2600 | resultNode = new nsNavHistoryQueryResultNode(aTitle, aTime, aQueryURI, |
| 2601 | queryObj, optionsObj); |
| 2602 | resultNode->mItemId = aItemId; |
| 2603 | resultNode->mBookmarkGuid = aBookmarkGuid; |
| 2604 | } |
| 2605 | } |
| 2606 | |
| 2607 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2608 | NS_WARNING("Generating a generic empty node for a broken query!")NS_DebugBreak(NS_DEBUG_WARNING, "Generating a generic empty node for a broken query!" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2608); |
| 2609 | // This is a broken query, that either did not parse or points to not |
| 2610 | // existing data. We don't want to return failure since that will kill the |
| 2611 | // whole result. Instead make a generic empty query node. |
| 2612 | resultNode = new nsNavHistoryQueryResultNode(aTitle, 0, aQueryURI, queryObj, |
| 2613 | optionsObj); |
| 2614 | resultNode->mItemId = aItemId; |
| 2615 | resultNode->mBookmarkGuid = aBookmarkGuid; |
| 2616 | // This is a perf hack to generate an empty query that skips filtering. |
| 2617 | resultNode->GetAsQuery()->Options()->SetExcludeItems(true); |
| 2618 | } |
| 2619 | |
| 2620 | resultNode.forget(aNode); |
| 2621 | return NS_OK; |
| 2622 | } |
| 2623 | |
| 2624 | void nsNavHistory::GetAgeInDaysString(int32_t aInt, const char* aName, |
| 2625 | nsACString& aResult) { |
| 2626 | nsIStringBundle* bundle = GetBundle(); |
| 2627 | if (bundle) { |
| 2628 | AutoTArray<nsString, 1> strings; |
| 2629 | strings.AppendElement()->AppendInt(aInt); |
| 2630 | nsAutoString value; |
| 2631 | nsresult rv = bundle->FormatStringFromName(aName, strings, value); |
| 2632 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 2633 | CopyUTF16toUTF8(value, aResult); |
| 2634 | return; |
| 2635 | } |
| 2636 | } |
| 2637 | aResult.Assign(aName); |
| 2638 | } |
| 2639 | |
| 2640 | void nsNavHistory::GetStringFromName(const char* aName, nsACString& aResult) { |
| 2641 | nsIStringBundle* bundle = GetBundle(); |
| 2642 | if (bundle) { |
| 2643 | nsAutoString value; |
| 2644 | nsresult rv = bundle->GetStringFromName(aName, value); |
| 2645 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) { |
| 2646 | CopyUTF16toUTF8(value, aResult); |
| 2647 | return; |
| 2648 | } |
| 2649 | } |
| 2650 | aResult.Assign(aName); |
| 2651 | } |
| 2652 | |
| 2653 | // static |
| 2654 | void nsNavHistory::GetMonthName(const PRExplodedTime& aTime, |
| 2655 | nsACString& aResult) { |
| 2656 | nsAutoString month; |
| 2657 | |
| 2658 | mozilla::intl::DateTimeFormat::ComponentsBag components; |
| 2659 | components.month = Some(mozilla::intl::DateTimeFormat::Month::Long); |
| 2660 | nsresult rv = |
| 2661 | mozilla::intl::AppDateTimeFormat::Format(components, &aTime, month); |
| 2662 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2663 | aResult = nsPrintfCString("[%d]", aTime.tm_month + 1); |
| 2664 | return; |
| 2665 | } |
| 2666 | CopyUTF16toUTF8(month, aResult); |
| 2667 | } |
| 2668 | |
| 2669 | // static |
| 2670 | void nsNavHistory::GetMonthYear(const PRExplodedTime& aTime, |
| 2671 | nsACString& aResult) { |
| 2672 | nsAutoString monthYear; |
| 2673 | mozilla::intl::DateTimeFormat::ComponentsBag components; |
| 2674 | components.month = Some(mozilla::intl::DateTimeFormat::Month::Long); |
| 2675 | components.year = Some(mozilla::intl::DateTimeFormat::Numeric::Numeric); |
| 2676 | nsresult rv = |
| 2677 | mozilla::intl::AppDateTimeFormat::Format(components, &aTime, monthYear); |
| 2678 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 2679 | aResult = nsPrintfCString("[%d-%d]", aTime.tm_month + 1, aTime.tm_year); |
| 2680 | return; |
| 2681 | } |
| 2682 | CopyUTF16toUTF8(monthYear, aResult); |
| 2683 | } |
| 2684 | |
| 2685 | namespace { |
| 2686 | |
| 2687 | // GetSimpleBookmarksQueryParent |
| 2688 | // |
| 2689 | // Determines if this is a simple bookmarks query for a |
| 2690 | // folder with no other constraints. In these common cases, we can more |
| 2691 | // efficiently compute the results. |
| 2692 | // |
| 2693 | // A simple bookmarks query will result in a hierarchical tree of |
| 2694 | // bookmark items, folders and separators. |
| 2695 | // |
| 2696 | // Returns the folder ID as Maybe<nsCString> if it is a simple folder |
| 2697 | // query, Nothing() if not. |
| 2698 | static Maybe<nsCString> GetSimpleBookmarksQueryParent( |
| 2699 | const RefPtr<nsNavHistoryQuery>& aQuery, |
| 2700 | const RefPtr<nsNavHistoryQueryOptions>& aOptions) { |
| 2701 | if (aQuery->Parents().Length() != 1) return Nothing(); |
| 2702 | |
| 2703 | bool hasIt; |
| 2704 | if ((NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasBeginTime (&hasIt))), 1))) && hasIt) || |
| 2705 | (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aQuery->GetHasEndTime (&hasIt))), 1))) && hasIt) || |
| 2706 | !aQuery->Domain().IsVoid() || aQuery->Uri() || |
| 2707 | !aQuery->SearchTerms().IsEmpty() || aQuery->Tags().Length() > 0 || |
| 2708 | aOptions->MaxResults() > 0 || !IsValidGUID(aQuery->Parents()[0])) { |
| 2709 | return Nothing(); |
| 2710 | } |
| 2711 | |
| 2712 | return Some(aQuery->Parents()[0]); |
| 2713 | } |
| 2714 | |
| 2715 | // ParseSearchTermsFromQuery |
| 2716 | // |
| 2717 | // Construct an array of search terms from the given query. |
| 2718 | // Within a query, all the terms are ANDed together. |
| 2719 | // |
| 2720 | // This just breaks the query up into words. We don't do anything fancy, |
| 2721 | // not even quoting. We do, however, strip quotes, because people might |
| 2722 | // try to input quotes expecting them to do something and get no results |
| 2723 | // back. |
| 2724 | |
| 2725 | inline bool isQueryWhitespace(char16_t ch) { return ch == ' '; } |
| 2726 | |
| 2727 | void ParseSearchTermsFromQuery(const RefPtr<nsNavHistoryQuery>& aQuery, |
| 2728 | nsTArray<nsString>* aTerms) { |
| 2729 | int32_t lastBegin = -1; |
| 2730 | if (!aQuery->SearchTerms().IsEmpty()) { |
| 2731 | const nsString& searchTerms = aQuery->SearchTerms(); |
| 2732 | for (uint32_t j = 0; j < searchTerms.Length(); j++) { |
| 2733 | if (isQueryWhitespace(searchTerms[j]) || searchTerms[j] == '"') { |
| 2734 | if (lastBegin >= 0) { |
| 2735 | // found the end of a word |
| 2736 | aTerms->AppendElement( |
| 2737 | Substring(searchTerms, lastBegin, j - lastBegin)); |
| 2738 | lastBegin = -1; |
| 2739 | } |
| 2740 | } else { |
| 2741 | if (lastBegin < 0) { |
| 2742 | // found the beginning of a word |
| 2743 | lastBegin = j; |
| 2744 | } |
| 2745 | } |
| 2746 | } |
| 2747 | // last word |
| 2748 | if (lastBegin >= 0) |
| 2749 | aTerms->AppendElement(Substring(searchTerms, lastBegin)); |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | } // namespace |
| 2754 | |
| 2755 | nsIStringBundle* nsNavHistory::GetBundle() { |
| 2756 | if (!mBundle) { |
| 2757 | nsCOMPtr<nsIStringBundleService> bundleService = |
| 2758 | components::StringBundle::Service(); |
| 2759 | NS_ENSURE_TRUE(bundleService, nullptr)do { if ((__builtin_expect(!!(!(bundleService)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "bundleService" ") failed" , nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2759); return nullptr; } } while (false); |
| 2760 | nsresult rv = bundleService->CreateBundle( |
| 2761 | "chrome://places/locale/places.properties", getter_AddRefs(mBundle)); |
| 2762 | NS_ENSURE_SUCCESS(rv, nullptr)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "nullptr", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../toolkit/components/places/nsNavHistory.cpp" , 2762); return nullptr; } } while (false); |
| 2763 | } |
| 2764 | return mBundle; |
| 2765 | } |