Title: [211551] trunk/Source
Revision
211551
Author
commit-qu...@webkit.org
Date
2017-02-02 00:33:29 -0800 (Thu, 02 Feb 2017)

Log Message

In iOS, we should take background assertion when accessing localstorage databases.
https://bugs.webkit.org/show_bug.cgi?id=165478

Source/WebCore:

Move WebSQLiteDatabaseTrackerClient from WebKitLegacy to WebCore so that it can be accessible from
WebKit1 and WebKit2. Previously, to avoid dependencies on UIKit, WebKitLegacy introduced several
global methods for UIKit to setup the start/end background task blocks on runtime (WebKitSetStartBackgroundTaskBlock,
WebKitSetInvalidWebBackgroundTaskIdentifier and WebKitSetEndBackgroundTaskBlock). Since we have to
move the background task handling to WebCore, to avoid adding WebCore dependencies on UIKit, this
patch introdues a new WebCore class WebBackgroundTaskController which holds the start/end background
task blocks. The existing WebKitSetStartBackgroundTaskBlock and WebKitSetEndBackgroundTaskBlock methods
in WebKit1 will use WebBackgroundTaskController to store the blocks set by UIKit.

Patch by Yongjun Zhang <yongjun_zh...@apple.com> on 2017-02-02
Reviewed by Brady Eidson.

No new test since this is code refactoring.

* WebCore.xcodeproj/project.pbxproj: Add a new class WebBackgroundTaskController to the project. Also move
    WebSQLiteDatabaseTrackerClient from WebKitLegacy to WebCore.
* platform/ios/WebBackgroundTaskController.h: Use properties to hold the blocks for starting or ending background tasks.
* platform/ios/WebBackgroundTaskController.mm:
(+[WebBackgroundTaskController sharedController]):
(-[WebBackgroundTaskController dealloc]):
(-[WebBackgroundTaskController startBackgroundTaskWithExpirationHandler:]): Start a background task with a expiration handler;
    to start the background task, we will use backgroundTaskStartBlock set up by UIKit.
(-[WebBackgroundTaskController endBackgroundTaskWithIdentifier:]): Call backgroundTaskEndBlack to end a background task.
* platform/ios/WebSQLiteDatabaseTrackerClient.h: Copied from Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.h.
* platform/ios/WebSQLiteDatabaseTrackerClient.mm: Copied from Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.mm.
(WebCore::WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient): Make WebSQLiteDatabaseTrackerClient a singleton.
(WebCore::WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient):
(WebCore::WebSQLiteDatabaseTrackerClient::~WebSQLiteDatabaseTrackerClient):
(WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction): Use a utility class WebDatabaseTransactionBackgroundTaskController
    to schedule database transaction background task.
(WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction): Use WebDatabaseTransactionBackgroundTaskController to stop
    databas transaction background task.
(transactionBackgroundTaskIdentifierLock: Moved from Source/WebKit/mac/Storage/WebDatabaseManager.mm.
(setTransactionBackgroundTaskIdentifier): Ditto.
(getTransactionBackgroundTaskIdentifier): Ditto.
(+[WebDatabaseTransactionBackgroundTaskController startBackgroundTask]): Ditto.
(+[WebDatabaseTransactionBackgroundTaskController endBackgroundTask]): Ditto.

Source/WebKit:

Patch by Yongjun Zhang <yongjun_zh...@apple.com> on 2017-02-02
Reviewed by Brady Eidson.

* WebKit.xcodeproj/project.pbxproj: Moved WebSQLiteDatabaseTrackerClient to WebCore.

Source/WebKit/ios:

Move application background task handling code from WebKit to WebCore.

Patch by Yongjun Zhang <yongjun_zh...@apple.com> on 2017-02-02
Reviewed by Brady Eidson.

* Misc/WebUIKitSupport.h: Remove several methods that only used internally for background
    task handling. They are not needed in WebKit any more since background task handling
    is moved to WebCore and wrapped in WebBackgroundTaskController class.
* Misc/WebUIKitSupport.mm:
(WebKitSetInvalidWebBackgroundTaskIdentifier): Instead of storing the value in a static global
    variable, save it in WebBackgroundTaskController.
(WebKitSetStartBackgroundTaskBlock): Ditto.
(WebKitSetEndBackgroundTaskBlock): Ditto.

Source/WebKit/mac:

Move database transaction background task handling code from WebDatabaseManager to
WebCore's WebSQLiteDatabaseTrackerClient.

Patch by Yongjun Zhang <yongjun_zh...@apple.com> on 2017-02-02
Reviewed by Brady Eidson.

* Storage/WebDatabaseManager.mm:
* Storage/WebDatabaseManagerInternal.h: Remove a category for background task handling.
* WebCoreSupport/WebApplicationCache.mm:
(+[WebApplicationCache initializeWithBundleIdentifier:]): Use WebCore::WebSQLiteDatabaseTrackerClient.
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]): Ditto.

Source/WebKit2:

Just like in WebKit1, when initializing a WKWebView, initialize the database transaction
tracker client. Also, we should set up the start and end background task blocks here. In
WebKit1, this is done inside UIKit.

Patch by Yongjun Zhang <yongjun_zh...@apple.com> on 2017-02-02
Reviewed by Brady Eidson.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
(-[WKWebView _setUpSQLiteDatabaseTrackerClient]): Set up the start/end background task blocks
    and database transaction tracker client.

Modified Paths

