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

Unified Diff: pdf/document_loader.cc

Issue 2455663004: Add test to ensure that URLs that redirect inside the PDF plugin fail to load (Closed)
Patch Set: . Created 4 years, 1 month 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 | « chrome/test/data/pdf/redirects_fail_test.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/document_loader.cc
diff --git a/pdf/document_loader.cc b/pdf/document_loader.cc
index 67ac8ff789089c5f2c6b9e74c13c0553c2a4286b..661e4ca04fe653efa20f4c2738e1149beaeafd17 100644
--- a/pdf/document_loader.cc
+++ b/pdf/document_loader.cc
@@ -27,6 +27,17 @@ namespace {
// Experimentally chosen value.
const int kChunkCloseDistance = 10;
+// Return true if the HTTP response of |loader| is a successful one and loading
+// should continue. 4xx error indicate subsequent requests will fail too.
+// e.g. resource has been removed from the server while loading it. 301
+// indicates a redirect was returned which won't be successful because we
+// disable following redirects for PDF loading (we assume they are already
+// resolved by the browser.
+bool ResponseStatusSuccess(const URLLoaderWrapper* loader) {
+ int32_t http_code = loader->GetStatusCode();
+ return (http_code < 400 && http_code != 301) || http_code >= 500;
+}
+
bool IsValidContentType(const std::string& type) {
return (base::EndsWith(type, "/pdf", base::CompareCase::INSENSITIVE_ASCII) ||
base::EndsWith(type, ".pdf", base::CompareCase::INSENSITIVE_ASCII) ||
@@ -65,6 +76,10 @@ bool DocumentLoader::Init(std::unique_ptr<URLLoaderWrapper> loader,
DCHECK(url_.empty());
DCHECK(!loader_);
+ // Check that the initial response status is a valid one.
+ if (!ResponseStatusSuccess(loader.get()))
+ return false;
+
std::string type = loader->GetContentType();
// This happens for PDFs not loaded from http(s) sources.
@@ -244,13 +259,8 @@ void DocumentLoader::DidOpenPartial(int32_t result) {
return ReadComplete();
}
- int32_t http_code = loader_->GetStatusCode();
- if (http_code >= 400 && http_code < 500) {
- // Error accessing resource. 4xx error indicate subsequent requests
- // will fail too.
- // E.g. resource has been removed from the server while loading it.
+ if (!ResponseStatusSuccess(loader_.get()))
return ReadComplete();
- }
// Leave position untouched for multiparted responce for now, when we read the
// data we'll get it.
« no previous file with comments | « chrome/test/data/pdf/redirects_fail_test.js ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698