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