diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index 2672f6f67ae5..649967a2b1eb 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -60,45 +60,36 @@ void Tray::OnBalloonClosed() { Emit("balloon-closed"); } +bool Tray::IsDestroyed() const { + return !tray_icon_; +} + void Tray::Destroy() { tray_icon_.reset(); } void Tray::SetImage(mate::Arguments* args, const gfx::Image& image) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetImage(image); } void Tray::SetPressedImage(mate::Arguments* args, const gfx::Image& image) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetPressedImage(image); } void Tray::SetToolTip(mate::Arguments* args, const std::string& tool_tip) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetToolTip(tool_tip); } void Tray::SetTitle(mate::Arguments* args, const std::string& title) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetTitle(title); } void Tray::SetHighlightMode(mate::Arguments* args, bool highlight) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetHighlightMode(highlight); } void Tray::DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options) { - if (!CheckTrayLife(args)) - return; - gfx::Image icon; options.Get("icon", &icon); base::string16 title, content; @@ -112,25 +103,14 @@ void Tray::DisplayBalloon(mate::Arguments* args, } void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) { - if (!CheckTrayLife(args)) - return; tray_icon_->SetContextMenu(menu->model()); } -bool Tray::CheckTrayLife(mate::Arguments* args) { - if (!tray_icon_) { - args->ThrowError("Tray is already destroyed"); - return false; - } else { - return true; - } -} - // static void Tray::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { mate::ObjectTemplateBuilder(isolate, prototype) - .SetMethod("destroy", &Tray::Destroy) + .SetMethod("destroy", &Tray::Destroy, true) .SetMethod("setImage", &Tray::SetImage) .SetMethod("setPressedImage", &Tray::SetPressedImage) .SetMethod("setToolTip", &Tray::SetToolTip) diff --git a/atom/browser/api/atom_api_tray.h b/atom/browser/api/atom_api_tray.h index 6bbbe6d2d90c..1a4a498d16b9 100644 --- a/atom/browser/api/atom_api_tray.h +++ b/atom/browser/api/atom_api_tray.h @@ -47,6 +47,9 @@ class Tray : public mate::EventEmitter, void OnBalloonClicked() override; void OnBalloonClosed() override; + // mate::Wrappable: + bool IsDestroyed() const override; + void Destroy(); void SetImage(mate::Arguments* args, const gfx::Image& image); void SetPressedImage(mate::Arguments* args, const gfx::Image& image); @@ -57,8 +60,6 @@ class Tray : public mate::EventEmitter, void SetContextMenu(mate::Arguments* args, Menu* menu); private: - bool CheckTrayLife(mate::Arguments* args); - scoped_ptr tray_icon_; DISALLOW_COPY_AND_ASSIGN(Tray); diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d07b03760d0b..e2d1b31ae3fa 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -740,8 +740,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( v8::Isolate* isolate) { if (template_.IsEmpty()) template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate) - .SetMethod("destroy", &WebContents::Destroy) - .SetMethod("isAlive", &WebContents::IsAlive) + .SetMethod("destroy", &WebContents::Destroy, true) + .SetMethod("isAlive", &WebContents::IsAlive, true) .SetMethod("getId", &WebContents::GetID) .SetMethod("equal", &WebContents::Equal) .SetMethod("_loadUrl", &WebContents::LoadURL) @@ -775,7 +775,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("unselect", &WebContents::Unselect) .SetMethod("replace", &WebContents::Replace) .SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling) - .SetMethod("_send", &WebContents::SendIPCMessage) + .SetMethod("_send", &WebContents::SendIPCMessage, true) .SetMethod("setSize", &WebContents::SetSize) .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency) .SetMethod("isGuest", &WebContents::IsGuest) @@ -792,6 +792,10 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( isolate, v8::Local::New(isolate, template_)); } +bool WebContents::IsDestroyed() const { + return !IsAlive(); +} + void WebContents::OnRendererMessage(const base::string16& channel, const base::ListValue& args) { // webContents.emit(channel, new Event(), args...); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e6056d056574..085f82e3dd64 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -111,6 +111,7 @@ class WebContents : public mate::TrackableObject, // mate::Wrappable: mate::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) override; + bool IsDestroyed() const override; // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index c888676b1960..d5bce5891135 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -177,6 +177,10 @@ mate::Wrappable* Window::New(v8::Isolate* isolate, return new Window(isolate, options); } +bool Window::IsDestroyed() const { + return !window_ || window_->IsClosed(); +} + void Window::Destroy() { window_->CloseContents(nullptr); } @@ -477,7 +481,7 @@ v8::Local Window::DevToolsWebContents(v8::Isolate* isolate) { void Window::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { mate::ObjectTemplateBuilder(isolate, prototype) - .SetMethod("destroy", &Window::Destroy) + .SetMethod("destroy", &Window::Destroy, true) .SetMethod("close", &Window::Close) .SetMethod("isClosed", &Window::IsClosed) .SetMethod("focus", &Window::Focus) @@ -540,9 +544,9 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("showDefinitionForSelection", &Window::ShowDefinitionForSelection) #endif - .SetProperty("id", &Window::ID) - .SetProperty("webContents", &Window::WebContents) - .SetProperty("devToolsWebContents", &Window::DevToolsWebContents); + .SetProperty("id", &Window::ID, true) + .SetProperty("webContents", &Window::WebContents, true) + .SetProperty("devToolsWebContents", &Window::DevToolsWebContents, true); } } // namespace api diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 5867b1e6281a..5cdb49e41bbf 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -73,6 +73,9 @@ class Window : public mate::TrackableObject, void OnDevToolsClosed() override; void OnExecuteWindowsCommand(const std::string& command_name) override; + // mate::Wrappable: + bool IsDestroyed() const override; + private: // APIs for NativeWindow. void Destroy(); diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index e26c93513c9c..6f5040ce21d3 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -21,9 +21,8 @@ createGuest = (embedder, url, frameName, options) -> # guest is closed by user then we should prevent |embedder| from double # closing guest. closedByEmbedder = -> - embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', guest.id guest.removeListener 'closed', closedByUser - guest.destroy() unless guest.isClosed() + guest.destroy() closedByUser = -> embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', guest.id embedder.removeListener 'render-view-deleted', closedByEmbedder diff --git a/vendor/native_mate b/vendor/native_mate index cc4e2fcd94b5..41cd6d13c9c9 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit cc4e2fcd94b5a22e6720f0fba1c586a89640f1f6 +Subproject commit 41cd6d13c9c9be164f427864277f3cc36b69eb39