0

PDF: Give every JS timer a unique ID.

Currently, every PDFiumFormFiller instance has its own ID counter.
Multiple PDFiumFormFiller instances may exist in the same process.
Meanwhile, PDFium expects every timer to have a unique ID inside a given
process. This leads to a clash where timers do not work right due to
duplicate timer IDs inside PDFium.

To fix this, make all PDFiumFormFiller instances share an ID counter.

Bug: 1071689
Change-Id: Ide58aef8258a357196308f2d9d1ab7c967238c14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153942
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759932}
This commit is contained in:
Lei Zhang
2020-04-17 04:07:52 +00:00
committed by Commit Bot
parent fee348763a
commit ad01fb22ec
2 changed files with 9 additions and 5 deletions

@ -20,6 +20,8 @@ namespace chrome_pdf {
namespace {
int g_last_timer_id = 0;
std::string WideStringToString(FPDF_WIDESTRING wide_string) {
return base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wide_string));
}
@ -669,7 +671,9 @@ PDFiumEngine* PDFiumFormFiller::GetEngine(IPDF_JSPLATFORM* platform) {
int PDFiumFormFiller::SetTimer(const base::TimeDelta& delay,
TimerCallback timer_func) {
const int timer_id = ++last_timer_id_;
const int timer_id = ++g_last_timer_id;
DCHECK(!base::Contains(timers_, timer_id));
auto timer = std::make_unique<base::RepeatingTimer>();
timer->Start(FROM_HERE, delay, base::BindRepeating(timer_func, timer_id));
timers_[timer_id] = std::move(timer);
@ -677,7 +681,8 @@ int PDFiumFormFiller::SetTimer(const base::TimeDelta& delay,
}
void PDFiumFormFiller::KillTimer(int timer_id) {
timers_.erase(timer_id);
size_t erased = timers_.erase(timer_id);
DCHECK_EQ(1u, erased);
}
} // namespace chrome_pdf

@ -21,6 +21,8 @@ class PDFiumEngine;
class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
public:
PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript);
PDFiumFormFiller(const PDFiumFormFiller&) = delete;
PDFiumFormFiller& operator=(const PDFiumFormFiller&) = delete;
~PDFiumFormFiller();
private:
@ -186,9 +188,6 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
PDFiumEngine* const engine_;
std::map<int, std::unique_ptr<base::RepeatingTimer>> timers_;
int last_timer_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(PDFiumFormFiller);
};
} // namespace chrome_pdf