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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1365563003: Prevent guest views from issuing a search for empty text. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lint Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/i18n/icu_encoding_detection.h" 9 #include "base/i18n/icu_encoding_detection.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 feature = "Screen"; 1317 feature = "Screen";
1318 break; 1318 break;
1319 case FPDF_UNSP_ANNOT_SIG: 1319 case FPDF_UNSP_ANNOT_SIG:
1320 feature = "Digital_Signature"; 1320 feature = "Digital_Signature";
1321 break; 1321 break;
1322 } 1322 }
1323 client_->DocumentHasUnsupportedFeature(feature); 1323 client_->DocumentHasUnsupportedFeature(feature);
1324 } 1324 }
1325 1325
1326 void PDFiumEngine::ContinueFind(int32_t result) { 1326 void PDFiumEngine::ContinueFind(int32_t result) {
1327 StartFind(current_find_text_.c_str(), !!result); 1327 StartFind(current_find_text_, result != 0);
1328 } 1328 }
1329 1329
1330 bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) { 1330 bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
1331 DCHECK(!defer_page_unload_); 1331 DCHECK(!defer_page_unload_);
1332 defer_page_unload_ = true; 1332 defer_page_unload_ = true;
1333 bool rv = false; 1333 bool rv = false;
1334 switch (event.GetType()) { 1334 switch (event.GetType()) {
1335 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 1335 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
1336 rv = OnMouseDown(pp::MouseInputEvent(event)); 1336 rv = OnMouseDown(pp::MouseInputEvent(event));
1337 break; 1337 break;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 if (last_page_mouse_down_ == -1) 1994 if (last_page_mouse_down_ == -1)
1995 return false; 1995 return false;
1996 1996
1997 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); 1997 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString());
1998 return !!FORM_OnChar( 1998 return !!FORM_OnChar(
1999 form_, pages_[last_page_mouse_down_]->GetPage(), 1999 form_, pages_[last_page_mouse_down_]->GetPage(),
2000 str[0], 2000 str[0],
2001 event.GetModifiers()); 2001 event.GetModifiers());
2002 } 2002 }
2003 2003
2004 void PDFiumEngine::StartFind(const char* text, bool case_sensitive) { 2004 void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) {
2005 // We can get a call to StartFind before we have any page information (i.e. 2005 // If the caller asks StartFind() to search for no text, then this is an
2006 // error on the part of the caller. The PPAPI Find_Private interface
2007 // guarantees it is not empty, so this should never happen.
2008 DCHECK(!text.empty());
2009
2010 // If StartFind() gets called before we have any page information (i.e.
2006 // before the first call to LoadDocument has happened). Handle this case. 2011 // before the first call to LoadDocument has happened). Handle this case.
2007 if (pages_.empty()) 2012 if (pages_.empty())
2008 return; 2013 return;
2009 2014
2010 bool first_search = false; 2015 bool first_search = (current_find_text_ != text);
2011 int character_to_start_searching_from = 0; 2016 int character_to_start_searching_from = 0;
2012 if (current_find_text_ != text) { // First time we search for this text. 2017 if (first_search) {
2013 first_search = true;
2014 std::vector<PDFiumRange> old_selection = selection_; 2018 std::vector<PDFiumRange> old_selection = selection_;
2015 StopFind(); 2019 StopFind();
2016 current_find_text_ = text; 2020 current_find_text_ = text;
2017 2021
2018 if (old_selection.empty()) { 2022 if (old_selection.empty()) {
2019 // Start searching from the beginning of the document. 2023 // Start searching from the beginning of the document.
2020 next_page_to_search_ = 0; 2024 next_page_to_search_ = 0;
2021 last_page_to_search_ = pages_.size() - 1; 2025 last_page_to_search_ = pages_.size() - 1;
2022 last_character_index_to_search_ = -1; 2026 last_character_index_to_search_ = -1;
2023 } else { 2027 } else {
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
3497 if (current_find_index_.valid()) 3501 if (current_find_index_.valid())
3498 resume_find_index_.SetIndex(current_find_index_.GetIndex()); 3502 resume_find_index_.SetIndex(current_find_index_.GetIndex());
3499 else 3503 else
3500 resume_find_index_.Invalidate(); 3504 resume_find_index_.Invalidate();
3501 3505
3502 InvalidateAllPages(); 3506 InvalidateAllPages();
3503 3507
3504 if (!current_find_text.empty()) { 3508 if (!current_find_text.empty()) {
3505 // Clear the UI. 3509 // Clear the UI.
3506 client_->NotifyNumberOfFindResultsChanged(0, false); 3510 client_->NotifyNumberOfFindResultsChanged(0, false);
3507 StartFind(current_find_text.c_str(), false); 3511 StartFind(current_find_text, false);
3508 } 3512 }
3509 } 3513 }
3510 3514
3511 void PDFiumEngine::SetSelecting(bool selecting) { 3515 void PDFiumEngine::SetSelecting(bool selecting) {
3512 bool was_selecting = selecting_; 3516 bool was_selecting = selecting_;
3513 selecting_ = selecting; 3517 selecting_ = selecting;
3514 if (selecting_ != was_selecting) 3518 if (selecting_ != was_selecting)
3515 client_->IsSelectingChanged(selecting); 3519 client_->IsSelectingChanged(selecting);
3516 } 3520 }
3517 3521
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
4062 double* height) { 4066 double* height) {
4063 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4067 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4064 if (!doc) 4068 if (!doc)
4065 return false; 4069 return false;
4066 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4070 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4067 FPDF_CloseDocument(doc); 4071 FPDF_CloseDocument(doc);
4068 return success; 4072 return success;
4069 } 4073 }
4070 4074
4071 } // namespace chrome_pdf 4075 } // namespace chrome_pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698