summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/find_backend_unittest.cc28
-rw-r--r--chrome/browser/find_bar_controller.cc7
-rw-r--r--chrome/browser/find_bar_host_browsertest.cc132
-rw-r--r--chrome/browser/find_bar_state.cc20
-rw-r--r--chrome/browser/find_bar_state.h40
-rw-r--r--chrome/browser/profile.cc18
-rw-r--r--chrome/browser/profile.h7
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc16
-rw-r--r--chrome/browser/tab_contents/tab_contents.h9
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/test/testing_profile.h9
11 files changed, 249 insertions, 39 deletions
diff --git a/chrome/browser/find_backend_unittest.cc b/chrome/browser/find_backend_unittest.cc
index e00e3e9..b927b35 100644
--- a/chrome/browser/find_backend_unittest.cc
+++ b/chrome/browser/find_backend_unittest.cc
@@ -2,26 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/string16.h"
#include "base/string_util.h"
+#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/common/url_constants.h"
typedef RenderViewHostTestHarness FindBackendTest;
+namespace {
+
+string16 FindPrepopulateText(TabContents* contents) {
+ return FindBarState::GetLastPrepopulateText(contents->profile());
+}
+
+} // end namespace
+
// This test takes two TabContents objects, searches in both of them and
// tests the internal state for find_text and find_prepopulate_text.
TEST_F(FindBackendTest, InternalState) {
// Initial state for the TabContents is blank strings.
- EXPECT_EQ(string16(), contents()->find_prepopulate_text());
+ EXPECT_EQ(string16(), FindPrepopulateText(contents()));
EXPECT_EQ(string16(), contents()->find_text());
// Get another TabContents object ready.
TestTabContents contents2(profile_.get(), NULL);
// No search has still been issued, strings should be blank.
- EXPECT_EQ(string16(), contents()->find_prepopulate_text());
+ EXPECT_EQ(string16(), FindPrepopulateText(contents()));
EXPECT_EQ(string16(), contents()->find_text());
- EXPECT_EQ(string16(), contents2.find_prepopulate_text());
+ EXPECT_EQ(string16(), FindPrepopulateText(&contents2));
EXPECT_EQ(string16(), contents2.find_text());
string16 search_term1 = ASCIIToUTF16(" I had a 401K ");
@@ -34,9 +44,9 @@ TEST_F(FindBackendTest, InternalState) {
// Pre-populate string should always match between the two, but find_text
// should not.
- EXPECT_EQ(search_term1, contents()->find_prepopulate_text());
+ EXPECT_EQ(search_term1, FindPrepopulateText(contents()));
EXPECT_EQ(search_term1, contents()->find_text());
- EXPECT_EQ(search_term1, contents2.find_prepopulate_text());
+ EXPECT_EQ(search_term1, FindPrepopulateText(&contents2));
EXPECT_EQ(string16(), contents2.find_text());
// Now search in the other TabContents, searching forwards but not case
@@ -45,9 +55,9 @@ TEST_F(FindBackendTest, InternalState) {
// Again, pre-populate string should always match between the two, but
// find_text should not.
- EXPECT_EQ(search_term2, contents()->find_prepopulate_text());
+ EXPECT_EQ(search_term2, FindPrepopulateText(contents()));
EXPECT_EQ(search_term1, contents()->find_text());
- EXPECT_EQ(search_term2, contents2.find_prepopulate_text());
+ EXPECT_EQ(search_term2, FindPrepopulateText(&contents2));
EXPECT_EQ(search_term2, contents2.find_text());
// Search again in the first TabContents, searching forwards but not case
@@ -56,8 +66,8 @@ TEST_F(FindBackendTest, InternalState) {
// Once more, pre-populate string should always match between the two, but
// find_text should not.
- EXPECT_EQ(search_term3, contents()->find_prepopulate_text());
+ EXPECT_EQ(search_term3, FindPrepopulateText(contents()));
EXPECT_EQ(search_term3, contents()->find_text());
- EXPECT_EQ(search_term3, contents2.find_prepopulate_text());
+ EXPECT_EQ(search_term3, FindPrepopulateText(&contents2));
EXPECT_EQ(search_term2, contents2.find_text());
}
diff --git a/chrome/browser/find_bar_controller.cc b/chrome/browser/find_bar_controller.cc
index 643e777..954cab9 100644
--- a/chrome/browser/find_bar_controller.cc
+++ b/chrome/browser/find_bar_controller.cc
@@ -7,6 +7,7 @@
#include "base/i18n/rtl.h"
#include "build/build_config.h"
#include "chrome/browser/find_bar.h"
+#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/notification_service.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -202,8 +203,10 @@ void FindBarController::MaybeSetPrepopulateText() {
string16 find_string = tab_contents_->find_text();
if (find_string.empty())
find_string = tab_contents_->previous_find_text();
- if (find_string.empty())
- find_string = tab_contents_->find_prepopulate_text();
+ if (find_string.empty()) {
+ find_string =
+ FindBarState::GetLastPrepopulateText(tab_contents_->profile());
+ }
// Update the find bar with existing results and search text, regardless of
// whether or not the find bar is visible, so that if it's subsequently
diff --git a/chrome/browser/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc
index d168e7e..2d6bd00 100644
--- a/chrome/browser/find_bar_host_browsertest.cc
+++ b/chrome/browser/find_bar_host_browsertest.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/find_bar.h"
#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/find_notification_details.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
@@ -63,25 +64,39 @@ class FindInPageControllerTest : public InProcessBrowserTest {
}
protected:
- bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) {
+ bool GetFindBarWindowInfoForBrowser(
+ Browser* browser, gfx::Point* position, bool* fully_visible) {
FindBarTesting* find_bar =
- browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
+ browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetFindBarWindowInfo(position, fully_visible);
}
- string16 GetFindBarText() {
+ bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) {
+ return GetFindBarWindowInfoForBrowser(browser(), position, fully_visible);
+ }
+
+ string16 GetFindBarTextForBrowser(Browser* browser) {
FindBarTesting* find_bar =
- browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
+ browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetFindText();
}
- void EnsureFindBoxOpen() {
- browser()->ShowFindBar();
+ string16 GetFindBarText() {
+ return GetFindBarTextForBrowser(browser());
+ }
+
+ void EnsureFindBoxOpenForBrowser(Browser* browser) {
+ browser->ShowFindBar();
gfx::Point position;
bool fully_visible = false;
- EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
+ EXPECT_TRUE(GetFindBarWindowInfoForBrowser(
+ browser, &position, &fully_visible));
EXPECT_TRUE(fully_visible);
}
+
+ void EnsureFindBoxOpen() {
+ EnsureFindBoxOpenForBrowser(browser());
+ }
};
// Platform independent FindInPage that takes |const wchar_t*|
@@ -99,6 +114,7 @@ int FindInPageWchar(TabContents* tab,
// This test loads a page with frames and starts FindInPage requests.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our frames page.
GURL url = server->TestServerPageW(kFramePage);
@@ -191,6 +207,7 @@ std::string FocusedOnPage(TabContents* tab_contents) {
// focused).
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our special focus tracking page.
GURL url = server->TestServerPageW(kEndState);
@@ -238,6 +255,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
// sense as we FindNext over all the items.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kFrameData);
@@ -277,6 +295,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) {
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
SelectChangesOrdinal_Issue20883) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our test content.
GURL url = server->TestServerPageW(kSelectChangesOrdinal);
@@ -316,6 +335,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// sense.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kFramePage);
@@ -367,6 +387,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
// See http://crbug.com/5132.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kFramePage);
@@ -397,6 +418,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
// Load a page with no selectable text and make sure we don't crash.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kUserSelectPage);
@@ -415,6 +437,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) {
// Try to reproduce the crash seen in issue 1341577.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kCrashPage);
@@ -447,6 +470,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) {
// hits in the BitStack size comparison in WebKit.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kBitstackCrash);
@@ -469,6 +493,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) {
// again from where it left off).
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our page.
GURL url = server->TestServerPageW(kTooFewMatchesPage);
@@ -488,6 +513,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) {
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
DISABLED_FindInPagePrematureEnd) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our special focus tracking page.
GURL url = server->TestServerPageW(kPrematureEnd);
@@ -505,6 +531,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our special focus tracking page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -539,6 +566,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
FindDisappearOnNewTabAndHistory) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our special focus tracking page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -586,6 +614,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Make sure Find box moves out of the way if it is obscuring the active match.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FindMovesWhenObscuring) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
GURL url = server->TestServerPageW(kMoveIfOver);
ui_test_utils::NavigateToURL(browser(), url);
@@ -638,6 +667,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FindMovesWhenObscuring) {
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
FindNextInNewTabUsesPrepopulate) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -684,6 +714,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
#endif
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -736,6 +767,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// we switch to a tab contents with an empty find string. See issue 13570.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -760,6 +792,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
// session. See issue http://crbug.com/28306.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to a simple page.
GURL url = server->TestServerPageW(kSimple);
@@ -794,6 +827,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
#endif
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimplePage);
@@ -832,12 +866,13 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
#endif
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
- // Find the word "page".
+ // Search for the word "page".
int ordinal = 0;
TabContents* tab1 = browser()->GetSelectedTabContents();
EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
@@ -869,12 +904,13 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) {
#endif
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
- // Find the word "page".
+ // Search for the word "page".
int ordinal = 0;
TabContents* tab1 = browser()->GetSelectedTabContents();
EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
@@ -904,12 +940,13 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
#endif
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
- // Find the word "page".
+ // Search for the word "page".
int ordinal = 0;
TabContents* tab1 = browser()->GetSelectedTabContents();
EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
@@ -930,7 +967,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
TabContents* tab2 = browser()->GetSelectedTabContents();
EXPECT_NE(tab1, tab2);
- // Find "text".
+ // Search for the word "text".
FindInPageWchar(tab2, L"text", kFwd, kIgnoreCase, &ordinal);
// Go back to the first tab and make sure we have NOT switched the prepopulate
@@ -959,9 +996,82 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
}
+// TODO(rohitrao): Searching in incognito tabs does not work in browser tests in
+// linux views. Investigate and fix. http://crbug.com/40948
+#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
+#define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate
+#else
+#define MAYBE_NoIncognitoPrepopulate NoIncognitoPrepopulate
+#endif
+
+// This tests that search terms entered into an incognito find bar are not used
+// as prepopulate terms for non-incognito windows.
+IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) {
+#if defined(OS_MACOSX)
+ // FindInPage on Mac doesn't use prepopulated values. Search there is global.
+ return;
+#endif
+
+ HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
+
+ // First we navigate to the "simple" test page.
+ GURL url = server->TestServerPageW(kSimple);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // Search for the word "page" in the normal browser tab.
+ int ordinal = 0;
+ TabContents* tab1 = browser()->GetSelectedTabContents();
+ EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal));
+
+ // Open the Find box.
+ EnsureFindBoxOpenForBrowser(browser());
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
+
+ // Close the Find box.
+ browser()->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
+
+ // Open a new incognito window and navigate to the same page.
+ Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
+ Browser* incognito_browser = Browser::Create(incognito_profile);
+ incognito_browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE,
+ true, -1, false, NULL);
+ ui_test_utils::WaitForNavigation(
+ &incognito_browser->GetSelectedTabContents()->controller());
+ incognito_browser->window()->Show();
+
+ // Open the find box and make sure that it is prepopulated with "page".
+ EnsureFindBoxOpenForBrowser(incognito_browser);
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser));
+
+ // Search for the word "text" in the incognito tab.
+ TabContents* incognito_tab = incognito_browser->GetSelectedTabContents();
+ EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text",
+ kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser));
+
+ // Close the Find box.
+ incognito_browser->GetFindBarController()->EndFindSession(
+ FindBarController::kKeepSelection);
+
+ // Now open a new tab in the original (non-incognito) browser.
+ browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1,
+ false, NULL);
+ browser()->SelectTabContentsAt(1, false);
+ TabContents* tab2 = browser()->GetSelectedTabContents();
+ EXPECT_NE(tab1, tab2);
+
+ // Open the Find box and make sure it is prepopulated with the search term
+ // from the original browser, not the search term from the incognito window.
+ EnsureFindBoxOpenForBrowser(browser());
+ EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
+}
+
// This makes sure that dismissing the find bar with kActivateSelection works.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server);
// First we navigate to our test content.
GURL url = server->TestServerPageW(kLinkPage);
diff --git a/chrome/browser/find_bar_state.cc b/chrome/browser/find_bar_state.cc
new file mode 100644
index 0000000..d33d104
--- /dev/null
+++ b/chrome/browser/find_bar_state.cc
@@ -0,0 +1,20 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/browser/find_bar_state.h"
+#include "chrome/browser/profile.h"
+
+// static
+string16 FindBarState::GetLastPrepopulateText(Profile* p) {
+ FindBarState* state = p->GetFindBarState();
+ string16 text = state->last_prepopulate_text();
+
+ if (text.empty() && p->IsOffTheRecord()) {
+ // Fall back to the original profile.
+ state = p->GetOriginalProfile()->GetFindBarState();
+ text = state->last_prepopulate_text();
+ }
+
+ return text;
+}
diff --git a/chrome/browser/find_bar_state.h b/chrome/browser/find_bar_state.h
new file mode 100644
index 0000000..026caac
--- /dev/null
+++ b/chrome/browser/find_bar_state.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2010 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.
+
+// Stores per-profile state needed for find in page. This includes the most
+// recently searched for term.
+
+#ifndef CHROME_BROWSER_FIND_BAR_STATE_H_
+#define CHROME_BROWSER_FIND_BAR_STATE_H_
+
+#include "base/basictypes.h"
+#include "base/string16.h"
+
+class Profile;
+
+class FindBarState {
+ public:
+ FindBarState() {}
+ ~FindBarState() {}
+
+ string16 last_prepopulate_text() const {
+ return last_prepopulate_text_;
+ }
+
+ void set_last_prepopulate_text(const string16 text) {
+ last_prepopulate_text_ = text;
+ }
+
+ // Retrieves the last prepopulate text for a given Profile. If the profile is
+ // off the record and has an empty prepopulate text, falls back to the
+ // prepopulate text from the normal profile.
+ static string16 GetLastPrepopulateText(Profile* profile);
+
+ private:
+ string16 last_prepopulate_text_;
+
+ DISALLOW_COPY_AND_ASSIGN(FindBarState);
+};
+
+#endif // CHROME_BROWSER_FIND_BAR_STATE_H_
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index f1593ae..83b2ad3e 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/user_script_master.h"
#include "chrome/browser/favicon_service.h"
+#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/transport_security_persister.h"
@@ -454,6 +455,12 @@ class OffTheRecordProfileImpl : public Profile,
return profile_->GetUserStyleSheetWatcher();
}
+ virtual FindBarState* GetFindBarState() {
+ if (!find_bar_state_.get())
+ find_bar_state_.reset(new FindBarState());
+ return find_bar_state_.get();
+ }
+
virtual SessionService* GetSessionService() {
// Don't save any sessions when off the record.
return NULL;
@@ -585,6 +592,10 @@ class OffTheRecordProfileImpl : public Profile,
// the user visited while OTR.
scoped_ptr<SSLHostState> ssl_host_state_;
+ // Use a separate FindBarState so search terms do not leak back to the main
+ // profile.
+ scoped_ptr<FindBarState> find_bar_state_;
+
// The TransportSecurityState that only stores enabled sites in memory.
scoped_refptr<net::TransportSecurityState>
transport_security_state_;
@@ -1083,6 +1094,13 @@ UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() {
return user_style_sheet_watcher_.get();
}
+FindBarState* ProfileImpl::GetFindBarState() {
+ if (!find_bar_state_.get()) {
+ find_bar_state_.reset(new FindBarState());
+ }
+ return find_bar_state_.get();
+}
+
HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) {
if (!history_service_created_) {
history_service_created_ = true;
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 15cb97a..feee692 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -43,6 +43,7 @@ class ExtensionProcessManager;
class ExtensionMessageService;
class ExtensionsService;
class FaviconService;
+class FindBarState;
class GeolocationContentSettingsMap;
class HistoryService;
class HostContentSettingsMap;
@@ -319,6 +320,10 @@ class Profile {
// Returns the user style sheet watcher.
virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() = 0;
+ // Returns the find bar state for this profile. The find bar state is lazily
+ // created the first time that this method is called.
+ virtual FindBarState* GetFindBarState() = 0;
+
// Returns the session service for this profile. This may return NULL. If
// this profile supports a session service (it isn't off the record), and
// the session service hasn't yet been created, this forces creation of
@@ -491,6 +496,7 @@ class ProfileImpl : public Profile,
virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap();
virtual Blacklist* GetPrivacyBlacklist();
virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher();
+ virtual FindBarState* GetFindBarState();
virtual SessionService* GetSessionService();
virtual void ShutdownSessionService();
virtual bool HasSessionService() const;
@@ -580,6 +586,7 @@ class ProfileImpl : public Profile,
geolocation_content_settings_map_;
scoped_refptr<Blacklist> privacy_blacklist_;
scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher_;
+ scoped_ptr<FindBarState> find_bar_state_;
scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<HistoryService> history_service_;
scoped_refptr<FaviconService> favicon_service_;
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 27d67ec..0b64c05 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -32,6 +32,7 @@
#include "chrome/browser/external_protocol_handler.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/favicon_service.h"
+#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/google_util.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/hung_renderer_dialog.h"
@@ -270,7 +271,6 @@ TabContents::TabContents(Profile* profile,
find_op_aborted_(false),
current_find_request_id_(find_request_id_counter_++),
last_search_case_sensitive_(false),
- last_search_prepopulate_text_(NULL),
last_search_result_(),
app_extension_(NULL),
app_extension_for_current_page_(NULL),
@@ -341,10 +341,6 @@ TabContents::TabContents(Profile* profile,
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
NotificationService::AllSources());
- // Keep a global copy of the previous search string (if any).
- static string16 global_last_search = string16();
- last_search_prepopulate_text_ = &global_last_search;
-
// Set-up the showing of the omnibox search infobar if applicable.
if (OmniboxSearchHint::IsEnabled(profile))
omnibox_search_hint_.reset(new OmniboxSearchHint(this));
@@ -1142,12 +1138,15 @@ void TabContents::StartFinding(string16 search_string,
// 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 if (!last_search_prepopulate_text.empty())
+ search_string = last_search_prepopulate_text;
else
return;
}
@@ -1174,7 +1173,8 @@ void TabContents::StartFinding(string16 search_string,
find_op_aborted_ = false;
// Keep track of what the last search was across the tabs.
- *last_search_prepopulate_text_ = find_text_;
+ 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,
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 123157d..902e61e 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -557,12 +557,6 @@ class TabContents : public PageNavigator,
// Accessor for the previous search we issued.
string16 previous_find_text() const { return previous_find_text_; }
- // Accessor for last_search_prepopulate_text_. Used to access the last search
- // string entered, whatever tab that search was performed in.
- string16 find_prepopulate_text() const {
- return *last_search_prepopulate_text_;
- }
-
// Accessor for find_result_.
const FindNotificationDetails& find_result() const {
return last_search_result_;
@@ -1171,9 +1165,6 @@ class TabContents : public PageNavigator,
// Whether the last search was case sensitive or not.
bool last_search_case_sensitive_;
- // Keeps track of the last search string that was used to search in any tab.
- string16* last_search_prepopulate_text_;
-
// The last find result. This object contains details about the number of
// matches, the find selection rectangle, etc. The UI can access this
// information to build its presentation.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 715fc39..c8ff9e8 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1095,6 +1095,8 @@
'browser/find_bar.h',
'browser/find_bar_controller.cc',
'browser/find_bar_controller.h',
+ 'browser/find_bar_state.h',
+ 'browser/find_bar_state.cc',
'browser/find_notification_details.h',
'browser/first_run.cc',
'browser/first_run.h',
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 2099948..814d8b9 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -13,6 +13,7 @@
#include "chrome/browser/browser_prefs.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/favicon_service.h"
+#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/history/history.h"
@@ -186,6 +187,11 @@ class TestingProfile : public Profile {
virtual net::SSLConfigService* GetSSLConfigService() { return NULL; }
virtual Blacklist* GetPrivacyBlacklist() { return NULL; }
virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() { return NULL; }
+ virtual FindBarState* GetFindBarState() {
+ if (!find_bar_state_.get())
+ find_bar_state_.reset(new FindBarState());
+ return find_bar_state_.get();
+ }
virtual HostContentSettingsMap* GetHostContentSettingsMap() {
if (!host_content_settings_map_.get())
host_content_settings_map_ = new HostContentSettingsMap(this);
@@ -326,6 +332,9 @@ class TestingProfile : public Profile {
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
scoped_refptr<GeolocationContentSettingsMap>
geolocation_content_settings_map_;
+
+ // Find bar state. Created lazily by GetFindBarState().
+ scoped_ptr<FindBarState> find_bar_state_;
};
// A profile that derives from another profile. This does not actually