Changeset 215907 in webkit


Ignore:
Timestamp:
Apr 27, 2017 4:48:51 PM (7 years ago)
Author:
beidson@apple.com
Message:

Refactor SessionID to support multiple non-ephemeral (persistent) sessions.
https://bugs.webkit.org/show_bug.cgi?id=171367

Reviewed by Andy Estes.

Source/WebCore:

This is also a nice general cleanup of SessionID, including privatizing the "arbitrary number" constructor
and moving encode/decode into the class.

No new tests (Refactor, no behavior change yet).

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • page/SessionID.cpp: Added.

(WebCore::SessionID::generatePersistentSessionID):
(WebCore::SessionID::generateEphemeralSessionID):
(WebCore::SessionID::enableGenerationProtection):

  • page/SessionID.h:

(WebCore::SessionID::SessionID):
(WebCore::SessionID::emptySessionID):
(WebCore::SessionID::hashTableDeletedValue):
(WebCore::SessionID::defaultSessionID):
(WebCore::SessionID::legacyPrivateSessionID):
(WebCore::SessionID::isValid):
(WebCore::SessionID::isEphemeral):
(WebCore::SessionID::encode):
(WebCore::SessionID::decode):
(WTF::HashTraits<WebCore::SessionID>::constructDeletedValue):
(WTF::HashTraits<WebCore::SessionID>::isDeletedValue):

Source/WebKit2:

  • Shared/ChildProcess.cpp:

(WebKit::ChildProcess::initialize): Child processes should never be generating new SessionIDs,

so enable generation protection.

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<SessionID>::encode): Deleted.
(IPC::ArgumentCoder<SessionID>::decode): Deleted.

  • Shared/WebCoreArgumentCoders.h:
  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::createNonPersistent):
(WebKit::generateNonPersistentSessionID): Deleted.

