@@ -587,8 +587,7 @@ def Initialize(applicationSettings=None, commandLineSwitches=None, **kwargs):
587587 g_commandLineSwitches[" disable-gpu-shader-disk-cache" ] = " "
588588
589589 IF UNAME_SYSNAME == " Linux" :
590- # Apply Linux default command-line switches before the browser-process
591- # argv is built from g_commandLineSwitches below. setdefault lets an app
590+ # Apply Linux default command-line switches. setdefault lets an app
592591 # override either by passing it explicitly to cef.Initialize(switches=).
593592 #
594593 # Force Chrome's Ozone backend to X11. This is the *only* thing keeping
@@ -623,29 +622,13 @@ def Initialize(applicationSettings=None, commandLineSwitches=None, **kwargs):
623622 cdef HINSTANCE hInstance = GetModuleHandle(NULL )
624623 cdef CefMainArgs cefMainArgs = CefMainArgs(hInstance)
625624 ELIF UNAME_SYSNAME == " Linux" :
626- # Build a complete argv so the browser process sees all switches.
627- # OnBeforeChildProcessLaunch only reaches child processes; switches
628- # like --in-process-gpu and --single-process must be in the browser
629- # process's own command line to take effect.
630- _cefMainArgvPyList = [sys.executable.encode(' utf-8' )]
631- for _cefArgK, _cefArgV in g_commandLineSwitches.items():
632- if _cefArgV:
633- _cefMainArgvPyList.append(
634- (" --{}={}" .format(_cefArgK, _cefArgV)).encode(' utf-8' ))
635- else :
636- _cefMainArgvPyList.append(
637- (" --{}" .format(_cefArgK)).encode(' utf-8' ))
638- cdef int _cefMainArgc = len (_cefMainArgvPyList)
639- cdef char ** _cefMainArgvC = \
640- < char ** > malloc(_cefMainArgc * sizeof(char * ))
641- cdef bytes _cefMainArgvItem
642- cdef int _cefMainArgvI
643- for _cefMainArgvI in range (_cefMainArgc):
644- _cefMainArgvItem = _cefMainArgvPyList[_cefMainArgvI]
645- _cefMainArgvC[_cefMainArgvI] = _cefMainArgvItem
646- cdef CefMainArgs cefMainArgs = CefMainArgs(_cefMainArgc, _cefMainArgvC)
647- # _cefMainArgvPyList keeps the bytes alive; freed below after
648- # CefInitialize() has processed the command line.
625+ cdef list args = [arg.encode(' utf-8' ) for arg in sys.argv]
626+ cdef char ** argv = < char ** > malloc((len (args) + 1 ) * sizeof(char * ))
627+ cdef int i
628+ for i in range (len (args)):
629+ argv[i] = args[i]
630+ argv[len (args)] = NULL
631+ cdef CefMainArgs cefMainArgs = CefMainArgs(len (args), argv)
649632 ELIF UNAME_SYSNAME == " Darwin" :
650633 # TODO: use the CefMainArgs(int argc, char** argv) constructor.
651634 cdef CefMainArgs cefMainArgs
@@ -682,7 +665,7 @@ def Initialize(applicationSettings=None, commandLineSwitches=None, **kwargs):
682665 with nogil:
683666 ret = CefInitialize(cefMainArgs, cefApplicationSettings, cefApp, NULL )
684667 IF UNAME_SYSNAME == " Linux" :
685- free(_cefMainArgvC )
668+ free(argv )
686669
687670 global g_cef_initialized
688671 g_cef_initialized = True
0 commit comments