Added Paths

Removed Paths

  • trunk/Source/WebKit/ios/Storage/

Diff

Modified: trunk/Source/WebCore/ChangeLog (211550 => 211551)


--- trunk/Source/WebCore/ChangeLog	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebCore/ChangeLog	2017-02-02 08:33:29 UTC (rev 211551)
@@ -1,3 +1,45 @@
+2017-02-02  Yongjun Zhang  <yongjun_zh...@apple.com>
+
+        In iOS, we should take background assertion when accessing localstorage databases.
+        https://bugs.webkit.org/show_bug.cgi?id=165478
+
+        Move WebSQLiteDatabaseTrackerClient from WebKitLegacy to WebCore so that it can be accessible from
+        WebKit1 and WebKit2. Previously, to avoid dependencies on UIKit, WebKitLegacy introduced several
+        global methods for UIKit to setup the start/end background task blocks on runtime (WebKitSetStartBackgroundTaskBlock,
+        WebKitSetInvalidWebBackgroundTaskIdentifier and WebKitSetEndBackgroundTaskBlock). Since we have to
+        move the background task handling to WebCore, to avoid adding WebCore dependencies on UIKit, this
+        patch introdues a new WebCore class WebBackgroundTaskController which holds the start/end background
+        task blocks. The existing WebKitSetStartBackgroundTaskBlock and WebKitSetEndBackgroundTaskBlock methods
+        in WebKit1 will use WebBackgroundTaskController to store the blocks set by UIKit. 
+
+        Reviewed by Brady Eidson.
+
+        No new test since this is code refactoring.
+
+        * WebCore.xcodeproj/project.pbxproj: Add a new class WebBackgroundTaskController to the project. Also move
+            WebSQLiteDatabaseTrackerClient from WebKitLegacy to WebCore.
+        * platform/ios/WebBackgroundTaskController.h: Use properties to hold the blocks for starting or ending background tasks.
+        * platform/ios/WebBackgroundTaskController.mm:
+        (+[WebBackgroundTaskController sharedController]):
+        (-[WebBackgroundTaskController dealloc]):
+        (-[WebBackgroundTaskController startBackgroundTaskWithExpirationHandler:]): Start a background task with a expiration handler;
+            to start the background task, we will use backgroundTaskStartBlock set up by UIKit.
+        (-[WebBackgroundTaskController endBackgroundTaskWithIdentifier:]): Call backgroundTaskEndBlack to end a background task.
+        * platform/ios/WebSQLiteDatabaseTrackerClient.h: Copied from Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.h.
+        * platform/ios/WebSQLiteDatabaseTrackerClient.mm: Copied from Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.mm.
+        (WebCore::WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient): Make WebSQLiteDatabaseTrackerClient a singleton.
+        (WebCore::WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient): 
+        (WebCore::WebSQLiteDatabaseTrackerClient::~WebSQLiteDatabaseTrackerClient):
+        (WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction): Use a utility class WebDatabaseTransactionBackgroundTaskController
+            to schedule database transaction background task.
+        (WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction): Use WebDatabaseTransactionBackgroundTaskController to stop
+            databas transaction background task.
+        (transactionBackgroundTaskIdentifierLock: Moved from Source/WebKit/mac/Storage/WebDatabaseManager.mm.
+        (setTransactionBackgroundTaskIdentifier): Ditto.
+        (getTransactionBackgroundTaskIdentifier): Ditto.
+        (+[WebDatabaseTransactionBackgroundTaskController startBackgroundTask]): Ditto.
+        (+[WebDatabaseTransactionBackgroundTaskController endBackgroundTask]): Ditto.
+
 2017-02-01  Zan Dobersek  <zdober...@igalia.com>
 
         [EME] Implement MediaKeySession::update()

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211550 => 211551)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-02-02 08:33:29 UTC (rev 211551)
@@ -1011,10 +1011,14 @@
 		1CCDF5BD1990332400BCEBAD /* SVGToOTFFontConversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CCDF5BB1990332400BCEBAD /* SVGToOTFFontConversion.cpp */; };
 		1CCDF5BE1990332400BCEBAD /* SVGToOTFFontConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */; };
 		1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */; };
+		1F36EA9C1E21BA1700621E25 /* WebBackgroundTaskController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		1F36EA9D1E21BA1700621E25 /* WebBackgroundTaskController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */; };
 		1F3C3BEA135CAF3C00B8C1AC /* MediaControls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1F3C3BE8135CAF3C00B8C1AC /* MediaControls.cpp */; };
 		1F3C3BEB135CAF3C00B8C1AC /* MediaControls.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F3C3BE9135CAF3C00B8C1AC /* MediaControls.h */; };
+		1F4B419B1E2301C900AC037F /* WebSQLiteDatabaseTrackerClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */; };
 		1F72BF0A187FD4490009BCB3 /* TileControllerMemoryHandlerIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1F72BF08187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.cpp */; };
 		1F72BF0B187FD45C0009BCB3 /* TileControllerMemoryHandlerIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F72BF09187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		1F8756B21E22C3350042C40D /* WebSQLiteDatabaseTrackerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1FAFBF1815A5FA6E00083A20 /* UTIUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */; };
 		1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */; };
 		1FC40FB91655CCB60040F29E /* SubimageCacheWithTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FC40FB81655C5910040F29E /* SubimageCacheWithTimer.cpp */; };
