]> khamidou — GitHub mirrors - electron.git/commitdiff
Throw error when BrowserWindow is created before app is ready
authorCheng Zhao <zcbenz@gmail.com>
Thu, 30 Oct 2014 13:32:35 +0000 (21:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 30 Oct 2014 13:32:35 +0000 (21:32 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/browser.cc
atom/browser/browser.h
vendor/native_mate

index 1bce8f957f09ad637ed68ddc73549dcd434071f8..73527ecfc70c09c79d7ce5e9c85581b124d373f2 100644 (file)
@@ -5,6 +5,7 @@
 #include "atom/browser/api/atom_api_window.h"
 
 #include "atom/browser/api/atom_api_web_contents.h"
+#include "atom/browser/browser.h"
 #include "atom/browser/native_window.h"
 #include "atom/common/native_mate_converters/gfx_converter.h"
 #include "content/public/browser/render_process_host.h"
@@ -118,8 +119,15 @@ void Window::OnRendererResponsive() {
 }
 
 // static
-mate::Wrappable* Window::New(const mate::Dictionary& options) {
-  return new Window(options);
+mate::Wrappable* Window::New(v8::Isolate* isolate,
+                             const mate::Dictionary& options) {
+  if (Browser::Get()->is_ready()) {
+    return new Window(options);
+  } else {
+    isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8(
+        isolate, "Can not create BrowserWindow before app is ready")));
+    return nullptr;
+  }
 }
 
 void Window::Destroy() {
index 5a4785ee25016272101deb853fe5bd9c7f89ff29..cf39f104bdffa767fa676e5a315d1e1ef2e09d88 100644 (file)
@@ -31,7 +31,8 @@ class WebContents;
 class Window : public mate::EventEmitter,
                public NativeWindowObserver {
  public:
-  static mate::Wrappable* New(const mate::Dictionary& options);
+  static mate::Wrappable* New(v8::Isolate* isolate,
+                              const mate::Dictionary& options);
 
   static void BuildPrototype(v8::Isolate* isolate,
                              v8::Handle<v8::ObjectTemplate> prototype);
index 9f31177d31aed07bef26b809421b7d92638c6984..fe8c607ddf7f7cc688a8db69973419d52150cfa6 100644 (file)
@@ -13,7 +13,8 @@
 namespace atom {
 
 Browser::Browser()
-    : is_quiting_(false) {
+    : is_quiting_(false),
+      is_ready_(false) {
   WindowList::AddObserver(this);
 }
 
@@ -93,6 +94,7 @@ void Browser::WillFinishLaunching() {
 }
 
 void Browser::DidFinishLaunching() {
+  is_ready_ = true;
   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
 }
 
index 54608699bdf2c5624290d67d1890e217ce7ef23e..a3bf0c7dc6b608eb9e862e4ea436f24fdd8dd86a 100644 (file)
@@ -84,6 +84,7 @@ class Browser : public WindowListObserver {
   }
 
   bool is_quiting() const { return is_quiting_; }
+  bool is_ready() const { return is_ready_; }
 
  protected:
   // Returns the version of application bundle or executable file.
@@ -105,6 +106,9 @@ class Browser : public WindowListObserver {
   // Observers of the browser.
   ObserverList<BrowserObserver> observers_;
 
+  // Whether "ready" event has been emitted.
+  bool is_ready_;
+
   std::string version_override_;
   std::string name_override_;
 
index cc9d22292361e8b74e82a4e6a77407c17b4bfda7..b1f7cfa9da1f53158a4992428b40a780c9617632 160000 (submodule)
@@ -1 +1 @@
-Subproject commit cc9d22292361e8b74e82a4e6a77407c17b4bfda7
+Subproject commit b1f7cfa9da1f53158a4992428b40a780c9617632