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

Unified Diff: pdf/pdfium/pdfium_engine.cc

Issue 568803004: PDF: Fix uninit memory access in PDFiumEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« pdf/pdfium/pdfium_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pdf/pdfium/pdfium_engine.cc
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 6457478f2bfcb062721d2a33b26564988c4bdc01..42f69e7bf2a9bb30154015f0bd2269ff6f0a908b 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -561,6 +561,8 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
form_(NULL),
defer_page_unload_(false),
selecting_(false),
+ mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA,
+ PDFiumPage::LinkTarget()),
next_page_to_search_(-1),
last_page_to_search_(-1),
last_character_index_to_search_(-1),
@@ -1322,7 +1324,7 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) {
PDFiumPage::LinkTarget target;
PDFiumPage::Area area = GetCharIndex(event, &page_index,
&char_index, &target);
- mouse_down_state_ = MouseDownState(area, target);
+ mouse_down_state_.Set(area, target);
// Decide whether to open link or not based on user action in mouse up and
// mouse move events.
@@ -1410,7 +1412,7 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
GetCharIndex(event, &page_index, &char_index, &target);
// Open link on mouse up for same link for which mouse down happened earlier.
- if (mouse_down_state_ == MouseDownState(area, target)) {
+ if (mouse_down_state_.Matches(area, target)) {
if (area == PDFiumPage::WEBLINK_AREA) {
bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier);
client_->NavigateTo(target.url, open_in_new_tab);
@@ -1443,8 +1445,8 @@ bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) {
// Clear |mouse_down_state_| if mouse moves away from where the mouse down
// happened.
- if (mouse_down_state_ != MouseDownState(area, target))
- mouse_down_state_ = MouseDownState();
+ if (!mouse_down_state_.Matches(area, target))
+ mouse_down_state_.Reset();
if (!selecting_) {
PP_CursorType_Dev cursor;
@@ -2756,6 +2758,39 @@ PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects(
}
}
+PDFiumEngine::MouseDownState::MouseDownState(
+ const PDFiumPage::Area& area,
+ const PDFiumPage::LinkTarget& target)
+ : area_(area), target_(target) {
+}
+
+PDFiumEngine::MouseDownState::~MouseDownState() {
+}
+
+void PDFiumEngine::MouseDownState::Set(const PDFiumPage::Area& area,
+ const PDFiumPage::LinkTarget& target) {
+ area_ = area;
+ target_ = target;
+}
+
+void PDFiumEngine::MouseDownState::Reset() {
+ area_ = PDFiumPage::NONSELECTABLE_AREA;
+ target_ = PDFiumPage::LinkTarget();
+}
+
+bool PDFiumEngine::MouseDownState::Matches(
+ const PDFiumPage::Area& area,
+ const PDFiumPage::LinkTarget& target) const {
+ if (area_ == area) {
+ if (area == PDFiumPage::WEBLINK_AREA)
+ return target_.url == target.url;
+ if (area == PDFiumPage::DOCLINK_AREA)
+ return target_.page == target.page;
+ return true;
+ }
+ return false;
+}
+
void PDFiumEngine::DeviceToPage(int page_index,
float device_x,
float device_y,
« pdf/pdfium/pdfium_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698