Diff
Modified: trunk/Source/WebKit2/ChangeLog (185893 => 185894)
--- trunk/Source/WebKit2/ChangeLog 2015-06-24 00:43:03 UTC (rev 185893)
+++ trunk/Source/WebKit2/ChangeLog 2015-06-24 00:50:36 UTC (rev 185894)
@@ -1,5 +1,43 @@
2015-06-23 Anders Carlsson <[email protected]>
+ Add a class that tracks whether we're a background or foreground application
+ https://bugs.webkit.org/show_bug.cgi?id=146259
+ rdar://problem/19833808
+
+ Reviewed by Darin Adler.
+
+ First step towards being able to send out these notifications for view services.
+
+ * UIProcess/ApplicationStateTracker.h: Added.
+ (WebKit::ApplicationStateTracker::isInBackground):
+ * UIProcess/ApplicationStateTracker.mm: Added.
+ (WebKit::ApplicationStateTracker::singleton):
+ (WebKit::ApplicationStateTracker::ApplicationStateTracker):
+ (WebKit::ApplicationStateTracker::addListener):
+ (WebKit::ApplicationStateTracker::applicationDidEnterBackground):
+ (WebKit::ApplicationStateTracker::applicationWillEnterForeground):
+ (WebKit::ApplicationStateTracker::invokeListeners):
+ (WebKit::ApplicationStateTracker::pruneListeners):
+ * UIProcess/ios/ProcessAssertionIOS.mm:
+ (-[WKProcessAssertionBackgroundTaskManager init]):
+ (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
+ (-[WKProcessAssertionBackgroundTaskManager _applicationWillEnterForeground]):
+ (-[WKProcessAssertionBackgroundTaskManager _applicationDidEnterBackground]):
+ (-[WKProcessAssertionBackgroundTaskManager dealloc]): Deleted.
+ (-[WKProcessAssertionBackgroundTaskManager _applicationWillEnterForeground:]): Deleted.
+ (-[WKProcessAssertionBackgroundTaskManager _applicationDidEnterBackground:]): Deleted.
+ * UIProcess/ios/WKContentView.h:
+ * UIProcess/ios/WKContentView.mm:
+ (-[WKContentView _commonInitializationWithProcessPool:configuration:]):
+ (-[WKContentView isBackground]):
+ (-[WKContentView _applicationDidEnterBackground]):
+ (-[WKContentView _applicationWillEnterForeground]):
+ (-[WKContentView _applicationDidEnterBackground:]): Deleted.
+ (-[WKContentView _applicationWillEnterForeground:]): Deleted.
+ * WebKit2.xcodeproj/project.pbxproj:
+
+2015-06-23 Anders Carlsson <[email protected]>
+
Remove windowResizerRect code, nobody is using it anymore
https://bugs.webkit.org/show_bug.cgi?id=146265
Added: trunk/Source/WebKit2/UIProcess/ApplicationStateTracker.h (0 => 185894)
--- trunk/Source/WebKit2/UIProcess/ApplicationStateTracker.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/ApplicationStateTracker.h 2015-06-24 00:50:36 UTC (rev 185894)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2015 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 ApplicationStateTracker_h
+#define ApplicationStateTracker_h
+
+#if PLATFORM(IOS)
+
+#import "WeakObjCPtr.h"
+#import <wtf/Forward.h>
+#import <wtf/Vector.h>
+
+namespace WebKit {
+
+class ApplicationStateTracker {
+ friend NeverDestroyed<ApplicationStateTracker>;
+
+public:
+ static ApplicationStateTracker& singleton();
+
+ bool isInBackground() const { return m_isInBackground; }
+
+ void addListener(id, SEL willEnterForegroundSelector, SEL didEnterBackgroundSelector);
+
+private:
+ ApplicationStateTracker();
+ ~ApplicationStateTracker() = delete;
+
+ void applicationDidEnterBackground();
+ void applicationWillEnterForeground();
+
+ struct Listener;
+
+ void invokeListeners(SEL Listener::*);
+ void pruneListeners();
+
+ bool m_isInBackground;
+
+ struct Listener {
+ WeakObjCPtr<id> object;
+ SEL didEnterBackgroundSelector;
+ SEL willEnterForegroundSelector;
+ };
+ Vector<Listener> m_listeners;
+};
+
+}
+
+#endif
+
+#endif // ApplicationStateTracker_h
Added: trunk/Source/WebKit2/UIProcess/ApplicationStateTracker.mm (0 => 185894)
--- trunk/Source/WebKit2/UIProcess/ApplicationStateTracker.mm (rev 0)
+++ trunk/Source/WebKit2/UIProcess/ApplicationStateTracker.mm 2015-06-24 00:50:36 UTC (rev 185894)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015 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 "ApplicationStateTracker.h"
+
+#if PLATFORM(IOS)
+
+#import <UIKit/UIApplication.h>
+#import <wtf/NeverDestroyed.h>
+#import <wtf/ObjcRuntimeExtras.h>
+
+namespace WebKit {
+
+ApplicationStateTracker& ApplicationStateTracker::singleton()
+{
+ static NeverDestroyed<ApplicationStateTracker> applicationStateTracker;
+
+ return applicationStateTracker;
+}
+
+ApplicationStateTracker::ApplicationStateTracker()
+{
+ UIApplication *application = [UIApplication sharedApplication];
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+
+ m_isInBackground = application.applicationState == UIApplicationStateBackground;
+
+ [notificationCenter addObserverForName:UIApplicationDidEnterBackgroundNotification object:application queue:nil usingBlock:[this](NSNotification *) {
+ applicationDidEnterBackground();
+ }];
+
+ [notificationCenter addObserverForName:UIApplicationWillEnterForegroundNotification object:application queue:nil usingBlock:[this](NSNotification *) {
+ applicationWillEnterForeground();
+ }];
+}
+
+void ApplicationStateTracker::addListener(id object, SEL willEnterForegroundSelector, SEL didEnterBackgroundSelector)
+{
+ ASSERT([object respondsToSelector:willEnterForegroundSelector]);
+ ASSERT([object respondsToSelector:didEnterBackgroundSelector]);
+
+ m_listeners.append({ object, willEnterForegroundSelector, didEnterBackgroundSelector });
+}
+
+void ApplicationStateTracker::applicationDidEnterBackground()
+{
+ m_isInBackground = true;
+
+ invokeListeners(&Listener::didEnterBackgroundSelector);
+}
+
+void ApplicationStateTracker::applicationWillEnterForeground()
+{
+ m_isInBackground = false;
+
+ invokeListeners(&Listener::willEnterForegroundSelector);
+}
+
+void ApplicationStateTracker::invokeListeners(SEL Listener::* selector)
+{
+ bool shouldPruneListeners = false;
+
+ for (auto& listener : m_listeners) {
+ auto object = listener.object.get();
+ if (!object) {
+ shouldPruneListeners = true;
+ continue;
+ }
+
+ wtfObjcMsgSend<void>(object.get(), listener.*selector);
+ }
+
+ if (shouldPruneListeners)
+ pruneListeners();
+}
+
+void ApplicationStateTracker::pruneListeners()
+{
+ auto listeners = WTF::move(m_listeners);
+ ASSERT(m_listeners.isEmpty());
+
+ for (auto& listener : listeners) {
+ if (!listener.object)
+ continue;
+
+ m_listeners.append(WTF::move(listener));
+ }
+}
+
+}
+
+#endif
Modified: trunk/Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm (185893 => 185894)
--- trunk/Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm 2015-06-24 00:43:03 UTC (rev 185893)
+++ trunk/Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm 2015-06-24 00:50:36 UTC (rev 185894)
@@ -28,6 +28,7 @@
#if PLATFORM(IOS)
+#import "ApplicationStateTracker.h"
#import "BKSProcessAssertionSPI.h"
#import <UIKit/UIApplication.h>
#import <wtf/HashSet.h>
@@ -52,7 +53,6 @@
@implementation WKProcessAssertionBackgroundTaskManager
{
unsigned _needsToRunInBackgroundCount;
- BOOL _appIsBackground;
UIBackgroundTaskIdentifier _backgroundTask;
HashSet<ProcessAssertionClient*> _clients;
}
@@ -69,22 +69,15 @@
if (!self)
return nil;
- _appIsBackground = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground;
_backgroundTask = UIBackgroundTaskInvalid;
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
- [center addObserver:self selector:@selector(_applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
- [center addObserver:self selector:@selector(_applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ WebKit::ApplicationStateTracker::singleton().addListener(self, _applicationWillEnterForeground, _applicationDidEnterBackground);
return self;
}
- (void)dealloc
{
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
- [center removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
- [center removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
-
if (_backgroundTask != UIBackgroundTaskInvalid)
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
@@ -103,7 +96,7 @@
- (void)_updateBackgroundTask
{
- bool shouldHoldTask = _needsToRunInBackgroundCount && _appIsBackground;
+ bool shouldHoldTask = _needsToRunInBackgroundCount && WebKit::ApplicationStateTracker::singleton().isInBackground();
if (shouldHoldTask && _backgroundTask == UIBackgroundTaskInvalid) {
_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"com.apple.WebKit.ProcessAssertion" expirationHandler:^{
@@ -123,15 +116,13 @@
}
}
-- (void)_applicationWillEnterForeground:(NSNotification *)notification
+- (void)_applicationWillEnterForeground
{
- _appIsBackground = NO;
[self _updateBackgroundTask];
}
-- (void)_applicationDidEnterBackground:(NSNotification *)notification
+- (void)_applicationDidEnterBackground
{
- _appIsBackground = YES;
[self _updateBackgroundTask];
}
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.h (185893 => 185894)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.h 2015-06-24 00:43:03 UTC (rev 185893)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.h 2015-06-24 00:50:36 UTC (rev 185894)
@@ -52,7 +52,6 @@
@package
RefPtr<WebKit::WebPageProxy> _page;
WKWebView *_webView;
- BOOL _isBackground;
}
@property (nonatomic, readonly) WKBrowsingContextController *browsingContextController;
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (185893 => 185894)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm 2015-06-24 00:43:03 UTC (rev 185893)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm 2015-06-24 00:50:36 UTC (rev 185894)
@@ -28,6 +28,7 @@
#if PLATFORM(IOS)
+#import "ApplicationStateTracker.h"
#import "PageClientImplIOS.h"
#import "RemoteLayerTreeDrawingAreaProxy.h"
#import "RemoteScrollingCoordinatorProxy.h"
@@ -188,8 +189,6 @@
_page->setUseFixedLayout(true);
_page->setDelegatesScrolling(true);
- _isBackground = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground;
-
WebProcessPool::statistics().wkViewCount++;
_rootContentView = adoptNS([[UIView alloc] init]);
@@ -211,8 +210,8 @@
self.layer.hitTestsAsOpaque = YES;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:[UIApplication sharedApplication]];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:[UIApplication sharedApplication]];
+ ApplicationStateTracker::singleton().addListener(self, @selector(_applicationDidEnterBackground), @selector(_applicationWillEnterForeground));
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication]];
@@ -306,7 +305,7 @@
- (BOOL)isBackground
{
- return _isBackground;
+ return ApplicationStateTracker::singleton().isInBackground();
}
- (void)_showInspectorHighlight:(const WebCore::Highlight&)highlight
@@ -541,16 +540,14 @@
_page->applicationWillResignActive();
}
-- (void)_applicationDidEnterBackground:(NSNotification*)notification
+- (void)_applicationDidEnterBackground
{
- _isBackground = YES;
_page->applicationDidEnterBackground();
_page->viewStateDidChange(ViewState::AllFlags & ~ViewState::IsInWindow);
}
-- (void)_applicationWillEnterForeground:(NSNotification*)notification
+- (void)_applicationWillEnterForeground
{
- _isBackground = NO;
_page->applicationWillEnterForeground();
if (auto drawingArea = _page->drawingArea())
drawingArea->hideContentUntilNextUpdate();
Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (185893 => 185894)
--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2015-06-24 00:43:03 UTC (rev 185893)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2015-06-24 00:50:36 UTC (rev 185894)
@@ -444,6 +444,8 @@
1AD25E96167AB08100EA9BCD /* DownloadProxyMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD25E94167AB08100EA9BCD /* DownloadProxyMap.h */; };
1AD3306E16B1D991004F60E7 /* StorageAreaImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD3306C16B1D991004F60E7 /* StorageAreaImpl.cpp */; };
1AD3306F16B1D991004F60E7 /* StorageAreaImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD3306D16B1D991004F60E7 /* StorageAreaImpl.h */; };
+ 1AD4C1921B39F33200ABC28E /* ApplicationStateTracker.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AD4C1901B39F33200ABC28E /* ApplicationStateTracker.mm */; };
+ 1AD4C1931B39F33200ABC28E /* ApplicationStateTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD4C1911B39F33200ABC28E /* ApplicationStateTracker.h */; };
1AD60F5D18E20F4C0020C034 /* WKWindowFeatures.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AD60F5B18E20F4C0020C034 /* WKWindowFeatures.mm */; };
1AD60F5E18E20F4C0020C034 /* WKWindowFeatures.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD60F5C18E20F4C0020C034 /* WKWindowFeatures.h */; settings = {ATTRIBUTES = (Public, ); }; };
1AD60F6018E20F740020C034 /* WKWindowFeaturesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD60F5F18E20F740020C034 /* WKWindowFeaturesInternal.h */; };
@@ -2560,6 +2562,8 @@
1AD25E94167AB08100EA9BCD /* DownloadProxyMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadProxyMap.h; sourceTree = "<group>"; };
1AD3306C16B1D991004F60E7 /* StorageAreaImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageAreaImpl.cpp; sourceTree = "<group>"; };
1AD3306D16B1D991004F60E7 /* StorageAreaImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageAreaImpl.h; sourceTree = "<group>"; };
+ 1AD4C1901B39F33200ABC28E /* ApplicationStateTracker.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ApplicationStateTracker.mm; sourceTree = "<group>"; };
+ 1AD4C1911B39F33200ABC28E /* ApplicationStateTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationStateTracker.h; sourceTree = "<group>"; };
1AD60F5B18E20F4C0020C034 /* WKWindowFeatures.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWindowFeatures.mm; sourceTree = "<group>"; };
1AD60F5C18E20F4C0020C034 /* WKWindowFeatures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWindowFeatures.h; sourceTree = "<group>"; };
1AD60F5F18E20F740020C034 /* WKWindowFeaturesInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWindowFeaturesInternal.h; sourceTree = "<group>"; };
@@ -5103,6 +5107,8 @@
isa = PBXGroup;
children = (
C54256AE18BEC16100DE4179 /* forms */,
+ 1AD4C1911B39F33200ABC28E /* ApplicationStateTracker.h */,
+ 1AD4C1901B39F33200ABC28E /* ApplicationStateTracker.mm */,
A115DC6E191D82AB00DA8072 /* _WKWebViewPrintFormatter.h */,
A115DC6D191D82AB00DA8072 /* _WKWebViewPrintFormatter.mm */,
0F0C365D18C110A500F607D7 /* LayerRepresentation.mm */,
@@ -8349,6 +8355,7 @@
1A66BF8F18A052ED002071B4 /* WKWebViewInternal.h in Headers */,
26F9A83B18A3468100AEB88A /* WKWebViewPrivate.h in Headers */,
1AD60F5E18E20F4C0020C034 /* WKWindowFeatures.h in Headers */,
+ 1AD4C1931B39F33200ABC28E /* ApplicationStateTracker.h in Headers */,
1AD60F6018E20F740020C034 /* WKWindowFeaturesInternal.h in Headers */,
BCBECDE816B6416800047A1A /* XPCServiceEntryPoint.h in Headers */,
);
@@ -9579,6 +9586,7 @@
1AEFCC1311D01F96008219D3 /* PluginInfoStore.cpp in Sources */,
1AEFCCBD11D02C5E008219D3 /* PluginInfoStoreMac.mm in Sources */,
1A043977124D034800FFBFB5 /* PluginProcess.cpp in Sources */,
+ 1AD4C1921B39F33200ABC28E /* ApplicationStateTracker.mm in Sources */,
1A0EC907124C0AB8007EF4A5 /* PluginProcessConnection.cpp in Sources */,
1A0EC910124C0AF5007EF4A5 /* PluginProcessConnectionManager.cpp in Sources */,
1A7865B916CAC71500ACE83A /* PluginProcessConnectionManagerMessageReceiver.cpp in Sources */,