Changeset 221059 in webkit


Ignore:
Timestamp:
Aug 22, 2017 5:09:40 PM (7 years ago)
Author:
Chris Dumez
Message:

Introduce a new CompletionHandler type and use it for NetworkDataTaskClient's completion handlers to help catch bugs
https://bugs.webkit.org/show_bug.cgi?id=175832

Reviewed by Alex Christensen.

Source/WebKit:

Use new CompletionHandler type for NetworkDataTaskClient's completion handlers to help catch bugs.
It actually already found a bug in our HTTP 0.9 error handling which is fixed in this patch
as well.

  • NetworkProcess/NetworkDataTask.cpp:

(WebKit::NetworkDataTask::didReceiveResponse):

  • NetworkProcess/NetworkDataTask.h:
  • NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
  • NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:

(WebKit::NetworkDataTaskCocoa::tryPasswordBasedAuthentication):

  • Shared/Authentication/AuthenticationManager.cpp:

(WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):

  • Shared/Authentication/AuthenticationManager.h:
  • Shared/Authentication/mac/AuthenticationManager.mac.mm:

(WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):

Source/WTF:

Introduce a new CompletionHandler type which wraps a WTF::Function and ensures via assertions
that the function is always called once and only once.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/CompletionHandler.h: Added.

(WTF::CompletionHandler<Out):

