Skip to content

Commit

Permalink
Merge pull request #615 from brave/maxk-disable-rewards-in-tor-private
Browse files Browse the repository at this point in the history
Disable Brave Rewards button in Guest, Tor, and incognito profiles.
  • Loading branch information
bbondy authored Oct 14, 2018
2 parents 08b6428 + 4a75991 commit 4099364
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
19 changes: 19 additions & 0 deletions browser/extensions/brave_extension_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/extensions/brave_extension_service.h"
#include "brave/common/extensions/extension_constants.h"
#include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/profiles/profile.h"

namespace extensions {
Expand All @@ -26,6 +29,22 @@ BraveExtensionService::~BraveExtensionService() {
void BraveExtensionService::AddComponentExtension(const Extension* extension) {
ExtensionService::AddComponentExtension(extension);

// Disable Brave Rewards extension action for Guest and Tor profiles on all
// tabs right after loading the extension for these profiles. Can't do the
// same for the regular off the record (incognito) profile as there doesn't
// appear to be a separate from the regular profile action manager for it, so
// disabling it would apply to the regular profile as well. Instead, catch
// the extension when BraveActionViewController is queried about the
// visibility of the action.
if ((extension->id() == brave_rewards_extension_id) &&
(profile_->IsGuestSession() || profile_->IsTorProfile())) {
extensions::ExtensionActionManager* extension_action_manager =
ExtensionActionManager::Get(profile_);
ExtensionAction* action =
extension_action_manager->GetExtensionAction(*extension);
action->SetIsVisible(ExtensionAction::kDefaultTabId, false);
}

// ContentSettingsStore::RegisterExtension is only called for default components
// on the first run with a fresh profile. All restarts of the browser after that do not call it.
// This causes ContentSettingsStore's `entries_` to never insert the component ID
Expand Down
17 changes: 14 additions & 3 deletions browser/ui/brave_actions/brave_action_view_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#include "brave/browser/ui/brave_actions/brave_action_view_controller.h"

#include "brave/browser/ui/brave_actions/brave_action_icon_with_badge_image_source.h"
#include "brave/common/extensions/extension_constants.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/canvas.h"
Expand All @@ -16,6 +19,15 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"

bool BraveActionViewController::IsEnabled(
content::WebContents* web_contents) const {
bool is_enabled = ExtensionActionViewController::IsEnabled(web_contents);
if (is_enabled && extension_->id() == brave_rewards_extension_id &&
browser_->profile()->IsOffTheRecord())
is_enabled = false;
return is_enabled;
}

void BraveActionViewController::HideActivePopup() {
// Usually, for an extension this should call the main extensions
// toolbar_actions_bar_->HideActivePopup(), but we don't have a reference
Expand Down Expand Up @@ -59,8 +71,7 @@ std::unique_ptr<BraveActionIconWithBadgeImageSource> BraveActionViewController::
// state
// If the extension doesn't want to run on the active web contents, we
// grayscale it to indicate that.
bool is_enabled_for_tab = extension_action()->GetIsVisible(tab_id);
image_source->set_grayscale(!is_enabled_for_tab);
image_source->set_grayscale(!IsEnabled(web_contents));
image_source->set_paint_page_action_decoration(false);
return image_source;
}
1 change: 1 addition & 0 deletions browser/ui/brave_actions/brave_action_view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace ui {
class BraveActionViewController : public ExtensionActionViewController {
public:
using ExtensionActionViewController::ExtensionActionViewController;
bool IsEnabled(content::WebContents* web_contents) const override;
void HideActivePopup() override;
gfx::Image GetIcon(content::WebContents* web_contents, const gfx::Size& size) override;
bool DisabledClickOpensMenu() const override;
Expand Down

0 comments on commit 4099364

Please sign in to comment.