Always initailize webContents in BrowserWindow
authorCheng Zhao <zcbenz@gmail.com>
Wed, 24 Jun 2015 11:04:08 +0000 (19:04 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 24 Jun 2015 11:04:08 +0000 (19:04 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h

index d764cee..0ee56db 100644 (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,12 +448,10 @@ 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());
-  }
-  return v8::Local<v8::Value>::New(isolate, web_contents_);
+  if (web_contents_.IsEmpty())
+    return v8::Null(isolate);
+  else
+    return v8::Local<v8::Value>::New(isolate, web_contents_);
 }
 
 v8::Local<v8::Value> Window::DevToolsWebContents(v8::Isolate* isolate) {
index 0c4cd76..87eabaf 100644 (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;