Title: [140009] tags/Safari-537.26.1/Source/WebKit2

Diff

Modified: tags/Safari-537.26.1/Source/WebKit2/ChangeLog (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/ChangeLog	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/ChangeLog	2013-01-17 19:25:58 UTC (rev 140009)
@@ -1,5 +1,81 @@
 2013-01-17  Lucas Forschler  <lforsch...@apple.com>
 
+        Merge r139888
+
+    2013-01-16  Kiran Muppala  <cmupp...@apple.com>
+
+            Groundwork to enable process suppression by default on Mac
+            https://bugs.webkit.org/show_bug.cgi?id=106513
+
+            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:
+
+2013-01-17  Lucas Forschler  <lforsch...@apple.com>
+
         Merge r139796
 
     2013-01-15  Enrica Casucci  <enr...@apple.com>

Modified: tags/Safari-537.26.1/Source/WebKit2/Shared/mac/ChildProcessMac.mm (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/Shared/mac/ChildProcessMac.mm	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/Shared/mac/ChildProcessMac.mm	2013-01-17 19:25:58 UTC (rev 140009)
@@ -60,6 +60,7 @@
     setpriority(PRIO_DARWIN_PROCESS, 0, 0);
     initializeTimerCoalescingPolicy();
 #endif
+    // Starting as unoccluded.  The proxy for this process will set the actual value from didFinishLaunching().
     setApplicationIsOccluded(false);
 }
 

Copied: tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.cpp (from rev 139888, trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.cpp) (0 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.cpp	                        (rev 0)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.cpp	2013-01-17 19:25:58 UTC (rev 140009)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include "config.h"
+#include "WKContextPrivateMac.h"
+
+#include "WKAPICast.h"
+#include "WebContext.h"
+
+using namespace WebKit;
+
+bool WKContextGetProcessSuppressionEnabled(WKContextRef contextRef)
+{
+    return toImpl(contextRef)->processSuppressionEnabled();
+}
+
+void WKContextSetProcessSuppressionEnabled(WKContextRef contextRef, bool enabled)
+{
+    toImpl(contextRef)->setProcessSuppressionEnabled(enabled);
+}

Copied: tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h (from rev 139888, trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h) (0 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h	                        (rev 0)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h	2013-01-17 19:25:58 UTC (rev 140009)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 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 WKContextPrivateMac_h
+#define WKContextPrivateMac_h
+
+#include <WebKit2/WKBase.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WK_EXPORT bool WKContextGetProcessSuppressionEnabled(WKContextRef context);
+WK_EXPORT void WKContextSetProcessSuppressionEnabled(WKContextRef context, bool enabled);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* WKContextPrivateMac_h */

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp	2013-01-17 19:25:58 UTC (rev 140009)
@@ -184,7 +184,7 @@
     m_numPendingConnectionRequests = 0;
 
 #if PLATFORM(MAC)
-    if (WebContext::applicationIsOccluded())
+    if (WebContext::applicationIsOccluded() && m_webContext->processSuppressionEnabled())
         connection()->send(Messages::NetworkProcess::SetApplicationIsOccluded(true), 0);
 #endif
 }

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp	2013-01-17 19:25:58 UTC (rev 140009)
@@ -232,7 +232,7 @@
     m_numPendingConnectionRequests = 0;
 
 #if PLATFORM(MAC)
-    if (WebContext::applicationIsOccluded())
+    if (WebContext::applicationIsOccluded() && WebContext::processSuppressionEnabledForGlobalChildProcesses())
         m_connection->send(Messages::PluginProcess::SetApplicationIsOccluded(true), 0);
 #endif
 }

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/SharedWorkers/SharedWorkerProcessProxy.cpp (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/SharedWorkers/SharedWorkerProcessProxy.cpp	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/SharedWorkers/SharedWorkerProcessProxy.cpp	2013-01-17 19:25:58 UTC (rev 140009)
@@ -166,7 +166,7 @@
     m_numPendingConnectionRequests = 0;
 
 #if PLATFORM(MAC)
-    if (WebContext::applicationIsOccluded())
+    if (WebContext::applicationIsOccluded() && WebContext::processSuppressionEnabledForGlobalChildProcesses())
         m_connection->send(Messages::SharedWorkerProcess::SetApplicationIsOccluded(true), 0);
 #endif
 }

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebContext.cpp (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebContext.cpp	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebContext.cpp	2013-01-17 19:25:58 UTC (rev 140009)
@@ -106,9 +106,6 @@
     JSC::initializeThreading();
     WTF::initializeMainThread();
     RunLoop::initializeMainRunLoop();
-#if PLATFORM(MAC)
-    WebContext::initializeProcessSuppressionSupport();
-#endif
     return adoptRef(new WebContext(ProcessModelSharedSecondaryProcess, injectedBundlePath));
 }
 
@@ -144,6 +141,9 @@
 #if ENABLE(NETWORK_PROCESS)
     , m_usesNetworkProcess(false)
 #endif
+#if PLATFORM(MAC)
+    , m_processSuppressionEnabled(false)
+#endif
 #if USE(SOUP)
     , m_ignoreTLSErrors(true)
 #endif

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebContext.h (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebContext.h	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebContext.h	2013-01-17 19:25:58 UTC (rev 140009)
@@ -270,7 +270,11 @@
 
 
 #if PLATFORM(MAC)
-    static bool applicationIsOccluded() { return s_applicationIsOccluded; }
+    void setProcessSuppressionEnabled(bool);
+    bool processSuppressionEnabled() const { return m_processSuppressionEnabled; }
+    void updateChildProcessesApplicationOcclusionState();
+    static bool applicationIsOccluded();
+    static bool processSuppressionEnabledForGlobalChildProcesses();
 #endif
 
     static void willStartUsingPrivateBrowsing();
@@ -343,10 +347,7 @@
     String platformDefaultCookieStorageDirectory() const;
 
 #if PLATFORM(MAC)
-    static void applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t);
-    static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t);
-    static void initializeProcessSuppressionSupport();
-    static void registerOcclusionNotificationHandlers();
+    void processSuppressionEnabledChanged();
     void registerNotificationObservers();
     void unregisterNotificationObservers();
 #endif
