Merge pull request #1616 from deepak1556/webview_fullscreen_patch
webContents: override fullscreen notification apis for webview
This commit is contained in:
commit
fd41f1e8bc
11 changed files with 114 additions and 3 deletions
|
@ -215,6 +215,36 @@ void WebContents::HandleKeyboardEvent(
|
||||||
web_contents(), event);
|
web_contents(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
|
||||||
|
const GURL& origin) {
|
||||||
|
auto window = GetWindowFromGuest(source);
|
||||||
|
if (window) {
|
||||||
|
window->SetHtmlApiFullscreen(true);
|
||||||
|
window->NotifyWindowEnterHtmlFullScreen();
|
||||||
|
source->GetRenderViewHost()->WasResized();
|
||||||
|
Emit("enter-html-full-screen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||||
|
auto window = GetWindowFromGuest(source);
|
||||||
|
if (window) {
|
||||||
|
window->SetHtmlApiFullscreen(false);
|
||||||
|
window->NotifyWindowLeaveHtmlFullScreen();
|
||||||
|
source->GetRenderViewHost()->WasResized();
|
||||||
|
Emit("leave-html-full-screen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebContents::IsFullscreenForTabOrPending(
|
||||||
|
const content::WebContents* source) const {
|
||||||
|
auto window = GetWindowFromGuest(source);
|
||||||
|
if (window)
|
||||||
|
return window->is_html_api_fullscreen();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||||
Emit("render-view-deleted",
|
Emit("render-view-deleted",
|
||||||
render_view_host->GetProcess()->GetID(),
|
render_view_host->GetProcess()->GetID(),
|
||||||
|
|
|
@ -151,6 +151,11 @@ class WebContents : public mate::EventEmitter,
|
||||||
void HandleKeyboardEvent(
|
void HandleKeyboardEvent(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::NativeWebKeyboardEvent& event) override;
|
const content::NativeWebKeyboardEvent& event) override;
|
||||||
|
void EnterFullscreenModeForTab(content::WebContents* source,
|
||||||
|
const GURL& origin) override;
|
||||||
|
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||||
|
bool IsFullscreenForTabOrPending(
|
||||||
|
const content::WebContents* source) const override;
|
||||||
|
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||||
|
|
|
@ -132,6 +132,14 @@ void Window::OnWindowLeaveFullScreen() {
|
||||||
Emit("leave-full-screen");
|
Emit("leave-full-screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnWindowEnterHtmlFullScreen() {
|
||||||
|
Emit("enter-html-full-screen");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::OnWindowLeaveHtmlFullScreen() {
|
||||||
|
Emit("leave-html-full-screen");
|
||||||
|
}
|
||||||
|
|
||||||
void Window::OnRendererUnresponsive() {
|
void Window::OnRendererUnresponsive() {
|
||||||
Emit("unresponsive");
|
Emit("unresponsive");
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,8 @@ class Window : public mate::EventEmitter,
|
||||||
void OnWindowRestore() override;
|
void OnWindowRestore() override;
|
||||||
void OnWindowEnterFullScreen() override;
|
void OnWindowEnterFullScreen() override;
|
||||||
void OnWindowLeaveFullScreen() override;
|
void OnWindowLeaveFullScreen() override;
|
||||||
|
void OnWindowEnterHtmlFullScreen() override;
|
||||||
|
void OnWindowLeaveHtmlFullScreen() override;
|
||||||
void OnRendererUnresponsive() override;
|
void OnRendererUnresponsive() override;
|
||||||
void OnRendererResponsive() override;
|
void OnRendererResponsive() override;
|
||||||
void OnDevToolsFocus() override;
|
void OnDevToolsFocus() override;
|
||||||
|
|
|
@ -20,6 +20,8 @@ supportedWebViewEvents = [
|
||||||
'destroyed'
|
'destroyed'
|
||||||
'page-title-set'
|
'page-title-set'
|
||||||
'page-favicon-updated'
|
'page-favicon-updated'
|
||||||
|
'enter-html-full-screen'
|
||||||
|
'leave-html-full-screen'
|
||||||
]
|
]
|
||||||
|
|
||||||
nextInstanceId = 0
|
nextInstanceId = 0
|
||||||
|
|
|
@ -99,6 +99,8 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
is_closed_(false),
|
is_closed_(false),
|
||||||
node_integration_(true),
|
node_integration_(true),
|
||||||
has_dialog_attached_(false),
|
has_dialog_attached_(false),
|
||||||
|
html_fullscreen_(false),
|
||||||
|
native_fullscreen_(false),
|
||||||
zoom_factor_(1.0),
|
zoom_factor_(1.0),
|
||||||
weak_factory_(this),
|
weak_factory_(this),
|
||||||
inspectable_web_contents_(
|
inspectable_web_contents_(
|
||||||
|
@ -476,6 +478,25 @@ void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::SetHtmlApiFullscreen(bool enter_fullscreen) {
|
||||||
|
// Window is already in fullscreen mode, save the state.
|
||||||
|
if (enter_fullscreen && IsFullscreen()) {
|
||||||
|
native_fullscreen_ = true;
|
||||||
|
html_fullscreen_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit html fullscreen state but not window's fullscreen mode.
|
||||||
|
if (!enter_fullscreen && native_fullscreen_) {
|
||||||
|
html_fullscreen_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetFullScreen(enter_fullscreen);
|
||||||
|
html_fullscreen_ = enter_fullscreen;
|
||||||
|
native_fullscreen_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowClosed() {
|
void NativeWindow::NotifyWindowClosed() {
|
||||||
if (is_closed_)
|
if (is_closed_)
|
||||||
return;
|
return;
|
||||||
|
@ -524,6 +545,16 @@ void NativeWindow::NotifyWindowLeaveFullScreen() {
|
||||||
OnWindowLeaveFullScreen());
|
OnWindowLeaveFullScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::NotifyWindowEnterHtmlFullScreen() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||||
|
OnWindowEnterHtmlFullScreen());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||||
|
OnWindowLeaveHtmlFullScreen());
|
||||||
|
}
|
||||||
|
|
||||||
bool NativeWindow::ShouldCreateWebContents(
|
bool NativeWindow::ShouldCreateWebContents(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
int route_id,
|
int route_id,
|
||||||
|
@ -698,16 +729,16 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
|
|
||||||
void NativeWindow::EnterFullscreenModeForTab(content::WebContents* source,
|
void NativeWindow::EnterFullscreenModeForTab(content::WebContents* source,
|
||||||
const GURL& origin) {
|
const GURL& origin) {
|
||||||
SetFullScreen(true);
|
SetHtmlApiFullscreen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::ExitFullscreenModeForTab(content::WebContents* source) {
|
void NativeWindow::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||||
SetFullScreen(false);
|
SetHtmlApiFullscreen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindow::IsFullscreenForTabOrPending(
|
bool NativeWindow::IsFullscreenForTabOrPending(
|
||||||
const content::WebContents* source) const {
|
const content::WebContents* source) const {
|
||||||
return IsFullscreen();
|
return is_html_api_fullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||||
|
|
|
@ -195,6 +195,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
int child_process_id);
|
int child_process_id);
|
||||||
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
||||||
|
|
||||||
|
// Set fullscreen mode triggered by html api.
|
||||||
|
void SetHtmlApiFullscreen(bool enter_fullscreen);
|
||||||
|
|
||||||
// Public API used by platform-dependent delegates and observers to send UI
|
// Public API used by platform-dependent delegates and observers to send UI
|
||||||
// related notifications.
|
// related notifications.
|
||||||
void NotifyWindowClosed();
|
void NotifyWindowClosed();
|
||||||
|
@ -206,6 +209,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
void NotifyWindowRestore();
|
void NotifyWindowRestore();
|
||||||
void NotifyWindowEnterFullScreen();
|
void NotifyWindowEnterFullScreen();
|
||||||
void NotifyWindowLeaveFullScreen();
|
void NotifyWindowLeaveFullScreen();
|
||||||
|
void NotifyWindowEnterHtmlFullScreen();
|
||||||
|
void NotifyWindowLeaveHtmlFullScreen();
|
||||||
|
|
||||||
void AddObserver(NativeWindowObserver* obs) {
|
void AddObserver(NativeWindowObserver* obs) {
|
||||||
observers_.AddObserver(obs);
|
observers_.AddObserver(obs);
|
||||||
|
@ -217,6 +222,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
|
|
||||||
bool has_frame() const { return has_frame_; }
|
bool has_frame() const { return has_frame_; }
|
||||||
|
|
||||||
|
bool is_html_api_fullscreen() const { return html_fullscreen_; }
|
||||||
|
|
||||||
void set_has_dialog_attached(bool has_dialog_attached) {
|
void set_has_dialog_attached(bool has_dialog_attached) {
|
||||||
has_dialog_attached_ = has_dialog_attached;
|
has_dialog_attached_ = has_dialog_attached;
|
||||||
}
|
}
|
||||||
|
@ -343,6 +350,12 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
// There is a dialog that has been attached to window.
|
// There is a dialog that has been attached to window.
|
||||||
bool has_dialog_attached_;
|
bool has_dialog_attached_;
|
||||||
|
|
||||||
|
// Whether window is fullscreened by HTML5 api.
|
||||||
|
bool html_fullscreen_;
|
||||||
|
|
||||||
|
// Whether window is fullscreened by window api.
|
||||||
|
bool native_fullscreen_;
|
||||||
|
|
||||||
// Closure that would be called when window is unresponsive when closing,
|
// Closure that would be called when window is unresponsive when closing,
|
||||||
// it should be cancelled when we can prove that the window is responsive.
|
// it should be cancelled when we can prove that the window is responsive.
|
||||||
base::CancelableClosure window_unresposive_closure_;
|
base::CancelableClosure window_unresposive_closure_;
|
||||||
|
|
|
@ -49,6 +49,8 @@ class NativeWindowObserver {
|
||||||
virtual void OnWindowRestore() {}
|
virtual void OnWindowRestore() {}
|
||||||
virtual void OnWindowEnterFullScreen() {}
|
virtual void OnWindowEnterFullScreen() {}
|
||||||
virtual void OnWindowLeaveFullScreen() {}
|
virtual void OnWindowLeaveFullScreen() {}
|
||||||
|
virtual void OnWindowEnterHtmlFullScreen() {}
|
||||||
|
virtual void OnWindowLeaveHtmlFullScreen() {}
|
||||||
|
|
||||||
// Called when devtools window gets focused.
|
// Called when devtools window gets focused.
|
||||||
virtual void OnDevToolsFocus() {}
|
virtual void OnDevToolsFocus() {}
|
||||||
|
|
|
@ -22,6 +22,8 @@ WEB_VIEW_EVENTS =
|
||||||
'destroyed': []
|
'destroyed': []
|
||||||
'page-title-set': ['title', 'explicitSet']
|
'page-title-set': ['title', 'explicitSet']
|
||||||
'page-favicon-updated': ['favicons']
|
'page-favicon-updated': ['favicons']
|
||||||
|
'enter-html-full-screen': []
|
||||||
|
'leave-html-full-screen': []
|
||||||
|
|
||||||
dispatchEvent = (webView, event, args...) ->
|
dispatchEvent = (webView, event, args...) ->
|
||||||
throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]?
|
throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]?
|
||||||
|
|
|
@ -179,6 +179,14 @@ Emitted when window enters full screen state.
|
||||||
|
|
||||||
Emitted when window leaves full screen state.
|
Emitted when window leaves full screen state.
|
||||||
|
|
||||||
|
### Event: 'enter-html-full-screen'
|
||||||
|
|
||||||
|
Emitted when window enters full screen state triggered by html api.
|
||||||
|
|
||||||
|
### Event: 'leave-html-full-screen'
|
||||||
|
|
||||||
|
Emitted when window leaves full screen state triggered by html api.
|
||||||
|
|
||||||
### Event: 'devtools-opened'
|
### Event: 'devtools-opened'
|
||||||
|
|
||||||
Emitted when devtools is opened.
|
Emitted when devtools is opened.
|
||||||
|
|
|
@ -365,6 +365,14 @@ url.
|
||||||
|
|
||||||
Fired when page receives favicon urls.
|
Fired when page receives favicon urls.
|
||||||
|
|
||||||
|
### enter-html-full-screen
|
||||||
|
|
||||||
|
Fired when page enters fullscreen triggered by html api.
|
||||||
|
|
||||||
|
### leave-html-full-screen
|
||||||
|
|
||||||
|
Fired when page leaves fullscreen triggered by html api.
|
||||||
|
|
||||||
### console-message
|
### console-message
|
||||||
|
|
||||||
* `level` Integer
|
* `level` Integer
|
||||||
|
|
Loading…
Reference in a new issue