Index: pdf/pdfium/pdfium_engine.cc |
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc |
index fc36c1ef152e46a89786ce8adfb37692f4dba11f..e6f570230a3ea4e842644ee889c6c65869e5e1b7 100644 |
--- a/pdf/pdfium/pdfium_engine.cc |
+++ b/pdf/pdfium/pdfium_engine.cc |
@@ -524,15 +524,12 @@ void FormatStringForOS(base::string16* text) { |
pp::VarDictionary TraverseBookmarks(FPDF_DOCUMENT doc, FPDF_BOOKMARK bookmark) { |
pp::VarDictionary dict; |
base::string16 title; |
- unsigned long buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0); |
- size_t title_length = base::checked_cast<size_t>(buffer_size) / |
- sizeof(base::string16::value_type); |
- if (title_length > 0) { |
- PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter( |
- &title, title_length, true); |
- void* data = api_string_adapter.GetData(); |
- FPDFBookmark_GetTitle(bookmark, data, buffer_size); |
- api_string_adapter.Close(title_length); |
+ size_t buffer_size = FPDFBookmark_GetTitle(bookmark, NULL, 0); |
raymes
2015/08/26 06:33:15
Should we keep this as an unsigned long since this
Sam McNally
2015/08/26 08:23:10
Done.
|
+ if (buffer_size > 0) { |
+ PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> api_string_adapter( |
+ &title, buffer_size, true); |
+ api_string_adapter.Close(FPDFBookmark_GetTitle( |
+ bookmark, api_string_adapter.GetData(), buffer_size)); |
} |
dict.Set(pp::Var("title"), pp::Var(base::UTF16ToUTF8(title))); |
@@ -1176,6 +1173,19 @@ bool PDFiumEngine::IsProgressiveLoad() { |
return doc_loader_.is_partial_document(); |
} |
+std::string PDFiumEngine::GetMetadata(const std::string& key) { |
+ size_t size = FPDF_GetMetaText(doc(), key.c_str(), nullptr, 0); |
+ if (size == 0) |
+ return std::string(); |
+ |
+ base::string16 value; |
+ PDFiumAPIStringBufferSizeInBytesAdapter<base::string16> string_adapter( |
+ &value, size, false); |
+ string_adapter.Close( |
+ FPDF_GetMetaText(doc(), key.c_str(), string_adapter.GetData(), size)); |
+ return base::UTF16ToUTF8(value); |
+} |
+ |
void PDFiumEngine::OnPartialDocumentLoaded() { |
file_access_.m_FileLen = doc_loader_.document_size(); |
fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_); |
@@ -3931,15 +3941,11 @@ bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, |
// bitmap. Note that this code does not kick in for PDFs printed from Chrome |
// because in that case we create a temp PDF first before printing and this |
// temp PDF does not have a creator string that starts with "cairo". |
- base::string16 creator; |
- size_t buffer_bytes = FPDF_GetMetaText(doc, "Creator", NULL, 0); |
- if (buffer_bytes > 1) { |
- FPDF_GetMetaText(doc, "Creator", |
- base::WriteInto(&creator, buffer_bytes + 1), buffer_bytes); |
- } |
bool use_bitmap = false; |
- if (base::StartsWith(creator, L"cairo", base::CompareCase::INSENSITIVE_ASCII)) |
+ if (base::StartsWith(GetMetadata("Creator"), "cairo", |
+ base::CompareCase::INSENSITIVE_ASCII)) { |
use_bitmap = true; |
+ } |
// Another temporary hack. Some PDFs seems to render very slowly if |
// FPDF_RenderPage is directly used on a printer DC. I suspect it is |