Always initailize webContents in BrowserWindow

This commit is contained in:
Cheng Zhao 2015-06-24 19:04:08 +08:00
parent 8c83dfe918
commit f198148c79
2 changed files with 14 additions and 6 deletions

View file

@ -49,6 +49,13 @@ Window::~Window() {
Destroy();
}
void Window::AfterInit(v8::Isolate* isolate) {
mate::TrackableObject<Window>::AfterInit(isolate);
auto web_contents = window_->managed_web_contents();
auto handle = WebContents::CreateFrom(isolate, web_contents);
web_contents_.Reset(isolate, handle.ToV8());
}
void Window::OnPageTitleUpdated(bool* prevent_default,
const std::string& title) {
*prevent_default = Emit("page-title-updated", title);
@ -441,11 +448,9 @@ int32_t Window::ID() const {
}
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
if (web_contents_.IsEmpty()) {
auto handle =
WebContents::CreateFrom(isolate, window_->managed_web_contents());
web_contents_.Reset(isolate, handle.ToV8());
}
if (web_contents_.IsEmpty())
return v8::Null(isolate);
else
return v8::Local<v8::Value>::New(isolate, web_contents_);
}

View file

@ -52,6 +52,9 @@ class Window : public mate::TrackableObject<Window>,
explicit Window(const mate::Dictionary& options);
virtual ~Window();
// mate::Wrappable:
void AfterInit(v8::Isolate* isolate) override;
// NativeWindowObserver:
void OnPageTitleUpdated(bool* prevent_default,
const std::string& title) override;