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