Skip to content

Commit

Permalink
Merge pull request #431 from brave/maxk-rewards-extension-in-brave-bar
Browse files Browse the repository at this point in the history
Rewards extension in brave bar
  • Loading branch information
petemill authored Sep 13, 2018
2 parents 3adf5d7 + e4149ec commit e8468ee
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 65 deletions.
2 changes: 2 additions & 0 deletions brave_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ template("brave_extra_paks") {
"$root_gen_dir/brave/brave_unscaled_resources.pak",
"$root_gen_dir/components/brave_components_resources.pak",
"$target_gen_dir/browser/resources/brave_extension.pak",
"$target_gen_dir/components/brave_rewards/brave_rewards_resources.pak",
"$target_gen_dir/components/brave_webtorrent/brave_webtorrent_resources.pak",
]

deps = [
"//brave/app:brave_generated_resources_grit",
"//brave/app/theme:brave_unscaled_resources",
"//brave/components/brave_rewards:resources",
"//brave/components/brave_webtorrent:resources",
"//brave/components/resources:brave_components_resources_grit",
"//brave/browser/resources:brave_extension_grit",
Expand Down
1 change: 1 addition & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source_set("extensions") {
deps = [
"//brave/browser/resources:brave_extension_grit",
"//brave/common/extensions/api",
"//brave/components/brave_rewards:resources",
"//brave/components/brave_webtorrent:resources",
"//chrome/browser",
"//content/public/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "brave/browser/extensions/brave_component_extension_resource_manager.h"

#include "brave/browser/resources/grit/brave_extension_resources_map.h"
#include "brave/components/brave_rewards/grit/brave_rewards_resources_map.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h"

namespace extensions {
Expand All @@ -15,6 +16,10 @@ BraveComponentExtensionResourceManager() {
kBraveExtension,
kBraveExtensionSize);

AddComponentResourceEntries(
kBraveRewardsResources,
kBraveRewardsResourcesSize);

AddComponentResourceEntries(
kBraveWebtorrentResources,
kBraveWebtorrentResourcesSize);
Expand Down
13 changes: 13 additions & 0 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "base/command_line.h"
#include "brave/common/brave_switches.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_rewards/grit/brave_rewards_resources.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
#include "components/grit/brave_components_resources.h"

Expand Down Expand Up @@ -35,6 +37,17 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
Add(IDR_BRAVE_EXTENSON, brave_extension_path);
}

// !defined(OFFICIAL_BUILD) should be removed once brave/brave-browser#920
// (the proper extension UI) is implemented.
#if BUILDFLAG(BRAVE_REWARDS_ENABLED) && !defined(OFFICIAL_BUILD)
if (!command_line.HasSwitch(switches::kDisableBraveRewardsExtension)) {
base::FilePath brave_rewards_path(FILE_PATH_LITERAL(""));
brave_rewards_path =
brave_rewards_path.Append(FILE_PATH_LITERAL("brave_rewards"));
Add(IDR_BRAVE_REWARDS, brave_rewards_path);
}
#endif

base::FilePath brave_webtorrent_path(FILE_PATH_LITERAL(""));
brave_webtorrent_path =
brave_webtorrent_path.Append(FILE_PATH_LITERAL("brave_webtorrent"));
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/brave_extension_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace extensions {
bool BraveExtensionProvider::IsVetted(const Extension* extension) {
static std::vector<std::string> vetted_extensions({
brave_extension_id,
brave_rewards_extension_id,
brave_webtorrent_extension_id,
pdfjs_extension_id,
// 1Password
Expand Down Expand Up @@ -133,6 +134,7 @@ bool BraveExtensionProvider::UserMayLoad(const Extension* extension,
bool BraveExtensionProvider::MustRemainInstalled(const Extension* extension,
base::string16* error) const {
return extension->id() == brave_extension_id ||
extension->id() == brave_rewards_extension_id ||
extension->id() == brave_webtorrent_extension_id;
}

Expand Down
3 changes: 3 additions & 0 deletions browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@
"includes": [36500],
},
# brave webtorrent 37500
"brave/components/brave_rewards/resources.grd": {
"includes": [38000],
},
}
4 changes: 2 additions & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ source_set("ui") {
"brave_pages.h",
"brave_layout_constants.cc",
"brave_layout_constants.h",
"brave_actions/shields_action_view_controller.cc",
"brave_actions/shields_action_view_controller.h",
"brave_actions/brave_action_icon_with_badge_image_source.cc",
"brave_actions/brave_action_icon_with_badge_image_source.h",
"brave_actions/brave_action_view_controller.cc",
"brave_actions/brave_action_view_controller.h",
"content_settings/brave_autoplay_blocked_image_model.cc",
"content_settings/brave_autoplay_blocked_image_model.h",
"content_settings/brave_autoplay_content_setting_bubble_model.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/brave_actions/shields_action_view_controller.h"
#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 "chrome/browser/extensions/extension_action.h"
Expand All @@ -16,28 +16,30 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"

void ShieldsActionViewController::HideActivePopup() {
void BraveActionViewController::HideActivePopup() {
// Usually, for an extension this should call the main extensions
// toolbar_actions_bar_->HideActivePopup(), but we don't have a reference
// to that, and it doesn't seem neccessary, whether the extension is opened
// via mouse or keyboard (if a `commands` extension property is present)
}

bool ShieldsActionViewController::DisabledClickOpensMenu() const {
bool BraveActionViewController::DisabledClickOpensMenu() const {
// disabled is a per-tab state
return false;
}

ui::MenuModel* ShieldsActionViewController::GetContextMenu() {
// no context menu for shields button
ui::MenuModel* BraveActionViewController::GetContextMenu() {
// no context menu for brave actions button
return nullptr;
}

gfx::Image ShieldsActionViewController::GetIcon(content::WebContents* web_contents, const gfx::Size& size) {
gfx::Image BraveActionViewController::GetIcon(
content::WebContents* web_contents,
const gfx::Size& size) {
return gfx::Image(gfx::ImageSkia(GetIconImageSource(web_contents, size), size));
}

std::unique_ptr<BraveActionIconWithBadgeImageSource> ShieldsActionViewController::GetIconImageSource(
std::unique_ptr<BraveActionIconWithBadgeImageSource> BraveActionViewController::GetIconImageSource(
content::WebContents* web_contents, const gfx::Size& size) {
int tab_id = SessionTabHelper::IdForTab(web_contents).id();
// generate icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_BRAVE_ACTIONS_SHIELDS_ACTION_VIEW_CONTROLLER_H_
#define BRAVE_BROWSER_UI_BRAVE_ACTIONS_SHIELDS_ACTION_VIEW_CONTROLLER_H_
#ifndef BRAVE_BROWSER_UI_BRAVE_ACTIONS_BRAVE_ACTION_VIEW_CONTROLLER_H_
#define BRAVE_BROWSER_UI_BRAVE_ACTIONS_BRAVE_ACTION_VIEW_CONTROLLER_H_

#include "chrome/browser/ui/extensions/extension_action_view_controller.h"

Expand All @@ -18,7 +18,7 @@ namespace ui {
// - Use our custom class for painting the badge differently compared to
// user-installed extensions
// - Remove the context menu from the button since we do not allow uninstall
class ShieldsActionViewController : public ExtensionActionViewController {
class BraveActionViewController : public ExtensionActionViewController {
public:
using ExtensionActionViewController::ExtensionActionViewController;
void HideActivePopup() override;
Expand All @@ -30,7 +30,7 @@ class ShieldsActionViewController : public ExtensionActionViewController {
std::unique_ptr<BraveActionIconWithBadgeImageSource> GetIconImageSource(
content::WebContents* web_contents,
const gfx::Size& size);
DISALLOW_COPY_AND_ASSIGN(ShieldsActionViewController);
DISALLOW_COPY_AND_ASSIGN(BraveActionViewController);
};

#endif
7 changes: 4 additions & 3 deletions browser/ui/toolbar/brave_toolbar_actions_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include "extensions/common/extension.h"

bool BraveToolbarActionsModel::ShouldAddExtension(const extensions::Extension* extension) {
// Don't show the Brave 'extension' in the ToolbarActions extensions area. It
// will instead be shown in the BraveActions area.
if (extension->id() == brave_extension_id) {
// Don't show the Brave and Rewards 'extensions' in the ToolbarActions
// extensions area. They will instead be shown in the BraveActions area.
if (extension->id() == brave_extension_id ||
extension->id() == brave_rewards_extension_id) {
return false;
}
return ToolbarActionsModel::ShouldAddExtension(extension);
Expand Down
Loading

0 comments on commit e8468ee

Please sign in to comment.