@@ -448,7 +449,7 @@
     HashMap<uint64_t, RefPtr<DictionaryCallback> > m_dictionaryCallbacks;
 
 #if PLATFORM(MAC)
-    static bool s_applicationIsOccluded;
+    bool m_processSuppressionEnabled;
 #endif
 
 #if USE(SOUP)

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebProcessProxy.cpp (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2013-01-17 19:25:58 UTC (rev 140009)
@@ -516,7 +516,7 @@
     m_context->processDidFinishLaunching(this);
 
 #if PLATFORM(MAC)
-    if (WebContext::applicationIsOccluded())
+    if (WebContext::applicationIsOccluded() && m_context->processSuppressionEnabled())
         connection()->send(Messages::WebProcess::SetApplicationIsOccluded(true), 0);
 #endif
 }

Modified: tags/Safari-537.26.1/Source/WebKit2/UIProcess/mac/WebContextMac.mm (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2013-01-17 19:25:58 UTC (rev 140009)
@@ -65,7 +65,9 @@
 NSString *SchemeForCustomProtocolRegisteredNotificationName = @"WebKitSchemeForCustomProtocolRegisteredNotification";
 NSString *SchemeForCustomProtocolUnregisteredNotificationName = @"WebKitSchemeForCustomProtocolUnregisteredNotification";
 
-bool WebContext::s_applicationIsOccluded = false;
+static bool s_applicationIsOccluded = false;
+static bool s_occlusionNotificationHandlersRegistered = false;
+static bool s_processSuppressionEnabledForGlobalChildProcesses = true;
 
 static void registerUserDefaultsIfNeeded()
 {
@@ -83,10 +85,151 @@
     [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDictionary];
 }
 
+static void updateGlobalChildProcessesApplicationOcclusionState()
+{
+    // The plan is to have all child processes become context specific.  This function
+    // can be removed once that is complete.
+#if ENABLE(PLUGIN_PROCESS) || ENABLE(SHARED_WORKER_PROCESS)
+    bool isOccludedForGlobalChildProcesses = s_processSuppressionEnabledForGlobalChildProcesses && s_applicationIsOccluded;
+#endif
+#if ENABLE(PLUGIN_PROCESS)
+    PluginProcessManager::shared().setApplicationIsOccluded(isOccludedForGlobalChildProcesses);
+#endif
+#if ENABLE(SHARED_WORKER_PROCESS)
+    SharedWorkerProcessManager::shared().setApplicationIsOccluded(isOccludedForGlobalChildProcesses);
+#endif
+}
+
+#if __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]->updateChildProcessesApplicationOcclusionState();
+    }
+
+    if (s_processSuppressionEnabledForGlobalChildProcesses)
+        updateGlobalChildProcessesApplicationOcclusionState();
+}
+
+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();
+}
+#endif
+
+static void registerOcclusionNotificationHandlers()
+{
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameVisible, applicationBecameVisible)) {
+        WTFLogAlways("Registration of \"Application Became Visible\" notification handler failed.\n");
+        return;
+    }
+    
+    if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded))
+        WTFLogAlways("Registration of \"Application Became Occluded\" notification handler failed.\n");
+#endif
+}
+
+static void unregisterOcclusionNotificationHandlers()
+{
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    if (!WKUnregisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded)) {
+        WTFLogAlways("Unregistration of \"Application Became Occluded\" notification handler failed.\n");
+        return;
+    }
+    
+    if (!WKUnregisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameVisible))
+        WTFLogAlways("Unregistration of \"Application Became Visible\" notification handler failed.\n");
+#endif
+}
+
+static void enableOcclusionNotifications()
+{
+    if (s_occlusionNotificationHandlersRegistered)
+        return;
+
+    static bool shouldOmitProcessSuppression = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKit2OmitProcessSuppression"];
+    if (shouldOmitProcessSuppression)
+        return;
+
+    s_occlusionNotificationHandlersRegistered = true;
+    registerOcclusionNotificationHandlers();
+}
+
+static void disableOcclusionNotifications()
+{
+    if (!s_occlusionNotificationHandlersRegistered)
+        return;
+
+    s_occlusionNotificationHandlersRegistered = false;
+    unregisterOcclusionNotificationHandlers();
+}
+
+static void enableProcessSuppressionForGlobalChildProcesses()
+{
+    if (s_processSuppressionEnabledForGlobalChildProcesses)
+        return;
+
+    s_processSuppressionEnabledForGlobalChildProcesses = true;
+    if (s_applicationIsOccluded)
+        updateGlobalChildProcessesApplicationOcclusionState();
+}
+
+static void disableProcessSuppressionForGlobalChildProcesses()
+{
+    if (!s_processSuppressionEnabledForGlobalChildProcesses)
+        return;
+
+    s_processSuppressionEnabledForGlobalChildProcesses = false;
+    if (s_applicationIsOccluded)
+        updateGlobalChildProcessesApplicationOcclusionState();
+}
+
+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;
+    const Vector<WebContext*>& contexts = WebContext::allContexts();
+    for (size_t i = 0, count = contexts.size(); i < count; ++i) {
+        if (!contexts[i]->processSuppressionEnabled()) {
+            result = false;
+            break;
+        }
+    }
+    return result;
+}
+
 void WebContext::platformInitialize()
 {
     registerUserDefaultsIfNeeded();
     registerNotificationObservers();
+    ASSERT(!m_processSuppressionEnabled);
+    disableProcessSuppressionForGlobalChildProcesses();
 }
 
 String WebContext::applicationCacheDirectory()
