0

Use chrome_pdf::Timer within PDFiumFormFiller.

Change-Id: Ifa001b139873cfff3e47d54ab9cfb205e45867f2
Reviewed-on: https://chromium-review.googlesource.com/1094440
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#566830}
This commit is contained in:
Artem Strygin
2018-06-13 14:50:35 +00:00
committed by Commit Bot
parent 16f81534cc
commit 407c07d03e
9 changed files with 55 additions and 63 deletions

@ -1239,10 +1239,6 @@ void OutOfProcessInstance::OnClientTouchTimerFired(int32_t id) {
engine_->OnTouchTimerCallback(id);
}
void OutOfProcessInstance::OnClientTimerFired(int32_t id) {
engine_->OnCallback(id);
}
void OutOfProcessInstance::CalculateBackgroundParts() {
background_parts_.clear();
int left_width = available_area_.x();
@ -1566,13 +1562,6 @@ pp::URLLoader OutOfProcessInstance::CreateURLLoader() {
return CreateURLLoaderInternal();
}
void OutOfProcessInstance::ScheduleCallback(int id, base::TimeDelta delay) {
pp::CompletionCallback callback =
callback_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired);
pp::Module::Get()->core()->CallOnMainThread(delay.InMilliseconds(), callback,
id);
}
void OutOfProcessInstance::ScheduleTouchTimerCallback(int id,
base::TimeDelta delay) {
pp::CompletionCallback callback = callback_factory_.NewCallback(

@ -96,7 +96,6 @@ class OutOfProcessInstance : public pp::Instance,
void DidOpenPreview(int32_t result);
// Called when the timer is fired.
void OnClientTimerFired(int32_t id);
void OnClientTouchTimerFired(int32_t id);
// Called to print without re-entrancy issues.
@ -136,7 +135,6 @@ class OutOfProcessInstance : public pp::Instance,
const void* data,
int length) override;
pp::URLLoader CreateURLLoader() override;
void ScheduleCallback(int id, base::TimeDelta delay) override;
void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) override;
std::vector<SearchStringResult> SearchString(const base::char16* string,
const base::char16* term,

@ -219,8 +219,6 @@ class PDFEngine {
// Creates and returns new URL loader for partial document requests.
virtual pp::URLLoader CreateURLLoader() = 0;
// Calls the client's OnCallback() function in |delay| with the given |id|.
virtual void ScheduleCallback(int id, base::TimeDelta delay) {}
// Calls the client's OnTouchTimerCallback() function in |delay| with the
// given |id|.
virtual void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) {}
@ -363,8 +361,6 @@ class PDFEngine {
virtual int GetVerticalScrollbarYPosition() = 0;
// Set color / grayscale rendering modes.
virtual void SetGrayscale(bool grayscale) = 0;
// Callback for timer that's set with ScheduleCallback().
virtual void OnCallback(int id) = 0;
// Callback for timer that's set with ScheduleTouchTimerCallback().
virtual void OnTouchTimerCallback(int id) = 0;
// Get the number of characters on a given page.

@ -677,9 +677,9 @@ std::unique_ptr<PDFEngine> PDFEngine::Create(PDFEngine::Client* client,
PDFiumEngine::PDFiumEngine(PDFEngine::Client* client, bool enable_javascript)
: client_(client),
form_filler_(this, enable_javascript),
mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA,
PDFiumPage::LinkTarget()),
form_filler_(this, enable_javascript),
print_(this) {
find_factory_.Initialize(this);
password_factory_.Initialize(this);
@ -2370,17 +2370,6 @@ void PDFiumEngine::SetGrayscale(bool grayscale) {
render_grayscale_ = grayscale;
}
void PDFiumEngine::OnCallback(int id) {
auto it = formfill_timers_.find(id);
if (it == formfill_timers_.end())
return;
it->second.timer_callback(id);
it = formfill_timers_.find(id); // The callback might delete the timer.
if (it != formfill_timers_.end())
client_->ScheduleCallback(id, it->second.timer_period);
}
void PDFiumEngine::OnTouchTimerCallback(int id) {
if (!touch_timers_.count(id))
return;
@ -3610,10 +3599,6 @@ void PDFiumEngine::GetSelection(uint32_t* selection_start_page_index,
}
}
PDFiumEngine::FormFillTimerData::FormFillTimerData(base::TimeDelta period,
TimerCallback callback)
: timer_period(period), timer_callback(callback) {}
PDFiumEngine::ProgressivePaint::ProgressivePaint(int index,
const pp::Rect& rect)
: page_index_(index), rect_(rect) {}

@ -103,7 +103,6 @@ class PDFiumEngine : public PDFEngine,
pp::Rect GetPageScreenRect(int page_index) const override;
int GetVerticalScrollbarYPosition() override;
void SetGrayscale(bool grayscale) override;
void OnCallback(int id) override;
void OnTouchTimerCallback(int id) override;
int GetCharCount(int page_index) override;
pp::FloatRect GetCharBounds(int page_index, int char_index) override;
@ -512,18 +511,9 @@ class PDFiumEngine : public PDFEngine,
bool getting_password_ = false;
int password_tries_remaining_ = 0;
// Used to manage timers that form fill API needs. The key is the timer id.
// The value holds the timer period and the callback function.
struct FormFillTimerData {
FormFillTimerData(base::TimeDelta period, TimerCallback callback);
base::TimeDelta timer_period;
TimerCallback timer_callback;
};
// Needs to be above pages_, as destroying a page may stop timers.
std::map<int, const FormFillTimerData> formfill_timers_;
int next_formfill_timer_id_ = 0;
// Needs to be above pages_, as destroying a page may call some methods of
// form filler.
PDFiumFormFiller form_filler_;
// Interface structure to provide access to document stream.
FPDF_FILEACCESS file_access_;
@ -701,7 +691,6 @@ class PDFiumEngine : public PDFEngine,
bool edit_mode_ = false;
PDFiumFormFiller form_filler_;
PDFiumPrint print_;
DISALLOW_COPY_AND_ASSIGN(PDFiumEngine);

@ -6,10 +6,12 @@
#include <algorithm>
#include <string>
#include <utility>
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/timer.h"
namespace chrome_pdf {
@ -19,6 +21,23 @@ std::string WideStringToString(FPDF_WIDESTRING wide_string) {
return base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wide_string));
}
class FormFillTimer : public Timer {
public:
FormFillTimer(base::TimeDelta delay, int id, TimerCallback timer_callback)
: Timer(delay), id_(id), timer_callback_(timer_callback) {}
~FormFillTimer() override = default;
// Timer overrides:
void OnTimer() override { timer_callback_(id_); }
private:
const int id_;
TimerCallback timer_callback_;
DISALLOW_COPY_AND_ASSIGN(FormFillTimer);
};
} // namespace
PDFiumFormFiller::PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript)
@ -79,6 +98,8 @@ PDFiumFormFiller::PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript)
}
}
PDFiumFormFiller::~PDFiumFormFiller() = default;
// static
void PDFiumFormFiller::Form_Invalidate(FPDF_FORMFILLINFO* param,
FPDF_PAGE page,
@ -133,21 +154,15 @@ void PDFiumFormFiller::Form_SetCursor(FPDF_FORMFILLINFO* param,
int PDFiumFormFiller::Form_SetTimer(FPDF_FORMFILLINFO* param,
int elapse,
TimerCallback timer_func) {
PDFiumEngine* engine = GetEngine(param);
base::TimeDelta elapse_time = base::TimeDelta::FromMilliseconds(elapse);
engine->formfill_timers_.emplace(
std::piecewise_construct,
std::forward_as_tuple(++engine->next_formfill_timer_id_),
std::forward_as_tuple(elapse_time, timer_func));
engine->client_->ScheduleCallback(engine->next_formfill_timer_id_,
elapse_time);
return engine->next_formfill_timer_id_;
auto* form_filler = static_cast<PDFiumFormFiller*>(param);
return form_filler->SetTimer(base::TimeDelta::FromMilliseconds(elapse),
timer_func);
}
// static
void PDFiumFormFiller::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) {
PDFiumEngine* engine = GetEngine(param);
engine->formfill_timers_.erase(timer_id);
auto* form_filler = static_cast<PDFiumFormFiller*>(param);
form_filler->KillTimer(timer_id);
}
// static
@ -626,4 +641,16 @@ PDFiumEngine* PDFiumFormFiller::GetEngine(IPDF_JSPLATFORM* platform) {
return form_filler->engine_;
}
int PDFiumFormFiller::SetTimer(const base::TimeDelta& delay,
TimerCallback timer_func) {
const int timer_id = ++last_timer_id_;
timers_[timer_id] =
std::make_unique<FormFillTimer>(delay, timer_id, timer_func);
return timer_id;
}
void PDFiumFormFiller::KillTimer(int timer_id) {
timers_.erase(timer_id);
}
} // namespace chrome_pdf

