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