Location:
trunk/Source
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r215683 r215907  
    21022102    page/SecurityOriginData.cpp
    21032103    page/SecurityPolicy.cpp
     2104    page/SessionID.cpp
    21042105    page/Settings.cpp
    21052106    page/SocketProvider.cpp
  • trunk/Source/WebCore/ChangeLog

    r215905 r215907  
     12017-04-27  Brady Eidson  <beidson@apple.com>
     2
     3        Refactor SessionID to support multiple non-ephemeral (persistent) sessions.
     4        https://bugs.webkit.org/show_bug.cgi?id=171367
     5
     6        Reviewed by Andy Estes.
     7
     8        This is also a nice general cleanup of SessionID, including privatizing the "arbitrary number" constructor
     9        and moving encode/decode into the class.
     10
     11        No new tests (Refactor, no behavior change yet).
     12
     13        * CMakeLists.txt:
     14        * WebCore.xcodeproj/project.pbxproj:
     15       
     16        * page/SessionID.cpp: Added.
     17        (WebCore::SessionID::generatePersistentSessionID):
     18        (WebCore::SessionID::generateEphemeralSessionID):
     19        (WebCore::SessionID::enableGenerationProtection):
     20       
     21        * page/SessionID.h:
     22        (WebCore::SessionID::SessionID):
     23        (WebCore::SessionID::emptySessionID):
     24        (WebCore::SessionID::hashTableDeletedValue):
     25        (WebCore::SessionID::defaultSessionID):
     26        (WebCore::SessionID::legacyPrivateSessionID):
     27        (WebCore::SessionID::isValid):
     28        (WebCore::SessionID::isEphemeral):
     29        (WebCore::SessionID::encode):
     30        (WebCore::SessionID::decode):
     31        (WTF::HashTraits<WebCore::SessionID>::constructDeletedValue):
     32        (WTF::HashTraits<WebCore::SessionID>::isDeletedValue):
     33
    1342017-04-27  Said Abou-Hallawa  <sabouhallawa@apple.com>
    235
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r215859 r215907  
    21932193                511EF2CB17F0FD3500E4FA16 /* JSIDBVersionChangeEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 269239911505E1AA009E57FC /* JSIDBVersionChangeEvent.cpp */; };
    21942194                511EF2D117F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511EF2CE17F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp */; };
     2195                511F7D441EB1C39100E47B83 /* SessionID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511F7D431EB1C38900E47B83 /* SessionID.cpp */; };
    21952196                5126E6BB0A2E3B12005C29FA /* IconDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */; };
    21962197                5126E6BC0A2E3B12005C29FA /* IconDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 5126E6BA0A2E3B12005C29FA /* IconDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    25162517                55A336F71D8209F40022C4C7 /* NativeImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 55A336F61D8209F40022C4C7 /* NativeImage.h */; };
    25172518                55A336F91D821E3C0022C4C7 /* ImageBackingStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 55A336F81D821E3C0022C4C7 /* ImageBackingStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
    2518                 55B2BDD71EA923A400BFFCBD /* ImageIOSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 55B2BDD61EA923A400BFFCBD /* ImageIOSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
    25192519                55AF14E51EAAC59B0026EEAA /* UTIRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 55AF14E31EAAC59B0026EEAA /* UTIRegistry.cpp */; };
    25202520                55AF14E61EAAC59B0026EEAA /* UTIRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 55AF14E41EAAC59B0026EEAA /* UTIRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2521                55B2BDD71EA923A400BFFCBD /* ImageIOSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 55B2BDD61EA923A400BFFCBD /* ImageIOSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
    25212522                570440531E5278B200356601 /* CryptoAlgorithmAES_CFB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5712526A1E52527C008FF369 /* CryptoAlgorithmAES_CFB.cpp */; };
    25222523                570440581E53851600356601 /* CryptoAlgorithmAES_CFBMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 570440571E53851600356601 /* CryptoAlgorithmAES_CFBMac.cpp */; };
     
    98899890                511EF2B417F0FC4800E4FA16 /* JSIDBTransaction.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBTransaction.cpp; sourceTree = "<group>"; };
    98909891                511EF2CE17F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBObjectStoreCustom.cpp; sourceTree = "<group>"; };
     9892                511F7D431EB1C38900E47B83 /* SessionID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionID.cpp; sourceTree = "<group>"; };
    98919893                511FAEA91BDC989A00B4AFE4 /* ThreadSafeDataBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadSafeDataBuffer.h; sourceTree = "<group>"; };
    98929894                5123AF161890A4CA0031CDC9 /* IDBKeyRangeData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBKeyRangeData.cpp; sourceTree = "<group>"; };
     
    1023910241                55A336F61D8209F40022C4C7 /* NativeImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeImage.h; sourceTree = "<group>"; };
    1024010242                55A336F81D821E3C0022C4C7 /* ImageBackingStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageBackingStore.h; sourceTree = "<group>"; };
    10241                 55B2BDD61EA923A400BFFCBD /* ImageIOSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageIOSPI.h; sourceTree = "<group>"; };
    1024210243                55AF14E31EAAC59B0026EEAA /* UTIRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UTIRegistry.cpp; sourceTree = "<group>"; };
    1024310244                55AF14E41EAAC59B0026EEAA /* UTIRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UTIRegistry.h; sourceTree = "<group>"; };
     10245                55B2BDD61EA923A400BFFCBD /* ImageIOSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageIOSPI.h; sourceTree = "<group>"; };
    1024410246                55D408F71A7C631800C78450 /* SVGImageClients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGImageClients.h; sourceTree = "<group>"; };
    1024510247                570440571E53851600356601 /* CryptoAlgorithmAES_CFBMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmAES_CFBMac.cpp; sourceTree = "<group>"; };
     
    1925219254                                974D2DA2146A535D00D51F8B /* SecurityPolicy.cpp */,
    1925319255                                974D2DA3146A535D00D51F8B /* SecurityPolicy.h */,
     19256                                511F7D431EB1C38900E47B83 /* SessionID.cpp */,
    1925419257                                756B2CE018B7101600FECFAA /* SessionID.h */,
    1925519258                                14C9A5E90B3D105F005A0232 /* Settings.cpp */,
     
    3333933342                                B2227ACD0D00BF220071B782 /* SVGTextPathElement.cpp in Sources */,
    3334033343                                B2227AD00D00BF220071B782 /* SVGTextPositioningElement.cpp in Sources */,
     33344                                511F7D441EB1C39100E47B83 /* SessionID.cpp in Sources */,
    3334133345                                B2227AD30D00BF220071B782 /* SVGTitleElement.cpp in Sources */,
    3334233346                                1CCDF5BD1990332400BCEBAD /* SVGToOTFFontConversion.cpp in Sources */,
  • trunk/Source/WebCore/page/SessionID.h

    r208179 r215907  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434public:
    3535    SessionID()
    36         : SessionID(emptySessionID()) { }
    37     explicit SessionID(uint64_t sessionID)
    38         : m_sessionID(sessionID) { }
    39     bool isValid() const { return *this != emptySessionID(); }
    40     bool isEphemeral() const { return *this != defaultSessionID(); }
     36        : SessionID(emptySessionID())
     37    {
     38    }
     39
     40    enum SessionConstants : uint64_t {
     41        EphemeralSessionMask    = 0x8000000000000000,
     42        DefaultSessionID        = 1,
     43        LegacyPrivateSessionID  = DefaultSessionID | EphemeralSessionMask,
     44        HashTableEmptyValueID   = 0,
     45        HashTableDeletedValueID = std::numeric_limits<uint64_t>::max(),
     46    };
     47
     48    static SessionID emptySessionID() { return SessionID(HashTableEmptyValueID); }
     49    static SessionID hashTableDeletedValue() { return SessionID(HashTableDeletedValueID); }
     50    static SessionID defaultSessionID() { return SessionID(DefaultSessionID); }
     51    static SessionID legacyPrivateSessionID() { return SessionID(LegacyPrivateSessionID); }
     52
     53    bool isValid() const { return m_sessionID != HashTableEmptyValueID && m_sessionID != HashTableDeletedValueID; }
     54    bool isEphemeral() const { return m_sessionID & EphemeralSessionMask && m_sessionID != HashTableDeletedValueID; }
     55
     56    WEBCORE_EXPORT static SessionID generateEphemeralSessionID();
     57    WEBCORE_EXPORT static SessionID generatePersistentSessionID();
     58    WEBCORE_EXPORT static void enableGenerationProtection();
     59
    4160    uint64_t sessionID() const { return m_sessionID; }
    4261    bool operator==(SessionID sessionID) const { return m_sessionID == sessionID.m_sessionID; }
     
    4463    bool isAlwaysOnLoggingAllowed() const { return !isEphemeral(); }
    4564
    46     static SessionID emptySessionID() { return SessionID(0); }
    47     static SessionID defaultSessionID() { return SessionID(1); }
    48     static SessionID legacyPrivateSessionID() { return SessionID(2); }
     65    template<class Encoder> void encode(Encoder&) const;
     66    template<class Decoder> static bool decode(Decoder&, SessionID&);
     67
    4968private:
     69    explicit SessionID(uint64_t sessionID)
     70        : m_sessionID(sessionID)
     71    {
     72    }
     73
    5074    uint64_t m_sessionID;
    5175};
     76
     77template<class Encoder>
     78void SessionID::encode(Encoder& encoder) const
     79{
     80    // FIXME: Eliminate places that encode invalid SessionIDs, then ASSERT here that the sessionID is valid.
     81    encoder << m_sessionID;
     82}
     83
     84template<class Decoder>
     85bool SessionID::decode(Decoder& decoder, SessionID& sessionID)
     86{
     87    if (!decoder.decode(sessionID.m_sessionID))
     88        return false;
     89
     90    // FIXME: Eliminate places that encode invalid SessionIDs, then fail to decode an invalid sessionID.
     91    return true;
     92}
    5293
    5394} // namespace WebCore
     
    5596namespace WTF {
    5697
    57 // The empty value is emptySessionID(), the deleted value is (-1)
    5898struct SessionIDHash {
    5999    static unsigned hash(const WebCore::SessionID& p) { return intHash(p.sessionID()); }
     
    62102};
    63103template<> struct HashTraits<WebCore::SessionID> : GenericHashTraits<WebCore::SessionID> {
    64     static const uint64_t deletedValueIdentifier = std::numeric_limits<uint64_t>::max();
    65104    static WebCore::SessionID emptyValue() { return WebCore::SessionID::emptySessionID(); }
    66105
    67     static void constructDeletedValue(WebCore::SessionID& slot) { slot = WebCore::SessionID(deletedValueIdentifier); }
    68     static bool isDeletedValue(const WebCore::SessionID& slot) { return slot == WebCore::SessionID(deletedValueIdentifier); }
     106    static void constructDeletedValue(WebCore::SessionID& slot) { slot = WebCore::SessionID::hashTableDeletedValue(); }
     107    static bool isDeletedValue(const WebCore::SessionID& slot) { return slot == WebCore::SessionID::hashTableDeletedValue(); }
    69108};
    70109template<> struct DefaultHash<WebCore::SessionID> {
  • trunk/Source/WebKit2/ChangeLog

    r215900 r215907  
     12017-04-27  Brady Eidson  <beidson@apple.com>
     2
     3        Refactor SessionID to support multiple non-ephemeral (persistent) sessions.
     4        https://bugs.webkit.org/show_bug.cgi?id=171367
     5
     6        Reviewed by Andy Estes.
     7
     8        * Shared/ChildProcess.cpp:
     9        (WebKit::ChildProcess::initialize): Child processes should never be generating new SessionIDs,
     10          so enable generation protection.
     11
     12        * Shared/WebCoreArgumentCoders.cpp:
     13        (IPC::ArgumentCoder<SessionID>::encode): Deleted.
     14        (IPC::ArgumentCoder<SessionID>::decode): Deleted.
     15        * Shared/WebCoreArgumentCoders.h:
     16
     17        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     18        (WebKit::WebsiteDataStore::createNonPersistent):
     19        (WebKit::generateNonPersistentSessionID): Deleted.
     20
    1212017-04-27  Said Abou-Hallawa  <sabouhallawa@apple.com>
    222
  • trunk/Source/WebKit2/Shared/ChildProcess.cpp

    r215173 r215907  
    2929#include "Logging.h"
    3030#include "SandboxInitializationParameters.h"
     31#include <WebCore/SessionID.h>
    3132#include <unistd.h>
    3233
     
    7273    SandboxInitializationParameters sandboxParameters;
    7374    initializeSandbox(parameters, sandboxParameters);
    74    
     75
     76    // In WebKit2, only the UI process should ever be generating non-default SessionIDs.
     77    WebCore::SessionID::enableGenerationProtection();
     78
    7579    m_connection = IPC::Connection::createClientConnection(parameters.connectionIdentifier, *this);
    7680    m_connection->setDidCloseOnConnectionWorkQueueCallback(didCloseOnConnectionWorkQueue);
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r215672 r215907  
    20202020#endif // !USE(COORDINATED_GRAPHICS)
    20212021
    2022 void ArgumentCoder<SessionID>::encode(Encoder& encoder, const SessionID& sessionID)
    2023 {
    2024     encoder << sessionID.sessionID();
    2025 }
    2026 
    2027 bool ArgumentCoder<SessionID>::decode(Decoder& decoder, SessionID& sessionID)
    2028 {
    2029     uint64_t session;
    2030     if (!decoder.decode(session))
    2031         return false;
    2032 
    2033     sessionID = SessionID(session);
    2034 
    2035     return true;
    2036 }
    2037 
    20382022void ArgumentCoder<BlobPart>::encode(Encoder& encoder, const BlobPart& blobPart)
    20392023{
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h

    r215771 r215907  
    494494#endif
    495495
    496 template<> struct ArgumentCoder<WebCore::SessionID> {
    497     static void encode(Encoder&, const WebCore::SessionID&);
    498     static bool decode(Decoder&, WebCore::SessionID&);
    499 };
    500 
    501496template<> struct ArgumentCoder<WebCore::BlobPart> {
    502497    static void encode(Encoder&, const WebCore::BlobPart&);
  • trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r215741 r215907  
    5252namespace WebKit {
    5353
    54 static WebCore::SessionID generateNonPersistentSessionID()
    55 {
    56     // FIXME: We count backwards here to not conflict with API::Session.
    57     static uint64_t sessionID = std::numeric_limits<uint64_t>::max();
    58 
    59     return WebCore::SessionID(--sessionID);
    60 }
    61 
    6254static uint64_t generateIdentifier()
    6355{
     
    6961Ref<WebsiteDataStore> WebsiteDataStore::createNonPersistent()
    7062{
    71     return adoptRef(*new WebsiteDataStore(generateNonPersistentSessionID()));
     63    return adoptRef(*new WebsiteDataStore(WebCore::SessionID::generateEphemeralSessionID()));
    7264}
    7365
Note: See TracChangeset for help on using the changeset viewer.