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

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

Issue 1167393002: PDF: Interpret printing permission bits correctly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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') | no next file » | 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 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
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 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 GetCharIndex(point, &page_index, &temp, &form_type, &target); 2317 GetCharIndex(point, &page_index, &temp, &form_type, &target);
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 {
raymes 2015/06/09 00:32:59 Is it worth checking that this is not -1?
Lei Zhang 2015/06/09 00:39:41 I'm interpreting -1 as unknown and treating it as
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+.
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:
raymes 2015/06/09 00:32:59 So I guess that if the revision is <3 then you onl
Lei Zhang 2015/06/09 00:39:41 Sure.
2333 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; 2351 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0;
2334 case PERMISSION_PRINT_HIGH_QUALITY:
2335 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 &&
2336 (permissions_ & kPDFPermissionPrintHighQualityMask) != 0;
2337 default: 2352 default:
2338 return true; 2353 return true;
2339 } 2354 }
2340 } 2355 }
2341 2356
2342 void PDFiumEngine::SelectAll() { 2357 void PDFiumEngine::SelectAll() {
2343 SelectionChangeInvalidator selection_invalidator(this); 2358 SelectionChangeInvalidator selection_invalidator(this);
2344 2359
2345 selection_.clear(); 2360 selection_.clear();
2346 for (size_t i = 0; i < pages_.size(); ++i) 2361 for (size_t i = 0; i < pages_.size(); ++i)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 2630
2616 if (!doc_) { 2631 if (!doc_) {
2617 client_->DocumentLoadFailed(); 2632 client_->DocumentLoadFailed();
2618 return; 2633 return;
2619 } 2634 }
2620 2635
2621 if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES) 2636 if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES)
2622 client_->DocumentHasUnsupportedFeature("Bookmarks"); 2637 client_->DocumentHasUnsupportedFeature("Bookmarks");
2623 2638
2624 permissions_ = FPDF_GetDocPermissions(doc_); 2639 permissions_ = FPDF_GetDocPermissions(doc_);
2640 permissions_handler_revision_ = FPDF_GetSecurityHandlerRevision(doc_);
2625 2641
2626 if (!form_) { 2642 if (!form_) {
2627 // Only returns 0 when data isn't available. If form data is downloaded, or 2643 // Only returns 0 when data isn't available. If form data is downloaded, or
2628 // if this isn't a form, returns positive values. 2644 // if this isn't a form, returns positive values.
2629 if (!doc_loader_.IsDocumentComplete() && 2645 if (!doc_loader_.IsDocumentComplete() &&
2630 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) { 2646 !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) {
2631 return; 2647 return;
2632 } 2648 }
2633 2649
2634 form_ = FPDFDOC_InitFormFillEnvironment( 2650 form_ = FPDFDOC_InitFormFillEnvironment(
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
4013 double* height) { 4029 double* height) {
4014 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4030 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4015 if (!doc) 4031 if (!doc)
4016 return false; 4032 return false;
4017 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4033 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4018 FPDF_CloseDocument(doc); 4034 FPDF_CloseDocument(doc);
4019 return success; 4035 return success;
4020 } 4036 }
4021 4037
4022 } // namespace chrome_pdf 4038 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698