Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear browsing data on exit. #1213

Merged
merged 1 commit into from
Mar 1, 2019
Merged

Conversation

mkarolin
Copy link
Collaborator

@mkarolin mkarolin commented Jan 4, 2019

Fixes brave/brave-browser#492

  1. Adds a new "On exit" tab to chrome://settings/clearBrowserData dialog
    with the same options as on the "Advanced" tab and a "Save" button. By
    default all "On exit" options are turned off. When an option is modified
    from the current state the Save button becomes enabled and allows the
    user to save the "on exit" options. The options are saved to profile's
    preferences: new *OnExit preferences have been added for each option.

  2. Clear browsing data on exit functionality is triggered from
    BraveBrowserMainParts::PreShutdown overrides. For each loaded profile
    the code checks if user selected any on exit options and if so then a
    BrowsingDataRemover is called.

  3. Adds BraveClearDataOnExitTest and BraveClearDataOnExitTwoBrowsersTest
    browser tests that verify that:

  • the removal of the browsing data is triggered only when an "on exit"
    preference is set;
  • the removal flags are constrcuted correctly;
  • the removal is called only when the browser is exiting (tests with
    OTR/Guest/multiple profiles).

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

Automated tests:
npm run test -- brave_browser_tests --filter=BraveClearDataOnExitTest.*
npm run test -- brave_browser_tests --filter=BraveClearDataOnExitTwoBrowsersTest.*

Manual tests:

