xpcom/tests/nsIFileEnumerator.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

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

mercurial