nsIUrlClassifierDBService.idl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. #include "nsISupports.idl"
  5. %{C++
  6. #include "Entries.h"
  7. #include "LookupCache.h"
  8. class nsUrlClassifierLookupResult;
  9. %}
  10. [ptr] native ResultArray(nsTArray<mozilla::safebrowsing::LookupResult>);
  11. [ptr] native CacheCompletionArray(nsTArray<mozilla::safebrowsing::CacheResult>);
  12. [ptr] native PrefixArray(mozilla::safebrowsing::PrefixArray);
  13. interface nsIUrlClassifierHashCompleter;
  14. interface nsIPrincipal;
  15. // Interface for JS function callbacks
  16. [scriptable, function, uuid(4ca27b6b-a674-4b3d-ab30-d21e2da2dffb)]
  17. interface nsIUrlClassifierCallback : nsISupports {
  18. void handleEvent(in ACString value);
  19. };
  20. /**
  21. * The nsIUrlClassifierUpdateObserver interface is implemented by
  22. * clients streaming updates to the url-classifier (usually
  23. * nsUrlClassifierStreamUpdater.
  24. */
  25. [scriptable, uuid(9fa11561-5816-4e1b-bcc9-b629ca05cce6)]
  26. interface nsIUrlClassifierUpdateObserver : nsISupports {
  27. /**
  28. * The update requested a new URL whose contents should be downloaded
  29. * and sent to the classifier as a new stream.
  30. *
  31. * @param url The url that was requested.
  32. * @param table The table name that this URL's contents will be associated
  33. * with. This should be passed back to beginStream().
  34. */
  35. void updateUrlRequested(in ACString url,
  36. in ACString table);
  37. /**
  38. * A stream update has completed.
  39. *
  40. * @param status The state of the update process.
  41. * @param delay The amount of time the updater should wait to fetch the
  42. * next URL in ms.
  43. */
  44. void streamFinished(in nsresult status, in unsigned long delay);
  45. /* The update has encountered an error and should be cancelled */
  46. void updateError(in nsresult error);
  47. /**
  48. * The update has completed successfully.
  49. *
  50. * @param requestedTimeout The number of seconds that the caller should
  51. * wait before trying to update again.
  52. **/
  53. void updateSuccess(in unsigned long requestedTimeout);
  54. };
  55. /**
  56. * This is a proxy class that is instantiated and called from the JS thread.
  57. * It provides async methods for querying and updating the database. As the
  58. * methods complete, they call the callback function.
  59. */
  60. [scriptable, uuid(7a258022-6765-11e5-b379-b37b1f2354be)]
  61. interface nsIUrlClassifierDBService : nsISupports
  62. {
  63. /**
  64. * Looks up a URI in the specified tables.
  65. *
  66. * @param principal: The principal containing the URI to search.
  67. * @param c: The callback will be called with a comma-separated list
  68. * of tables to which the key belongs.
  69. */
  70. void lookup(in nsIPrincipal principal,
  71. in ACString tables,
  72. in nsIUrlClassifierCallback c);
  73. /**
  74. * Lists the tables along with their meta info in the following format:
  75. *
  76. * tablename;[metadata]\n
  77. * tablename2;[metadata]\n
  78. *
  79. * For v2 tables, the metadata is the chunks info such as
  80. *
  81. * goog-phish-shavar;a:10,14,30-40s:56,67
  82. * goog-unwanted-shavar;a:1-3,5
  83. *
  84. * For v4 tables, base64 encoded state is currently the only info in the
  85. * metadata (can be extended whenever necessary). For exmaple,
  86. *
  87. * goog-phish-proto;Cg0IARAGGAEiAzAwMTABEKqTARoCGAjT1gDD:oCGAjT1gDD\n
  88. * goog-malware-proto;Cg0IAhAGGAEiAzAwMTABENCQARoCGAjx5Yty:BENCQARoCGAj\n
  89. *
  90. * Note that the metadata is colon-separated.
  91. *
  92. */
  93. void getTables(in nsIUrlClassifierCallback c);
  94. /**
  95. * Set the nsIUrlClassifierCompleter object for a given table. This
  96. * object will be used to request complete versions of partial
  97. * hashes.
  98. */
  99. void setHashCompleter(in ACString tableName,
  100. in nsIUrlClassifierHashCompleter completer);
  101. /**
  102. * Set the last update time for the given table. We use this to
  103. * remember freshness past restarts. Time is in milliseconds since epoch.
  104. */
  105. void setLastUpdateTime(in ACString tableName,
  106. in unsigned long long lastUpdateTime);
  107. /**
  108. * Forget the results that were used in the last DB update.
  109. */
  110. void clearLastResults();
  111. ////////////////////////////////////////////////////////////////////////////
  112. // Incremental update methods.
  113. //
  114. // An update to the database has the following steps:
  115. //
  116. // 1) The update process is started with beginUpdate(). The client
  117. // passes an nsIUrlClassifierUpdateObserver object which will be
  118. // notified as the update is processed by the dbservice.
  119. // 2) The client sends an initial update stream to the dbservice,
  120. // using beginStream/updateStream/finishStream.
  121. // 3) While reading this initial update stream, the dbservice may
  122. // request additional streams from the client as requested by the
  123. // update stream.
  124. // 4) For each additional update stream, the client feeds the
  125. // contents to the dbservice using beginStream/updateStream/endStream.
  126. // 5) Once all streams have been processed, the client calls
  127. // finishUpdate. When the dbservice has finished processing
  128. // all streams, it will notify the observer that the update process
  129. // is complete.
  130. /**
  131. * Begin an update process. Will throw NS_ERROR_NOT_AVAILABLE if there
  132. * is already an update in progress.
  133. *
  134. * @param updater The update observer tied to this update.
  135. * @param tables A comma-separated list of tables included in this update.
  136. */
  137. void beginUpdate(in nsIUrlClassifierUpdateObserver updater,
  138. in ACString tables);
  139. /**
  140. * Begin a stream update. This should be called once per url being
  141. * fetched.
  142. *
  143. * @param table The table the contents of this stream will be associated
  144. * with, or empty for the initial stream.
  145. */
  146. void beginStream(in ACString table);
  147. /**
  148. * Update the table incrementally.
  149. */
  150. void updateStream(in ACString updateChunk);
  151. // It would be nice to have an updateFromStream method to round out the
  152. // interface, but it's tricky because of XPCOM proxies.
  153. /**
  154. * Finish an individual stream update. Must be called for every
  155. * beginStream() call, before the next beginStream() or finishUpdate().
  156. *
  157. * The update observer's streamFinished will be called once the
  158. * stream has been processed.
  159. */
  160. void finishStream();
  161. /**
  162. * Finish an incremental update. This will attempt to commit any
  163. * pending changes and resets the update interface.
  164. *
  165. * The update observer's updateSucceeded or updateError methods
  166. * will be called when the update has been processed.
  167. */
  168. void finishUpdate();
  169. /**
  170. * Cancel an incremental update. This rolls back any pending changes.
  171. * and resets the update interface.
  172. *
  173. * The update observer's updateError method will be called when the
  174. * update has been rolled back.
  175. */
  176. void cancelUpdate();
  177. /**
  178. * Reset the url-classifier database. This call will delete the existing
  179. * database, emptying all tables. Mostly intended for use in unit tests.
  180. */
  181. void resetDatabase();
  182. /**
  183. * Reload he url-classifier database. This will empty all cache for
  184. * completions from gethash, and reload it from database. Mostly intended
  185. * for use in tests.
  186. */
  187. void reloadDatabase();
  188. };
  189. /**
  190. * This is an internal helper interface for communication between the
  191. * main thread and the dbservice worker thread. It is called for each
  192. * lookup to provide a set of possible results, which the main thread
  193. * may need to expand using an nsIUrlClassifierCompleter.
  194. */
  195. [uuid(b903dc8f-dff1-42fe-894b-36e7a59bb801)]
  196. interface nsIUrlClassifierLookupCallback : nsISupports
  197. {
  198. /**
  199. * The lookup process is complete.
  200. *
  201. * @param results
  202. * If this parameter is null, there were no results found.
  203. * If not, it contains an array of nsUrlClassifierEntry objects
  204. * with possible matches. The callee is responsible for freeing
  205. * this array.
  206. */
  207. void lookupComplete(in ResultArray results);
  208. };