Changeset 211551 in webkit


Ignore:
Timestamp:
Feb 2, 2017 12:33:29 AM (7 years ago)
Author:
commit-queue@webkit.org
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_zhang@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_zhang@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_zhang@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_zhang@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_zhang@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.

Location:
trunk/Source
Files:
1 added
1 deleted
14 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211550 r211551  
     12017-02-02  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        In iOS, we should take background assertion when accessing localstorage databases.
     4        https://bugs.webkit.org/show_bug.cgi?id=165478
     5
     6        Move WebSQLiteDatabaseTrackerClient from WebKitLegacy to WebCore so that it can be accessible from
     7        WebKit1 and WebKit2. Previously, to avoid dependencies on UIKit, WebKitLegacy introduced several
     8        global methods for UIKit to setup the start/end background task blocks on runtime (WebKitSetStartBackgroundTaskBlock,
     9        WebKitSetInvalidWebBackgroundTaskIdentifier and WebKitSetEndBackgroundTaskBlock). Since we have to
     10        move the background task handling to WebCore, to avoid adding WebCore dependencies on UIKit, this
     11        patch introdues a new WebCore class WebBackgroundTaskController which holds the start/end background
     12        task blocks. The existing WebKitSetStartBackgroundTaskBlock and WebKitSetEndBackgroundTaskBlock methods
     13        in WebKit1 will use WebBackgroundTaskController to store the blocks set by UIKit.
     14
     15        Reviewed by Brady Eidson.
     16
     17        No new test since this is code refactoring.
     18
     19        * WebCore.xcodeproj/project.pbxproj: Add a new class WebBackgroundTaskController to the project. Also move
     20            WebSQLiteDatabaseTrackerClient from WebKitLegacy to WebCore.
     21        * platform/ios/WebBackgroundTaskController.h: Use properties to hold the blocks for starting or ending background tasks.
     22        * platform/ios/WebBackgroundTaskController.mm:
     23        (+[WebBackgroundTaskController sharedController]):
     24        (-[WebBackgroundTaskController dealloc]):
     25        (-[WebBackgroundTaskController startBackgroundTaskWithExpirationHandler:]): Start a background task with a expiration handler;
     26            to start the background task, we will use backgroundTaskStartBlock set up by UIKit.
     27        (-[WebBackgroundTaskController endBackgroundTaskWithIdentifier:]): Call backgroundTaskEndBlack to end a background task.
     28        * platform/ios/WebSQLiteDatabaseTrackerClient.h: Copied from Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.h.
     29        * platform/ios/WebSQLiteDatabaseTrackerClient.mm: Copied from Source/WebKit/ios/Storage/WebSQLiteDatabaseTrackerClient.mm.
     30        (WebCore::WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient): Make WebSQLiteDatabaseTrackerClient a singleton.
     31        (WebCore::WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient):
     32        (WebCore::WebSQLiteDatabaseTrackerClient::~WebSQLiteDatabaseTrackerClient):
     33        (WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction): Use a utility class WebDatabaseTransactionBackgroundTaskController
     34            to schedule database transaction background task.
     35        (WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction): Use WebDatabaseTransactionBackgroundTaskController to stop
     36            databas transaction background task.
     37        (transactionBackgroundTaskIdentifierLock: Moved from Source/WebKit/mac/Storage/WebDatabaseManager.mm.
     38        (setTransactionBackgroundTaskIdentifier): Ditto.
     39        (getTransactionBackgroundTaskIdentifier): Ditto.
     40        (+[WebDatabaseTransactionBackgroundTaskController startBackgroundTask]): Ditto.
     41        (+[WebDatabaseTransactionBackgroundTaskController endBackgroundTask]): Ditto.
     42
    1432017-02-01  Zan Dobersek  <zdobersek@igalia.com>
    244
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r211539 r211551  
    10121012                1CCDF5BE1990332400BCEBAD /* SVGToOTFFontConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */; };
    10131013                1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */; };
     1014                1F36EA9C1E21BA1700621E25 /* WebBackgroundTaskController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1015                1F36EA9D1E21BA1700621E25 /* WebBackgroundTaskController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */; };
    10141016                1F3C3BEA135CAF3C00B8C1AC /* MediaControls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1F3C3BE8135CAF3C00B8C1AC /* MediaControls.cpp */; };
    10151017                1F3C3BEB135CAF3C00B8C1AC /* MediaControls.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F3C3BE9135CAF3C00B8C1AC /* MediaControls.h */; };
     1018                1F4B419B1E2301C900AC037F /* WebSQLiteDatabaseTrackerClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */; };
    10161019                1F72BF0A187FD4490009BCB3 /* TileControllerMemoryHandlerIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1F72BF08187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.cpp */; };
    10171020                1F72BF0B187FD45C0009BCB3 /* TileControllerMemoryHandlerIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F72BF09187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1021                1F8756B21E22C3350042C40D /* WebSQLiteDatabaseTrackerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10181022                1FAFBF1815A5FA6E00083A20 /* UTIUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */; };
    10191023                1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */; };
     
    81568160                1CDD45E60BA9C84600F90147 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
    81578161                1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; };
     8162                1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebBackgroundTaskController.h; sourceTree = "<group>"; };
     8163                1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebBackgroundTaskController.mm; sourceTree = "<group>"; };
    81588164                1F3C3BE8135CAF3C00B8C1AC /* MediaControls.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControls.cpp; sourceTree = "<group>"; };
    81598165                1F3C3BE9135CAF3C00B8C1AC /* MediaControls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControls.h; sourceTree = "<group>"; };
    81608166                1F72BF08187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileControllerMemoryHandlerIOS.cpp; sourceTree = "<group>"; };
    81618167                1F72BF09187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileControllerMemoryHandlerIOS.h; sourceTree = "<group>"; };
     8168                1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSQLiteDatabaseTrackerClient.mm; sourceTree = "<group>"; };
     8169                1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSQLiteDatabaseTrackerClient.h; sourceTree = "<group>"; };
    81628170                1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTIUtilities.h; sourceTree = "<group>"; };
    81638171                1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIUtilities.mm; sourceTree = "<group>"; };
     
    1993919947                                CDA29A2C1CBF73FC00901CCF /* WebAVPlayerController.h */,
    1994019948                                CDA29A2D1CBF73FC00901CCF /* WebAVPlayerController.mm */,
     19949                                1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */,
     19950                                1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */,
    1994119951                                31403797124BEA7F00AF40E4 /* WebCoreMotionManager.h */,
    1994219952                                31403798124BEA7F00AF40E4 /* WebCoreMotionManager.mm */,
     
    1994819958                                CDA29A2E1CBF73FC00901CCF /* WebPlaybackSessionInterfaceAVKit.h */,
    1994919959                                CDA29A2F1CBF73FC00901CCF /* WebPlaybackSessionInterfaceAVKit.mm */,
     19960                                1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */,
     19961                                1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */,
    1995019962                                3F42B31B1881191B00278AAC /* WebVideoFullscreenControllerAVKit.h */,
    1995119963                                3F42B31C1881191B00278AAC /* WebVideoFullscreenControllerAVKit.mm */,
     
    2563425646                                937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */,
    2563525647                                2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */,
     25648                                1F36EA9C1E21BA1700621E25 /* WebBackgroundTaskController.h in Headers */,
    2563625649                                FDAF19991513D131008DB0C3 /* DirectConvolver.h in Headers */,
    2563725650                                7EDAAFC919A2CCDC0034DFD1 /* DiskCacheMonitorCocoa.h in Headers */,
     
    2572825741                                4F1534E011B533020021FD86 /* EditingBehaviorTypes.h in Headers */,
    2572925742                                3AC648B2129E146500C3EB25 /* EditingBoundary.h in Headers */,
     25743                                1F8756B21E22C3350042C40D /* WebSQLiteDatabaseTrackerClient.h in Headers */,
    2573025744                                9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */,
    2573125745                                4B3043CD0AE0373B00A82647 /* Editor.h in Headers */,
     
    3062630640                                B2FA3DDA0AB75A6F000E5AC4 /* JSSVGPathSegList.cpp in Sources */,
    3062730641                                B2FA3DDC0AB75A6F000E5AC4 /* JSSVGPathSegMovetoAbs.cpp in Sources */,
     30642                                1F36EA9D1E21BA1700621E25 /* WebBackgroundTaskController.mm in Sources */,
    3062830643                                B2FA3DDE0AB75A6F000E5AC4 /* JSSVGPathSegMovetoRel.cpp in Sources */,
    3062930644                                B2FA3DE00AB75A6F000E5AC4 /* JSSVGPatternElement.cpp in Sources */,
     
    3214932164                                93F19B0308245E59001E9ABC /* XSLStyleSheetLibxslt.cpp in Sources */,
    3215032165                                E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */,
     32166                                1F4B419B1E2301C900AC037F /* WebSQLiteDatabaseTrackerClient.mm in Sources */,
    3215132167                                93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */,
    3215232168                                93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */,
  • trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.h

    r211550 r211551  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2010, 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#if PLATFORM(IOS)
    2727
    28 #import "WebSQLiteDatabaseTrackerClient.h"
     28WEBCORE_EXPORT @interface WebBackgroundTaskController : NSObject
    2929
    30 #import "WebDatabaseManagerInternal.h"
    31 #import "WebDatabaseManagerPrivate.h"
     30@property (nonatomic) NSUInteger invalidBackgroundTaskIdentifier;
     31@property (nonatomic, copy) NSUInteger (^backgroundTaskStartBlock)(void (^)());
     32@property (nonatomic, copy) void (^backgroundTaskEndBlock)(NSUInteger);
    3233
    33 #import <WebCore/SQLiteDatabaseTracker.h>
     34+ (WebBackgroundTaskController *)sharedController;
    3435
    35 using namespace WebCore;
     36- (NSUInteger)startBackgroundTaskWithExpirationHandler:(void (^)())handler;
     37- (void)endBackgroundTaskWithIdentifier:(NSUInteger)identifier;
    3638
    37 WebSQLiteDatabaseTrackerClient* WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient()
    38 {
    39     static WebSQLiteDatabaseTrackerClient* sharedClient = new WebSQLiteDatabaseTrackerClient();
    40     return sharedClient;
    41 }
     39@end
    4240
    43 void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction()
    44 {
    45     [WebDatabaseManager willBeginFirstTransaction];
    46 }
    47 
    48 void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
    49 {
    50     [WebDatabaseManager didFinishLastTransaction];
    51 }
    52 
    53 #endif // PLATFORM(IOS)
     41#endif
  • trunk/Source/WebCore/platform/ios/WebBackgroundTaskController.mm

    r211550 r211551  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
     26#import "config.h"
     27#import "WebBackgroundTaskController.h"
     28
    2629#if PLATFORM(IOS)
    2730
    28 #import "WebSQLiteDatabaseTrackerClient.h"
     31@implementation WebBackgroundTaskController
    2932
    30 #import "WebDatabaseManagerInternal.h"
    31 #import "WebDatabaseManagerPrivate.h"
    32 
    33 #import <WebCore/SQLiteDatabaseTracker.h>
    34 
    35 using namespace WebCore;
    36 
    37 WebSQLiteDatabaseTrackerClient* WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient()
     33+ (WebBackgroundTaskController *)sharedController
    3834{
    39     static WebSQLiteDatabaseTrackerClient* sharedClient = new WebSQLiteDatabaseTrackerClient();
    40     return sharedClient;
     35    static WebBackgroundTaskController *sharedController;
     36    if (!sharedController)
     37        sharedController = [[self alloc] init];
     38    return sharedController;
    4139}
    4240
    43 void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction()
     41- (void)dealloc
    4442{
    45     [WebDatabaseManager willBeginFirstTransaction];
     43    [super dealloc];
    4644}
    4745
    48 void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
     46- (NSUInteger)startBackgroundTaskWithExpirationHandler:(void (^)())handler
    4947{
    50     [WebDatabaseManager didFinishLastTransaction];
     48    if (!_backgroundTaskStartBlock)
     49        return _invalidBackgroundTaskIdentifier;
     50    return _backgroundTaskStartBlock(handler);
    5151}
    5252
    53 #endif // PLATFORM(IOS)
     53- (void)endBackgroundTaskWithIdentifier:(NSUInteger)identifier
     54{
     55    if (!_backgroundTaskEndBlock)
     56        return;
     57    _backgroundTaskEndBlock(identifier);
     58}
     59
     60@end
     61
     62#endif
  • trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h

    r211550 r211551  
    2424 */
    2525
    26 #import <WebCore/SQLiteDatabaseTrackerClient.h>
     26#pragma once
    2727
    28 class WebSQLiteDatabaseTrackerClient : public WebCore::SQLiteDatabaseTrackerClient {
     28#include "PlatformExportMacros.h"
     29
     30#if PLATFORM(IOS)
     31
     32#include "SQLiteDatabaseTrackerClient.h"
     33#include <wtf/NeverDestroyed.h>
     34#include <wtf/Noncopyable.h>
     35
     36namespace WebCore {
     37
     38class WebSQLiteDatabaseTrackerClient final : public SQLiteDatabaseTrackerClient {
     39    WTF_MAKE_NONCOPYABLE(WebSQLiteDatabaseTrackerClient);
    2940public:
    30     static WebSQLiteDatabaseTrackerClient* sharedWebSQLiteDatabaseTrackerClient();
    31 
    32     ~WebSQLiteDatabaseTrackerClient() override { }
     41    WEBCORE_EXPORT static WebSQLiteDatabaseTrackerClient& sharedWebSQLiteDatabaseTrackerClient();
    3342
    3443    void willBeginFirstTransaction() override;
     
    3645
    3746private:
    38     WebSQLiteDatabaseTrackerClient() { }
     47    friend class NeverDestroyed<WebSQLiteDatabaseTrackerClient>;
     48    WebSQLiteDatabaseTrackerClient();
     49    virtual ~WebSQLiteDatabaseTrackerClient();
    3950};
     51
     52}
     53
     54#endif
  • trunk/Source/WebKit/ChangeLog

    r210835 r211551  
     12017-02-02  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        In iOS, we should take background assertion when accessing localstorage databases.
     4        https://bugs.webkit.org/show_bug.cgi?id=165478
     5
     6        Reviewed by Brady Eidson.
     7
     8        * WebKit.xcodeproj/project.pbxproj: Moved WebSQLiteDatabaseTrackerClient to WebCore.
     9
    1102017-01-17  Antti Koivisto  <antti@apple.com>
    211
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r209896 r211551  
    705705                A10C1D3D18202FC50036883A /* WebUIKitSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D2E18202FC50036883A /* WebUIKitSupport.h */; settings = {ATTRIBUTES = (Private, ); }; };
    706706                A10C1D3E18202FC50036883A /* WebUIKitSupport.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D2F18202FC50036883A /* WebUIKitSupport.mm */; };
    707                 A10C1D4218202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D4018202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h */; };
    708                 A10C1D4318202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D4118202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm */; };
    709707                A10C1D5F1820300E0036883A /* PopupMenuIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = A10C1D451820300E0036883A /* PopupMenuIOS.h */; };
    710708                A10C1D601820300E0036883A /* PopupMenuIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = A10C1D461820300E0036883A /* PopupMenuIOS.mm */; };
     
    14501448                A10C1D2E18202FC50036883A /* WebUIKitSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebUIKitSupport.h; path = ios/Misc/WebUIKitSupport.h; sourceTree = SOURCE_ROOT; };
    14511449                A10C1D2F18202FC50036883A /* WebUIKitSupport.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebUIKitSupport.mm; path = ios/Misc/WebUIKitSupport.mm; sourceTree = SOURCE_ROOT; };
    1452                 A10C1D4018202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebSQLiteDatabaseTrackerClient.h; path = ios/Storage/WebSQLiteDatabaseTrackerClient.h; sourceTree = SOURCE_ROOT; };
    1453                 A10C1D4118202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebSQLiteDatabaseTrackerClient.mm; path = ios/Storage/WebSQLiteDatabaseTrackerClient.mm; sourceTree = SOURCE_ROOT; };
    14541450                A10C1D451820300E0036883A /* PopupMenuIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PopupMenuIOS.h; path = ios/WebCoreSupport/PopupMenuIOS.h; sourceTree = SOURCE_ROOT; };
    14551451                A10C1D461820300E0036883A /* PopupMenuIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PopupMenuIOS.mm; path = ios/WebCoreSupport/PopupMenuIOS.mm; sourceTree = SOURCE_ROOT; };
     
    18911887                        isa = PBXGroup;
    18921888                        children = (
    1893                                 A10C1D3F18202FDC0036883A /* ios */,
    18941889                                1A6B31241A51F3A900422975 /* StorageAreaImpl.cpp */,
    18951890                                1A6B31251A51F3A900422975 /* StorageAreaImpl.h */,
     
    21362131                                A10C1D2E18202FC50036883A /* WebUIKitSupport.h */,
    21372132                                A10C1D2F18202FC50036883A /* WebUIKitSupport.mm */,
    2138                         );
    2139                         name = ios;
    2140                         sourceTree = "<group>";
    2141                 };
    2142                 A10C1D3F18202FDC0036883A /* ios */ = {
    2143                         isa = PBXGroup;
    2144                         children = (
    2145                                 A10C1D4018202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h */,
    2146                                 A10C1D4118202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm */,
    21472133                        );
    21482134                        name = ios;
     
    31813167                                2DD632C219E5D1F0002E9C7B /* WebSelectionServiceController.h in Headers */,
    31823168                                2D25396618CE85C200270222 /* WebSharingServicePickerController.h in Headers */,
    3183                                 A10C1D4218202FEF0036883A /* WebSQLiteDatabaseTrackerClient.h in Headers */,
    31843169                                3AE15D5012DBDED4009323C8 /* WebStorageManagerInternal.h in Headers */,
    31853170                                3AB02B0012C132B200FBB694 /* WebStorageManagerPrivate.h in Headers */,
     
    36983683                                2DD632C319E5D1F0002E9C7B /* WebSelectionServiceController.mm in Sources */,
    36993684                                2D25396718CE85C200270222 /* WebSharingServicePickerController.mm in Sources */,
    3700                                 A10C1D4318202FEF0036883A /* WebSQLiteDatabaseTrackerClient.mm in Sources */,
    37013685                                3AB02AF612C1319B00FBB694 /* WebStorageManager.mm in Sources */,
    37023686                                1A591D451A2E91BB000907C4 /* WebStorageNamespaceProvider.cpp in Sources */,
  • trunk/Source/WebKit/ios/ChangeLog

    r211156 r211551  
     12017-02-02  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        In iOS, we should take background assertion when accessing localstorage databases.
     4        https://bugs.webkit.org/show_bug.cgi?id=165478
     5
     6        Move application background task handling code from WebKit to WebCore.
     7
     8        Reviewed by Brady Eidson.
     9
     10        * Misc/WebUIKitSupport.h: Remove several methods that only used internally for background
     11            task handling. They are not needed in WebKit any more since background task handling
     12            is moved to WebCore and wrapped in WebBackgroundTaskController class.
     13        * Misc/WebUIKitSupport.mm:
     14        (WebKitSetInvalidWebBackgroundTaskIdentifier): Instead of storing the value in a static global
     15            variable, save it in WebBackgroundTaskController.
     16        (WebKitSetStartBackgroundTaskBlock): Ditto.
     17        (WebKitSetEndBackgroundTaskBlock): Ditto.
     18
    1192017-01-25  Aakash Jain  <aakash_jain@apple.com>
    220
  • trunk/Source/WebKit/ios/Misc/WebUIKitSupport.h

    r187107 r211551  
    4646void WebKitSetEndBackgroundTaskBlock(EndBackgroundTaskBlock);
    4747
    48 // These methods are what WebKit uses to start/stop background tasks after UIKit has set things up.
    49 WebBackgroundTaskIdentifier invalidWebBackgroundTaskIdentifier();
    50 WebBackgroundTaskIdentifier startBackgroundTask(VoidBlock);
    51 void endBackgroundTask(WebBackgroundTaskIdentifier);
    52 
    5348// This method gives WebKit the notifications to listen to so it knows about app Suspend/Resume
    5449void WebKitSetBackgroundAndForegroundNotificationNames(NSString *, NSString *);
  • trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm

    r211156 r211551  
    3838#import <WebCore/ResourceRequest.h>
    3939#import <WebCore/Settings.h>
     40#import <WebCore/WebBackgroundTaskController.h>
    4041#import <WebCore/WebCoreSystemInterface.h>
    4142#import <WebCore/WebCoreThreadSystemInterface.h>
     
    133134}
    134135
    135 static WebBackgroundTaskIdentifier invalidTaskIdentifier = 0;
    136 static StartBackgroundTaskBlock startBackgroundTaskBlock = 0;
    137 static EndBackgroundTaskBlock endBackgroundTaskBlock = 0;
    138 
    139136void WebKitSetInvalidWebBackgroundTaskIdentifier(WebBackgroundTaskIdentifier taskIdentifier)
    140137{
    141     invalidTaskIdentifier = taskIdentifier;
     138    [[WebBackgroundTaskController sharedController] setInvalidBackgroundTaskIdentifier:taskIdentifier];
    142139}
    143140
    144141void WebKitSetStartBackgroundTaskBlock(StartBackgroundTaskBlock startBlock)
    145142{
    146     Block_release(startBackgroundTaskBlock);
    147     startBackgroundTaskBlock = Block_copy(startBlock);   
     143    [[WebBackgroundTaskController sharedController] setBackgroundTaskStartBlock:startBlock];
    148144}
    149145
    150146void WebKitSetEndBackgroundTaskBlock(EndBackgroundTaskBlock endBlock)
    151147{
    152     Block_release(endBackgroundTaskBlock);
    153     endBackgroundTaskBlock = Block_copy(endBlock);   
    154 }
    155 
    156 WebBackgroundTaskIdentifier invalidWebBackgroundTaskIdentifier()
    157 {
    158     return invalidTaskIdentifier;
    159 }
    160 
    161 WebBackgroundTaskIdentifier startBackgroundTask(VoidBlock expirationHandler)
    162 {
    163     if (!startBackgroundTaskBlock)
    164         return invalidTaskIdentifier;
    165     return startBackgroundTaskBlock(expirationHandler);
    166 }
    167 
    168 void endBackgroundTask(WebBackgroundTaskIdentifier taskIdentifier)
    169 {
    170     if (!endBackgroundTaskBlock)
    171         return;
    172     endBackgroundTaskBlock(taskIdentifier);
     148    [[WebBackgroundTaskController sharedController] setBackgroundTaskEndBlock:endBlock];
    173149}
    174150
  • trunk/Source/WebKit/mac/ChangeLog

    r211492 r211551  
     12017-02-02  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        In iOS, we should take background assertion when accessing localstorage databases.
     4        https://bugs.webkit.org/show_bug.cgi?id=165478
     5
     6        Move database transaction background task handling code from WebDatabaseManager to
     7        WebCore's WebSQLiteDatabaseTrackerClient.
     8
     9        Reviewed by Brady Eidson.
     10
     11        * Storage/WebDatabaseManager.mm:
     12        * Storage/WebDatabaseManagerInternal.h: Remove a category for background task handling.
     13        * WebCoreSupport/WebApplicationCache.mm:
     14        (+[WebApplicationCache initializeWithBundleIdentifier:]): Use WebCore::WebSQLiteDatabaseTrackerClient.
     15        * WebView/WebView.mm:
     16        (-[WebView _commonInitializationWithFrameName:groupName:]): Ditto.
     17
    1182017-02-01  Wenson Hsieh  <wenson_hsieh@apple.com>
    219
  • trunk/Source/WebKit/mac/Storage/WebDatabaseManager.mm

    r208727 r211551  
    235235@end
    236236
    237 #if PLATFORM(IOS)
    238 
    239 @implementation WebDatabaseManager (WebDatabaseManagerInternal)
    240 
    241 static Lock& transactionBackgroundTaskIdentifierLock()
    242 {
    243     static NeverDestroyed<Lock> mutex;
    244     return mutex;
    245 }
    246 
    247 static WebBackgroundTaskIdentifier transactionBackgroundTaskIdentifier;
    248 
    249 static void setTransactionBackgroundTaskIdentifier(WebBackgroundTaskIdentifier identifier)
    250 {
    251     transactionBackgroundTaskIdentifier = identifier;
    252 }
    253 
    254 static WebBackgroundTaskIdentifier getTransactionBackgroundTaskIdentifier()
    255 {
    256     static dispatch_once_t pred;
    257     dispatch_once(&pred, ^{
    258         setTransactionBackgroundTaskIdentifier(invalidWebBackgroundTaskIdentifier());
    259     });
    260    
    261     return transactionBackgroundTaskIdentifier;
    262 }
    263 
    264 + (void)willBeginFirstTransaction
    265 {
    266     [self startBackgroundTask];
    267 }
    268 
    269 + (void)didFinishLastTransaction
    270 {
    271     [self endBackgroundTask];
    272 }
    273 
    274 + (void)startBackgroundTask
    275 {
    276     LockHolder lock(transactionBackgroundTaskIdentifierLock());
    277 
    278     // If there's already an existing background task going on, there's no need to start a new one.
    279     if (getTransactionBackgroundTaskIdentifier() != invalidWebBackgroundTaskIdentifier())
    280         return;
    281    
    282     setTransactionBackgroundTaskIdentifier(startBackgroundTask(^ {
    283         DatabaseTracker::singleton().closeAllDatabases(CurrentQueryBehavior::Interrupt);
    284         [WebDatabaseManager endBackgroundTask];
    285     }));
    286 }
    287 
    288 + (void)endBackgroundTask
    289 {
    290     LockHolder lock(transactionBackgroundTaskIdentifierLock());
    291 
    292     // It is possible that we were unable to start the background task when the first transaction began.
    293     // Don't try to end the task in that case.
    294     // It is also possible we finally finish the last transaction right when the background task expires
    295     // and this will end up being called twice for the same background task.  transactionBackgroundTaskIdentifier
    296     // will be invalid for the second caller.
    297     if (getTransactionBackgroundTaskIdentifier() == invalidWebBackgroundTaskIdentifier())
    298         return;
    299        
    300     endBackgroundTask(getTransactionBackgroundTaskIdentifier());
    301     setTransactionBackgroundTaskIdentifier(invalidWebBackgroundTaskIdentifier());
    302 }
    303 
    304 @end
    305 
    306 #endif // PLATFORM(IOS)
    307 
    308237static NSString *databasesDirectoryPath()
    309238{
  • trunk/Source/WebKit/mac/Storage/WebDatabaseManagerInternal.h

    r187926 r211551  
    2828
    2929#import "WebDatabaseManagerPrivate.h"
    30 
    31 #if PLATFORM(IOS)
    32 @interface WebDatabaseManager (WebDatabaseManagerInternal)
    33 + (void)willBeginFirstTransaction;
    34 + (void)didFinishLastTransaction;
    35 + (void)startBackgroundTask;
    36 + (void)endBackgroundTask;
    37 @end
    38 
    39 #endif
  • trunk/Source/WebKit/mac/WebCoreSupport/WebApplicationCache.mm

    r199829 r211551  
    3434
    3535#if PLATFORM(IOS)
    36 #import "WebSQLiteDatabaseTrackerClient.h"
    3736#import <WebCore/RuntimeApplicationChecks.h>
    3837#import <WebCore/SQLiteDatabaseTracker.h>
     38#import <WebCore/WebSQLiteDatabaseTrackerClient.h>
    3939#endif
    4040
     
    5555        return;
    5656
    57     SQLiteDatabaseTracker::setClient(WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
     57    SQLiteDatabaseTracker::setClient(&WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
    5858
    5959    ASSERT(!overrideBundleIdentifier);
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r211492 r211551  
    258258#import "WebPluginController.h"
    259259#import "WebPolicyDelegatePrivate.h"
    260 #import "WebSQLiteDatabaseTrackerClient.h"
    261260#import "WebStorageManagerPrivate.h"
    262261#import "WebUIKitSupport.h"
     
    281280#import <WebCore/WebCoreThreadRun.h>
    282281#import <WebCore/WebEvent.h>
     282#import <WebCore/WebSQLiteDatabaseTrackerClient.h>
    283283#import <WebCore/WebVideoFullscreenControllerAVKit.h>
    284284#import <libkern/OSAtomic.h>
     
    13151315#if PLATFORM(IOS)
    13161316        // Set the WebSQLiteDatabaseTrackerClient.
    1317         SQLiteDatabaseTracker::setClient(WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
     1317        SQLiteDatabaseTracker::setClient(&WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
    13181318
    13191319        if ([standardPreferences databasesEnabled])
  • trunk/Source/WebKit2/ChangeLog

    r211547 r211551  
     12017-02-02  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        In iOS, we should take background assertion when accessing localstorage databases.
     4        https://bugs.webkit.org/show_bug.cgi?id=165478
     5
     6        Just like in WebKit1, when initializing a WKWebView, initialize the database transaction
     7        tracker client. Also, we should set up the start and end background task blocks here. In
     8        WebKit1, this is done inside UIKit.
     9
     10        Reviewed by Brady Eidson.
     11
     12        * UIProcess/API/Cocoa/WKWebView.mm:
     13        (-[WKWebView _initializeWithConfiguration:]):
     14        (-[WKWebView _setUpSQLiteDatabaseTrackerClient]): Set up the start/end background task blocks
     15            and database transaction tracker client.
     16
    1172017-02-01  Wenson Hsieh  <wenson_hsieh@apple.com>
    218
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r211541 r211551  
    9696#import <WebCore/PlatformScreen.h>
    9797#import <WebCore/RuntimeApplicationChecks.h>
     98#import <WebCore/SQLiteDatabaseTracker.h>
    9899#import <WebCore/Settings.h>
    99100#import <WebCore/TextStream.h>
    100101#import <WebCore/ValidationBubble.h>
     102#import <WebCore/WebBackgroundTaskController.h>
     103#import <WebCore/WebSQLiteDatabaseTrackerClient.h>
    101104#import <WebCore/WritingMode.h>
    102105#import <wtf/HashMap.h>
     
    555558#endif
    556559
     560#if PLATFORM(IOS)
     561    [self _setUpSQLiteDatabaseTrackerClient];
     562#endif
     563
    557564    pageToViewMap().add(_page.get(), self);
     565}
     566
     567- (void)_setUpSQLiteDatabaseTrackerClient
     568{
     569#if PLATFORM(IOS)
     570    WebBackgroundTaskController *controller = [WebBackgroundTaskController sharedController];
     571    if (controller.backgroundTaskStartBlock)
     572        return;
     573
     574    controller.backgroundTaskStartBlock = ^NSUInteger (void (^expirationHandler)())
     575    {
     576        return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
     577    };
     578    controller.backgroundTaskEndBlock = ^(UIBackgroundTaskIdentifier taskIdentifier)
     579    {
     580        [[UIApplication sharedApplication] endBackgroundTask:taskIdentifier];
     581    };
     582    controller.invalidBackgroundTaskIdentifier = UIBackgroundTaskInvalid;
     583
     584    WebCore::SQLiteDatabaseTracker::setClient(&WebCore::WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
     585#endif
    558586}
    559587
Note: See TracChangeset for help on using the changeset viewer.