@@ -297,80 +440,51 @@
     PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
 }
 
-void WebContext::applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t)
+void WebContext::setProcessSuppressionEnabled(bool enabled)
 {
-    if (s_applicationIsOccluded) {
-        s_applicationIsOccluded = false;
+    if (m_processSuppressionEnabled == enabled)
+        return;
+    m_processSuppressionEnabled = enabled;
+    processSuppressionEnabledChanged();
+}
 
-        const Vector<WebContext*>& contexts = WebContext::allContexts();
-        for (size_t i = 0, count = contexts.size(); i < count; ++i) {
+void WebContext::updateChildProcessesApplicationOcclusionState()
+{
+    bool isOccludedForChildProcesses = m_processSuppressionEnabled && s_applicationIsOccluded;
+
 #if ENABLE(NETWORK_PROCESS)
-            if (contexts[i]->usesNetworkProcess() && contexts[i]->networkProcess())
-                contexts[i]->networkProcess()->setApplicationIsOccluded(false);
+    if (usesNetworkProcess() && networkProcess())
+        networkProcess()->setApplicationIsOccluded(isOccludedForChildProcesses);
 #endif
-
-            contexts[i]->sendToAllProcesses(Messages::WebProcess::SetApplicationIsOccluded(false));
-        }
-
-#if ENABLE(PLUGIN_PROCESS)
-        PluginProcessManager::shared().setApplicationIsOccluded(false);
-#endif
-#if ENABLE(SHARED_WORKER_PROCESS)
-        SharedWorkerProcessManager::shared().setApplicationIsOccluded(false);
-#endif
-    }
+    sendToAllProcesses(Messages::WebProcess::SetApplicationIsOccluded(isOccludedForChildProcesses));
 }
 
