diff --git a/cobalt/browser/application.cc b/cobalt/browser/application.cc index 0be21cba301c..01dc6ed5bae1 100644 --- a/cobalt/browser/application.cc +++ b/cobalt/browser/application.cc @@ -985,15 +985,20 @@ Application::Application(const base::Closure& quit_closure, bool should_preload, #endif // ENABLE_WEBDRIVER #if defined(ENABLE_DEBUGGER) - int remote_debugging_port = GetRemoteDebuggingPort(); - if (remote_debugging_port == 0) { - DLOG(INFO) << "Remote web debugger disabled because " - << switches::kRemoteDebuggingPort << " is 0."; + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableWebDebugger)) { + LOG(INFO) << "Remote web debugger disabled."; } else { - debug_web_server_.reset(new debug::remote::DebugWebServer( - remote_debugging_port, GetDevServersListenIp(), - base::Bind(&BrowserModule::CreateDebugClient, - base::Unretained(browser_module_.get())))); + int remote_debugging_port = GetRemoteDebuggingPort(); + if (remote_debugging_port == 0) { + LOG(INFO) << "Remote web debugger disabled because " + << switches::kRemoteDebuggingPort << " is 0."; + } else { + debug_web_server_.reset(new debug::remote::DebugWebServer( + remote_debugging_port, GetDevServersListenIp(), + base::Bind(&BrowserModule::CreateDebugClient, + base::Unretained(browser_module_.get())))); + } } #endif // ENABLE_DEBUGGER diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index d0e9f37f24e8..d83200f7f2bf 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -620,6 +620,10 @@ void BrowserModule::Navigate(const GURL& url_reference) { } options.debugger_state = debugger_state_.get(); + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableWebDebugger)) { + options.enable_debugger = true; + } #endif // ENABLE_DEBUGGER // Pass down this callback from to Web module. @@ -1418,9 +1422,14 @@ std::unique_ptr BrowserModule::CreateDebugClient( FROM_HERE, base::Bind(&BrowserModule::GetDebugDispatcherInternal, base::Unretained(this), base::Unretained(&debug_dispatcher))); - DCHECK(debug_dispatcher); - return std::unique_ptr( - new debug::DebugClient(debug_dispatcher, delegate)); + if (debug_dispatcher) { + return std::unique_ptr( + new debug::DebugClient(debug_dispatcher, delegate)); + } else { + LOG(ERROR) + << "Debugger connected but debugging the main web module is disabled."; + return nullptr; + } } void BrowserModule::GetDebugDispatcherInternal( diff --git a/cobalt/browser/debug_console.cc b/cobalt/browser/debug_console.cc index b08fed0b8336..f540eec8f6eb 100644 --- a/cobalt/browser/debug_console.cc +++ b/cobalt/browser/debug_console.cc @@ -205,7 +205,14 @@ bool DebugConsole::FilterOnScreenKeyboardInputEvent( void DebugConsole::CycleMode() { base::AutoLock lock(mode_mutex_); - mode_ = (mode_ + 1) % debug::console::kDebugConsoleModeCount; + int number_of_modes = debug::console::kDebugConsoleModeCount; +#if defined(ENABLE_DEBUGGER) + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableWebDebugger)) { + number_of_modes = (debug::console::kDebugConsoleModeHud + 1); + } +#endif + mode_ = (mode_ + 1) % number_of_modes; } debug::console::DebugConsoleMode DebugConsole::GetMode() { diff --git a/cobalt/browser/switches.cc b/cobalt/browser/switches.cc index db916a58fb05..70bb7561cd1a 100644 --- a/cobalt/browser/switches.cc +++ b/cobalt/browser/switches.cc @@ -36,6 +36,9 @@ const char kDevServersListenIpHelp[] = "IPv4), and to listen to LOOPBACK use \"::1\" (\"127.0.0.1\" for IPv4)"; #if defined(ENABLE_DEBUGGER) +const char kDisableWebDebugger[] = "disable_web_debugger"; +const char kDisableWebDebuggerHelp[] = "Disable support for the web debugger"; + const char kRemoteDebuggingPort[] = "remote_debugging_port"; const char kRemoteDebuggingPortHelp[] = "Remote web debugger is served from the specified port. If 0, then the " @@ -439,8 +442,9 @@ std::string HelpMessage() { {kDebugConsoleMode, kDebugConsoleModeHelp}, {kDevServersListenIp, kDevServersListenIpHelp}, #if defined(ENABLE_DEBUGGER) - {kWaitForWebDebugger, kWaitForWebDebuggerHelp}, + {kDisableWebDebugger, kDisableWebDebuggerHelp}, {kRemoteDebuggingPort, kRemoteDebuggingPortHelp}, + {kWaitForWebDebugger, kWaitForWebDebuggerHelp}, #endif // ENABLE_DEBUGGER {kDisableImageAnimations, kDisableImageAnimationsHelp}, {kForceDeterministicRendering, kForceDeterministicRenderingHelp}, diff --git a/cobalt/browser/switches.h b/cobalt/browser/switches.h index a6636bb5e7b3..8cef3d8a6d07 100644 --- a/cobalt/browser/switches.h +++ b/cobalt/browser/switches.h @@ -30,6 +30,8 @@ extern const char kDevServersListenIp[]; extern const char kDevServersListenIpHelp[]; #if defined(ENABLE_DEBUGGER) +extern const char kDisableWebDebugger[]; +extern const char kDisableWebDebuggerHelp[]; extern const char kRemoteDebuggingPort[]; extern const char kRemoteDebuggingPortHelp[]; extern const char kWaitForWebDebugger[]; diff --git a/cobalt/browser/web_module.cc b/cobalt/browser/web_module.cc index 7e5f31b2922c..c955f83591d4 100644 --- a/cobalt/browser/web_module.cc +++ b/cobalt/browser/web_module.cc @@ -142,8 +142,7 @@ class WebModule::Impl { #if defined(ENABLE_DEBUGGER) debug::backend::DebugDispatcher* debug_dispatcher() { - DCHECK(debug_module_); - return debug_module_->debug_dispatcher(); + return debug_module_ ? debug_module_->debug_dispatcher() : nullptr; } #endif // ENABLE_DEBUGGER @@ -229,7 +228,13 @@ class WebModule::Impl { void FreezeDebugger( std::unique_ptr* debugger_state) { - if (debugger_state) *debugger_state = debug_module_->Freeze(); + if (debugger_state) { + if (debug_module_) { + *debugger_state = debug_module_->Freeze(); + } else { + debugger_state->reset(); + } + } } #endif // defined(ENABLE_DEBUGGER) @@ -613,7 +618,7 @@ WebModule::Impl::Impl(web::Context* web_context, const ConstructionData& data) web_context_->global_environment()->AddRoot(media_source_registry_.get()); #if defined(ENABLE_DEBUGGER) - if (data.options.wait_for_web_debugger) { + if (data.options.enable_debugger && data.options.wait_for_web_debugger) { // Post a task that blocks the message loop and waits for the web debugger. // This must be posted before the the window's task to load the document. waiting_for_web_debugger_->store(true); @@ -718,13 +723,15 @@ WebModule::Impl::Impl(web::Context* web_context, const ConstructionData& data) } #if defined(ENABLE_DEBUGGER) - debug_overlay_.reset( - new debug::backend::RenderOverlay(render_tree_produced_callback_)); - - debug_module_.reset(new debug::backend::DebugModule( - &debugger_hooks_, web_context_->global_environment(), - debug_overlay_.get(), resource_provider_, window_, - data.options.debugger_state)); + if (data.options.enable_debugger) { + debug_overlay_.reset( + new debug::backend::RenderOverlay(render_tree_produced_callback_)); + + debug_module_.reset(new debug::backend::DebugModule( + &debugger_hooks_, web_context_->global_environment(), + debug_overlay_.get(), resource_provider_, window_, + data.options.debugger_state)); + } #endif // ENABLE_DEBUGGER report_unload_timing_info_callback_ = @@ -955,7 +962,11 @@ void WebModule::Impl::OnRenderTreeProduced( last_render_tree_produced_time_)); #if defined(ENABLE_DEBUGGER) - debug_overlay_->OnRenderTreeProduced(layout_results_with_callback); + if (debug_overlay_) { + debug_overlay_->OnRenderTreeProduced(layout_results_with_callback); + } else { + render_tree_produced_callback_.Run(layout_results_with_callback); + } #else // ENABLE_DEBUGGER render_tree_produced_callback_.Run(layout_results_with_callback); #endif // ENABLE_DEBUGGER @@ -1036,12 +1047,13 @@ void WebModule::Impl::CreateWindowDriver( #if defined(ENABLE_DEBUGGER) void WebModule::Impl::WaitForWebDebugger() { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - DCHECK(debug_module_); - LOG(WARNING) << "\n-------------------------------------" - "\n Waiting for web debugger to connect " - "\n-------------------------------------"; - // This blocks until the web debugger connects. - debug_module_->debug_dispatcher()->SetPaused(true); + if (debug_module_) { + LOG(WARNING) << "\n-------------------------------------" + "\n Waiting for web debugger to connect " + "\n-------------------------------------"; + // This blocks until the web debugger connects. + debug_module_->debug_dispatcher()->SetPaused(true); + } waiting_for_web_debugger_->store(false); } #endif // defined(ENABLE_DEBUGGER) @@ -1132,7 +1144,7 @@ void WebModule::Impl::Conceal(render_tree::ResourceProvider* resource_provider, #if defined(ENABLE_DEBUGGER) // The debug overlay may be holding onto a render tree, clear that out. - debug_overlay_->ClearInput(); + if (debug_overlay_) debug_overlay_->ClearInput(); #endif // Force garbage collection in |javascript_engine|. diff --git a/cobalt/browser/web_module.h b/cobalt/browser/web_module.h index 8c28dcebcbad..28fa71409d5d 100644 --- a/cobalt/browser/web_module.h +++ b/cobalt/browser/web_module.h @@ -229,6 +229,8 @@ class WebModule : public base::MessageLoop::DestructionObserver, bool limit_performance_timer_resolution = true; #if defined(ENABLE_DEBUGGER) + // Whether a debugger should be started for this WebModule. + bool enable_debugger = false; // Whether the debugger should block until remote devtools connects. bool wait_for_web_debugger = false; diff --git a/cobalt/debug/console/content/debugger_client.js b/cobalt/debug/console/content/debugger_client.js index 2ceb3e0b70ab..daaa47b60205 100644 --- a/cobalt/debug/console/content/debugger_client.js +++ b/cobalt/debug/console/content/debugger_client.js @@ -16,6 +16,7 @@ function DebuggerClient() { this.DEBUGGER_DETACHED = 0; this.DEBUGGER_ATTACHING = 1; this.DEBUGGER_ATTACHED = 2; + this.DEBUGGER_DISABLED = 3; this.scripts = []; this.attachState = this.DEBUGGER_DETACHED; this.onAttachCallback = this.onAttach.bind(this); @@ -25,11 +26,11 @@ function DebuggerClient() { // Attaches to the debugger and listens for debug events. // Enables the domains we care about here. -DebuggerClient.prototype.attach = function() { +DebuggerClient.prototype.attach = function () { if (this.attachState == this.DEBUGGER_DETACHED) { this.attachState = this.DEBUGGER_ATTACHING; printToMessageLog(MessageLog.INTERACTIVE, - 'Attempting to attach to debugger...'); + 'Attempting to attach to debugger...'); this.scripts = []; debugHub.onEvent.addListener(this.onEventCallback); debugHub.attach(this.onAttachCallback); @@ -38,14 +39,14 @@ DebuggerClient.prototype.attach = function() { this.sendCommand('Runtime.enable'); } else if (this.attachState == this.DEBUGGER_ATTACHING) { printToMessageLog(MessageLog.INTERACTIVE, - 'Still attempting to attach to debugger...'); + 'Still attempting to attach to debugger...'); } } -// Local method to list the parsed scripts the client has been notifed of +// Local method to list the parsed scripts the client has been notified of // via the |Debugger.scriptParsed| event. Maps the possibly very long script id // from the debug dispatcher to a more human-readable 0-based index. -DebuggerClient.prototype.getScripts = function(scriptId) { +DebuggerClient.prototype.getScripts = function (scriptId) { for (var i in this.scripts) { var index = this.pad(i, 3); var scriptUrl = this.scripts[i].url; @@ -57,7 +58,7 @@ DebuggerClient.prototype.getScripts = function(scriptId) { // Each debugger command has an associated callback to get the result. -DebuggerClient.prototype.getScriptSource = function(scriptId) { +DebuggerClient.prototype.getScriptSource = function (scriptId) { // If the id looks like an index into the local script array, look it up there. if (scriptId >= 0 && scriptId < this.scripts.length) { scriptId = this.scripts[scriptId].scriptId; @@ -69,7 +70,7 @@ DebuggerClient.prototype.getScriptSource = function(scriptId) { this.sendCommand(method, params, callback); } -DebuggerClient.prototype.getScriptSourceCallback = function(result) { +DebuggerClient.prototype.getScriptSourceCallback = function (result) { var scriptSource = result.scriptSource; var lines = scriptSource.split('\n'); for (var i = 0; i < lines.length; i++) { @@ -78,7 +79,7 @@ DebuggerClient.prototype.getScriptSourceCallback = function(result) { } } -DebuggerClient.prototype.evaluate = function(expression, callback) { +DebuggerClient.prototype.evaluate = function (expression, callback) { var method = 'Runtime.evaluate'; var params = {}; params.contextId = this.executionContext; @@ -92,8 +93,8 @@ DebuggerClient.prototype.evaluate = function(expression, callback) { // All debugger commands are routed through this method. Converts the command // parameters into a JSON string to pass to the debug dispatcher. -DebuggerClient.prototype.sendCommand = function(method, commandParams, - callback) { +DebuggerClient.prototype.sendCommand = function (method, commandParams, + callback) { var jsonParams = JSON.stringify(commandParams); var responseCallback = this.responseCallback.bind(this, method, callback); debugHub.sendCommand(method, jsonParams, responseCallback); @@ -102,15 +103,15 @@ DebuggerClient.prototype.sendCommand = function(method, commandParams, // All command responses are routed through this method. Parses the JSON // response from the debug dispatcher, checks for errors and passes on to the // command-specific callback to handle the result. -DebuggerClient.prototype.responseCallback = function(method, callback, - responseString) { +DebuggerClient.prototype.responseCallback = function (method, callback, + responseString) { var response = JSON.parse(responseString); if (response && response.error) { printToMessageLog( - MessageLog.ERROR, - '[ERROR(' + response.error.code + '):' + method + '] ' + - response.error.message); + MessageLog.ERROR, + '[ERROR(' + response.error.code + '):' + method + '] ' + + response.error.message); } else if (callback) { if (response) { callback(response.result); @@ -122,10 +123,10 @@ DebuggerClient.prototype.responseCallback = function(method, callback, //-- Events. -DebuggerClient.prototype.onAttach = function() { +DebuggerClient.prototype.onAttach = function () { if (debugHub.lastError) { printToMessageLog(MessageLog.WARNING, 'Could not attach to debugger.'); - this.attachState = this.DEBUGGER_DETACHED; + this.attachState = this.DEBUGGER_DISABLED; } else { printToMessageLog(MessageLog.INTERACTIVE, 'Debugger attached.'); this.attachState = this.DEBUGGER_ATTACHED; @@ -135,7 +136,7 @@ DebuggerClient.prototype.onAttach = function() { // All events generated by the debug dispatcher are routed through this method. // Parses the JSON string and passes on to the appropriate handler according to // the method name. -DebuggerClient.prototype.onEvent = function(method, paramString) { +DebuggerClient.prototype.onEvent = function (method, paramString) { var params = JSON.parse(paramString); if (method == 'Console.messageAdded') { this.onConsoleMessageAdded(params) @@ -152,32 +153,32 @@ DebuggerClient.prototype.onEvent = function(method, paramString) { } } -DebuggerClient.prototype.onDetached = function() { +DebuggerClient.prototype.onDetached = function () { printToMessageLog(MessageLog.INTERACTIVE, 'Debugger detached.'); this.attachState = this.DEBUGGER_DETACHED; } -DebuggerClient.prototype.onExecutionContextCreated = function(params) { +DebuggerClient.prototype.onExecutionContextCreated = function (params) { this.executionContext = params.context.id; printToMessageLog(MessageLog.INFO, - 'Execution context created: ' + this.executionContext); + 'Execution context created: ' + this.executionContext); } -DebuggerClient.prototype.onLogEntryAdded = function(params) { +DebuggerClient.prototype.onLogEntryAdded = function (params) { printToMessageLog(params.entry.level, params.entry.text); } -DebuggerClient.prototype.onConsoleMessageAdded = function(params) { +DebuggerClient.prototype.onConsoleMessageAdded = function (params) { // Translate Console.messageAdded params to Runtime.consoleAPICalled params. var consoleApiParams = { type: params.message.level, - args: [ { type: 'string', value: params.message.text } ] + args: [{ type: 'string', value: params.message.text }] }; this.onConsoleApiCalled(consoleApiParams); } -DebuggerClient.prototype.onConsoleApiCalled = function(params) { +DebuggerClient.prototype.onConsoleApiCalled = function (params) { var severity = params.type; if (severity === "assert") { severity = MessageLog.ERROR; @@ -200,13 +201,13 @@ DebuggerClient.prototype.onConsoleApiCalled = function(params) { printToMessageLog(MessageLog.CONSOLE + severity, message); } -DebuggerClient.prototype.onScriptParsed = function(params) { +DebuggerClient.prototype.onScriptParsed = function (params) { this.scripts.push(params); } //--- Utils. -DebuggerClient.prototype.pad = function(number, minLength) { +DebuggerClient.prototype.pad = function (number, minLength) { var result = number.toString(); while (result.length < minLength) { result = ' ' + result; diff --git a/cobalt/renderer/backend/egl/graphics_system.cc b/cobalt/renderer/backend/egl/graphics_system.cc index f4ed70a06cbf..cc35c7ace61c 100644 --- a/cobalt/renderer/backend/egl/graphics_system.cc +++ b/cobalt/renderer/backend/egl/graphics_system.cc @@ -200,7 +200,6 @@ GraphicsSystemEGL::GraphicsSystemEGL( } GraphicsSystemEGL::~GraphicsSystemEGL() { - LOG(INFO) << "GraphicsSystemEGL::~GraphicsSystemEGL()"; if (window_surface_ != EGL_NO_SURFACE) { EGL_CALL_SIMPLE(eglDestroySurface(display_, window_surface_)); } @@ -208,7 +207,6 @@ GraphicsSystemEGL::~GraphicsSystemEGL() { EGL_CALL_SIMPLE(eglTerminate(display_)); EGLint result = EGL_CALL_SIMPLE(eglGetError()); if (result != EGL_SUCCESS) LOG(INFO) << "eglTerminate returned " << result; - LOG(INFO) << "GraphicsSystemEGL::~GraphicsSystemEGL() done"; } std::unique_ptr GraphicsSystemEGL::CreateDisplay( diff --git a/cobalt/script/v8c/v8c_script_debugger.cc b/cobalt/script/v8c/v8c_script_debugger.cc index 9a9c3eaf8dd1..f9b4733286f6 100644 --- a/cobalt/script/v8c/v8c_script_debugger.cc +++ b/cobalt/script/v8c/v8c_script_debugger.cc @@ -138,8 +138,6 @@ V8cScriptDebugger::V8cScriptDebugger( sizeof(kContextName) - 1))); } -V8cScriptDebugger::~V8cScriptDebugger() {} - void V8cScriptDebugger::Attach(const std::string& state) { DCHECK(!inspector_session_); inspector_session_ = diff --git a/cobalt/script/v8c/v8c_script_debugger.h b/cobalt/script/v8c/v8c_script_debugger.h index ac71e774b775..95c76d34d529 100644 --- a/cobalt/script/v8c/v8c_script_debugger.h +++ b/cobalt/script/v8c/v8c_script_debugger.h @@ -34,8 +34,9 @@ class V8cScriptDebugger : public ScriptDebugger, public: V8cScriptDebugger(V8cGlobalEnvironment* v8c_global_environment, Delegate* delegate); - ~V8cScriptDebugger() override; + ~V8cScriptDebugger() override {} + // From ScriptDebugger. void Attach(const std::string& state) override; std::string Detach() override; @@ -60,6 +61,7 @@ class V8cScriptDebugger : public ScriptDebugger, PauseOnExceptionsState SetPauseOnExceptions( PauseOnExceptionsState state) override; + // From base::DebuggerHooks. void AsyncTaskScheduled(const void* task, const std::string& name, bool recurring) override; void AsyncTaskStarted(const void* task) override; @@ -67,7 +69,7 @@ class V8cScriptDebugger : public ScriptDebugger, void AsyncTaskCanceled(const void* task) override; void AllAsyncTasksCanceled() override; - // v8_inspector::V8InspectorClient implementation. + // From v8_inspector::V8InspectorClient. void runMessageLoopOnPause(int contextGroupId) override; void quitMessageLoopOnPause() override; void runIfWaitingForDebugger(int contextGroupId) override; @@ -82,7 +84,7 @@ class V8cScriptDebugger : public ScriptDebugger, unsigned lineNumber, unsigned columnNumber, v8_inspector::V8StackTrace*) override; - // v8_inspector::V8Inspector::Channel implementation. + // From v8_inspector::V8Inspector::Channel. void sendResponse( int callId, std::unique_ptr message) override; void sendNotification(