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

Unified Diff: android_webview/browser/find_helper.h

Issue 10941015: [Android] Upstream the WebView find-in-page API implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit fixes. Created 8 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
« no previous file with comments | « android_webview/browser/DEPS ('k') | android_webview/browser/find_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/browser/find_helper.h
diff --git a/android_webview/browser/find_helper.h b/android_webview/browser/find_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..a9d7aed2296871a2de86ccda9df8fedfc7be1160
--- /dev/null
+++ b/android_webview/browser/find_helper.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_
+#define ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace android_webview {
+
+// Handles the WebView find-in-page API requests.
+class FindHelper : public content::WebContentsObserver {
+ public:
+ class Listener {
+ public:
+ // Called when receiving a new find-in-page update.
+ // This will be triggered when the results of FindAllSync, FindAllAsync and
+ // FindNext are available. The value provided in active_ordinal is 0-based.
+ virtual void OnFindResultReceived(int active_ordinal,
+ int match_count,
+ bool finished) = 0;
+ virtual ~Listener() {}
+ };
+
+ explicit FindHelper(content::WebContents* web_contents);
+ virtual ~FindHelper();
+
+ // Sets the listener to receive find result updates.
+ // Does not own the listener and must set to NULL when invalid.
+ void SetListener(Listener* listener);
+
+ // Synchronous API.
+ int FindAllSync(const string16& search_string);
+
+ // Asynchronous API.
+ void FindAllAsync(const string16& search_string);
+ void HandleFindReply(int request_id,
+ int match_count,
+ int active_ordinal,
+ bool finished);
+
+ // Methods valid in both synchronous and asynchronous modes.
+ void FindNext(bool forward);
+ void ClearMatches();
+
+ private:
+ void StartNewRequest(const string16& search_string);
+ void NotifyResults(int active_ordinal, int match_count, bool finished);
+
+ // Listener results are reported to.
+ Listener* listener_;
+
+ // Used to check the validity of FindNext operations.
+ bool async_find_started_;
+ bool sync_find_started_;
+
+ // Used to provide different ids to each request and for result
+ // verification in asynchronous calls.
+ int find_request_id_counter_;
+ int current_request_id_;
+
+ // Required by FindNext and the incremental find replies.
+ string16 last_search_string_;
+ int last_match_count_;
+ int last_active_ordinal_;
+
+ // Used to post synchronous result notifications to ourselves.
+ base::WeakPtrFactory<FindHelper> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FindHelper);
+};
+
+} // namespace android_webview
+
+#endif // ANDROID_WEBVIEW_BROWSER_FIND_HELPER_H_
« no previous file with comments | « android_webview/browser/DEPS ('k') | android_webview/browser/find_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698