diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index 3127fb77d..d0ccbe1da 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -20,7 +20,6 @@ #include "config.h" CefRefPtr g_handler; -CefRefPtr g_command_line; CefRefPtr AppGetBrowser() { if (!g_handler.get()) @@ -34,39 +33,24 @@ CefWindowHandle AppGetMainHwnd() { return g_handler->GetMainHwnd(); } -void AppInitCommandLine(int argc, const char* const* argv) { - g_command_line = CefCommandLine::CreateCommandLine(); -#if defined(OS_WIN) - g_command_line->InitFromString(::GetCommandLineW()); -#else - g_command_line->InitFromArgv(argc, argv); -#endif -} - -// Returns the application command line object. -CefRefPtr AppGetCommandLine() { - return g_command_line; -} - // Returns the application settings based on command line arguments. -void AppGetSettings(CefSettings& settings, CefRefPtr app) { - DCHECK(app.get()); - DCHECK(g_command_line.get()); - if (!g_command_line.get()) +void AppGetSettings(CefSettings& settings, CefRefPtr command_line) { + DCHECK(command_line.get()); + if (!command_line.get()) return; #if defined(OS_WIN) settings.multi_threaded_message_loop = - g_command_line->HasSwitch(client::switches::kMultiThreadedMessageLoop); + command_line->HasSwitch(client::switches::kMultiThreadedMessageLoop); #endif CefString(&settings.cache_path) = - g_command_line->GetSwitchValue(client::switches::kCachePath); + command_line->GetSwitchValue(client::switches::kCachePath); CefString(&settings.log_file) = - g_command_line->GetSwitchValue(client::switches::kLogFile); + command_line->GetSwitchValue(client::switches::kLogFile); { - std::string str = g_command_line->GetSwitchValue(client::switches::kLogSeverity); + std::string str = command_line->GetSwitchValue(client::switches::kLogSeverity); // Default to LOGSEVERITY_DISABLE settings.log_severity = LOGSEVERITY_DISABLE; @@ -91,7 +75,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr app) { //CefString(&settings.locale) = appshell::GetCurrentLanguage( ); CefString(&settings.javascript_flags) = - g_command_line->GetSwitchValue(client::switches::kJavascriptFlags); + command_line->GetSwitchValue(client::switches::kJavascriptFlags); // Enable dev tools settings.remote_debugging_port = REMOTE_DEBUGGING_PORT; diff --git a/appshell/cefclient.h b/appshell/cefclient.h index 5cf80477c..f62278c65 100644 --- a/appshell/cefclient.h +++ b/appshell/cefclient.h @@ -26,14 +26,8 @@ std::string AppGetWorkingDirectory(); // Returns the starting URL CefString AppGetInitialURL(); -// Initialize the application command line. -void AppInitCommandLine(int argc, const char* const* argv); - -// Returns the application command line object. -CefRefPtr AppGetCommandLine(); - // Returns the application settings based on command line arguments. -void AppGetSettings(CefSettings& settings, CefRefPtr app); +void AppGetSettings(CefSettings& settings, CefRefPtr command_line); // Returns the application browser settings based on command line arguments. void AppGetBrowserSettings(CefBrowserSettings& settings); diff --git a/appshell/cefclient_gtk.cc b/appshell/cefclient_gtk.cc index 16510956d..8656a71fd 100644 --- a/appshell/cefclient_gtk.cc +++ b/appshell/cefclient_gtk.cc @@ -153,12 +153,13 @@ int main(int argc, char* argv[]) { GtkWidget* window; // Parse command line arguments. - AppInitCommandLine(argc, argv); + CefRefPtr cmdLine = CefCommandLine::CreateCommandLine(); + cmdLine->InitFromArgv(argc, argv); CefSettings settings; // Populate the settings based on command line arguments. - AppGetSettings(settings, app); + AppGetSettings(settings, cmdLine); settings.no_sandbox = TRUE; @@ -166,9 +167,7 @@ int main(int argc, char* argv[]) { if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = appshell::AppGetCachePath(); } - - CefRefPtr cmdLine = AppGetCommandLine(); - + if (cmdLine->HasSwitch(client::switches::kStartupPath)) { szInitialUrl = cmdLine->GetSwitchValue(client::switches::kStartupPath); } else { diff --git a/appshell/cefclient_mac.mm b/appshell/cefclient_mac.mm index 43797cc1b..26447001f 100644 --- a/appshell/cefclient_mac.mm +++ b/appshell/cefclient_mac.mm @@ -686,8 +686,6 @@ - (void)createApp:(id)object { settings.javascript_access_clipboard = STATE_ENABLED; settings.javascript_dom_paste = STATE_ENABLED; - CefRefPtr cmdLine = AppGetCommandLine(); - #ifdef DARK_INITIAL_PAGE // Avoid white flash at startup or refresh by making this the default // CSS. @@ -830,12 +828,13 @@ int main(int argc, char* argv[]) { [NSApp setDelegate:delegate]; // Parse command line arguments. - AppInitCommandLine(argc, argv); + CefRefPtr cmdLine = CefCommandLine::CreateCommandLine(); + cmdLine->InitFromArgv(argc, argv); CefSettings settings; // Populate the settings based on command line arguments. - AppGetSettings(settings, app); + AppGetSettings(settings, cmdLine); settings.no_sandbox = YES; @@ -851,8 +850,7 @@ int main(int argc, char* argv[]) { CGEventRef event = CGEventCreate(NULL); CGEventFlags modifiers = CGEventGetFlags(event); CFRelease(event); - - CefRefPtr cmdLine = AppGetCommandLine(); + if (cmdLine->HasSwitch(client::switches::kStartupPath)) { CefString cmdLineStartupURL = cmdLine->GetSwitchValue(client::switches::kStartupPath); std::string startupURLStr(cmdLineStartupURL); diff --git a/appshell/cefclient_win.cpp b/appshell/cefclient_win.cpp index b3ee4b988..e09473752 100644 --- a/appshell/cefclient_win.cpp +++ b/appshell/cefclient_win.cpp @@ -129,13 +129,13 @@ bool GetFullPath(const std::wstring& path, std::wstring& oFullPath) } -std::wstring GetFilenamesFromCommandLine() { +std::wstring GetFilenamesFromCommandLine(CefRefPtr command_line) { std::wstring result = L"[]"; - if (AppGetCommandLine()->HasArguments()) { + if (command_line->HasArguments()) { bool firstEntry = true; std::vector args; - AppGetCommandLine()->GetArguments(args); + command_line->GetArguments(args); std::vector::iterator iterator; result = L"["; for (iterator = args.begin(); iterator != args.end(); iterator++) { @@ -188,12 +188,13 @@ int APIENTRY wWinMain(HINSTANCE hInstance, if (_getcwd(szWorkingDir, MAX_UNC_PATH) == NULL) szWorkingDir[0] = 0; - // Parse command line arguments. The passed in values are ignored on Windows. - AppInitCommandLine(0, NULL); + // Parse command line arguments. + CefRefPtr cmdLine = CefCommandLine::CreateCommandLine(); + cmdLine->InitFromString(::GetCommandLineW()); // Determine if we should use an already running instance of Brackets. HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, FIRST_INSTANCE_MUTEX_NAME); - if ((hMutex != NULL) && AppGetCommandLine()->HasArguments() && (lpCmdLine != NULL)) { + if ((hMutex != NULL) && cmdLine->HasArguments() && (lpCmdLine != NULL)) { // for subsequent instances, re-use an already running instance if we're being called to // open an existing file on the command-line (eg. Open With.. from Windows Explorer) HWND hFirstInstanceWnd = cef_main_window::FindFirstTopLevelInstance(); @@ -229,7 +230,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, CefSettings settings; // Populate the settings based on command line arguments. - AppGetSettings(settings, app); + AppGetSettings(settings, cmdLine); // Check command if (CefString(&settings.cache_path).length() == 0) { @@ -239,7 +240,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance, // Initialize CEF. CefInitialize(main_args, settings, app.get(), NULL); - CefRefPtr cmdLine = AppGetCommandLine(); if (cmdLine->HasSwitch(client::switches::kStartupPath)) { wcscpy(szInitialUrl, cmdLine->GetSwitchValue(client::switches::kStartupPath).c_str()); } @@ -299,7 +299,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, // Start the node server process startNodeProcess(); - gFilesToOpen = GetFilenamesFromCommandLine(); + gFilesToOpen = GetFilenamesFromCommandLine(cmdLine); int result = 0;