| 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);
|
|
|