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 #include "nsIFile.h"
2 #include "nsStringGlue.h"
4 #include <stdio.h>
5 #include "nsIComponentRegistrar.h"
6 #include "nsIComponentManager.h"
7 #include "nsIServiceManager.h"
8 #include "nsMemory.h"
9 #include "nsISimpleEnumerator.h"
10 #include "nsCOMPtr.h"
12 bool LoopInDir(nsIFile* file)
13 {
14 nsresult rv;
15 nsCOMPtr<nsISimpleEnumerator> entries;
16 rv = file->GetDirectoryEntries(getter_AddRefs(entries));
17 if(NS_FAILED(rv) || !entries)
18 return false;
20 bool hasMore;
21 while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore)
22 {
23 nsCOMPtr<nsISupports> sup;
24 entries->GetNext(getter_AddRefs(sup));
25 if(!sup)
26 return false;
28 nsCOMPtr<nsIFile> file = do_QueryInterface(sup);
29 if(!file)
30 return false;
32 nsAutoCString name;
33 if(NS_FAILED(file->GetNativeLeafName(name)))
34 return false;
36 bool isDir;
37 printf("%s\n", name.get());
38 rv = file->IsDirectory(&isDir);
39 if (NS_FAILED(rv))
40 {
41 printf("IsDirectory Failed!!!\n");
42 return false;
43 }
45 if (isDir)
46 {
47 LoopInDir(file);
48 }
49 }
50 return true;
51 }
54 int
55 main(int argc, char* argv[])
56 {
57 nsresult rv;
58 {
59 nsCOMPtr<nsIFile> topDir;
61 nsCOMPtr<nsIServiceManager> servMan;
62 rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
63 if (NS_FAILED(rv)) return -1;
65 if (argc > 1 && argv[1] != nullptr)
66 {
67 char* pathStr = argv[1];
68 NS_NewNativeLocalFile(nsDependentCString(pathStr), false, getter_AddRefs(topDir));
69 }
71 if (!topDir)
72 {
73 printf("No Top Dir\n");
74 return -1;
75 }
76 int32_t startTime = PR_IntervalNow();
78 LoopInDir(topDir);
80 int32_t endTime = PR_IntervalNow();
82 printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime));
83 } // this scopes the nsCOMPtrs
84 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
85 rv = NS_ShutdownXPCOM(nullptr);
86 NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
87 return 0;
88 }