-void WebContext::applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t)
+bool WebContext::applicationIsOccluded()
 {
-    if (!s_applicationIsOccluded) {
-        s_applicationIsOccluded = true;
-        const Vector<WebContext*>& contexts = WebContext::allContexts();
-        for (size_t i = 0, count = contexts.size(); i < count; ++i) {
-#if ENABLE(NETWORK_PROCESS)
-            if (contexts[i]->usesNetworkProcess() && contexts[i]->networkProcess())
-                contexts[i]->networkProcess()->setApplicationIsOccluded(true);
-#endif
-
-            contexts[i]->sendToAllProcesses(Messages::WebProcess::SetApplicationIsOccluded(true));
-        }
-
-#if ENABLE(PLUGIN_PROCESS)
-        PluginProcessManager::shared().setApplicationIsOccluded(true);
-#endif
-#if ENABLE(SHARED_WORKER_PROCESS)
-        SharedWorkerProcessManager::shared().setApplicationIsOccluded(true);
-#endif
-    }
+    return s_applicationIsOccluded;
 }
 
-void WebContext::initializeProcessSuppressionSupport()
+bool WebContext::processSuppressionEnabledForGlobalChildProcesses()
 {
-    static bool didInitialize = false;
-    if (didInitialize)
-        return;
-
-    didInitialize = true;
-    // A temporary default until process suppression is enabled by default, at which point a context setting can be added with the
-    // interpretation that any context disabling process suppression disables it for plugin/network and shared worker processes.
-    bool processSuppressionSupportEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitProcessSuppressionSupportEnabled"];
-    if (processSuppressionSupportEnabled)
-        registerOcclusionNotificationHandlers();
+    return s_processSuppressionEnabledForGlobalChildProcesses;
 }
 
-void WebContext::registerOcclusionNotificationHandlers()
+void WebContext::processSuppressionEnabledChanged()
 {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameVisible, applicationBecameVisible)) {
-        WTFLogAlways("Registeration of \"App Became Visible\" notification handler failed.\n");
-        return;
-    }
+    if (s_applicationIsOccluded)
+        updateChildProcessesApplicationOcclusionState();
 
-    if (!WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationTypeApplicationBecameOccluded, applicationBecameOccluded))
-        WTFLogAlways("Registeration of \"App Became Occluded\" notification handler failed.\n");
-#endif
+    if (processSuppressionIsEnabledForAnyContext())
+        enableOcclusionNotifications();
+    else
+        disableOcclusionNotifications();
+
+    if (processSuppressionIsEnabledForAllContexts())
+        enableProcessSuppressionForGlobalChildProcesses();
+    else
+        disableProcessSuppressionForGlobalChildProcesses();
 }
