From 25f69df341ca82f2b535dd8773acb4a48bee49c0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 30 Oct 2014 21:32:35 +0800 Subject: [PATCH] Throw error when BrowserWindow is created before app is ready --- atom/browser/api/atom_api_window.cc | 12 ++++++++++-- atom/browser/api/atom_api_window.h | 3 ++- atom/browser/browser.cc | 4 +++- atom/browser/browser.h | 4 ++++ vendor/native_mate | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 1bce8f957f09..73527ecfc70c 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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() { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 5a4785ee2501..cf39f104bdff 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -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 prototype); diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 9f31177d31ae..fe8c607ddf7f 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -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()); } diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 54608699bdf2..a3bf0c7dc6b6 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -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 observers_; + // Whether "ready" event has been emitted. + bool is_ready_; + std::string version_override_; std::string name_override_; diff --git a/vendor/native_mate b/vendor/native_mate index cc9d22292361..b1f7cfa9da1f 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit cc9d22292361e8b74e82a4e6a77407c17b4bfda7 +Subproject commit b1f7cfa9da1f53158a4992428b40a780c9617632