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

Commit fd8fce7

Browse files
g-217swmitra
authored andcommitted
Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work (#668)
* Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work * Addressing review comments * Addressing review comments * Updating error meesage for port validation * 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 * More error message correction
1 parent 76aef0b commit fd8fce7

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

appshell/appshell_extension_handler.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class AppShellExtensionHandler : public CefV8Handler {
160160
CefString& exception) {
161161

162162
// The only messages that are handled here is getElapsedMilliseconds(),
163-
// GetCurrentLanguage(), GetApplicationSupportDirectory(), and GetRemoteDebuggingPort().
163+
// GetCurrentLanguage(), and GetApplicationSupportDirectory().
164164
// All other messages are passed to the browser process.
165165
if (name == "GetElapsedMilliseconds") {
166166
retval = CefV8Value::CreateDouble(GetElapsedMilliseconds());
@@ -170,8 +170,6 @@ class AppShellExtensionHandler : public CefV8Handler {
170170
retval = CefV8Value::CreateString(AppGetSupportDirectory());
171171
} else if (name == "GetUserDocumentsDirectory") {
172172
retval = CefV8Value::CreateString(AppGetDocumentsDirectory());
173-
} else if (name == "GetRemoteDebuggingPort") {
174-
retval = CefV8Value::CreateInt(REMOTE_DEBUGGING_PORT);
175173
} else {
176174
// Pass all messages to the browser process. Look in appshell_extensions.cpp for implementation.
177175
CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();

appshell/appshell_extensions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "update.h"
3838

3939
extern std::vector<CefString> gDroppedFiles;
40+
extern int g_remote_debugging_port;
4041

4142
namespace appshell_extensions {
4243

@@ -842,6 +843,8 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
842843
uberDict->SetList(0, dirContents);
843844
uberDict->SetList(1, allStats);
844845
responseArgs->SetList(2, uberDict);
846+
} else if (message_name == "GetRemoteDebuggingPort") {
847+
responseArgs->SetInt(2, g_remote_debugging_port);
845848
}
846849

847850
else {

appshell/appshell_extensions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ if (!brackets) {
640640
* @return int. The remote debugging port used by the appshell.
641641
*/
642642
native function GetRemoteDebuggingPort();
643-
appshell.app.getRemoteDebuggingPort = function () {
644-
return GetRemoteDebuggingPort();
643+
appshell.app.getRemoteDebuggingPort = function (callback) {
644+
GetRemoteDebuggingPort(callback || _dummyCallback);
645645
};
646646

647647

appshell/cefclient.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdlib>
88
#include <sstream>
99
#include <string>
10+
#include <errno.h>
1011
#include "include/cef_app.h"
1112
#include "include/cef_browser.h"
1213
#include "include/cef_command_line.h"
@@ -19,6 +20,7 @@
1920
#include "config.h"
2021

2122
CefRefPtr<ClientHandler> g_handler;
23+
int g_remote_debugging_port = 0;
2224

2325
#ifdef OS_WIN
2426
bool g_force_enable_acc = false;
@@ -95,7 +97,28 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<CefCommandLine> command_lin
9597
command_line->GetSwitchValue(client::switches::kJavascriptFlags);
9698

9799
// Enable dev tools
98-
settings.remote_debugging_port = REMOTE_DEBUGGING_PORT;
100+
CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port");
101+
if (!debugger_port.empty()) {
102+
const long port = strtol(debugger_port.ToString().c_str(), NULL, 10);
103+
if (errno == ERANGE || port == 0) {
104+
LOG(ERROR) << "Could not enable Remote debugging.";
105+
LOG(ERROR) << "Error while parsing remote-debugging-port arg: "<< debugger_port.ToString();
106+
errno = 0;
107+
}
108+
else {
109+
static const long max_port_num = 65535;
110+
static const long max_reserved_port_num = 1024;
111+
if (port > max_reserved_port_num && port < max_port_num) {
112+
g_remote_debugging_port = static_cast<int>(port);
113+
settings.remote_debugging_port = g_remote_debugging_port;
114+
}
115+
else {
116+
LOG(ERROR) << "Could not enable Remote debugging on port: "<< port
117+
<< ". Port number must be greater than "<< max_reserved_port_num
118+
<< " and less than " << max_port_num << ".";
119+
}
120+
}
121+
}
99122

100123
std::wstring versionStr = appshell::AppGetProductVersionString();
101124

appshell/config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282

8383
#endif
8484

85-
#define REMOTE_DEBUGGING_PORT 9234
86-
8785
// Comment out this line to enable OS themed drawing
8886
#define DARK_UI
8987
#define DARK_AERO_GLASS

0 commit comments

Comments
 (0)