Skip to content

Commit

Permalink
Throw error when BrowserWindow is created before app is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Oct 30, 2014
1 parent 35e5c21 commit 25f69df
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
12 changes: 10 additions & 2 deletions atom/browser/api/atom_api_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion atom/browser/api/atom_api_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion atom/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
namespace atom {

Browser::Browser()
: is_quiting_(false) {
: is_quiting_(false),
is_ready_(false) {
WindowList::AddObserver(this);
}

Expand Down Expand Up @@ -93,6 +94,7 @@ void Browser::WillFinishLaunching() {
}

void Browser::DidFinishLaunching() {
is_ready_ = true;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
}

Expand Down
4 changes: 4 additions & 0 deletions atom/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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_;

Expand Down
2 changes: 1 addition & 1 deletion vendor/native_mate

0 comments on commit 25f69df

Please sign in to comment.