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/i18n/icu_encoding_detection.h" | 9 #include "base/i18n/icu_encoding_detection.h" |
10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 doc_(NULL), | 585 doc_(NULL), |
586 form_(NULL), | 586 form_(NULL), |
587 defer_page_unload_(false), | 587 defer_page_unload_(false), |
588 selecting_(false), | 588 selecting_(false), |
589 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 589 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
590 PDFiumPage::LinkTarget()), | 590 PDFiumPage::LinkTarget()), |
591 next_page_to_search_(-1), | 591 next_page_to_search_(-1), |
592 last_page_to_search_(-1), | 592 last_page_to_search_(-1), |
593 last_character_index_to_search_(-1), | 593 last_character_index_to_search_(-1), |
594 permissions_(0), | 594 permissions_(0), |
| 595 permissions_handler_revision_(-1), |
595 fpdf_availability_(NULL), | 596 fpdf_availability_(NULL), |
596 next_timer_id_(0), | 597 next_timer_id_(0), |
597 last_page_mouse_down_(-1), | 598 last_page_mouse_down_(-1), |
598 first_visible_page_(-1), | 599 first_visible_page_(-1), |
599 most_visible_page_(-1), | 600 most_visible_page_(-1), |
600 called_do_document_action_(false), | 601 called_do_document_action_(false), |
601 render_grayscale_(false), | 602 render_grayscale_(false), |
602 progressive_paint_timeout_(0), | 603 progressive_paint_timeout_(0), |
603 getting_password_(false) { | 604 getting_password_(false) { |
604 find_factory_.Initialize(this); | 605 find_factory_.Initialize(this); |
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2317 if (area == PDFiumPage::WEBLINK_AREA) | 2318 if (area == PDFiumPage::WEBLINK_AREA) |
2318 url = target.url; | 2319 url = target.url; |
2319 return url; | 2320 return url; |
2320 } | 2321 } |
2321 | 2322 |
2322 bool PDFiumEngine::IsSelecting() { | 2323 bool PDFiumEngine::IsSelecting() { |
2323 return selecting_; | 2324 return selecting_; |
2324 } | 2325 } |
2325 | 2326 |
2326 bool PDFiumEngine::HasPermission(DocumentPermission permission) const { | 2327 bool PDFiumEngine::HasPermission(DocumentPermission permission) const { |
| 2328 // PDF 1.7 spec, section 3.5.2 says: "If the revision number is 2 or greater, |
| 2329 // the operations to which user access can be controlled are as follows: ..." |
| 2330 // |
| 2331 // Thus for revision numbers less than 2, permissions are ignored and this |
| 2332 // always returns true. |
| 2333 if (permissions_handler_revision_ < 2) |
| 2334 return true; |
| 2335 |
| 2336 // Handle high quality printing permission separately for security handler |
| 2337 // revision 3+. See table 3.20 in the PDF 1.7 spec. |
| 2338 if (permission == PERMISSION_PRINT_HIGH_QUALITY && |
| 2339 permissions_handler_revision_ >= 3) { |
| 2340 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 && |
| 2341 (permissions_ & kPDFPermissionPrintHighQualityMask) != 0; |
| 2342 } |
| 2343 |
2327 switch (permission) { | 2344 switch (permission) { |
2328 case PERMISSION_COPY: | 2345 case PERMISSION_COPY: |
2329 return (permissions_ & kPDFPermissionCopyMask) != 0; | 2346 return (permissions_ & kPDFPermissionCopyMask) != 0; |
2330 case PERMISSION_COPY_ACCESSIBLE: | 2347 case PERMISSION_COPY_ACCESSIBLE: |
2331 return (permissions_ & kPDFPermissionCopyAccessibleMask) != 0; | 2348 return (permissions_ & kPDFPermissionCopyAccessibleMask) != 0; |
2332 case PERMISSION_PRINT_LOW_QUALITY: | 2349 case PERMISSION_PRINT_LOW_QUALITY: |
| 2350 case PERMISSION_PRINT_HIGH_QUALITY: |
| 2351 // With security handler revision 2 rules, check the same bit for high |
| 2352 // and low quality. See table 3.20 in the PDF 1.7 spec. |
2333 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; | 2353 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; |
2334 case PERMISSION_PRINT_HIGH_QUALITY: | |
2335 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 && | |
2336 (permissions_ & kPDFPermissionPrintHighQualityMask) != 0; | |
2337 default: | 2354 default: |
2338 return true; | 2355 return true; |
2339 } | 2356 } |
2340 } | 2357 } |
2341 | 2358 |
2342 void PDFiumEngine::SelectAll() { | 2359 void PDFiumEngine::SelectAll() { |
2343 SelectionChangeInvalidator selection_invalidator(this); | 2360 SelectionChangeInvalidator selection_invalidator(this); |
2344 | 2361 |
2345 selection_.clear(); | 2362 selection_.clear(); |
2346 for (size_t i = 0; i < pages_.size(); ++i) | 2363 for (size_t i = 0; i < pages_.size(); ++i) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2615 | 2632 |
2616 if (!doc_) { | 2633 if (!doc_) { |
2617 client_->DocumentLoadFailed(); | 2634 client_->DocumentLoadFailed(); |
2618 return; | 2635 return; |
2619 } | 2636 } |
2620 | 2637 |
2621 if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES) | 2638 if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES) |
2622 client_->DocumentHasUnsupportedFeature("Bookmarks"); | 2639 client_->DocumentHasUnsupportedFeature("Bookmarks"); |
2623 | 2640 |
2624 permissions_ = FPDF_GetDocPermissions(doc_); | 2641 permissions_ = FPDF_GetDocPermissions(doc_); |
| 2642 permissions_handler_revision_ = FPDF_GetSecurityHandlerRevision(doc_); |
2625 | 2643 |
2626 if (!form_) { | 2644 if (!form_) { |
2627 // Only returns 0 when data isn't available. If form data is downloaded, or | 2645 // Only returns 0 when data isn't available. If form data is downloaded, or |
2628 // if this isn't a form, returns positive values. | 2646 // if this isn't a form, returns positive values. |
2629 if (!doc_loader_.IsDocumentComplete() && | 2647 if (!doc_loader_.IsDocumentComplete() && |
2630 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { | 2648 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { |
2631 return; | 2649 return; |
2632 } | 2650 } |
2633 | 2651 |
2634 form_ = FPDFDOC_InitFormFillEnvironment( | 2652 form_ = FPDFDOC_InitFormFillEnvironment( |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4013 double* height) { | 4031 double* height) { |
4014 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4032 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4015 if (!doc) | 4033 if (!doc) |
4016 return false; | 4034 return false; |
4017 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4035 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4018 FPDF_CloseDocument(doc); | 4036 FPDF_CloseDocument(doc); |
4019 return success; | 4037 return success; |
4020 } | 4038 } |
4021 | 4039 |
4022 } // namespace chrome_pdf | 4040 } // namespace chrome_pdf |
OLD | NEW |