Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: third_party/WebKit/Source/core/fetch/FetchRequest.cpp

Issue 2423683002: Add Blink support for showing image placeholders using range requests. (Closed)
Patch Set: Change test data to "const unsigned char" instead of "const char" to fix warnings in windows build Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/fetch/FetchRequest.cpp
diff --git a/third_party/WebKit/Source/core/fetch/FetchRequest.cpp b/third_party/WebKit/Source/core/fetch/FetchRequest.cpp
index 952e4d42a6954ad986d6f628e54ff29326e327b9..eeb6ea61f2d5ab740a88079b670ad7b6adc196c2 100644
--- a/third_party/WebKit/Source/core/fetch/FetchRequest.cpp
+++ b/third_party/WebKit/Source/core/fetch/FetchRequest.cpp
@@ -27,6 +27,7 @@
#include "core/fetch/CrossOriginAccessControl.h"
#include "core/fetch/ResourceFetcher.h"
+#include "platform/weborigin/KURL.h"
namespace blink {
@@ -40,7 +41,8 @@ FetchRequest::FetchRequest(const ResourceRequest& resourceRequest,
m_linkPreload(false),
m_preloadDiscoveryTime(0.0),
m_defer(NoDefer),
- m_originRestriction(UseDefaultOriginRestrictionForType) {
+ m_originRestriction(UseDefaultOriginRestrictionForType),
+ m_placeholderImageRequestType(DisallowPlaceholder) {
m_options.initiatorInfo.name = initiator;
}
@@ -53,7 +55,9 @@ FetchRequest::FetchRequest(const ResourceRequest& resourceRequest,
m_linkPreload(false),
m_preloadDiscoveryTime(0.0),
m_defer(NoDefer),
- m_originRestriction(UseDefaultOriginRestrictionForType) {
+ m_originRestriction(UseDefaultOriginRestrictionForType),
+ m_placeholderImageRequestType(
+ PlaceholderImageRequestType::DisallowPlaceholder) {
m_options.initiatorInfo.name = initiator;
}
@@ -65,7 +69,9 @@ FetchRequest::FetchRequest(const ResourceRequest& resourceRequest,
m_linkPreload(false),
m_preloadDiscoveryTime(0.0),
m_defer(NoDefer),
- m_originRestriction(UseDefaultOriginRestrictionForType) {
+ m_originRestriction(UseDefaultOriginRestrictionForType),
+ m_placeholderImageRequestType(
+ PlaceholderImageRequestType::DisallowPlaceholder) {
m_options.initiatorInfo = initiator;
}
@@ -119,4 +125,25 @@ void FetchRequest::makeSynchronous() {
m_options.synchronousPolicy = RequestSynchronously;
}
+void FetchRequest::setAllowImagePlaceholder() {
+ DCHECK_EQ(DisallowPlaceholder, m_placeholderImageRequestType);
+ if (!m_resourceRequest.url().protocolIsInHTTPFamily() ||
+ m_resourceRequest.httpMethod() != "GET" ||
+ !m_resourceRequest.httpHeaderField("range").isNull()) {
+ return;
+ }
+
+ m_placeholderImageRequestType = AllowPlaceholder;
+
+ // Fetch the first few bytes of the image. This number is tuned to both (a)
+ // likely capture the entire image for small images and (b) likely contain
+ // the dimensions for larger images.
+ // TODO(sclittle): Calculate the optimal value for this number.
+ m_resourceRequest.setHTTPHeaderField("range", "bytes=0-2047");
+
+ // TODO(sclittle): Indicate somehow (e.g. through a new request bit) to the
+ // embedder that it should return the full resource if the entire resource is
+ // fresh in the cache.
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/fetch/FetchRequest.h ('k') | third_party/WebKit/Source/core/fetch/ImageResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698