toolkit/xre/nsWindowsWMain.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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 // This file is a .cpp file meant to be included in nsBrowserApp.cpp and other
     6 // similar bootstrap code. It converts wide-character windows wmain into UTF-8
     7 // narrow-character strings.
     9 #ifndef XP_WIN
    10 #error This file only makes sense on Windows.
    11 #endif
    13 #include "nsUTF8Utils.h"
    15 #ifndef XRE_DONT_PROTECT_DLL_LOAD
    16 #include "nsSetDllDirectory.h"
    17 #endif
    19 #ifdef __MINGW32__
    21 /* MingW currently does not implement a wide version of the
    22    startup routines.  Workaround is to implement something like
    23    it ourselves.  See bug 411826 */
    25 #include <shellapi.h>
    27 int wmain(int argc, WCHAR **argv);
    29 int main(int argc, char **argv)
    30 {
    31   LPWSTR commandLine = GetCommandLineW();
    32   int argcw = 0;
    33   LPWSTR *argvw = CommandLineToArgvW(commandLine, &argcw);
    34   if (!argvw)
    35     return 127;
    37   int result = wmain(argcw, argvw);
    38   LocalFree(argvw);
    39   return result;
    40 }
    41 #endif /* __MINGW32__ */
    43 #define main NS_internal_main
    45 #ifndef XRE_WANT_ENVIRON
    46 int main(int argc, char **argv);
    47 #else
    48 int main(int argc, char **argv, char **envp);
    49 #endif
    51 static char*
    52 AllocConvertUTF16toUTF8(char16ptr_t arg)
    53 {
    54   // be generous... UTF16 units can expand up to 3 UTF8 units
    55   int len = wcslen(arg);
    56   char *s = new char[len * 3 + 1];
    57   if (!s)
    58     return nullptr;
    60   ConvertUTF16toUTF8 convert(s);
    61   convert.write(arg, len);
    62   convert.write_terminator();
    63   return s;
    64 }
    66 static void
    67 FreeAllocStrings(int argc, char **argv)
    68 {
    69   while (argc) {
    70     --argc;
    71     delete [] argv[argc];
    72   }
    74   delete [] argv;
    75 }
    77 int wmain(int argc, WCHAR **argv)
    78 {
    79 #ifndef XRE_DONT_PROTECT_DLL_LOAD
    80   mozilla::SanitizeEnvironmentVariables();
    81   SetDllDirectoryW(L"");
    82 #endif
    84   char **argvConverted = new char*[argc + 1];
    85   if (!argvConverted)
    86     return 127;
    88   for (int i = 0; i < argc; ++i) {
    89     argvConverted[i] = AllocConvertUTF16toUTF8(argv[i]);
    90     if (!argvConverted[i]) {
    91       return 127;
    92     }
    93   }
    94   argvConverted[argc] = nullptr;
    96   // need to save argvConverted copy for later deletion.
    97   char **deleteUs = new char*[argc+1];
    98   if (!deleteUs) {
    99     FreeAllocStrings(argc, argvConverted);
   100     return 127;
   101   }
   102   for (int i = 0; i < argc; i++)
   103     deleteUs[i] = argvConverted[i];
   104 #ifndef XRE_WANT_ENVIRON
   105   int result = main(argc, argvConverted);
   106 #else
   107   // Force creation of the multibyte _environ variable.
   108   getenv("PATH");
   109   int result = main(argc, argvConverted, _environ);
   110 #endif
   112   delete[] argvConverted;
   113   FreeAllocStrings(argc, deleteUs);
   115   return result;
   116 }

mercurial