michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: %{C++ michael@0: #include "Entries.h" michael@0: #include "LookupCache.h" michael@0: class nsUrlClassifierLookupResult; michael@0: %} michael@0: [ptr] native ResultArray(nsTArray); michael@0: [ptr] native CacheCompletionArray(nsTArray); michael@0: [ptr] native PrefixArray(mozilla::safebrowsing::PrefixArray); michael@0: michael@0: interface nsIUrlClassifierHashCompleter; michael@0: interface nsIPrincipal; michael@0: michael@0: // Interface for JS function callbacks michael@0: [scriptable, function, uuid(4ca27b6b-a674-4b3d-ab30-d21e2da2dffb)] michael@0: interface nsIUrlClassifierCallback : nsISupports { michael@0: void handleEvent(in ACString value); michael@0: }; michael@0: michael@0: /** michael@0: * The nsIUrlClassifierUpdateObserver interface is implemented by michael@0: * clients streaming updates to the url-classifier (usually michael@0: * nsUrlClassifierStreamUpdater. michael@0: */ michael@0: [scriptable, uuid(9fa11561-5816-4e1b-bcc9-b629ca05cce6)] michael@0: interface nsIUrlClassifierUpdateObserver : nsISupports { michael@0: /** michael@0: * The update requested a new URL whose contents should be downloaded michael@0: * and sent to the classifier as a new stream. michael@0: * michael@0: * @param url The url that was requested. michael@0: * @param table The table name that this URL's contents will be associated michael@0: * with. This should be passed back to beginStream(). michael@0: */ michael@0: void updateUrlRequested(in ACString url, michael@0: in ACString table); michael@0: michael@0: /** michael@0: * A stream update has completed. michael@0: * michael@0: * @param status The state of the update process. michael@0: * @param delay The amount of time the updater should wait to fetch the michael@0: * next URL in ms. michael@0: */ michael@0: void streamFinished(in nsresult status, in unsigned long delay); michael@0: michael@0: /* The update has encountered an error and should be cancelled */ michael@0: void updateError(in nsresult error); michael@0: michael@0: /** michael@0: * The update has completed successfully. michael@0: * michael@0: * @param requestedTimeout The number of seconds that the caller should michael@0: * wait before trying to update again. michael@0: **/ michael@0: void updateSuccess(in unsigned long requestedTimeout); michael@0: }; michael@0: michael@0: /** michael@0: * This is a proxy class that is instantiated and called from the JS thread. michael@0: * It provides async methods for querying and updating the database. As the michael@0: * methods complete, they call the callback function. michael@0: */ michael@0: [scriptable, uuid(3f9e61e5-01bd-45d0-8dd2-f1abcd20dbb7)] michael@0: interface nsIUrlClassifierDBService : nsISupports michael@0: { michael@0: /** michael@0: * Looks up a URI in the specified tables. michael@0: * michael@0: * @param principal: The principal containing the URI to search. michael@0: * @param c: The callback will be called with a comma-separated list michael@0: * of tables to which the key belongs. michael@0: */ michael@0: void lookup(in nsIPrincipal principal, michael@0: in ACString tables, michael@0: in nsIUrlClassifierCallback c); michael@0: michael@0: /** michael@0: * Lists the tables along with which chunks are available in each table. michael@0: * This list is in the format of the request body: michael@0: * tablename;chunkdata\n michael@0: * tablename2;chunkdata2\n michael@0: * michael@0: * For example: michael@0: * goog-phish-regexp;a:10,14,30-40s:56,67 michael@0: * goog-white-regexp;a:1-3,5 michael@0: */ michael@0: void getTables(in nsIUrlClassifierCallback c); michael@0: michael@0: /** michael@0: * Set the nsIUrlClassifierCompleter object for a given table. This michael@0: * object will be used to request complete versions of partial michael@0: * hashes. michael@0: */ michael@0: void setHashCompleter(in ACString tableName, michael@0: in nsIUrlClassifierHashCompleter completer); michael@0: michael@0: //////////////////////////////////////////////////////////////////////////// michael@0: // Incremental update methods. michael@0: // michael@0: // An update to the database has the following steps: michael@0: // michael@0: // 1) The update process is started with beginUpdate(). The client michael@0: // passes an nsIUrlClassifierUpdateObserver object which will be michael@0: // notified as the update is processed by the dbservice. michael@0: // 2) The client sends an initial update stream to the dbservice, michael@0: // using beginStream/updateStream/finishStream. michael@0: // 3) While reading this initial update stream, the dbservice may michael@0: // request additional streams from the client as requested by the michael@0: // update stream. michael@0: // 4) For each additional update stream, the client feeds the michael@0: // contents to the dbservice using beginStream/updateStream/endStream. michael@0: // 5) Once all streams have been processed, the client calls michael@0: // finishUpdate. When the dbservice has finished processing michael@0: // all streams, it will notify the observer that the update process michael@0: // is complete. michael@0: michael@0: /** michael@0: * Begin an update process. Will throw NS_ERROR_NOT_AVAILABLE if there michael@0: * is already an update in progress. michael@0: * michael@0: * @param updater The update observer tied to this update. michael@0: * @param tables A comma-separated list of tables included in this update. michael@0: */ michael@0: void beginUpdate(in nsIUrlClassifierUpdateObserver updater, michael@0: in ACString tables); michael@0: michael@0: /** michael@0: * Begin a stream update. This should be called once per url being michael@0: * fetched. michael@0: * michael@0: * @param table The table the contents of this stream will be associated michael@0: * with, or empty for the initial stream. michael@0: */ michael@0: void beginStream(in ACString table); michael@0: michael@0: /** michael@0: * Update the table incrementally. michael@0: */ michael@0: void updateStream(in ACString updateChunk); michael@0: michael@0: // It would be nice to have an updateFromStream method to round out the michael@0: // interface, but it's tricky because of XPCOM proxies. michael@0: michael@0: /** michael@0: * Finish an individual stream update. Must be called for every michael@0: * beginStream() call, before the next beginStream() or finishUpdate(). michael@0: * michael@0: * The update observer's streamFinished will be called once the michael@0: * stream has been processed. michael@0: */ michael@0: void finishStream(); michael@0: michael@0: /** michael@0: * Finish an incremental update. This will attempt to commit any michael@0: * pending changes and resets the update interface. michael@0: * michael@0: * The update observer's updateSucceeded or updateError methods michael@0: * will be called when the update has been processed. michael@0: */ michael@0: void finishUpdate(); michael@0: michael@0: /** michael@0: * Cancel an incremental update. This rolls back any pending changes. michael@0: * and resets the update interface. michael@0: * michael@0: * The update observer's updateError method will be called when the michael@0: * update has been rolled back. michael@0: */ michael@0: void cancelUpdate(); michael@0: michael@0: /** michael@0: * Reset the url-classifier database. This call will delete the existing michael@0: * database, emptying all tables. Mostly intended for use in unit tests. michael@0: */ michael@0: void resetDatabase(); michael@0: }; michael@0: michael@0: /** michael@0: * Interface for the actual worker thread. Implementations of this need not michael@0: * be thread aware and just work on the database. michael@0: */ michael@0: [scriptable, uuid(abcd7978-c304-4a7d-a44c-33c2ed5441e7)] michael@0: interface nsIUrlClassifierDBServiceWorker : nsIUrlClassifierDBService michael@0: { michael@0: // Provide a way to forcibly close the db connection. michael@0: void closeDb(); michael@0: michael@0: [noscript]void cacheCompletions(in CacheCompletionArray completions); michael@0: [noscript]void cacheMisses(in PrefixArray misses); michael@0: }; michael@0: michael@0: /** michael@0: * This is an internal helper interface for communication between the michael@0: * main thread and the dbservice worker thread. It is called for each michael@0: * lookup to provide a set of possible results, which the main thread michael@0: * may need to expand using an nsIUrlClassifierCompleter. michael@0: */ michael@0: [uuid(b903dc8f-dff1-42fe-894b-36e7a59bb801)] michael@0: interface nsIUrlClassifierLookupCallback : nsISupports michael@0: { michael@0: /** michael@0: * The lookup process is complete. michael@0: * michael@0: * @param results michael@0: * If this parameter is null, there were no results found. michael@0: * If not, it contains an array of nsUrlClassifierEntry objects michael@0: * with possible matches. The callee is responsible for freeing michael@0: * this array. michael@0: */ michael@0: void lookupComplete(in ResultArray results); michael@0: };