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

Unified Diff: pdf/document_loader.cc

Issue 1155963004: PDF: Cleanup more code now that it is completely out of process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pdf/out_of_process_instance.h » ('j') | pdf/out_of_process_instance.cc » ('J')
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 9918b1250c9487a12dcf1632bea8044356f63078..132dec484b3fae77093f0bf09852abcf49ac8826 100644
--- a/pdf/document_loader.cc
+++ b/pdf/document_loader.cc
@@ -14,9 +14,22 @@
namespace chrome_pdf {
+namespace {
+
// Document below size will be downloaded in one chunk.
const uint32 kMinFileSize = 64*1024;
+bool IsValidContentType(const std::string& type) {
+ return (EndsWith(type, "/pdf", false) ||
+ EndsWith(type, ".pdf", false) ||
+ EndsWith(type, "/x-pdf", false) ||
+ EndsWith(type, "/*", false) ||
+ EndsWith(type, "/acrobat", false) ||
+ EndsWith(type, "/unknown", false));
+}
+
+} // namespace
+
DocumentLoader::DocumentLoader(Client* client)
: client_(client), partial_document_(false), request_pending_(false),
current_pos_(0), current_chunk_size_(0), current_chunk_read_(0),
@@ -51,7 +64,15 @@ bool DocumentLoader::Init(const pp::URLLoader& loader,
uint32 content_length = 0;
std::string type;
std::string disposition;
- if (!response_headers.empty()) {
+
+ // This happens for PDFs not loaded from http(s) sources.
+ if (response_headers == "Content-Type: text/plain") {
+ if (!StartsWithASCII(url, "http://", false) &&
+ !StartsWithASCII(url, "https://", false)) {
+ type = "application/pdf";
+ }
+ }
+ if (type.empty() && !response_headers.empty()) {
net::HttpUtil::HeadersIterator it(response_headers.begin(),
response_headers.end(), "\n");
while (it.GetNext()) {
@@ -73,18 +94,10 @@ bool DocumentLoader::Init(const pp::URLLoader& loader,
}
}
}
- if (!type.empty() &&
- !EndsWith(type, "/pdf", false) &&
- !EndsWith(type, ".pdf", false) &&
- !EndsWith(type, "/x-pdf", false) &&
- !EndsWith(type, "/*", false) &&
- !EndsWith(type, "/acrobat", false) &&
- !EndsWith(type, "/unknown", false)) {
+ if (!type.empty() && !IsValidContentType(type))
return false;
- }
- if (StartsWithASCII(disposition, "attachment", false)) {
+ if (StartsWithASCII(disposition, "attachment", false))
return false;
- }
if (content_length > 0)
chunk_stream_.Preallocate(content_length);
« no previous file with comments | « no previous file | pdf/out_of_process_instance.h » ('j') | pdf/out_of_process_instance.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698