Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brave://skus-internals rev1 implementation (uplift to 1.52.x) #18538

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "brave/browser/profiles/brave_renderer_updater_factory.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/skus/skus_service_factory.h"
#include "brave/browser/ui/webui/skus_internals_ui.h"
#include "brave/components/brave_ads/common/features.h"
#include "brave/components/brave_federated/features.h"
#include "brave/components/brave_rewards/browser/rewards_protocol_handler.h"
Expand Down Expand Up @@ -69,6 +70,8 @@
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/playlist/common/buildflags/buildflags.h"
#include "brave/components/playlist/common/features.h"
#include "brave/components/skus/common/features.h"
#include "brave/components/skus/common/skus_internals.mojom.h"
#include "brave/components/skus/common/skus_sdk.mojom.h"
#include "brave/components/speedreader/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
Expand Down Expand Up @@ -534,6 +537,10 @@ void BraveContentBrowserClient::RegisterWebUIInterfaceBrokers(
.Add<commands::mojom::CommandsService>();
}
#endif

if (base::FeatureList::IsEnabled(skus::features::kSkusFeature)) {
registry.ForWebUI<SkusInternalsUI>().Add<skus::mojom::SkusInternals>();
}
}

bool BraveContentBrowserClient::AllowWorkerFingerprinting(
Expand Down
15 changes: 13 additions & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ source_set("ui") {
"webui/brave_web_ui_controller_factory.h",
"webui/brave_webui_source.cc",
"webui/brave_webui_source.h",
"webui/skus_internals_ui.cc",
"webui/skus_internals_ui.h",
]

# It doesn't make sense to view accelerators on iOS & Android.
Expand Down Expand Up @@ -470,6 +472,10 @@ source_set("ui") {
"//brave/components/p3a_utils",
"//brave/components/playlist/common/buildflags",
"//brave/components/resources:static_resources",
"//brave/components/skus/browser",
"//brave/components/skus/browser/resources:generated_resources",
"//brave/components/skus/common",
"//brave/components/skus/common:mojom",
"//brave/components/text_recognition/common/buildflags",
"//brave/components/time_period_storage",
"//brave/components/tor/buildflags",
Expand Down Expand Up @@ -522,6 +528,13 @@ source_set("ui") {
"//url",
]

if (enable_brave_vpn) {
deps += [
"//brave/components/brave_vpn/browser",
"//brave/components/brave_vpn/common",
]
}

if (is_linux) {
sources += [
"views/brave_views_delegate_linux.cc",
Expand Down Expand Up @@ -802,8 +815,6 @@ source_set("ui") {
"webui/brave_vpn/vpn_panel_ui.h",
]
deps += [
"//brave/components/brave_vpn/browser",
"//brave/components/brave_vpn/common",
"//brave/components/brave_vpn/common/mojom",
"//brave/components/brave_vpn/resources:panel_resources",
"//mojo/public/cpp/bindings",
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#include "brave/browser/ui/webui/brave_adblock_ui.h"
#include "brave/browser/ui/webui/brave_rewards_internals_ui.h"
#include "brave/browser/ui/webui/brave_rewards_page_ui.h"
#include "brave/browser/ui/webui/skus_internals_ui.h"
#include "brave/components/brave_federated/features.h"
#include "brave/components/brave_rewards/common/rewards_util.h"
#include "brave/components/brave_shields/common/features.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/constants/webui_url_constants.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/playlist/common/buildflags/buildflags.h"
#include "brave/components/skus/common/features.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -94,6 +96,8 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
return new BraveAdblockUI(web_ui, url.host());
} else if (host == kAdblockInternalsHost) {
return new BraveAdblockInternalsUI(web_ui, url.host());
} else if (host == kSkusInternalsHost) {
return new SkusInternalsUI(web_ui, url.host());
#if !BUILDFLAG(IS_ANDROID)
} else if (host == kWebcompatReporterHost) {
return new WebcompatReporterUI(web_ui, url.host());
Expand Down Expand Up @@ -193,6 +197,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
if (url.host_piece() == kAdblockHost ||
url.host_piece() == kAdblockInternalsHost ||
url.host_piece() == kWebcompatReporterHost ||
(url.host_piece() == kSkusInternalsHost &&
base::FeatureList::IsEnabled(skus::features::kSkusFeature)) ||
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
(url.host_piece() == kIPFSWebUIHost &&
ipfs::IpfsServiceFactory::IsIpfsEnabled(profile)) ||
Expand Down
97 changes: 97 additions & 0 deletions browser/ui/webui/skus_internals_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.

#include "brave/browser/ui/webui/skus_internals_ui.h"

#include <utility>

#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/notreached.h"
#include "base/values.h"
#include "brave/browser/ui/webui/brave_webui_source.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/skus/browser/pref_names.h"
#include "brave/components/skus/browser/resources/grit/skus_internals_generated_map.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "components/grit/brave_components_resources.h"
#include "components/prefs/pref_service.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/components/brave_vpn/browser/brave_vpn_service_helper.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#include "brave/components/brave_vpn/common/pref_names.h"
#endif

SkusInternalsUI::SkusInternalsUI(content::WebUI* web_ui,
const std::string& name)
: content::WebUIController(web_ui),
local_state_(g_browser_process->local_state()) {
CreateAndAddWebUIDataSource(web_ui, name, kSkusInternalsGenerated,
kSkusInternalsGeneratedSize,
IDR_SKUS_INTERNALS_HTML);
}

SkusInternalsUI::~SkusInternalsUI() = default;

void SkusInternalsUI::BindInterface(
mojo::PendingReceiver<skus::mojom::SkusInternals> pending_receiver) {
if (skus_internals_receiver_.is_bound()) {
skus_internals_receiver_.reset();
}

skus_internals_receiver_.Bind(std::move(pending_receiver));
}

void SkusInternalsUI::GetEventLog(GetEventLogCallback callback) {
// TODO(simonhong): Ask log to SkusService
NOTIMPLEMENTED_LOG_ONCE();
}

void SkusInternalsUI::GetSkusState(GetSkusStateCallback callback) {
// TODO(simonhong): Determine which value should be displayed.
const auto& skus_state = local_state_->GetDict(skus::prefs::kSkusState);
base::Value::Dict dict;

#if BUILDFLAG(ENABLE_BRAVE_VPN)
auto* profile = Profile::FromWebUI(web_ui());
if (brave_vpn::IsBraveVPNEnabled(profile->GetPrefs())) {
dict.Set("env",
local_state_->GetString(brave_vpn::prefs::kBraveVPNEnvironment));
}
#endif

for (const auto kv : skus_state) {
// Only shows "skus:xx" kv in webui.
if (!base::StartsWith(kv.first, "skus:")) {
continue;
}

if (auto value = base::JSONReader::Read(kv.second.GetString()); value) {
dict.Set(kv.first, std::move(*value));
}
}

std::string result;
base::JSONWriter::Write(dict, &result);
std::move(callback).Run(result);
}

void SkusInternalsUI::ResetSkusState() {
#if BUILDFLAG(ENABLE_BRAVE_VPN)
// VPN service caches credentials. It should be cleared also
// when skus state is reset. Otherwise, vpn service is still
// in purchased state.
auto* profile = Profile::FromWebUI(web_ui());
if (brave_vpn::IsBraveVPNEnabled(profile->GetPrefs())) {
brave_vpn::ClearSubscriberCredential(local_state_);
}
#endif

local_state_->ClearPref(skus::prefs::kSkusState);
}

WEB_UI_CONTROLLER_TYPE_IMPL(SkusInternalsUI)
40 changes: 40 additions & 0 deletions browser/ui/webui/skus_internals_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.

#ifndef BRAVE_BROWSER_UI_WEBUI_SKUS_INTERNALS_UI_H_
#define BRAVE_BROWSER_UI_WEBUI_SKUS_INTERNALS_UI_H_

#include <string>

#include "base/memory/raw_ptr.h"
#include "brave/components/skus/common/skus_internals.mojom.h"
#include "content/public/browser/web_ui_controller.h"

class PrefService;

class SkusInternalsUI : public content::WebUIController,
public skus::mojom::SkusInternals {
public:
SkusInternalsUI(content::WebUI* web_ui, const std::string& host);
~SkusInternalsUI() override;
SkusInternalsUI(const SkusInternalsUI&) = delete;
SkusInternalsUI& operator=(const SkusInternalsUI&) = delete;

void BindInterface(
mojo::PendingReceiver<skus::mojom::SkusInternals> pending_receiver);

private:
// skus::mojom::SkusInternals overrides:
void GetEventLog(GetEventLogCallback callback) override;
void GetSkusState(GetSkusStateCallback callback) override;
void ResetSkusState() override;

raw_ptr<PrefService> local_state_ = nullptr;
mojo::Receiver<skus::mojom::SkusInternals> skus_internals_receiver_{this};

WEB_UI_CONTROLLER_TYPE_DECL();
};

#endif // BRAVE_BROWSER_UI_WEBUI_SKUS_INTERNALS_UI_H_
2 changes: 1 addition & 1 deletion chromium_src/chrome/common/webui_url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define kChromeUIAttributionInternalsHost \
kChromeUIAttributionInternalsHost, kAdblockHost, kAdblockInternalsHost, \
kRewardsPageHost, kRewardsInternalsHost, kWelcomeHost, kWalletPageHost, \
kTorInternalsHost
kTorInternalsHost, kSkusInternalsHost
#define kChromeUIPerformanceSettingsURL kChromeUIPerformanceSettingsURL_UnUsed
#define kPerformanceSubPage kPerformanceSubPage_UnUsed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const IconBox = styled.span`
}
`

const COUNTRIES = ['AU', 'BR', 'CA', 'CH', 'DE', 'ES', 'FR', 'GB', 'IT', 'JP', 'MX', 'NL', 'SG', 'US']
const COUNTRIES = ['AU', 'BR', 'CA', 'CH', 'DE', 'ES', 'FR', 'GB', 'IT', 'JP',
'MX', 'NL', 'SG', 'US']

function Flag (props: Props) {
const [url, setUrl] = React.useState<undefined | string>(undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const NftCountHeading = styled.h1`

export const PinNftsButton = styled(ActionButton)`
margin: 32px;

&:disabled {
color: ${leo.color.white};
opacity: 0.5;
Expand Down
1 change: 1 addition & 0 deletions components/constants/webui_url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const char kAdblockHost[] = "adblock";
const char kAdblockInternalsHost[] = "adblock-internals";
const char kAdblockJS[] = "brave_adblock.js";
const char kSkusInternalsHost[] = "skus-internals";
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
const char kIPFSWebUIHost[] = "ipfs-internals";
const char kIPFSWebUIURL[] = "chrome://ipfs-internals/";
Expand Down
1 change: 1 addition & 0 deletions components/constants/webui_url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
extern const char kAdblockHost[];
extern const char kAdblockInternalsHost[];
extern const char kAdblockJS[];
extern const char kSkusInternalsHost[];
#if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI)
extern const char kIPFSWebUIHost[];
extern const char kIPFSWebUIURL[];
Expand Down
2 changes: 2 additions & 0 deletions components/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ repack("resources") {
"//brave/components/brave_adblock_ui:generated_resources",
"//brave/components/brave_adblock_ui/adblock_internals:generated_resources",
"//brave/components/cosmetic_filters/resources/data:generated_resources",
"//brave/components/skus/browser/resources:generated_resources",
]

sources += [
"$root_gen_dir/brave/components/brave_adblock/adblock_internals/resources/brave_adblock_internals_generated.pak",
"$root_gen_dir/brave/components/brave_adblock/resources/brave_adblock_generated.pak",
"$root_gen_dir/brave/components/cosmetic_filters/resources/cosmetic_filters_generated.pak",
"$root_gen_dir/brave/components/skus/browser/resources/skus_internals_generated.pak",
]
}

Expand Down
1 change: 1 addition & 0 deletions components/resources/brave_components_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<part file="../brave_perf_predictor/resources/brave_perf_predictor_resources.grdp" />
<part file="../commands/browser/resources/commands_resources.grdp" />
<part file="../playlist/browser/resources/playlist_resources.grdp" />
<part file="../skus/browser/resources/skus_internals_resources.grdp" />
<part file="brave_blank_page_resources.grdp" />
<part file="brave_translate_resources.grdp" />
<part file="speedreader_resources.grdp" />
Expand Down
26 changes: 26 additions & 0 deletions components/skus/browser/resources/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.

import("//brave/components/common/typescript.gni")

transpile_web_ui("skus_internals_ui") {
entry_points = [ [
"skus_internals",
rebase_path("skus_internals.tsx"),
] ]

public_deps = [
"//brave/components/skus/common:mojom_js",
"//mojo/public/mojom/base",
]

resource_name = "skus_internals"
}

pack_web_resources("generated_resources") {
resource_name = "skus_internals"
output_dir = "$root_gen_dir/brave/components/skus/browser/resources"
deps = [ ":skus_internals_ui" ]
}
28 changes: 28 additions & 0 deletions components/skus/browser/resources/skus_internals.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.
-->

<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>SKUs internals</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<script src="/skus_internals.bundle.js"></script>
<style>
body {
margin: 0;
}
</style>
</head>

<body>
<div id="root"></div>
</body>

</html>
Loading