Throw error when BrowserWindow is created before app is ready

This commit is contained in:
Cheng Zhao 2014-10-30 21:32:35 +08:00
parent 35e5c2172f
commit 25f69df341
5 changed files with 20 additions and 5 deletions

View 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() {

View 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);

View 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());
}

View 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_;

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit cc9d22292361e8b74e82a4e6a77407c17b4bfda7
Subproject commit b1f7cfa9da1f53158a4992428b40a780c9617632