Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef Classifier_h__
7 #define Classifier_h__
9 #include "Entries.h"
10 #include "HashStore.h"
11 #include "ProtocolParser.h"
12 #include "LookupCache.h"
13 #include "nsCOMPtr.h"
14 #include "nsString.h"
15 #include "nsIFile.h"
16 #include "nsICryptoHash.h"
17 #include "nsDataHashtable.h"
19 namespace mozilla {
20 namespace safebrowsing {
22 /**
23 * Maintains the stores and LookupCaches for the url classifier.
24 */
25 class Classifier {
26 public:
27 Classifier();
28 ~Classifier();
30 nsresult Open(nsIFile& aCacheDirectory);
31 void Close();
32 void Reset();
34 /**
35 * Get the list of active tables and their chunks in a format
36 * suitable for an update request.
37 */
38 void TableRequest(nsACString& aResult);
40 /*
41 * Get all tables that we know about.
42 */
43 nsresult ActiveTables(nsTArray<nsCString>& aTables);
45 /**
46 * Check a URL against the specified tables.
47 */
48 nsresult Check(const nsACString& aSpec,
49 const nsACString& tables,
50 LookupResultArray& aResults);
52 /**
53 * Apply the table updates in the array. Takes ownership of
54 * the updates in the array and clears it. Wacky!
55 */
56 nsresult ApplyUpdates(nsTArray<TableUpdate*>* aUpdates);
57 /**
58 * Failed update. Spoil the entries so we don't block hosts
59 * unnecessarily
60 */
61 nsresult MarkSpoiled(nsTArray<nsCString>& aTables);
62 nsresult CacheCompletions(const CacheResultArray& aResults);
63 uint32_t GetHashKey(void) { return mHashKey; }
64 void SetFreshTime(uint32_t aTime) { mFreshTime = aTime; }
65 /*
66 * Get a bunch of extra prefixes to query for completion
67 * and mask the real entry being requested
68 */
69 nsresult ReadNoiseEntries(const Prefix& aPrefix,
70 const nsACString& aTableName,
71 uint32_t aCount,
72 PrefixArray* aNoiseEntries);
73 static void SplitTables(const nsACString& str, nsTArray<nsCString>& tables);
75 private:
76 void DropStores();
77 nsresult CreateStoreDirectory();
78 nsresult SetupPathNames();
79 nsresult RecoverBackups();
80 nsresult CleanToDelete();
81 nsresult BackupTables();
82 nsresult RemoveBackupTables();
83 nsresult RegenActiveTables();
84 nsresult ScanStoreDir(nsTArray<nsCString>& aTables);
86 nsresult ApplyTableUpdates(nsTArray<TableUpdate*>* aUpdates,
87 const nsACString& aTable);
89 LookupCache *GetLookupCache(const nsACString& aTable);
91 // Root dir of the Local profile.
92 nsCOMPtr<nsIFile> mCacheDirectory;
93 // Main directory where to store the databases.
94 nsCOMPtr<nsIFile> mStoreDirectory;
95 // Used for atomically updating the other dirs.
96 nsCOMPtr<nsIFile> mBackupDirectory;
97 nsCOMPtr<nsIFile> mToDeleteDirectory;
98 nsCOMPtr<nsICryptoHash> mCryptoHash;
99 nsTArray<HashStore*> mHashStores;
100 nsTArray<LookupCache*> mLookupCaches;
101 nsTArray<nsCString> mActiveTablesCache;
102 uint32_t mHashKey;
103 // Stores the last time a given table was updated (seconds).
104 nsDataHashtable<nsCStringHashKey, int64_t> mTableFreshness;
105 uint32_t mFreshTime;
106 };
108 }
109 }
111 #endif