summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_url_request_job.cc
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-21 03:59:04 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-21 03:59:04 +0000
commit80f584d94f57afdfddeba1fa7384ed409cd91273 (patch)
treed6e51ebde489e245e98e56ca061c0dce78895d63 /webkit/appcache/appcache_url_request_job.cc
parent204e936d3b0455b0c55f2dc5713f8a84b55e0cbf (diff)
downloadchromium_src-80f584d94f57afdfddeba1fa7384ed409cd91273.zip
chromium_src-80f584d94f57afdfddeba1fa7384ed409cd91273.tar.gz
chromium_src-80f584d94f57afdfddeba1fa7384ed409cd91273.tar.bz2
Support for playing back media from the appcache.
* add the appcache_host_id to resource requests * support for byte-range requests TEST=manual BUG=none Review URL: http://codereview.chromium.org/550040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36727 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_url_request_job.cc')
-rw-r--r--webkit/appcache/appcache_url_request_job.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/webkit/appcache/appcache_url_request_job.cc b/webkit/appcache/appcache_url_request_job.cc
index 4a6e4ae..a616394 100644
--- a/webkit/appcache/appcache_url_request_job.cc
+++ b/webkit/appcache/appcache_url_request_job.cc
@@ -2,9 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <vector>
+
#include "webkit/appcache/appcache_url_request_job.h"
#include "base/message_loop.h"
+#include "base/string_util.h"
+#include "net/http/http_util.h"
#include "net/url_request/url_request_status.h"
namespace appcache {
@@ -97,6 +101,10 @@ void AppCacheURLRequestJob::OnResponseInfoLoaded(
info_ = response_info;
reader_.reset(
storage_->CreateResponseReader(manifest_url_, entry_.response_id()));
+
+ if (is_range_request())
+ SetupRangeResponse();
+
NotifyHeadersComplete();
} else {
NotifyStartError(
@@ -105,6 +113,53 @@ void AppCacheURLRequestJob::OnResponseInfoLoaded(
storage_ = NULL; // no longer needed
}
+const net::HttpResponseInfo* AppCacheURLRequestJob::http_info() const {
+ if (!info_.get())
+ return NULL;
+ if (range_response_info_.get())
+ return range_response_info_.get();
+ return info_->http_response_info();
+}
+
+void AppCacheURLRequestJob::SetupRangeResponse() {
+ DCHECK(is_range_request() && reader_.get() &&
+ is_delivering_appcache_response());
+ int resource_size = reader_->GetResourceSize();
+ if (resource_size < 0 || !range_requested_.ComputeBounds(resource_size)) {
+ range_requested_ = net::HttpByteRange();
+ return;
+ }
+
+ DCHECK(range_requested_.HasFirstBytePosition() &&
+ range_requested_.HasLastBytePosition());
+ int offset = static_cast<int>(range_requested_.first_byte_position());
+ int length = static_cast<int>(range_requested_.last_byte_position() -
+ range_requested_.first_byte_position() + 1);
+
+ // Tell the reader about the range to read.
+ reader_->SetReadRange(offset, length);
+
+ // Make a copy of the full response headers and fix them up
+ // for the range we'll be returning.
+ const char kLengthHeader[] = "Content-Length";
+ const char kRangeHeader[] = "Content-Range";
+ const char kPartialStatusLine[] = "HTTP/1.1 206 Partial Content";
+ range_response_info_.reset(
+ new net::HttpResponseInfo(*info_->http_response_info()));
+ net::HttpResponseHeaders* headers = range_response_info_->headers;
+ headers->RemoveHeader(kLengthHeader);
+ headers->RemoveHeader(kRangeHeader);
+ headers->ReplaceStatusLine(kPartialStatusLine);
+ headers->AddHeader(
+ StringPrintf("%s: %d", kLengthHeader, length));
+ headers->AddHeader(
+ StringPrintf("%s: bytes %d-%d/%d",
+ kRangeHeader,
+ offset,
+ offset + length - 1,
+ resource_size));
+}
+
void AppCacheURLRequestJob::OnReadComplete(int result) {
DCHECK(is_delivering_appcache_response());
if (result == 0)
@@ -186,5 +241,15 @@ bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size,
return false;
}
+void AppCacheURLRequestJob::SetExtraRequestHeaders(
+ const std::string& headers) {
+ // If multiple ranges are requested, we play dumb and
+ // return the entire response with 200 OK.
+ std::vector<net::HttpByteRange> ranges;
+ if (!net::HttpUtil::ParseRanges(headers, &ranges) || (ranges.size() > 1U))
+ return;
+ range_requested_ = ranges[0];
+}
+
} // namespace appcache