Skip to content

Commit 08ec907

Browse files
committed
Address review feedbacks from iefremov
1 parent 8e44311 commit 08ec907

File tree

6 files changed

+31
-32
lines changed

6 files changed

+31
-32
lines changed

browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@
131131
on-settings-boolean-control-change="onTorEnabledChange_">
132132
</settings-toggle-button>
133133
<settings-toggle-button
134-
pref="{{prefs.tor.auto_onion_location}}"
135-
class="cr-row"
136-
label="$i18n{autoOnionLocationLabel}"
137-
sub-label="$i18n{autoOnionLocationDesc}"
138-
disabled="[[!torEnabled_]]">
134+
pref="{{prefs.tor.auto_onion_location}}"
135+
class="cr-row"
136+
label="$i18n{autoOnionLocationLabel}"
137+
sub-label="$i18n{autoOnionLocationDesc}"
138+
disabled="[[!torEnabled_]]">
139139
</settings-toggle-button>
140140
</if>
141141
<settings-toggle-button id="webTorrentEnabled"

browser/tor/BUILD.gn

+5-7
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,26 @@ source_set("tor") {
2424
"//mojo/public/cpp/bindings",
2525
]
2626

27-
public_deps = [
28-
":buildflags",
29-
]
27+
public_deps = [ ":buildflags" ]
3028

3129
if (enable_tor) {
3230
sources += [
31+
"onion_location_navigation_throttle.cc",
32+
"onion_location_navigation_throttle.h",
33+
"onion_location_tab_helper.cc",
34+
"onion_location_tab_helper.h",
3335
"tor_control.cc",
3436
"tor_control.h",
3537
"tor_launcher_factory.cc",
3638
"tor_launcher_factory.h",
3739
"tor_navigation_throttle.cc",
3840
"tor_navigation_throttle.h",
39-
"onion_location_navigation_throttle.cc",
40-
"onion_location_navigation_throttle.h",
4141
"tor_profile_service.cc",
4242
"tor_profile_service.h",
4343
"tor_profile_service_impl.cc",
4444
"tor_profile_service_impl.h",
4545
"tor_tab_helper.cc",
4646
"tor_tab_helper.h",
47-
"onion_location_tab_helper.cc",
48-
"onion_location_tab_helper.h",
4947
]
5048

5149
deps += [

browser/tor/onion_location_navigation_throttle.cc

+20-17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace {
2626

2727
bool GetOnionLocation(const net::HttpResponseHeaders* headers,
2828
std::string* onion_location) {
29+
DCHECK(onion_location);
30+
2931
onion_location->clear();
3032
std::string name = "onion-location";
3133

@@ -54,7 +56,8 @@ void OnTorProfileCreated(GURL onion_location,
5456
std::unique_ptr<OnionLocationNavigationThrottle>
5557
OnionLocationNavigationThrottle::MaybeCreateThrottleFor(
5658
content::NavigationHandle* navigation_handle) {
57-
if (tor::TorProfileService::IsTorDisabled())
59+
if (tor::TorProfileService::IsTorDisabled() ||
60+
!navigation_handle->IsInMainFrame())
5861
return nullptr;
5962
return std::make_unique<OnionLocationNavigationThrottle>(navigation_handle);
6063
}
@@ -70,23 +73,24 @@ OnionLocationNavigationThrottle::~OnionLocationNavigationThrottle() {}
7073

7174
content::NavigationThrottle::ThrottleCheckResult
7275
OnionLocationNavigationThrottle::WillProcessResponse() {
73-
if (navigation_handle()->IsInMainFrame()) {
74-
auto* headers = navigation_handle()->GetResponseHeaders();
75-
std::string onion_location;
76-
if (headers && GetOnionLocation(headers, &onion_location) &&
77-
!navigation_handle()->GetURL().DomainIs("onion")) {
78-
// If user prefers opening it automatically
79-
if (profile_->GetPrefs()->GetBoolean(prefs::kAutoOnionLocation)) {
80-
profiles::SwitchToTorProfile(
81-
base::BindRepeating(&OnTorProfileCreated, GURL(onion_location)));
82-
} else {
83-
OnionLocationTabHelper::SetOnionLocation(
84-
navigation_handle()->GetWebContents(), GURL(onion_location));
85-
}
86-
} else {
76+
auto* headers = navigation_handle()->GetResponseHeaders();
77+
std::string onion_location;
78+
if (headers && GetOnionLocation(headers, &onion_location) &&
79+
!navigation_handle()->GetURL().DomainIs("onion")) {
80+
// If user prefers opening it automatically
81+
if (profile_->GetPrefs()->GetBoolean(prefs::kAutoOnionLocation)) {
82+
// Cleanup previous label before user switching to kAutoOnionLocation
8783
OnionLocationTabHelper::SetOnionLocation(
8884
navigation_handle()->GetWebContents(), GURL());
85+
profiles::SwitchToTorProfile(
86+
base::BindRepeating(&OnTorProfileCreated, GURL(onion_location)));
87+
} else {
88+
OnionLocationTabHelper::SetOnionLocation(
89+
navigation_handle()->GetWebContents(), GURL(onion_location));
8990
}
91+
} else {
92+
OnionLocationTabHelper::SetOnionLocation(
93+
navigation_handle()->GetWebContents(), GURL());
9094
}
9195
return content::NavigationThrottle::PROCEED;
9296
}
@@ -95,8 +99,7 @@ content::NavigationThrottle::ThrottleCheckResult
9599
OnionLocationNavigationThrottle::WillStartRequest() {
96100
if (!brave::IsTorProfile(profile_)) {
97101
GURL url = navigation_handle()->GetURL();
98-
if (url.SchemeIsHTTPOrHTTPS() && url.DomainIs("onion") &&
99-
navigation_handle()->IsInMainFrame()) {
102+
if (url.SchemeIsHTTPOrHTTPS() && url.DomainIs("onion")) {
100103
profiles::SwitchToTorProfile(
101104
base::BindRepeating(&OnTorProfileCreated, std::move(url)));
102105
return content::NavigationThrottle::CANCEL_AND_IGNORE;

browser/ui/views/brave_actions/brave_actions_container.cc

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "ui/views/layout/grid_layout.h"
4040
#include "ui/views/view.h"
4141

42-
4342
class BraveActionsContainer::EmptyExtensionsContainer
4443
: public ExtensionsContainer {
4544
public:

browser/ui/views/brave_actions/brave_actions_container.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#endif
2828

2929
class BraveActionViewController;
30-
class OnionLocationView;
3130
class BraveActionsContainerTest;
31+
class OnionLocationView;
3232
class RewardsBrowserTest;
3333

3434
namespace extensions {

browser/ui/views/location_bar/onion_location_view.h

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_ONION_LOCATION_VIEW_H_
77
#define BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_ONION_LOCATION_VIEW_H_
88

9-
#include "chrome/browser/profiles/profile.h"
109
#include "ui/views/controls/button/label_button.h"
1110

1211
class Profile;

0 commit comments

Comments
 (0)