@@ -8155,10 +8159,14 @@
 		1CDD45E50BA9C84600F90147 /* WebCore.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebCore.xcconfig; sourceTree = "<group>"; };
 		1CDD45E60BA9C84600F90147 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
 		1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; };
+		1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebBackgroundTaskController.h; sourceTree = "<group>"; };
+		1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebBackgroundTaskController.mm; sourceTree = "<group>"; };
 		1F3C3BE8135CAF3C00B8C1AC /* MediaControls.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControls.cpp; sourceTree = "<group>"; };
 		1F3C3BE9135CAF3C00B8C1AC /* MediaControls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControls.h; sourceTree = "<group>"; };
 		1F72BF08187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileControllerMemoryHandlerIOS.cpp; sourceTree = "<group>"; };
 		1F72BF09187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileControllerMemoryHandlerIOS.h; sourceTree = "<group>"; };
+		1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSQLiteDatabaseTrackerClient.mm; sourceTree = "<group>"; };
+		1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSQLiteDatabaseTrackerClient.h; sourceTree = "<group>"; };
 		1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTIUtilities.h; sourceTree = "<group>"; };
 		1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIUtilities.mm; sourceTree = "<group>"; };
 		1FC40FB71655C5910040F29E /* SubimageCacheWithTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubimageCacheWithTimer.h; sourceTree = "<group>"; };
@@ -19938,6 +19946,8 @@
 				837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */,
 				CDA29A2C1CBF73FC00901CCF /* WebAVPlayerController.h */,
 				CDA29A2D1CBF73FC00901CCF /* WebAVPlayerController.mm */,
+				1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */,
+				1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */,
 				31403797124BEA7F00AF40E4 /* WebCoreMotionManager.h */,
 				31403798124BEA7F00AF40E4 /* WebCoreMotionManager.mm */,
 				E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */,
@@ -19947,6 +19957,8 @@
 				F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */,
 				CDA29A2E1CBF73FC00901CCF /* WebPlaybackSessionInterfaceAVKit.h */,
 				CDA29A2F1CBF73FC00901CCF /* WebPlaybackSessionInterfaceAVKit.mm */,
+				1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */,
+				1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */,
 				3F42B31B1881191B00278AAC /* WebVideoFullscreenControllerAVKit.h */,
 				3F42B31C1881191B00278AAC /* WebVideoFullscreenControllerAVKit.mm */,
 				3FBC4AF2189881560046EE38 /* WebVideoFullscreenInterfaceAVKit.h */,
@@ -25633,6 +25645,7 @@
 				D0BD4F5D1408850F006839B6 /* DictationCommandIOS.h in Headers */,
 				937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */,
 				2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */,
+				1F36EA9C1E21BA1700621E25 /* WebBackgroundTaskController.h in Headers */,
 				FDAF19991513D131008DB0C3 /* DirectConvolver.h in Headers */,
 				7EDAAFC919A2CCDC0034DFD1 /* DiskCacheMonitorCocoa.h in Headers */,
 				0FE5FBD31C3DD51E0007A2CA /* DisplayList.h in Headers */,
@@ -25727,6 +25740,7 @@
 				4F1534DE11B532EC0021FD86 /* EditingBehavior.h in Headers */,
 				4F1534E011B533020021FD86 /* EditingBehaviorTypes.h in Headers */,
 				3AC648B2129E146500C3EB25 /* EditingBoundary.h in Headers */,
+				1F8756B21E22C3350042C40D /* WebSQLiteDatabaseTrackerClient.h in Headers */,
 				9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */,
 				4B3043CD0AE0373B00A82647 /* Editor.h in Headers */,
 				1AF326790D78B9440068F0C4 /* EditorClient.h in Headers */,
@@ -30625,6 +30639,7 @@
 				B2FA3DD80AB75A6F000E5AC4 /* JSSVGPathSegLinetoVerticalRel.cpp in Sources */,
 				B2FA3DDA0AB75A6F000E5AC4 /* JSSVGPathSegList.cpp in Sources */,
 				B2FA3DDC0AB75A6F000E5AC4 /* JSSVGPathSegMovetoAbs.cpp in Sources */,
+				1F36EA9D1E21BA1700621E25 /* WebBackgroundTaskController.mm in Sources */,
 				B2FA3DDE0AB75A6F000E5AC4 /* JSSVGPathSegMovetoRel.cpp in Sources */,
 				B2FA3DE00AB75A6F000E5AC4 /* JSSVGPatternElement.cpp in Sources */,
 				8542A7960AE5C94200DF58DF /* JSSVGPoint.cpp in Sources */,
@@ -32148,6 +32163,7 @@
 				85217E020A5ECD4700DB8D00 /* XSLImportRule.cpp in Sources */,
 				93F19B0308245E59001E9ABC /* XSLStyleSheetLibxslt.cpp in Sources */,
 				E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */,
+				1F4B419B1E2301C900AC037F /* WebSQLiteDatabaseTrackerClient.mm in Sources */,
 				93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */,
 				93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */,
 				E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,

Copied: trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.h (from rev 211550, trunk/Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.mm) (0 => 211551)


--- trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.h	2017-02-02 08:33:29 UTC (rev 211551)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010, 2017 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. ``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
+ * 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.
+ */
+
+#if PLATFORM(IOS)
+
+WEBCORE_EXPORT @interface WebBackgroundTaskController : NSObject
+
+@property (nonatomic) NSUInteger invalidBackgroundTaskIdentifier;
+@property (nonatomic, copy) NSUInteger (^backgroundTaskStartBlock)(void (^)());
+@property (nonatomic, copy) void (^backgroundTaskEndBlock)(NSUInteger);
+
++ (WebBackgroundTaskController *)sharedController;
+
+- (NSUInteger)startBackgroundTaskWithExpirationHandler:(void (^)())handler;
+- (void)endBackgroundTaskWithIdentifier:(NSUInteger)identifier;
+
+@end
+
+#endif

Copied: trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.mm (from rev 211550, trunk/Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.mm) (0 => 211551)


--- trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2017 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. ``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
+ * 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 "WebBackgroundTaskController.h"
+
+#if PLATFORM(IOS)
+
+@implementation WebBackgroundTaskController
+
++ (WebBackgroundTaskController *)sharedController
+{
+    static WebBackgroundTaskController *sharedController;
+    if (!sharedController)
+        sharedController = [[self alloc] init];
+    return sharedController;
+}
+
+- (void)dealloc
+{
+    [super dealloc];
+}
+
+- (NSUInteger)startBackgroundTaskWithExpirationHandler:(void (^)())handler
+{
+    if (!_backgroundTaskStartBlock)
+        return _invalidBackgroundTaskIdentifier;
+    return _backgroundTaskStartBlock(handler);
+}
+
+- (void)endBackgroundTaskWithIdentifier:(NSUInteger)identifier
+{
+    if (!_backgroundTaskEndBlock)
+        return;
+    _backgroundTaskEndBlock(identifier);
+}
+
+@end
+
+#endif

Copied: trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h (from rev 211550, trunk/Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.h) (0 => 211551)


--- trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h	2017-02-02 08:33:29 UTC (rev 211551)
@@ -0,0 +1,54 @@
+/*
+ * 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. ``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
+ * 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.
+ */
+
+#pragma once
+
+#include "PlatformExportMacros.h"
+
+#if PLATFORM(IOS)
+
+#include "SQLiteDatabaseTrackerClient.h"
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+class WebSQLiteDatabaseTrackerClient final : public SQLiteDatabaseTrackerClient {
+    WTF_MAKE_NONCOPYABLE(WebSQLiteDatabaseTrackerClient);
+public:
+    WEBCORE_EXPORT static WebSQLiteDatabaseTrackerClient& sharedWebSQLiteDatabaseTrackerClient();
+
+    void willBeginFirstTransaction() override;
+    void didFinishLastTransaction() override;
+
+private:
+    friend class NeverDestroyed<WebSQLiteDatabaseTrackerClient>;
+    WebSQLiteDatabaseTrackerClient();
+    virtual ~WebSQLiteDatabaseTrackerClient();
+};
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm (0 => 211551)


--- trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2017 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. ``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
+ * 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 "WebSQLiteDatabaseTrackerClient.h"
+
+#if PLATFORM(IOS)
+
+#import "WebBackgroundTaskController.h"
+#import <WebCore/DatabaseTracker.h>
+#import <WebCore/SQLiteDatabaseTracker.h>
+#import <wtf/NeverDestroyed.h>
+
+@interface WebDatabaseTransactionBackgroundTaskController : NSObject
++ (void)startBackgroundTask;
++ (void)endBackgroundTask;
+@end
+
+namespace WebCore {
+
+WebSQLiteDatabaseTrackerClient& WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient()
+{
+    static NeverDestroyed<WebSQLiteDatabaseTrackerClient> client;
+    return client;
+}
+
+WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient()
+{
+}
+
+WebSQLiteDatabaseTrackerClient::~WebSQLiteDatabaseTrackerClient()
+{
+}
+
+void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction()
+{
+    [WebDatabaseTransactionBackgroundTaskController startBackgroundTask];
+}
+
+void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
+{
+    [WebDatabaseTransactionBackgroundTaskController endBackgroundTask];
+}
+
+}
+
+static Lock& transactionBackgroundTaskIdentifierLock()
+{
+    static NeverDestroyed<Lock> mutex;
+    return mutex;
+}
+
+static NSUInteger transactionBackgroundTaskIdentifier;
+
+static void setTransactionBackgroundTaskIdentifier(NSUInteger identifier)
+{
+    transactionBackgroundTaskIdentifier = identifier;
+}
+
+static NSUInteger getTransactionBackgroundTaskIdentifier()
+{
+    static dispatch_once_t pred;
+    dispatch_once(&pred, ^ {
+        setTransactionBackgroundTaskIdentifier([[WebBackgroundTaskController sharedController] invalidBackgroundTaskIdentifier]);
+    });
+
+    return transactionBackgroundTaskIdentifier;
+}
+
+@implementation WebDatabaseTransactionBackgroundTaskController
+
++ (void)startBackgroundTask
+{
+    LockHolder lock(transactionBackgroundTaskIdentifierLock());
+
+    // If there's already an existing background task going on, there's no need to start a new one.
+    WebBackgroundTaskController *backgroundTaskController = [WebBackgroundTaskController sharedController];
+    if (getTransactionBackgroundTaskIdentifier() != [backgroundTaskController invalidBackgroundTaskIdentifier])
+        return;
+
+    setTransactionBackgroundTaskIdentifier([backgroundTaskController startBackgroundTaskWithExpirationHandler:(^ {
+        WebCore::DatabaseTracker::singleton().closeAllDatabases(WebCore::CurrentQueryBehavior::Interrupt);
+        [self endBackgroundTask];
+    })]);
+}
+
++ (void)endBackgroundTask
+{
+    LockHolder lock(transactionBackgroundTaskIdentifierLock());
+
+    // It is possible that we were unable to start the background task when the first transaction began.
+    // Don't try to end the task in that case.
+    // It is also possible we finally finish the last transaction right when the background task expires
+    // and this will end up being called twice for the same background task. transactionBackgroundTaskIdentifier
+    // will be invalid for the second caller.
+    WebBackgroundTaskController *backgroundTaskController = [WebBackgroundTaskController sharedController];
+    if (getTransactionBackgroundTaskIdentifier() == [backgroundTaskController invalidBackgroundTaskIdentifier])
+        return;
+
+    [backgroundTaskController endBackgroundTaskWithIdentifier:getTransactionBackgroundTaskIdentifier()];
+    setTransactionBackgroundTaskIdentifier([backgroundTaskController invalidBackgroundTaskIdentifier]);
+}
+
+@end
+
+#endif // PLATFORM(IOS)

