From b59ab7ac8433652b921f2a93289c6d13b862e5a0 Mon Sep 17 00:00:00 2001 From: raymes Date: Wed, 21 Jan 2015 18:07:49 -0800 Subject: [PATCH] Delay printing OOP PDF until loading is complete This delays the print command in OOP PDF. This simplifies the use of the OOP PDF scripting API so print can be called immediately before the document is loaded. BUG=303491 Review URL: https://codereview.chromium.org/865023002 Cr-Commit-Position: refs/heads/master@{#312524} --- pdf/out_of_process_instance.cc | 55 +++++++++++++++++++++--------------------- pdf/out_of_process_instance.h | 5 +++- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc index 2f08ff9cda26..58b25a9f66c9 100644 --- a/pdf/out_of_process_instance.cc +++ b/pdf/out_of_process_instance.cc @@ -255,7 +255,6 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) cursor_(PP_CURSORTYPE_POINTER), zoom_(1.0), device_scale_(1.0), - printing_enabled_(true), full_(false), paint_manager_(this, this, true), first_paint_(true), @@ -268,7 +267,8 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) recently_sent_find_update_(false), received_viewport_message_(false), did_call_start_loading_(false), - stop_scrolling_(false) { + stop_scrolling_(false), + delay_print_(false) { loader_factory_.Initialize(this); timer_factory_.Initialize(this); form_factory_.Initialize(this); @@ -970,9 +970,13 @@ void OutOfProcessInstance::Email(const std::string& to, } void OutOfProcessInstance::Print() { - if (!printing_enabled_ || - (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && - !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))) { + if (document_load_state_ == LOAD_STATE_LOADING) { + delay_print_ = true; + return; + } + + if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && + !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { return; } @@ -1088,38 +1092,35 @@ void OutOfProcessInstance::DocumentLoadComplete(int page_count) { pp::Var(named_destinations)); PostMessage(named_destinations_message); + pp::VarDictionary bookmarks_message; + bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); + bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); + PostMessage(bookmarks_message); + pp::VarDictionary progress_message; progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); PostMessage(progress_message); - pp::VarDictionary bookmarksMessage; - bookmarksMessage.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); - bookmarksMessage.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); - PostMessage(bookmarksMessage); - - if (!full_) - return; + if (full_) { + if (did_call_start_loading_) { + pp::PDF::DidStopLoading(this); + did_call_start_loading_ = false; + } - if (did_call_start_loading_) { - pp::PDF::DidStopLoading(this); - did_call_start_loading_ = false; - } + int content_restrictions = + CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; + if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) + content_restrictions |= CONTENT_RESTRICTION_COPY; - int content_restrictions = - CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; - if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) - content_restrictions |= CONTENT_RESTRICTION_COPY; + pp::PDF::SetContentRestriction(this, content_restrictions); - if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && - !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { - printing_enabled_ = false; + uma_.HistogramCustomCounts("PDF.PageCount", page_count, + 1, 1000000, 50); } - pp::PDF::SetContentRestriction(this, content_restrictions); - - uma_.HistogramCustomCounts("PDF.PageCount", page_count, - 1, 1000000, 50); + if (delay_print_) + Print(); } void OutOfProcessInstance::RotateClockwise() { diff --git a/pdf/out_of_process_instance.h b/pdf/out_of_process_instance.h index 8a841bf251ea..bcd507dd3da3 100644 --- a/pdf/out_of_process_instance.h +++ b/pdf/out_of_process_instance.h @@ -236,7 +236,6 @@ class OutOfProcessInstance : public pp::Instance, double zoom_; // Current zoom factor. float device_scale_; // Current device scale factor. - bool printing_enabled_; // True if the plugin is full-page. bool full_; @@ -340,6 +339,10 @@ class OutOfProcessInstance : public pp::Instance, // zooming the plugin so that flickering doesn't occur while zooming. bool stop_scrolling_; + // If a print command comes in before the document has loaded, we set + // |delay_print_| to true and print after the document has loaded. + bool delay_print_; + // The callback for receiving the password from the page. scoped_ptr > password_callback_; }; -- 2.11.4.GIT