Changeset 139888 in webkit


Ignore:
Timestamp:
Jan 16, 2013 9:44:57 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Groundwork to enable process suppression by default on Mac
https://bugs.webkit.org/show_bug.cgi?id=106513

Patch by Kiran Muppala <cmuppala@apple.com> on 2013-01-16
Reviewed by Alexey Proskuryakov.

Process suppression has so far been controlled by a user default and
disabled by default. This patch provides the groundwork to enable it by
default and adds a private API to enable/disable it on a per-context
basis.

  • Shared/mac/ChildProcessMac.mm:

(WebKit::ChildProcess::platformInitialize): Add comment about
initilization of application occlusion state.

  • UIProcess/API/C/mac/WKContextPrivateMac.cpp: Added.

(WKContextGetProcessSuppressionEnabled):
(WKContextSetProcessSuppressionEnabled):
Add private API to enable/disable process suppression on a per-context
basis.

  • UIProcess/API/C/mac/WKContextPrivateMac.h: Added.
  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::didFinishLaunching): Check if owning
context has process suppression enabled before updating application
occlusion state.

  • UIProcess/WebProcessProxy.cpp:

(WebKit::WebProcessProxy::didFinishLaunching): Ditto.

  • UIProcess/Plugins/PluginProcessProxy.cpp:

(WebKit::PluginProcessProxy::didFinishLaunching): Check if
process suppression is enabled for global child processes before
updating application occlusion state.

  • UIProcess/SharedWorkers/SharedWorkerProcessProxy.cpp:

(WebKit::SharedWorkerProcessProxy::didFinishLaunching): Ditto.

  • UIProcess/WebContext.cpp:

(WebKit::WebContext::create): Remove call to
initializeProcessSuppressionSupport, since platformInitialize has been
modified to perform initialization.
(WebKit::WebContext::WebContext): Initialize new member variable
m_processSuppressionEnabled to false.

  • UIProcess/WebContext.h:

(WebKit::WebContext::processSuppressionEnabled): Remove "Support"
from the method name.

  • UIProcess/mac/WebContextMac.mm:

(WebKit::updateGlobalChildProcessesApplicationOcclusionState):
(WebKit::applicationOcclusionStateChanged): Update the application
occlusion state of child processes having process suppresion enabled.
(WebKit::applicationBecameVisible):
(WebKit::applicationBecameOccluded):
Simplify by moving code to applicationOcclusionStateChanged.
(WebKit::registerOcclusionNotificationHandlers): Fix typos.
(WebKit::unregisterOcclusionNotificationHandlers): Add
method to unregister occlusion notification handlers when no context
has process suppression enabled.
(WebKit::enableOcclusionNotifications):
(WebKit::disableOcclusionNotifications):
(WebKit::enableProcessSuppressionForGlobalChildProcesses):
(WebKit::disableProcessSuppressionForGlobalChildProcesses):
(WebKit::processSuppressionIsEnabledForAnyContext):
(WebKit::processSuppressionIsEnabledForAllContexts):
(WebKit::WebContext::platformInitialize): Disable process suppression
for global child processes since process suppression is disabled for a
context on construction.
(WebKit::WebContext::setProcessSuppressionEnabled):
(WebKit::WebContext::updateChildProcessesApplicationOcclusionState):
(WebKit::WebContext::applicationIsOccluded):
(WebKit::WebContext::processSuppressionEnabledForGlobalChildProcesses):
(WebKit::WebContext::processSuppressionEnabledChanged): Update child
processes application occlusion state, enable/disable occlusion
notifications and enable/disable process suppression for global child
processes.

  • WebKit2.xcodeproj/project.pbxproj:
