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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2103043003: Remove legacy PDF JSON interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo after merge Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 13
14 #include "base/i18n/icu_encoding_detection.h" 14 #include "base/i18n/icu_encoding_detection.h"
15 #include "base/i18n/icu_string_conversions.h" 15 #include "base/i18n/icu_string_conversions.h"
16 #include "base/json/json_writer.h"
17 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
18 #include "base/logging.h" 17 #include "base/logging.h"
19 #include "base/macros.h" 18 #include "base/macros.h"
20 #include "base/numerics/safe_conversions.h" 19 #include "base/numerics/safe_conversions.h"
21 #include "base/stl_util.h" 20 #include "base/stl_util.h"
22 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_piece.h" 22 #include "base/strings/string_piece.h"
24 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
26 #include "base/values.h"
27 #include "gin/array_buffer.h" 25 #include "gin/array_buffer.h"
28 #include "gin/public/gin_embedders.h" 26 #include "gin/public/gin_embedders.h"
29 #include "gin/public/isolate_holder.h" 27 #include "gin/public/isolate_holder.h"
30 #include "pdf/draw_utils.h" 28 #include "pdf/draw_utils.h"
31 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" 29 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
32 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h" 30 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
33 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h" 31 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
34 #include "ppapi/c/pp_errors.h" 32 #include "ppapi/c/pp_errors.h"
35 #include "ppapi/c/pp_input_event.h" 33 #include "ppapi/c/pp_input_event.h"
36 #include "ppapi/c/ppb_core.h" 34 #include "ppapi/c/ppb_core.h"
(...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 2285
2288 void PDFiumEngine::OnCallback(int id) { 2286 void PDFiumEngine::OnCallback(int id) {
2289 if (!timers_.count(id)) 2287 if (!timers_.count(id))
2290 return; 2288 return;
2291 2289
2292 timers_[id].second(id); 2290 timers_[id].second(id);
2293 if (timers_.count(id)) // The callback might delete the timer. 2291 if (timers_.count(id)) // The callback might delete the timer.
2294 client_->ScheduleCallback(id, timers_[id].first); 2292 client_->ScheduleCallback(id, timers_[id].first);
2295 } 2293 }
2296 2294
2297 std::string PDFiumEngine::GetPageAsJSON(int index) {
2298 if (!(HasPermission(PERMISSION_COPY) ||
2299 HasPermission(PERMISSION_COPY_ACCESSIBLE))) {
2300 return "{}";
2301 }
2302
2303 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1)
2304 return "{}";
2305
2306 std::unique_ptr<base::Value> node(
2307 pages_[index]->GetAccessibleContentAsValue(current_rotation_));
2308 std::string page_json;
2309 base::JSONWriter::Write(*node, &page_json);
2310 return page_json;
2311 }
2312
2313 int PDFiumEngine::GetCharCount(int page_index) { 2295 int PDFiumEngine::GetCharCount(int page_index) {
2314 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size())); 2296 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size()));
2315 return pages_[page_index]->GetCharCount(); 2297 return pages_[page_index]->GetCharCount();
2316 } 2298 }
2317 2299
2318 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) { 2300 pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) {
2319 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size())); 2301 DCHECK(page_index >= 0 && page_index < static_cast<int>(pages_.size()));
2320 return pages_[page_index]->GetCharBounds(char_index); 2302 return pages_[page_index]->GetCharBounds(char_index);
2321 } 2303 }
2322 2304
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
3912 FPDF_DOCUMENT doc = 3894 FPDF_DOCUMENT doc =
3913 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3895 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3914 if (!doc) 3896 if (!doc)
3915 return false; 3897 return false;
3916 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3898 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3917 FPDF_CloseDocument(doc); 3899 FPDF_CloseDocument(doc);
3918 return success; 3900 return success;
3919 } 3901 }
3920 3902
3921 } // namespace chrome_pdf 3903 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698