Throw error when BrowserWindow is created before app is ready
This commit is contained in:
parent
35e5c2172f
commit
25f69df341
5 changed files with 20 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "atom/browser/api/atom_api_window.h"
|
#include "atom/browser/api/atom_api_window.h"
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
@ -118,8 +119,15 @@ void Window::OnRendererResponsive() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Wrappable* Window::New(const mate::Dictionary& options) {
|
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
||||||
|
const mate::Dictionary& options) {
|
||||||
|
if (Browser::Get()->is_ready()) {
|
||||||
return new Window(options);
|
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() {
|
void Window::Destroy() {
|
||||||
|
|
|
@ -31,7 +31,8 @@ class WebContents;
|
||||||
class Window : public mate::EventEmitter,
|
class Window : public mate::EventEmitter,
|
||||||
public NativeWindowObserver {
|
public NativeWindowObserver {
|
||||||
public:
|
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,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Handle<v8::ObjectTemplate> prototype);
|
v8::Handle<v8::ObjectTemplate> prototype);
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
Browser::Browser()
|
Browser::Browser()
|
||||||
: is_quiting_(false) {
|
: is_quiting_(false),
|
||||||
|
is_ready_(false) {
|
||||||
WindowList::AddObserver(this);
|
WindowList::AddObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ void Browser::WillFinishLaunching() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::DidFinishLaunching() {
|
void Browser::DidFinishLaunching() {
|
||||||
|
is_ready_ = true;
|
||||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
|
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ class Browser : public WindowListObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_quiting() const { return is_quiting_; }
|
bool is_quiting() const { return is_quiting_; }
|
||||||
|
bool is_ready() const { return is_ready_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Returns the version of application bundle or executable file.
|
// Returns the version of application bundle or executable file.
|
||||||
|
@ -105,6 +106,9 @@ class Browser : public WindowListObserver {
|
||||||
// Observers of the browser.
|
// Observers of the browser.
|
||||||
ObserverList<BrowserObserver> observers_;
|
ObserverList<BrowserObserver> observers_;
|
||||||
|
|
||||||
|
// Whether "ready" event has been emitted.
|
||||||
|
bool is_ready_;
|
||||||
|
|
||||||
std::string version_override_;
|
std::string version_override_;
|
||||||
std::string name_override_;
|
std::string name_override_;
|
||||||
|
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit cc9d22292361e8b74e82a4e6a77407c17b4bfda7
|
Subproject commit b1f7cfa9da1f53158a4992428b40a780c9617632
|
Loading…
Reference in a new issue