diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index bcf6ccc5a335..3a3b3c6efc80 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -219,6 +219,10 @@ void Window::OnWindowMoved() { Emit("moved"); } +void Window::OnWindowWillEnterFullScreen(bool* prevent_default) { + *prevent_default = Emit("will-enter-full-screen"); +} + void Window::OnWindowEnterFullScreen() { Emit("enter-full-screen"); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 641124f4dfd2..2d1e6d71ec34 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -67,6 +67,7 @@ class Window : public mate::TrackableObject, void OnWindowMoved() override; void OnWindowScrollTouchBegin() override; void OnWindowScrollTouchEnd() override; + void OnWindowWillEnterFullScreen(bool* prevent_default) override; void OnWindowEnterFullScreen() override; void OnWindowLeaveFullScreen() override; void OnWindowEnterHtmlFullScreen() override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index c25534f7f18e..a09705fbd967 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -445,6 +445,13 @@ void NativeWindow::NotifyWindowMoved() { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMoved()); } +bool NativeWindow::RequestEnterFullScreen() { + bool prevent_default = false; + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnWindowWillEnterFullScreen(&prevent_default)); + return prevent_default; +} + void NativeWindow::NotifyWindowEnterFullScreen() { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowEnterFullScreen()); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 09fae6c6bcfe..4cc04e790e1e 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -197,6 +197,9 @@ class NativeWindow : public base::SupportsUserData, // Requests the WebContents to close, can be cancelled by the page. virtual void RequestToClosePage(); + // Request the WebContents to go fullscreen, can be cancelled by the page. + virtual bool RequestEnterFullScreen(); + // Methods called by the WebContents. virtual void CloseContents(content::WebContents* source); virtual void RendererUnresponsive(content::WebContents* source); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 7967a1771735..aa0dde4c4864 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -602,6 +602,9 @@ void NativeWindowMac::SetFullScreen(bool fullscreen) { if (fullscreen == IsFullscreen()) return; + if (fullscreen && shell_->RequestEnterFullScreen()) + return; + if (!base::mac::IsOSLionOrLater()) { LOG(ERROR) << "Fullscreen mode is only supported above Lion"; return; diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 4af181085a08..1f66bac5b634 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -52,6 +52,7 @@ class NativeWindowObserver { virtual void OnWindowMoved() {} virtual void OnWindowScrollTouchBegin() {} virtual void OnWindowScrollTouchEnd() {} + virtual void OnWindowWillEnterFullScreen(bool* prevent_default) {} virtual void OnWindowEnterFullScreen() {} virtual void OnWindowLeaveFullScreen() {} virtual void OnWindowEnterHtmlFullScreen() {} diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 44df87da9fb8..101c57515af1 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -347,24 +347,33 @@ bool NativeWindowViews::IsMinimized() { } void NativeWindowViews::SetFullScreen(bool fullscreen) { + bool prevent_default = false; + if (fullscreen) + prevent_default = RequestEnterFullScreen(); + #if defined(OS_WIN) // There is no native fullscreen state on Windows. if (fullscreen) { - last_window_state_ = ui::SHOW_STATE_FULLSCREEN; - NotifyWindowEnterFullScreen(); + if (!prevent_default) { + last_window_state_ = ui::SHOW_STATE_FULLSCREEN; + NotifyWindowEnterFullScreen(); + } } else { last_window_state_ = ui::SHOW_STATE_NORMAL; NotifyWindowLeaveFullScreen(); } // We set the new value after notifying, so we can handle the size event // correctly. - window_->SetFullscreen(fullscreen); -#else - if (IsVisible()) + if (!prevent_default) window_->SetFullscreen(fullscreen); - else - window_->native_widget_private()->ShowWithWindowState( - ui::SHOW_STATE_FULLSCREEN); +#else + if (!(fullscreen && prevent_default)) { + if (IsVisible()) + window_->SetFullscreen(fullscreen); + else + window_->native_widget_private()->ShowWithWindowState( + ui::SHOW_STATE_FULLSCREEN); + } #endif }