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

Enable sidebar in private(tor) window #12203

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser/ui/brave_browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

BraveBrowser::BraveBrowser(const CreateParams& params) : Browser(params) {
#if BUILDFLAG(ENABLE_SIDEBAR)
if (!sidebar::CanUseSidebar(profile()) || !is_type_normal())
if (!sidebar::CanUseSidebar(this))
return;
// Below call order is important.
// When reaches here, Sidebar UI is setup in BraveBrowserView but
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void BraveBrowserCommandController::UpdateCommandForTor() {

void BraveBrowserCommandController::UpdateCommandForSidebar() {
#if BUILDFLAG(ENABLE_SIDEBAR)
if (sidebar::CanUseSidebar(browser_->profile()))
if (sidebar::CanUseSidebar(browser_))
UpdateCommandEnabled(IDC_SIDEBAR_SHOW_OPTION_MENU, true);
#endif
}
Expand Down
15 changes: 5 additions & 10 deletions browser/ui/sidebar/sidebar_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "brave/browser/ui/sidebar/sidebar_service_factory.h"

#include "base/feature_list.h"
#include "brave/components/sidebar/features.h"
#include "brave/components/sidebar/sidebar_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -20,14 +18,6 @@ SidebarServiceFactory* SidebarServiceFactory::GetInstance() {
}

SidebarService* SidebarServiceFactory::GetForProfile(Profile* profile) {
if (!base::FeatureList::IsEnabled(kSidebarFeature))
return nullptr;

if (profile->IsOffTheRecord()) {
// Temporarily disable sidebar except normal window.
return nullptr;
}

return static_cast<SidebarService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
Expand All @@ -44,4 +34,9 @@ KeyedService* SidebarServiceFactory::BuildServiceInstanceFor(
return new SidebarService(Profile::FromBrowserContext(context)->GetPrefs());
}

content::BrowserContext* SidebarServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}

} // namespace sidebar
2 changes: 2 additions & 0 deletions browser/ui/sidebar/sidebar_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SidebarServiceFactory : public BrowserContextKeyedServiceFactory {
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};

} // namespace sidebar
Expand Down
11 changes: 4 additions & 7 deletions browser/ui/sidebar/sidebar_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "brave/components/sidebar/features.h"
#include "brave/components/sidebar/sidebar_item.h"
#include "brave/components/sidebar/sidebar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
Expand Down Expand Up @@ -53,15 +52,13 @@ bool IsActiveTabAlreadyAddedToSidebar(Browser* browser) {

} // namespace

bool CanUseSidebar(Profile* profile) {
if (!base::FeatureList::IsEnabled(sidebar::kSidebarFeature))
return false;
bool CanUseSidebar(Browser* browser) {
DCHECK(browser);

if (!profile)
if (!base::FeatureList::IsEnabled(kSidebarFeature))
return false;

// Temporarily enable only normal profile.
return !profile->IsOffTheRecord();
return browser->is_type_normal();
}

bool CanAddCurrentActiveTabToSidebar(Browser* browser) {
Expand Down
3 changes: 1 addition & 2 deletions browser/ui/sidebar/sidebar_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#define BRAVE_BROWSER_UI_SIDEBAR_SIDEBAR_UTILS_H_

class Browser;
class Profile;

namespace sidebar {

bool CanUseSidebar(Profile* profile);
bool CanUseSidebar(Browser* browser);
bool CanAddCurrentActiveTabToSidebar(Browser* browser);

} // namespace sidebar
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/toolbar/brave_app_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
}

#if BUILDFLAG(ENABLE_SIDEBAR)
if (sidebar::CanUseSidebar(browser()->profile())) {
if (sidebar::CanUseSidebar(browser())) {
sub_menus_.push_back(std::make_unique<SidebarMenuModel>(browser()));
InsertSubMenuWithStringIdAt(
GetIndexOfBraveSidebarItem(), IDC_SIDEBAR_SHOW_OPTION_MENU,
Expand Down
6 changes: 2 additions & 4 deletions browser/ui/views/frame/brave_browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ BraveBrowserView::BraveBrowserView(std::unique_ptr<Browser> browser)

#if BUILDFLAG(ENABLE_SIDEBAR)
// Only normal window (tabbed) should have sidebar.
if (!sidebar::CanUseSidebar(browser_->profile()) ||
!browser_->is_type_normal()) {
if (!sidebar::CanUseSidebar(browser_.get())) {
return;
}

Expand Down Expand Up @@ -214,8 +213,7 @@ sidebar::Sidebar* BraveBrowserView::InitSidebar() {
}

ContentsLayoutManager* BraveBrowserView::GetContentsLayoutManager() const {
if (sidebar::CanUseSidebar(browser_->profile()) &&
browser_->is_type_normal()) {
if (sidebar::CanUseSidebar(browser_.get())) {
return static_cast<ContentsLayoutManager*>(
original_contents_container_->GetLayoutManager());
}
Expand Down
7 changes: 4 additions & 3 deletions browser/ui/webui/brave_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "content/public/common/content_features.h"

#if BUILDFLAG(ENABLE_SIDEBAR)
#include "brave/browser/ui/sidebar/sidebar_utils.h"
#include "brave/components/sidebar/features.h"
#endif

#if BUILDFLAG(ENABLE_SPEEDREADER)
Expand Down Expand Up @@ -88,8 +88,9 @@ void BraveSettingsUI::AddResources(content::WebUIDataSource* html_source,
#if BUILDFLAG(ENABLE_SIDEBAR)
// TODO(simonhong): Remove this when sidebar is shipped by default in all
// channels.
html_source->AddBoolean("isSidebarFeatureEnabled",
sidebar::CanUseSidebar(profile));
html_source->AddBoolean(
"isSidebarFeatureEnabled",
base::FeatureList::IsEnabled(sidebar::kSidebarFeature));
#endif
#if BUILDFLAG(ENABLE_BRAVE_VPN)
html_source->AddBoolean("isBraveVPNEnabled", brave_vpn::IsBraveVPNEnabled());
Expand Down