-    
+
 void WebContext::registerNotificationObservers()
 {
     m_customSchemeRegisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {

Modified: tags/Safari-537.26.1/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (140008 => 140009)


--- tags/Safari-537.26.1/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-01-17 19:23:21 UTC (rev 140008)
+++ tags/Safari-537.26.1/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-01-17 19:25:58 UTC (rev 140009)
@@ -566,6 +566,8 @@
 		9F4F59441648B67F00493B7E /* SharedWorkerProcessProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F4F59431648B67F00493B7E /* SharedWorkerProcessProxyMac.mm */; };
 		9F54F88F16488E87007DF81A /* ChildProcessMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F54F88E16488E87007DF81A /* ChildProcessMac.mm */; };
 		9F54F8951648AE0F007DF81A /* PluginProcessManagerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */; };
+		9FB5F394169E6A80002C25BF /* WKContextPrivateMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9FB5F392169E6A80002C25BF /* WKContextPrivateMac.cpp */; };
+		9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		B62E7310143047A60069EC35 /* WKHitTestResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B62E730F143047A60069EC35 /* WKHitTestResult.cpp */; };
 		B62E7312143047B00069EC35 /* WKHitTestResult.h in Headers */ = {isa = PBXBuildFile; fileRef = B62E7311143047B00069EC35 /* WKHitTestResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		B63403F914910D57001070B5 /* APIObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B63403F814910D57001070B5 /* APIObject.cpp */; };
@@ -1847,6 +1849,8 @@
 		9F4F59431648B67F00493B7E /* SharedWorkerProcessProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedWorkerProcessProxyMac.mm; sourceTree = "<group>"; };
 		9F54F88E16488E87007DF81A /* ChildProcessMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ChildProcessMac.mm; sourceTree = "<group>"; };
 		9F54F8941648AE0E007DF81A /* PluginProcessManagerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PluginProcessManagerMac.mm; sourceTree = "<group>"; };
+		9FB5F392169E6A80002C25BF /* WKContextPrivateMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WKContextPrivateMac.cpp; path = mac/WKContextPrivateMac.cpp; sourceTree = "<group>"; };
+		9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKContextPrivateMac.h; path = mac/WKContextPrivateMac.h; sourceTree = "<group>"; };
 		A72D5D7F1236CBA800A88B15 /* WebSerializedScriptValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSerializedScriptValue.h; sourceTree = "<group>"; };
 		B396EA5512E0ED2D00F4FEB7 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
 		B62E730F143047A60069EC35 /* WKHitTestResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKHitTestResult.cpp; sourceTree = "<group>"; };
@@ -3346,6 +3350,8 @@
 		6EE849C41368D9040038D481 /* mac */ = {
 			isa = PBXGroup;
 			children = (
+				9FB5F392169E6A80002C25BF /* WKContextPrivateMac.cpp */,
+				9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */,
 				6EE849C61368D92D0038D481 /* WKInspectorPrivateMac.h */,
 				BCE17B7B1381F1170012A641 /* WKPagePrivateMac.cpp */,
 				BCE17B7C1381F1170012A641 /* WKPagePrivateMac.h */,
@@ -4977,6 +4983,7 @@
 				51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */,
 				51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */,
 				BCC938E11180DE440085E5FE /* WKContextPrivate.h in Headers */,
+				9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */,
 				3309345B1315B9980097A7BC /* WKCookieManager.h in Headers */,
 				512F58FA12A88A5400629530 /* WKCredential.h in Headers */,
 				518ACF1112B015F800B04B83 /* WKCredentialTypes.h in Headers */,
@@ -5975,6 +5982,7 @@
 				BC4A6296147313A0006C681A /* WKConnectionRef.cpp in Sources */,
 				BCB9E24C1120E15C00A137E0 /* WKContext.cpp in Sources */,
 				51A555F5128C6C47009ABCEC /* WKContextMenuItem.cpp in Sources */,
+				9FB5F394169E6A80002C25BF /* WKContextPrivateMac.cpp in Sources */,
 				3309345A1315B9980097A7BC /* WKCookieManager.cpp in Sources */,
 				512F58F912A88A5400629530 /* WKCredential.cpp in Sources */,
 				BC4075F7124FF0270068F20A /* WKData.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to