Commit 425e7ab7 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove find in page history when clearing browsing history.

This removes the cached find-in-page value for a profile when that
profile's history data is cleared. Like most data that is deleted along
with DATA_TYPE_HISTORY, the time range is ignored; any time range will
cause the last find-in-page value to be deleted.

The original motivation for this change was to delete some Chrome
dependencies from //chrome/browser/ui/find_bar/, in preparation for
componentization, because it's an alternate way of achieving the
behavior that is being deleted there (wrt clearing FIP for guest
profiles). However it is also a behavioral improvement in that it makes
Clear Browsing Data more comprehensive.

Bug: 1038415, 889642
Change-Id: I429470c4f215e6a2ace29e42c2e8795a2e70daa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1986909Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729915}
parent 4844ce3c
......@@ -63,6 +63,8 @@
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "chrome/browser/ui/find_bar/find_bar_state_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
#include "chrome/common/buildflags.h"
......@@ -639,6 +641,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
#endif
CreateCrashUploadList()->Clear(delete_begin_, delete_end_);
FindBarStateFactory::GetForProfile(profile_)->set_last_prepopulate_text(
base::string16());
}
//////////////////////////////////////////////////////////////////////////////
......
......@@ -24,6 +24,8 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "chrome/browser/ui/find_bar/find_bar_state_factory.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/test/base/in_process_browser_test.h"
......@@ -200,6 +202,38 @@ IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestClearsCookies) {
ASSERT_EQ("", cookie);
}
IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestClearsFindInPageCache) {
Browser* guest_browser = OpenGuestBrowser();
Profile* guest_profile = guest_browser->profile();
base::string16 fip_text =
base::ASCIIToUTF16("first guest session search text");
FindBarStateFactory::GetForProfile(guest_profile)
->set_last_prepopulate_text(fip_text);
// Open a second guest window and close one. This should not affect the find
// in page cache as the guest session hasn't been ended.
profiles::FindOrCreateNewWindowForProfile(
guest_profile, chrome::startup::IS_NOT_PROCESS_STARTUP,
chrome::startup::IS_NOT_FIRST_RUN, true /*always_create*/);
CloseBrowserSynchronously(guest_browser);
EXPECT_EQ(fip_text, FindBarStateFactory::GetForProfile(guest_profile)
->last_prepopulate_text());
// Close the remaining guest browser window.
guest_browser = chrome::FindAnyBrowser(guest_profile, true);
EXPECT_TRUE(guest_browser);
CloseBrowserSynchronously(guest_browser);
// Open a new guest browser window. Since this is a separate session, the find
// in page text should have been cleared (along with all other browsing data).
profiles::FindOrCreateNewWindowForProfile(
guest_profile, chrome::startup::IS_NOT_PROCESS_STARTUP,
chrome::startup::IS_NOT_FIRST_RUN, true /*always_create*/);
EXPECT_EQ(base::string16(), FindBarStateFactory::GetForProfile(guest_profile)
->last_prepopulate_text());
}
IN_PROC_BROWSER_TEST_F(ProfileWindowBrowserTest, GuestCannotSignin) {
Browser* guest_browser = OpenGuestBrowser();
......
......@@ -13,10 +13,6 @@
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_state.h"
#include "chrome/browser/ui/find_bar/find_bar_state_factory.h"
......@@ -40,67 +36,13 @@ namespace {
// The minimum space between the FindInPage window and the search result.
constexpr int kMinFindWndDistanceFromSelection = 5;
// Tracks windows and makes sure that closing the last Guest browser window
// clears the find pre-populate text.
class FindBrowserListObserver : public BrowserListObserver {
public:
FindBrowserListObserver() {
BrowserList::AddObserver(this);
}
~FindBrowserListObserver() override { BrowserList::RemoveObserver(this); }
static void EnsureInstance() {
static base::NoDestructor<FindBrowserListObserver> the_instance;
the_instance.get();
}
protected:
// BrowserListObserver:
void OnBrowserRemoved(Browser* browser) override {
Profile* const guest_profile = GetGuestProfile(browser);
if (!guest_profile)
return;
if (IsGuestWindowOpen())
return;
// Remove persistent find text across guest sessions. If we don't do this, a
// future guest session in this browser process might get its find text
// prepopulated with something that was searched in this session, which is a
// violation of privacy expectations.
FindBarState* const find_bar_state =
FindBarStateFactory::GetForProfile(guest_profile);
find_bar_state->set_last_prepopulate_text(base::string16());
}
private:
// Returns a guest profile if the current browser has one, or nullptr
// otherwise.
static Profile* GetGuestProfile(Browser* browser) {
Profile* profile = browser->profile();
DCHECK(profile);
return profile->IsGuestSession() ? profile : nullptr;
}
static bool IsGuestWindowOpen() {
for (Browser* other : *BrowserList::GetInstance()) {
if (GetGuestProfile(other))
return true;
}
return false;
}
};
} // namespace
FindBarController::FindBarController(std::unique_ptr<FindBar> find_bar,
Browser* browser)
: find_bar_(std::move(find_bar)),
browser_(browser),
find_bar_platform_helper_(FindBarPlatformHelper::Create(this)) {
FindBrowserListObserver::EnsureInstance();
}
find_bar_platform_helper_(FindBarPlatformHelper::Create(this)) {}
FindBarController::~FindBarController() {
DCHECK(!web_contents_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment