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

Add setting option for disabling tor component #4046

Merged
merged 6 commits into from
Dec 4, 2019

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Nov 21, 2019

fix brave/brave-browser#6808

When tor is managed by group policy, this option is disabled. (only possible on Windows now)
image

Submitter Checklist:

Test Plan:

yarn test brave_browser_tests --filter=BraveLocalStateBrowserTest*
yarn test brave_browser_tests --filter=TorDisabledPolicyBrowserTest*
yarn test brave_browser_tests --filter=TorEnabledPolicyBrowserTest*
yarn test brave_browser_tests --filter=NoTorPolicyBrowserTest*

Manual test steps

  1. Launch browser with clean profile
  2. Load brave://settings/extensions and check Tor is on by default
  3. Turn it off and Tor menu is not visible in the app menu
  4. Turn it on and Tor menu is visible in the app menu
  5. Open tor window
  6. Turn it off and tor window is still alive
  7. Close opened tor window and check Tor utility process is not visible from task manager.

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

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@simonhong simonhong force-pushed the add_options_for_disabling_tor branch 3 times, most recently from a40dc70 to 576f1d6 Compare November 21, 2019 10:51
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.

Changes look good and work great! As shared here, some of these blocks of settings are getting crowded and could use some organization

There was a lint problem, I just pushed a fix for. All other CI passed fine (only failure besides lint was on Publish xUnit test result report which is fine)

@simonhong
Copy link
Member Author

@bsclifton Thanks for fixing lint error 👍

@simonhong
Copy link
Member Author

@rebron Can you check the this options' title and position?
Also if we want to add sub label, let me know.

@simonhong simonhong force-pushed the add_options_for_disabling_tor branch 2 times, most recently from e55d35d to ee87251 Compare November 22, 2019 08:56
@simonhong
Copy link
Member Author

Friendly ping to owner review @bridiver

