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