@@ -26,6 +26,8 @@ namespace {
26
26
27
27
bool GetOnionLocation (const net::HttpResponseHeaders* headers,
28
28
std::string* onion_location) {
29
+ DCHECK (onion_location);
30
+
29
31
onion_location->clear ();
30
32
std::string name = " onion-location" ;
31
33
@@ -54,7 +56,8 @@ void OnTorProfileCreated(GURL onion_location,
54
56
std::unique_ptr<OnionLocationNavigationThrottle>
55
57
OnionLocationNavigationThrottle::MaybeCreateThrottleFor (
56
58
content::NavigationHandle* navigation_handle) {
57
- if (tor::TorProfileService::IsTorDisabled ())
59
+ if (tor::TorProfileService::IsTorDisabled () ||
60
+ !navigation_handle->IsInMainFrame ())
58
61
return nullptr ;
59
62
return std::make_unique<OnionLocationNavigationThrottle>(navigation_handle);
60
63
}
@@ -70,23 +73,24 @@ OnionLocationNavigationThrottle::~OnionLocationNavigationThrottle() {}
70
73
71
74
content::NavigationThrottle::ThrottleCheckResult
72
75
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
87
83
OnionLocationTabHelper::SetOnionLocation (
88
84
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));
89
90
}
91
+ } else {
92
+ OnionLocationTabHelper::SetOnionLocation (
93
+ navigation_handle ()->GetWebContents (), GURL ());
90
94
}
91
95
return content::NavigationThrottle::PROCEED;
92
96
}
@@ -95,8 +99,7 @@ content::NavigationThrottle::ThrottleCheckResult
95
99
OnionLocationNavigationThrottle::WillStartRequest () {
96
100
if (!brave::IsTorProfile (profile_)) {
97
101
GURL url = navigation_handle ()->GetURL ();
98
- if (url.SchemeIsHTTPOrHTTPS () && url.DomainIs (" onion" ) &&
99
- navigation_handle ()->IsInMainFrame ()) {
102
+ if (url.SchemeIsHTTPOrHTTPS () && url.DomainIs (" onion" )) {
100
103
profiles::SwitchToTorProfile (
101
104
base::BindRepeating (&OnTorProfileCreated, std::move (url)));
102
105
return content::NavigationThrottle::CANCEL_AND_IGNORE;
0 commit comments