Changeset 207871 in webkit


Ignore:
Timestamp:
Oct 26, 2016 1:08:11 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Make CachedResourceLoader originsMatch check more efficient
https://bugs.webkit.org/show_bug.cgi?id=163938

Patch by Youenn Fablet <youenn@apple.com> on 2016-10-26
Reviewed by Darin Adler.

No change of behavior.

  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::shouldUpdateCachedResourceWithCurrentRequest):
(WebCore::originsMatch): Moved to SecurityOrigin.cpp.

  • page/SecurityOrigin.cpp:

(WebCore::areOriginsMatching): Helper routine to check whether origins are matching.
(WebCore::originsMatch): Ensuring string comparison provides the same result as this function.

  • page/SecurityOrigin.h:

(WebCore::SecurityOrigin::protocol):
(WebCore::SecurityOrigin::host):
(WebCore::SecurityOrigin::domain):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207869 r207871  
     12016-10-26  Youenn Fablet  <youenn@apple.com>
     2
     3        Make CachedResourceLoader originsMatch check more efficient
     4        https://bugs.webkit.org/show_bug.cgi?id=163938
     5
     6        Reviewed by Darin Adler.
     7
     8        No change of behavior.
     9
     10        * loader/cache/CachedResourceLoader.cpp:
     11        (WebCore::CachedResourceLoader::shouldUpdateCachedResourceWithCurrentRequest):
     12        (WebCore::originsMatch): Moved to SecurityOrigin.cpp.
     13        * page/SecurityOrigin.cpp:
     14        (WebCore::areOriginsMatching): Helper routine to check whether origins are matching.
     15        (WebCore::originsMatch): Ensuring string comparison provides the same result as this function.
     16        * page/SecurityOrigin.h:
     17        (WebCore::SecurityOrigin::protocol):
     18        (WebCore::SecurityOrigin::host):
     19        (WebCore::SecurityOrigin::domain):
     20
    1212016-10-25  Yusuke Suzuki  <utatane.tea@gmail.com>
    222
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r207817 r207871  
    552552}
    553553
    554 static inline bool originsMatch(const CachedResourceRequest& request, const CachedResource& resource)
    555 {
    556     if (request.origin() == resource.origin())
    557         return true;
    558     if (!request.origin() || !resource.origin())
    559         return false;
    560     // We use string comparison as this is how they are serialized as HTTP Origin header value.
    561     // This is in particular useful for unique origins that are serialized as "null"
    562     return request.origin()->toString() == resource.origin()->toString();
    563 }
    564 
    565554bool CachedResourceLoader::shouldUpdateCachedResourceWithCurrentRequest(const CachedResource& resource, const CachedResourceRequest& request)
    566555{
     
    596585    }
    597586
    598     if (resource.options().mode != request.options().mode || !originsMatch(request, resource))
     587    if (resource.options().mode != request.options().mode || !originsMatch(request.origin(), resource.origin()))
    599588        return true;
    600589
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r207769 r207871  
    463463}
    464464
     465static inline bool areOriginsMatching(const SecurityOrigin& origin1, const SecurityOrigin& origin2)
     466{
     467    if (origin1.isUnique() || origin2.isUnique())
     468        return origin1.isUnique() == origin2.isUnique();
     469
     470    if (origin1.protocol() != origin2.protocol())
     471        return false;
     472
     473    if (origin1.protocol() == "file")
     474        return true;
     475
     476    if (origin1.host() != origin2.host())
     477        return false;
     478
     479    return origin1.port() == origin2.port();
     480}
     481
     482// This function mimics the result of string comparison of serialized origins
     483bool originsMatch(const SecurityOrigin& origin1, const SecurityOrigin& origin2)
     484{
     485    if (&origin1 == &origin2)
     486        return true;
     487
     488    bool result = areOriginsMatching(origin1, origin2);
     489    ASSERT(result == (origin1.toString() == origin2.toString()));
     490    return result;
     491}
     492
     493bool originsMatch(const SecurityOrigin* origin1, const SecurityOrigin* origin2)
     494{
     495    if (!origin1 || !origin2)
     496        return origin1 == origin2;
     497
     498    return originsMatch(*origin1, *origin2);
     499}
     500
    465501Ref<SecurityOrigin> SecurityOrigin::createFromString(const String& originString)
    466502{
     
    471507
    472508RefPtr<SecurityOrigin> SecurityOrigin::maybeCreateFromDatabaseIdentifier(const String& databaseIdentifier)
    473 { 
     509{
    474510    // Make sure there's a first separator
    475511    size_t separator1 = databaseIdentifier.find(separatorCharacter);
    476512    if (separator1 == notFound)
    477513        return nullptr;
    478        
     514
    479515    // Make sure there's a second separator
    480516    size_t separator2 = databaseIdentifier.reverseFind(separatorCharacter);
  • trunk/Source/WebCore/page/SecurityOrigin.h

    r207769 r207871  
    8585    bool domainWasSetInDOM() const { return m_domainWasSetInDOM; }
    8686
    87     String protocol() const { return m_protocol; }
    88     String host() const { return m_host; }
    89     String domain() const { return m_domain; }
     87    const String& protocol() const { return m_protocol; }
     88    const String& host() const { return m_host; }
     89    const String& domain() const { return m_domain; }
    9090    Optional<uint16_t> port() const { return m_port; }
    9191
     
    236236};
    237237
     238// Returns true if the Origin header values serialized from these two origins would be the same.
     239bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
     240bool originsMatch(const SecurityOrigin*, const SecurityOrigin*);
     241
    238242} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.