@ -5,16 +5,22 @@
#ifndef PDF_PDFIUM_PDFIUM_FORM_FILLER_H_
#define PDF_PDFIUM_PDFIUM_FORM_FILLER_H_
#include <map>
#include <memory>
#include "base/macros.h"
#include "base/time/time.h"
#include "third_party/pdfium/public/fpdf_formfill.h"
namespace chrome_pdf {
class PDFiumEngine;
class Timer;
class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
public:
PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript);
~PDFiumFormFiller();
private:
// FPDF_FORMFILLINFO callbacks.
@ -165,8 +171,15 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
static PDFiumEngine* GetEngine(FPDF_FORMFILLINFO* info);
static PDFiumEngine* GetEngine(IPDF_JSPLATFORM* platform);
int SetTimer(const base::TimeDelta& delay, TimerCallback timer_func);
void KillTimer(int timer_id);
PDFiumEngine* const engine_;
std::map<int, std::unique_ptr<Timer>> timers_;
int last_timer_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(PDFiumFormFiller);
};

@ -109,10 +109,6 @@ pp::URLLoader PreviewModeClient::CreateURLLoader() {
return pp::URLLoader();
}
void PreviewModeClient::ScheduleCallback(int id, base::TimeDelta delay) {
NOTREACHED();
}
void PreviewModeClient::ScheduleTouchTimerCallback(int id,
base::TimeDelta delay) {
NOTREACHED();

@ -56,7 +56,6 @@ class PreviewModeClient : public PDFEngine::Client {
const void* data,
int length) override;
pp::URLLoader CreateURLLoader() override;
void ScheduleCallback(int id, base::TimeDelta delay) override;
void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) override;
std::vector<SearchStringResult> SearchString(const base::char16* string,
const base::char16* term,