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

Unified Diff: net/url_request/url_request_simple_job.cc

Issue 104513002: Fixed playing video in component extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_simple_job.cc
diff --git a/net/url_request/url_request_simple_job.cc b/net/url_request/url_request_simple_job.cc
index bd945557e3de2f5edd0b71b4c5fbf9839409a2d6..20d23271d9b5952112f7275ee2b69c9806e615b0 100644
--- a/net/url_request/url_request_simple_job.cc
+++ b/net/url_request/url_request_simple_job.cc
@@ -4,11 +4,15 @@
#include "net/url_request/url_request_simple_job.h"
+#include <vector>
+
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
+#include "net/http/http_request_headers.h"
+#include "net/http/http_util.h"
#include "net/url_request/url_request_status.h"
namespace net {
@@ -42,7 +46,7 @@ URLRequestSimpleJob::~URLRequestSimpleJob() {}
bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size,
int* bytes_read) {
DCHECK(bytes_read);
- int remaining = static_cast<int>(data_.size()) - data_offset_;
+ int remaining = byte_range_.last_byte_position() - data_offset_ + 1;
if (buf_size > remaining)
buf_size = remaining;
memcpy(buf->data(), data_.data() + data_offset_, buf_size);
@@ -51,6 +55,22 @@ bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size,
return true;
}
+void URLRequestSimpleJob::SetExtraRequestHeaders(
+ const HttpRequestHeaders& headers) {
+ std::string range_header;
+ if (headers.GetHeader(HttpRequestHeaders::kRange, &range_header)) {
+ std::vector<HttpByteRange> ranges;
+ if (HttpUtil::ParseRangeHeader(range_header, &ranges)) {
mmenke 2013/12/17 17:10:15 Should we fail if we have a range header we can't
+ if (ranges.size() == 1) {
+ byte_range_ = ranges[0];
+ } else {
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
+ ERR_REQUEST_RANGE_NOT_SATISFIABLE));
mmenke 2013/12/17 17:10:15 Calling NotifyDone before Start() seems like a bad
kirr 2013/12/18 08:03:30 It seems you are right. But all URLRequestJobs wit
mmenke 2013/12/18 15:40:31 Thanks for pointing that out! I think conceptuall
+ }
+ }
+ }
+}
+
void URLRequestSimpleJob::StartAsync() {
if (!request_)
return;
@@ -65,6 +85,16 @@ void URLRequestSimpleJob::StartAsync() {
void URLRequestSimpleJob::OnGetDataCompleted(int result) {
if (result == OK) {
// Notify that the headers are complete
+ if (!byte_range_.ComputeBounds(data_.size())) {
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
+ ERR_REQUEST_RANGE_NOT_SATISFIABLE));
+ return;
+ }
+
+ data_offset_ = byte_range_.first_byte_position();
+ int remaining_bytes = byte_range_.last_byte_position() -
+ byte_range_.first_byte_position() + 1;
+ set_expected_content_size(remaining_bytes);
NotifyHeadersComplete();
} else {
NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698