Location:
trunk/Source/WebKit2
Files:
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r139825 r139888  
     12013-01-16  Kiran Muppala  <cmuppala@apple.com>
     2
     3        Groundwork to enable process suppression by default on Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=106513
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Process suppression has so far been controlled by a user default and
     9        disabled by default.  This patch provides the groundwork to enable it by
     10        default and adds a private API to enable/disable it on a per-context
     11        basis.
     12
     13        * Shared/mac/ChildProcessMac.mm:
     14        (WebKit::ChildProcess::platformInitialize): Add comment about
     15        initilization of application occlusion state.
     16        * UIProcess/API/C/mac/WKContextPrivateMac.cpp: Added.
     17        (WKContextGetProcessSuppressionEnabled):
     18        (WKContextSetProcessSuppressionEnabled):
     19        Add private API to enable/disable process suppression on a per-context
     20        basis.
     21        * UIProcess/API/C/mac/WKContextPrivateMac.h: Added.
     22        * UIProcess/Network/NetworkProcessProxy.cpp:
     23        (WebKit::NetworkProcessProxy::didFinishLaunching): Check if owning
     24        context has process suppression enabled before updating application
     25        occlusion state.
     26        * UIProcess/WebProcessProxy.cpp:
     27        (WebKit::WebProcessProxy::didFinishLaunching): Ditto.
     28        * UIProcess/Plugins/PluginProcessProxy.cpp:
     29        (WebKit::PluginProcessProxy::didFinishLaunching): Check if
     30        process suppression is enabled for global child processes before
     31        updating application occlusion state.
     32        * UIProcess/SharedWorkers/SharedWorkerProcessProxy.cpp:
     33        (WebKit::SharedWorkerProcessProxy::didFinishLaunching): Ditto.
     34        * UIProcess/WebContext.cpp:
     35        (WebKit::WebContext::create): Remove call to
     36        initializeProcessSuppressionSupport, since platformInitialize has been
     37        modified to perform initialization.
     38        (WebKit::WebContext::WebContext): Initialize new member variable
     39        m_processSuppressionEnabled to false.
     40        * UIProcess/WebContext.h:
     41        (WebKit::WebContext::processSuppressionEnabled): Remove "Support"
     42        from the method name.
     43        * UIProcess/mac/WebContextMac.mm:
     44        (WebKit::updateGlobalChildProcessesApplicationOcclusionState):
     45        (WebKit::applicationOcclusionStateChanged): Update the application
     46        occlusion state of child processes having process suppresion enabled.
     47        (WebKit::applicationBecameVisible):
     48        (WebKit::applicationBecameOccluded):
     49        Simplify by moving code to applicationOcclusionStateChanged.
     50        (WebKit::registerOcclusionNotificationHandlers): Fix typos.
     51        (WebKit::unregisterOcclusionNotificationHandlers): Add
     52        method to unregister occlusion notification handlers when no context
     53        has process suppression enabled.
     54        (WebKit::enableOcclusionNotifications):
     55        (WebKit::disableOcclusionNotifications):
     56        (WebKit::enableProcessSuppressionForGlobalChildProcesses):
     57        (WebKit::disableProcessSuppressionForGlobalChildProcesses):
     58        (WebKit::processSuppressionIsEnabledForAnyContext):
     59        (WebKit::processSuppressionIsEnabledForAllContexts):
     60        (WebKit::WebContext::platformInitialize): Disable process suppression
     61        for global child processes since process suppression is disabled for a
     62        context on construction.
     63        (WebKit::WebContext::setProcessSuppressionEnabled):
     64        (WebKit::WebContext::updateChildProcessesApplicationOcclusionState):
     65        (WebKit::WebContext::applicationIsOccluded):
     66        (WebKit::WebContext::processSuppressionEnabledForGlobalChildProcesses):
     67        (WebKit::WebContext::processSuppressionEnabledChanged): Update child
     68        processes application occlusion state, enable/disable occlusion
     69        notifications and enable/disable process suppression for global child
     70        processes.
     71        * WebKit2.xcodeproj/project.pbxproj:
     72
    1732013-01-15  Anders Carlsson  <andersca@apple.com>
    274
  • trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm

    r138336 r139888  
    6161    initializeTimerCoalescingPolicy();
    6262#endif
     63    // Starting as unoccluded.  The proxy for this process will set the actual value from didFinishLaunching().
    6364    setApplicationIsOccluded(false);
    6465}
  • trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.cpp

    r139887 r139888  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "config.h"
    27 #import "ChildProcess.h"
     26#include "config.h"
     27#include "WKContextPrivateMac.h"
    2828
    29 #import "WebKitSystemInterface.h"
    30 #import <mach/task.h>
     29#include "WKAPICast.h"
     30#include "WebContext.h"
    3131
    32 namespace WebKit {
     32using namespace WebKit;
    3333
    34 void ChildProcess::setApplicationIsOccluded(bool applicationIsOccluded)
     34bool WKContextGetProcessSuppressionEnabled(WKContextRef contextRef)
    3535{
    36     if (this->applicationIsOccluded() == applicationIsOccluded)
    37         return;
    38 
    39 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    40     if (applicationIsOccluded)
    41         m_processVisibleAssertion.clear();
    42     else
    43         m_processVisibleAssertion = WKNSProcessInfoProcessAssertionWithTypes(WKProcessAssertionTypeVisible);
    44 #endif
     36    return toImpl(contextRef)->processSuppressionEnabled();
    4537}
    4638
    47 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    48 static void initializeTimerCoalescingPolicy()
     39void WKContextSetProcessSuppressionEnabled(WKContextRef contextRef, bool enabled)
    4940{
    50     // Set task_latency and task_throughput QOS tiers as appropriate for a visible application.
    51     struct task_qos_policy qosinfo = { LATENCY_QOS_TIER_0, THROUGHPUT_QOS_TIER_0 };
    52     kern_return_t kr = task_policy_set(mach_task_self(), TASK_BASE_QOS_POLICY, (task_policy_t)&qosinfo, TASK_QOS_POLICY_COUNT);
    53     ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
     41    toImpl(contextRef)->setProcessSuppressionEnabled(enabled);
    5442}
    55 #endif
    56 
    57 void ChildProcess::platformInitialize()
    58 {
    59 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    60     setpriority(PRIO_DARWIN_PROCESS, 0, 0);
    61     initializeTimerCoalescingPolicy();
    62 #endif
    63     setApplicationIsOccluded(false);
    64 }
    65 
    66 }
  • trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h

    r139887 r139888  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "config.h"
    27 #import "ChildProcess.h"
     26#ifndef WKContextPrivateMac_h
     27#define WKContextPrivateMac_h
    2828
    29 #import "WebKitSystemInterface.h"
    30 #import <mach/task.h>
     29#include <WebKit2/WKBase.h>
    3130
    32 namespace WebKit {
     31#ifdef __cplusplus
     32extern "C" {
     33#endif
    3334
    34 void ChildProcess::setApplicationIsOccluded(bool applicationIsOccluded)
    35 {
    36     if (this->applicationIsOccluded() == applicationIsOccluded)
    37         return;
     35WK_EXPORT bool WKContextGetProcessSuppressionEnabled(WKContextRef context);
     36WK_EXPORT void WKContextSetProcessSuppressionEnabled(WKContextRef context, bool enabled);
    3837
    39 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    40     if (applicationIsOccluded)
    41         m_processVisibleAssertion.clear();
    42     else
    43         m_processVisibleAssertion = WKNSProcessInfoProcessAssertionWithTypes(WKProcessAssertionTypeVisible);
    44 #endif
    45 }
    46 
    47 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    48 static void initializeTimerCoalescingPolicy()
    49 {
    50     // Set task_latency and task_throughput QOS tiers as appropriate for a visible application.
    51     struct task_qos_policy qosinfo = { LATENCY_QOS_TIER_0, THROUGHPUT_QOS_TIER_0 };
    52     kern_return_t kr = task_policy_set(mach_task_self(), TASK_BASE_QOS_POLICY, (task_policy_t)&qosinfo, TASK_QOS_POLICY_COUNT);
    53     ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
     38#ifdef __cplusplus
    5439}
    5540#endif
    5641
    57 void ChildProcess::platformInitialize()
    58 {
    59 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    60     setpriority(PRIO_DARWIN_PROCESS, 0, 0);
    61     initializeTimerCoalescingPolicy();
    62 #endif
    63     setApplicationIsOccluded(false);
    64 }
    65 
    66 }
     42#endif /* WKContextPrivateMac_h */
  • trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp

    r139066 r139888  
    185185
    186186#if PLATFORM(MAC)
    187     if (WebContext::applicationIsOccluded())
     187    if (WebContext::applicationIsOccluded() && m_webContext->processSuppressionEnabled())
    188188        connection()->send(Messages::NetworkProcess::SetApplicationIsOccluded(true), 0);
    189189#endif
  • trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp

    r136193 r139888  
    233233
    234234#if PLATFORM(MAC)
    235     if (WebContext::applicationIsOccluded())
     235    if (WebContext::applicationIsOccluded() && WebContext::processSuppressionEnabledForGlobalChildProcesses())
    236236        m_connection->send(Messages::PluginProcess::SetApplicationIsOccluded(true), 0);
    237237#endif
  • trunk/Source/WebKit2/UIProcess/SharedWorkers/SharedWorkerProcessProxy.cpp

    r133699 r139888  
    167167
    168168#if PLATFORM(MAC)
    169     if (WebContext::applicationIsOccluded())
     169    if (WebContext::applicationIsOccluded() && WebContext::processSuppressionEnabledForGlobalChildProcesses())
    170170        m_connection->send(Messages::SharedWorkerProcess::SetApplicationIsOccluded(true), 0);
    171171#endif
  • trunk/Source/WebKit2/UIProcess/WebContext.cpp

    r139541 r139888  
    107107    WTF::initializeMainThread();
    108108    RunLoop::initializeMainRunLoop();
    109 #if PLATFORM(MAC)
    110     WebContext::initializeProcessSuppressionSupport();
    111 #endif
    112109    return adoptRef(new WebContext(ProcessModelSharedSecondaryProcess, injectedBundlePath));
    113110}
     
    145142    , m_usesNetworkProcess(false)
    146143#endif
     144#if PLATFORM(MAC)
     145    , m_processSuppressionEnabled(false)
     146#endif
    147147#if USE(SOUP)
    148148    , m_ignoreTLSErrors(true)
  • trunk/Source/WebKit2/UIProcess/WebContext.h

    r139023 r139888  
    271271
    272272#if PLATFORM(MAC)
    273     static bool applicationIsOccluded() { return s_applicationIsOccluded; }
     273    void setProcessSuppressionEnabled(bool);
     274    bool processSuppressionEnabled() const { return m_processSuppressionEnabled; }
     275    void updateChildProcessesApplicationOcclusionState();
     276    static bool applicationIsOccluded();
     277    static bool processSuppressionEnabledForGlobalChildProcesses();
    274278#endif
    275279
     
    344348
    345349#if PLATFORM(MAC)
    346     static void applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t);
    347     static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t);
    348     static void initializeProcessSuppressionSupport();
    349     static void registerOcclusionNotificationHandlers();
     350    void processSuppressionEnabledChanged();
    350351    void registerNotificationObservers();
    351352    void unregisterNotificationObservers();
     
    449450
    450451#if PLATFORM(MAC)
    451     static bool s_applicationIsOccluded;
     452    bool m_processSuppressionEnabled;
    452453#endif
    453454
  • trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp

    r139009 r139888  
    517517
    518518#if PLATFORM(MAC)
    519     if (WebContext::applicationIsOccluded())
     519    if (WebContext::applicationIsOccluded() && m_context->processSuppressionEnabled())
    520520        connection()->send(Messages::WebProcess::SetApplicationIsOccluded(true), 0);
    521521#endif
  • trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm

    r139241 r139888  
    6666NSString *SchemeForCustomProtocolUnregisteredNotificationName = @"WebKitSchemeForCustomProtocolUnregisteredNotification";
    6767
    68 bool WebContext::s_applicationIsOccluded = false;
     68static bool s_applicationIsOccluded = false;
     69static bool s_occlusionNotificationHandlersRegistered = false;
     70static bool s_processSuppressionEnabledForGlobalChildProcesses = true;
    6971
    7072static void registerUserDefaultsIfNeeded()
     
    8486}
    8587
     88static void updateGlobalChildProcessesApplicationOcclusionState()
     89{
     90    // The plan is to have all child processes become context specific.  This function
     91    // can be removed once that is complete.
     92#if ENABLE(PLUGIN_PROCESS) || ENABLE(SHARED_WORKER_PROCESS)
     93    bool isOccludedForGlobalChildProcesses = s_processSuppressionEnabledForGlobalChildProcesses && s_applicationIsOccluded;
     94#endif
     95#if ENABLE(PLUGIN_PROCESS)
     96    PluginProcessManager::shared().setApplicationIsOccluded(isOccludedForGlobalChildProcesses);
     97#endif
     98#if ENABLE(SHARED_WORKER_PROCESS)
     99    SharedWorkerProcessManager::shared().setApplicationIsOccluded(isOccludedForGlobalChildProcesses);
     100#endif
     101}
     102
     103#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     104static void applicationOcclusionStateChanged()
     105{
     106    const Vector<WebContext*>& contexts = WebContext::allContexts();
     107    for (size_t i = 0, count = contexts.size(); i < count; ++i) {
     108        if (contexts[i]->processSuppressionEnabled())
     109            contexts[i]->updateChildProcessesApplicationOcclusionState();
     110    }
     111
     112    if (s_processSuppressionEnabledForGlobalChildProcesses)
     113        updateGlobalChildProcessesApplicationOcclusionState();
     114}
     115
     116static void applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t)
     117{
     118    if (!s_applicationIsOccluded)
     119        return;
     120    s_applicationIsOccluded = false;
     121    applicationOcclusionStateChanged();
     122}
     123
     124static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t)
     125{
     126    if (s_applicationIsOccluded)
     127        return;
     128    s_applicationIsOccluded = true;
     129    applicationOcclusionStateChanged();
     130}
     131#endif
     132
     133static void registerOcclusionNotificationHandlers()
     134{
     135#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     136    if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameVisible, applicationBecameVisible)) {
     137        WTFLogAlways("Registration of \"Application Became Visible\" notification handler failed.\n");
     138        return;
     139    }
     140   
     141    if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded))
     142        WTFLogAlways("Registration of \"Application Became Occluded\" notification handler failed.\n");
     143#endif
     144}
     145
     146static void unregisterOcclusionNotificationHandlers()
     147{
     148#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     149    if (!WKUnregisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded)) {
     150        WTFLogAlways("Unregistration of \"Application Became Occluded\" notification handler failed.\n");
     151        return;
     152    }
     153   
     154    if (!WKUnregisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameVisible))
     155        WTFLogAlways("Unregistration of \"Application Became Visible\" notification handler failed.\n");
     156#endif
     157}
     158
     159static void enableOcclusionNotifications()
     160{
     161    if (s_occlusionNotificationHandlersRegistered)
     162        return;
     163
     164    static bool shouldOmitProcessSuppression = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKit2OmitProcessSuppression"];
     165    if (shouldOmitProcessSuppression)
     166        return;
     167
     168    s_occlusionNotificationHandlersRegistered = true;
     169    registerOcclusionNotificationHandlers();
     170}
     171
     172static void disableOcclusionNotifications()
     173{
     174    if (!s_occlusionNotificationHandlersRegistered)
     175        return;
     176
     177    s_occlusionNotificationHandlersRegistered = false;
     178    unregisterOcclusionNotificationHandlers();
     179}
     180
     181static void enableProcessSuppressionForGlobalChildProcesses()
     182{
     183    if (s_processSuppressionEnabledForGlobalChildProcesses)
     184        return;
     185
     186    s_processSuppressionEnabledForGlobalChildProcesses = true;
     187    if (s_applicationIsOccluded)
     188        updateGlobalChildProcessesApplicationOcclusionState();
     189}
     190
     191static void disableProcessSuppressionForGlobalChildProcesses()
     192{
     193    if (!s_processSuppressionEnabledForGlobalChildProcesses)
     194        return;
     195
     196    s_processSuppressionEnabledForGlobalChildProcesses = false;
     197    if (s_applicationIsOccluded)
     198        updateGlobalChildProcessesApplicationOcclusionState();
     199}
     200
     201static bool processSuppressionIsEnabledForAnyContext()
     202{
     203    bool result = false;
     204    const Vector<WebContext*>& contexts = WebContext::allContexts();
     205    for (size_t i = 0, count = contexts.size(); i < count; ++i) {
     206        if (contexts[i]->processSuppressionEnabled()) {
     207            result = true;
     208            break;
     209        }
     210    }
     211    return result;
     212}
     213
     214static bool processSuppressionIsEnabledForAllContexts()
     215{
     216    bool result = true;
     217    const Vector<WebContext*>& contexts = WebContext::allContexts();
     218    for (size_t i = 0, count = contexts.size(); i < count; ++i) {
     219        if (!contexts[i]->processSuppressionEnabled()) {
     220            result = false;
     221            break;
     222        }
     223    }
     224    return result;
     225}
     226
    86227void WebContext::platformInitialize()
    87228{
    88229    registerUserDefaultsIfNeeded();
    89230    registerNotificationObservers();
     231    ASSERT(!m_processSuppressionEnabled);
     232    disableProcessSuppressionForGlobalChildProcesses();
    90233}
    91234
     
    298441}
    299442
    300 void WebContext::applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t)
    301 {
    302     if (s_applicationIsOccluded) {
    303         s_applicationIsOccluded = false;
    304 
    305         const Vector<WebContext*>& contexts = WebContext::allContexts();
    306         for (size_t i = 0, count = contexts.size(); i < count; ++i) {
     443void WebContext::setProcessSuppressionEnabled(bool enabled)
     444{
     445    if (m_processSuppressionEnabled == enabled)
     446        return;
     447    m_processSuppressionEnabled = enabled;
     448    processSuppressionEnabledChanged();
     449}
     450
     451void WebContext::updateChildProcessesApplicationOcclusionState()
     452{
     453    bool isOccludedForChildProcesses = m_processSuppressionEnabled && s_applicationIsOccluded;
     454
    307455#if ENABLE(NETWORK_PROCESS)
    308             if (contexts[i]->usesNetworkProcess() && contexts[i]->networkProcess())
    309                 contexts[i]->networkProcess()->setApplicationIsOccluded(false);
    310 #endif
    311 
    312             contexts[i]->sendToAllProcesses(Messages::WebProcess::SetApplicationIsOccluded(false));
    313         }
    314 
    315 #if ENABLE(PLUGIN_PROCESS)
    316         PluginProcessManager::shared().setApplicationIsOccluded(false);
    317 #endif
    318 #if ENABLE(SHARED_WORKER_PROCESS)
    319         SharedWorkerProcessManager::shared().setApplicationIsOccluded(false);
    320 #endif
    321     }
    322 }
    323 
    324 void WebContext::applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t)
    325 {
    326     if (!s_applicationIsOccluded) {
    327         s_applicationIsOccluded = true;
    328         const Vector<WebContext*>& contexts = WebContext::allContexts();
    329         for (size_t i = 0, count = contexts.size(); i < count; ++i) {
    330 #if ENABLE(NETWORK_PROCESS)
    331             if (contexts[i]->usesNetworkProcess() && contexts[i]->networkProcess())
    332                 contexts[i]->networkProcess()->setApplicationIsOccluded(true);
    333 #endif
    334 
    335             contexts[i]->sendToAllProcesses(Messages::WebProcess::SetApplicationIsOccluded(true));
    336         }
    337 
    338 #if ENABLE(PLUGIN_PROCESS)
    339         PluginProcessManager::shared().setApplicationIsOccluded(true);
    340 #endif
    341 #if ENABLE(SHARED_WORKER_PROCESS)
    342         SharedWorkerProcessManager::shared().setApplicationIsOccluded(true);
    343 #endif
    344     }
    345 }
    346 
    347 void WebContext::initializeProcessSuppressionSupport()
    348 {
    349     static bool didInitialize = false;
    350     if (didInitialize)
    351         return;
    352 
    353     didInitialize = true;
    354     // A temporary default until process suppression is enabled by default, at which point a context setting can be added with the
    355     // interpretation that any context disabling process suppression disables it for plugin/network and shared worker processes.
    356     bool processSuppressionSupportEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitProcessSuppressionSupportEnabled"];
    357     if (processSuppressionSupportEnabled)
    358         registerOcclusionNotificationHandlers();
    359 }
    360 
    361 void WebContext::registerOcclusionNotificationHandlers()
    362 {
    363 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
    364     if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameVisible, applicationBecameVisible)) {
    365         WTFLogAlways("Registeration of \"App Became Visible\" notification handler failed.\n");
    366         return;
    367     }
    368 
    369     if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded))
    370         WTFLogAlways("Registeration of \"App Became Occluded\" notification handler failed.\n");
    371 #endif
    372 }
    373    
     456    if (usesNetworkProcess() && networkProcess())
     457        networkProcess()->setApplicationIsOccluded(isOccludedForChildProcesses);
     458#endif
     459    sendToAllProcesses(Messages::WebProcess::SetApplicationIsOccluded(isOccludedForChildProcesses));
     460}
     461
     462bool WebContext::applicationIsOccluded()
     463{
     464    return s_applicationIsOccluded;
     465}
     466
     467bool WebContext::processSuppressionEnabledForGlobalChildProcesses()
     468{
     469    return s_processSuppressionEnabledForGlobalChildProcesses;
     470}
     471
     472void WebContext::processSuppressionEnabledChanged()
     473{
     474    if (s_applicationIsOccluded)
     475        updateChildProcessesApplicationOcclusionState();
     476
     477    if (processSuppressionIsEnabledForAnyContext())
     478        enableOcclusionNotifications();
     479    else
     480        disableOcclusionNotifications();
     481
     482    if (processSuppressionIsEnabledForAllContexts())
     483        enableProcessSuppressionForGlobalChildProcesses();
     484    else
     485        disableProcessSuppressionForGlobalChildProcesses();
     486}
     487
    374488void WebContext::registerNotificationObservers()
    375489{
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r139825 r139888  
    569569                9F54F88F16488E87007DF81A /* ChildProcessMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F54F88E16488E87007DF81A /* ChildProcessMac.mm */; };
    570570                9F54F8951648AE0F007DF81A /* PluginProcessManagerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */; };
     571                9FB5F394169E6A80002C25BF /* WKContextPrivateMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9FB5F392169E6A80002C25BF /* WKContextPrivateMac.cpp */; };
     572                9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
    571573                B62E7310143047A60069EC35 /* WKHitTestResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B62E730F143047A60069EC35 /* WKHitTestResult.cpp */; };
    572574                B62E7312143047B00069EC35 /* WKHitTestResult.h in Headers */ = {isa = PBXBuildFile; fileRef = B62E7311143047B00069EC35 /* WKHitTestResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    18481850                9F54F88E16488E87007DF81A /* ChildProcessMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ChildProcessMac.mm; sourceTree = "<group>"; };
    18491851                9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginProcessManagerMac.mm; sourceTree = "<group>"; };
     1852                9FB5F392169E6A80002C25BF /* WKContextPrivateMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WKContextPrivateMac.cpp; path = mac/WKContextPrivateMac.cpp; sourceTree = "<group>"; };
     1853                9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKContextPrivateMac.h; path = mac/WKContextPrivateMac.h; sourceTree = "<group>"; };
    18501854                A72D5D7F1236CBA800A88B15 /* WebSerializedScriptValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSerializedScriptValue.h; sourceTree = "<group>"; };
    18511855                B396EA5512E0ED2D00F4FEB7 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
     
    33433347                        isa = PBXGroup;
    33443348                        children = (
     3349                                9FB5F392169E6A80002C25BF /* WKContextPrivateMac.cpp */,
     3350                                9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */,
    33453351                                6EE849C61368D92D0038D481 /* WKInspectorPrivateMac.h */,
    33463352                                BCE17B7B1381F1170012A641 /* WKPagePrivateMac.cpp */,
     
    49544960                                51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */,
    49554961                                BCC938E11180DE440085E5FE /* WKContextPrivate.h in Headers */,
     4962                                9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */,
    49564963                                3309345B1315B9980097A7BC /* WKCookieManager.h in Headers */,
    49574964                                512F58FA12A88A5400629530 /* WKCredential.h in Headers */,
     
    59515958                                BCB9E24C1120E15C00A137E0 /* WKContext.cpp in Sources */,
    59525959                                51A555F5128C6C47009ABCEC /* WKContextMenuItem.cpp in Sources */,
     5960                                9FB5F394169E6A80002C25BF /* WKContextPrivateMac.cpp in Sources */,
    59535961                                3309345A1315B9980097A7BC /* WKCookieManager.cpp in Sources */,
    59545962                                512F58F912A88A5400629530 /* WKCredential.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.