Skip to content

Commit

Permalink
Merge pull request #5160 from brave/binance-version-2
Browse files Browse the repository at this point in the history
Binance version 2 trading widget
  • Loading branch information
ryanml committed Apr 13, 2020
1 parent 52e38eb commit 9da3e06
Show file tree
Hide file tree
Showing 57 changed files with 6,827 additions and 53 deletions.
12 changes: 12 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import("//brave/build/config.gni")
import("//brave/components/binance/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 @@ -126,12 +127,14 @@ source_set("browser_process") {
"//brave/common",
"//brave/common:pref_names",
"//brave/components/brave_ads/browser",
"//brave/components/binance/browser/buildflags",
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_drm",
"//brave/components/brave_referrals/browser",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser",
"//brave/components/brave_shields/common",
"//brave/components/brave_wallet/browser/buildflags",
"//brave/components/brave_wayback_machine:buildflags",
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/content_settings/core/browser",
Expand Down Expand Up @@ -249,6 +252,15 @@ source_set("browser_process") {
]
}

if (binance_enabled) {
sources += [
"binance/binance_service_factory.cc",
"binance/binance_service_factory.h",
]

deps += [ "//brave/components/binance/browser" ]
}

if (enable_tor) {
deps += [
"//brave/browser/tor",
Expand Down
41 changes: 41 additions & 0 deletions browser/binance/binance_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* 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/binance/binance_service_factory.h"

#include "brave/components/binance/browser/binance_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
BinanceServiceFactory* BinanceServiceFactory::GetInstance() {
return base::Singleton<BinanceServiceFactory>::get();
}

// static
BinanceService* BinanceServiceFactory::GetForProfile(Profile* profile) {
return static_cast<BinanceService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}

BinanceServiceFactory::BinanceServiceFactory()
: BrowserContextKeyedServiceFactory(
"BinanceService",
BrowserContextDependencyManager::GetInstance()) {
}

BinanceServiceFactory::~BinanceServiceFactory() {
}

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

content::BrowserContext* BinanceServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
35 changes: 35 additions & 0 deletions browser/binance/binance_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_BINANCE_BINANCE_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_BINANCE_BINANCE_SERVICE_FACTORY_H_

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

class BinanceService;
class Profile;

class BinanceServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static BinanceService* GetForProfile(Profile* profile);
static BinanceServiceFactory* GetInstance();

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

BinanceServiceFactory();
~BinanceServiceFactory() override;

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

DISALLOW_COPY_AND_ASSIGN(BinanceServiceFactory);
};

#endif // BRAVE_BROWSER_BINANCE_BINANCE_SERVICE_FACTORY_H_
13 changes: 13 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
Expand Down Expand Up @@ -102,6 +103,10 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#include "content/public/common/resource_type.h"
#endif

#if BUILDFLAG(BINANCE_ENABLED)
#include "brave/components/binance/browser/binance_protocol_handler.h"
#endif

namespace {

bool HandleURLReverseOverrideRewrite(GURL* url,
Expand Down Expand Up @@ -186,6 +191,14 @@ bool BraveContentBrowserClient::HandleExternalProtocol(
}
#endif

#if BUILDFLAG(BINANCE_ENABLED)
if (binance::IsBinanceProtocol(url)) {
binance::HandleBinanceProtocol(url, std::move(web_contents_getter),
page_transition, has_user_gesture);
return true;
}
#endif

return ChromeContentBrowserClient::HandleExternalProtocol(
url, std::move(web_contents_getter), child_id, navigation_data,
is_main_frame, page_transition, has_user_gesture, initiating_origin,
Expand Down
7 changes: 7 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/common/brave_wallet_constants.h"
#include "brave/common/pref_names.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
Expand Down Expand Up @@ -203,6 +204,12 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterIntegerPref(kBraveWalletWeb3Provider,
static_cast<int>(BraveWalletWeb3ProviderTypes::ASK));

// Binance widget
#if BUILDFLAG(BINANCE_ENABLED)
registry->RegisterStringPref(kBinanceAccessToken, "");
registry->RegisterStringPref(kBinanceRefreshToken, "");
#endif

// Autocomplete in address bar
registry->RegisterBooleanPref(kAutocompleteEnabled, true);

Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/binance/buildflags.gni")
import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
Expand Down
Loading

0 comments on commit 9da3e06

Please sign in to comment.