summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents/tab_contents.cc
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 18:26:39 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 18:26:39 +0000
commitae5379b6f7bad9acde2c95087eb623a2940599c4 (patch)
tree5b8994febfcbf908f088bd382a6980265e4d035e /chrome/browser/tab_contents/tab_contents.cc
parentf7b8b9f697e41f44319ac7b757c9442d07f73b0c (diff)
downloadchromium_src-ae5379b6f7bad9acde2c95087eb623a2940599c4.zip
chromium_src-ae5379b6f7bad9acde2c95087eb623a2940599c4.tar.gz
chromium_src-ae5379b6f7bad9acde2c95087eb623a2940599c4.tar.bz2
Revert 73294 - Move find-in-page from TabContents to TabContentsWrapper.
BUG=71097 TEST=Hammer on find-in-page on all platforms. Nothing should crash, break, or have any user-visible change. Review URL: http://codereview.chromium.org/6378014 TBR=avi@chromium.org Review URL: http://codereview.chromium.org/6286019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/tab_contents.cc')
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc119
1 files changed, 119 insertions, 0 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 0c8e6de..8a941cd 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -80,6 +80,7 @@
#include "chrome/browser/tab_contents/thumbnail_generator.h"
#include "chrome/browser/translate/page_translated_details.h"
#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
+#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "chrome/common/bindings_policy.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/content_restriction.h"
@@ -253,6 +254,10 @@ void MakeNavigateParams(const NavigationEntry& entry,
// TabContents ----------------------------------------------------------------
+// static
+int TabContents::find_request_id_counter_ = -1;
+
+
TabContents::TabContents(Profile* profile,
SiteInstance* site_instance,
int routing_id,
@@ -293,6 +298,11 @@ TabContents::TabContents(Profile* profile,
dont_notify_render_view_(false),
displayed_insecure_content_(false),
infobar_delegates_(),
+ find_ui_active_(false),
+ find_op_aborted_(false),
+ current_find_request_id_(find_request_id_counter_++),
+ last_search_case_sensitive_(false),
+ last_search_result_(),
extension_app_(NULL),
capturing_contents_(false),
is_being_destroyed_(false),
@@ -528,6 +538,7 @@ bool TabContents::OnMessageReceived(const IPC::Message& message) {
OnUpdateContentRestrictions)
IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
OnPDFHasUnsupportedFeature)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
OnDidGetApplicationInfo)
@@ -1270,6 +1281,74 @@ void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
#endif
}
+void TabContents::StartFinding(string16 search_string,
+ bool forward_direction,
+ bool case_sensitive) {
+ // If search_string is empty, it means FindNext was pressed with a keyboard
+ // shortcut so unless we have something to search for we return early.
+ if (search_string.empty() && find_text_.empty()) {
+ string16 last_search_prepopulate_text =
+ FindBarState::GetLastPrepopulateText(profile());
+
+ // Try the last thing we searched for on this tab, then the last thing
+ // searched for on any tab.
+ if (!previous_find_text_.empty())
+ search_string = previous_find_text_;
+ else if (!last_search_prepopulate_text.empty())
+ search_string = last_search_prepopulate_text;
+ else
+ return;
+ }
+
+ // Keep track of the previous search.
+ previous_find_text_ = find_text_;
+
+ // This is a FindNext operation if we are searching for the same text again,
+ // or if the passed in search text is empty (FindNext keyboard shortcut). The
+ // exception to this is if the Find was aborted (then we don't want FindNext
+ // because the highlighting has been cleared and we need it to reappear). We
+ // therefore treat FindNext after an aborted Find operation as a full fledged
+ // Find.
+ bool find_next = (find_text_ == search_string || search_string.empty()) &&
+ (last_search_case_sensitive_ == case_sensitive) &&
+ !find_op_aborted_;
+ if (!find_next)
+ current_find_request_id_ = find_request_id_counter_++;
+
+ if (!search_string.empty())
+ find_text_ = search_string;
+ last_search_case_sensitive_ = case_sensitive;
+
+ find_op_aborted_ = false;
+
+ // Keep track of what the last search was across the tabs.
+ FindBarState* find_bar_state = profile()->GetFindBarState();
+ find_bar_state->set_last_prepopulate_text(find_text_);
+ render_view_host()->StartFinding(current_find_request_id_,
+ find_text_,
+ forward_direction,
+ case_sensitive,
+ find_next);
+}
+
+void TabContents::StopFinding(
+ FindBarController::SelectionAction selection_action) {
+ if (selection_action == FindBarController::kClearSelection) {
+ // kClearSelection means the find string has been cleared by the user, but
+ // the UI has not been dismissed. In that case we want to clear the
+ // previously remembered search (http://crbug.com/42639).
+ previous_find_text_ = string16();
+ } else {
+ find_ui_active_ = false;
+ if (!find_text_.empty())
+ previous_find_text_ = find_text_;
+ }
+ find_text_.clear();
+ find_op_aborted_ = true;
+ last_search_result_ = FindNotificationDetails();
+ render_view_host()->StopFinding(selection_action);
+}
+
void TabContents::OnSavePage() {
// If we can not save the page, try to download it.
if (!SavePackage::IsSavableContents(contents_mime_type())) {
@@ -2092,6 +2171,46 @@ void TabContents::GenerateKeywordIfNecessary(
url_model->Add(new_url);
}
+void TabContents::OnFindReply(int request_id,
+ int number_of_matches,
+ const gfx::Rect& selection_rect,
+ int active_match_ordinal,
+ bool final_update) {
+ // Ignore responses for requests that have been aborted.
+ // Ignore responses for requests other than the one we have most recently
+ // issued. That way we won't act on stale results when the user has
+ // already typed in another query.
+ if (!find_op_aborted_ && request_id == current_find_request_id_) {
+ if (number_of_matches == -1)
+ number_of_matches = last_search_result_.number_of_matches();
+ if (active_match_ordinal == -1)
+ active_match_ordinal = last_search_result_.active_match_ordinal();
+
+ gfx::Rect selection = selection_rect;
+ if (selection.IsEmpty())
+ selection = last_search_result_.selection_rect();
+
+ // Notify the UI, automation and any other observers that a find result was
+ // found.
+ last_search_result_ = FindNotificationDetails(
+ request_id, number_of_matches, selection, active_match_ordinal,
+ final_update);
+ NotificationService::current()->Notify(
+ NotificationType::FIND_RESULT_AVAILABLE,
+ Source<TabContents>(this),
+ Details<FindNotificationDetails>(&last_search_result_));
+ }
+
+ // Send a notification to the renderer that we are ready to receive more
+ // results from the scoping effort of the Find operation. The FindInPage
+ // scoping is asynchronous and periodically sends results back up to the
+ // browser using IPC. In an effort to not spam the browser we have the
+ // browser send an ACK for each FindReply message and have the renderer
+ // queue up the latest status message while waiting for this ACK.
+ render_view_host()->Send(new ViewMsg_FindReplyACK(
+ render_view_host()->routing_id()));
+}
+
void TabContents::OnGoToEntryAtOffset(int offset) {
if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
NavigationEntry* entry = controller_.GetEntryAtOffset(offset);