Modified: trunk/Source/WebKit/ChangeLog (211550 => 211551)


--- trunk/Source/WebKit/ChangeLog	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/ChangeLog	2017-02-02 08:33:29 UTC (rev 211551)
@@ -1,3 +1,12 @@
+2017-02-02  Yongjun Zhang  <yongjun_zh...@apple.com>
+
+        In iOS, we should take background assertion when accessing localstorage databases.
+        https://bugs.webkit.org/show_bug.cgi?id=165478
+
+        Reviewed by Brady Eidson.
+
+        * WebKit.xcodeproj/project.pbxproj: Moved WebSQLiteDatabaseTrackerClient to WebCore.
+
 2017-01-17  Antti Koivisto  <an...@apple.com>
 
         Persist derived data

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (211550 => 211551)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-02-02 08:33:29 UTC (rev 211551)
@@ -704,8 +704,6 @@
 		A10C1D3C18202FC50036883A /* WebNSStringExtrasIPhone.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D2D18202FC50036883A /* WebNSStringExtrasIPhone.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A10C1D3D18202FC50036883A /* WebUIKitSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D2E18202FC50036883A /* WebUIKitSupport.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A10C1D3E18202FC50036883A /* WebUIKitSupport.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D2F18202FC50036883A /* WebUIKitSupport.mm */; };
-		A10C1D4218202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D4018202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h */; };
-		A10C1D4318202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D4118202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm */; };
 		A10C1D5F1820300E0036883A /* PopupMenuIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D451820300E0036883A /* PopupMenuIOS.h */; };
 		A10C1D601820300E0036883A /* PopupMenuIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D461820300E0036883A /* PopupMenuIOS.mm */; };
 		A10C1D611820300E0036883A /* SearchPopupMenuIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D471820300E0036883A /* SearchPopupMenuIOS.cpp */; };
