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); set_delete_view(false);
#endif #endif
WebContentsViewRelay::CreateForWebContents(web_contents->web_contents()); WebContentsViewRelay::CreateForWebContents(web_contents->web_contents());
api_web_contents_->AddObserver(this); Observe(web_contents->web_contents());
} }
WebContentsView::~WebContentsView() { WebContentsView::~WebContentsView() {
if (api_web_contents_) { if (api_web_contents_)
api_web_contents_->RemoveObserver(this);
api_web_contents_->DestroyWebContents(false /* async */); api_web_contents_->DestroyWebContents(false /* async */);
}
} }
void WebContentsView::OnCloseContents() { void WebContentsView::WebContentsDestroyed() {
api_web_contents_ = nullptr; api_web_contents_ = nullptr;
web_contents_.Reset(); web_contents_.Reset();
} }

View file

@ -6,7 +6,12 @@
#define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_VIEW_H_ #define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_VIEW_H_
#include "atom/browser/api/atom_api_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 { namespace atom {
@ -14,7 +19,7 @@ namespace api {
class WebContents; class WebContents;
class WebContentsView : public View, public ExtendedWebContentsObserver { class WebContentsView : public View, public content::WebContentsObserver {
public: public:
static mate::WrappableBase* New(mate::Arguments* args, static mate::WrappableBase* New(mate::Arguments* args,
mate::Handle<WebContents> web_contents); mate::Handle<WebContents> web_contents);
@ -28,8 +33,8 @@ class WebContentsView : public View, public ExtendedWebContentsObserver {
brightray::InspectableWebContents* iwc); brightray::InspectableWebContents* iwc);
~WebContentsView() override; ~WebContentsView() override;
// ExtendedWebContentsObserver: // content::WebContentsObserver:
void OnCloseContents() override; void WebContentsDestroyed() override;
private: private:
// Keep a reference to v8 wrapper. // Keep a reference to v8 wrapper.