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(); 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, void Window::OnPageTitleUpdated(bool* prevent_default,
const std::string& title) { const std::string& title) {
*prevent_default = Emit("page-title-updated", 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) { v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
if (web_contents_.IsEmpty()) { if (web_contents_.IsEmpty())
auto handle = return v8::Null(isolate);
WebContents::CreateFrom(isolate, window_->managed_web_contents()); else
web_contents_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, web_contents_); 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); explicit Window(const mate::Dictionary& options);
virtual ~Window(); virtual ~Window();
// mate::Wrappable:
void AfterInit(v8::Isolate* isolate) override;
// NativeWindowObserver: // NativeWindowObserver:
void OnPageTitleUpdated(bool* prevent_default, void OnPageTitleUpdated(bool* prevent_default,
const std::string& title) override; const std::string& title) override;