OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "pdf/document_loader.h" | 5 #include "pdf/document_loader.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 pp::URLRequestInfo request = GetRequest(pos, size); | 267 pp::URLRequestInfo request = GetRequest(pos, size); |
268 requests_count_++; | 268 requests_count_++; |
269 int rv = loader_.Open(request, callback); | 269 int rv = loader_.Open(request, callback); |
270 if (rv != PP_OK_COMPLETIONPENDING) | 270 if (rv != PP_OK_COMPLETIONPENDING) |
271 callback.Run(rv); | 271 callback.Run(rv); |
272 } | 272 } |
273 | 273 |
274 pp::URLRequestInfo DocumentLoader::GetRequest(uint32 position, | 274 pp::URLRequestInfo DocumentLoader::GetRequest(uint32 position, |
275 uint32 size) const { | 275 uint32 size) const { |
276 pp::URLRequestInfo request(client_->GetPluginInstance()); | 276 pp::URLRequestInfo request(client_->GetPluginInstance()); |
277 request.SetURL(url_.c_str()); | 277 request.SetURL(url_); |
278 request.SetMethod("GET"); | 278 request.SetMethod("GET"); |
279 request.SetFollowRedirects(true); | 279 request.SetFollowRedirects(true); |
| 280 request.SetCustomReferrerURL(url_); |
280 | 281 |
281 const size_t kBufSize = 100; | 282 const size_t kBufSize = 100; |
282 char buf[kBufSize]; | 283 char buf[kBufSize]; |
283 // According to rfc2616, byte range specifies position of the first and last | 284 // According to rfc2616, byte range specifies position of the first and last |
284 // bytes in the requested range inclusively. Therefore we should subtract 1 | 285 // bytes in the requested range inclusively. Therefore we should subtract 1 |
285 // from the position + size, to get index of the last byte that needs to be | 286 // from the position + size, to get index of the last byte that needs to be |
286 // downloaded. | 287 // downloaded. |
287 base::snprintf(buf, kBufSize, "Range: bytes=%d-%d", position, | 288 base::snprintf(buf, kBufSize, "Range: bytes=%d-%d", position, |
288 position + size - 1); | 289 position + size - 1); |
289 pp::Var header(buf); | 290 pp::Var header(buf); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 uint32 DocumentLoader::GetRequestSize() const { | 505 uint32 DocumentLoader::GetRequestSize() const { |
505 // Document loading strategy: | 506 // Document loading strategy: |
506 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we | 507 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we |
507 // double the size (64k), and so on, until we cap max request size at 2M for | 508 // double the size (64k), and so on, until we cap max request size at 2M for |
508 // 71 or more requests. | 509 // 71 or more requests. |
509 uint32 limited_count = std::min(std::max(requests_count_, 10u), 70u); | 510 uint32 limited_count = std::min(std::max(requests_count_, 10u), 70u); |
510 return 32*1024 * (1 << ((limited_count - 1) / 10u)); | 511 return 32*1024 * (1 << ((limited_count - 1) / 10u)); |
511 } | 512 } |
512 | 513 |
513 } // namespace chrome_pdf | 514 } // namespace chrome_pdf |
OLD | NEW |