Location:
trunk/Source
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r221037 r221059  
     12017-08-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Introduce a new CompletionHandler type and use it for NetworkDataTaskClient's completion handlers to help catch bugs
     4        https://bugs.webkit.org/show_bug.cgi?id=175832
     5
     6        Reviewed by Alex Christensen.
     7
     8        Introduce a new CompletionHandler type which wraps a WTF::Function and ensures via assertions
     9        that the function is always called once and only once.
     10
     11        * WTF.xcodeproj/project.pbxproj:
     12        * wtf/CompletionHandler.h: Added.
     13        (WTF::CompletionHandler<Out):
     14
    1152017-08-22  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r220712 r221059  
    299299                37C7CC291EA40A73007BD956 /* WeakLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakLinking.h; sourceTree = "<group>"; };
    300300                430B47871AAAAC1A001223DA /* StringCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringCommon.h; sourceTree = "<group>"; };
     301                46BA9EAB1F4CD61E009A2BBC /* CompletionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompletionHandler.h; sourceTree = "<group>"; };
    301302                513E170A1CD7D5BF00E3650B /* LoggingAccumulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggingAccumulator.h; sourceTree = "<group>"; };
    302303                515F794B1CFC9F4A00CCED93 /* CrossThreadCopier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossThreadCopier.cpp; sourceTree = "<group>"; };
     
    760761                                0F8F2B90172E00F0007DBDA5 /* CompilationThread.h */,
    761762                                A8A47270151A825A004123FF /* Compiler.h */,
     763                                46BA9EAB1F4CD61E009A2BBC /* CompletionHandler.h */,
    762764                                0FDB698D1B7C643A000C1078 /* Condition.h */,
    763765                                E38C41261EB4E0680042957D /* CPUTime.cpp */,
     
    842844                                0FE164681B6FFC9600400E7C /* Lock.cpp */,
    843845                                0FE164691B6FFC9600400E7C /* Lock.h */,
     846                                0F0FCDDD1DD167F900CCAB53 /* LockAlgorithm.h */,
    844847                                0F31DD701F1308BC0072EB4A /* LockAlgorithmInlines.h */,
    845                                 0F0FCDDD1DD167F900CCAB53 /* LockAlgorithm.h */,
    846848                                0F60F32D1DFCBD1B00416D6C /* LockedPrintStream.cpp */,
    847849                                0F60F32E1DFCBD1B00416D6C /* LockedPrintStream.h */,
     
    13171319                                A8A473AA151A825B004123FF /* bignum.cc in Sources */,
    13181320                                A8A47451151A825B004123FF /* BinarySemaphore.cpp in Sources */,
    1319                                 51F1752D1F3D486000C74950 /* PersistentEncoder.cpp in Sources */,
    13201321                                A8A4738B151A825B004123FF /* BitVector.cpp in Sources */,
    1321                                 A3E4DD931F3A803400DED0B4 /* TextStream.cpp in Sources */,
    13221322                                DCEE22011CEA7551000C2396 /* BlockObjCExceptions.mm in Sources */,
    13231323                                A8A473AC151A825B004123FF /* cached-powers.cc in Sources */,
     
    13261326                                A8A47463151A825B004123FF /* CollatorICU.cpp in Sources */,
    13271327                                0F8F2B92172E0103007DBDA5 /* CompilationThread.cpp in Sources */,
    1328                                 51F1752C1F3D486000C74950 /* PersistentDecoder.cpp in Sources */,
    13291328                                E38C41281EB4E0680042957D /* CPUTime.cpp in Sources */,
    13301329                                E38C41251EB4E04C0042957D /* CPUTimeCocoa.mm in Sources */,
     
    13411340                                A8A473B0151A825B004123FF /* double-conversion.cc in Sources */,
    13421341                                A8A473BA151A825B004123FF /* dtoa.cpp in Sources */,
    1343                                 51F1752B1F3D486000C74950 /* PersistentCoders.cpp in Sources */,
    13441342                                A8A473B3151A825B004123FF /* fast-dtoa.cc in Sources */,
    13451343                                0F7C5FB61D885CF20044F5E2 /* FastBitVector.cpp in Sources */,
     
    13481346                                A8A473B5151A825B004123FF /* fixed-dtoa.cc in Sources */,
    13491347                                1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */,
     1348                                0F5BF1761F23D49A0029D91D /* Gigacage.cpp in Sources */,
    13501349                                0F30BA901E78708E002CA847 /* GlobalVersion.cpp in Sources */,
    13511350                                2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */,
     
    13531352                                0FE1646A1B6FFC9600400E7C /* Lock.cpp in Sources */,
    13541353                                0F60F32F1DFCBD1B00416D6C /* LockedPrintStream.cpp in Sources */,
    1355                                 0FEC3C5E1F368A9700F59B6C /* ReadWriteLock.cpp in Sources */,
    13561354                                53534F2A1EC0E10E00141B2F /* MachExceptions.defs in Sources */,
    13571355                                A8A473E5151A825B004123FF /* MainThread.cpp in Sources */,
     
    13701368                                0FFF19DC1BB334EB00886D91 /* ParallelHelperPool.cpp in Sources */,
    13711369                                0F824A681B7443A0002E345D /* ParkingLot.cpp in Sources */,
     1370                                51F1752B1F3D486000C74950 /* PersistentCoders.cpp in Sources */,
     1371                                51F1752C1F3D486000C74950 /* PersistentDecoder.cpp in Sources */,
     1372                                51F1752D1F3D486000C74950 /* PersistentEncoder.cpp in Sources */,
    13721373                                DCEE22031CEA7551000C2396 /* PlatformUserPreferredLanguagesMac.mm in Sources */,
    13731374                                0F9D3362165DBA73005AD387 /* PrintStream.cpp in Sources */,
     
    13751376                                A3B725EC987446AD93F1A440 /* RandomDevice.cpp in Sources */,
    13761377                                A8A47414151A825B004123FF /* RandomNumber.cpp in Sources */,
     1378                                0FEC3C5E1F368A9700F59B6C /* ReadWriteLock.cpp in Sources */,
    13771379                                A8A4741A151A825B004123FF /* RefCountedLeakCounter.cpp in Sources */,
    13781380                                2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */,
     
    13941396                                A5BA15FC182435A600A82E69 /* StringImplCF.cpp in Sources */,
    13951397                                A5BA15F51824348000A82E69 /* StringImplMac.mm in Sources */,
    1396                                 0F5BF1761F23D49A0029D91D /* Gigacage.cpp in Sources */,
    13971398                                A5BA15F3182433A900A82E69 /* StringMac.mm in Sources */,
    13981399                                0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */,
     
    14051406                                1C181C7F1D3078DA00F5FA16 /* TextBreakIterator.cpp in Sources */,
    14061407                                1C181C961D30800A00F5FA16 /* TextBreakIteratorInternalICUMac.mm in Sources */,
     1408                                A3E4DD931F3A803400DED0B4 /* TextStream.cpp in Sources */,
     1409                                E311FB171F0A568B003C08DE /* ThreadGroup.cpp in Sources */,
    14071410                                A8A4744A151A825B004123FF /* Threading.cpp in Sources */,
    14081411                                A8A4744E151A825B004123FF /* ThreadingPthreads.cpp in Sources */,
    1409                                 E311FB171F0A568B003C08DE /* ThreadGroup.cpp in Sources */,
    14101412                                5311BD5C1EA822F900525281 /* ThreadMessage.cpp in Sources */,
    14111413                                0F66B2901DC97BAB004A1D3F /* TimeWithDynamicClockType.cpp in Sources */,
  • trunk/Source/WebKit/ChangeLog

    r221055 r221059  
     12017-08-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Introduce a new CompletionHandler type and use it for NetworkDataTaskClient's completion handlers to help catch bugs
     4        https://bugs.webkit.org/show_bug.cgi?id=175832
     5
     6        Reviewed by Alex Christensen.
     7
     8        Use new CompletionHandler type for NetworkDataTaskClient's completion handlers to help catch bugs.
     9        It actually already found a bug in our HTTP 0.9 error handling which is fixed in this patch
     10        as well.
     11
     12        * NetworkProcess/NetworkDataTask.cpp:
     13        (WebKit::NetworkDataTask::didReceiveResponse):
     14        * NetworkProcess/NetworkDataTask.h:
     15        * NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
     16        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
     17        (WebKit::NetworkDataTaskCocoa::tryPasswordBasedAuthentication):
     18        * Shared/Authentication/AuthenticationManager.cpp:
     19        (WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):
     20        * Shared/Authentication/AuthenticationManager.h:
     21        * Shared/Authentication/mac/AuthenticationManager.mac.mm:
     22        (WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):
     23
    1242017-08-22  Alex Christensen  <achristensen@webkit.org>
    225
  • trunk/Source/WebKit/NetworkProcess/NetworkDataTask.cpp

    r218765 r221059  
    104104        std::optional<uint16_t> port = url.port();
    105105        if (port && !isDefaultPortForProtocol(port.value(), url.protocol())) {
     106            completionHandler({ });
    106107            cancel();
    107108            m_client->didCompleteWithError({ String(), 0, url, "Cancelled load from '" + url.stringCenterEllipsizedToLength() + "' because it is using HTTP/0.9." });
  • trunk/Source/WebKit/NetworkProcess/NetworkDataTask.h

    r215065 r221059  
    3737#include <WebCore/ResourceRequest.h>
    3838#include <WebCore/Timer.h>
    39 #include <wtf/Function.h>
     39#include <wtf/CompletionHandler.h>
    4040#include <wtf/text/WTFString.h>
    4141
     
    5555enum class AuthenticationChallengeDisposition;
    5656
    57 typedef Function<void(const WebCore::ResourceRequest&)> RedirectCompletionHandler;
    58 typedef Function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)> ChallengeCompletionHandler;
    59 typedef Function<void(WebCore::PolicyAction)> ResponseCompletionHandler;
     57using RedirectCompletionHandler = CompletionHandler<void(const WebCore::ResourceRequest&)>;
     58using ChallengeCompletionHandler = CompletionHandler<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>;
     59using ResponseCompletionHandler = CompletionHandler<void(WebCore::PolicyAction)>;
    6060
    6161class NetworkDataTaskClient {
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h

    r212993 r221059  
    7474    NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::StoredCredentials, WebCore::ContentSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
    7575
    76     bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, const ChallengeCompletionHandler&);
     76    bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&);
    7777
    7878    RefPtr<SandboxExtension> m_sandboxExtension;
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm

    r220243 r221059  
    255255}
    256256
    257 bool NetworkDataTaskCocoa::tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge& challenge, const ChallengeCompletionHandler& completionHandler)
     257bool NetworkDataTaskCocoa::tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge& challenge, ChallengeCompletionHandler& completionHandler)
    258258{
    259259    if (!challenge.protectionSpace().isPasswordBased())
  • trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp

    r219587 r221059  
    190190// Currently, only Mac knows how to respond to authentication challenges with certificate info.
    191191#if !HAVE(SEC_IDENTITY)
    192 bool AuthenticationManager::tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const CertificateInfo&, const ChallengeCompletionHandler&)
     192bool AuthenticationManager::tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const CertificateInfo&, ChallengeCompletionHandler&)
    193193{
    194194    return false;
  • trunk/Source/WebKit/Shared/Authentication/AuthenticationManager.h

    r219587 r221059  
    3131#include "WebProcessSupplement.h"
    3232#include <WebCore/AuthenticationChallenge.h>
     33#include <wtf/CompletionHandler.h>
    3334#include <wtf/Forward.h>
    34 #include <wtf/Function.h>
    3535#include <wtf/HashMap.h>
    3636
     
    5555    RejectProtectionSpace
    5656};
    57 typedef Function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)> ChallengeCompletionHandler;
     57using ChallengeCompletionHandler = CompletionHandler<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>;
    5858
    5959class AuthenticationManager : public WebProcessSupplement, public NetworkProcessSupplement, public IPC::MessageReceiver {
     
    106106    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
    107107
    108     bool tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const WebCore::CertificateInfo&, const ChallengeCompletionHandler&);
     108    bool tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const WebCore::CertificateInfo&, ChallengeCompletionHandler&);
    109109
    110110    uint64_t addChallengeToChallengeMap(Challenge&&);
  • trunk/Source/WebKit/Shared/Authentication/mac/AuthenticationManager.mac.mm

    r210890 r221059  
    7070
    7171// FIXME: This function creates an identity from a certificate, which should not be needed. We should pass an identity over IPC (as we do on iOS).
    72 bool AuthenticationManager::tryUseCertificateInfoForChallenge(const AuthenticationChallenge& challenge, const CertificateInfo& certificateInfo, const ChallengeCompletionHandler& completionHandler)
     72bool AuthenticationManager::tryUseCertificateInfoForChallenge(const AuthenticationChallenge& challenge, const CertificateInfo& certificateInfo, ChallengeCompletionHandler& completionHandler)
    7373{
    7474    if (certificateInfo.isEmpty())
Note: See TracChangeset for help on using the changeset viewer.