Commit 3cbf0c90 authored by barraclough@apple.com's avatar barraclough@apple.com

Propagate WindowServer modifications state to WebProcess

https://bugs.webkit.org/show_bug.cgi?id=126356

Reviewed by Sam Weinig.

This will be necessary to move control of process suppression to the WebProcess.
IsVisuallyIdle implies the process has stopped painting, or painted rects are
occluded and not actually being composited. State is provided on a per
WindowServer connection basis, and as such may produce (safe) false positives.

* Shared/ViewState.h:
    - added IsVisuallyIdle.
* UIProcess/API/mac/PageClientImpl.h:
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::isVisuallyIdle):
    - added, on mac checks WindowServerConnection.
* UIProcess/PageClient.h:
(WebKit::PageClient::isVisuallyIdle):
    - base implementation purely based on isViewVisible.
* UIProcess/WebContext.cpp:
(WebKit::WebContext::windowServerConnectionStateChanged):
    - broadcast the state change.
* UIProcess/WebContext.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::updateViewState):
(WebKit::WebPageProxy::viewStateDidChange):
    - propagate IsVisuallyIdle.
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::windowServerConnectionStateChanged):
    - broadcast the state change.
* UIProcess/WebProcessProxy.h:
    - add windowServerConnectionStateChanged.
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::updateProcessSuppressionStateOfGlobalChildProcesses):
    - moved from static in fle to static member of class.
(WebKit::WebContext::platformInitialize):
    - no need to enableOcclusionNotifications.
(WebKit::WebContext::canEnableProcessSuppressionForNetworkProcess):
(WebKit::WebContext::canEnableProcessSuppressionForWebProcess):
(WebKit::WebContext::canEnableProcessSuppressionForGlobalChildProcesses):
    - changed to call WindowServerConnection.
(WebKit::WebContext::processSuppressionEnabledChanged):
    - don't remove/reregister occlusion notifications.
* UIProcess/mac/WindowServerConnection.h: Added.
(WebKit::WindowServerConnection::applicationIsOccluded):
(WebKit::WindowServerConnection::applicationWindowModificationsHaveStopped):
    - accessors.
* UIProcess/mac/WindowServerConnection.mm: Added.
(WebKit::WindowServerConnection::applicationBecameOccluded):
(WebKit::WindowServerConnection::applicationWindowModificationsStopped):
(WebKit::WindowServerConnection::applicationBecameVisible):
(WebKit::WindowServerConnection::applicationWindowModificationsStarted):
    - handle notifications from the WindowServer.
(WebKit::WindowServerConnection::windowServerConnectionStateChanged):
    - broadcast the state change.
(WebKit::WindowServerConnection::shared):
    - accessor for singleton object.
(WebKit::WindowServerConnection::WindowServerConnection):
    - constructor inizializes fields & register notification handlers.
* WebKit2.xcodeproj/project.pbxproj:
    - added new files.
* config.h:
    - added HAVE_WINDOW_SERVER_OCCLUSION_NOTIFICATIONS.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161246 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 343619bd
