-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on the Rewards extension
- Loading branch information
1 parent
c866433
commit ca047fb
Showing
100 changed files
with
3,088 additions
and
684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CANVAS_DIMENSIONS, 16, | ||
PATH_COLOR_ARGB, 0xFF, 0xFF, 0x47, 0x24, | ||
MOVE_TO, 0.03f, 14.56f, | ||
R_LINE_TO, 4.68f, -2.75f, | ||
LINE_TO, 7.94f, 6.15f, | ||
V_LINE_TO, 0.69f, | ||
R_CUBIC_TO, -0.09f, 0, -0.17f, 0.06f, -0.23f, 0.17f, | ||
LINE_TO, 3.88f, 7.57f, | ||
LINE_TO, 0.06f, 14.27f, | ||
R_CUBIC_TO, -0.06f, 0.11f, -0.07f, 0.22f, -0.03f, 0.29f, | ||
CLOSE, | ||
NEW_PATH, | ||
PATH_COLOR_ARGB, 0xFF, 0x9E, 0x1F, 0x63, | ||
MOVE_TO, 7.94f, 0.69f, | ||
V_LINE_TO, 6.15f, | ||
R_LINE_TO, 3.23f, 5.66f, | ||
R_LINE_TO, 4.68f, 2.75f, | ||
R_CUBIC_TO, 0.04f, -0.07f, 0.04f, -0.18f, -0.03f, -0.29f, | ||
R_LINE_TO, -3.83f, -6.7f, | ||
LINE_TO, 8.18f, 0.86f, | ||
R_CUBIC_TO, -0.06f, -0.11f, -0.15f, -0.17f, -0.23f, -0.17f, | ||
CLOSE, | ||
NEW_PATH, | ||
PATH_COLOR_ARGB, 0xFF, 0x66, 0x2D, 0x91, | ||
MOVE_TO, 15.85f, 14.56f, | ||
R_LINE_TO, -4.68f, -2.75f, | ||
H_LINE_TO, 4.71f, | ||
LINE_TO, 0.03f, 14.56f, | ||
R_CUBIC_TO, 0.04f, 0.08f, 0.13f, 0.12f, 0.26f, 0.12f, | ||
H_LINE_TO, 15.59f, | ||
R_CUBIC_TO, 0.13f, 0, 0.22f, -0.05f, 0.26f, -0.12f, | ||
CLOSE, | ||
NEW_PATH, | ||
PATH_COLOR_ARGB, 0xFF, 0xFF, 0xFF, 0xFF, | ||
MOVE_TO, 4.71f, 11.81f, | ||
R_H_LINE_TO, 6.46f, | ||
LINE_TO, 7.94f, 6.15f, | ||
LINE_TO, 4.71f, 11.81f, | ||
CLOSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/brave_rewards/rewards_extension_panel_handler.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/strings/strcat.h" | ||
#include "brave/browser/brave_rewards/rewards_service_factory.h" | ||
#include "brave/browser/extensions/brave_component_loader.h" | ||
#include "brave/browser/ui/views/brave_actions/brave_actions_container.h" | ||
#include "chrome/browser/extensions/extension_service.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/browser_finder.h" | ||
#include "chrome/browser/ui/browser_window.h" | ||
#include "extensions/browser/extension_system.h" | ||
|
||
namespace brave_rewards { | ||
|
||
namespace { | ||
|
||
constexpr char kRewardsPanelUrl[] = "/brave_rewards_panel.html"; | ||
constexpr char kAdsEnableRelativeUrl[] = "/request_ads_enabled_panel.html"; | ||
|
||
std::string GetExtensionPath(const mojom::RewardsPanelArgs& args) { | ||
switch (args.view) { | ||
case mojom::RewardsPanelView::kDefault: | ||
return kRewardsPanelUrl; | ||
case mojom::RewardsPanelView::kRewardsTour: | ||
return base::StrCat({kRewardsPanelUrl, "#tour"}); | ||
case mojom::RewardsPanelView::kGrantCaptcha: | ||
return base::StrCat({kRewardsPanelUrl, "#grant_", args.data}); | ||
case mojom::RewardsPanelView::kAdaptiveCaptcha: | ||
return base::StrCat({kRewardsPanelUrl, "#load_adaptive_captcha"}); | ||
case mojom::RewardsPanelView::kBraveTalkOptIn: | ||
return kAdsEnableRelativeUrl; | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
RewardsExtensionPanelHandler::~RewardsExtensionPanelHandler() = default; | ||
|
||
bool RewardsExtensionPanelHandler::IsRewardsExtensionPanelURL(const GURL& url) { | ||
return url.SchemeIs("chrome-extension") && | ||
url.host() == brave_rewards_extension_id && | ||
(url.path() == kRewardsPanelUrl || | ||
url.path() == kAdsEnableRelativeUrl); | ||
} | ||
|
||
void RewardsExtensionPanelHandler::OnRewardsPanelRequested( | ||
Browser* browser, | ||
const mojom::RewardsPanelArgs& args) { | ||
DCHECK(browser); | ||
auto* profile = browser->profile(); | ||
|
||
// Start the rewards ledger process if it is not already started | ||
auto* rewards_service = RewardsServiceFactory::GetForProfile(profile); | ||
if (!rewards_service) { | ||
return; | ||
} | ||
|
||
rewards_service->StartProcess(base::DoNothing()); | ||
|
||
// Load the rewards extension if it is not already loaded. | ||
auto* extension_service = | ||
extensions::ExtensionSystem::Get(profile)->extension_service(); | ||
if (!extension_service) { | ||
return; | ||
} | ||
|
||
static_cast<extensions::BraveComponentLoader*>( | ||
extension_service->component_loader()) | ||
->AddRewardsExtension(); | ||
|
||
std::string error; | ||
extensions::BraveActionAPI::ShowActionUI( | ||
browser, brave_rewards_extension_id, | ||
std::make_unique<std::string>(GetExtensionPath(args)), &error); | ||
} | ||
|
||
} // namespace brave_rewards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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_BRAVE_REWARDS_REWARDS_EXTENSION_PANEL_HANDLER_H_ | ||
#define BRAVE_BROWSER_BRAVE_REWARDS_REWARDS_EXTENSION_PANEL_HANDLER_H_ | ||
|
||
#include "brave/browser/brave_rewards/rewards_panel_service.h" | ||
#include "url/gurl.h" | ||
|
||
namespace brave_rewards { | ||
|
||
// A `RewardsPanelService` observer that loads the Rewards extension if required | ||
// and dispatches panel requests to the extension. | ||
class RewardsExtensionPanelHandler : public RewardsPanelService::Observer { | ||
public: | ||
~RewardsExtensionPanelHandler() override; | ||
|
||
static bool IsRewardsExtensionPanelURL(const GURL& url); | ||
|
||
void OnRewardsPanelRequested(Browser* browser, | ||
const mojom::RewardsPanelArgs& args) override; | ||
}; | ||
|
||
} // namespace brave_rewards | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_REWARDS_REWARDS_EXTENSION_PANEL_HANDLER_H_ |
Oops, something went wrong.