-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move more browser components to monorepo (#7239)
* π¦ remake the repository structure * πΏ incorporate subsequent whisthq/brave-core changes * π more fixes and upstream changes
- Loading branch information
Roshan Padaki
authored
Sep 14, 2022
1 parent
fdcd360
commit 465b81c
Showing
119 changed files
with
16,839 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
source_set("extensions") { | ||
sources = [ | ||
"//whist/browser/hybrid/browser/extensions/whist_component_loader.cc", | ||
"//whist/browser/hybrid/browser/extensions/whist_component_loader.h", | ||
] | ||
|
||
deps = [ | ||
":resources", | ||
"//base", | ||
"//brave/browser/extensions", | ||
] | ||
} | ||
|
||
group("resources") { | ||
deps = [ | ||
"//brave/components/whist_extension:generated_resources", | ||
"//brave/components/whist_extension:static_resources", | ||
] | ||
} |
22 changes: 22 additions & 0 deletions
22
browser/hybrid/browser/extensions/whist_component_loader.cc
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,22 @@ | ||
#include "whist_component_loader.h" | ||
|
||
namespace extensions { | ||
WhistComponentLoader::WhistComponentLoader(ExtensionSystem* extension_system, | ||
Profile* profile) | ||
: BraveComponentLoader(extension_system, profile) {} | ||
|
||
WhistComponentLoader::~WhistComponentLoader() {} | ||
|
||
void WhistComponentLoader::AddWhistExtension() { | ||
if (!Exists(whist_extension_id)) { | ||
base::FilePath whist_extension_path(FILE_PATH_LITERAL("")); | ||
whist_extension_path = whist_extension_path.Append(FILE_PATH_LITERAL("whist_extension")); | ||
Add(IDR_WHIST_EXTENSION, whist_extension_path); | ||
} | ||
} | ||
|
||
void WhistComponentLoader::AddDefaultComponentExtensions(bool skip_session_components) { | ||
BraveComponentLoader::AddDefaultComponentExtensions(skip_session_components); | ||
AddWhistExtension(); | ||
} | ||
} // namespace extensions |
22 changes: 22 additions & 0 deletions
22
browser/hybrid/browser/extensions/whist_component_loader.h
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,22 @@ | ||
#ifndef WHIST_BROWSER_EXTENSIONS_WHIST_COMPONENT_LOADER_H | ||
#define WHIST_BROWSER_EXTENSIONS_WHIST_COMPONENT_LOADER_H | ||
|
||
#include "src/brave/browser/extensions/brave_component_loader.h" | ||
#include "brave/components/whist_extension/grit/whist_extension.h" | ||
#include "extensions/common/constants.h" | ||
|
||
namespace extensions { | ||
class WhistComponentLoader : public BraveComponentLoader { | ||
public: | ||
WhistComponentLoader(ExtensionSystem* extension_system, | ||
Profile* browser_context); | ||
WhistComponentLoader(const WhistComponentLoader&) = delete; | ||
WhistComponentLoader& operator=(const WhistComponentLoader&) = delete; | ||
~WhistComponentLoader() override; | ||
|
||
void AddDefaultComponentExtensions(bool skip_session_components) override; | ||
void AddWhistExtension(); | ||
}; | ||
} // namespace extensions | ||
|
||
#endif // WHIST_BROWSER_EXTENSIONS_WHIST_COMPONENT_LOADER_H |
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,7 @@ | ||
import("//extensions/buildflags/buildflags.gni") | ||
|
||
whist_chrome_browser_deps = [ "//whist/browser/hybrid/browser/ui" ] | ||
|
||
if (enable_extensions) { | ||
whist_chrome_browser_deps += [ "//whist/browser/hybrid/browser/extensions" ] | ||
} |
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,14 @@ | ||
source_set("ui") { | ||
sources = [ | ||
"webui/cloud_tabs_ui/cloud_tabs_ui.cc", | ||
"webui/cloud_tabs_ui/cloud_tabs_ui.h", | ||
"webui/whist_web_ui_controller_factory.cc", | ||
"webui/whist_web_ui_controller_factory.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//brave/browser/ui", | ||
"//whist/browser/hybrid/components/cloud_tabs_ui:generated_resources", | ||
] | ||
} |
80 changes: 80 additions & 0 deletions
80
browser/hybrid/browser/ui/webui/cloud_tabs_ui/cloud_tabs_ui.cc
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,80 @@ | ||
// Copyright 2022 Whist Technologies, Inc. All rights reserved. | ||
|
||
#include "cloud_tabs_ui.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/rand_util.h" | ||
#include "brave/common/pref_names.h" | ||
#include "brave/browser/ui/webui/brave_webui_source.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/profiles/profile_manager.h" | ||
#include "chrome/common/url_constants.h" | ||
#include "components/prefs/pref_change_registrar.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/public/browser/web_ui.h" | ||
#include "content/public/browser/web_ui_data_source.h" | ||
#include "content/public/browser/web_ui_message_handler.h" | ||
#include "content/public/browser/web_ui_controller.h" | ||
#include "content/public/browser/web_ui_data_source.h" | ||
#include "content/public/common/url_constants.h" | ||
#include "components/grit/brave_components_resources.h" | ||
|
||
#include "whist/browser/hybrid/components/cloud_tabs_ui/resources/grit/cloud_tabs_ui_generated_map.h" | ||
|
||
using content::WebUIMessageHandler; | ||
|
||
namespace { | ||
class CloudUIHandler : public WebUIMessageHandler { | ||
public: | ||
CloudUIHandler() {} | ||
CloudUIHandler(const CloudUIHandler&) = delete; | ||
CloudUIHandler& operator=(const CloudUIHandler&) = delete; | ||
|
||
// WebUIMessageHandler implementation. | ||
void RegisterMessages() override; | ||
|
||
// Added by Whist | ||
private: | ||
void OnWhistMandelboxInfoChanged(); | ||
|
||
PrefChangeRegistrar local_state_change_registrar_; | ||
PrefChangeRegistrar profile_state_change_registrar_; | ||
}; | ||
|
||
// Added by Whist | ||
void CloudUIHandler::RegisterMessages() {} | ||
} | ||
|
||
std::string RandomString() { | ||
std::string random_string; | ||
for (int index = 0; index < 32; ++index) { | ||
random_string.append(1, static_cast<char>(base::RandInt('A', 'Z'))); | ||
} | ||
return random_string; | ||
} | ||
|
||
WhistCloudUI::WhistCloudUI(content::WebUI* web_ui, const GURL& url) | ||
: content::WebUIController(web_ui) { | ||
content::WebUIDataSource* source = CreateAndAddWebUIDataSource( | ||
web_ui, content::kCloudScheme, kCloudTabsUiGenerated, kCloudTabsUiGeneratedSize, | ||
IDR_WHIST_CLOUD_TABS_UI_HTML, | ||
/*disable_trusted_types_csp=*/true); | ||
|
||
web_ui->AddMessageHandler(std::make_unique<CloudUIHandler>()); | ||
|
||
// Generate random nonce and set security policy accordingly | ||
std::string random_nonce = RandomString(); | ||
source->OverrideContentSecurityPolicy( | ||
network::mojom::CSPDirectiveName::ScriptSrc, | ||
"script-src cloud: chrome://resources 'nonce-" + random_nonce + "' 'self';"); | ||
source->AddString("whistUINonce", random_nonce); | ||
// Required resources. | ||
source->UseStringsJs(); | ||
source->SetDefaultResource(IDR_WHIST_CLOUD_TABS_UI_HTML); | ||
|
||
Profile* profile = Profile::FromWebUI(web_ui); | ||
content::WebUIDataSource::Add(profile, source); | ||
} | ||
|
||
WhistCloudUI::~WhistCloudUI() = default; |
19 changes: 19 additions & 0 deletions
19
browser/hybrid/browser/ui/webui/cloud_tabs_ui/cloud_tabs_ui.h
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,19 @@ | ||
// Copyright 2022 Whist Technologies, Inc. All rights reserved. | ||
|
||
#ifndef CHROME_BROWSER_UI_WEBUI_WHIST_CLOUD_WHIST_CLOUD_UI_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_WHIST_CLOUD_WHIST_CLOUD_UI_H_ | ||
|
||
#include "content/public/browser/web_ui_controller.h" | ||
|
||
// The WebUI for cloud:*. | ||
class WhistCloudUI : public content::WebUIController { | ||
public: | ||
WhistCloudUI(content::WebUI* web_ui, const GURL& url); | ||
|
||
WhistCloudUI(const WhistCloudUI&) = delete; | ||
WhistCloudUI& operator=(const WhistCloudUI&) = delete; | ||
|
||
~WhistCloudUI() override; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_WHIST_CLOUD_WHIST_CLOUD_UI_H_ |
59 changes: 59 additions & 0 deletions
59
browser/hybrid/browser/ui/webui/whist_web_ui_controller_factory.cc
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,59 @@ | ||
#include "whist_web_ui_controller_factory.h" | ||
#include "whist/browser/hybrid/browser/ui/webui/cloud_tabs_ui/cloud_tabs_ui.h" | ||
#include "chrome/common/url_constants.h" | ||
#include "base/logging.h" | ||
#include <memory> | ||
|
||
using content::WebUI; | ||
using content::WebUIController; | ||
|
||
namespace { | ||
typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui, | ||
const GURL& url); | ||
|
||
WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { | ||
if(url.SchemeIs(content::kCloudScheme)) { | ||
return new WhistCloudUI(web_ui, url); | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, const GURL& url) { | ||
if (url.SchemeIs(content::kCloudScheme)) { | ||
return &NewWebUI; | ||
} | ||
|
||
return nullptr; | ||
} | ||
} // namespace | ||
|
||
WebUI::TypeID WhistWebUIControllerFactory::GetWebUIType( | ||
content::BrowserContext* browser_context, | ||
const GURL& url) { | ||
WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, url); | ||
if (function) { | ||
return reinterpret_cast<WebUI::TypeID>(function); | ||
} | ||
return BraveWebUIControllerFactory::GetWebUIType(browser_context, url); | ||
} | ||
|
||
std::unique_ptr<WebUIController> | ||
WhistWebUIControllerFactory::CreateWebUIControllerForURL(WebUI* web_ui, | ||
const GURL& url) { | ||
WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, url); | ||
if (!function) { | ||
return BraveWebUIControllerFactory::CreateWebUIControllerForURL(web_ui, | ||
url); | ||
} | ||
|
||
return base::WrapUnique((*function)(web_ui, url)); | ||
} | ||
|
||
// static | ||
WhistWebUIControllerFactory* WhistWebUIControllerFactory::GetInstance() { | ||
return base::Singleton<WhistWebUIControllerFactory>::get(); | ||
} | ||
|
||
WhistWebUIControllerFactory::WhistWebUIControllerFactory() {} | ||
WhistWebUIControllerFactory::~WhistWebUIControllerFactory() {} |
28 changes: 28 additions & 0 deletions
28
browser/hybrid/browser/ui/webui/whist_web_ui_controller_factory.h
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,28 @@ | ||
#ifndef WHIST_BROWSER_UI_WEBUI_WHIST_WEB_UI_CONTROLLER_FACTORY_H | ||
#define WHIST_BROWSER_UI_WEBUI_WHIST_WEB_UI_CONTROLLER_FACTORY_H | ||
|
||
#include "base/memory/ptr_util.h" | ||
#include "brave/browser/ui/webui/brave_web_ui_controller_factory.h" | ||
|
||
class WhistWebUIControllerFactory : public BraveWebUIControllerFactory { | ||
public: | ||
WhistWebUIControllerFactory(const WhistWebUIControllerFactory&) = delete; | ||
WhistWebUIControllerFactory& operator=(const WhistWebUIControllerFactory&) = | ||
delete; | ||
|
||
content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, | ||
const GURL& url) override; | ||
std::unique_ptr<content::WebUIController> CreateWebUIControllerForURL( | ||
content::WebUI* web_ui, | ||
const GURL& url) override; | ||
|
||
static WhistWebUIControllerFactory* GetInstance(); | ||
|
||
protected: | ||
friend struct base::DefaultSingletonTraits<WhistWebUIControllerFactory>; | ||
|
||
WhistWebUIControllerFactory(); | ||
~WhistWebUIControllerFactory() override; | ||
}; | ||
|
||
#endif // WHIST_BROWSER_UI_WEBUI_WHIST_WEB_UI_CONTROLLER_FACTORY_H |
31 changes: 31 additions & 0 deletions
31
browser/hybrid/components/cloud_tabs_extension/.eslintrc.js
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,31 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: [ | ||
"plugin:react/recommended", | ||
"standard-with-typescript", | ||
"plugin:prettier/recommended", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 12, | ||
sourceType: "module", | ||
project: "./tsconfig.json", | ||
}, | ||
plugins: ["react", "@typescript-eslint", "prettier"], | ||
rules: { | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/consistent-type-assertions": "off", | ||
"prettier/prettier": "error", | ||
}, | ||
settings: { | ||
react: { | ||
version: "detect", | ||
}, | ||
}, | ||
} |
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,6 @@ | ||
# General | ||
src/generated_config.json | ||
src/config.json | ||
public/css/tailwind.css | ||
node_modules | ||
build |
Oops, something went wrong.