diff --git a/browser/search_engines/search_engine_tracker_browsertest.cc b/browser/search_engines/search_engine_tracker_browsertest.cc index bf0681149160..b115ccd684c2 100644 --- a/browser/search_engines/search_engine_tracker_browsertest.cc +++ b/browser/search_engines/search_engine_tracker_browsertest.cc @@ -9,13 +9,17 @@ #include "brave/browser/profiles/profile_util.h" #include "brave/browser/ui/browser_commands.h" #include "brave/components/search_engines/brave_prepopulated_engines.h" -#include "brave/components/tor/tor_launcher_factory.h" +#include "brave/components/tor/buildflags/buildflags.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/test/base/in_process_browser_test.h" #include "components/search_engines/template_url_prepopulate_data.h" #include "content/public/test/browser_test.h" +#if BUILDFLAG(ENABLE_TOR) +#include "brave/components/tor/tor_launcher_factory.h" +#endif + class SearchEngineProviderP3ATest : public InProcessBrowserTest { public: SearchEngineProviderP3ATest() { @@ -47,8 +51,10 @@ IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest, // Check that incognito or TOR profiles do not emit the metric. CreateIncognitoBrowser(); +#if BUILDFLAG(ENABLE_TOR) ScopedTorLaunchPreventerForTest prevent_tor_process; brave::NewOffTheRecordWindowTor(browser()); +#endif histogram_tester_->ExpectTotalCount(kDefaultSearchEngineMetric, 2); } diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index ad3302665d6b..646db01cf836 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -5,6 +5,7 @@ import("//brave/components/brave_wallet/buildflags/buildflags.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") import("//brave/components/ipfs/buildflags/buildflags.gni") import("//brave/components/speedreader/buildflags.gni") +import("//brave/components/tor/buildflags/buildflags.gni") import("//build/config/features.gni") import("//components/gcm_driver/config.gni") import("//chrome/common/features.gni") @@ -293,8 +294,6 @@ source_set("ui") { "views/location_bar/brave_location_bar_view.h", "views/location_bar/brave_star_view.cc", "views/location_bar/brave_star_view.h", - "views/location_bar/onion_location_view.cc", - "views/location_bar/onion_location_view.h", "views/profiles/brave_avatar_toolbar_button.cc", "views/profiles/brave_avatar_toolbar_button.h", "views/tabs/brave_alert_indicator.cc", @@ -319,6 +318,13 @@ source_set("ui") { ] } + if (enable_tor) { + sources += [ + "views/location_bar/onion_location_view.cc", + "views/location_bar/onion_location_view.h", + ] + } + deps += [ "//brave/browser/resources/extensions:resources", "//brave/components/brave_extension:generated_resources", diff --git a/browser/ui/brave_browser_command_controller_browsertest.cc b/browser/ui/brave_browser_command_controller_browsertest.cc index 494b9567acfb..8324d258d154 100644 --- a/browser/ui/brave_browser_command_controller_browsertest.cc +++ b/browser/ui/brave_browser_command_controller_browsertest.cc @@ -155,6 +155,7 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest, EXPECT_TRUE(command_controller->IsCommandEnabled( IDC_SHOW_BRAVE_WEBCOMPAT_REPORTER)); +#if BUILDFLAG(ENABLE_TOR) // Launch tor window and check its command status. content::WindowedNotificationObserver tor_browser_creation_observer( chrome::NOTIFICATION_BROWSER_OPENED, @@ -176,12 +177,10 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest, EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_ADBLOCK)); -#if BUILDFLAG(ENABLE_TOR) EXPECT_TRUE( command_controller->IsCommandEnabled(IDC_NEW_TOR_CONNECTION_FOR_SITE)); EXPECT_TRUE( command_controller->IsCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR)); -#endif #if BUILDFLAG(ENABLE_BRAVE_SYNC) if (switches::IsSyncAllowedByFlag()) @@ -200,7 +199,6 @@ IN_PROC_BROWSER_TEST_F(BraveBrowserCommandControllerTest, IDC_SHOW_BRAVE_WEBCOMPAT_REPORTER)); // Check tor commands when tor is disabled. -#if BUILDFLAG(ENABLE_TOR) TorProfileServiceFactory::SetTorDisabled(true); command_controller = browser()->command_controller(); EXPECT_FALSE( diff --git a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc index 1d65d880c6c8..45fd3dbc1100 100644 --- a/browser/ui/toolbar/brave_app_menu_model_browsertest.cc +++ b/browser/ui/toolbar/brave_app_menu_model_browsertest.cc @@ -197,6 +197,7 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) { CheckCommandsAreDisabledInMenuModel(guest_browser, commands_disabled_for_guest_profile); +#if BUILDFLAG(ENABLE_TOR) content::WindowedNotificationObserver tor_browser_creation_observer( chrome::NOTIFICATION_BROWSER_OPENED, content::NotificationService::AllSources()); @@ -215,9 +216,7 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) { IDC_NEW_TOR_CONNECTION_FOR_SITE, IDC_NEW_WINDOW, IDC_NEW_INCOGNITO_WINDOW, -#if BUILDFLAG(ENABLE_TOR) IDC_NEW_OFFTHERECORD_WINDOW_TOR, -#endif #if BUILDFLAG(BRAVE_REWARDS_ENABLED) IDC_SHOW_BRAVE_REWARDS, #endif @@ -251,4 +250,5 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, MenuOrderTest) { commands_in_order_for_tor_profile); CheckCommandsAreDisabledInMenuModel(tor_browser, commands_disabled_for_tor_profile); +#endif } diff --git a/browser/ui/views/location_bar/brave_location_bar_view.cc b/browser/ui/views/location_bar/brave_location_bar_view.cc index e1f6a3e636b3..fc1df2315ff5 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.cc +++ b/browser/ui/views/location_bar/brave_location_bar_view.cc @@ -10,7 +10,6 @@ #include "brave/browser/profiles/profile_util.h" #include "brave/browser/themes/brave_theme_service.h" #include "brave/browser/ui/views/brave_actions/brave_actions_container.h" -#include "brave/browser/ui/views/location_bar/onion_location_view.h" #include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service_factory.h" @@ -21,6 +20,10 @@ #include "components/version_info/channel.h" #include "ui/views/controls/highlight_path_generator.h" +#if BUILDFLAG(ENABLE_TOR) +#include "brave/browser/ui/views/location_bar/onion_location_view.h" +#endif + namespace { class BraveLocationBarViewFocusRingHighlightPathGenerator @@ -49,11 +52,13 @@ void BraveLocationBarView::Init() { std::make_unique< BraveLocationBarViewFocusRingHighlightPathGenerator>()); } - // brave action buttons +#if BUILDFLAG(ENABLE_TOR) onion_location_view_ = new OnionLocationView(browser_->profile()); + AddChildView(onion_location_view_); +#endif + // brave action buttons brave_actions_ = new BraveActionsContainer(browser_, profile()); brave_actions_->Init(); - AddChildView(onion_location_view_); AddChildView(brave_actions_); // Call Update again to cause a Layout Update(nullptr); @@ -69,8 +74,10 @@ void BraveLocationBarView::Update(content::WebContents* contents) { if (brave_actions_) { brave_actions_->Update(); } +#if BUILDFLAG(ENABLE_TOR) if (onion_location_view_) onion_location_view_->Update(contents); +#endif LocationBarView::Update(contents); } @@ -81,9 +88,11 @@ void BraveLocationBarView::OnChanged() { ShouldHidePageActionIcons() && !omnibox_view_->GetText().empty(); brave_actions_->SetShouldHide(should_hide); } +#if BUILDFLAG(ENABLE_TOR) if (onion_location_view_) onion_location_view_->Update( browser_->tab_strip_model()->GetActiveWebContents()); +#endif // OnChanged calls Layout LocationBarView::OnChanged(); @@ -91,8 +100,10 @@ void BraveLocationBarView::OnChanged() { std::vector BraveLocationBarView::GetTrailingViews() { std::vector views; +#if BUILDFLAG(ENABLE_TOR) if (onion_location_view_) views.push_back(onion_location_view_); +#endif if (brave_actions_) views.push_back(brave_actions_); @@ -107,11 +118,13 @@ gfx::Size BraveLocationBarView::CalculatePreferredSize() const { GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); min_size.Enlarge(extra_width, 0); } +#if BUILDFLAG(ENABLE_TOR) if (onion_location_view_ && onion_location_view_->GetVisible()) { const int extra_width = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + onion_location_view_->GetMinimumSize().width(); min_size.Enlarge(extra_width, 0); } +#endif return min_size; } diff --git a/browser/ui/views/location_bar/brave_location_bar_view.h b/browser/ui/views/location_bar/brave_location_bar_view.h index 539b2752b6d4..42241a275aaf 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.h +++ b/browser/ui/views/location_bar/brave_location_bar_view.h @@ -8,14 +8,18 @@ #include +#include "brave/components/tor/buildflags/buildflags.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" class BraveActionsContainer; class BraveActionsContainerTest; -class OnionLocationView; class RewardsBrowserTest; class SkPath; +#if BUILDFLAG(ENABLE_TOR) +class OnionLocationView; +#endif + // The purposes of this subclass are to: // - Add the BraveActionsContainer to the location bar class BraveLocationBarView : public LocationBarView { @@ -25,7 +29,9 @@ class BraveLocationBarView : public LocationBarView { void Update(content::WebContents* contents) override; void OnChanged() override; BraveActionsContainer* GetBraveActionsContainer() { return brave_actions_; } +#if BUILDFLAG(ENABLE_TOR) OnionLocationView* GetOnionLocationView() { return onion_location_view_; } +#endif // LocationBarView: std::vector GetTrailingViews() override; @@ -44,7 +50,9 @@ class BraveLocationBarView : public LocationBarView { friend class ::BraveActionsContainerTest; friend class ::RewardsBrowserTest; BraveActionsContainer* brave_actions_ = nullptr; +#if BUILDFLAG(ENABLE_TOR) OnionLocationView* onion_location_view_ = nullptr; +#endif DISALLOW_COPY_AND_ASSIGN(BraveLocationBarView); }; diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.cc b/browser/ui/webui/settings/brave_default_extensions_handler.cc index 8e366811ffe1..e3c6115cc2c5 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.cc +++ b/browser/ui/webui/settings/brave_default_extensions_handler.cc @@ -83,7 +83,6 @@ void BraveDefaultExtensionsHandler::RegisterMessages() { "getRestartNeeded", base::BindRepeating(&BraveDefaultExtensionsHandler::GetRestartNeeded, base::Unretained(this))); -#if BUILDFLAG(ENABLE_TOR) web_ui()->RegisterMessageCallback( "setTorEnabled", base::BindRepeating( @@ -97,7 +96,6 @@ void BraveDefaultExtensionsHandler::RegisterMessages() { "isTorManaged", base::BindRepeating(&BraveDefaultExtensionsHandler::IsTorManaged, base::Unretained(this))); -#endif // Can't call this in ctor because it needs to access web_ui(). InitializePrefCallbacks(); @@ -233,13 +231,14 @@ void BraveDefaultExtensionsHandler::SetMediaRouterEnabled( about_flags::SetFeatureEntryEnabled(&flags_storage, feature_name, true); } -#if BUILDFLAG(ENABLE_TOR) void BraveDefaultExtensionsHandler::SetTorEnabled(const base::ListValue* args) { +#if BUILDFLAG(ENABLE_TOR) CHECK_EQ(args->GetSize(), 1U); bool enabled; args->GetBoolean(0, &enabled); AllowJavascript(); TorProfileServiceFactory::SetTorDisabled(!enabled); +#endif } void BraveDefaultExtensionsHandler::IsTorEnabled( @@ -248,14 +247,22 @@ void BraveDefaultExtensionsHandler::IsTorEnabled( AllowJavascript(); ResolveJavascriptCallback( args->GetList()[0], +#if BUILDFLAG(ENABLE_TOR) base::Value(!TorProfileServiceFactory::IsTorDisabled())); +#else + base::Value(false)); +#endif } void BraveDefaultExtensionsHandler::OnTorEnabledChanged() { if (IsJavascriptAllowed()) { FireWebUIListener( "tor-enabled-changed", +#if BUILDFLAG(ENABLE_TOR) base::Value(!TorProfileServiceFactory::IsTorDisabled())); +#else + base::Value(false)); +#endif } } @@ -263,13 +270,16 @@ void BraveDefaultExtensionsHandler::IsTorManaged( const base::ListValue* args) { CHECK_EQ(args->GetSize(), 1U); +#if BUILDFLAG(ENABLE_TOR) const bool is_managed = g_brave_browser_process->local_state()-> FindPreference(tor::prefs::kTorDisabled)->IsManaged(); +#else + const bool is_managed = false; +#endif AllowJavascript(); ResolveJavascriptCallback(args->GetList()[0], base::Value(is_managed)); } -#endif void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled( const base::ListValue* args) { diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.h b/browser/ui/webui/settings/brave_default_extensions_handler.h index 0af0cbcee3f1..dd9e5aa2490b 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.h +++ b/browser/ui/webui/settings/brave_default_extensions_handler.h @@ -36,12 +36,10 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler { #if BUILDFLAG(BRAVE_WALLET_ENABLED) void SetBraveWalletEnabled(const base::ListValue* args); #endif -#if BUILDFLAG(ENABLE_TOR) void SetTorEnabled(const base::ListValue* args); void IsTorEnabled(const base::ListValue* args); void OnTorEnabledChanged(); void IsTorManaged(const base::ListValue* args); -#endif void InitializePrefCallbacks(); diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc index a755ad7ec2ec..81e0588773f7 100644 --- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -115,9 +115,9 @@ void BraveRenderViewContextMenu::AddSpellCheckServiceItem( void BraveRenderViewContextMenu::InitMenu() { RenderViewContextMenu_Chromium::InitMenu(); + int index = -1; #if BUILDFLAG(ENABLE_TOR) // Add Open Link with Tor - int index = -1; if (!TorProfileServiceFactory::IsTorDisabled() && !params_.link_url.is_empty()) { const Browser* browser = GetBrowser();