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/gfx_converter.h"
14 #include "atom/common/native_mate_converters/gurl_converter.h"
15 #include "atom/common/native_mate_converters/image_converter.h"
16 #include "atom/common/native_mate_converters/string16_converter.h"
17 #include "atom/common/options_switches.h"
18 #include "base/command_line.h"
19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/common/content_switches.h"
21 #include "native_mate/constructor.h"
22 #include "native_mate/dictionary.h"
23 #include "ui/gfx/geometry/rect.h"
25 #if defined(TOOLKIT_VIEWS)
26 #include "atom/browser/native_window_views.h"
30 #include "atom/browser/ui/win/taskbar_host.h"
33 #include "atom/common/node_includes.h"
39 struct Converter<atom::TaskbarHost::ThumbarButton> {
40 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
41 atom::TaskbarHost::ThumbarButton* out) {
42 mate::Dictionary dict;
43 if (!ConvertFromV8(isolate, val, &dict))
45 dict.Get("click", &(out->clicked_callback));
46 dict.Get("tooltip", &(out->tooltip));
47 dict.Get("flags", &out->flags);
48 return dict.Get("icon", &(out->icon));
61 // Converts binary data to Buffer.
62 v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
63 auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
65 return v8::Null(isolate);
67 return buffer.ToLocalChecked();
73 Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
74 const mate::Dictionary& options) {
75 mate::Handle<class WebContents> web_contents;
76 // If no WebContents was passed to the constructor, create it from options.
77 if (!options.Get("webContents", &web_contents)) {
78 // Use options.webPreferences to create WebContents.
79 mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
80 options.Get(options::kWebPreferences, &web_preferences);
82 // Copy the backgroundColor to webContents.
83 v8::Local<v8::Value> value;
84 if (options.Get(options::kBackgroundColor, &value))
85 web_preferences.Set(options::kBackgroundColor, value);
87 v8::Local<v8::Value> transparent;
88 if (options.Get("transparent", &transparent))
89 web_preferences.Set("transparent", transparent);
91 // Creates the WebContents used by BrowserWindow.
92 web_contents = WebContents::Create(isolate, web_preferences);
95 Init(isolate, wrapper, options, web_contents);
98 void Window::Init(v8::Isolate* isolate,
99 v8::Local<v8::Object> wrapper,
100 const mate::Dictionary& options,
101 mate::Handle<class WebContents> web_contents) {
102 web_contents_.Reset(isolate, web_contents.ToV8());
103 api_web_contents_ = web_contents.get();
105 // Keep a copy of the options for later use.
106 mate::Dictionary(isolate, web_contents->GetWrapper()).Set(
107 "browserWindowOptions", options);
109 // The parent window.
110 mate::Handle<Window> parent;
111 if (options.Get("parent", &parent))
112 parent_window_.Reset(isolate, parent.ToV8());
114 // Creates BrowserWindow.
115 window_.reset(NativeWindow::Create(
116 web_contents->managed_web_contents(),
118 parent.IsEmpty() ? nullptr : parent->window_.get()));
119 web_contents->SetOwnerWindow(window_.get());
121 #if defined(TOOLKIT_VIEWS)
122 // Sets the window icon.
123 mate::Handle<NativeImage> icon;
124 if (options.Get(options::kIcon, &icon))
128 window_->InitFromOptions(options);
129 window_->AddObserver(this);
131 InitWith(isolate, wrapper);
132 AttachAsUserData(window_.get());
134 // We can only append this window to parent window's child windows after this
135 // window's JS wrapper gets initialized.
136 if (!parent.IsEmpty())
137 parent->child_windows_.Set(isolate, ID(), wrapper);
141 if (!window_->IsClosed())
142 window_->CloseContents(nullptr);
144 // Destroy the native window in next tick because the native code might be
145 // iterating all windows.
146 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
149 void Window::WillCloseWindow(bool* prevent_default) {
150 *prevent_default = Emit("close");
153 void Window::WillDestroyNativeObject() {
154 // Close all child windows before closing current window.
155 v8::Locker locker(isolate());
156 v8::HandleScope handle_scope(isolate());
157 for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
158 mate::Handle<Window> child;
159 if (mate::ConvertFromV8(isolate(), value, &child))
160 child->window_->CloseImmediately();
164 void Window::OnWindowClosed() {
165 api_web_contents_->DestroyWebContents();
168 window_->RemoveObserver(this);
170 // We can not call Destroy here because we need to call Emit first, but we
171 // also do not want any method to be used, so just mark as destroyed here.
176 RemoveFromParentChildWindows();
178 // Destroy the native class when window is closed.
179 base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure());
182 void Window::OnWindowBlur() {
186 void Window::OnWindowFocus() {
190 void Window::OnWindowShow() {
194 void Window::OnWindowHide() {
198 void Window::OnReadyToShow() {
199 Emit("ready-to-show");
202 void Window::OnWindowMaximize() {
206 void Window::OnWindowUnmaximize() {
210 void Window::OnWindowMinimize() {
214 void Window::OnWindowRestore() {
218 void Window::OnWindowResize() {
222 void Window::OnWindowMove() {
226 void Window::OnWindowMoved() {
230 void Window::OnWindowEnterFullScreen() {
231 Emit("enter-full-screen");
234 void Window::OnWindowLeaveFullScreen() {
235 Emit("leave-full-screen");
238 void Window::OnWindowScrollTouchBegin() {
239 Emit("scroll-touch-begin");
242 void Window::OnWindowScrollTouchEnd() {
243 Emit("scroll-touch-end");
246 void Window::OnWindowScrollTouchEdge() {
247 Emit("scroll-touch-edge");
250 void Window::OnWindowSwipe(const std::string& direction) {
251 Emit("swipe", direction);
254 void Window::OnWindowEnterHtmlFullScreen() {
255 Emit("enter-html-full-screen");
258 void Window::OnWindowLeaveHtmlFullScreen() {
259 Emit("leave-html-full-screen");
262 void Window::OnRendererUnresponsive() {
263 Emit("unresponsive");
266 void Window::OnRendererResponsive() {
270 void Window::OnExecuteWindowsCommand(const std::string& command_name) {
271 Emit("app-command", command_name);
275 void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
276 if (IsWindowMessageHooked(message)) {
277 messages_callback_map_[message].Run(
278 ToBuffer(isolate(), static_cast<void*>(&w_param), sizeof(WPARAM)),
279 ToBuffer(isolate(), static_cast<void*>(&l_param), sizeof(LPARAM)));
285 mate::WrappableBase* Window::New(mate::Arguments* args) {
286 if (!Browser::Get()->is_ready()) {
287 args->ThrowError("Cannot create BrowserWindow before app is ready");
291 if (args->Length() > 1) {
296 mate::Dictionary options;
297 if (!(args->Length() == 1 && args->GetNext(&options))) {
298 options = mate::Dictionary::CreateEmpty(args->isolate());
301 return new Window(args->isolate(), args->GetThis(), options);
304 void Window::Close() {
308 void Window::Focus() {
309 window_->Focus(true);
312 void Window::Blur() {
313 window_->Focus(false);
316 bool Window::IsFocused() {
317 return window_->IsFocused();
320 void Window::Show() {
324 void Window::ShowInactive() {
325 // This method doesn't make sense for modal window..
329 window_->ShowInactive();
332 void Window::Hide() {
336 bool Window::IsVisible() {
337 return window_->IsVisible();
340 bool Window::IsEnabled() {
341 return window_->IsEnabled();
344 void Window::Maximize() {
348 void Window::Unmaximize() {
349 window_->Unmaximize();
352 bool Window::IsMaximized() {
353 return window_->IsMaximized();
356 void Window::Minimize() {
360 void Window::Restore() {
364 bool Window::IsMinimized() {
365 return window_->IsMinimized();
368 void Window::SetFullScreen(bool fullscreen) {
369 window_->SetFullScreen(fullscreen);
372 bool Window::IsFullscreen() {
373 return window_->IsFullscreen();
376 void Window::SetBounds(const gfx::Rect& bounds, mate::Arguments* args) {
377 bool animate = false;
378 args->GetNext(&animate);
379 window_->SetBounds(bounds, animate);
382 gfx::Rect Window::GetBounds() {
383 return window_->GetBounds();
386 void Window::SetContentBounds(const gfx::Rect& bounds, mate::Arguments* args) {
387 bool animate = false;
388 args->GetNext(&animate);
389 window_->SetContentBounds(bounds, animate);
392 gfx::Rect Window::GetContentBounds() {
393 return window_->GetContentBounds();
396 void Window::SetSize(int width, int height, mate::Arguments* args) {
397 bool animate = false;
398 args->GetNext(&animate);
399 window_->SetSize(gfx::Size(width, height), animate);
402 std::vector<int> Window::GetSize() {
403 std::vector<int> result(2);
404 gfx::Size size = window_->GetSize();
405 result[0] = size.width();
406 result[1] = size.height();
410 void Window::SetContentSize(int width, int height, mate::Arguments* args) {
411 bool animate = false;
412 args->GetNext(&animate);
413 window_->SetContentSize(gfx::Size(width, height), animate);
416 std::vector<int> Window::GetContentSize() {
417 std::vector<int> result(2);
418 gfx::Size size = window_->GetContentSize();
419 result[0] = size.width();
420 result[1] = size.height();
424 void Window::SetMinimumSize(int width, int height) {
425 window_->SetMinimumSize(gfx::Size(width, height));
428 std::vector<int> Window::GetMinimumSize() {
429 std::vector<int> result(2);
430 gfx::Size size = window_->GetMinimumSize();
431 result[0] = size.width();
432 result[1] = size.height();
436 void Window::SetMaximumSize(int width, int height) {
437 window_->SetMaximumSize(gfx::Size(width, height));
440 std::vector<int> Window::GetMaximumSize() {
441 std::vector<int> result(2);
442 gfx::Size size = window_->GetMaximumSize();
443 result[0] = size.width();
444 result[1] = size.height();
448 void Window::SetSheetOffset(double offsetY, mate::Arguments* args) {
449 double offsetX = 0.0;
450 args->GetNext(&offsetX);
451 window_->SetSheetOffset(offsetX, offsetY);
454 void Window::SetResizable(bool resizable) {
455 window_->SetResizable(resizable);
458 bool Window::IsResizable() {
459 return window_->IsResizable();
462 void Window::SetMovable(bool movable) {
463 window_->SetMovable(movable);
466 bool Window::IsMovable() {
467 return window_->IsMovable();
470 void Window::SetMinimizable(bool minimizable) {
471 window_->SetMinimizable(minimizable);
474 bool Window::IsMinimizable() {
475 return window_->IsMinimizable();
478 void Window::SetMaximizable(bool maximizable) {
479 window_->SetMaximizable(maximizable);
482 bool Window::IsMaximizable() {
483 return window_->IsMaximizable();
486 void Window::SetFullScreenable(bool fullscreenable) {
487 window_->SetFullScreenable(fullscreenable);
490 bool Window::IsFullScreenable() {
491 return window_->IsFullScreenable();
494 void Window::SetClosable(bool closable) {
495 window_->SetClosable(closable);
498 bool Window::IsClosable() {
499 return window_->IsClosable();
502 void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) {
503 std::string level = "floating";
504 args->GetNext(&level);
505 window_->SetAlwaysOnTop(top, level);
508 bool Window::IsAlwaysOnTop() {
509 return window_->IsAlwaysOnTop();
512 void Window::Center() {
516 void Window::SetPosition(int x, int y, mate::Arguments* args) {
517 bool animate = false;
518 args->GetNext(&animate);
519 window_->SetPosition(gfx::Point(x, y), animate);
522 std::vector<int> Window::GetPosition() {
523 std::vector<int> result(2);
524 gfx::Point pos = window_->GetPosition();
530 void Window::SetTitle(const std::string& title) {
531 window_->SetTitle(title);
534 std::string Window::GetTitle() {
535 return window_->GetTitle();
538 void Window::FlashFrame(bool flash) {
539 window_->FlashFrame(flash);
542 void Window::SetSkipTaskbar(bool skip) {
543 window_->SetSkipTaskbar(skip);
546 void Window::SetKiosk(bool kiosk) {
547 window_->SetKiosk(kiosk);
550 bool Window::IsKiosk() {
551 return window_->IsKiosk();
554 void Window::SetBackgroundColor(const std::string& color_name) {
555 window_->SetBackgroundColor(color_name);
558 void Window::SetHasShadow(bool has_shadow) {
559 window_->SetHasShadow(has_shadow);
562 bool Window::HasShadow() {
563 return window_->HasShadow();
566 void Window::FocusOnWebView() {
567 window_->FocusOnWebView();
570 void Window::BlurWebView() {
571 window_->BlurWebView();
574 bool Window::IsWebViewFocused() {
575 return window_->IsWebViewFocused();
578 void Window::SetRepresentedFilename(const std::string& filename) {
579 window_->SetRepresentedFilename(filename);
582 std::string Window::GetRepresentedFilename() {
583 return window_->GetRepresentedFilename();
586 void Window::SetDocumentEdited(bool edited) {
587 window_->SetDocumentEdited(edited);
590 bool Window::IsDocumentEdited() {
591 return window_->IsDocumentEdited();
594 void Window::SetIgnoreMouseEvents(bool ignore) {
595 return window_->SetIgnoreMouseEvents(ignore);
598 void Window::SetContentProtection(bool enable) {
599 return window_->SetContentProtection(enable);
602 void Window::SetFocusable(bool focusable) {
603 return window_->SetFocusable(focusable);
606 void Window::SetProgressBar(double progress, mate::Arguments* args) {
607 mate::Dictionary options;
609 NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL;
611 args->GetNext(&options) && options.Get("mode", &mode);
613 if (mode == "error") {
614 state = NativeWindow::PROGRESS_ERROR;
615 } else if (mode == "paused") {
616 state = NativeWindow::PROGRESS_PAUSED;
617 } else if (mode == "indeterminate") {
618 state = NativeWindow::PROGRESS_INDETERMINATE;
619 } else if (mode == "none") {
620 state = NativeWindow::PROGRESS_NONE;
623 window_->SetProgressBar(progress, state);
626 void Window::SetOverlayIcon(const gfx::Image& overlay,
627 const std::string& description) {
628 window_->SetOverlayIcon(overlay, description);
631 bool Window::SetThumbarButtons(mate::Arguments* args) {
633 std::vector<TaskbarHost::ThumbarButton> buttons;
634 if (!args->GetNext(&buttons)) {
638 auto window = static_cast<NativeWindowViews*>(window_.get());
639 return window->taskbar_host().SetThumbarButtons(
640 window_->GetAcceleratedWidget(), buttons);
646 void Window::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
647 mate::Handle<Menu> menu;
648 if (value->IsObject() &&
649 mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" &&
650 mate::ConvertFromV8(isolate, value, &menu)) {
651 menu_.Reset(isolate, menu.ToV8());
652 window_->SetMenu(menu->model());
653 } else if (value->IsNull()) {
655 window_->SetMenu(nullptr);
657 isolate->ThrowException(v8::Exception::TypeError(
658 mate::StringToV8(isolate, "Invalid Menu")));
662 void Window::SetAutoHideMenuBar(bool auto_hide) {
663 window_->SetAutoHideMenuBar(auto_hide);
666 bool Window::IsMenuBarAutoHide() {
667 return window_->IsMenuBarAutoHide();
670 void Window::SetMenuBarVisibility(bool visible) {
671 window_->SetMenuBarVisibility(visible);
674 bool Window::IsMenuBarVisible() {
675 return window_->IsMenuBarVisible();
679 bool Window::HookWindowMessage(UINT message,
680 const MessageCallback& callback) {
681 messages_callback_map_[message] = callback;
685 void Window::UnhookWindowMessage(UINT message) {
686 if (!ContainsKey(messages_callback_map_, message))
689 messages_callback_map_.erase(message);
692 bool Window::IsWindowMessageHooked(UINT message) {
693 return ContainsKey(messages_callback_map_, message);
696 void Window::UnhookAllWindowMessages() {
697 messages_callback_map_.clear();
700 bool Window::SetThumbnailClip(const gfx::Rect& region) {
701 auto window = static_cast<NativeWindowViews*>(window_.get());
702 return window->taskbar_host().SetThumbnailClip(
703 window_->GetAcceleratedWidget(), region);
706 bool Window::SetThumbnailToolTip(const std::string& tooltip) {
707 auto window = static_cast<NativeWindowViews*>(window_.get());
708 return window->taskbar_host().SetThumbnailToolTip(
709 window_->GetAcceleratedWidget(), tooltip);
713 #if defined(TOOLKIT_VIEWS)
714 void Window::SetIcon(mate::Handle<NativeImage> icon) {
716 static_cast<NativeWindowViews*>(window_.get())->SetIcon(
717 icon->GetHICON(GetSystemMetrics(SM_CXSMICON)),
718 icon->GetHICON(GetSystemMetrics(SM_CXICON)));
719 #elif defined(USE_X11)
720 static_cast<NativeWindowViews*>(window_.get())->SetIcon(
721 icon->image().AsImageSkia());
726 void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
727 gfx::Size extra_size;
728 args->GetNext(&extra_size);
729 window_->SetAspectRatio(aspect_ratio, extra_size);
732 void Window::PreviewFile(const std::string& path, mate::Arguments* args) {
733 std::string display_name;
734 if (!args->GetNext(&display_name))
736 window_->PreviewFile(path, display_name);
739 void Window::SetParentWindow(v8::Local<v8::Value> value,
740 mate::Arguments* args) {
742 args->ThrowError("Can not be called for modal window");
746 mate::Handle<Window> parent;
747 if (value->IsNull()) {
748 RemoveFromParentChildWindows();
749 parent_window_.Reset();
750 window_->SetParentWindow(nullptr);
751 } else if (mate::ConvertFromV8(isolate(), value, &parent)) {
752 parent_window_.Reset(isolate(), value);
753 window_->SetParentWindow(parent->window_.get());
754 parent->child_windows_.Set(isolate(), ID(), GetWrapper());
756 args->ThrowError("Must pass BrowserWindow instance or null");
760 v8::Local<v8::Value> Window::GetParentWindow() const {
761 if (parent_window_.IsEmpty())
762 return v8::Null(isolate());
764 return v8::Local<v8::Value>::New(isolate(), parent_window_);
767 std::vector<v8::Local<v8::Object>> Window::GetChildWindows() const {
768 return child_windows_.Values(isolate());
771 bool Window::IsModal() const {
772 return window_->is_modal();
775 v8::Local<v8::Value> Window::GetNativeWindowHandle() {
776 gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
778 isolate(), static_cast<void*>(&handle), sizeof(gfx::AcceleratedWidget));
781 void Window::SetVisibleOnAllWorkspaces(bool visible) {
782 return window_->SetVisibleOnAllWorkspaces(visible);
785 bool Window::IsVisibleOnAllWorkspaces() {
786 return window_->IsVisibleOnAllWorkspaces();
789 int32_t Window::ID() const {
790 return weak_map_id();
793 v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
794 if (web_contents_.IsEmpty())
795 return v8::Null(isolate);
797 return v8::Local<v8::Value>::New(isolate, web_contents_);
800 void Window::RemoveFromParentChildWindows() {
801 if (parent_window_.IsEmpty())
804 mate::Handle<Window> parent;
805 if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent))
808 parent->child_windows_.Remove(ID());
812 void Window::BuildPrototype(v8::Isolate* isolate,
813 v8::Local<v8::FunctionTemplate> prototype) {
814 prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
815 mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
817 .SetMethod("close", &Window::Close)
818 .SetMethod("focus", &Window::Focus)
819 .SetMethod("blur", &Window::Blur)
820 .SetMethod("isFocused", &Window::IsFocused)
821 .SetMethod("show", &Window::Show)
822 .SetMethod("showInactive", &Window::ShowInactive)
823 .SetMethod("hide", &Window::Hide)
824 .SetMethod("isVisible", &Window::IsVisible)
825 .SetMethod("isEnabled", &Window::IsEnabled)
826 .SetMethod("maximize", &Window::Maximize)
827 .SetMethod("unmaximize", &Window::Unmaximize)
828 .SetMethod("isMaximized", &Window::IsMaximized)
829 .SetMethod("minimize", &Window::Minimize)
830 .SetMethod("restore", &Window::Restore)
831 .SetMethod("isMinimized", &Window::IsMinimized)
832 .SetMethod("setFullScreen", &Window::SetFullScreen)
833 .SetMethod("isFullScreen", &Window::IsFullscreen)
834 .SetMethod("setAspectRatio", &Window::SetAspectRatio)
835 .SetMethod("previewFile", &Window::PreviewFile)
837 .SetMethod("setParentWindow", &Window::SetParentWindow)
839 .SetMethod("getParentWindow", &Window::GetParentWindow)
840 .SetMethod("getChildWindows", &Window::GetChildWindows)
841 .SetMethod("isModal", &Window::IsModal)
842 .SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
843 .SetMethod("getBounds", &Window::GetBounds)
844 .SetMethod("setBounds", &Window::SetBounds)
845 .SetMethod("getSize", &Window::GetSize)
846 .SetMethod("setSize", &Window::SetSize)
847 .SetMethod("getContentBounds", &Window::GetContentBounds)
848 .SetMethod("setContentBounds", &Window::SetContentBounds)
849 .SetMethod("getContentSize", &Window::GetContentSize)
850 .SetMethod("setContentSize", &Window::SetContentSize)
851 .SetMethod("setMinimumSize", &Window::SetMinimumSize)
852 .SetMethod("getMinimumSize", &Window::GetMinimumSize)
853 .SetMethod("setMaximumSize", &Window::SetMaximumSize)
854 .SetMethod("getMaximumSize", &Window::GetMaximumSize)
855 .SetMethod("setSheetOffset", &Window::SetSheetOffset)
856 .SetMethod("setResizable", &Window::SetResizable)
857 .SetMethod("isResizable", &Window::IsResizable)
858 .SetMethod("setMovable", &Window::SetMovable)
859 .SetMethod("isMovable", &Window::IsMovable)
860 .SetMethod("setMinimizable", &Window::SetMinimizable)
861 .SetMethod("isMinimizable", &Window::IsMinimizable)
862 .SetMethod("setMaximizable", &Window::SetMaximizable)
863 .SetMethod("isMaximizable", &Window::IsMaximizable)
864 .SetMethod("setFullScreenable", &Window::SetFullScreenable)
865 .SetMethod("isFullScreenable", &Window::IsFullScreenable)
866 .SetMethod("setClosable", &Window::SetClosable)
867 .SetMethod("isClosable", &Window::IsClosable)
868 .SetMethod("setAlwaysOnTop", &Window::SetAlwaysOnTop)
869 .SetMethod("isAlwaysOnTop", &Window::IsAlwaysOnTop)
870 .SetMethod("center", &Window::Center)
871 .SetMethod("setPosition", &Window::SetPosition)
872 .SetMethod("getPosition", &Window::GetPosition)
873 .SetMethod("setTitle", &Window::SetTitle)
874 .SetMethod("getTitle", &Window::GetTitle)
875 .SetMethod("flashFrame", &Window::FlashFrame)
876 .SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
877 .SetMethod("setKiosk", &Window::SetKiosk)
878 .SetMethod("isKiosk", &Window::IsKiosk)
879 .SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
880 .SetMethod("setHasShadow", &Window::SetHasShadow)
881 .SetMethod("hasShadow", &Window::HasShadow)
882 .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
883 .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
884 .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
885 .SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
886 .SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
887 .SetMethod("setContentProtection", &Window::SetContentProtection)
888 .SetMethod("setFocusable", &Window::SetFocusable)
889 .SetMethod("focusOnWebView", &Window::FocusOnWebView)
890 .SetMethod("blurWebView", &Window::BlurWebView)
891 .SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
892 .SetMethod("setProgressBar", &Window::SetProgressBar)
893 .SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
894 .SetMethod("setThumbarButtons", &Window::SetThumbarButtons)
895 .SetMethod("setMenu", &Window::SetMenu)
896 .SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar)
897 .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
898 .SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
899 .SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
900 .SetMethod("setVisibleOnAllWorkspaces",
901 &Window::SetVisibleOnAllWorkspaces)
902 .SetMethod("isVisibleOnAllWorkspaces",
903 &Window::IsVisibleOnAllWorkspaces)
905 .SetMethod("hookWindowMessage", &Window::HookWindowMessage)
906 .SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
907 .SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage)
908 .SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages)
909 .SetMethod("setThumbnailClip", &Window::SetThumbnailClip)
910 .SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip)
912 #if defined(TOOLKIT_VIEWS)
913 .SetMethod("setIcon", &Window::SetIcon)
915 .SetProperty("id", &Window::ID)
916 .SetProperty("webContents", &Window::WebContents);
920 v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
921 NativeWindow* native_window) {
922 auto existing = TrackableObject::FromWrappedClass(isolate, native_window);
924 return existing->GetWrapper();
926 return v8::Null(isolate);
936 using atom::api::Window;
938 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
939 v8::Local<v8::Context> context, void* priv) {
940 v8::Isolate* isolate = context->GetIsolate();
941 Window::SetConstructor(isolate, base::Bind(&Window::New));
943 mate::Dictionary browser_window(
944 isolate, Window::GetConstructor(isolate)->GetFunction());
945 browser_window.SetMethod("fromId",
946 &mate::TrackableObject<Window>::FromWeakMapID);
947 browser_window.SetMethod("getAllWindows",
948 &mate::TrackableObject<Window>::GetAll);
950 mate::Dictionary dict(isolate, exports);
951 dict.Set("BrowserWindow", browser_window);
956 NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_window, Initialize)