From: Robo Date: Fri, 22 Jan 2016 04:57:25 +0000 (+0530) Subject: fix api and docs X-Git-Tag: v0.36.6~29^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=df5bad3f89a2946691416121b47af3b8cfae190f;p=electron.git fix api and docs --- diff --git a/atom/browser/api/atom_api_debugger.cc b/atom/browser/api/atom_api_debugger.cc index 39fb5782..76ea46df 100644 --- a/atom/browser/api/atom_api_debugger.cc +++ b/atom/browser/api/atom_api_debugger.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2015 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. @@ -33,8 +33,7 @@ void Debugger::AgentHostClosed(DevToolsAgentHost* agent_host, std::string detach_reason = "target closed"; if (replaced_with_another_client) detach_reason = "replaced with devtools"; - if (!detach_callback_.is_null()) - detach_callback_.Run(detach_reason); + Emit("detach", detach_reason); } void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host, @@ -54,8 +53,7 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host, return; base::DictionaryValue* params = nullptr; dict->GetDictionary("params", ¶ms); - if (!response_callback_.is_null()) - response_callback_.Run(method, *params); + Emit("message", method, *params); } else { auto send_command_callback = pending_requests_[id]; pending_requests_.erase(id); @@ -90,7 +88,10 @@ void Debugger::Attach(mate::Arguments* args) { } void Debugger::Detach() { + if (!agent_host_.get()) + return; agent_host_->DetachClient(); + AgentHostClosed(agent_host_.get(), false); agent_host_ = nullptr; } @@ -121,14 +122,6 @@ void Debugger::SendCommand(mate::Arguments* args) { agent_host_->DispatchProtocolMessage(json_args); } -void Debugger::OnDetach(const DetachCallback& callback) { - detach_callback_ = callback; -} - -void Debugger::OnEvent(const ResponseCallback& callback) { - response_callback_ = callback; -} - // static mate::Handle Debugger::Create( v8::Isolate* isolate, @@ -142,9 +135,7 @@ void Debugger::BuildPrototype(v8::Isolate* isolate, mate::ObjectTemplateBuilder(isolate, prototype) .SetMethod("attach", &Debugger::Attach) .SetMethod("detach", &Debugger::Detach) - .SetMethod("sendCommand", &Debugger::SendCommand) - .SetMethod("onDetach", &Debugger::OnDetach) - .SetMethod("onEvent", &Debugger::OnEvent); + .SetMethod("sendCommand", &Debugger::SendCommand); } } // namespace api diff --git a/atom/browser/api/atom_api_debugger.h b/atom/browser/api/atom_api_debugger.h index 51b5749d..894c2bc3 100644 --- a/atom/browser/api/atom_api_debugger.h +++ b/atom/browser/api/atom_api_debugger.h @@ -1,4 +1,4 @@ -// Copyright (c) 2015 GitHub, Inc. +// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. @@ -30,11 +30,8 @@ namespace api { class Debugger: public mate::TrackableObject, public content::DevToolsAgentHostClient { public: - using ResponseCallback = - base::Callback; using SendCommandCallback = base::Callback; - using DetachCallback = base::Callback; static mate::Handle Create( v8::Isolate* isolate, content::WebContents* web_contents); @@ -59,15 +56,10 @@ class Debugger: public mate::TrackableObject, void Attach(mate::Arguments* args); void Detach(); void SendCommand(mate::Arguments* args); - void OnDetach(const DetachCallback& callback); - void OnEvent(const ResponseCallback& callback); content::WebContents* web_contents_; // Weak Reference. scoped_refptr agent_host_; - DetachCallback detach_callback_; - ResponseCallback response_callback_; - PendingRequestMap pending_requests_; int previous_request_id_; diff --git a/atom/browser/api/lib/web-contents.js b/atom/browser/api/lib/web-contents.js index 2cce6e6c..b71ddf4c 100644 --- a/atom/browser/api/lib/web-contents.js +++ b/atom/browser/api/lib/web-contents.js @@ -70,6 +70,9 @@ let wrapWebContents = function(webContents) { var controller, method, name, ref1; webContents.__proto__ = EventEmitter.prototype; + // webContents.debugger is an EventEmitter. + webContents.debugger.__proto__ = EventEmitter.prototype; + // Every remote callback from renderer process would add a listenter to the // render-view-deleted event, so ignore the listenters warning. webContents.setMaxListeners(0); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index c64f1886..2bf593d1 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -836,7 +836,7 @@ when the DevTools has been closed. ### `webContents.debugger` -Debugger API serves as an alternate transport for remote debugging protocol. +Debugger API serves as an alternate transport for [remote debugging protocol][rdp]. ```javascript try { @@ -845,11 +845,11 @@ try { console.log("Debugger attach failed : ", err); }; -win.webContents.debugger.onDetach(function(reason) { +win.webContents.debugger.on('detach', function(event, reason) { console.log("Debugger detached due to : ", reason); }); -win.webContents.debugger.onEvent(function(method, params) { +win.webContents.debugger.on('message', function(event, method, params) { if (method == "Network.requestWillBeSent") { if (params.request.url == "https://www.github.com") win.webContents.debugger.detach(); @@ -861,7 +861,7 @@ win.webContents.debugger.sendCommand("Network.enable"); #### `webContents.debugger.attach([protocolVersion])` -* `protocolVersion` String - Required debugging protocol version. +* `protocolVersion` String - Requested debugging protocol version. Attaches the debugger to the `webContents`. @@ -880,19 +880,21 @@ Detaches the debugger from the `webContents`. Send given command to the debugging target. -#### `webContents.debugger.onDetach(callback)` +#### Event: 'detach' -* `callback` Function - * `reason` String - Reason for detaching debugger. +* `event` Event +* `reason` String - Reason for detaching debugger. -`callback` is fired when debugging session is terminated. This happens either when +Emitted when debugging session is terminated. This happens either when `webContents` is closed or devtools is invoked for the attached `webContents`. -#### `webContents.debugger.onEvent(callback)` +#### Event: 'message' -* `callback` Function - * `method` String - Method name. - * `params` Object - Event parameters defined by the 'parameters' - attribute in the remote debugging protocol. +* `event` Event +* `method` String - Method name. +* `params` Object - Event parameters defined by the 'parameters' + attribute in the remote debugging protocol. + +Emitted whenever debugging target issues instrumentation event. -`callback` is fired whenever debugging target issues instrumentation event. +[rdp]: https://developer.chrome.com/devtools/docs/debugger-protocol