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: 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 | #include "nsCommandLineServiceMac.h" |
michael@0 | 7 | #include "MacApplicationDelegate.h" |
michael@0 | 8 | |
michael@0 | 9 | #include <CoreFoundation/CoreFoundation.h> |
michael@0 | 10 | #include <Carbon/Carbon.h> |
michael@0 | 11 | |
michael@0 | 12 | namespace CommandLineServiceMac { |
michael@0 | 13 | |
michael@0 | 14 | static const int kArgsGrowSize = 20; |
michael@0 | 15 | |
michael@0 | 16 | static char** sArgs = nullptr; |
michael@0 | 17 | static int sArgsAllocated = 0; |
michael@0 | 18 | static int sArgsUsed = 0; |
michael@0 | 19 | |
michael@0 | 20 | static bool sBuildingCommandLine = false; |
michael@0 | 21 | |
michael@0 | 22 | void AddToCommandLine(const char* inArgText) |
michael@0 | 23 | { |
michael@0 | 24 | if (sArgsUsed >= sArgsAllocated - 1) { |
michael@0 | 25 | // realloc does not free the given pointer if allocation fails |
michael@0 | 26 | char **temp = static_cast<char**>(realloc(sArgs, (sArgsAllocated + kArgsGrowSize) * sizeof(char*))); |
michael@0 | 27 | if (!temp) |
michael@0 | 28 | return; |
michael@0 | 29 | sArgs = temp; |
michael@0 | 30 | sArgsAllocated += kArgsGrowSize; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | char *temp2 = strdup(inArgText); |
michael@0 | 34 | if (!temp2) |
michael@0 | 35 | return; |
michael@0 | 36 | |
michael@0 | 37 | sArgs[sArgsUsed++] = temp2; |
michael@0 | 38 | sArgs[sArgsUsed] = nullptr; |
michael@0 | 39 | |
michael@0 | 40 | return; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void SetupMacCommandLine(int& argc, char**& argv, bool forRestart) |
michael@0 | 44 | { |
michael@0 | 45 | sArgs = static_cast<char **>(malloc(kArgsGrowSize * sizeof(char*))); |
michael@0 | 46 | if (!sArgs) |
michael@0 | 47 | return; |
michael@0 | 48 | sArgsAllocated = kArgsGrowSize; |
michael@0 | 49 | sArgs[0] = nullptr; |
michael@0 | 50 | sArgsUsed = 0; |
michael@0 | 51 | |
michael@0 | 52 | sBuildingCommandLine = true; |
michael@0 | 53 | |
michael@0 | 54 | // Copy args, stripping anything we don't want. |
michael@0 | 55 | for (int arg = 0; arg < argc; arg++) { |
michael@0 | 56 | char* flag = argv[arg]; |
michael@0 | 57 | // Don't pass on the psn (Process Serial Number) flag from the OS. |
michael@0 | 58 | if (strncmp(flag, "-psn_", 5) != 0) |
michael@0 | 59 | AddToCommandLine(flag); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | // Force processing of any pending Apple GetURL Events while we're building |
michael@0 | 63 | // the command line. The handlers will append to the command line rather than |
michael@0 | 64 | // act directly so there is no chance we'll process them during a XUL window |
michael@0 | 65 | // load and accidentally open unnecessary windows and home pages. |
michael@0 | 66 | ProcessPendingGetURLAppleEvents(); |
michael@0 | 67 | |
michael@0 | 68 | // If the process will be relaunched, the child should be in the foreground |
michael@0 | 69 | // if the parent is in the foreground. This will be communicated in a |
michael@0 | 70 | // command-line argument to the child. |
michael@0 | 71 | if (forRestart) { |
michael@0 | 72 | Boolean isForeground = false; |
michael@0 | 73 | ProcessSerialNumber psnSelf, psnFront; |
michael@0 | 74 | if (::GetCurrentProcess(&psnSelf) == noErr && |
michael@0 | 75 | ::GetFrontProcess(&psnFront) == noErr && |
michael@0 | 76 | ::SameProcess(&psnSelf, &psnFront, &isForeground) == noErr && |
michael@0 | 77 | isForeground) { |
michael@0 | 78 | AddToCommandLine("-foreground"); |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | sBuildingCommandLine = false; |
michael@0 | 83 | |
michael@0 | 84 | argc = sArgsUsed; |
michael@0 | 85 | argv = sArgs; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | bool AddURLToCurrentCommandLine(const char* aURL) |
michael@0 | 89 | { |
michael@0 | 90 | if (!sBuildingCommandLine) { |
michael@0 | 91 | return false; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | AddToCommandLine("-url"); |
michael@0 | 95 | AddToCommandLine(aURL); |
michael@0 | 96 | |
michael@0 | 97 | return true; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | } // namespace CommandLineServiceMac |