toolkit/components/url-classifier/nsUrlClassifierDBService.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.

michael@0 1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-/
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsUrlClassifierDBService_h_
michael@0 7 #define nsUrlClassifierDBService_h_
michael@0 8
michael@0 9 #include <nsISupportsUtils.h>
michael@0 10
michael@0 11 #include "nsID.h"
michael@0 12 #include "nsInterfaceHashtable.h"
michael@0 13 #include "nsIObserver.h"
michael@0 14 #include "nsUrlClassifierPrefixSet.h"
michael@0 15 #include "nsIUrlClassifierHashCompleter.h"
michael@0 16 #include "nsIUrlClassifierDBService.h"
michael@0 17 #include "nsIURIClassifier.h"
michael@0 18 #include "nsToolkitCompsCID.h"
michael@0 19 #include "nsICryptoHash.h"
michael@0 20 #include "nsICryptoHMAC.h"
michael@0 21 #include "mozilla/Attributes.h"
michael@0 22
michael@0 23 #include "LookupCache.h"
michael@0 24
michael@0 25 // The hash length for a domain key.
michael@0 26 #define DOMAIN_LENGTH 4
michael@0 27
michael@0 28 // The hash length of a partial hash entry.
michael@0 29 #define PARTIAL_LENGTH 4
michael@0 30
michael@0 31 // The hash length of a complete hash entry.
michael@0 32 #define COMPLETE_LENGTH 32
michael@0 33
michael@0 34 class nsUrlClassifierDBServiceWorker;
michael@0 35 class nsIThread;
michael@0 36 class nsIURI;
michael@0 37
michael@0 38 // This is a proxy class that just creates a background thread and delagates
michael@0 39 // calls to the background thread.
michael@0 40 class nsUrlClassifierDBService MOZ_FINAL : public nsIUrlClassifierDBService,
michael@0 41 public nsIURIClassifier,
michael@0 42 public nsIObserver
michael@0 43 {
michael@0 44 public:
michael@0 45 // This is thread safe. It throws an exception if the thread is busy.
michael@0 46 nsUrlClassifierDBService();
michael@0 47
michael@0 48 nsresult Init();
michael@0 49
michael@0 50 static nsUrlClassifierDBService* GetInstance(nsresult *result);
michael@0 51
michael@0 52 NS_DECLARE_STATIC_IID_ACCESSOR(NS_URLCLASSIFIERDBSERVICE_CID)
michael@0 53
michael@0 54 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 55 NS_DECL_NSIURLCLASSIFIERDBSERVICE
michael@0 56 NS_DECL_NSIURICLASSIFIER
michael@0 57 NS_DECL_NSIOBSERVER
michael@0 58
michael@0 59 bool GetCompleter(const nsACString& tableName,
michael@0 60 nsIUrlClassifierHashCompleter** completer);
michael@0 61 nsresult CacheCompletions(mozilla::safebrowsing::CacheResultArray *results);
michael@0 62 nsresult CacheMisses(mozilla::safebrowsing::PrefixArray *results);
michael@0 63
michael@0 64 static nsIThread* BackgroundThread();
michael@0 65
michael@0 66 private:
michael@0 67 // No subclassing
michael@0 68 ~nsUrlClassifierDBService();
michael@0 69
michael@0 70 // Disallow copy constructor
michael@0 71 nsUrlClassifierDBService(nsUrlClassifierDBService&);
michael@0 72
michael@0 73 nsresult LookupURI(nsIPrincipal* aPrincipal,
michael@0 74 const nsACString& tables,
michael@0 75 nsIUrlClassifierCallback* c,
michael@0 76 bool forceCheck, bool *didCheck);
michael@0 77
michael@0 78 // Close db connection and join the background thread if it exists.
michael@0 79 nsresult Shutdown();
michael@0 80
michael@0 81 // Check if the key is on a known-clean host.
michael@0 82 nsresult CheckClean(const nsACString &lookupKey,
michael@0 83 bool *clean);
michael@0 84
michael@0 85 // Read everything into mGethashTables and mDisallowCompletionTables
michael@0 86 nsresult ReadTablesFromPrefs();
michael@0 87
michael@0 88 nsRefPtr<nsUrlClassifierDBServiceWorker> mWorker;
michael@0 89 nsCOMPtr<nsIUrlClassifierDBServiceWorker> mWorkerProxy;
michael@0 90
michael@0 91 nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter> mCompleters;
michael@0 92
michael@0 93 // TRUE if the nsURIClassifier implementation should check for malware
michael@0 94 // uris on document loads.
michael@0 95 bool mCheckMalware;
michael@0 96
michael@0 97 // TRUE if the nsURIClassifier implementation should check for phishing
michael@0 98 // uris on document loads.
michael@0 99 bool mCheckPhishing;
michael@0 100
michael@0 101 // TRUE if a BeginUpdate() has been called without an accompanying
michael@0 102 // CancelUpdate()/FinishUpdate(). This is used to prevent competing
michael@0 103 // updates, not to determine whether an update is still being
michael@0 104 // processed.
michael@0 105 bool mInUpdate;
michael@0 106
michael@0 107 // The list of tables that can use the default hash completer object.
michael@0 108 nsTArray<nsCString> mGethashTables;
michael@0 109
michael@0 110 // The list of tables that should never be hash completed.
michael@0 111 nsTArray<nsCString> mDisallowCompletionsTables;
michael@0 112
michael@0 113 // Thread that we do the updates on.
michael@0 114 static nsIThread* gDbBackgroundThread;
michael@0 115 };
michael@0 116
michael@0 117 NS_DEFINE_STATIC_IID_ACCESSOR(nsUrlClassifierDBService, NS_URLCLASSIFIERDBSERVICE_CID)
michael@0 118
michael@0 119 #endif // nsUrlClassifierDBService_h_

mercurial