OLD | NEW |
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 "android_webview/browser/find_helper.h" | 5 #include "android_webview/browser/find_helper.h" |
6 | 6 |
7 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" | 7 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 FindHelper::~FindHelper() { | 31 FindHelper::~FindHelper() { |
32 } | 32 } |
33 | 33 |
34 void FindHelper::SetListener(Listener* listener) { | 34 void FindHelper::SetListener(Listener* listener) { |
35 listener_ = listener; | 35 listener_ = listener; |
36 } | 36 } |
37 | 37 |
38 void FindHelper::FindAllAsync(const base::string16& search_string) { | 38 void FindHelper::FindAllAsync(const base::string16& search_string) { |
39 // Stop any ongoing asynchronous request. | 39 // Stop any ongoing asynchronous request. |
40 web_contents()->GetRenderViewHost()->StopFinding( | 40 web_contents()->StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION); |
41 content::STOP_FIND_ACTION_KEEP_SELECTION); | |
42 | 41 |
43 sync_find_started_ = false; | 42 sync_find_started_ = false; |
44 async_find_started_ = true; | 43 async_find_started_ = true; |
45 | 44 |
46 WebFindOptions options; | 45 WebFindOptions options; |
47 options.forward = true; | 46 options.forward = true; |
48 options.matchCase = false; | 47 options.matchCase = false; |
49 options.findNext = false; | 48 options.findNext = false; |
50 | 49 |
51 StartNewRequest(search_string); | 50 StartNewRequest(search_string); |
52 web_contents()->GetRenderViewHost()->Find(current_request_id_, | 51 web_contents()->Find(current_request_id_, search_string, options); |
53 search_string, options); | |
54 } | 52 } |
55 | 53 |
56 void FindHelper::HandleFindReply(int request_id, | 54 void FindHelper::HandleFindReply(int request_id, |
57 int match_count, | 55 int match_count, |
58 int active_ordinal, | 56 int active_ordinal, |
59 bool finished) { | 57 bool finished) { |
60 if ((!async_find_started_ && !sync_find_started_) || | 58 if ((!async_find_started_ && !sync_find_started_) || |
61 request_id != current_request_id_) { | 59 request_id != current_request_id_) { |
62 return; | 60 return; |
63 } | 61 } |
64 | 62 |
65 NotifyResults(active_ordinal, match_count, finished); | 63 NotifyResults(active_ordinal, match_count, finished); |
66 } | 64 } |
67 | 65 |
68 void FindHelper::FindNext(bool forward) { | 66 void FindHelper::FindNext(bool forward) { |
69 if (!sync_find_started_ && !async_find_started_) | 67 if (!sync_find_started_ && !async_find_started_) |
70 return; | 68 return; |
71 | 69 |
72 WebFindOptions options; | 70 WebFindOptions options; |
73 options.forward = forward; | 71 options.forward = forward; |
74 options.matchCase = false; | 72 options.matchCase = false; |
75 options.findNext = true; | 73 options.findNext = true; |
76 | 74 |
77 web_contents()->GetRenderViewHost()->Find(current_request_id_, | 75 web_contents()->Find(current_request_id_, last_search_string_, options); |
78 last_search_string_, | |
79 options); | |
80 } | 76 } |
81 | 77 |
82 void FindHelper::ClearMatches() { | 78 void FindHelper::ClearMatches() { |
83 web_contents()->GetRenderViewHost()->StopFinding( | 79 web_contents()->StopFinding(content::STOP_FIND_ACTION_CLEAR_SELECTION); |
84 content::STOP_FIND_ACTION_CLEAR_SELECTION); | |
85 | 80 |
86 sync_find_started_ = false; | 81 sync_find_started_ = false; |
87 async_find_started_ = false; | 82 async_find_started_ = false; |
88 last_search_string_.clear(); | 83 last_search_string_.clear(); |
89 last_match_count_ = -1; | 84 last_match_count_ = -1; |
90 last_active_ordinal_ = -1; | 85 last_active_ordinal_ = -1; |
91 } | 86 } |
92 | 87 |
93 void FindHelper::StartNewRequest(const base::string16& search_string) { | 88 void FindHelper::StartNewRequest(const base::string16& search_string) { |
94 current_request_id_ = find_request_id_counter_++; | 89 current_request_id_ = find_request_id_counter_++; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 124 |
130 // WebView.FindListener active match ordinals are 0-based while WebKit sends | 125 // WebView.FindListener active match ordinals are 0-based while WebKit sends |
131 // 1-based ordinals. Still we can receive 0 ordinal in case of no results. | 126 // 1-based ordinals. Still we can receive 0 ordinal in case of no results. |
132 active_ordinal = std::max(active_ordinal - 1, 0); | 127 active_ordinal = std::max(active_ordinal - 1, 0); |
133 | 128 |
134 if (listener_) | 129 if (listener_) |
135 listener_->OnFindResultReceived(active_ordinal, match_count, finished); | 130 listener_->OnFindResultReceived(active_ordinal, match_count, finished); |
136 } | 131 } |
137 | 132 |
138 } // namespace android_webview | 133 } // namespace android_webview |
OLD | NEW |