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:
@@ -20,6 +20,8 @@ namespace chrome_pdf {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
int g_last_timer_id = 0;
|
||||||
|
|
||||||
std::string WideStringToString(FPDF_WIDESTRING wide_string) {
|
std::string WideStringToString(FPDF_WIDESTRING wide_string) {
|
||||||
return base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(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,
|
int PDFiumFormFiller::SetTimer(const base::TimeDelta& delay,
|
||||||
TimerCallback timer_func) {
|
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>();
|
auto timer = std::make_unique<base::RepeatingTimer>();
|
||||||
timer->Start(FROM_HERE, delay, base::BindRepeating(timer_func, timer_id));
|
timer->Start(FROM_HERE, delay, base::BindRepeating(timer_func, timer_id));
|
||||||
timers_[timer_id] = std::move(timer);
|
timers_[timer_id] = std::move(timer);
|
||||||
@@ -677,7 +681,8 @@ int PDFiumFormFiller::SetTimer(const base::TimeDelta& delay,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PDFiumFormFiller::KillTimer(int timer_id) {
|
void PDFiumFormFiller::KillTimer(int timer_id) {
|
||||||
timers_.erase(timer_id);
|
size_t erased = timers_.erase(timer_id);
|
||||||
|
DCHECK_EQ(1u, erased);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chrome_pdf
|
} // namespace chrome_pdf
|
||||||
|
@@ -21,6 +21,8 @@ class PDFiumEngine;
|
|||||||
class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
|
class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
|
||||||
public:
|
public:
|
||||||
PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript);
|
PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript);
|
||||||
|
PDFiumFormFiller(const PDFiumFormFiller&) = delete;
|
||||||
|
PDFiumFormFiller& operator=(const PDFiumFormFiller&) = delete;
|
||||||
~PDFiumFormFiller();
|
~PDFiumFormFiller();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -186,9 +188,6 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
|
|||||||
PDFiumEngine* const engine_;
|
PDFiumEngine* const engine_;
|
||||||
|
|
||||||
std::map<int, std::unique_ptr<base::RepeatingTimer>> timers_;
|
std::map<int, std::unique_ptr<base::RepeatingTimer>> timers_;
|
||||||
int last_timer_id_ = 0;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(PDFiumFormFiller);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chrome_pdf
|
} // namespace chrome_pdf
|
||||||
|
Reference in New Issue
Block a user