From 463260b249e3c438ad51d391e9bd2fdce2ffb797 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Ali Date: Sat, 21 Oct 2017 22:21:24 +0200 Subject: [PATCH] Electron crashes if user clicks Dev Tools & Zoom options #10697 --- atom/browser/api/atom_api_web_contents.cc | 18 ++++++++++++------ atom/browser/api/atom_api_web_contents.h | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 89727cb27d0d..0cfc07e65a16 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -286,12 +286,13 @@ WebContents::WebContents(v8::Isolate* isolate, request_id_(0), background_throttling_(true), enable_devtools_(true) { + const mate::Dictionary options = mate::Dictionary::CreateEmpty(isolate); if (type == REMOTE) { web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); Init(isolate); AttachAsUserData(web_contents); + InitZoomController(web_contents, options); } else { - const mate::Dictionary options = mate::Dictionary::CreateEmpty(isolate); auto session = Session::CreateFrom(isolate, GetBrowserContext()); session_.Reset(isolate, session.ToV8()); InitWithSessionAndOptions(isolate, web_contents, session, options); @@ -392,6 +393,15 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) InitWithSessionAndOptions(isolate, web_contents, session, options); } +void WebContents::InitZoomController(content::WebContents* web_contents, + const mate::Dictionary& options) { + WebContentsZoomController::CreateForWebContents(web_contents); + zoom_controller_ = WebContentsZoomController::FromWebContents(web_contents); + double zoom_factor; + if (options.Get(options::kZoomFactor, &zoom_factor)) + zoom_controller_->SetDefaultZoomFactor(zoom_factor); +} + void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate, content::WebContents *web_contents, mate::Handle session, @@ -409,11 +419,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate, // Initialize security state client. SecurityStateTabHelper::CreateForWebContents(web_contents); // Initialize zoom controller. - WebContentsZoomController::CreateForWebContents(web_contents); - zoom_controller_ = WebContentsZoomController::FromWebContents(web_contents); - double zoom_factor; - if (options.Get(options::kZoomFactor, &zoom_factor)) - zoom_controller_->SetDefaultZoomFactor(zoom_factor); + InitZoomController(web_contents, options); web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 6aeab4e4c7a5..7a63ce3af44b 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -385,6 +385,9 @@ class WebContents : public mate::TrackableObject, // get the zoom level. void OnGetZoomLevel(IPC::Message* reply_msg); + void InitZoomController(content::WebContents* web_contents, + const mate::Dictionary& options); + v8::Global session_; v8::Global devtools_web_contents_; v8::Global debugger_;