Skip to content

Commit

Permalink
Merge pull request #6828 from brave/crypto-dot-com-1.16
Browse files Browse the repository at this point in the history
Adding Crypto.com widget to the NTP [1.16]
  • Loading branch information
kjozwiak committed Oct 19, 2020
2 parents 49ca725 + 79b178f commit 34964dc
Show file tree
Hide file tree
Showing 68 changed files with 3,680 additions and 23 deletions.
17 changes: 17 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/components/brave_together/buildflags/buildflags.gni")
import("//brave/components/moonpay/browser/buildflags/buildflags.gni")
import("//brave/components/gemini/browser/buildflags/buildflags.gni")
import("//brave/components/crypto_dot_com/browser/buildflags/buildflags.gni")
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")
import("//brave/components/brave_perf_predictor/browser/buildflags/buildflags.gni")
Expand Down Expand Up @@ -127,6 +128,7 @@ source_set("browser_process") {
"//brave/components/brave_ads/browser",
"//brave/components/binance/browser/buildflags",
"//brave/components/gemini/browser/buildflags",
"//brave/components/crypto_dot_com/browser/buildflags",
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_drm",
"//brave/components/brave_referrals/buildflags",
Expand Down Expand Up @@ -273,6 +275,21 @@ source_set("browser_process") {
]
}

if (crypto_dot_com_enabled) {
sources += [
"crypto_dot_com/crypto_dot_com_service_factory.cc",
"crypto_dot_com/crypto_dot_com_service_factory.h",
]

deps += [
"//base",
"//brave/browser/profiles",
"//brave/components/crypto_dot_com/browser",
"//brave/components/crypto_dot_com/common",
"//components/keyed_service/content",
]
}

if (ipfs_enabled) {
sources += [
"ipfs/content_browser_client_helper.cc",
Expand Down
12 changes: 11 additions & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/moonpay/browser/buildflags/buildflags.h"
#include "brave/components/crypto_dot_com/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "chrome/browser/net/prediction_options.h"
Expand Down Expand Up @@ -80,6 +81,11 @@
#include "brave/components/speedreader/speedreader_service.h"
#endif

#if BUILDFLAG(CRYPTO_DOT_COM_ENABLED)
#include "brave/components/crypto_dot_com/browser/crypto_dot_com_pref_utils.h"
#include "brave/components/crypto_dot_com/common/pref_names.h"
#endif

#if defined(OS_ANDROID)
#include "components/feed/core/shared_prefs/pref_names.h"
#include "components/ntp_tiles/pref_names.h"
Expand Down Expand Up @@ -236,7 +242,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kNewTabPageShowStats, true);
registry->RegisterBooleanPref(kNewTabPageShowRewards, true);
registry->RegisterBooleanPref(kNewTabPageShowBinance, true);
registry->RegisterBooleanPref(kNewTabPageShowTogether, true);
registry->RegisterBooleanPref(kNewTabPageShowTogether, false);
registry->RegisterBooleanPref(kNewTabPageShowAddCard, true);
registry->RegisterBooleanPref(kNewTabPageShowGemini, true);

Expand Down Expand Up @@ -283,6 +289,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
moonpay::MoonpayPrefUtils::RegisterPrefs(registry);
#endif

#if BUILDFLAG(CRYPTO_DOT_COM_ENABLED)
crypto_dot_com::RegisterPrefs(registry);
#endif

#if !defined(OS_ANDROID)
BraveOmniboxClientImpl::RegisterPrefs(registry);
#endif
Expand Down
47 changes: 47 additions & 0 deletions browser/crypto_dot_com/crypto_dot_com_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2020 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/crypto_dot_com/crypto_dot_com_service_factory.h"

#include "brave/browser/profiles/profile_util.h"
#include "brave/components/crypto_dot_com/browser/crypto_dot_com_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"

// static
CryptoDotComServiceFactory* CryptoDotComServiceFactory::GetInstance() {
return base::Singleton<CryptoDotComServiceFactory>::get();
}

// static
CryptoDotComService*CryptoDotComServiceFactory::GetForProfile(
Profile* profile) {
if (!brave::IsRegularProfile(profile)) {
return nullptr;
}

return static_cast<CryptoDotComService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}

CryptoDotComServiceFactory::CryptoDotComServiceFactory()
: BrowserContextKeyedServiceFactory(
"CryptoDotComService",
BrowserContextDependencyManager::GetInstance()) {
}

CryptoDotComServiceFactory::~CryptoDotComServiceFactory() {
}

KeyedService* CryptoDotComServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new CryptoDotComService(Profile::FromBrowserContext(context));
}

content::BrowserContext* CryptoDotComServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
35 changes: 35 additions & 0 deletions browser/crypto_dot_com/crypto_dot_com_service_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (c) 2020 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_CRYPTO_DOT_COM_CRYPTO_DOT_COM_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_CRYPTO_DOT_COM_CRYPTO_DOT_COM_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

class CryptoDotComService;
class Profile;

class CryptoDotComServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static CryptoDotComService* GetForProfile(Profile* profile);
static CryptoDotComServiceFactory* GetInstance();

private:
friend struct base::DefaultSingletonTraits<CryptoDotComServiceFactory>;

CryptoDotComServiceFactory();
~CryptoDotComServiceFactory() override;

// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;

DISALLOW_COPY_AND_ASSIGN(CryptoDotComServiceFactory);
};

#endif // BRAVE_BROWSER_CRYPTO_DOT_COM_CRYPTO_DOT_COM_SERVICE_FACTORY_H_
18 changes: 18 additions & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/components/gemini/browser/buildflags/buildflags.gni")
import("//brave/components/crypto_dot_com/browser/buildflags/buildflags.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
Expand Down Expand Up @@ -182,6 +183,23 @@ source_set("extensions") {
"//brave/components/ntp_widget_utils/browser",
]
}
if (crypto_dot_com_enabled) {
sources += [
"api/crypto_dot_com_api.cc",
"api/crypto_dot_com_api.h",
]
deps += [
"//brave/browser/profiles",
"//brave/common",
"//brave/components/crypto_dot_com/browser",
"//brave/components/crypto_dot_com/common/",
"//brave/components/ntp_widget_utils/browser",
"//chrome/browser/extensions",
"//components/prefs",
"//extensions/browser",
"//extensions/common:common_constants",
]
}
}

group("resources") {
Expand Down
Loading

0 comments on commit 34964dc

Please sign in to comment.