2014-01-02 Gavin Barraclough <barraclough@apple.com>
Propagate WindowServer modifications state to WebProcess
https://bugs.webkit.org/show_bug.cgi?id=126356
Reviewed by Sam Weinig.
This will be necessary to move control of process suppression to the WebProcess.
IsVisuallyIdle implies the process has stopped painting, or painted rects are
occluded and not actually being composited. State is provided on a per
WindowServer connection basis, and as such may produce (safe) false positives.
* Shared/ViewState.h:
- added IsVisuallyIdle.
* UIProcess/API/mac/PageClientImpl.h:
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::isVisuallyIdle):
- added, on mac checks WindowServerConnection.
* UIProcess/PageClient.h:
(WebKit::PageClient::isVisuallyIdle):
- base implementation purely based on isViewVisible.
* UIProcess/WebContext.cpp:
(WebKit::WebContext::windowServerConnectionStateChanged):
- broadcast the state change.
* UIProcess/WebContext.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::updateViewState):
(WebKit::WebPageProxy::viewStateDidChange):
- propagate IsVisuallyIdle.
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::windowServerConnectionStateChanged):
- broadcast the state change.
* UIProcess/WebProcessProxy.h:
- add windowServerConnectionStateChanged.
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::updateProcessSuppressionStateOfGlobalChildProcesses):
- moved from static in fle to static member of class.
(WebKit::WebContext::platformInitialize):
- no need to enableOcclusionNotifications.
(WebKit::WebContext::canEnableProcessSuppressionForNetworkProcess):
(WebKit::WebContext::canEnableProcessSuppressionForWebProcess):
(WebKit::WebContext::canEnableProcessSuppressionForGlobalChildProcesses):
- changed to call WindowServerConnection.
(WebKit::WebContext::processSuppressionEnabledChanged):
- don't remove/reregister occlusion notifications.
* UIProcess/mac/WindowServerConnection.h: Added.
(WebKit::WindowServerConnection::applicationIsOccluded):
(WebKit::WindowServerConnection::applicationWindowModificationsHaveStopped):
- accessors.
* UIProcess/mac/WindowServerConnection.mm: Added.
(WebKit::WindowServerConnection::applicationBecameOccluded):
(WebKit::WindowServerConnection::applicationWindowModificationsStopped):
(WebKit::WindowServerConnection::applicationBecameVisible):
(WebKit::WindowServerConnection::applicationWindowModificationsStarted):
- handle notifications from the WindowServer.
(WebKit::WindowServerConnection::windowServerConnectionStateChanged):
- broadcast the state change.
(WebKit::WindowServerConnection::shared):
- accessor for singleton object.
(WebKit::WindowServerConnection::WindowServerConnection):
- constructor inizializes fields & register notification handlers.
* WebKit2.xcodeproj/project.pbxproj:
- added new files.
* config.h:
- added HAVE_WINDOW_SERVER_OCCLUSION_NOTIFICATIONS.
2014-01-02 Gavin Barraclough <barraclough@apple.com>
Remove WindowIsVisible
......
......@@ -34,13 +34,14 @@ struct ViewState {
IsFocused = 1 << 1,
IsVisible = 1 << 2,
IsInWindow = 1 << 3,
IsLayerWindowServerHosted = 1 << 4
IsVisuallyIdle = 1 << 4,
IsLayerWindowServerHosted = 1 << 5,
};
typedef unsigned Flags;
static const Flags NoFlags = 0;
static const Flags AllFlags = WindowIsActive | IsFocused | IsVisible | IsInWindow | IsLayerWindowServerHosted;
static const Flags AllFlags = WindowIsActive | IsFocused | IsVisible | IsInWindow | IsLayerWindowServerHosted | IsVisuallyIdle;
};
} // namespace WebKit
......
......@@ -65,6 +65,7 @@ private:
virtual bool isViewFocused();
virtual bool isViewVisible();
virtual bool isViewInWindow();
virtual bool isVisuallyIdle();
#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
virtual bool isLayerWindowServerHosted();
#endif
......
......@@ -42,6 +42,7 @@
#import "WebContextMenuProxyMac.h"
#import "WebEditCommandProxy.h"
#import "WebPopupMenuProxyMac.h"
#import "WindowServerConnection.h"
#import <WebCore/AlternativeTextUIController.h>
#import <WebCore/BitmapImage.h>
#import <WebCore/Cursor.h>
......@@ -214,6 +215,11 @@ bool PageClientImpl::isViewInWindow()
return [m_wkView window];
}
bool PageClientImpl::isVisuallyIdle()
{
return WindowServerConnection::shared().applicationWindowModificationsHaveStopped() || !isViewVisible();
}
#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
bool PageClientImpl::isLayerWindowServerHosted()
{
......
......@@ -108,6 +108,9 @@ public:
// Return whether the view is in a window.
virtual bool isViewInWindow() = 0;
// Return whether the view is visually idle.
virtual bool isVisuallyIdle() { return !isViewVisible(); }
#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
// Return whether the layer is window server hosted.
virtual bool isLayerWindowServerHosted() = 0;
......
......@@ -452,6 +452,13 @@ void WebContext::willStopUsingPrivateBrowsing()
contexts[i]->setAnyPageGroupMightHavePrivateBrowsingEnabled(false);
}
void WebContext::windowServerConnectionStateChanged()
{
size_t processCount = m_processes.size();
for (size_t i = 0; i < processCount; ++i)
m_processes[i]->windowServerConnectionStateChanged();
}
void WebContext::setAnyPageGroupMightHavePrivateBrowsingEnabled(bool privateBrowsingEnabled)
{
m_iconDatabase->setPrivateBrowsingEnabled(privateBrowsingEnabled);
......
......@@ -291,6 +291,8 @@ public:
void updateProcessSuppressionStateOfChildProcesses();
#endif
void windowServerConnectionStateChanged();
static void willStartUsingPrivateBrowsing();
static void willStopUsingPrivateBrowsing();
......@@ -316,6 +318,10 @@ public:
static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
#endif
#if PLATFORM(MAC)
static void updateProcessSuppressionStateOfGlobalChildProcesses();
#endif
private:
void platformInitialize();
......
......@@ -929,6 +929,8 @@ void WebPageProxy::updateViewState(ViewState::Flags flagsToUpdate)
m_viewState |= ViewState::IsVisible;
if (flagsToUpdate & ViewState::IsInWindow && m_pageClient.isViewInWindow())
m_viewState |= ViewState::IsInWindow;
if (flagsToUpdate & ViewState::IsVisuallyIdle && m_pageClient.isVisuallyIdle())
m_viewState |= ViewState::IsVisuallyIdle;
#if HAVE(LAYER_HOSTING_IN_WINDOW_SERVER)
if (flagsToUpdate & ViewState::IsLayerWindowServerHosted && m_pageClient.isLayerWindowServerHosted())
m_viewState |= ViewState::IsLayerWindowServerHosted;
......@@ -943,6 +945,9 @@ void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, WantsRepl
// If the in-window state may have changed, then so may the layer hosting.
if (mayHaveChanged & ViewState::IsInWindow)
mayHaveChanged |= ViewState::IsLayerWindowServerHosted;
// If the visibility state may have changed, then so may the visually idle.
if (mayHaveChanged & ViewState::IsVisible)
mayHaveChanged |= ViewState::IsVisuallyIdle;
// Record the prior view state, update the flags that may have changed,
// and check which flags have actually changed.
......
......@@ -638,6 +638,11 @@ void WebProcessProxy::releasePageCache()
send(Messages::WebProcess::ReleasePageCache(), 0);
}
void WebProcessProxy::windowServerConnectionStateChanged()
{
for (const auto& page : m_pageMap.values())
page->viewStateDidChange(ViewState::IsVisuallyIdle);
}
void WebProcessProxy::requestTermination()
{
......@@ -652,7 +657,6 @@ void WebProcessProxy::requestTermination()
disconnect();
}
void WebProcessProxy::enableSuddenTermination()
{
if (!isValid())
......
......@@ -125,6 +125,8 @@ public:
RefPtr<API::Object> apiObjectByConvertingToHandles(API::Object*);
void windowServerConnectionStateChanged();
private:
explicit WebProcessProxy(WebContext&);
......
......@@ -33,6 +33,7 @@
#import "WebKitSystemInterface.h"
#import "WebProcessCreationParameters.h"
#import "WebProcessMessages.h"
#import "WindowServerConnection.h"
#if !PLATFORM(IOS)
#import <QuartzCore/CARemoteLayerServer.h>
#endif
......@@ -84,9 +85,6 @@ namespace WebKit {
NSString *SchemeForCustomProtocolRegisteredNotificationName = @"WebKitSchemeForCustomProtocolRegisteredNotification";
NSString *SchemeForCustomProtocolUnregisteredNotificationName = @"WebKitSchemeForCustomProtocolUnregisteredNotification";
static bool s_applicationIsOccluded = false;
static bool s_applicationWindowModificationsHaveStopped = false;
static bool s_occlusionNotificationHandlersRegistered = false;
static bool s_processSuppressionEnabledForAllContexts = true;
static void registerUserDefaultsIfNeeded()
......@@ -105,7 +103,7 @@ static void registerUserDefaultsIfNeeded()
[[NSUserDefaults standardUserDefaults] registerDefaults:registrationDictionary];
}
static void updateProcessSuppressionStateOfGlobalChildProcesses()
void WebContext::updateProcessSuppressionStateOfGlobalChildProcesses()
{
// The plan is to have all child processes become context specific. This function
// can be removed once that is complete.
......@@ -117,119 +115,6 @@ static void updateProcessSuppressionStateOfGlobalChildProcesses()
#endif
}
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
static void applicationOcclusionStateChanged()
{
const Vector<WebContext*>& contexts = WebContext::allContexts();
for (size_t i = 0, count = contexts.size(); i < count; ++i) {
if (contexts[i]->processSuppressionEnabled())
contexts[i]->updateProcessSuppressionStateOfChildProcesses();
}
if (s_processSuppressionEnabledForAllContexts)
updateProcessSuppressionStateOfGlobalChildProcesses();
}
static void applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t)
{
if (!s_applicationIsOccluded)
return;
s_applicationIsOccluded = false;
applicationOcclusionStateChanged();
}
static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t)
{
if (s_applicationIsOccluded)
return;
s_applicationIsOccluded = true;
applicationOcclusionStateChanged();
}
static void applicationWindowModificationsStarted(uint32_t, void*, uint32_t, void*, uint32_t)
{
if (!s_applicationWindowModificationsHaveStopped)
return;
s_applicationWindowModificationsHaveStopped = false;
applicationOcclusionStateChanged();
}
static void applicationWindowModificationsStopped(uint32_t, void*, uint32_t, void*, uint32_t)
{
if (s_applicationWindowModificationsHaveStopped)
return;
s_applicationWindowModificationsHaveStopped = true;
applicationOcclusionStateChanged();
}
struct OcclusionNotificationHandler {
WKOcclusionNotificationType notificationType;
WKOcclusionNotificationHandler handler;
const char *name;
};
static const OcclusionNotificationHandler occlusionNotificationHandlers[] = {
{ WKOcclusionNotificationTypeApplicationBecameVisible, applicationBecameVisible, "Application Became Visible" },
{ WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded, "Application Became Occluded" },
{ WKOcclusionNotificationTypeApplicationWindowModificationsStarted, applicationWindowModificationsStarted, "Application Window Modifications Started" },
{ WKOcclusionNotificationTypeApplicationWindowModificationsStopped, applicationWindowModificationsStopped, "Application Window Modifications Stopped" },
};
#endif
static void registerOcclusionNotificationHandlers()
{
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
for (const OcclusionNotificationHandler& occlusionNotificationHandler : occlusionNotificationHandlers) {
bool result = WKRegisterOcclusionNotificationHandler(occlusionNotificationHandler.notificationType, occlusionNotificationHandler.handler);
UNUSED_PARAM(result);
ASSERT_WITH_MESSAGE(result, "Registration of \"%s\" notification handler failed.\n", occlusionNotificationHandler.name);
}
#endif
}
static void unregisterOcclusionNotificationHandlers()
{
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
for (const OcclusionNotificationHandler& occlusionNotificationHandler : occlusionNotificationHandlers) {
bool result = WKUnregisterOcclusionNotificationHandler(occlusionNotificationHandler.notificationType, occlusionNotificationHandler.handler);
UNUSED_PARAM(result);
ASSERT_WITH_MESSAGE(result, "Unregistration of \"%s\" notification handler failed.\n", occlusionNotificationHandler.name);
}
#endif
}
static void enableOcclusionNotifications()
{
if (s_occlusionNotificationHandlersRegistered)
return;
s_occlusionNotificationHandlersRegistered = true;
registerOcclusionNotificationHandlers();
}
static void disableOcclusionNotifications()
{
if (!s_occlusionNotificationHandlersRegistered)
return;
s_occlusionNotificationHandlersRegistered = false;
unregisterOcclusionNotificationHandlers();
}
static bool processSuppressionIsEnabledForAnyContext()
{
bool result = false;
const Vector<WebContext*>& contexts = WebContext::allContexts();
for (size_t i = 0, count = contexts.size(); i < count; ++i) {
if (contexts[i]->processSuppressionEnabled()) {
result = true;
break;
}
}
return result;
}
static bool processSuppressionIsEnabledForAllContexts()
{
bool result = true;
......@@ -254,7 +139,6 @@ void WebContext::platformInitialize()
registerUserDefaultsIfNeeded();
registerNotificationObservers();
ASSERT(m_processSuppressionEnabled);
enableOcclusionNotifications();
}
String WebContext::platformDefaultApplicationCacheDirectory() const
......@@ -540,29 +424,24 @@ void WebContext::updateProcessSuppressionStateOfChildProcesses()
bool WebContext::canEnableProcessSuppressionForNetworkProcess() const
{
return (s_applicationIsOccluded || s_applicationWindowModificationsHaveStopped) && m_processSuppressionEnabled && !omitProcessSuppression();
return (WindowServerConnection::shared().applicationIsOccluded() || WindowServerConnection::shared().applicationWindowModificationsHaveStopped()) && m_processSuppressionEnabled && !omitProcessSuppression();
}
bool WebContext::canEnableProcessSuppressionForWebProcess(const WebKit::WebProcessProxy *webProcess) const
{
return (s_applicationIsOccluded || s_applicationWindowModificationsHaveStopped || webProcess->allPagesAreProcessSuppressible())
return (WindowServerConnection::shared().applicationIsOccluded() || WindowServerConnection::shared().applicationWindowModificationsHaveStopped() || webProcess->allPagesAreProcessSuppressible())
&& m_processSuppressionEnabled && !omitProcessSuppression();
}
bool WebContext::canEnableProcessSuppressionForGlobalChildProcesses()
{
return (s_applicationIsOccluded || s_applicationWindowModificationsHaveStopped) && s_processSuppressionEnabledForAllContexts && !omitProcessSuppression();
return (WindowServerConnection::shared().applicationIsOccluded() || WindowServerConnection::shared().applicationWindowModificationsHaveStopped()) && s_processSuppressionEnabledForAllContexts && !omitProcessSuppression();
}
void WebContext::processSuppressionEnabledChanged()
{
updateProcessSuppressionStateOfChildProcesses();
if (processSuppressionIsEnabledForAnyContext())
enableOcclusionNotifications();
else
disableOcclusionNotifications();
bool newProcessSuppressionEnabledForAllContexts = processSuppressionIsEnabledForAllContexts();
if (s_processSuppressionEnabledForAllContexts != newProcessSuppressionEnabledForAllContexts) {
s_processSuppressionEnabledForAllContexts = newProcessSuppressionEnabledForAllContexts;
......
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WindowServerConnection_h
#define WindowServerConnection_h
namespace WebKit {
class WindowServerConnection {
public:
static WindowServerConnection& shared();
bool applicationIsOccluded() const { return m_applicationIsOccluded; }
bool applicationWindowModificationsHaveStopped() const { return m_applicationWindowModificationsHaveStopped; }
private:
WindowServerConnection();
#if HAVE(WINDOW_SERVER_OCCLUSION_NOTIFICATIONS)
void windowServerConnectionStateChanged();
void applicationBecameOccluded(bool occluded);
void applicationWindowModificationsStopped(bool stopped);
static void applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t);
static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t);
static void applicationWindowModificationsStarted(uint32_t, void*, uint32_t, void*, uint32_t);
static void applicationWindowModificationsStopped(uint32_t, void*, uint32_t, void*, uint32_t);
#endif
bool m_applicationIsOccluded;
bool m_applicationWindowModificationsHaveStopped;
};
} // namespace WebKit
#endif // WindowServerConnection_h
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "WindowServerConnection.h"
#import "WebContext.h"
#import "WebKitSystemInterface.h"
namespace WebKit {
#if HAVE(WINDOW_SERVER_OCCLUSION_NOTIFICATIONS)
void WindowServerConnection::applicationBecameOccluded(bool occluded)
{
if (m_applicationIsOccluded == occluded)
return;
m_applicationIsOccluded = occluded;
windowServerConnectionStateChanged();
}
void WindowServerConnection::applicationWindowModificationsStopped(bool stopped)
{
if (m_applicationWindowModificationsHaveStopped == stopped)
return;
m_applicationWindowModificationsHaveStopped = stopped;
windowServerConnectionStateChanged();
}
void WindowServerConnection::applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t)
{
WindowServerConnection::shared().applicationBecameOccluded(false);
}
void WindowServerConnection::applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t)
{
WindowServerConnection::shared().applicationBecameOccluded(true);
}
void WindowServerConnection::applicationWindowModificationsStarted(uint32_t, void*, uint32_t, void*, uint32_t)
{
WindowServerConnection::shared().applicationWindowModificationsStopped(false);
}
void WindowServerConnection::applicationWindowModificationsStopped(uint32_t, void*, uint32_t, void*, uint32_t)
{
WindowServerConnection::shared().applicationWindowModificationsStopped(true);
}
void WindowServerConnection::windowServerConnectionStateChanged()
{
for (auto* context : WebContext::allContexts()) {
context->windowServerConnectionStateChanged();
if (context->processSuppressionEnabled())
context->updateProcessSuppressionStateOfChildProcesses();
}
WebContext::updateProcessSuppressionStateOfGlobalChildProcesses();
}
#endif
WindowServerConnection& WindowServerConnection::shared()
{
static WindowServerConnection& windowServerConnection = *new WindowServerConnection;
return windowServerConnection;
}
WindowServerConnection::WindowServerConnection()
: m_applicationIsOccluded(false)
, m_applicationWindowModificationsHaveStopped(false)
{
#if HAVE(WINDOW_SERVER_OCCLUSION_NOTIFICATIONS)
struct OcclusionNotificationHandler {
WKOcclusionNotificationType notificationType;
WKOcclusionNotificationHandler handler;
const char* name;
};
static const OcclusionNotificationHandler occlusionNotificationHandlers[] = {
{ WKOcclusionNotificationTypeApplicationBecameVisible, applicationBecameVisible, "Application Became Visible" },
{ WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded, "Application Became Occluded" },
{ WKOcclusionNotificationTypeApplicationWindowModificationsStarted, applicationWindowModificationsStarted, "Application Window Modifications Started" },
{ WKOcclusionNotificationTypeApplicationWindowModificationsStopped, applicationWindowModificationsStopped, "Application Window Modifications Stopped" },
};
for (auto occlusionNotificationHandler : occlusionNotificationHandlers) {
bool result = WKRegisterOcclusionNotificationHandler(occlusionNotificationHandler.notificationType, occlusionNotificationHandler.handler);
UNUSED_PARAM(result);
ASSERT_WITH_MESSAGE(result, "Registration of \"%s\" notification handler failed.\n", occlusionNotificationHandler.name);
}
#endif
}
} // namespace WebKit
......@@ -783,6 +783,7 @@
7CF47FFF17276AE3008ACB91 /* WKBundlePageBannerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CF47FFD17276AE3008ACB91 /* WKBundlePageBannerMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
84477853176FCC0800CDC7BB /* InjectedBundleHitTestResultMediaType.h in Headers */ = {isa = PBXBuildFile; fileRef = 84477851176FCAC100CDC7BB /* InjectedBundleHitTestResultMediaType.h */; };
865E0485181A094A001F72F2 /* ViewState.h in Headers */ = {isa = PBXBuildFile; fileRef = 865E0484181A090D001F72F2 /* ViewState.h */; };
868160D0187645570021E79D /* WindowServerConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 868160CF187645370021E79D /* WindowServerConnection.mm */; };
8CFECE941490F140002AAA32 /* EditorState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8CFECE931490F140002AAA32 /* EditorState.cpp */; };
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
909854EC12BC4E17000AD080 /* WebMemorySampler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 905620E812BC248B000799B6 /* WebMemorySampler.cpp */; };
......@@ -2402,6 +2403,8 @@
7CF47FFD17276AE3008ACB91 /* WKBundlePageBannerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundlePageBannerMac.h; sourceTree = "<group>"; };
84477851176FCAC100CDC7BB /* InjectedBundleHitTestResultMediaType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundleHitTestResultMediaType.h; sourceTree = "<group>"; };
865E0484181A090D001F72F2 /* ViewState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewState.h; sourceTree = "<group>"; };
868160CD18763D4B0021E79D /* WindowServerConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WindowServerConnection.h; sourceTree = "<group>"; };
868160CF187645370021E79D /* WindowServerConnection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowServerConnection.mm; sourceTree = "<group>"; };
8CFECE931490F140002AAA32 /* EditorState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditorState.cpp; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* WebKit2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WebKit2.framework; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -5352,6 +5355,8 @@
BCCF085C113F3B7500C650C5 /* mac */ = {
isa = PBXGroup;
children = (
868160CF187645370021E79D /* WindowServerConnection.mm */,
868160CD18763D4B0021E79D /* WindowServerConnection.h */,
B878B613133428DC006888E9 /* CorrectionPanel.h */,
B878B614133428DC006888E9 /* CorrectionPanel.mm */,
1AB16AE01648656D00290D62 /* RemoteLayerTreeDrawingAreaProxy.h */,
......@@ -7369,6 +7374,7 @@
518D2CAD12D5153B003BB93B /* WebBackForwardListItem.cpp in Sources */,
BC72B9FA11E6476B001EB4EA /* WebBackForwardListProxy.cpp in Sources */,
BC111A5A112F4FBB00337BAB /* WebChromeClient.cpp in Sources */,
868160D0187645570021E79D /* WindowServerConnection.mm in Sources */,
3F87B9BD158940120090FF62 /* WebColorChooser.cpp in Sources */,
F036978815F4BF0500C3A80E /* WebColorPicker.cpp in Sources */,
F036978B15F4BF1300C3A80E /* WebColorPickerResultListenerProxy.cpp in Sources */,
......
......@@ -80,3 +80,9 @@
#define ENABLE_SEC_ITEM_SHIM 1
#endif
#endif
#ifndef HAVE_WINDOW_SERVER_OCCLUSION_NOTIFICATIONS
#if PLATFORM(MAC) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
#define HAVE_WINDOW_SERVER_OCCLUSION_NOTIFICATIONS 1
#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment