diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 0ee56dbce726..86399ce057d2 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -409,8 +409,20 @@ void Window::SetOverlayIcon(const gfx::Image& overlay, window_->SetOverlayIcon(overlay, description); } -void Window::SetMenu(ui::SimpleMenuModel* menu) { - window_->SetMenu(menu); +void Window::SetMenu(v8::Isolate* isolate, v8::Local value) { + mate::Handle menu; + if (value->IsObject() && + mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" && + mate::ConvertFromV8(isolate, value, &menu)) { + menu_.Reset(isolate, menu.ToV8()); + window_->SetMenu(menu->model()); + } else if (value->IsNull()) { + menu_.Reset(); + window_->SetMenu(nullptr); + } else { + isolate->ThrowException(v8::Exception::TypeError( + mate::StringToV8(isolate, "Invalid Menu"))); + } } void Window::SetAutoHideMenuBar(bool auto_hide) { @@ -515,7 +527,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("capturePage", &Window::CapturePage) .SetMethod("setProgressBar", &Window::SetProgressBar) .SetMethod("setOverlayIcon", &Window::SetOverlayIcon) - .SetMethod("_setMenu", &Window::SetMenu) + .SetMethod("setMenu", &Window::SetMenu) .SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar) .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide) .SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 87eabaff7c1d..a0403dde54f6 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -25,10 +25,6 @@ class Arguments; class Dictionary; } -namespace ui { -class SimpleMenuModel; -} - namespace atom { class NativeWindow; @@ -137,7 +133,7 @@ class Window : public mate::TrackableObject, void SetProgressBar(double progress); void SetOverlayIcon(const gfx::Image& overlay, const std::string& description); - void SetMenu(ui::SimpleMenuModel* menu); + void SetMenu(v8::Isolate* isolate, v8::Local menu); void SetAutoHideMenuBar(bool auto_hide); bool IsMenuBarAutoHide(); void SetMenuBarVisibility(bool visible); @@ -156,6 +152,7 @@ class Window : public mate::TrackableObject, v8::Global web_contents_; v8::Global devtools_web_contents_; + v8::Global menu_; scoped_ptr window_; diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index 1aa84bb15c48..66e0670dc20e 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -27,12 +27,6 @@ BrowserWindow::_init = -> @on 'focus', (event) => app.emit 'browser-window-focus', event, this -BrowserWindow::setMenu = (menu) -> - throw new TypeError('Invalid menu') unless menu is null or menu?.constructor?.name is 'Menu' - - @menu = menu # Keep a reference of menu in case of GC. - @_setMenu menu - BrowserWindow.getFocusedWindow = -> windows = BrowserWindow.getAllWindows() return window for window in windows when window.isFocused()