1. Verify browsing history removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Browsing History" box,
  • Navigate to brave://history/ and verify that it's empty,
  • In a new tab, navigate to any site (e.g. https://example.com),
  • Wait for the site to load, then close the tab,
  • Back in the brave://history/ tab, reload the page and verify that an entry for the site has appeared,
  • Exit Brave browser,
  • Start Brave browser again,
  • Navigate to brave://history/ and verify that it's empty.

2. Verify downloads history removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Download History" box,
  • Navigate to brave://downloads/ and verify that it's empty,
  • In a new tab, navigate to any site (e.g. https://example.com),
  • Wait for the site to load, right-click on the page and select Save As..., save the page and wait for the download to complete; then close the tab,
  • Back in the brave://downloads/ tab, reload the page and verify that an entry for the site has appeared,
  • Exit Brave browser,
  • Start Brave browser again,
  • Navigate to brave://downloads/ and verify that it's empty.

3. Verify cookies removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Cookies and other site data" box,
  • Navigate to brave://settings/siteData and verify that it's empty,
  • In a new tab, navigate to any site that uses cookies (e.g. https://google.com),
  • Wait for the site to load, then close the tab,
  • Back in the brave://settings/siteData tab, reload the page and verify that entries for the site have appeared (cookies and possibly local storage),
  • Exit Brave browser,
  • Start Brave browser again,
  • Navigate to brave://settings/siteData and verify that it's empty. Note: on Linux, while cookies should be gone, the local storage will remain - this is not specific to clearing data on exit and behaves the same way when clearing data from the Advanced tab of Clear Browsing Data dialog.

4. Verify cache removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Cached images and files" box,
  • Open cache location in the file system (for example, on Windows in C:\Users_yourusername_\AppData\Local\BraveSoftware\Brave-Browser[-Dev|Beta]\User Data\Default\Cache)
  • In Brave, in a new tab, navigate to any site (e.g. https://example.com),
  • Wait for the site to load, then close the tab,
  • Verify that new cache file(s) is create in the cache file system folder (typically starts with f_),
  • Exit Brave browser,
  • Verify that cache file(s) created in the cache file system folder in the above step have been removed.

Alternatively, on Windows you can use NirSoft's ChromeCacheView and point it to Brave's cache, verify the cache content before exiting the browser and after.

5. Verify passwords removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Passwords and other sign-in data" box,
  • Navigate to brave://settings/passwords and verify that the Saved Passwords list is empty,
  • In a new tab, navigate to any site that requires signing-in (e.g. https://hotmail.com),
  • Sign in and when a popup shows offering to save the site password agree to do so,
  • Back in the brave://settings/passwords tab, reload the page and verify that an entry for the site has appeared in the Saved Passwords list,
  • Exit Brave browser,
  • Start Brave browser again,
  • Navigate to brave://settings/passwords and verify that the Saved Passwords list is empty.

6. Verify autofill form data removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Autofill form data" box,
  • Navigate to brave://settings/payments and verify that the Payment methods list is empty,
  • Add a payment method and verify that it shows in the list,
  • Exit Brave browser,
  • Start Brave browser again,
  • Navigate to brave://settings/payments and verify that the Payment methods list is empty.

7. Verify content settings removal.

  • Start Brave browser with a clean profile,
  • Navigate to brave://settings/clearBrowserData, select "On exit" tab, check "Content settings" box,
  • Navigate to one or more of the content setting pages, for example, brave://settings/content/javascript and verify that the Block list is empty,
  • Add a site to the Block list and verify that it shows in the list,
  • Exit Brave browser,
  • Start Brave browser again,
  • Navigate to brave://settings/content/javascript and verify that the Block list is empty.

Note: this will also clear out per site Brave Shields settings.

8. Test that clearing data on exit and manually produce the same results (suggested by @fmarier, thx!)

  1. Create a new profile and start the browser.
  2. Wait 5 minutes and close the browser.
  3. Make a copy ("original") of the profile directory.
  4. Open the browser again, navigate to a site where you can login and save the password.
  5. Add a payment method.
  6. Go to a site to trigger a download.
  7. Add a site to the block list.
  8. Set "clear everything on exit".
  9. Close the browser.
  10. Diff the new profile directory with the original one (e.g. diff -Nurd original/ autocleared/ on Linux).
  11. Repeat Steps 1-10 but instead of using "clear on exit", do a manual "clear everything".
  12. Close the browser and diff that third profile with the other two.

This will allow us to:

  • see what residues are left after auto-clearing, and
  • confirm that auto-clearing is just as effective as manually clearing everything.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@mkarolin mkarolin self-assigned this Jan 4, 2019
@mkarolin mkarolin force-pushed the maxk-clear-browsing-data-on-exit branch 4 times, most recently from 250044f to edd9a56 Compare January 7, 2019 20:31
@mkarolin mkarolin changed the title WIP: Clear browsing data on exit. Clear browsing data on exit. Jan 7, 2019
@mkarolin mkarolin changed the title Clear browsing data on exit. WIP: Clear browsing data on exit. Jan 15, 2019
@mkarolin mkarolin force-pushed the maxk-clear-browsing-data-on-exit branch 4 times, most recently from dc1098f to a74e5cd Compare January 24, 2019 23:37
browser/BUILD.gn Outdated
@@ -11,8 +11,18 @@ source_set("browser_process") {
"bookmarks/brave_bookmark_client.h",
"brave_browser_main_extra_parts.cc",
"brave_browser_main_extra_parts.h",
"brave_browser_main_parts.cc",
"brave_browser_main_parts.h",
"brave_browser_main_parts_android.cc",
Copy link
Collaborator

@bridiver bridiver Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need all of these brave_browser_main_parts_os files because none of them implement PreShutdown

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChromeBrowserMainParts inherit from ChromeBrowserMainParts (except Linux and Mac which both inherit from Posix). If I just subclass ChromeBrowserMainParts I would still have to change ChromeBrowserMainParts<Win,Android,Posix> to inherit from the new subclass (see instantiation in https://cs.chromium.org/chromium/src/chrome/browser/chrome_content_browser_client.cc?l=1150).
Also, while none of them override PreShutdown now I am not sure we can depend on it staying this way or, if they do override, that they'd call the base class implementation.


int num_profiles_to_clear_ = 0;
base::RunLoop run_loop_;
ScopedObserver<content::BrowsingDataRemover,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused. The is a subclass of content::BrowsingDataRemover::Observer, but also has an internal ScopedObserver for content::BrowsingDataRemover::Observer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am following the patter suggested in the comment here: https://cs.chromium.org/chromium/src/content/public/browser/browsing_data_remover.h?l=41 but delegating keeping track of content::BrowsingDataRemover for each profile to ScopedObserver.

@mkarolin mkarolin force-pushed the maxk-clear-browsing-data-on-exit branch 2 times, most recently from a55cd20 to 3fc55a9 Compare February 2, 2019 00:58
@mkarolin mkarolin changed the title WIP: Clear browsing data on exit. Clear browsing data on exit. Feb 5, 2019
@diracdeltas
Copy link
Member

Please open a security review issue for this when ready, thanks.

@mkarolin mkarolin force-pushed the maxk-clear-browsing-data-on-exit branch from 5982a91 to bf99490 Compare February 28, 2019 00:53
@petemill
Copy link
Member

The checkboxes in the dialog don't seem to be remembering state for me. But the save button knows that the state (with the boxes unchecked) is different to what is saved. i.e.:

  1. Open the dialog to the 'On exit' tab, tick "Passwords and other sign-in data"
  2. Click Save
  3. Close tab and open settings again
  4. Open the dialog again to the 'On exit' tab.
    Problem:
  • "Passwords and other sign-in data is not ticked"

@petemill
Copy link
Member

Looks like it works on Debug builds but not Release build. Confirming...

@mkarolin
Copy link
Collaborator Author

Just built Release, seems to be working for me.

@petemill
Copy link
Member

sorry @mkarolin false alarm on both fronts it seems. I can't replicate the issue I had with the checkboxes either 🤷‍♂️

petemill
petemill previously approved these changes Feb 28, 2019
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI changes in settings are great. Thanks for looking at the minimized patching. After discussing again with @bridiver I have some improvements to make this and some other settings modifications 0-patch, but I'll do that in a follow-up.

bsclifton
bsclifton previously approved these changes Feb 28, 2019
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great 😄

// static
void BraveClearBrowsingData::ClearOnExit() {
TRACE_EVENT0("browser", "BraveClearBrowsingData::ClearOnExit");
// Do not clear browsing data when the OS is ending session (logout/reboot/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, it would be nice to document this somewhere that's user-visible. If it's too much information for the UI, maybe a page on support.brave.com?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@bsclifton bsclifton Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmarier support.brave.com might not be the right audience for that- but we can definitely document custom trace events in our wiki. @mkarolin I created a stub page, if you wanted to add that (and describe why you'd use it):
https://github.com/brave/brave-browser/wiki/Custom-tracing-events

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bsclifton, I understood it that @fmarier was referring to the comment that we are not clearing browsing data on logout/reboot/shutdown.

Copy link
Member

@bsclifton bsclifton Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkarolin ah- LOL; that makes a lot more sense 😂

cc'ing @Brave-Matt on that one - would be great to document this feature in general 😄 @Brave-Matt: this would be something we're planning for 0.63.x

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I was referring to was not the trace events, but the limitation that if you shutdown your computer, it won't clear your history.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very bad limitation, which would probably surprise a lot of people who use the feature. IMO, we should back this out and fix that problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @rebron for the above comment by @tomlowenthal ^^

We may want to compare with Muon- it's possible Muon had that same limitation also. If the current experience is WORSE than Muon (ex: Muon works as expected), then I definitely agree that we should consider hiding this new UI until that problem is resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomlowenthal should brave/brave-browser#3549 cover this use-case also?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that issue is intended to be the new partial fix for this… someday.

}

int GetRemoveMaskAll() {
return ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should "Hosted App Data" be included here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Hosted App Data" is defined as a combination of mask = ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA and origin = content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, so it should be already accounted for.

@fmarier
Copy link
Member

fmarier commented Feb 28, 2019

I noticed that "Media licences" is missing from the list of things that can be cleared on shutdown, even though it's part of the Advanced tab. Is that intentional?

@mkarolin
Copy link
Collaborator Author

mkarolin commented Feb 28, 2019

I noticed that "Media licences" is missing from the list of things that can be cleared on shutdown, even though it's part of the Advanced tab. Is that intentional?

@fmarier, "Media licenses" is no longer a part of the Advanced tab in Chromium:

commit 3dece3d74d88a717a3a1e77eea8916e48847d8e8
Author: John Rummell
Date:   Thu Jan 10 00:34:57 2019 +0000
Remove "Media Licenses" from Clear Browsing Data dialog
Media licenses will now be deleted when "Cookies and site data" is selected.
BUG=901993

#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "components/browsing_data/core/pref_names.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Fixes brave/brave-browser#492

1. Adds a new "On exit" tab to chrome://settings/clearBrowserData dialog
with the same options as on the "Advanced" tab and a "Save" button. By
default all "On exit" options are turned off. When an option is modified
from the current state the Save button becomes enabled and allows the
user to save the "on exit" options. The options are saved to profile's
preferences: new *OnExit preferences have been added for each option.

2. Clear browsing data on exit functionality is triggered from
BraveBrowserMainParts::PreShutdown override. For each loaded profile
the code checks if user selected any on exit options and if so then a
BrowsingDataRemover is called.

3. Adds BraveClearDataOnExitTest and BraveClearDataOnExitTwoBrowsersTest
browser tests that verify that:
- the removal of the browsing data is triggered only when an "on exit"
  preference is set;
- the removal flags are constrcuted correctly;
- the removal is called only when the browser is exiting (tests with
  OTR/Guest/multiple profiles).
@mkarolin mkarolin dismissed stale reviews from bsclifton and petemill via 02e63a9 March 1, 2019 03:43
@mkarolin mkarolin force-pushed the maxk-clear-browsing-data-on-exit branch from bf99490 to 02e63a9 Compare March 1, 2019 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to clear browsing data on exit