Load vpn urls from post-purchased app menu

fix https://github.com/brave/brave-browser/issues/18573

also some files that are not used by android are moved to mac/win specific
source list.
This commit is contained in:
Simon Hong
2021-10-06 16:38:38 +09:00
parent d540a09b15
commit 504edd531b
11 changed files with 73 additions and 34 deletions
+3 -3
View File
@@ -24,7 +24,7 @@
#include "brave/components/speedreader/buildflags.h"
#include "net/base/features.h"
#if BUILDFLAG(ENABLE_BRAVE_VPN)
#if BUILDFLAG(ENABLE_BRAVE_VPN) && !defined(OS_ANDROID)
#include "brave/components/brave_vpn/features.h"
#endif
@@ -219,12 +219,12 @@ constexpr char kUseDevUpdaterUrlDescription[] =
// file so we turn it off for the macro sections.
// clang-format off
#if BUILDFLAG(ENABLE_BRAVE_VPN)
#if BUILDFLAG(ENABLE_BRAVE_VPN) && !defined(OS_ANDROID)
#define BRAVE_VPN_FEATURE_ENTRIES \
{kBraveVPNFeatureInternalName, \
flag_descriptions::kBraveVPNName, \
flag_descriptions::kBraveVPNDescription, \
kOsMac | kOsWin | kOsAndroid, \
kOsMac | kOsWin, \
FEATURE_VALUE_TYPE(brave_vpn::features::kBraveVPN)},
#else
#define BRAVE_VPN_FEATURE_ENTRIES
+2 -2
View File
@@ -44,7 +44,7 @@
#include "brave/components/brave_wayback_machine/pref_names.h"
#endif
#if BUILDFLAG(ENABLE_BRAVE_VPN)
#if BUILDFLAG(ENABLE_BRAVE_VPN) && !defined(OS_ANDROID)
#include "brave/components/brave_vpn/pref_names.h"
#endif
@@ -127,7 +127,7 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
kBraveGCMChannelStatus));
#endif
#if BUILDFLAG(ENABLE_BRAVE_VPN)
#if BUILDFLAG(ENABLE_BRAVE_VPN) && !defined(OS_ANDROID)
EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
brave_vpn::prefs::kBraveVPNShowButton));
#endif
+1 -1
View File
@@ -178,7 +178,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
brave_sync::Prefs::RegisterProfilePrefs(registry);
#if BUILDFLAG(ENABLE_BRAVE_VPN)
#if BUILDFLAG(ENABLE_BRAVE_VPN) && !defined(OS_ANDROID)
brave_vpn::prefs::RegisterProfilePrefs(registry);
#endif
@@ -5,7 +5,6 @@
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
@@ -15,6 +14,7 @@
#if defined(OS_WIN) || defined(OS_MAC)
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#endif
#if defined(OS_ANDROID)
@@ -304,7 +304,7 @@ bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
case IDC_SEND_BRAVE_VPN_FEEDBACK:
case IDC_ABOUT_BRAVE_VPN:
case IDC_MANAGE_BRAVE_VPN_PLAN:
NOTIMPLEMENTED();
brave::OpenBraveVPNUrls(browser_, id);
break;
default:
LOG(WARNING) << "Received Unimplemented Command: " << id;
+27
View File
@@ -5,7 +5,10 @@
#include "brave/browser/ui/browser_commands.h"
#include <string>
#include "base/files/file_path.h"
#include "brave/app/brave_command_ids.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_vpn/buildflags/buildflags.h"
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
@@ -18,6 +21,7 @@
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
@@ -41,7 +45,9 @@
#endif
#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#include "brave/components/brave_vpn/pref_names.h"
#include "brave/components/brave_vpn/url_constants.h"
#endif
using content::WebContents;
@@ -130,6 +136,27 @@ void ToggleBraveVPNButton(Browser* browser) {
#endif
}
void OpenBraveVPNUrls(Browser* browser, int command_id) {
#if BUILDFLAG(ENABLE_BRAVE_VPN)
std::string target_url;
switch (command_id) {
case IDC_SEND_BRAVE_VPN_FEEDBACK:
target_url = brave_vpn::kFeedbackUrl;
break;
case IDC_ABOUT_BRAVE_VPN:
target_url = brave_vpn::kAboutUrl;
break;
case IDC_MANAGE_BRAVE_VPN_PLAN:
target_url = brave_vpn::GetManageUrl();
break;
default:
NOTREACHED();
}
chrome::AddTabAt(browser, GURL(target_url), -1, true);
#endif
}
void ShowWalletBubble(Browser* browser) {
#if BUILDFLAG(BRAVE_WALLET_ENABLED) && defined(TOOLKIT_VIEWS)
static_cast<BraveBrowserView*>(browser->window())->CreateWalletBubble();
+1
View File
@@ -20,6 +20,7 @@ void CloseWalletBubble(Browser* browser);
void MaybeDistillAndShowSpeedreaderBubble(Browser* browser);
void ShowBraveVPNBubble(Browser* browser);
void ToggleBraveVPNButton(Browser* browser);
void OpenBraveVPNUrls(Browser* browser, int command_id);
} // namespace brave
+7 -7
View File
@@ -15,19 +15,12 @@ static_library("brave_vpn") {
sources = [
"brave_vpn_service.cc",
"brave_vpn_service.h",
"brave_vpn_utils.cc",
"brave_vpn_utils.h",
"features.cc",
"features.h",
"pref_names.cc",
"pref_names.h",
]
deps = [
"//base",
"//brave/components/api_request_helper:api_request_helper",
"//components/keyed_service/core",
"//components/prefs",
"//services/network/public/cpp",
"//third_party/abseil-cpp:absl",
"//url",
@@ -48,6 +41,12 @@ static_library("brave_vpn") {
"brave_vpn_service_desktop.h",
"brave_vpn_service_observer.cc",
"brave_vpn_service_observer.h",
"brave_vpn_utils.cc",
"brave_vpn_utils.h",
"features.cc",
"features.h",
"pref_names.cc",
"pref_names.h",
"switches.h",
"url_constants.h",
]
@@ -74,6 +73,7 @@ static_library("brave_vpn") {
deps += [
":brave_vpn_internal",
":mojom",
"//components/prefs",
"//third_party/icu",
]
}
@@ -32,24 +32,6 @@ constexpr char kRegionContinentKey[] = "continent";
constexpr char kRegionNameKey[] = "name";
constexpr char kRegionNamePrettyKey[] = "name-pretty";
std::string GetManageUrl() {
auto* cmd = base::CommandLine::ForCurrentProcess();
if (!cmd->HasSwitch(brave_vpn::switches::kBraveVPNAccountHost))
return brave_vpn::kManageUrlProd;
const std::string value =
cmd->GetSwitchValueASCII(brave_vpn::switches::kBraveVPNAccountHost);
if (value == "prod")
return brave_vpn::kManageUrlProd;
if (value == "staging")
return brave_vpn::kManageUrlStaging;
if (value == "dev")
return brave_vpn::kManageUrlDev;
NOTREACHED();
return brave_vpn::kManageUrlProd;
}
bool GetVPNCredentialsFromSwitch(brave_vpn::BraveVPNConnectionInfo* info) {
DCHECK(info);
auto* cmd = base::CommandLine::ForCurrentProcess();
@@ -477,7 +459,7 @@ void BraveVpnServiceDesktop::GetProductUrls(GetProductUrlsCallback callback) {
brave_vpn::mojom::ProductUrls urls;
urls.feedback = brave_vpn::kFeedbackUrl;
urls.about = brave_vpn::kAboutUrl;
urls.manage = GetManageUrl();
urls.manage = brave_vpn::GetManageUrl();
std::move(callback).Run(urls.Clone());
}
+26
View File
@@ -5,8 +5,11 @@
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "brave/components/brave_vpn/features.h"
#include "brave/components/brave_vpn/switches.h"
#include "brave/components/brave_vpn/url_constants.h"
namespace brave_vpn {
@@ -14,4 +17,27 @@ bool IsBraveVPNEnabled() {
return base::FeatureList::IsEnabled(brave_vpn::features::kBraveVPN);
}
std::string GetManageUrl() {
auto* cmd = base::CommandLine::ForCurrentProcess();
if (!cmd->HasSwitch(brave_vpn::switches::kBraveVPNAccountHost)) {
#if defined(OFFICIAL_BUILD)
return brave_vpn::kManageUrlProd;
#else
return brave_vpn::kManageUrlDev;
#endif
}
const std::string value =
cmd->GetSwitchValueASCII(brave_vpn::switches::kBraveVPNAccountHost);
if (value == "prod")
return brave_vpn::kManageUrlProd;
if (value == "staging")
return brave_vpn::kManageUrlStaging;
if (value == "dev")
return brave_vpn::kManageUrlDev;
NOTREACHED();
return brave_vpn::kManageUrlProd;
}
} // namespace brave_vpn
+3
View File
@@ -6,9 +6,12 @@
#ifndef BRAVE_COMPONENTS_BRAVE_VPN_BRAVE_VPN_UTILS_H_
#define BRAVE_COMPONENTS_BRAVE_VPN_BRAVE_VPN_UTILS_H_
#include <string>
namespace brave_vpn {
bool IsBraveVPNEnabled();
std::string GetManageUrl();
} // namespace brave_vpn