Title: [207871] trunk/Source/WebCore
- Revision
- 207871
- Author
- [email protected]
- Date
- 2016-10-26 01:08:11 -0700 (Wed, 26 Oct 2016)
Log Message
Make CachedResourceLoader originsMatch check more efficient
https://bugs.webkit.org/show_bug.cgi?id=163938
Patch by Youenn Fablet <[email protected]> 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (207870 => 207871)
--- trunk/Source/WebCore/ChangeLog 2016-10-26 07:45:14 UTC (rev 207870)
+++ trunk/Source/WebCore/ChangeLog 2016-10-26 08:08:11 UTC (rev 207871)
@@ -1,3 +1,23 @@
+2016-10-26 Youenn Fablet <[email protected]>
+
+ Make CachedResourceLoader originsMatch check more efficient
+ https://bugs.webkit.org/show_bug.cgi?id=163938
+
+ 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):
+
2016-10-25 Yusuke Suzuki <[email protected]>
[DOMJIT] Tell IDL result type to DFG to drop type checks in AI
Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (207870 => 207871)
--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2016-10-26 07:45:14 UTC (rev 207870)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2016-10-26 08:08:11 UTC (rev 207871)
@@ -551,17 +551,6 @@
return !newRequest.isNull();
}
-static inline bool originsMatch(const CachedResourceRequest& request, const CachedResource& resource)
-{
- if (request.origin() == resource.origin())
- return true;
- if (!request.origin() || !resource.origin())
- return false;
- // We use string comparison as this is how they are serialized as HTTP Origin header value.
- // This is in particular useful for unique origins that are serialized as "null"
- return request.origin()->toString() == resource.origin()->toString();
-}
-
bool CachedResourceLoader::shouldUpdateCachedResourceWithCurrentRequest(const CachedResource& resource, const CachedResourceRequest& request)
{
// WebKit is not supporting CORS for fonts (https://bugs.webkit.org/show_bug.cgi?id=86817), no need to update the resource before reusing it.
@@ -595,7 +584,7 @@
break;
}
- if (resource.options().mode != request.options().mode || !originsMatch(request, resource))
+ if (resource.options().mode != request.options().mode || !originsMatch(request.origin(), resource.origin()))
return true;
if (resource.options().redirect != request.options().redirect && resource.hasRedirections())
Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (207870 => 207871)
--- trunk/Source/WebCore/page/SecurityOrigin.cpp 2016-10-26 07:45:14 UTC (rev 207870)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp 2016-10-26 08:08:11 UTC (rev 207871)
@@ -462,6 +462,42 @@
return result.toString();
}
+static inline bool areOriginsMatching(const SecurityOrigin& origin1, const SecurityOrigin& origin2)
+{
+ if (origin1.isUnique() || origin2.isUnique())
+ return origin1.isUnique() == origin2.isUnique();
+
+ if (origin1.protocol() != origin2.protocol())
+ return false;
+
+ if (origin1.protocol() == "file")
+ return true;
+
+ if (origin1.host() != origin2.host())
+ return false;
+
+ return origin1.port() == origin2.port();
+}
+
+// This function mimics the result of string comparison of serialized origins
+bool originsMatch(const SecurityOrigin& origin1, const SecurityOrigin& origin2)
+{
+ if (&origin1 == &origin2)
+ return true;
+
+ bool result = areOriginsMatching(origin1, origin2);
+ ASSERT(result == (origin1.toString() == origin2.toString()));
+ return result;
+}
+
+bool originsMatch(const SecurityOrigin* origin1, const SecurityOrigin* origin2)
+{
+ if (!origin1 || !origin2)
+ return origin1 == origin2;
+
+ return originsMatch(*origin1, *origin2);
+}
+
Ref<SecurityOrigin> SecurityOrigin::createFromString(const String& originString)
{
return SecurityOrigin::create(URL(URL(), originString));
@@ -470,12 +506,12 @@
static const char separatorCharacter = '_';
RefPtr<SecurityOrigin> SecurityOrigin::maybeCreateFromDatabaseIdentifier(const String& databaseIdentifier)
-{
+{
// Make sure there's a first separator
size_t separator1 = databaseIdentifier.find(separatorCharacter);
if (separator1 == notFound)
return nullptr;
-
+
// Make sure there's a second separator
size_t separator2 = databaseIdentifier.reverseFind(separatorCharacter);
if (separator2 == notFound)
Modified: trunk/Source/WebCore/page/SecurityOrigin.h (207870 => 207871)
--- trunk/Source/WebCore/page/SecurityOrigin.h 2016-10-26 07:45:14 UTC (rev 207870)
+++ trunk/Source/WebCore/page/SecurityOrigin.h 2016-10-26 08:08:11 UTC (rev 207871)
@@ -84,9 +84,9 @@
void setDomainFromDOM(const String& newDomain);
bool domainWasSetInDOM() const { return m_domainWasSetInDOM; }
- String protocol() const { return m_protocol; }
- String host() const { return m_host; }
- String domain() const { return m_domain; }
+ const String& protocol() const { return m_protocol; }
+ const String& host() const { return m_host; }
+ const String& domain() const { return m_domain; }
Optional<uint16_t> port() const { return m_port; }
// Returns true if a given URL is secure, based either directly on its
@@ -235,4 +235,8 @@
bool m_needsDatabaseIdentifierQuirkForFiles;
};
+// Returns true if the Origin header values serialized from these two origins would be the same.
+bool originsMatch(const SecurityOrigin&, const SecurityOrigin&);
+bool originsMatch(const SecurityOrigin*, const SecurityOrigin*);
+
} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes