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..773cc68a6 100644 --- a/appshell/appshell_extensions.cpp +++ b/appshell/appshell_extensions.cpp @@ -37,6 +37,8 @@ #include "update.h" extern std::vector gDroppedFiles; +extern int g_remote_debugging_port; +extern std::string g_get_remote_debugging_port_error; namespace appshell_extensions { @@ -56,6 +58,7 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { CefRefPtr argList = message->GetArgumentList(); int32 callbackId = -1; int32 error = NO_ERROR; + std::string errInfo; CefRefPtr response = CefProcessMessage::Create("invokeCallback"); CefRefPtr responseArgs = response->GetArgumentList(); @@ -842,6 +845,14 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { uberDict->SetList(0, dirContents); uberDict->SetList(1, allStats); responseArgs->SetList(2, uberDict); + } else if (message_name == "GetRemoteDebuggingPort") { + if (g_get_remote_debugging_port_error.empty() && g_remote_debugging_port > 0) { + responseArgs->SetInt(2, g_remote_debugging_port); + } + else { + responseArgs->SetNull(2); + errInfo = g_get_remote_debugging_port_error; + } } else { @@ -850,8 +861,13 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { } if (callbackId != -1) { - responseArgs->SetInt(1, error); - + if (errInfo.empty()) { + responseArgs->SetInt(1, error); + } + else { + responseArgs->SetString(1, errInfo); + } + // Send response browser->SendProcessMessage(PID_RENDERER, response); } 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..07b7fe9fe 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,6 +20,8 @@ #include "config.h" CefRefPtr g_handler; +int g_remote_debugging_port = 0; +std::string g_get_remote_debugging_port_error; #ifdef OS_WIN bool g_force_enable_acc = false; @@ -95,7 +98,26 @@ 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()) { + g_get_remote_debugging_port_error = debugger_port.ToString(); + long port = strtol(g_get_remote_debugging_port_error.c_str(), NULL, 10); + if (errno == ERANGE) { + errno = port = 0; + } + static const long max_port_num = 65535; + static const long max_reserved_port_num = 1023; + 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; + g_get_remote_debugging_port_error.clear(); + } + else { + // Setting debugging port to highest number will disable remote debugging + // As setting.remote_debugging_port has higher priority compared to command line option + settings.remote_debugging_port = max_port_num; + } + } std::wstring versionStr = appshell::AppGetProductVersionString(); diff --git a/appshell/config.h b/appshell/config.h index 2e1d5d397..9744e1973 100644 --- a/appshell/config.h +++ b/appshell/config.h @@ -82,8 +82,6 @@ #endif -#define REMOTE_DEBUGGING_PORT 9234 - // Comment out this line to enable OS themed drawing #define DARK_UI #define DARK_AERO_GLASS