| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 3053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3064 int length) { | 3064 int length) { |
| 3065 std::string question_str = base::UTF16ToUTF8( | 3065 std::string question_str = base::UTF16ToUTF8( |
| 3066 reinterpret_cast<const base::char16*>(question)); | 3066 reinterpret_cast<const base::char16*>(question)); |
| 3067 std::string default_str = base::UTF16ToUTF8( | 3067 std::string default_str = base::UTF16ToUTF8( |
| 3068 reinterpret_cast<const base::char16*>(default_response)); | 3068 reinterpret_cast<const base::char16*>(default_response)); |
| 3069 | 3069 |
| 3070 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3070 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3071 std::string rv = engine->client_->Prompt(question_str, default_str); | 3071 std::string rv = engine->client_->Prompt(question_str, default_str); |
| 3072 base::string16 rv_16 = base::UTF8ToUTF16(rv); | 3072 base::string16 rv_16 = base::UTF8ToUTF16(rv); |
| 3073 int rv_bytes = rv_16.size() * sizeof(base::char16); | 3073 int rv_bytes = rv_16.size() * sizeof(base::char16); |
| 3074 if (response && rv_bytes <= length) | 3074 if (response) { |
| 3075 memcpy(response, rv_16.c_str(), rv_bytes); | 3075 int bytes_to_copy = rv_bytes < length ? rv_bytes : length; |
| 3076 memcpy(response, rv_16.c_str(), bytes_to_copy); |
| 3077 } |
| 3076 return rv_bytes; | 3078 return rv_bytes; |
| 3077 } | 3079 } |
| 3078 | 3080 |
| 3079 int PDFiumEngine::Form_GetFilePath(IPDF_JSPLATFORM* param, | 3081 int PDFiumEngine::Form_GetFilePath(IPDF_JSPLATFORM* param, |
| 3080 void* file_path, | 3082 void* file_path, |
| 3081 int length) { | 3083 int length) { |
| 3082 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3084 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3083 std::string rv = engine->client_->GetURL(); | 3085 std::string rv = engine->client_->GetURL(); |
| 3084 if (file_path && rv.size() <= static_cast<size_t>(length)) | 3086 if (file_path && rv.size() <= static_cast<size_t>(length)) |
| 3085 memcpy(file_path, rv.c_str(), rv.size()); | 3087 memcpy(file_path, rv.c_str(), rv.size()); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3395 double* height) { | 3397 double* height) { |
| 3396 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3398 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3397 if (!doc) | 3399 if (!doc) |
| 3398 return false; | 3400 return false; |
| 3399 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3401 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3400 FPDF_CloseDocument(doc); | 3402 FPDF_CloseDocument(doc); |
| 3401 return success; | 3403 return success; |
| 3402 } | 3404 } |
| 3403 | 3405 |
| 3404 } // namespace chrome_pdf | 3406 } // namespace chrome_pdf |
| OLD | NEW |