1 // Copyright (c) 2013 GitHub, Inc.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
5 #include "atom/browser/api/atom_api_window.h"
6 #include "atom/common/native_mate_converters/value_converter.h"
8 #include "atom/browser/api/atom_api_menu.h"
9 #include "atom/browser/api/atom_api_web_contents.h"
10 #include "atom/browser/browser.h"
11 #include "atom/browser/native_window.h"
12 #include "atom/common/native_mate_converters/callback.h"
13 #include "atom/common/native_mate_converters/file_path_converter.h"
14 #include "atom/common/native_mate_converters/gfx_converter.h"
15 #include "atom/common/native_mate_converters/gurl_converter.h"
16 #include "atom/common/native_mate_converters/image_converter.h"
17 #include "atom/common/native_mate_converters/string16_converter.h"
18 #include "atom/common/options_switches.h"
19 #include "base/command_line.h"
20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/common/content_switches.h"
22 #include "native_mate/constructor.h"
23 #include "native_mate/dictionary.h"
24 #include "ui/gfx/geometry/rect.h"
26 #if defined(TOOLKIT_VIEWS)
27 #include "atom/browser/native_window_views.h"
31 #include "atom/browser/ui/win/taskbar_host.h"
32 #include "ui/base/win/shell.h"
35 #include "atom/common/node_includes.h"
41 struct Converter<atom::TaskbarHost::ThumbarButton> {
42 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
43 atom::TaskbarHost::ThumbarButton* out) {
44 mate::Dictionary dict;
45 if (!ConvertFromV8(isolate, val, &dict))
47 dict.Get("click", &(out->clicked_callback));
48 dict.Get("tooltip", &(out->tooltip));
49 dict.Get("flags", &out->flags);
50 return dict.Get("icon", &(out->icon));
63 // Converts binary data to Buffer.
64 v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
65 auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
67 return v8::Null(isolate);
69 return buffer.ToLocalChecked();
75 Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
76 const mate::Dictionary& options) {
77 mate::Handle<class WebContents> web_contents;
78 // If no WebContents was passed to the constructor, create it from options.
79 if (!options.Get("webContents", &web_contents)) {
80 // Use options.webPreferences to create WebContents.
81 mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
82 options.Get(options::kWebPreferences, &web_preferences);
84 // Copy the backgroundColor to webContents.
85 v8::Local<v8::Value> value;
86 if (options.Get(options::kBackgroundColor, &value))
87 web_preferences.Set(options::kBackgroundColor, value);
89 v8::Local<v8::Value> transparent;
90 if (options.Get("transparent", &transparent))
91 web_preferences.Set("transparent", transparent);
93 // Creates the WebContents used by BrowserWindow.
94 web_contents = WebContents::Create(isolate, web_preferences);
97 Init(isolate, wrapper, options, web_contents);
100 void Window::Init(v8::Isolate* isolate,
101 v8::Local<v8::Object> wrapper,
102 const mate::Dictionary& options,
103 mate::Handle<class WebContents> web_contents) {
104 web_contents_.Reset(isolate, web_contents.ToV8());
105 api_web_contents_ = web_contents.get();
107 // Keep a copy of the options for later use.
108 mate::Dictionary(isolate, web_contents->GetWrapper()).Set(
109 "browserWindowOptions", options);
111 // The parent window.
112 mate::Handle<Window> parent;
113 if (options.Get("parent", &parent))
114 parent_window_.Reset(isolate, parent.ToV8());
116 // Creates BrowserWindow.
117 window_.reset(NativeWindow::Create(
118 web_contents->managed_web_contents(),
120 parent.IsEmpty() ? nullptr : parent->window_.get()));
121 web_contents->SetOwnerWindow(window_.get());
123 #if defined(TOOLKIT_VIEWS)
124 // Sets the window icon.
125 mate::Handle<NativeImage> icon;
126 if (options.Get(options::kIcon, &icon))
130 window_->InitFromOptions(options);
131 window_->AddObserver(this);
133 InitWith(isolate, wrapper);
134 AttachAsUserData(window_.get());
136 // We can only append this window to parent window's child windows after this
137 // window's JS wrapper gets initialized.
138 if (!parent.IsEmpty())
139 parent->child_windows_.Set(isolate, ID(), wrapper);
143 if (!window_->IsClosed())
144 window_->CloseContents(nullptr);
146 // Destroy the native window in next tick because the native code might be
147 // iterating all windows.
148 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
151 void Window::WillCloseWindow(bool* prevent_default) {
152 *prevent_default = Emit("close");
155 void Window::WillDestroyNativeObject() {
156 // Close all child windows before closing current window.
157 v8::Locker locker(isolate());
158 v8::HandleScope handle_scope(isolate());
159 for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
160 mate::Handle<Window> child;
161 if (mate::ConvertFromV8(isolate(), value, &child))
162 child->window_->CloseImmediately();
166 void Window::OnWindowClosed() {
167 api_web_contents_->DestroyWebContents();
170 window_->RemoveObserver(this);
172 // We can not call Destroy here because we need to call Emit first, but we
173 // also do not want any method to be used, so just mark as destroyed here.
178 RemoveFromParentChildWindows();
180 // Destroy the native class when window is closed.
181 base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure());
184 void Window::OnWindowBlur() {
188 void Window::OnWindowFocus() {
192 void Window::OnWindowShow() {
196 void Window::OnWindowHide() {
200 void Window::OnReadyToShow() {
201 Emit("ready-to-show");
204 void Window::OnWindowMaximize() {
208 void Window::OnWindowUnmaximize() {
212 void Window::OnWindowMinimize() {
216 void Window::OnWindowRestore() {
220 void Window::OnWindowResize() {
224 void Window::OnWindowMove() {
228 void Window::OnWindowMoved() {
232 void Window::OnWindowEnterFullScreen() {
233 Emit("enter-full-screen");
236 void Window::OnWindowLeaveFullScreen() {
237 Emit("leave-full-screen");
240 void Window::OnWindowScrollTouchBegin() {
241 Emit("scroll-touch-begin");
244 void Window::OnWindowScrollTouchEnd() {
245 Emit("scroll-touch-end");
248 void Window::OnWindowScrollTouchEdge() {
249 Emit("scroll-touch-edge");
252 void Window::OnWindowSwipe(const std::string& direction) {
253 Emit("swipe", direction);
256 void Window::OnWindowEnterHtmlFullScreen() {
257 Emit("enter-html-full-screen");
260 void Window::OnWindowLeaveHtmlFullScreen() {
261 Emit("leave-html-full-screen");
264 void Window::OnRendererUnresponsive() {
265 Emit("unresponsive");
268 void Window::OnRendererResponsive() {
272 void Window::OnExecuteWindowsCommand(const std::string& command_name) {
273 Emit("app-command", command_name);
277 void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
278 if (IsWindowMessageHooked(message)) {
279 messages_callback_map_[message].Run(
280 ToBuffer(isolate(), static_cast<void*>(&w_param), sizeof(WPARAM)),
281 ToBuffer(isolate(), static_cast<void*>(&l_param), sizeof(LPARAM)));
287 mate::WrappableBase* Window::New(mate::Arguments* args) {
288 if (!Browser::Get()->is_ready()) {
289 args->ThrowError("Cannot create BrowserWindow before app is ready");
293 if (args->Length() > 1) {
298 mate::Dictionary options;
299 if (!(args->Length() == 1 && args->GetNext(&options))) {
300 options = mate::Dictionary::CreateEmpty(args->isolate());
303 return new Window(args->isolate(), args->GetThis(), options);
306 void Window::Close() {
310 void Window::Focus() {
311 window_->Focus(true);
314 void Window::Blur() {
315 window_->Focus(false);
318 bool Window::IsFocused() {
319 return window_->IsFocused();
322 void Window::Show() {
326 void Window::ShowInactive() {
327 // This method doesn't make sense for modal window..
331 window_->ShowInactive();
334 void Window::Hide() {
338 bool Window::IsVisible() {
339 return window_->IsVisible();
342 bool Window::IsEnabled() {
343 return window_->IsEnabled();
346 void Window::Maximize() {
350 void Window::Unmaximize() {
351 window_->Unmaximize();
354 bool Window::IsMaximized() {
355 return window_->IsMaximized();
358 void Window::Minimize() {
362 void Window::Restore() {
366 bool Window::IsMinimized() {
367 return window_->IsMinimized();
370 void Window::SetFullScreen(bool fullscreen) {
371 window_->SetFullScreen(fullscreen);
374 bool Window::IsFullscreen() {
375 return window_->IsFullscreen();
378 void Window::SetBounds(const gfx::Rect& bounds, mate::Arguments* args) {
379 bool animate = false;
380 args->GetNext(&animate);
381 window_->SetBounds(bounds, animate);
384 gfx::Rect Window::GetBounds() {
385 return window_->GetBounds();
388 void Window::SetContentBounds(const gfx::Rect& bounds, mate::Arguments* args) {
389 bool animate = false;
390 args->GetNext(&animate);
391 window_->SetContentBounds(bounds, animate);
394 gfx::Rect Window::GetContentBounds() {
395 return window_->GetContentBounds();
398 void Window::SetSize(int width, int height, mate::Arguments* args) {
399 bool animate = false;
400 args->GetNext(&animate);
401 window_->SetSize(gfx::Size(width, height), animate);
404 std::vector<int> Window::GetSize() {
405 std::vector<int> result(2);
406 gfx::Size size = window_->GetSize();
407 result[0] = size.width();
408 result[1] = size.height();
412 void Window::SetContentSize(int width, int height, mate::Arguments* args) {
413 bool animate = false;
414 args->GetNext(&animate);
415 window_->SetContentSize(gfx::Size(width, height), animate);
418 std::vector<int> Window::GetContentSize() {
419 std::vector<int> result(2);
420 gfx::Size size = window_->GetContentSize();
421 result[0] = size.width();
422 result[1] = size.height();
426 void Window::SetMinimumSize(int width, int height) {
427 window_->SetMinimumSize(gfx::Size(width, height));
430 std::vector<int> Window::GetMinimumSize() {
431 std::vector<int> result(2);
432 gfx::Size size = window_->GetMinimumSize();
433 result[0] = size.width();
434 result[1] = size.height();
438 void Window::SetMaximumSize(int width, int height) {
439 window_->SetMaximumSize(gfx::Size(width, height));
442 std::vector<int> Window::GetMaximumSize() {
443 std::vector<int> result(2);
444 gfx::Size size = window_->GetMaximumSize();
445 result[0] = size.width();
446 result[1] = size.height();
450 void Window::SetSheetOffset(double offsetY, mate::Arguments* args) {
451 double offsetX = 0.0;
452 args->GetNext(&offsetX);
453 window_->SetSheetOffset(offsetX, offsetY);
456 void Window::SetResizable(bool resizable) {
457 window_->SetResizable(resizable);
460 bool Window::IsResizable() {
461 return window_->IsResizable();
464 void Window::SetMovable(bool movable) {
465 window_->SetMovable(movable);
468 bool Window::IsMovable() {
469 return window_->IsMovable();
472 void Window::SetMinimizable(bool minimizable) {
473 window_->SetMinimizable(minimizable);
476 bool Window::IsMinimizable() {
477 return window_->IsMinimizable();
480 void Window::SetMaximizable(bool maximizable) {
481 window_->SetMaximizable(maximizable);
484 bool Window::IsMaximizable() {
485 return window_->IsMaximizable();
488 void Window::SetFullScreenable(bool fullscreenable) {
489 window_->SetFullScreenable(fullscreenable);
492 bool Window::IsFullScreenable() {
493 return window_->IsFullScreenable();
496 void Window::SetClosable(bool closable) {
497 window_->SetClosable(closable);
500 bool Window::IsClosable() {
501 return window_->IsClosable();
504 void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) {
505 std::string level = "floating";
506 args->GetNext(&level);
507 window_->SetAlwaysOnTop(top, level);
510 bool Window::IsAlwaysOnTop() {
511 return window_->IsAlwaysOnTop();
514 void Window::Center() {
518 void Window::SetPosition(int x, int y, mate::Arguments* args) {
519 bool animate = false;
520 args->GetNext(&animate);
521 window_->SetPosition(gfx::Point(x, y), animate);
524 std::vector<int> Window::GetPosition() {
525 std::vector<int> result(2);
526 gfx::Point pos = window_->GetPosition();
532 void Window::SetTitle(const std::string& title) {
533 window_->SetTitle(title);
536 std::string Window::GetTitle() {
537 return window_->GetTitle();
540 void Window::FlashFrame(bool flash) {
541 window_->FlashFrame(flash);
544 void Window::SetSkipTaskbar(bool skip) {
545 window_->SetSkipTaskbar(skip);
548 void Window::SetKiosk(bool kiosk) {
549 window_->SetKiosk(kiosk);
552 bool Window::IsKiosk() {
553 return window_->IsKiosk();
556 void Window::SetBackgroundColor(const std::string& color_name) {
557 window_->SetBackgroundColor(color_name);
560 void Window::SetHasShadow(bool has_shadow) {
561 window_->SetHasShadow(has_shadow);
564 bool Window::HasShadow() {
565 return window_->HasShadow();
568 void Window::FocusOnWebView() {
569 window_->FocusOnWebView();
572 void Window::BlurWebView() {
573 window_->BlurWebView();
576 bool Window::IsWebViewFocused() {
577 return window_->IsWebViewFocused();
580 void Window::SetRepresentedFilename(const std::string& filename) {
581 window_->SetRepresentedFilename(filename);
584 std::string Window::GetRepresentedFilename() {
585 return window_->GetRepresentedFilename();
588 void Window::SetDocumentEdited(bool edited) {
589 window_->SetDocumentEdited(edited);
592 bool Window::IsDocumentEdited() {
593 return window_->IsDocumentEdited();
596 void Window::SetIgnoreMouseEvents(bool ignore) {
597 return window_->SetIgnoreMouseEvents(ignore);
600 void Window::SetContentProtection(bool enable) {
601 return window_->SetContentProtection(enable);
604 void Window::SetFocusable(bool focusable) {
605 return window_->SetFocusable(focusable);
608 void Window::SetProgressBar(double progress, mate::Arguments* args) {
609 mate::Dictionary options;
611 NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL;
613 args->GetNext(&options) && options.Get("mode", &mode);
615 if (mode == "error") {
616 state = NativeWindow::PROGRESS_ERROR;
617 } else if (mode == "paused") {
618 state = NativeWindow::PROGRESS_PAUSED;
619 } else if (mode == "indeterminate") {
620 state = NativeWindow::PROGRESS_INDETERMINATE;
621 } else if (mode == "none") {
622 state = NativeWindow::PROGRESS_NONE;
625 window_->SetProgressBar(progress, state);
628 void Window::SetOverlayIcon(const gfx::Image& overlay,
629 const std::string& description) {
630 window_->SetOverlayIcon(overlay, description);
633 bool Window::SetThumbarButtons(mate::Arguments* args) {
635 std::vector<TaskbarHost::ThumbarButton> buttons;
636 if (!args->GetNext(&buttons)) {
640 auto window = static_cast<NativeWindowViews*>(window_.get());
641 return window->taskbar_host().SetThumbarButtons(
642 window_->GetAcceleratedWidget(), buttons);
648 void Window::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
649 mate::Handle<Menu> menu;
650 if (value->IsObject() &&
651 mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" &&
652 mate::ConvertFromV8(isolate, value, &menu)) {
653 menu_.Reset(isolate, menu.ToV8());
654 window_->SetMenu(menu->model());
655 } else if (value->IsNull()) {
657 window_->SetMenu(nullptr);
659 isolate->ThrowException(v8::Exception::TypeError(
660 mate::StringToV8(isolate, "Invalid Menu")));
664 void Window::SetAutoHideMenuBar(bool auto_hide) {
665 window_->SetAutoHideMenuBar(auto_hide);
668 bool Window::IsMenuBarAutoHide() {
669 return window_->IsMenuBarAutoHide();
672 void Window::SetMenuBarVisibility(bool visible) {
673 window_->SetMenuBarVisibility(visible);
676 bool Window::IsMenuBarVisible() {
677 return window_->IsMenuBarVisible();
681 bool Window::HookWindowMessage(UINT message,
682 const MessageCallback& callback) {
683 messages_callback_map_[message] = callback;
687 void Window::UnhookWindowMessage(UINT message) {
688 if (!ContainsKey(messages_callback_map_, message))
691 messages_callback_map_.erase(message);
694 bool Window::IsWindowMessageHooked(UINT message) {
695 return ContainsKey(messages_callback_map_, message);
698 void Window::UnhookAllWindowMessages() {
699 messages_callback_map_.clear();
702 bool Window::SetThumbnailClip(const gfx::Rect& region) {
703 auto window = static_cast<NativeWindowViews*>(window_.get());
704 return window->taskbar_host().SetThumbnailClip(
705 window_->GetAcceleratedWidget(), region);
708 bool Window::SetThumbnailToolTip(const std::string& tooltip) {
709 auto window = static_cast<NativeWindowViews*>(window_.get());
710 return window->taskbar_host().SetThumbnailToolTip(
711 window_->GetAcceleratedWidget(), tooltip);
714 void Window::SetAppDetails(const mate::Dictionary& options) {
715 base::string16 app_id;
716 base::FilePath app_icon_path;
717 int app_icon_index = 0;
718 base::string16 relaunch_command;
719 base::string16 relaunch_display_name;
721 options.Get("appId", &app_id);
722 options.Get("appIconPath", &app_icon_path);
723 options.Get("appIconIndex", &app_icon_index);
724 options.Get("relaunchCommand", &relaunch_command);
725 options.Get("relaunchDisplayName", &relaunch_display_name);
727 ui::win::SetAppDetailsForWindow(
728 app_id, app_icon_path, app_icon_index,
729 relaunch_command, relaunch_display_name,
730 window_->GetAcceleratedWidget());
734 #if defined(TOOLKIT_VIEWS)
735 void Window::SetIcon(mate::Handle<NativeImage> icon) {
737 static_cast<NativeWindowViews*>(window_.get())->SetIcon(
738 icon->GetHICON(GetSystemMetrics(SM_CXSMICON)),
739 icon->GetHICON(GetSystemMetrics(SM_CXICON)));
740 #elif defined(USE_X11)
741 static_cast<NativeWindowViews*>(window_.get())->SetIcon(
742 icon->image().AsImageSkia());
747 void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
748 gfx::Size extra_size;
749 args->GetNext(&extra_size);
750 window_->SetAspectRatio(aspect_ratio, extra_size);
753 void Window::PreviewFile(const std::string& path, mate::Arguments* args) {
754 std::string display_name;
755 if (!args->GetNext(&display_name))
757 window_->PreviewFile(path, display_name);
760 void Window::SetParentWindow(v8::Local<v8::Value> value,
761 mate::Arguments* args) {
763 args->ThrowError("Can not be called for modal window");
767 mate::Handle<Window> parent;
768 if (value->IsNull()) {
769 RemoveFromParentChildWindows();
770 parent_window_.Reset();
771 window_->SetParentWindow(nullptr);
772 } else if (mate::ConvertFromV8(isolate(), value, &parent)) {
773 parent_window_.Reset(isolate(), value);
774 window_->SetParentWindow(parent->window_.get());
775 parent->child_windows_.Set(isolate(), ID(), GetWrapper());
777 args->ThrowError("Must pass BrowserWindow instance or null");
781 v8::Local<v8::Value> Window::GetParentWindow() const {
782 if (parent_window_.IsEmpty())
783 return v8::Null(isolate());
785 return v8::Local<v8::Value>::New(isolate(), parent_window_);
788 std::vector<v8::Local<v8::Object>> Window::GetChildWindows() const {
789 return child_windows_.Values(isolate());
792 bool Window::IsModal() const {
793 return window_->is_modal();
796 v8::Local<v8::Value> Window::GetNativeWindowHandle() {
797 gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
799 isolate(), static_cast<void*>(&handle), sizeof(gfx::AcceleratedWidget));
802 void Window::SetVisibleOnAllWorkspaces(bool visible) {
803 return window_->SetVisibleOnAllWorkspaces(visible);
806 bool Window::IsVisibleOnAllWorkspaces() {
807 return window_->IsVisibleOnAllWorkspaces();
810 void Window::SetVibrancy(mate::Arguments* args) {
813 args->GetNext(&type);
814 window_->SetVibrancy(type);
817 int32_t Window::ID() const {
818 return weak_map_id();
821 v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
822 if (web_contents_.IsEmpty())
823 return v8::Null(isolate);
825 return v8::Local<v8::Value>::New(isolate, web_contents_);
828 void Window::RemoveFromParentChildWindows() {
829 if (parent_window_.IsEmpty())
832 mate::Handle<Window> parent;
833 if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent))
836 parent->child_windows_.Remove(ID());
840 void Window::BuildPrototype(v8::Isolate* isolate,
841 v8::Local<v8::FunctionTemplate> prototype) {
842 prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
843 mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
845 .SetMethod("close", &Window::Close)
846 .SetMethod("focus", &Window::Focus)
847 .SetMethod("blur", &Window::Blur)
848 .SetMethod("isFocused", &Window::IsFocused)
849 .SetMethod("show", &Window::Show)
850 .SetMethod("showInactive", &Window::ShowInactive)
851 .SetMethod("hide", &Window::Hide)
852 .SetMethod("isVisible", &Window::IsVisible)
853 .SetMethod("isEnabled", &Window::IsEnabled)
854 .SetMethod("maximize", &Window::Maximize)
855 .SetMethod("unmaximize", &Window::Unmaximize)
856 .SetMethod("isMaximized", &Window::IsMaximized)
857 .SetMethod("minimize", &Window::Minimize)
858 .SetMethod("restore", &Window::Restore)
859 .SetMethod("isMinimized", &Window::IsMinimized)
860 .SetMethod("setFullScreen", &Window::SetFullScreen)
861 .SetMethod("isFullScreen", &Window::IsFullscreen)
862 .SetMethod("setAspectRatio", &Window::SetAspectRatio)
863 .SetMethod("previewFile", &Window::PreviewFile)
865 .SetMethod("setParentWindow", &Window::SetParentWindow)
867 .SetMethod("getParentWindow", &Window::GetParentWindow)
868 .SetMethod("getChildWindows", &Window::GetChildWindows)
869 .SetMethod("isModal", &Window::IsModal)
870 .SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
871 .SetMethod("getBounds", &Window::GetBounds)
872 .SetMethod("setBounds", &Window::SetBounds)
873 .SetMethod("getSize", &Window::GetSize)
874 .SetMethod("setSize", &Window::SetSize)
875 .SetMethod("getContentBounds", &Window::GetContentBounds)
876 .SetMethod("setContentBounds", &Window::SetContentBounds)
877 .SetMethod("getContentSize", &Window::GetContentSize)
878 .SetMethod("setContentSize", &Window::SetContentSize)
879 .SetMethod("setMinimumSize", &Window::SetMinimumSize)
880 .SetMethod("getMinimumSize", &Window::GetMinimumSize)
881 .SetMethod("setMaximumSize", &Window::SetMaximumSize)
882 .SetMethod("getMaximumSize", &Window::GetMaximumSize)
883 .SetMethod("setSheetOffset", &Window::SetSheetOffset)
884 .SetMethod("setResizable", &Window::SetResizable)
885 .SetMethod("isResizable", &Window::IsResizable)
886 .SetMethod("setMovable", &Window::SetMovable)
887 .SetMethod("isMovable", &Window::IsMovable)
888 .SetMethod("setMinimizable", &Window::SetMinimizable)
889 .SetMethod("isMinimizable", &Window::IsMinimizable)
890 .SetMethod("setMaximizable", &Window::SetMaximizable)
891 .SetMethod("isMaximizable", &Window::IsMaximizable)
892 .SetMethod("setFullScreenable", &Window::SetFullScreenable)
893 .SetMethod("isFullScreenable", &Window::IsFullScreenable)
894 .SetMethod("setClosable", &Window::SetClosable)
895 .SetMethod("isClosable", &Window::IsClosable)
896 .SetMethod("setAlwaysOnTop", &Window::SetAlwaysOnTop)
897 .SetMethod("isAlwaysOnTop", &Window::IsAlwaysOnTop)
898 .SetMethod("center", &Window::Center)
899 .SetMethod("setPosition", &Window::SetPosition)
900 .SetMethod("getPosition", &Window::GetPosition)
901 .SetMethod("setTitle", &Window::SetTitle)
902 .SetMethod("getTitle", &Window::GetTitle)
903 .SetMethod("flashFrame", &Window::FlashFrame)
904 .SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
905 .SetMethod("setKiosk", &Window::SetKiosk)
906 .SetMethod("isKiosk", &Window::IsKiosk)
907 .SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
908 .SetMethod("setHasShadow", &Window::SetHasShadow)
909 .SetMethod("hasShadow", &Window::HasShadow)
910 .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
911 .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
912 .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
913 .SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
914 .SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
915 .SetMethod("setContentProtection", &Window::SetContentProtection)
916 .SetMethod("setFocusable", &Window::SetFocusable)
917 .SetMethod("focusOnWebView", &Window::FocusOnWebView)
918 .SetMethod("blurWebView", &Window::BlurWebView)
919 .SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
920 .SetMethod("setProgressBar", &Window::SetProgressBar)
921 .SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
922 .SetMethod("setThumbarButtons", &Window::SetThumbarButtons)
923 .SetMethod("setMenu", &Window::SetMenu)
924 .SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar)
925 .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
926 .SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
927 .SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
928 .SetMethod("setVisibleOnAllWorkspaces",
929 &Window::SetVisibleOnAllWorkspaces)
930 .SetMethod("isVisibleOnAllWorkspaces",
931 &Window::IsVisibleOnAllWorkspaces)
932 .SetMethod("setVibrancy", &Window::SetVibrancy)
934 .SetMethod("hookWindowMessage", &Window::HookWindowMessage)
935 .SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
936 .SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage)
937 .SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages)
938 .SetMethod("setThumbnailClip", &Window::SetThumbnailClip)
939 .SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip)
940 .SetMethod("setAppDetails", &Window::SetAppDetails)
942 #if defined(TOOLKIT_VIEWS)
943 .SetMethod("setIcon", &Window::SetIcon)
945 .SetProperty("id", &Window::ID)
946 .SetProperty("webContents", &Window::WebContents);
950 v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
951 NativeWindow* native_window) {
952 auto existing = TrackableObject::FromWrappedClass(isolate, native_window);
954 return existing->GetWrapper();
956 return v8::Null(isolate);
966 using atom::api::Window;
968 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
969 v8::Local<v8::Context> context, void* priv) {
970 v8::Isolate* isolate = context->GetIsolate();
971 Window::SetConstructor(isolate, base::Bind(&Window::New));
973 mate::Dictionary browser_window(
974 isolate, Window::GetConstructor(isolate)->GetFunction());
975 browser_window.SetMethod("fromId",
976 &mate::TrackableObject<Window>::FromWeakMapID);
977 browser_window.SetMethod("getAllWindows",
978 &mate::TrackableObject<Window>::GetAll);
980 mate::Dictionary dict(isolate, exports);
981 dict.Set("BrowserWindow", browser_window);
986 NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_window, Initialize)