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

Side by Side Diff: android_webview/browser/find_helper.h

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 | « no previous file | android_webview/browser/find_helper.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 #ifndef ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_ 5 #ifndef ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_
6 #define ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_
7 7
8 #include "base/memory/weak_ptr.h"
9 #include "content/public/browser/web_contents_observer.h" 8 #include "content/public/browser/web_contents_observer.h"
10 9
11 namespace android_webview { 10 namespace android_webview {
12 11
13 // Handles the WebView find-in-page API requests. 12 // Handles the WebView find-in-page API requests.
14 class FindHelper : public content::WebContentsObserver { 13 class FindHelper : public content::WebContentsObserver {
15 public: 14 public:
16 class Listener { 15 class Listener {
17 public: 16 public:
18 // Called when receiving a new find-in-page update. 17 // Called when receiving a new find-in-page update.
19 // This will be triggered when the results of FindAllSync, FindAllAsync and 18 // This will be triggered when the results of FindAllSync, FindAllAsync and
20 // FindNext are available. The value provided in active_ordinal is 0-based. 19 // FindNext are available. The value provided in active_ordinal is 0-based.
21 virtual void OnFindResultReceived(int active_ordinal, 20 virtual void OnFindResultReceived(int active_ordinal,
22 int match_count, 21 int match_count,
23 bool finished) = 0; 22 bool finished) = 0;
24 virtual ~Listener() {} 23 virtual ~Listener() {}
25 }; 24 };
26 25
27 explicit FindHelper(content::WebContents* web_contents); 26 explicit FindHelper(content::WebContents* web_contents);
28 ~FindHelper() override; 27 ~FindHelper() override;
29 28
30 // Sets the listener to receive find result updates. 29 // Sets the listener to receive find result updates.
31 // Does not own the listener and must set to NULL when invalid. 30 // Does not own the listener and must set to nullptr when invalid.
32 void SetListener(Listener* listener); 31 void SetListener(Listener* listener);
33 32
34 // Asynchronous API. 33 // Asynchronous API.
35 void FindAllAsync(const base::string16& search_string); 34 void FindAllAsync(const base::string16& search_string);
36 void HandleFindReply(int request_id, 35 void HandleFindReply(int request_id,
37 int match_count, 36 int match_count,
38 int active_ordinal, 37 int active_ordinal,
39 bool finished); 38 bool finished);
40 39
41 // Methods valid in both synchronous and asynchronous modes. 40 // Methods valid in both synchronous and asynchronous modes.
42 void FindNext(bool forward); 41 void FindNext(bool forward);
43 void ClearMatches(); 42 void ClearMatches();
44 43
45 private: 44 private:
46 void StartNewRequest(const base::string16& search_string); 45 void StartNewRequest(const base::string16& search_string);
46 bool MaybeHandleEmptySearch(const base::string16& search_string);
47 void NotifyResults(int active_ordinal, int match_count, bool finished); 47 void NotifyResults(int active_ordinal, int match_count, bool finished);
48 48
49 // Listener results are reported to. 49 // Listener results are reported to.
50 Listener* listener_; 50 Listener* listener_;
51 51
52 // Used to check the validity of FindNext operations. 52 // Used to check the validity of FindNext operations.
53 bool async_find_started_; 53 bool async_find_started_;
54 bool sync_find_started_;
55 54
56 // Used to provide different ids to each request and for result 55 // Used to provide different ids to each request and for result
57 // verification in asynchronous calls. 56 // verification in asynchronous calls.
58 int find_request_id_counter_; 57 int find_request_id_counter_;
59 int current_request_id_; 58 int current_request_id_;
60 59
61 // Required by FindNext and the incremental find replies. 60 // Required by FindNext and the incremental find replies.
62 base::string16 last_search_string_; 61 base::string16 last_search_string_;
63 int last_match_count_; 62 int last_match_count_;
64 int last_active_ordinal_; 63 int last_active_ordinal_;
65 64
66 // Used to post synchronous result notifications to ourselves.
67 base::WeakPtrFactory<FindHelper> weak_factory_;
68
69 DISALLOW_COPY_AND_ASSIGN(FindHelper); 65 DISALLOW_COPY_AND_ASSIGN(FindHelper);
70 }; 66 };
71 67
72 } // namespace android_webview 68 } // namespace android_webview
73 69
74 #endif // ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_ 70 #endif // ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | android_webview/browser/find_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698