toolkit/components/places/SQLFunctions.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_places_SQLFunctions_h_
michael@0 7 #define mozilla_places_SQLFunctions_h_
michael@0 8
michael@0 9 /**
michael@0 10 * This file contains functions that Places adds to the database handle that can
michael@0 11 * be accessed by SQL queries.
michael@0 12 *
michael@0 13 * Keep the GUID-related parts of this file in sync with
michael@0 14 * toolkit/downloads/SQLFunctions.[h|cpp]!
michael@0 15 */
michael@0 16
michael@0 17 #include "mozIStorageFunction.h"
michael@0 18 #include "mozilla/Attributes.h"
michael@0 19
michael@0 20 class mozIStorageConnection;
michael@0 21
michael@0 22 namespace mozilla {
michael@0 23 namespace places {
michael@0 24
michael@0 25 ////////////////////////////////////////////////////////////////////////////////
michael@0 26 //// AutoComplete Matching Function
michael@0 27
michael@0 28 /**
michael@0 29 * This function is used to determine if a given set of data should match an
michael@0 30 * AutoComplete query.
michael@0 31 *
michael@0 32 * In SQL, you'd use it in the WHERE clause like so:
michael@0 33 * WHERE AUTOCOMPLETE_MATCH(aSearchString, aURL, aTitle, aTags, aVisitCount,
michael@0 34 * aTyped, aBookmark, aOpenPageCount, aMatchBehavior,
michael@0 35 * aSearchBehavior)
michael@0 36 *
michael@0 37 * @param aSearchString
michael@0 38 * The string to compare against.
michael@0 39 * @param aURL
michael@0 40 * The URL to test for an AutoComplete match.
michael@0 41 * @param aTitle
michael@0 42 * The title to test for an AutoComplete match.
michael@0 43 * @param aTags
michael@0 44 * The tags to test for an AutoComplete match.
michael@0 45 * @param aVisitCount
michael@0 46 * The number of visits aURL has.
michael@0 47 * @param aTyped
michael@0 48 * Indicates if aURL is a typed URL or not. Treated as a boolean.
michael@0 49 * @param aBookmark
michael@0 50 * Indicates if aURL is a bookmark or not. Treated as a boolean.
michael@0 51 * @param aOpenPageCount
michael@0 52 * The number of times aURL has been registered as being open. (See
michael@0 53 * mozIPlacesAutoComplete::registerOpenPage.)
michael@0 54 * @param aMatchBehavior
michael@0 55 * The match behavior to use for this search.
michael@0 56 * @param aSearchBehavior
michael@0 57 * A bitfield dictating the search behavior.
michael@0 58 */
michael@0 59 class MatchAutoCompleteFunction MOZ_FINAL : public mozIStorageFunction
michael@0 60 {
michael@0 61 public:
michael@0 62 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 63 NS_DECL_MOZISTORAGEFUNCTION
michael@0 64
michael@0 65 /**
michael@0 66 * Registers the function with the specified database connection.
michael@0 67 *
michael@0 68 * @param aDBConn
michael@0 69 * The database connection to register with.
michael@0 70 */
michael@0 71 static nsresult create(mozIStorageConnection *aDBConn);
michael@0 72
michael@0 73 private:
michael@0 74 /**
michael@0 75 * Argument Indexes
michael@0 76 */
michael@0 77 static const uint32_t kArgSearchString = 0;
michael@0 78 static const uint32_t kArgIndexURL = 1;
michael@0 79 static const uint32_t kArgIndexTitle = 2;
michael@0 80 static const uint32_t kArgIndexTags = 3;
michael@0 81 static const uint32_t kArgIndexVisitCount = 4;
michael@0 82 static const uint32_t kArgIndexTyped = 5;
michael@0 83 static const uint32_t kArgIndexBookmark = 6;
michael@0 84 static const uint32_t kArgIndexOpenPageCount = 7;
michael@0 85 static const uint32_t kArgIndexMatchBehavior = 8;
michael@0 86 static const uint32_t kArgIndexSearchBehavior = 9;
michael@0 87 static const uint32_t kArgIndexLength = 10;
michael@0 88
michael@0 89 /**
michael@0 90 * Typedefs
michael@0 91 */
michael@0 92 typedef bool (*searchFunctionPtr)(const nsDependentCSubstring &aToken,
michael@0 93 const nsACString &aSourceString);
michael@0 94
michael@0 95 typedef nsACString::const_char_iterator const_char_iterator;
michael@0 96
michael@0 97 /**
michael@0 98 * Obtains the search function to match on.
michael@0 99 *
michael@0 100 * @param aBehavior
michael@0 101 * The matching behavior to use defined by one of the
michael@0 102 * mozIPlacesAutoComplete::MATCH_* values.
michael@0 103 * @return a pointer to the function that will perform the proper search.
michael@0 104 */
michael@0 105 static searchFunctionPtr getSearchFunction(int32_t aBehavior);
michael@0 106
michael@0 107 /**
michael@0 108 * Tests if aSourceString starts with aToken.
michael@0 109 *
michael@0 110 * @param aToken
michael@0 111 * The string to search for.
michael@0 112 * @param aSourceString
michael@0 113 * The string to search.
michael@0 114 * @return true if found, false otherwise.
michael@0 115 */
michael@0 116 static bool findBeginning(const nsDependentCSubstring &aToken,
michael@0 117 const nsACString &aSourceString);
michael@0 118
michael@0 119 /**
michael@0 120 * Tests if aSourceString starts with aToken in a case sensitive way.
michael@0 121 *
michael@0 122 * @param aToken
michael@0 123 * The string to search for.
michael@0 124 * @param aSourceString
michael@0 125 * The string to search.
michael@0 126 * @return true if found, false otherwise.
michael@0 127 */
michael@0 128 static bool findBeginningCaseSensitive(const nsDependentCSubstring &aToken,
michael@0 129 const nsACString &aSourceString);
michael@0 130
michael@0 131 /**
michael@0 132 * Searches aSourceString for aToken anywhere in the string in a case-
michael@0 133 * insensitive way.
michael@0 134 *
michael@0 135 * @param aToken
michael@0 136 * The string to search for.
michael@0 137 * @param aSourceString
michael@0 138 * The string to search.
michael@0 139 * @return true if found, false otherwise.
michael@0 140 */
michael@0 141 static bool findAnywhere(const nsDependentCSubstring &aToken,
michael@0 142 const nsACString &aSourceString);
michael@0 143
michael@0 144 /**
michael@0 145 * Tests if aToken is found on a word boundary in aSourceString.
michael@0 146 *
michael@0 147 * @param aToken
michael@0 148 * The string to search for.
michael@0 149 * @param aSourceString
michael@0 150 * The string to search.
michael@0 151 * @return true if found, false otherwise.
michael@0 152 */
michael@0 153 static bool findOnBoundary(const nsDependentCSubstring &aToken,
michael@0 154 const nsACString &aSourceString);
michael@0 155
michael@0 156
michael@0 157 /**
michael@0 158 * Fixes a URI's spec such that it is ready to be searched. This includes
michael@0 159 * unescaping escaped characters and removing certain specs that we do not
michael@0 160 * care to search for.
michael@0 161 *
michael@0 162 * @param aURISpec
michael@0 163 * The spec of the URI to prepare for searching.
michael@0 164 * @param aMatchBehavior
michael@0 165 * The matching behavior to use defined by one of the
michael@0 166 * mozIPlacesAutoComplete::MATCH_* values.
michael@0 167 * @param _fixedSpec
michael@0 168 * An out parameter that is the fixed up string.
michael@0 169 */
michael@0 170 static void fixupURISpec(const nsCString &aURISpec, int32_t aMatchBehavior,
michael@0 171 nsCString &_fixedSpec);
michael@0 172 };
michael@0 173
michael@0 174
michael@0 175
michael@0 176 ////////////////////////////////////////////////////////////////////////////////
michael@0 177 //// Frecency Calculation Function
michael@0 178
michael@0 179 /**
michael@0 180 * This function is used to calculate frecency for a page.
michael@0 181 *
michael@0 182 * In SQL, you'd use it in when setting frecency like:
michael@0 183 * SET frecency = CALCULATE_FRECENCY(place_id).
michael@0 184 * Optional parameters must be passed in if the page is not yet in the database,
michael@0 185 * otherwise they will be fetched from it automatically.
michael@0 186 *
michael@0 187 * @param pageId
michael@0 188 * The id of the page. Pass -1 if the page is being added right now.
michael@0 189 * @param [optional] typed
michael@0 190 * Whether the page has been typed in. Default is false.
michael@0 191 * @param [optional] fullVisitCount
michael@0 192 * Count of all the visits (All types). Default is 0.
michael@0 193 * @param [optional] isBookmarked
michael@0 194 * Whether the page is bookmarked. Default is false.
michael@0 195 */
michael@0 196 class CalculateFrecencyFunction MOZ_FINAL : public mozIStorageFunction
michael@0 197 {
michael@0 198 public:
michael@0 199 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 200 NS_DECL_MOZISTORAGEFUNCTION
michael@0 201
michael@0 202 /**
michael@0 203 * Registers the function with the specified database connection.
michael@0 204 *
michael@0 205 * @param aDBConn
michael@0 206 * The database connection to register with.
michael@0 207 */
michael@0 208 static nsresult create(mozIStorageConnection *aDBConn);
michael@0 209 };
michael@0 210
michael@0 211 /**
michael@0 212 * SQL function to generate a GUID for a place or bookmark item. This is just
michael@0 213 * a wrapper around GenerateGUID in Helpers.h.
michael@0 214 *
michael@0 215 * @return a guid for the item.
michael@0 216 */
michael@0 217 class GenerateGUIDFunction MOZ_FINAL : public mozIStorageFunction
michael@0 218 {
michael@0 219 public:
michael@0 220 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 221 NS_DECL_MOZISTORAGEFUNCTION
michael@0 222
michael@0 223 /**
michael@0 224 * Registers the function with the specified database connection.
michael@0 225 *
michael@0 226 * @param aDBConn
michael@0 227 * The database connection to register with.
michael@0 228 */
michael@0 229 static nsresult create(mozIStorageConnection *aDBConn);
michael@0 230 };
michael@0 231
michael@0 232 /**
michael@0 233 * SQL function to unreverse the rev_host of a page.
michael@0 234 *
michael@0 235 * @param rev_host
michael@0 236 * The rev_host value of the page.
michael@0 237 *
michael@0 238 * @return the unreversed host of the page.
michael@0 239 */
michael@0 240 class GetUnreversedHostFunction MOZ_FINAL : public mozIStorageFunction
michael@0 241 {
michael@0 242 public:
michael@0 243 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 244 NS_DECL_MOZISTORAGEFUNCTION
michael@0 245
michael@0 246 /**
michael@0 247 * Registers the function with the specified database connection.
michael@0 248 *
michael@0 249 * @param aDBConn
michael@0 250 * The database connection to register with.
michael@0 251 */
michael@0 252 static nsresult create(mozIStorageConnection *aDBConn);
michael@0 253 };
michael@0 254
michael@0 255
michael@0 256 ////////////////////////////////////////////////////////////////////////////////
michael@0 257 //// Fixup URL Function
michael@0 258
michael@0 259 /**
michael@0 260 * Make a given URL more suitable for searches, by removing common prefixes
michael@0 261 * such as "www."
michael@0 262 *
michael@0 263 * @param url
michael@0 264 * A URL.
michael@0 265 * @return
michael@0 266 * The same URL, with redundant parts removed.
michael@0 267 */
michael@0 268 class FixupURLFunction MOZ_FINAL : public mozIStorageFunction
michael@0 269 {
michael@0 270 public:
michael@0 271 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 272 NS_DECL_MOZISTORAGEFUNCTION
michael@0 273
michael@0 274 /**
michael@0 275 * Registers the function with the specified database connection.
michael@0 276 *
michael@0 277 * @param aDBConn
michael@0 278 * The database connection to register with.
michael@0 279 */
michael@0 280 static nsresult create(mozIStorageConnection *aDBConn);
michael@0 281 };
michael@0 282
michael@0 283
michael@0 284 ////////////////////////////////////////////////////////////////////////////////
michael@0 285 //// Frecency Changed Notification Function
michael@0 286
michael@0 287 /**
michael@0 288 * For a given place, posts a runnable to the main thread that calls
michael@0 289 * onFrecencyChanged on nsNavHistory's nsINavHistoryObservers. The passed-in
michael@0 290 * newFrecency value is returned unchanged.
michael@0 291 *
michael@0 292 * @param newFrecency
michael@0 293 * The place's new frecency.
michael@0 294 * @param url
michael@0 295 * The place's URL.
michael@0 296 * @param guid
michael@0 297 * The place's GUID.
michael@0 298 * @param hidden
michael@0 299 * The place's hidden boolean.
michael@0 300 * @param lastVisitDate
michael@0 301 * The place's last visit date.
michael@0 302 * @return newFrecency
michael@0 303 */
michael@0 304 class FrecencyNotificationFunction MOZ_FINAL : public mozIStorageFunction
michael@0 305 {
michael@0 306 public:
michael@0 307 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 308 NS_DECL_MOZISTORAGEFUNCTION
michael@0 309
michael@0 310 /**
michael@0 311 * Registers the function with the specified database connection.
michael@0 312 *
michael@0 313 * @param aDBConn
michael@0 314 * The database connection to register with.
michael@0 315 */
michael@0 316 static nsresult create(mozIStorageConnection *aDBConn);
michael@0 317 };
michael@0 318
michael@0 319
michael@0 320 } // namespace places
michael@0 321 } // namespace storage
michael@0 322
michael@0 323 #endif // mozilla_places_SQLFunctions_h_

mercurial