@@ -1449,8 +1447,6 @@
 		A10C1D2D18202FC50036883A /* WebNSStringExtrasIPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebNSStringExtrasIPhone.h; path = ios/Misc/WebNSStringExtrasIPhone.h; sourceTree = SOURCE_ROOT; };
 		A10C1D2E18202FC50036883A /* WebUIKitSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebUIKitSupport.h; path = ios/Misc/WebUIKitSupport.h; sourceTree = SOURCE_ROOT; };
 		A10C1D2F18202FC50036883A /* WebUIKitSupport.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebUIKitSupport.mm; path = ios/Misc/WebUIKitSupport.mm; sourceTree = SOURCE_ROOT; };
-		A10C1D4018202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebSQLiteDatabaseTrackerClient.h; path = ios/Storage/WebSQLiteDatabaseTrackerClient.h; sourceTree = SOURCE_ROOT; };
-		A10C1D4118202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebSQLiteDatabaseTrackerClient.mm; path = ios/Storage/WebSQLiteDatabaseTrackerClient.mm; sourceTree = SOURCE_ROOT; };
 		A10C1D451820300E0036883A /* PopupMenuIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PopupMenuIOS.h; path = ios/WebCoreSupport/PopupMenuIOS.h; sourceTree = SOURCE_ROOT; };
 		A10C1D461820300E0036883A /* PopupMenuIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PopupMenuIOS.mm; path = ios/WebCoreSupport/PopupMenuIOS.mm; sourceTree = SOURCE_ROOT; };
 		A10C1D471820300E0036883A /* SearchPopupMenuIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SearchPopupMenuIOS.cpp; path = ios/WebCoreSupport/SearchPopupMenuIOS.cpp; sourceTree = SOURCE_ROOT; };
@@ -1890,7 +1886,6 @@
 		511F3FC30CECC7E200852565 /* Storage */ = {
 			isa = PBXGroup;
 			children = (
-				A10C1D3F18202FDC0036883A /* ios */,
 				1A6B31241A51F3A900422975 /* StorageAreaImpl.cpp */,
 				1A6B31251A51F3A900422975 /* StorageAreaImpl.h */,
 				1A6B31261A51F3A900422975 /* StorageAreaSync.cpp */,
@@ -2139,15 +2134,6 @@
 			name = ios;
 			sourceTree = "<group>";
 		};
-		A10C1D3F18202FDC0036883A /* ios */ = {
-			isa = PBXGroup;
-			children = (
-				A10C1D4018202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h */,
-				A10C1D4118202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm */,
-			);
-			name = ios;
-			sourceTree = "<group>";
-		};
 		A10C1D4418202FFB0036883A /* ios */ = {
 			isa = PBXGroup;
 			children = (
@@ -3180,7 +3166,6 @@
 				A10C1D741820300E0036883A /* WebSelectionRect.h in Headers */,
 				2DD632C219E5D1F0002E9C7B /* WebSelectionServiceController.h in Headers */,
 				2D25396618CE85C200270222 /* WebSharingServicePickerController.h in Headers */,
-				A10C1D4218202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h in Headers */,
 				3AE15D5012DBDED4009323C8 /* WebStorageManagerInternal.h in Headers */,
 				3AB02B0012C132B200FBB694 /* WebStorageManagerPrivate.h in Headers */,
 				1A591D461A2E91BB000907C4 /* WebStorageNamespaceProvider.h in Headers */,
@@ -3697,7 +3682,6 @@
 				A10C1D751820300E0036883A /* WebSelectionRect.m in Sources */,
 				2DD632C319E5D1F0002E9C7B /* WebSelectionServiceController.mm in Sources */,
 				2D25396718CE85C200270222 /* WebSharingServicePickerController.mm in Sources */,
-				A10C1D4318202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm in Sources */,
 				3AB02AF612C1319B00FBB694 /* WebStorageManager.mm in Sources */,
 				1A591D451A2E91BB000907C4 /* WebStorageNamespaceProvider.cpp in Sources */,
 				3ABB3C7B1309C3B500E93D94 /* WebStorageTrackerClient.mm in Sources */,

Modified: trunk/Source/WebKit/ios/ChangeLog (211550 => 211551)


--- trunk/Source/WebKit/ios/ChangeLog	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/ios/ChangeLog	2017-02-02 08:33:29 UTC (rev 211551)
@@ -1,3 +1,21 @@
+2017-02-02  Yongjun Zhang  <yongjun_zh...@apple.com>
+
+        In iOS, we should take background assertion when accessing localstorage databases.
+        https://bugs.webkit.org/show_bug.cgi?id=165478
+
+        Move application background task handling code from WebKit to WebCore.
+
+        Reviewed by Brady Eidson.
+
+        * Misc/WebUIKitSupport.h: Remove several methods that only used internally for background
+            task handling. They are not needed in WebKit any more since background task handling
+            is moved to WebCore and wrapped in WebBackgroundTaskController class.
+        * Misc/WebUIKitSupport.mm:
+        (WebKitSetInvalidWebBackgroundTaskIdentifier): Instead of storing the value in a static global
+            variable, save it in WebBackgroundTaskController.
+        (WebKitSetStartBackgroundTaskBlock): Ditto.
+        (WebKitSetEndBackgroundTaskBlock): Ditto.
+
 2017-01-25  Aakash Jain  <aakash_j...@apple.com>
 
         LoadWebLocalizedStrings method should be moved in correct file

Modified: trunk/Source/WebKit/ios/Misc/WebUIKitSupport.h (211550 => 211551)


--- trunk/Source/WebKit/ios/Misc/WebUIKitSupport.h	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/ios/Misc/WebUIKitSupport.h	2017-02-02 08:33:29 UTC (rev 211551)
@@ -45,11 +45,6 @@
 void WebKitSetStartBackgroundTaskBlock(StartBackgroundTaskBlock);
 void WebKitSetEndBackgroundTaskBlock(EndBackgroundTaskBlock);
 
-// These methods are what WebKit uses to start/stop background tasks after UIKit has set things up.
-WebBackgroundTaskIdentifier invalidWebBackgroundTaskIdentifier();
-WebBackgroundTaskIdentifier startBackgroundTask(VoidBlock);
-void endBackgroundTask(WebBackgroundTaskIdentifier);
-
 // This method gives WebKit the notifications to listen to so it knows about app Suspend/Resume
 void WebKitSetBackgroundAndForegroundNotificationNames(NSString *, NSString *);
 

Modified: trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm (211550 => 211551)


--- trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -37,6 +37,7 @@
 #import <WebCore/PathUtilities.h>
 #import <WebCore/ResourceRequest.h>
 #import <WebCore/Settings.h>
+#import <WebCore/WebBackgroundTaskController.h>
 #import <WebCore/WebCoreSystemInterface.h>
 #import <WebCore/WebCoreThreadSystemInterface.h>
 #import <wtf/spi/darwin/dyldSPI.h>
@@ -132,46 +133,21 @@
     // FIXME: Remove this function.
 }
 
-static WebBackgroundTaskIdentifier invalidTaskIdentifier = 0;
-static StartBackgroundTaskBlock startBackgroundTaskBlock = 0;
-static EndBackgroundTaskBlock endBackgroundTaskBlock = 0;
-
 void WebKitSetInvalidWebBackgroundTaskIdentifier(WebBackgroundTaskIdentifier taskIdentifier)
 {
-    invalidTaskIdentifier = taskIdentifier;
+    [[WebBackgroundTaskController sharedController] setInvalidBackgroundTaskIdentifier:taskIdentifier];
 }
 
 void WebKitSetStartBackgroundTaskBlock(StartBackgroundTaskBlock startBlock)
 {
-    Block_release(startBackgroundTaskBlock);
-    startBackgroundTaskBlock = Block_copy(startBlock);    
+    [[WebBackgroundTaskController sharedController] setBackgroundTaskStartBlock:startBlock];
 }
 
 void WebKitSetEndBackgroundTaskBlock(EndBackgroundTaskBlock endBlock)
 {
-    Block_release(endBackgroundTaskBlock);
-    endBackgroundTaskBlock = Block_copy(endBlock);    
+    [[WebBackgroundTaskController sharedController] setBackgroundTaskEndBlock:endBlock];
 }
 
-WebBackgroundTaskIdentifier invalidWebBackgroundTaskIdentifier()
-{
-    return invalidTaskIdentifier;
-}
-
-WebBackgroundTaskIdentifier startBackgroundTask(VoidBlock expirationHandler)
-{
-    if (!startBackgroundTaskBlock)
-        return invalidTaskIdentifier;
-    return startBackgroundTaskBlock(expirationHandler);
-}
-
-void endBackgroundTask(WebBackgroundTaskIdentifier taskIdentifier)
-{
-    if (!endBackgroundTaskBlock)
-        return;
-    endBackgroundTaskBlock(taskIdentifier);
-}
-
 CGPathRef WebKitCreatePathWithShrinkWrappedRects(NSArray* cgRects, CGFloat radius)
 {
     Vector<FloatRect> rects;

Modified: trunk/Source/WebKit/mac/ChangeLog (211550 => 211551)


--- trunk/Source/WebKit/mac/ChangeLog	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/mac/ChangeLog	2017-02-02 08:33:29 UTC (rev 211551)
@@ -1,3 +1,20 @@
+2017-02-02  Yongjun Zhang  <yongjun_zh...@apple.com>
+
+        In iOS, we should take background assertion when accessing localstorage databases.
+        https://bugs.webkit.org/show_bug.cgi?id=165478
+
+        Move database transaction background task handling code from WebDatabaseManager to
+        WebCore's WebSQLiteDatabaseTrackerClient.
+
+        Reviewed by Brady Eidson.
+
+        * Storage/WebDatabaseManager.mm:
+        * Storage/WebDatabaseManagerInternal.h: Remove a category for background task handling.
+        * WebCoreSupport/WebApplicationCache.mm:
+        (+[WebApplicationCache initializeWithBundleIdentifier:]): Use WebCore::WebSQLiteDatabaseTrackerClient.
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]): Ditto.
+
 2017-02-01  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [WK1] Allow the drag client to be initialized on platforms that do not support drag and drop

Modified: trunk/Source/WebKit/mac/Storage/WebDatabaseManager.mm (211550 => 211551)


--- trunk/Source/WebKit/mac/Storage/WebDatabaseManager.mm	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/mac/Storage/WebDatabaseManager.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -234,77 +234,6 @@
 
 @end
 
-#if PLATFORM(IOS)
-
-@implementation WebDatabaseManager (WebDatabaseManagerInternal)
-
-static Lock& transactionBackgroundTaskIdentifierLock()
-{
-    static NeverDestroyed<Lock> mutex;
-    return mutex;
-}
-
-static WebBackgroundTaskIdentifier transactionBackgroundTaskIdentifier;
-
-static void setTransactionBackgroundTaskIdentifier(WebBackgroundTaskIdentifier identifier)
-{
-    transactionBackgroundTaskIdentifier = identifier;
-}
-
-static WebBackgroundTaskIdentifier getTransactionBackgroundTaskIdentifier()
-{
-    static dispatch_once_t pred;
-    dispatch_once(&pred, ^{
-        setTransactionBackgroundTaskIdentifier(invalidWebBackgroundTaskIdentifier());
-    });
-    
-    return transactionBackgroundTaskIdentifier;
-}
-
-+ (void)willBeginFirstTransaction
-{
-    [self startBackgroundTask];
-}
-
-+ (void)didFinishLastTransaction
-{
-    [self endBackgroundTask];
-}
-
-+ (void)startBackgroundTask
-{
-    LockHolder lock(transactionBackgroundTaskIdentifierLock());
-
-    // If there's already an existing background task going on, there's no need to start a new one.
-    if (getTransactionBackgroundTaskIdentifier() != invalidWebBackgroundTaskIdentifier())
-        return;
-    
-    setTransactionBackgroundTaskIdentifier(startBackgroundTask(^ {
-        DatabaseTracker::singleton().closeAllDatabases(CurrentQueryBehavior::Interrupt);
-        [WebDatabaseManager endBackgroundTask];
-    }));
-}
-
-+ (void)endBackgroundTask
-{
-    LockHolder lock(transactionBackgroundTaskIdentifierLock());
-
-    // It is possible that we were unable to start the background task when the first transaction began.
-    // Don't try to end the task in that case.
-    // It is also possible we finally finish the last transaction right when the background task expires
-    // and this will end up being called twice for the same background task.  transactionBackgroundTaskIdentifier
-    // will be invalid for the second caller.
-    if (getTransactionBackgroundTaskIdentifier() == invalidWebBackgroundTaskIdentifier())
-        return;
-        
-    endBackgroundTask(getTransactionBackgroundTaskIdentifier());
-    setTransactionBackgroundTaskIdentifier(invalidWebBackgroundTaskIdentifier());
-}
-
-@end
-
-#endif // PLATFORM(IOS)
-
 static NSString *databasesDirectoryPath()
 {
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

Modified: trunk/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h (211550 => 211551)


--- trunk/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h	2017-02-02 08:33:29 UTC (rev 211551)
@@ -27,13 +27,3 @@
  */
 
 #import "WebDatabaseManagerPrivate.h"
-
-#if PLATFORM(IOS)
-@interface WebDatabaseManager (WebDatabaseManagerInternal)
-+ (void)willBeginFirstTransaction;
-+ (void)didFinishLastTransaction;
-+ (void)startBackgroundTask;
-+ (void)endBackgroundTask;
-@end
-
-#endif

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebApplicationCache.mm (211550 => 211551)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebApplicationCache.mm	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebApplicationCache.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -33,9 +33,9 @@
 #import <wtf/RetainPtr.h>
 
 #if PLATFORM(IOS)
-#import "WebSQLiteDatabaseTrackerClient.h"
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SQLiteDatabaseTracker.h>
+#import <WebCore/WebSQLiteDatabaseTrackerClient.h>
 #endif
 
 using namespace WebCore;
@@ -54,7 +54,7 @@
     if (initialized)
         return;
 
-    SQLiteDatabaseTracker::setClient(WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
+    SQLiteDatabaseTracker::setClient(&WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
 
     ASSERT(!overrideBundleIdentifier);
     overrideBundleIdentifier = [bundleIdentifier copy];

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (211550 => 211551)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -257,7 +257,6 @@
 #import "WebPlainWhiteView.h"
 #import "WebPluginController.h"
 #import "WebPolicyDelegatePrivate.h"
-#import "WebSQLiteDatabaseTrackerClient.h"
 #import "WebStorageManagerPrivate.h"
 #import "WebUIKitSupport.h"
 #import "WebVisiblePosition.h"
@@ -280,6 +279,7 @@
 #import <WebCore/WebCoreThreadMessage.h>
 #import <WebCore/WebCoreThreadRun.h>
 #import <WebCore/WebEvent.h>
+#import <WebCore/WebSQLiteDatabaseTrackerClient.h>
 #import <WebCore/WebVideoFullscreenControllerAVKit.h>
 #import <libkern/OSAtomic.h>
 #import <wtf/FastMalloc.h>
@@ -1314,7 +1314,7 @@
 
 #if PLATFORM(IOS)
         // Set the WebSQLiteDatabaseTrackerClient.
-        SQLiteDatabaseTracker::setClient(WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
+        SQLiteDatabaseTracker::setClient(&WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
 
         if ([standardPreferences databasesEnabled])
 #endif

Modified: trunk/Source/WebKit2/ChangeLog (211550 => 211551)


--- trunk/Source/WebKit2/ChangeLog	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit2/ChangeLog	2017-02-02 08:33:29 UTC (rev 211551)
@@ -1,3 +1,19 @@
+2017-02-02  Yongjun Zhang  <yongjun_zh...@apple.com>
+
+        In iOS, we should take background assertion when accessing localstorage databases.
+        https://bugs.webkit.org/show_bug.cgi?id=165478
+
+        Just like in WebKit1, when initializing a WKWebView, initialize the database transaction
+        tracker client. Also, we should set up the start and end background task blocks here. In
+        WebKit1, this is done inside UIKit.
+
+        Reviewed by Brady Eidson.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        (-[WKWebView _setUpSQLiteDatabaseTrackerClient]): Set up the start/end background task blocks
+            and database transaction tracker client.
+
 2017-02-01  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Unreviewed, fix the nightly open source build.

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (211550 => 211551)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-02-02 06:28:03 UTC (rev 211550)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-02-02 08:33:29 UTC (rev 211551)
@@ -95,9 +95,12 @@
 #import <WebCore/NSTextFinderSPI.h>
 #import <WebCore/PlatformScreen.h>
 #import <WebCore/RuntimeApplicationChecks.h>
+#import <WebCore/SQLiteDatabaseTracker.h>
 #import <WebCore/Settings.h>
 #import <WebCore/TextStream.h>
 #import <WebCore/ValidationBubble.h>
+#import <WebCore/WebBackgroundTaskController.h>
+#import <WebCore/WebSQLiteDatabaseTrackerClient.h>
 #import <WebCore/WritingMode.h>
 #import <wtf/HashMap.h>
 #import <wtf/MathExtras.h>
@@ -554,9 +557,34 @@
     _page->setFullscreenClient(std::make_unique<WebKit::FullscreenClient>(self));
 #endif
 
+#if PLATFORM(IOS)
+    [self _setUpSQLiteDatabaseTrackerClient];
+#endif
+
     pageToViewMap().add(_page.get(), self);
 }
 
+- (void)_setUpSQLiteDatabaseTrackerClient
+{
+#if PLATFORM(IOS)
+    WebBackgroundTaskController *controller = [WebBackgroundTaskController sharedController];
+    if (controller.backgroundTaskStartBlock)
+        return;
+
+    controller.backgroundTaskStartBlock = ^NSUInteger (void (^expirationHandler)())
+    {
+        return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
+    };
+    controller.backgroundTaskEndBlock = ^(UIBackgroundTaskIdentifier taskIdentifier)
+    {
+        [[UIApplication sharedApplication] endBackgroundTask:taskIdentifier];
+    };
+    controller.invalidBackgroundTaskIdentifier = UIBackgroundTaskInvalid;
+
+    WebCore::SQLiteDatabaseTracker::setClient(&WebCore::WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
+#endif
+}
+
 - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
 {
     if (!(self = [super initWithFrame:frame]))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to