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.

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

mercurial