WebContents may be managed by multiple owners

This commit is contained in:
Cheng Zhao 2018-05-21 10:50:26 +09:00
parent 300c7a4b04
commit 595b0663b2
2 changed files with 12 additions and 9 deletions

View file

@ -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();
}

View file

@ -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<WebContents> 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.