From 2a172efa46a98b02d2ad7bee999b574dfc415df9 Mon Sep 17 00:00:00 2001 From: Gautam Jha Date: Wed, 6 Nov 2019 19:04:04 +0530 Subject: [PATCH 1/6] Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work --- appshell/appshell_extension_handler.h | 4 +--- appshell/appshell_extensions.cpp | 2 ++ appshell/appshell_extensions.js | 4 ++-- appshell/cefclient.cpp | 17 ++++++++++++++++- appshell/config.h | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/appshell/appshell_extension_handler.h b/appshell/appshell_extension_handler.h index 588f42bbf..0df32e42f 100644 --- a/appshell/appshell_extension_handler.h +++ b/appshell/appshell_extension_handler.h @@ -160,7 +160,7 @@ class AppShellExtensionHandler : public CefV8Handler { CefString& exception) { // The only messages that are handled here is getElapsedMilliseconds(), - // GetCurrentLanguage(), GetApplicationSupportDirectory(), and GetRemoteDebuggingPort(). + // GetCurrentLanguage(), and GetApplicationSupportDirectory(). // All other messages are passed to the browser process. if (name == "GetElapsedMilliseconds") { retval = CefV8Value::CreateDouble(GetElapsedMilliseconds()); @@ -170,8 +170,6 @@ class AppShellExtensionHandler : public CefV8Handler { retval = CefV8Value::CreateString(AppGetSupportDirectory()); } else if (name == "GetUserDocumentsDirectory") { retval = CefV8Value::CreateString(AppGetDocumentsDirectory()); - } else if (name == "GetRemoteDebuggingPort") { - retval = CefV8Value::CreateInt(REMOTE_DEBUGGING_PORT); } else { // Pass all messages to the browser process. Look in appshell_extensions.cpp for implementation. CefRefPtr browser = CefV8Context::GetCurrentContext()->GetBrowser(); diff --git a/appshell/appshell_extensions.cpp b/appshell/appshell_extensions.cpp index c5ac80bd8..f8d749460 100644 --- a/appshell/appshell_extensions.cpp +++ b/appshell/appshell_extensions.cpp @@ -842,6 +842,8 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { uberDict->SetList(0, dirContents); uberDict->SetList(1, allStats); responseArgs->SetList(2, uberDict); + } else if (message_name == "GetRemoteDebuggingPort") { + responseArgs->SetInt(2, g_remote_debugging_port); } else { diff --git a/appshell/appshell_extensions.js b/appshell/appshell_extensions.js index fc161e6e4..379420d27 100644 --- a/appshell/appshell_extensions.js +++ b/appshell/appshell_extensions.js @@ -640,8 +640,8 @@ if (!brackets) { * @return int. The remote debugging port used by the appshell. */ native function GetRemoteDebuggingPort(); - appshell.app.getRemoteDebuggingPort = function () { - return GetRemoteDebuggingPort(); + appshell.app.getRemoteDebuggingPort = function (callback) { + GetRemoteDebuggingPort(callback || _dummyCallback); }; diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index a6bf5aca8..b574aa4ee 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "include/cef_app.h" #include "include/cef_browser.h" #include "include/cef_command_line.h" @@ -19,9 +20,11 @@ #include "config.h" CefRefPtr g_handler; +int g_remote_debugging_port = 0; #ifdef OS_WIN bool g_force_enable_acc = false; +#undef max #endif CefRefPtr AppGetBrowser() { @@ -95,7 +98,19 @@ void AppGetSettings(CefSettings& settings, CefRefPtr command_lin command_line->GetSwitchValue(client::switches::kJavascriptFlags); // Enable dev tools - settings.remote_debugging_port = REMOTE_DEBUGGING_PORT; + CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); + if (!debugger_port.empty()) { + int port = atoi(debugger_port.ToString().c_str()); + static const int max_port_num = static_cast(std::numeric_limits::max()); + if (port > 1024 && port < max_port_num) { + g_remote_debugging_port = port; + settings.remote_debugging_port = port; + } + else { + LOG(ERROR) << "Could not enable remote debugging on port: "<< port + << "; port number must be greater than 1024 and less than " << max_port_num; + } + } std::wstring versionStr = appshell::AppGetProductVersionString(); diff --git a/appshell/config.h b/appshell/config.h index 2e1d5d397..a35b6d774 100644 --- a/appshell/config.h +++ b/appshell/config.h @@ -82,7 +82,7 @@ #endif -#define REMOTE_DEBUGGING_PORT 9234 +extern int g_remote_debugging_port; // Comment out this line to enable OS themed drawing #define DARK_UI From 76fc591b145a8fc61ed64d9b73b3736cedb24867 Mon Sep 17 00:00:00 2001 From: Gautam Jha Date: Mon, 11 Nov 2019 11:29:40 +0530 Subject: [PATCH 2/6] Addressing review comments --- appshell/cefclient.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index b574aa4ee..9a54bcc65 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "include/cef_app.h" #include "include/cef_browser.h" #include "include/cef_command_line.h" @@ -24,7 +23,6 @@ int g_remote_debugging_port = 0; #ifdef OS_WIN bool g_force_enable_acc = false; -#undef max #endif CefRefPtr AppGetBrowser() { @@ -101,14 +99,16 @@ void AppGetSettings(CefSettings& settings, CefRefPtr command_lin CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); if (!debugger_port.empty()) { int port = atoi(debugger_port.ToString().c_str()); - static const int max_port_num = static_cast(std::numeric_limits::max()); - if (port > 1024 && port < max_port_num) { + static const int max_port_num = 65535; + static const int max_reserved_port_num = 1024; + if (port > max_reserved_port_num && port < max_port_num) { g_remote_debugging_port = port; settings.remote_debugging_port = port; } else { LOG(ERROR) << "Could not enable remote debugging on port: "<< port - << "; port number must be greater than 1024 and less than " << max_port_num; + << "; port number must be greater than "<< max_reserved_port_num + << "and less than " << max_port_num; } } From 533c965bc537b30f1299d9f78237a10f3529d4c8 Mon Sep 17 00:00:00 2001 From: Gautam Jha Date: Mon, 11 Nov 2019 11:45:28 +0530 Subject: [PATCH 3/6] Addressing review comments --- appshell/cefclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index 9a54bcc65..bf57435c5 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -108,7 +108,7 @@ void AppGetSettings(CefSettings& settings, CefRefPtr command_lin else { LOG(ERROR) << "Could not enable remote debugging on port: "<< port << "; port number must be greater than "<< max_reserved_port_num - << "and less than " << max_port_num; + << " and less than " << max_port_num; } } From 436bdb2d023a89eadfdc876c90b90202aa51f98b Mon Sep 17 00:00:00 2001 From: Gautam Jha Date: Mon, 11 Nov 2019 14:59:05 +0530 Subject: [PATCH 4/6] Updating error meesage for port validation --- appshell/cefclient.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index bf57435c5..1b80422cd 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -106,9 +106,9 @@ void AppGetSettings(CefSettings& settings, CefRefPtr command_lin settings.remote_debugging_port = port; } else { - LOG(ERROR) << "Could not enable remote debugging on port: "<< port - << "; port number must be greater than "<< max_reserved_port_num - << " and less than " << max_port_num; + LOG(ERROR) << "Could not enable Remote debugging on port: "<< port + << ". Port number must be greater than "<< max_reserved_port_num + << " and less than " << max_port_num << "."; } } From 9b903fa1703a90bdc25514d537f2915b5ef6bae8 Mon Sep 17 00:00:00 2001 From: Gautam Jha Date: Mon, 11 Nov 2019 22:59:49 +0530 Subject: [PATCH 5/6] Addressing review comments from vickramdhawal, also it is not possible to use g_handler to hold remote-debugging-port as g_handler does not get initialized while we are parsing command line --- appshell/appshell_extensions.cpp | 1 + appshell/cefclient.cpp | 15 ++++++++++----- appshell/config.h | 2 -- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/appshell/appshell_extensions.cpp b/appshell/appshell_extensions.cpp index f8d749460..4723876d9 100644 --- a/appshell/appshell_extensions.cpp +++ b/appshell/appshell_extensions.cpp @@ -37,6 +37,7 @@ #include "update.h" extern std::vector gDroppedFiles; +extern int g_remote_debugging_port; namespace appshell_extensions { diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index 1b80422cd..bb2188627 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "include/cef_app.h" #include "include/cef_browser.h" #include "include/cef_command_line.h" @@ -98,12 +99,16 @@ void AppGetSettings(CefSettings& settings, CefRefPtr command_lin // Enable dev tools CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); if (!debugger_port.empty()) { - int port = atoi(debugger_port.ToString().c_str()); - static const int max_port_num = 65535; - static const int max_reserved_port_num = 1024; + const long port = strtol(debugger_port.ToString().c_str(), NULL, 10); + if (errno == ERANGE) { + LOG(ERROR) << "Error while parsing remote-debugging-port arg: "<< debugger_port.ToString(); + errno = 0; + } + static const long max_port_num = 65535; + static const long max_reserved_port_num = 1024; if (port > max_reserved_port_num && port < max_port_num) { - g_remote_debugging_port = port; - settings.remote_debugging_port = port; + g_remote_debugging_port = static_cast(port); + settings.remote_debugging_port = g_remote_debugging_port; } else { LOG(ERROR) << "Could not enable Remote debugging on port: "<< port diff --git a/appshell/config.h b/appshell/config.h index a35b6d774..9744e1973 100644 --- a/appshell/config.h +++ b/appshell/config.h @@ -82,8 +82,6 @@ #endif -extern int g_remote_debugging_port; - // Comment out this line to enable OS themed drawing #define DARK_UI #define DARK_AERO_GLASS From de74633f7a040408cf301c4837bafdd881c8dcaa Mon Sep 17 00:00:00 2001 From: Gautam Jha Date: Tue, 12 Nov 2019 11:37:19 +0530 Subject: [PATCH 6/6] More error message correction --- appshell/cefclient.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/appshell/cefclient.cpp b/appshell/cefclient.cpp index bb2188627..5d84d930b 100644 --- a/appshell/cefclient.cpp +++ b/appshell/cefclient.cpp @@ -100,20 +100,23 @@ void AppGetSettings(CefSettings& settings, CefRefPtr command_lin CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port"); if (!debugger_port.empty()) { const long port = strtol(debugger_port.ToString().c_str(), NULL, 10); - if (errno == ERANGE) { + if (errno == ERANGE || port == 0) { + LOG(ERROR) << "Could not enable Remote debugging."; LOG(ERROR) << "Error while parsing remote-debugging-port arg: "<< debugger_port.ToString(); errno = 0; } - static const long max_port_num = 65535; - static const long max_reserved_port_num = 1024; - if (port > max_reserved_port_num && port < max_port_num) { - g_remote_debugging_port = static_cast(port); - settings.remote_debugging_port = g_remote_debugging_port; - } else { - LOG(ERROR) << "Could not enable Remote debugging on port: "<< port - << ". Port number must be greater than "<< max_reserved_port_num - << " and less than " << max_port_num << "."; + static const long max_port_num = 65535; + static const long max_reserved_port_num = 1024; + if (port > max_reserved_port_num && port < max_port_num) { + g_remote_debugging_port = static_cast(port); + settings.remote_debugging_port = g_remote_debugging_port; + } + else { + LOG(ERROR) << "Could not enable Remote debugging on port: "<< port + << ". Port number must be greater than "<< max_reserved_port_num + << " and less than " << max_port_num << "."; + } } }