Enable getting a window according to its attached devtools.

This commit is contained in:
Cheng Zhao 2014-04-04 22:28:18 +08:00
parent 86ebd6e8e3
commit f5fc26d8fc
3 changed files with 25 additions and 0 deletions

View file

@ -503,6 +503,19 @@ void Window::IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(self->window_->GetWebContents()->IsCrashed());
}
// static
void Window::GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
content::WebContents* web_contents = self->window_->GetDevToolsWebContents();
v8::Local<v8::Object> devtools = v8::Object::New();
devtools->Set(ToV8Value("processId"),
ToV8Value(web_contents->GetRenderProcessHost()->GetID()));
devtools->Set(ToV8Value("routingId"),
ToV8Value(web_contents->GetRoutingID()));
args.GetReturnValue().Set(devtools);
}
// static
void Window::LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
UNWRAP_WINDOW_AND_CHECK;
@ -686,6 +699,8 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "getProcessId", GetProcessID);
NODE_SET_PROTOTYPE_METHOD(t, "isCrashed", IsCrashed);
NODE_SET_PROTOTYPE_METHOD(t, "getDevTools", GetDevTools);
NODE_SET_PROTOTYPE_METHOD(t, "loadUrl", LoadURL);
NODE_SET_PROTOTYPE_METHOD(t, "getUrl", GetURL);
NODE_SET_PROTOTYPE_METHOD(t, "canGoBack", CanGoBack);

View file

@ -103,6 +103,9 @@ class Window : public EventEmitter,
static void GetProcessID(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsCrashed(const v8::FunctionCallbackInfo<v8::Value>& args);
// APIs for devtools.
static void GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
// APIs for NavigationController.
static void LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetURL(const v8::FunctionCallbackInfo<v8::Value>& args);

View file

@ -55,4 +55,11 @@ BrowserWindow.fromProcessIdAndRoutingId = (processId, routingId) ->
return window for window in windows when window.getProcessId() == processId and
window.getRoutingId() == routingId
BrowserWindow.fromDevTools = (processId, routingId) ->
windows = BrowserWindow.getAllWindows()
for window in windows
devtools = window.getDevTools()
return window if devtools.processId == processId and
devtools.routingId == routingId
module.exports = BrowserWindow