From: Cheng Zhao Date: Thu, 2 May 2013 10:19:07 +0000 (+0800) Subject: Add 'closed' and 'destroyed' event for Window. X-Git-Tag: v0.1.0~223 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=21df63fc9b0b17c1e737f3d7a9f92a41e0056578;p=electron.git Add 'closed' and 'destroyed' event for Window. --- diff --git a/browser/api/atom_api_event_emitter.cc b/browser/api/atom_api_event_emitter.cc index 5d2efcfb..48f27cdd 100644 --- a/browser/api/atom_api_event_emitter.cc +++ b/browser/api/atom_api_event_emitter.cc @@ -32,6 +32,11 @@ EventEmitter::EventEmitter(v8::Handle wrapper) { EventEmitter::~EventEmitter() { } +bool EventEmitter::Emit(const std::string& name) { + base::ListValue args; + return Emit(name, &args); +} + bool EventEmitter::Emit(const std::string& name, base::ListValue* args) { v8::HandleScope scope; diff --git a/browser/api/atom_api_event_emitter.h b/browser/api/atom_api_event_emitter.h index 4071355d..cc48f5c2 100644 --- a/browser/api/atom_api_event_emitter.h +++ b/browser/api/atom_api_event_emitter.h @@ -26,6 +26,7 @@ class EventEmitter : public node::ObjectWrap { virtual ~EventEmitter(); // Emit an event and returns whether the handler has called preventDefault(). + bool Emit(const std::string& name); bool Emit(const std::string& name, base::ListValue* args); // Small accessor to return handle_, this follows Google C++ Style. diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 65343e62..0b00d780 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -34,7 +34,7 @@ v8::Handle UTF16ToV8String(const string16& s) { return v8::String::New(reinterpret_cast(s.data()), s.size()); } -} +} // namespace Window::Window(v8::Handle wrapper, base::DictionaryValue* options) : EventEmitter(wrapper), @@ -44,6 +44,8 @@ Window::Window(v8::Handle wrapper, base::DictionaryValue* options) } Window::~Window() { + Emit("destroyed"); + window_->RemoveObserver(this); } @@ -55,11 +57,12 @@ void Window::OnPageTitleUpdated(bool* prevent_default, } void Window::WillCloseWindow(bool* prevent_default) { - base::ListValue args; - *prevent_default = Emit("close", &args); + *prevent_default = Emit("close"); } void Window::OnWindowClosed() { + Emit("closed"); + // Free memory immediately when window is closed. delete this; }