-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "Desktop Welcome Pages" feature
- Loading branch information
1 parent
52426ef
commit 56f5042
Showing
42 changed files
with
1,761 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) 2024 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/brave_education/brave_education_ui.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "brave/browser/ui/webui/brave_education/education_page_handler.h" | ||
#include "brave/browser/ui/webui/brave_webui_source.h" | ||
#include "brave/browser/ui/webui/browser_command/brave_browser_command_handler.h" | ||
#include "brave/components/brave_education/common/education_content_urls.h" | ||
#include "brave/components/brave_education/resources/grit/brave_education_generated_map.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/webui/webui_util.h" | ||
#include "chrome/grit/branded_strings.h" | ||
#include "components/grit/brave_components_resources.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/browser/web_ui.h" | ||
#include "content/public/browser/web_ui_data_source.h" | ||
#include "services/network/public/mojom/content_security_policy.mojom.h" | ||
#include "ui/base/webui/web_ui_util.h" | ||
|
||
namespace brave_education { | ||
|
||
namespace { | ||
|
||
std::vector<browser_command::mojom::Command> GetSupportedCommands( | ||
const GURL& webui_url) { | ||
using browser_command::mojom::Command; | ||
|
||
auto content_type = EducationContentTypeFromBrowserURL(webui_url.spec()); | ||
if (!content_type) { | ||
return {}; | ||
} | ||
|
||
switch (*content_type) { | ||
case EducationContentType::kGettingStartedAdBlock: | ||
return {Command::kOpenContentFilterSettings, | ||
Command::kOpenShieldsSettings, Command::kOpenVPNOnboarding}; | ||
case EducationContentType::kGettingStartedWeb3: | ||
return {Command::kOpenRewardsOnboarding, Command::kOpenWalletOnboarding, | ||
Command::kOpenWeb3Settings}; | ||
case EducationContentType::kGettingStartedPrivacy: | ||
return {Command::kOpenPrivacySettings, Command::kOpenVPNOnboarding}; | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
BraveEducationUI::BraveEducationUI(content::WebUI* web_ui, | ||
const std::string& host_name) | ||
: ui::MojoWebUIController(web_ui) { | ||
content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd( | ||
Profile::FromWebUI(web_ui), host_name); | ||
|
||
webui::SetupWebUIDataSource( | ||
source, | ||
base::make_span(kBraveEducationGenerated, kBraveEducationGeneratedSize), | ||
IDR_BRAVE_EDUCATION_HTML); | ||
|
||
AddBackgroundColorToSource(source, web_ui->GetWebContents()); | ||
|
||
static constexpr webui::LocalizedString kStrings[] = { | ||
{"headerText", IDS_WELCOME_HEADER}}; | ||
source->AddLocalizedStrings(kStrings); | ||
|
||
// Allow embedding of iframe from brave.com. | ||
source->OverrideContentSecurityPolicy( | ||
network::mojom::CSPDirectiveName::ChildSrc, | ||
"child-src chrome://webui-test https://brave.com/;"); | ||
} | ||
|
||
BraveEducationUI::~BraveEducationUI() = default; | ||
|
||
void BraveEducationUI::BindInterface( | ||
mojo::PendingReceiver<EducationPageHandlerFactory> pending_receiver) { | ||
if (page_factory_receiver_.is_bound()) { | ||
page_factory_receiver_.reset(); | ||
} | ||
page_factory_receiver_.Bind(std::move(pending_receiver)); | ||
} | ||
|
||
void BraveEducationUI::BindInterface( | ||
mojo::PendingReceiver<CommandHandlerFactory> pending_receiver) { | ||
if (command_handler_factory_receiver_.is_bound()) { | ||
command_handler_factory_receiver_.reset(); | ||
} | ||
command_handler_factory_receiver_.Bind(std::move(pending_receiver)); | ||
} | ||
|
||
void BraveEducationUI::CreatePageHandler( | ||
mojo::PendingReceiver<mojom::EducationPageHandler> handler) { | ||
page_handler_ = std::make_unique<EducationPageHandler>(std::move(handler)); | ||
} | ||
|
||
void BraveEducationUI::CreateBrowserCommandHandler( | ||
mojo::PendingReceiver<browser_command::mojom::CommandHandler> | ||
pending_handler) { | ||
command_handler_ = std::make_unique<BraveBrowserCommandHandler>( | ||
std::move(pending_handler), Profile::FromWebUI(web_ui()), | ||
GetSupportedCommands(web_ui()->GetWebContents()->GetVisibleURL())); | ||
} | ||
|
||
WEB_UI_CONTROLLER_TYPE_IMPL(BraveEducationUI) | ||
|
||
} // namespace brave_education |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) 2024 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_BRAVE_EDUCATION_BRAVE_EDUCATION_UI_H_ | ||
#define BRAVE_BROWSER_UI_WEBUI_BRAVE_EDUCATION_BRAVE_EDUCATION_UI_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/brave_education/common/education_page.mojom.h" | ||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/pending_remote.h" | ||
#include "mojo/public/cpp/bindings/receiver.h" | ||
#include "ui/webui/mojo_web_ui_controller.h" | ||
#include "ui/webui/resources/js/browser_command/browser_command.mojom.h" | ||
|
||
namespace content { | ||
class WebUI; | ||
} | ||
|
||
namespace brave_education { | ||
|
||
// The Web UI controller for the Brave product education page, which displays | ||
// production education website content in an iframe. | ||
class BraveEducationUI : public ui::MojoWebUIController, | ||
public mojom::EducationPageHandlerFactory, | ||
public browser_command::mojom::CommandHandlerFactory { | ||
public: | ||
BraveEducationUI(content::WebUI* web_ui, const std::string& host_name); | ||
~BraveEducationUI() override; | ||
|
||
BraveEducationUI(const BraveEducationUI&) = delete; | ||
BraveEducationUI& operator=(const BraveEducationUI&) = delete; | ||
|
||
void BindInterface( | ||
mojo::PendingReceiver<EducationPageHandlerFactory> pending_receiver); | ||
|
||
void BindInterface( | ||
mojo::PendingReceiver<CommandHandlerFactory> pending_receiver); | ||
|
||
// mojom::EducationPageHandlerFactory: | ||
void CreatePageHandler( | ||
mojo::PendingReceiver<mojom::EducationPageHandler> handler) override; | ||
|
||
// browser_command::mojom::CommandHandlerFactory: | ||
void CreateBrowserCommandHandler( | ||
mojo::PendingReceiver<browser_command::mojom::CommandHandler> handler) | ||
override; | ||
|
||
private: | ||
mojo::Receiver<EducationPageHandlerFactory> page_factory_receiver_{this}; | ||
mojo::Receiver<CommandHandlerFactory> command_handler_factory_receiver_{this}; | ||
std::unique_ptr<mojom::EducationPageHandler> page_handler_; | ||
std::unique_ptr<browser_command::mojom::CommandHandler> command_handler_; | ||
|
||
WEB_UI_CONTROLLER_TYPE_DECL(); | ||
}; | ||
|
||
} // namespace brave_education | ||
|
||
#endif // BRAVE_BROWSER_UI_WEBUI_BRAVE_EDUCATION_BRAVE_EDUCATION_UI_H_ |
Oops, something went wrong.