Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Init command_line directly in cefclient_<platform> #586

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions appshell/cefclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "config.h"

CefRefPtr<ClientHandler> g_handler;
CefRefPtr<CefCommandLine> g_command_line;

CefRefPtr<CefBrowser> AppGetBrowser() {
if (!g_handler.get())
Expand All @@ -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<CefCommandLine> AppGetCommandLine() {
return g_command_line;
}

// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) {
DCHECK(app.get());
DCHECK(g_command_line.get());
if (!g_command_line.get())
void AppGetSettings(CefSettings& settings, CefRefPtr<CefCommandLine> 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;
Expand All @@ -91,7 +75,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> 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;
Expand Down
8 changes: 1 addition & 7 deletions appshell/cefclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CefCommandLine> AppGetCommandLine();

// Returns the application settings based on command line arguments.
void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app);
void AppGetSettings(CefSettings& settings, CefRefPtr<CefCommandLine> command_line);

// Returns the application browser settings based on command line arguments.
void AppGetBrowserSettings(CefBrowserSettings& settings);
Expand Down
9 changes: 4 additions & 5 deletions appshell/cefclient_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,21 @@ int main(int argc, char* argv[]) {
GtkWidget* window;

// Parse command line arguments.
AppInitCommandLine(argc, argv);
CefRefPtr<CefCommandLine> 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;

// Check cache_path setting
if (CefString(&settings.cache_path).length() == 0) {
CefString(&settings.cache_path) = appshell::AppGetCachePath();
}

CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine();


if (cmdLine->HasSwitch(client::switches::kStartupPath)) {
szInitialUrl = cmdLine->GetSwitchValue(client::switches::kStartupPath);
} else {
Expand Down
10 changes: 4 additions & 6 deletions appshell/cefclient_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,6 @@ - (void)createApp:(id)object {
settings.javascript_access_clipboard = STATE_ENABLED;
settings.javascript_dom_paste = STATE_ENABLED;

CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine();

#ifdef DARK_INITIAL_PAGE
// Avoid white flash at startup or refresh by making this the default
// CSS.
Expand Down Expand Up @@ -830,12 +828,13 @@ int main(int argc, char* argv[]) {
[NSApp setDelegate:delegate];

// Parse command line arguments.
AppInitCommandLine(argc, argv);
CefRefPtr<CefCommandLine> 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;

Expand All @@ -851,8 +850,7 @@ int main(int argc, char* argv[]) {
CGEventRef event = CGEventCreate(NULL);
CGEventFlags modifiers = CGEventGetFlags(event);
CFRelease(event);

CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine();

if (cmdLine->HasSwitch(client::switches::kStartupPath)) {
CefString cmdLineStartupURL = cmdLine->GetSwitchValue(client::switches::kStartupPath);
std::string startupURLStr(cmdLineStartupURL);
Expand Down
18 changes: 9 additions & 9 deletions appshell/cefclient_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ bool GetFullPath(const std::wstring& path, std::wstring& oFullPath)

}

std::wstring GetFilenamesFromCommandLine() {
std::wstring GetFilenamesFromCommandLine(CefRefPtr<CefCommandLine> command_line) {
std::wstring result = L"[]";

if (AppGetCommandLine()->HasArguments()) {
if (command_line->HasArguments()) {
bool firstEntry = true;
std::vector<CefString> args;
AppGetCommandLine()->GetArguments(args);
command_line->GetArguments(args);
std::vector<CefString>::iterator iterator;
result = L"[";
for (iterator = args.begin(); iterator != args.end(); iterator++) {
Expand Down Expand Up @@ -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<CefCommandLine> 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();
Expand Down Expand Up @@ -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) {
Expand All @@ -239,7 +240,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
// Initialize CEF.
CefInitialize(main_args, settings, app.get(), NULL);

CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine();
if (cmdLine->HasSwitch(client::switches::kStartupPath)) {
wcscpy(szInitialUrl, cmdLine->GetSwitchValue(client::switches::kStartupPath).c_str());
}
Expand Down Expand Up @@ -299,7 +299,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
// Start the node server process
startNodeProcess();

gFilesToOpen = GetFilenamesFromCommandLine();
gFilesToOpen = GetFilenamesFromCommandLine(cmdLine);

int result = 0;

Expand Down