Skip to content

Commit

Permalink
Merge pull request #18356 from brave/skus_internals_stub_code
Browse files Browse the repository at this point in the history
brave://skus-internals stub code
  • Loading branch information
simonhong authored and bsclifton committed May 22, 2023
1 parent 87ba4e3 commit a865fe0
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 2 deletions.
7 changes: 7 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/skus/skus_service_factory.h"
#include "brave/components/brave_ads/common/features.h"
#include "brave/browser/ui/webui/skus_internals_ui.h"
#include "brave/components/brave_federated/features.h"
#include "brave/components/brave_rewards/browser/rewards_protocol_handler.h"
#include "brave/components/brave_search/browser/brave_search_default_host.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
5 changes: 5 additions & 0 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,9 @@ source_set("ui") {
"//brave/components/p3a_utils",
"//brave/components/playlist/common/buildflags",
"//brave/components/resources:static_resources",
"//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
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
39 changes: 39 additions & 0 deletions browser/ui/webui/skus_internals_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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/notreached.h"
#include "brave/browser/ui/webui/brave_webui_source.h"
#include "brave/components/skus/browser/resources/grit/skus_internals_generated_map.h"
#include "components/grit/brave_components_resources.h"

SkusInternalsUI::SkusInternalsUI(content::WebUI* web_ui,
const std::string& name)
: content::WebUIController(web_ui) {
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();
}

WEB_UI_CONTROLLER_TYPE_IMPL(SkusInternalsUI)
34 changes: 34 additions & 0 deletions browser/ui/webui/skus_internals_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 "brave/components/skus/common/skus_internals.mojom.h"
#include "content/public/browser/web_ui_controller.h"

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;

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
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>
17 changes: 17 additions & 0 deletions components/skus/browser/resources/skus_internals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 * as React from 'react'
import { render } from 'react-dom'

function App() {
return (
<div>Log here</div>
)
}

document.addEventListener('DOMContentLoaded', () => {
render(<App />, document.getElementById('root'))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit-part>
<include name="IDR_SKUS_INTERNALS_HTML" file="../skus/browser/resources/skus_internals.html" type="BINDATA" />
</grit-part>
9 changes: 9 additions & 0 deletions components/skus/browser/resources/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig",
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.d.ts",
"../../definitions/*.d.ts"
]
}
5 changes: 4 additions & 1 deletion components/skus/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ static_library("common") {
}

mojom("mojom") {
sources = [ "skus_sdk.mojom" ]
sources = [
"skus_internals.mojom",
"skus_sdk.mojom",
]

deps = [ "//mojo/public/mojom/base" ]
}
10 changes: 10 additions & 0 deletions components/skus/common/skus_internals.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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/.

module skus.mojom;

interface SkusInternals {
GetEventLog() => (string response);
};
4 changes: 4 additions & 0 deletions resources/resource_ids.spec
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,9 @@
"<(SHARED_INTERMEDIATE_DIR)/brave/web-ui-tip_panel/tip_panel.grd": {
"META": {"sizes": {"includes": [100]}},
"includes": [61400]
},
"<(SHARED_INTERMEDIATE_DIR)/brave/web-ui-skus_internals/skus_internals.grd": {
"META": {"sizes": {"includes": [100]}},
"includes": [61550],
}
}

0 comments on commit a865fe0

Please sign in to comment.