Skip to content

Commit

Permalink
Use Onion Available label button in Tor window
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Oct 7, 2020
1 parent 674a98f commit 8e44311
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_LOCATION_BAR_OPEN_IN_TOR" desc="Button in location bar to open onion available site in tor window.">
Open in Tor
</message>
<message name="IDS_LOCATION_BAR_ONION_AVAILABLE" desc="Button in location bar to indicate onion available site to open a new tab in tor window.">
Onion Available
</message>
<if expr="use_titlecase">
<message name="IDS_NEW_OFFTHERECORD_WINDOW_TOR" desc="Title case: The text label of a menu item to open a new off-the-record window with Tor.">
New Private Window with Tor
Expand Down
6 changes: 2 additions & 4 deletions browser/tor/onion_location_navigation_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ OnionLocationNavigationThrottle::WillProcessResponse() {
std::string onion_location;
if (headers && GetOnionLocation(headers, &onion_location) &&
!navigation_handle()->GetURL().DomainIs("onion")) {
// If we are in tor window, open onion site directly or user prefers
// opening it automatically
if (brave::IsTorProfile(profile_) ||
profile_->GetPrefs()->GetBoolean(prefs::kAutoOnionLocation)) {
// If user prefers opening it automatically
if (profile_->GetPrefs()->GetBoolean(prefs::kAutoOnionLocation)) {
profiles::SwitchToTorProfile(
base::BindRepeating(&OnTorProfileCreated, GURL(onion_location)));
} else {
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/views/brave_actions/brave_actions_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void BraveActionsContainer::Init() {
SetLayoutManager(std::move(vertical_container_layout));

// children
onion_location_view_ = new OnionLocationView();
onion_location_view_ = new OnionLocationView(browser_->profile());
AddChildViewAt(onion_location_view_, 0);

RoundedSeparator* brave_button_separator_ = new RoundedSeparator();
Expand Down
6 changes: 4 additions & 2 deletions browser/ui/views/location_bar/onion_location_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ void OnTorProfileCreated(GURL onion_location,

} // namespace

OnionLocationView::OnionLocationView()
OnionLocationView::OnionLocationView(Profile* profile)
: LabelButton(this,
l10n_util::GetStringUTF16((IDS_LOCATION_BAR_OPEN_IN_TOR))) {
l10n_util::GetStringUTF16(IDS_LOCATION_BAR_OPEN_IN_TOR)) {
if (brave::IsTorProfile(profile))
SetText(l10n_util::GetStringUTF16(IDS_LOCATION_BAR_ONION_AVAILABLE));
SetBackground(views::CreateSolidBackground(kOpenInTorBg));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::ImageSkia image;
Expand Down
4 changes: 3 additions & 1 deletion browser/ui/views/location_bar/onion_location_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include "chrome/browser/profiles/profile.h"
#include "ui/views/controls/button/label_button.h"

class Profile;

namespace content {
class WebContents;
} // namespace content

class OnionLocationView : public views::LabelButton,
public views::ButtonListener {
public:
OnionLocationView();
explicit OnionLocationView(Profile* profile);
~OnionLocationView() override;

void Update(content::WebContents* web_contents);
Expand Down

0 comments on commit 8e44311

Please sign in to comment.