From 595b0663b23438327a9067c7fa9e701733f05cb3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 21 May 2018 10:50:26 +0900 Subject: [PATCH] WebContents may be managed by multiple owners --- atom/browser/api/atom_api_web_contents_view.cc | 8 +++----- atom/browser/api/atom_api_web_contents_view.h | 13 +++++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents_view.cc b/atom/browser/api/atom_api_web_contents_view.cc index e0fb14d16d8..de27f8eeed6 100644 --- a/atom/browser/api/atom_api_web_contents_view.cc +++ b/atom/browser/api/atom_api_web_contents_view.cc @@ -59,17 +59,15 @@ WebContentsView::WebContentsView(v8::Isolate* isolate, set_delete_view(false); #endif WebContentsViewRelay::CreateForWebContents(web_contents->web_contents()); - api_web_contents_->AddObserver(this); + Observe(web_contents->web_contents()); } WebContentsView::~WebContentsView() { - if (api_web_contents_) { - api_web_contents_->RemoveObserver(this); + if (api_web_contents_) api_web_contents_->DestroyWebContents(false /* async */); - } } -void WebContentsView::OnCloseContents() { +void WebContentsView::WebContentsDestroyed() { api_web_contents_ = nullptr; web_contents_.Reset(); } diff --git a/atom/browser/api/atom_api_web_contents_view.h b/atom/browser/api/atom_api_web_contents_view.h index c29657d870f..d502918a155 100644 --- a/atom/browser/api/atom_api_web_contents_view.h +++ b/atom/browser/api/atom_api_web_contents_view.h @@ -6,7 +6,12 @@ #define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_VIEW_H_ #include "atom/browser/api/atom_api_view.h" -#include "atom/browser/api/atom_api_web_contents.h" +#include "content/public/browser/web_contents_observer.h" +#include "native_mate/handle.h" + +namespace brightray { +class InspectableWebContents; +} namespace atom { @@ -14,7 +19,7 @@ namespace api { class WebContents; -class WebContentsView : public View, public ExtendedWebContentsObserver { +class WebContentsView : public View, public content::WebContentsObserver { public: static mate::WrappableBase* New(mate::Arguments* args, mate::Handle web_contents); @@ -28,8 +33,8 @@ class WebContentsView : public View, public ExtendedWebContentsObserver { brightray::InspectableWebContents* iwc); ~WebContentsView() override; - // ExtendedWebContentsObserver: - void OnCloseContents() override; + // content::WebContentsObserver: + void WebContentsDestroyed() override; private: // Keep a reference to v8 wrapper.