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

Side by Side Diff: pdf/document_loader.cc

Issue 2407683002: PDF: Check the loaded URL in sendScriptingMessage_(). (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 int rv = loader_.Open(request, callback); 328 int rv = loader_.Open(request, callback);
329 if (rv != PP_OK_COMPLETIONPENDING) 329 if (rv != PP_OK_COMPLETIONPENDING)
330 callback.Run(rv); 330 callback.Run(rv);
331 } 331 }
332 332
333 pp::URLRequestInfo DocumentLoader::GetRequest(uint32_t position, 333 pp::URLRequestInfo DocumentLoader::GetRequest(uint32_t position,
334 uint32_t size) const { 334 uint32_t size) const {
335 pp::URLRequestInfo request(client_->GetPluginInstance()); 335 pp::URLRequestInfo request(client_->GetPluginInstance());
336 request.SetURL(url_); 336 request.SetURL(url_);
337 request.SetMethod("GET"); 337 request.SetMethod("GET");
338 request.SetFollowRedirects(true); 338 request.SetFollowRedirects(true);
raymes 2016/10/11 04:26:22 thestig: Can we just set this to false? I think th
Lei Zhang 2016/10/11 04:45:59 Well, I imagine before we had MimeHandler, we need
raymes 2016/10/11 05:24:28 You mean where the first request doesn't redirect
Lei Zhang 2016/10/11 19:07:31 Yes, I agree it is probably a bit crazy, but I'd l
339 request.SetCustomReferrerURL(url_); 339 request.SetCustomReferrerURL(url_);
340 340
341 const size_t kBufSize = 100; 341 const size_t kBufSize = 100;
342 char buf[kBufSize]; 342 char buf[kBufSize];
343 // According to rfc2616, byte range specifies position of the first and last 343 // According to rfc2616, byte range specifies position of the first and last
344 // bytes in the requested range inclusively. Therefore we should subtract 1 344 // bytes in the requested range inclusively. Therefore we should subtract 1
345 // from the position + size, to get index of the last byte that needs to be 345 // from the position + size, to get index of the last byte that needs to be
346 // downloaded. 346 // downloaded.
347 base::snprintf(buf, kBufSize, "Range: bytes=%d-%d", position, 347 base::snprintf(buf, kBufSize, "Range: bytes=%d-%d", position,
348 position + size - 1); 348 position + size - 1);
349 pp::Var header(buf); 349 pp::Var header(buf);
350 request.SetHeaders(header); 350 request.SetHeaders(header);
351 351
352 return request; 352 return request;
353 } 353 }
354 354
355 void DocumentLoader::DidOpen(int32_t result) { 355 void DocumentLoader::DidOpen(int32_t result) {
356 if (result != PP_OK) { 356 if (result != PP_OK) {
357 NOTREACHED(); 357 NOTREACHED();
358 return; 358 return;
359 } 359 }
360 360
361 int32_t http_code = loader_.GetResponseInfo().GetStatusCode(); 361 pp::URLResponseInfo response = loader_.GetResponseInfo();
362 int32_t http_code = response.GetStatusCode();
362 if (http_code >= 400 && http_code < 500) { 363 if (http_code >= 400 && http_code < 500) {
363 // Error accessing resource. 4xx error indicate subsequent requests 364 // Error accessing resource. 4xx error indicate subsequent requests
364 // will fail too. 365 // will fail too.
365 // E.g. resource has been removed from the server while loading it. 366 // E.g. resource has been removed from the server while loading it.
366 // https://code.google.com/p/chromium/issues/detail?id=414827 367 // https://code.google.com/p/chromium/issues/detail?id=414827
367 return; 368 return;
368 } 369 }
369 370
371 pp::Var response_url = response.GetURL();
372 std::string response_url_str;
373 if (response_url.is_string())
374 response_url_str = response_url.AsString();
375 if (response_url_str.empty())
376 return;
377
378 if (actual_url_.empty()) {
379 actual_url_ = response_url_str;
robwu 2016/10/09 10:49:50 Testing for URL equality may be too strict. Checki
Lei Zhang 2016/10/11 00:11:09 Ack. We can certainly do that if desired.
380 client_->OnGotActualURL(actual_url_);
381 } else {
382 if (actual_url_ != response_url_str)
Lei Zhang 2016/10/11 00:09:02 I was wondering about this as well. Would a web se
Tom Sepez 2016/10/11 16:10:47 Seems unlikely, but we'll find out. Want to add a
nasko 2016/10/12 00:47:47 Why not DumpWithoutCrashing? If it is never hit, i
383 return;
384 }
385
370 is_multipart_ = false; 386 is_multipart_ = false;
371 current_chunk_size_ = 0; 387 current_chunk_size_ = 0;
372 current_chunk_read_ = 0; 388 current_chunk_read_ = 0;
373 389
374 pp::Var headers_var = loader_.GetResponseInfo().GetHeaders(); 390 pp::Var headers_var = loader_.GetResponseInfo().GetHeaders();
375 std::string headers; 391 std::string headers;
376 if (headers_var.is_string()) 392 if (headers_var.is_string())
377 headers = headers_var.AsString(); 393 headers = headers_var.AsString();
378 394
379 std::string boundary = GetMultiPartBoundary(headers); 395 std::string boundary = GetMultiPartBoundary(headers);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 553
538 void DocumentLoader::UpdateRendering() { 554 void DocumentLoader::UpdateRendering() {
539 if (header_request_) 555 if (header_request_)
540 client_->OnPartialDocumentLoaded(); 556 client_->OnPartialDocumentLoaded();
541 else 557 else
542 client_->OnPendingRequestComplete(); 558 client_->OnPendingRequestComplete();
543 header_request_ = false; 559 header_request_ = false;
544 } 560 }
545 561
546 } // namespace chrome_pdf 562 } // namespace chrome_pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698