void GetTorDisabled(const base::ListValue* args);
void OnTorDisabledChanged();
#endif
void GetEnableTorOption(const base::ListValue* args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this?

Copy link
Member Author

@simonhong simonhong Nov 26, 2019

Choose a reason for hiding this comment

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

This is used to determine whether Disable Tor option should be enabled or not.
If tor is managed by group policy or tor is not built, this setting option should be in disabled state.
Added comment for this method.

Copy link
Collaborator

@bridiver bridiver Nov 28, 2019

Choose a reason for hiding this comment

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

If the tor feature is not included we shouldn't be showing any UI for it at all and we can detect that with the buildflag so we don't need a method for it. For group policy it should be IsTorManaged

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree with you. UI should not be visible if tor is not built.
To do this, I tried to hide settings UI by using template with dom-if.
However, toggle button can't get proper runtime value change if it is inside template.
I debugged this with @bsclifton but can't find solution at that time.
Maybe we need to dig more about polymer.
So, I left like this because we would not build brave w/o tor.
How about this as a f/u?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm trying to find how to hide webui with buildflags.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this into tor buildflags with renamed one.
and tor settings will be hidden by adding enable_tor defines to grit defines.
Much more clear 👍


void GetRestartNeeded(const base::ListValue* args);
void SetWebTorrentEnabled(const base::ListValue* args);
void SetHangoutsEnabled(const base::ListValue* args);
void SetIPFSCompanionEnabled(const base::ListValue* args);
void SetMediaRouterEnabled(const base::ListValue* args);
void SetBraveWalletEnabled(const base::ListValue* args);
#if BUILDFLAG(ENABLE_TOR)
void SetTorDisabled(const base::ListValue* args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use Enabled, not Disabled. It's easier to understand and more consistent with everything else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed that negative expression makes difficult to read/understand.
How about this leave as a f/u?
Just using enabled in this class also could increase complexity because related pref name is kTorDisabled and options name is also Disable Tor. Also some related static methods are IsTorDisabled() and already used by many other places.
I think it would be good to clean this up as a separate PR. WDYT?

Copy link
Member Author

@simonhong simonhong Nov 26, 2019

Choose a reason for hiding this comment

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

@bridiver, Changed to Enabled as settings text is changed to enabled meaning.

@@ -23,15 +25,23 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler {
private:
// SettingsPageUIHandler overrides:
void RegisterMessages() override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
void OnJavascriptAllowed() override {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are you defining these as empty methods? What's the point of overriding them if we're not going to implement them?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because they are pure virtual method in base class.

@@ -149,6 +149,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_IPFS_COMPANION_ENABLED_DESC},
{"mediaRouterEnabledDesc",
IDS_SETTINGS_MEDIA_ROUTER_ENABLED_DESC},
{"torDisabledLabel",
Copy link
Collaborator

@bridiver bridiver Nov 25, 2019

Choose a reason for hiding this comment

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

same as above disabled -> enabled. It is almost always better to use the "positive" form for readability

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@rebron
Copy link
Collaborator

rebron commented Nov 26, 2019

cc: @TomL for final text. Instead of Disable Tor I'd go withPrivate Window with Tor and then description Tor hides your IP address from the sites you visit.

@simonhong simonhong added the CI/skip Do not run CI builds (except noplatform) label Dec 3, 2019
@simonhong simonhong force-pushed the add_options_for_disabling_tor branch from 227578c to d127206 Compare December 3, 2019 02:16

void BraveBrowserProcessImpl::OnTorEnabledChanged() {
// Update all browsers' tor command status.
for (Browser* browser : *BrowserList::GetInstance()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

When tor option is changed, all browsers' tor commands are updated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

does the utility process automatically shut down when all tor windows are closed?

Copy link
Member Author

Choose a reason for hiding this comment

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

In nightly, tor process is gone. but not in stable version.

@simonhong simonhong force-pushed the add_options_for_disabling_tor branch 2 times, most recently from 9b49d20 to 768f6ec Compare December 3, 2019 03:02
@@ -57,6 +57,10 @@

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/extensions/brave_tor_client_updater.h"
#include "brave/browser/ui/brave_browser_command_controller.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

even though these are only used when tor is enabled, I still think it's a bad idea to put them in this guard because in the future other things may use these same header files and people may not move them out of the ENABLE_TOR block when that happens. I think only tor header files should go in here.

Copy link
Member Author

@simonhong simonhong Dec 3, 2019

Choose a reason for hiding this comment

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

Fixed.

@@ -85,6 +89,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
brave_component_updater::LocalDataFilesService* local_data_files_service();
#if BUILDFLAG(ENABLE_TOR)
extensions::BraveTorClientUpdater* tor_client_updater();
void OnTorEnabledChanged();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be public

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -130,6 +135,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
#endif
#if BUILDFLAG(ENABLE_TOR)
std::unique_ptr<extensions::BraveTorClientUpdater> tor_client_updater_;
PrefChangeRegistrar local_state_change_registrar_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is already pref_change_registrar_ in the superclass

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@simonhong simonhong removed the CI/skip Do not run CI builds (except noplatform) label Dec 3, 2019
@simonhong simonhong force-pushed the add_options_for_disabling_tor branch 2 times, most recently from 6606dae to 93a032d Compare December 3, 2019 23:04
Tor enabling change should only affect to browser after relaunching.
To cache user's change before relaunching, new kTorDisabledAtNextLaunching
pref value is introduced.
To check whether tor is enabled or not, tor component registration is
used instead of pref value because user can change pref via settings.
With this, we don't need to another prefs to check user changed or not.
Browsr commands will be updated after changing tor option.
If user turns it off, tor component will be removed at the next
launching. If there is already opened tor window, it can be used.
But, user can't create new tor window anymore.
@simonhong simonhong force-pushed the add_options_for_disabling_tor branch from 93a032d to 3e01e1f Compare December 4, 2019 02:25
@simonhong simonhong added CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS labels Dec 4, 2019
@simonhong
Copy link
Member Author

CI on macOS has below error.
test report file(s) were found with the pattern 'src/brave_browser_tests.xml' relative to '/Users/jenkins/jenkins/workspace/pr_add_options_for_disabling_tor' for the testing framework 'GoogleTest-1.8'.
But this seems not unrelated with this PR and all test cases are passed.
So merged.

@simonhong simonhong merged commit b1d0576 into master Dec 4, 2019
@simonhong simonhong deleted the add_options_for_disabling_tor branch December 4, 2019 10:52
@simonhong simonhong modified the milestones: 1.3.x - Dev, 1.4.x - Nightly Dec 4, 2019
@tildelowengrimm
Copy link
Contributor

This should also fix brave/brave-browser#4904.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS feature/tor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tor switch option in settings
6 participants