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

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: parens Created 5 years, 1 month 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
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | ppapi/cpp/private/find_private.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 feature = "Screen"; 1225 feature = "Screen";
1226 break; 1226 break;
1227 case FPDF_UNSP_ANNOT_SIG: 1227 case FPDF_UNSP_ANNOT_SIG:
1228 feature = "Digital_Signature"; 1228 feature = "Digital_Signature";
1229 break; 1229 break;
1230 } 1230 }
1231 client_->DocumentHasUnsupportedFeature(feature); 1231 client_->DocumentHasUnsupportedFeature(feature);
1232 } 1232 }
1233 1233
1234 void PDFiumEngine::ContinueFind(int32_t result) { 1234 void PDFiumEngine::ContinueFind(int32_t result) {
1235 StartFind(current_find_text_.c_str(), !!result); 1235 StartFind(current_find_text_, result != 0);
1236 } 1236 }
1237 1237
1238 bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) { 1238 bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
1239 DCHECK(!defer_page_unload_); 1239 DCHECK(!defer_page_unload_);
1240 defer_page_unload_ = true; 1240 defer_page_unload_ = true;
1241 bool rv = false; 1241 bool rv = false;
1242 switch (event.GetType()) { 1242 switch (event.GetType()) {
1243 case PP_INPUTEVENT_TYPE_MOUSEDOWN: 1243 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
1244 rv = OnMouseDown(pp::MouseInputEvent(event)); 1244 rv = OnMouseDown(pp::MouseInputEvent(event));
1245 break; 1245 break;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 if (last_page_mouse_down_ == -1) 1902 if (last_page_mouse_down_ == -1)
1903 return false; 1903 return false;
1904 1904
1905 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString()); 1905 base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString());
1906 return !!FORM_OnChar( 1906 return !!FORM_OnChar(
1907 form_, pages_[last_page_mouse_down_]->GetPage(), 1907 form_, pages_[last_page_mouse_down_]->GetPage(),
1908 str[0], 1908 str[0],
1909 event.GetModifiers()); 1909 event.GetModifiers());
1910 } 1910 }
1911 1911
1912 void PDFiumEngine::StartFind(const char* text, bool case_sensitive) { 1912 void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) {
1913 // We can get a call to StartFind before we have any page information (i.e. 1913 // If the caller asks StartFind() to search for no text, then this is an
1914 // error on the part of the caller. The PPAPI Find_Private interface
1915 // guarantees it is not empty, so this should never happen.
1916 DCHECK(!text.empty());
1917
1918 // If StartFind() gets called before we have any page information (i.e.
1914 // before the first call to LoadDocument has happened). Handle this case. 1919 // before the first call to LoadDocument has happened). Handle this case.
1915 if (pages_.empty()) 1920 if (pages_.empty())
1916 return; 1921 return;
1917 1922
1918 bool first_search = false; 1923 bool first_search = (current_find_text_ != text);
1919 int character_to_start_searching_from = 0; 1924 int character_to_start_searching_from = 0;
1920 if (current_find_text_ != text) { // First time we search for this text. 1925 if (first_search) {
1921 first_search = true;
1922 std::vector<PDFiumRange> old_selection = selection_; 1926 std::vector<PDFiumRange> old_selection = selection_;
1923 StopFind(); 1927 StopFind();
1924 current_find_text_ = text; 1928 current_find_text_ = text;
1925 1929
1926 if (old_selection.empty()) { 1930 if (old_selection.empty()) {
1927 // Start searching from the beginning of the document. 1931 // Start searching from the beginning of the document.
1928 next_page_to_search_ = 0; 1932 next_page_to_search_ = 0;
1929 last_page_to_search_ = pages_.size() - 1; 1933 last_page_to_search_ = pages_.size() - 1;
1930 last_character_index_to_search_ = -1; 1934 last_character_index_to_search_ = -1;
1931 } else { 1935 } else {
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
3425 if (current_find_index_.valid()) 3429 if (current_find_index_.valid())
3426 resume_find_index_.SetIndex(current_find_index_.GetIndex()); 3430 resume_find_index_.SetIndex(current_find_index_.GetIndex());
3427 else 3431 else
3428 resume_find_index_.Invalidate(); 3432 resume_find_index_.Invalidate();
3429 3433
3430 InvalidateAllPages(); 3434 InvalidateAllPages();
3431 3435
3432 if (!current_find_text.empty()) { 3436 if (!current_find_text.empty()) {
3433 // Clear the UI. 3437 // Clear the UI.
3434 client_->NotifyNumberOfFindResultsChanged(0, false); 3438 client_->NotifyNumberOfFindResultsChanged(0, false);
3435 StartFind(current_find_text.c_str(), false); 3439 StartFind(current_find_text, false);
3436 } 3440 }
3437 } 3441 }
3438 3442
3439 void PDFiumEngine::SetSelecting(bool selecting) { 3443 void PDFiumEngine::SetSelecting(bool selecting) {
3440 bool was_selecting = selecting_; 3444 bool was_selecting = selecting_;
3441 selecting_ = selecting; 3445 selecting_ = selecting;
3442 if (selecting_ != was_selecting) 3446 if (selecting_ != was_selecting)
3443 client_->IsSelectingChanged(selecting); 3447 client_->IsSelectingChanged(selecting);
3444 } 3448 }
3445 3449
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3990 double* height) { 3994 double* height) {
3991 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3995 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3992 if (!doc) 3996 if (!doc)
3993 return false; 3997 return false;
3994 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3998 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3995 FPDF_CloseDocument(doc); 3999 FPDF_CloseDocument(doc);
3996 return success; 4000 return success;
3997 } 4001 }
3998 4002
3999 } // namespace chrome_pdf 4003 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | ppapi/cpp/private/find_private.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698