From ca40ea8e2fc179668b8d9c8b429a94cb0f740781 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 1 Oct 2015 14:41:01 +0800 Subject: [PATCH] Inherit owner window in devtools --- atom/browser/api/atom_api_web_contents.cc | 5 +++++ atom/browser/common_web_contents_delegate.cc | 6 +++++- atom/browser/common_web_contents_delegate.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index bbe244da7e88..f6433ca635cd 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -506,6 +506,11 @@ void WebContents::DevToolsOpened() { isolate(), managed_web_contents()->GetDevToolsWebContents()); devtools_web_contents_.Reset(isolate(), handle.ToV8()); + // Inherit owner window in devtools. + if (owner_window()) + handle->SetOwnerWindow(managed_web_contents()->GetDevToolsWebContents(), + owner_window()); + Emit("devtools-opened"); } diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 518d4f650a63..8b7a159dd7d6 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -136,7 +136,11 @@ void CommonWebContentsDelegate::InitWithWebContents( } void CommonWebContentsDelegate::SetOwnerWindow(NativeWindow* owner_window) { - content::WebContents* web_contents = GetWebContents(); + SetOwnerWindow(GetWebContents(), owner_window); +} + +void CommonWebContentsDelegate::SetOwnerWindow( + content::WebContents* web_contents, NativeWindow* owner_window) { owner_window_ = owner_window->GetWeakPtr(); NativeWindowRelay* relay = new NativeWindowRelay(owner_window_); web_contents->SetUserData(relay->key, relay); diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index 3a5be180dcc1..ee18f36660ee 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -34,6 +34,8 @@ class CommonWebContentsDelegate // Set the window as owner window. void SetOwnerWindow(NativeWindow* owner_window); + void SetOwnerWindow(content::WebContents* web_contents, + NativeWindow* owner_window); // Destroy the managed InspectableWebContents object. void DestroyWebContents();