Skip to content

Commit

Permalink
Merge pull request #2388 from brave/donate-tip
Browse files Browse the repository at this point in the history
Replace donation with tip strings
  • Loading branch information
NejcZdovc authored May 8, 2019
2 parents ad6186f + 517a590 commit a8fac15
Show file tree
Hide file tree
Showing 66 changed files with 293 additions and 316 deletions.
4 changes: 2 additions & 2 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ source_set("browser_process") {
"brave_stats_updater_util.h",
"brave_tab_helpers.cc",
"brave_tab_helpers.h",
"brave_rewards/donations_dialog.cc",
"brave_rewards/donations_dialog.h",
"brave_rewards/tip_dialog.cc",
"brave_rewards/tip_dialog.h",
"browser_context_keyed_service_factories.cc",
"browser_context_keyed_service_factories.h",
"browsing_data/brave_clear_browsing_data.cc",
Expand Down
21 changes: 0 additions & 21 deletions browser/brave_rewards/donations_dialog.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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/brave_rewards/donations_dialog.h"
#include "brave/browser/brave_rewards/tip_dialog.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -33,12 +33,12 @@ constexpr int kDialogMargin = 25;
constexpr int kDialogMinHeight = 400;
constexpr int kDialogMaxHeight = 700;

// A ui::WebDialogDelegate that specifies the donation dialog appearance.
class DonationDialogDelegate : public ui::WebDialogDelegate {
// A ui::WebDialogDelegate that specifies the tip dialog appearance.
class TipDialogDelegate : public ui::WebDialogDelegate {
public:
explicit DonationDialogDelegate(WebContents* initiator,
explicit TipDialogDelegate(WebContents* initiator,
std::string publisher_key);
~DonationDialogDelegate() override;
~TipDialogDelegate() override;

ui::ModalType GetDialogModalType() const override;
base::string16 GetDialogTitle() const override;
Expand All @@ -55,39 +55,39 @@ class DonationDialogDelegate : public ui::WebDialogDelegate {
WebContents* initiator_;
const std::string publisher_key_;

DISALLOW_COPY_AND_ASSIGN(DonationDialogDelegate);
DISALLOW_COPY_AND_ASSIGN(TipDialogDelegate);
};

DonationDialogDelegate::DonationDialogDelegate(WebContents* initiator,
TipDialogDelegate::TipDialogDelegate(WebContents* initiator,
std::string publisher_key)
: initiator_(initiator),
publisher_key_(publisher_key) {
}

DonationDialogDelegate::~DonationDialogDelegate() {
TipDialogDelegate::~TipDialogDelegate() {
}

ui::ModalType DonationDialogDelegate::GetDialogModalType() const {
ui::ModalType TipDialogDelegate::GetDialogModalType() const {
// Not used, returning dummy value.
NOTREACHED();
return ui::MODAL_TYPE_WINDOW;
}

base::string16 DonationDialogDelegate::GetDialogTitle() const {
base::string16 TipDialogDelegate::GetDialogTitle() const {
// Only used on Windows?
return base::string16();
}

GURL DonationDialogDelegate::GetDialogContentURL() const {
return GURL(kBraveUIDonateURL);
GURL TipDialogDelegate::GetDialogContentURL() const {
return GURL(kBraveUITipURL);
}

void DonationDialogDelegate::GetWebUIMessageHandlers(
void TipDialogDelegate::GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* /* handlers */) const {
// DonationsWebUI should add its own message handlers.
// TipWebUI should add its own message handlers.
}

void DonationDialogDelegate::GetDialogSize(gfx::Size* size) const {
void TipDialogDelegate::GetDialogSize(gfx::Size* size) const {
DCHECK(size);

gfx::Size target_size;
Expand All @@ -110,33 +110,33 @@ void DonationDialogDelegate::GetDialogSize(gfx::Size* size) const {
size->SetSize(target_size.width() - kDialogMargin, max_height);
}

std::string DonationDialogDelegate::GetDialogArgs() const {
std::string TipDialogDelegate::GetDialogArgs() const {
std::string data;
base::DictionaryValue dialog_args;
dialog_args.SetString("publisherKey", publisher_key_);
base::JSONWriter::Write(dialog_args, &data);
return data;
}

void DonationDialogDelegate::OnDialogClosed(
void TipDialogDelegate::OnDialogClosed(
const std::string& /* json_retval */) {
}

void DonationDialogDelegate::OnCloseContents(WebContents* /* source */,
void TipDialogDelegate::OnCloseContents(WebContents* /* source */,
bool* out_close_dialog) {
*out_close_dialog = true;
}

bool DonationDialogDelegate::ShouldShowDialogTitle() const {
bool TipDialogDelegate::ShouldShowDialogTitle() const {
return false;
}

} // namespace

namespace brave_rewards {

void OpenDonationDialog(WebContents* initiator,
const std::string& publisher_key) {
void OpenTipDialog(WebContents* initiator,
const std::string& publisher_key) {
content::WebContents* outermost_web_contents =
guest_view::GuestViewBase::GetTopLevelWebContents(initiator);
gfx::Size host_size = outermost_web_contents->GetContainerBounds().size();
Expand All @@ -147,7 +147,7 @@ void OpenDonationDialog(WebContents* initiator,
// resize)
ShowConstrainedWebDialogWithAutoResize(
initiator->GetBrowserContext(),
std::make_unique<DonationDialogDelegate>(initiator, publisher_key),
std::make_unique<TipDialogDelegate>(initiator, publisher_key),
initiator, min_size, max_size);
}

Expand Down
22 changes: 22 additions & 0 deletions browser/brave_rewards/tip_dialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright 2019 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_TIP_DIALOG_H_
#define BRAVE_BROWSER_BRAVE_REWARDS_TIP_DIALOG_H_

#include <string>

namespace content {
class WebContents;
}

namespace brave_rewards {

void OpenTipDialog(content::WebContents* initiator,
const std::string& publisher_key);

}

#endif // BRAVE_BROWSER_BRAVE_REWARDS_TIP_DIALOG_H_
16 changes: 8 additions & 8 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <utility>

#include "base/bind.h"
#include "brave/browser/brave_rewards/donations_dialog.h"
#include "brave/browser/brave_rewards/tip_dialog.h"
#include "brave/common/extensions/api/brave_rewards.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_rewards/browser/rewards_service_factory.h"
Expand Down Expand Up @@ -41,19 +41,19 @@ ExtensionFunction::ResponseAction BraveRewardsCreateWalletFunction::Run() {
return RespondNow(NoArguments());
}

BraveRewardsDonateToSiteFunction::~BraveRewardsDonateToSiteFunction() {
BraveRewardsTipSiteFunction::~BraveRewardsTipSiteFunction() {
}

ExtensionFunction::ResponseAction BraveRewardsDonateToSiteFunction::Run() {
std::unique_ptr<brave_rewards::DonateToSite::Params> params(
brave_rewards::DonateToSite::Params::Create(*args_));
ExtensionFunction::ResponseAction BraveRewardsTipSiteFunction::Run() {
std::unique_ptr<brave_rewards::TipSite::Params> params(
brave_rewards::TipSite::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

// Sanity check: don't allow donations in private / tor contexts,
// Sanity check: don't allow tips in private / tor contexts,
// although the command should not have been enabled in the first place.
Profile* profile = Profile::FromBrowserContext(browser_context());
if (profile->IsOffTheRecord()) {
return RespondNow(Error("Cannot donate to site in a private context"));
return RespondNow(Error("Cannot tip to site in a private context"));
}

// Get web contents for this tab
Expand All @@ -69,7 +69,7 @@ ExtensionFunction::ResponseAction BraveRewardsDonateToSiteFunction::Run() {
return RespondNow(Error(tabs_constants::kTabNotFoundError,
base::IntToString(params->tab_id)));
}
::brave_rewards::OpenDonationDialog(contents, params->publisher_key);
::brave_rewards::OpenTipDialog(contents, params->publisher_key);

return RespondNow(NoArguments());
}
Expand Down
6 changes: 3 additions & 3 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class BraveRewardsCreateWalletFunction : public UIThreadExtensionFunction {
ResponseAction Run() override;
};

class BraveRewardsDonateToSiteFunction : public UIThreadExtensionFunction {
class BraveRewardsTipSiteFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.donateToSite", UNKNOWN)
DECLARE_EXTENSION_FUNCTION("braveRewards.tipSite", UNKNOWN)

protected:
~BraveRewardsDonateToSiteFunction() override;
~BraveRewardsTipSiteFunction() override;

ResponseAction Run() override;
};
Expand Down
2 changes: 1 addition & 1 deletion browser/importer/brave_profile_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void BraveProfileWriter::SetWalletProperties(brave_rewards::RewardsService*
site->provider = publisher.provider;

// Add `recurring_donation` entry
rewards_service->OnDonate(publisher.key,
rewards_service->OnTip(publisher.key,
amount_in_bat,
true,
std::move(site));
Expand Down
2 changes: 1 addition & 1 deletion browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"includes": [38700],
},
# This file is generated during the build.
"<(ROOT_GEN_DIR)/brave/web-ui-brave_donate/brave_donate.grd": {
"<(ROOT_GEN_DIR)/brave/web-ui-brave_tip/brave_tip.grd": {
"includes": [38800],
},
"brave/components/resources/brave_components_strings.grd": {
Expand Down
6 changes: 3 additions & 3 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ source_set("ui") {
"webui/basic_ui.h",
"webui/brave_adblock_ui.cc",
"webui/brave_adblock_ui.h",
"webui/brave_donate_ui.cc",
"webui/brave_donate_ui.h",
"webui/brave_tip_ui.cc",
"webui/brave_tip_ui.h",
"webui/brave_md_settings_ui.cc",
"webui/brave_md_settings_ui.h",
"webui/brave_new_tab_ui.cc",
Expand Down Expand Up @@ -124,7 +124,7 @@ source_set("ui") {
"//brave/components/brave_extension:generated_resources",
"//brave/components/brave_new_tab_ui:generated_resources",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_rewards/resources:donate_generated_resources",
"//brave/components/brave_rewards/resources:tip_generated_resources",
"//brave/components/brave_rewards/resources:static_resources",
"//brave/components/brave_rewards/resources:ui_generated_resources",
"//brave/components/brave_sync",
Expand Down
20 changes: 0 additions & 20 deletions browser/ui/webui/brave_donate_ui.h

This file was deleted.

Loading

0 comments on commit a8fac15

Please sign in to comment.