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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | /* |
michael@0 | 7 | |
michael@0 | 8 | Implementations for a bunch of useful RDF utility routines. Many of |
michael@0 | 9 | these will eventually be exported outside of RDF.DLL via the |
michael@0 | 10 | nsIRDFService interface. |
michael@0 | 11 | |
michael@0 | 12 | TO DO |
michael@0 | 13 | |
michael@0 | 14 | 1) Make this so that it doesn't permanently leak the RDF service |
michael@0 | 15 | object. |
michael@0 | 16 | |
michael@0 | 17 | 2) Make container functions thread-safe. They currently don't ensure |
michael@0 | 18 | that the RDF:nextVal property is maintained safely. |
michael@0 | 19 | |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | #include "nsCOMPtr.h" |
michael@0 | 23 | #include "nsIRDFDataSource.h" |
michael@0 | 24 | #include "nsIRDFNode.h" |
michael@0 | 25 | #include "nsIRDFService.h" |
michael@0 | 26 | #include "nsIServiceManager.h" |
michael@0 | 27 | #include "nsIURL.h" |
michael@0 | 28 | #include "nsIIOService.h" |
michael@0 | 29 | #include "nsIURL.h" |
michael@0 | 30 | #include "nsNetUtil.h" |
michael@0 | 31 | #include "nsRDFCID.h" |
michael@0 | 32 | #include "nsString.h" |
michael@0 | 33 | #include "nsXPIDLString.h" |
michael@0 | 34 | #include "nsUnicharUtils.h" |
michael@0 | 35 | #include "rdfutil.h" |
michael@0 | 36 | |
michael@0 | 37 | //////////////////////////////////////////////////////////////////////// |
michael@0 | 38 | |
michael@0 | 39 | nsresult |
michael@0 | 40 | rdf_MakeRelativeRef(const nsCSubstring& aBaseURI, nsCString& aURI) |
michael@0 | 41 | { |
michael@0 | 42 | // This implementation is extremely simple: e.g., it can't compute |
michael@0 | 43 | // relative paths, or anything fancy like that. If the context URI |
michael@0 | 44 | // is not a prefix of the URI in question, we'll just bail. |
michael@0 | 45 | uint32_t prefixLen = aBaseURI.Length(); |
michael@0 | 46 | if (prefixLen != 0 && StringBeginsWith(aURI, aBaseURI)) { |
michael@0 | 47 | if (prefixLen < aURI.Length() && aURI.CharAt(prefixLen) == '/') |
michael@0 | 48 | ++prefixLen; // chop the leading slash so it's not `absolute' |
michael@0 | 49 | |
michael@0 | 50 | aURI.Cut(0, prefixLen); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | return NS_OK; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | void |
michael@0 | 57 | rdf_FormatDate(PRTime aTime, nsACString &aResult) |
michael@0 | 58 | { |
michael@0 | 59 | // Outputs Unixish date in GMT plus usecs; e.g., |
michael@0 | 60 | // Wed Jan 9 19:15:13 2002 +002441 |
michael@0 | 61 | // |
michael@0 | 62 | PRExplodedTime t; |
michael@0 | 63 | PR_ExplodeTime(aTime, PR_GMTParameters, &t); |
michael@0 | 64 | |
michael@0 | 65 | char buf[256]; |
michael@0 | 66 | PR_FormatTimeUSEnglish(buf, sizeof buf, "%a %b %d %H:%M:%S %Y", &t); |
michael@0 | 67 | aResult.Append(buf); |
michael@0 | 68 | |
michael@0 | 69 | // usecs |
michael@0 | 70 | aResult.Append(" +"); |
michael@0 | 71 | int32_t usec = t.tm_usec; |
michael@0 | 72 | for (int32_t digit = 100000; digit > 1; digit /= 10) { |
michael@0 | 73 | aResult.Append(char('0' + (usec / digit))); |
michael@0 | 74 | usec %= digit; |
michael@0 | 75 | } |
michael@0 | 76 | aResult.Append(char('0' + usec)); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | PRTime |
michael@0 | 80 | rdf_ParseDate(const nsACString &aTime) |
michael@0 | 81 | { |
michael@0 | 82 | PRTime t; |
michael@0 | 83 | PR_ParseTimeString(PromiseFlatCString(aTime).get(), true, &t); |
michael@0 | 84 | |
michael@0 | 85 | int32_t usec = 0; |
michael@0 | 86 | |
michael@0 | 87 | nsACString::const_iterator begin, digit, end; |
michael@0 | 88 | aTime.BeginReading(begin); |
michael@0 | 89 | aTime.EndReading(end); |
michael@0 | 90 | |
michael@0 | 91 | // Walk backwards until we find a `+', run out of string, or a |
michael@0 | 92 | // non-numeric character. |
michael@0 | 93 | digit = end; |
michael@0 | 94 | while (--digit != begin && *digit != '+') { |
michael@0 | 95 | if (*digit < '0' || *digit > '9') |
michael@0 | 96 | break; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | if (digit != begin && *digit == '+') { |
michael@0 | 100 | // There's a usec field specified (or, at least, something |
michael@0 | 101 | // that looks close enough. Parse it, and add it to the time. |
michael@0 | 102 | while (++digit != end) { |
michael@0 | 103 | usec *= 10; |
michael@0 | 104 | usec += *digit - '0'; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | t += usec; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | return t; |
michael@0 | 111 | } |