From c06203793def9df386ed430b58b7db5721cc40ca Mon Sep 17 00:00:00 2001 From: brave-builds Date: Tue, 19 Sep 2023 22:05:14 +0000 Subject: [PATCH] Uplift of #20052 (squashed) to beta --- browser/ui/BUILD.gn | 7 +- browser/ui/brave_pages.cc | 2 +- .../shields_panel_data_handler.cc | 3 +- .../webui/brave_web_ui_controller_factory.cc | 4 +- browser/ui/webui/sources.gni | 1 + .../webcompat_reporter_dialog.cc | 39 +++- .../webcompat_reporter_dialog.h | 6 +- .../webcompat_reporter_ui.cc | 178 ++++++++++++++++++ .../webcompat_reporter_ui.h | 14 +- browser/ui/webui/webcompat_reporter_ui.cc | 80 -------- components/definitions/webcompatReporter.d.ts | 9 +- .../resources/brave_components_strings.grd | 2 +- .../webcompat_reporter/browser/BUILD.gn | 3 + .../webcompat_reporter/browser/fields.cc | 61 ++++++ .../webcompat_reporter/browser/fields.h | 34 ++++ .../browser/webcompat_report_uploader.cc | 45 +++-- .../browser/webcompat_report_uploader.h | 12 +- .../ui/actions/webcompatreporter_actions.ts | 6 +- .../ui/constants/webcompatreporter_types.ts | 2 +- .../webcompat_reporter/ui/containers/App.tsx | 2 +- .../ui/reducers/webcompatreporter_reducer.ts | 19 +- .../ui/stories/modal/fakeLocale.ts | 2 +- .../ui/webcompat_reporter.tsx | 2 +- 23 files changed, 410 insertions(+), 123 deletions(-) create mode 100644 browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc rename browser/ui/webui/{ => webcompat_reporter}/webcompat_reporter_ui.h (58%) delete mode 100644 browser/ui/webui/webcompat_reporter_ui.cc create mode 100644 components/webcompat_reporter/browser/fields.cc create mode 100644 components/webcompat_reporter/browser/fields.h diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index d592e322ca56..6a427b73ab4b 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -52,11 +52,11 @@ source_set("ui") { "webui/skus_internals_ui.h", ] - # It doesn't make sense to view accelerators on iOS & Android. + # It doesn't make sense to view the webcompat webui on iOS & Android. if (!is_android && !is_ios) { sources += [ - "webui/webcompat_reporter_ui.cc", - "webui/webcompat_reporter_ui.h", + "webui/webcompat_reporter/webcompat_reporter_ui.cc", + "webui/webcompat_reporter/webcompat_reporter_ui.h", ] } @@ -548,6 +548,7 @@ source_set("ui") { "//components/gcm_driver:gcm_buildflags", "//components/image_fetcher/core", "//components/infobars/content", + "//components/language/core/browser", "//components/omnibox/browser:vector_icons", "//components/optimization_guide/core:features", "//components/optimization_guide/optimization_guide_internals/webui:url_constants", diff --git a/browser/ui/brave_pages.cc b/browser/ui/brave_pages.cc index c6a583af52eb..d3700a6d121f 100644 --- a/browser/ui/brave_pages.cc +++ b/browser/ui/brave_pages.cc @@ -53,7 +53,7 @@ void ShowWebcompatReporter(Browser* browser) { return; } - OpenWebcompatReporterDialog(web_contents); + webcompat_reporter::OpenReporterDialog(web_contents); } void ShowBraveWallet(Browser* browser) { diff --git a/browser/ui/webui/brave_shields/shields_panel_data_handler.cc b/browser/ui/webui/brave_shields/shields_panel_data_handler.cc index 985817feea34..93ace295ad9f 100644 --- a/browser/ui/webui/brave_shields/shields_panel_data_handler.cc +++ b/browser/ui/webui/brave_shields/shields_panel_data_handler.cc @@ -163,7 +163,8 @@ void ShieldsPanelDataHandler::OpenWebCompatWindow() { if (!active_shields_data_controller_) return; - OpenWebcompatReporterDialog(active_shields_data_controller_->web_contents()); + webcompat_reporter::OpenReporterDialog( + active_shields_data_controller_->web_contents()); } void ShieldsPanelDataHandler::UpdateFavicon() { diff --git a/browser/ui/webui/brave_web_ui_controller_factory.cc b/browser/ui/webui/brave_web_ui_controller_factory.cc index d17a48065239..920dbaaeef3e 100644 --- a/browser/ui/webui/brave_web_ui_controller_factory.cc +++ b/browser/ui/webui/brave_web_ui_controller_factory.cc @@ -50,7 +50,7 @@ #include "brave/browser/ui/webui/new_tab_page/brave_new_tab_ui.h" #include "brave/browser/ui/webui/private_new_tab_page/brave_private_new_tab_ui.h" #include "brave/browser/ui/webui/speedreader/speedreader_toolbar_ui.h" -#include "brave/browser/ui/webui/webcompat_reporter_ui.h" +#include "brave/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.h" #include "brave/browser/ui/webui/welcome_page/brave_welcome_ui.h" #include "brave/components/brave_news/common/features.h" #include "brave/components/brave_wallet/browser/brave_wallet_utils.h" @@ -108,7 +108,7 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { return new SkusInternalsUI(web_ui, url.host()); #if !BUILDFLAG(IS_ANDROID) } else if (host == kWebcompatReporterHost) { - return new WebcompatReporterUI(web_ui, url.host()); + return new webcompat_reporter::WebcompatReporterUI(web_ui, url.host()); #endif #if BUILDFLAG(ENABLE_IPFS_INTERNALS_WEBUI) } else if (host == kIPFSWebUIHost && diff --git a/browser/ui/webui/sources.gni b/browser/ui/webui/sources.gni index 56aeb0c3ee34..774d08f82914 100644 --- a/browser/ui/webui/sources.gni +++ b/browser/ui/webui/sources.gni @@ -10,6 +10,7 @@ import("//brave/components/playlist/common/buildflags/buildflags.gni") brave_browser_ui_webui_configs_deps = [ "//base", "//brave/browser/ui", + "//brave/components/brave_shields/browser", "//brave/components/brave_vpn/common/buildflags", "//brave/components/playlist/common/buildflags", ] diff --git a/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.cc b/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.cc index 2da63d41227e..a9eccb790570 100644 --- a/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.cc +++ b/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.cc @@ -12,7 +12,10 @@ #include "base/json/json_writer.h" #include "base/values.h" +#include "brave/browser/ui/brave_shields_data_controller.h" +#include "brave/components/brave_shields/common/brave_shields_panel.mojom-shared.h" #include "brave/components/constants/webui_url_constants.h" +#include "brave/components/webcompat_reporter/browser/fields.h" #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" @@ -24,10 +27,16 @@ using content::WebContents; using content::WebUIMessageHandler; +namespace webcompat_reporter { + +namespace { + constexpr int kDialogMinHeight = 100; constexpr int kDialogMaxHeight = 700; constexpr int kDialogWidth = 375; +} // namespace + // A ui::WebDialogDelegate that specifies the webcompat reporter's appearance. class WebcompatReporterDialogDelegate : public ui::WebDialogDelegate { public: @@ -102,9 +111,33 @@ bool WebcompatReporterDialogDelegate::ShouldShowDialogTitle() const { return false; } -void OpenWebcompatReporterDialog(content::WebContents* initiator) { +void OpenReporterDialog(content::WebContents* initiator) { + bool shields_enabled = false; + brave_shields::mojom::FingerprintMode fp_block_mode = + brave_shields::mojom::FingerprintMode::STANDARD; + brave_shields::mojom::AdBlockMode ad_block_mode = + brave_shields::mojom::AdBlockMode::STANDARD; + brave_shields::BraveShieldsDataController* shields_data_controller = + brave_shields::BraveShieldsDataController::FromWebContents(initiator); + if (shields_data_controller != nullptr) { + shields_enabled = shields_data_controller->GetBraveShieldsEnabled(); + fp_block_mode = shields_data_controller->GetFingerprintMode(); + ad_block_mode = shields_data_controller->GetAdBlockMode(); + } + + // Remove query and fragments from reported URL. + GURL::Replacements replacements; + replacements.ClearQuery(); + replacements.ClearRef(); + GURL report_url = + initiator->GetLastCommittedURL().ReplaceComponents(replacements); + base::Value::Dict params_dict; - params_dict.Set("siteUrl", initiator->GetLastCommittedURL().spec()); + params_dict.Set(kSiteURLField, report_url.spec()); + params_dict.Set(kShieldsEnabledField, shields_enabled); + params_dict.Set(kAdBlockSettingField, GetAdBlockModeString(ad_block_mode)); + params_dict.Set(kFPBlockSettingField, + GetFingerprintModeString(fp_block_mode)); gfx::Size min_size(kDialogWidth, kDialogMinHeight); gfx::Size max_size(kDialogWidth, kDialogMaxHeight); @@ -113,3 +146,5 @@ void OpenWebcompatReporterDialog(content::WebContents* initiator) { std::make_unique(std::move(params_dict)), initiator, min_size, max_size); } + +} // namespace webcompat_reporter diff --git a/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.h b/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.h index 8e9ae7944ab6..f18162917b90 100644 --- a/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.h +++ b/browser/ui/webui/webcompat_reporter/webcompat_reporter_dialog.h @@ -10,6 +10,10 @@ namespace content { class WebContents; } -void OpenWebcompatReporterDialog(content::WebContents* initiator); +namespace webcompat_reporter { + +void OpenReporterDialog(content::WebContents* initiator); + +} // namespace webcompat_reporter #endif // BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_WEBCOMPAT_REPORTER_DIALOG_H_ diff --git a/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc b/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc new file mode 100644 index 000000000000..53a7278fe11e --- /dev/null +++ b/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc @@ -0,0 +1,178 @@ +/* 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/webcompat_reporter/webcompat_reporter_ui.h" + +#include +#include +#include + +#include "base/strings/string_util.h" +#include "brave/browser/brave_browser_process.h" +#include "brave/browser/ui/brave_shields_data_controller.h" +#include "brave/browser/ui/webui/brave_webui_source.h" +#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h" +#include "brave/components/brave_shields/browser/ad_block_service.h" +#include "brave/components/brave_shields/browser/filter_list_catalog_entry.h" +#include "brave/components/brave_shields/common/pref_names.h" +#include "brave/components/brave_vpn/common/buildflags/buildflags.h" +#include "brave/components/constants/webui_url_constants.h" +#include "brave/components/webcompat_reporter/browser/fields.h" +#include "brave/components/webcompat_reporter/browser/webcompat_report_uploader.h" +#include "brave/components/webcompat_reporter/resources/grit/webcompat_reporter_generated_map.h" +#include "chrome/browser/profiles/profile.h" +#include "components/grit/brave_components_resources.h" +#include "components/language/core/browser/pref_names.h" +#include "components/prefs/pref_service.h" +#include "content/public/browser/web_ui_data_source.h" +#include "content/public/browser/web_ui_message_handler.h" +#include "services/network/public/cpp/shared_url_loader_factory.h" +#include "ui/web_dialogs/web_dialog_delegate.h" +#include "url/gurl.h" + +#if BUILDFLAG(ENABLE_BRAVE_VPN) +#include "brave/browser/brave_vpn/brave_vpn_service_factory.h" +#include "brave/components/brave_vpn/browser/brave_vpn_service.h" +#endif + +namespace webcompat_reporter { + +namespace { + +class WebcompatReporterDOMHandler : public content::WebUIMessageHandler { + public: + explicit WebcompatReporterDOMHandler(Profile* profile); + WebcompatReporterDOMHandler(const WebcompatReporterDOMHandler&) = delete; + WebcompatReporterDOMHandler& operator=(const WebcompatReporterDOMHandler&) = + delete; + ~WebcompatReporterDOMHandler() override; + + // WebUIMessageHandler implementation. + void RegisterMessages() override; + + private: + void InitAdditionalParameters(Profile* profile); + void HandleSubmitReport(const base::Value::List& args); + + std::unique_ptr uploader_; + std::string ad_block_list_names_; + std::string languages_; + bool language_farbling_enabled_ = true; + bool brave_vpn_connected_ = false; +}; + +WebcompatReporterDOMHandler::WebcompatReporterDOMHandler(Profile* profile) + : uploader_(std::make_unique( + profile->GetURLLoaderFactory())) { + InitAdditionalParameters(profile); +} + +void WebcompatReporterDOMHandler::InitAdditionalParameters(Profile* profile) { + std::vector ad_block_list_names; + + // Collect all enabled adblock list names + brave_shields::AdBlockService* ad_block_service = + g_brave_browser_process->ad_block_service(); + if (ad_block_service != nullptr) { + brave_shields::AdBlockRegionalServiceManager* regional_service_manager = + ad_block_service->regional_service_manager(); + CHECK(regional_service_manager); + for (const brave_shields::FilterListCatalogEntry& entry : + regional_service_manager->GetFilterListCatalog()) { + if (regional_service_manager->IsFilterListEnabled(entry.uuid)) { + ad_block_list_names.push_back(entry.title); + } + } + } + + ad_block_list_names_ = base::JoinString(ad_block_list_names, ","); + +#if BUILDFLAG(ENABLE_BRAVE_VPN) + brave_vpn::BraveVpnService* vpn_service = + brave_vpn::BraveVpnServiceFactory::GetForProfile(profile); + if (vpn_service != nullptr) { + brave_vpn_connected_ = vpn_service->IsConnected(); + } +#endif + + PrefService* profile_prefs = profile->GetPrefs(); + languages_ = profile_prefs->GetString(language::prefs::kAcceptLanguages); + language_farbling_enabled_ = + profile_prefs->GetBoolean(brave_shields::prefs::kReduceLanguageEnabled); +} + +WebcompatReporterDOMHandler::~WebcompatReporterDOMHandler() = default; + +void WebcompatReporterDOMHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback( + "webcompat_reporter.submitReport", + base::BindRepeating(&WebcompatReporterDOMHandler::HandleSubmitReport, + base::Unretained(this))); +} + +void WebcompatReporterDOMHandler::HandleSubmitReport( + const base::Value::List& args) { + DCHECK_EQ(args.size(), 1U); + if (!args[0].is_dict()) { + return; + } + + const base::Value::Dict& submission_args = args[0].GetDict(); + + const std::string* url_arg = submission_args.FindString(kSiteURLField); + const std::string* ad_block_setting_arg = + submission_args.FindString(kAdBlockSettingField); + const std::string* fp_block_setting_arg = + submission_args.FindString(kFPBlockSettingField); + const base::Value* details_arg = submission_args.Find(kDetailsField); + const base::Value* contact_arg = submission_args.Find(kContactField); + bool shields_enabled = + submission_args.FindBool(kShieldsEnabledField).value_or(false); + + std::string url; + std::string ad_block_setting; + std::string fp_block_setting; + base::Value details; + base::Value contact; + + if (url_arg != nullptr) { + url = *url_arg; + } + if (ad_block_setting_arg != nullptr) { + ad_block_setting = *ad_block_setting_arg; + } + if (fp_block_setting_arg != nullptr) { + fp_block_setting = *fp_block_setting_arg; + } + if (details_arg != nullptr) { + details = details_arg->Clone(); + } + if (contact_arg != nullptr) { + contact = contact_arg->Clone(); + } + + uploader_->SubmitReport(GURL(url), shields_enabled, ad_block_setting, + fp_block_setting, ad_block_list_names_, languages_, + language_farbling_enabled_, brave_vpn_connected_, + details, contact); +} + +} // namespace + +WebcompatReporterUI::WebcompatReporterUI(content::WebUI* web_ui, + const std::string& name) + : ConstrainedWebDialogUI(web_ui) { + CreateAndAddWebUIDataSource(web_ui, name, kWebcompatReporterGenerated, + kWebcompatReporterGeneratedSize, + IDR_WEBCOMPAT_REPORTER_HTML); + Profile* profile = Profile::FromWebUI(web_ui); + + web_ui->AddMessageHandler( + std::make_unique(profile)); +} + +WebcompatReporterUI::~WebcompatReporterUI() = default; + +} // namespace webcompat_reporter diff --git a/browser/ui/webui/webcompat_reporter_ui.h b/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.h similarity index 58% rename from browser/ui/webui/webcompat_reporter_ui.h rename to browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.h index fe210561e3aa..735703da6aca 100644 --- a/browser/ui/webui/webcompat_reporter_ui.h +++ b/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.h @@ -1,10 +1,10 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. +/* 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 http://mozilla.org/MPL/2.0/. */ + * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_UI_H_ -#define BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_UI_H_ +#ifndef BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_WEBCOMPAT_REPORTER_UI_H_ +#define BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_WEBCOMPAT_REPORTER_UI_H_ #include @@ -14,6 +14,8 @@ namespace content { class WebUI; } +namespace webcompat_reporter { + class WebcompatReporterUI : public ConstrainedWebDialogUI { public: WebcompatReporterUI(content::WebUI* web_ui, const std::string& host); @@ -22,4 +24,6 @@ class WebcompatReporterUI : public ConstrainedWebDialogUI { ~WebcompatReporterUI() override; }; -#endif // BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_UI_H_ +} // namespace webcompat_reporter + +#endif // BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_WEBCOMPAT_REPORTER_UI_H_ diff --git a/browser/ui/webui/webcompat_reporter_ui.cc b/browser/ui/webui/webcompat_reporter_ui.cc deleted file mode 100644 index 049e68617ad7..000000000000 --- a/browser/ui/webui/webcompat_reporter_ui.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ - -#include "brave/browser/ui/webui/webcompat_reporter_ui.h" - -#include -#include - -#include "brave/browser/ui/webui/brave_webui_source.h" -#include "brave/components/constants/webui_url_constants.h" -#include "brave/components/webcompat_reporter/browser/webcompat_report_uploader.h" -#include "brave/components/webcompat_reporter/resources/grit/webcompat_reporter_generated_map.h" -#include "chrome/browser/profiles/profile.h" -#include "components/grit/brave_components_resources.h" -#include "content/public/browser/web_ui_data_source.h" -#include "content/public/browser/web_ui_message_handler.h" -#include "services/network/public/cpp/shared_url_loader_factory.h" -#include "url/gurl.h" - -namespace { - -class WebcompatReporterDOMHandler : public content::WebUIMessageHandler { - public: - explicit WebcompatReporterDOMHandler( - scoped_refptr loader_factory); - WebcompatReporterDOMHandler(const WebcompatReporterDOMHandler&) = delete; - WebcompatReporterDOMHandler& operator=(const WebcompatReporterDOMHandler&) = - delete; - ~WebcompatReporterDOMHandler() override; - - // WebUIMessageHandler implementation. - void RegisterMessages() override; - - private: - void HandleSubmitReport(const base::Value::List& args); - std::unique_ptr uploader_; -}; - -WebcompatReporterDOMHandler::WebcompatReporterDOMHandler( - scoped_refptr loader_factory) - : uploader_(std::make_unique( - std::move(loader_factory))) {} - -WebcompatReporterDOMHandler::~WebcompatReporterDOMHandler() = default; - -void WebcompatReporterDOMHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback( - "webcompat_reporter.submitReport", - base::BindRepeating(&WebcompatReporterDOMHandler::HandleSubmitReport, - base::Unretained(this))); -} - -void WebcompatReporterDOMHandler::HandleSubmitReport( - const base::Value::List& args) { - DCHECK_EQ(args.size(), 3U); - if (!args[0].is_string()) - return; - - GURL site_url(args[0].GetString()); - const base::Value& details = args[1]; - const base::Value& contact = args[2]; - uploader_->SubmitReport(site_url, details, contact); -} - -} // namespace - -WebcompatReporterUI::WebcompatReporterUI(content::WebUI* web_ui, - const std::string& name) - : ConstrainedWebDialogUI(web_ui) { - CreateAndAddWebUIDataSource(web_ui, name, kWebcompatReporterGenerated, - kWebcompatReporterGeneratedSize, - IDR_WEBCOMPAT_REPORTER_HTML); - Profile* profile = Profile::FromWebUI(web_ui); - web_ui->AddMessageHandler(std::make_unique( - profile->GetURLLoaderFactory())); -} - -WebcompatReporterUI::~WebcompatReporterUI() = default; diff --git a/components/definitions/webcompatReporter.d.ts b/components/definitions/webcompatReporter.d.ts index 90508ea4737c..53ec419c9aca 100644 --- a/components/definitions/webcompatReporter.d.ts +++ b/components/definitions/webcompatReporter.d.ts @@ -3,8 +3,15 @@ declare namespace WebcompatReporter { reporterState: State | undefined } + export interface DialogArgs { + url: string + adBlockSetting: string + fpBlockSetting: string + shieldsEnabled: string + } + export interface State { - siteUrl: string + dialogArgs: DialogArgs submitted: boolean } } diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index ffc080ea9cbe..ea9854ce74b7 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -433,7 +433,7 @@ Report a broken site Let Brave's developers know that this site doesn't work properly with Shields: - Note: When you click "Submit", you'll share the site address, your Brave version number, and your IP address with Brave developers. (The IP address will not be stored.) + Note: The report sent to Brave servers will include the site address, Brave version number, Shields settings, VPN status, and language settings. The IP address will be transmitted but not stored. Additional details (optional) Contact me at: (optional) Email, Twitter, etc. diff --git a/components/webcompat_reporter/browser/BUILD.gn b/components/webcompat_reporter/browser/BUILD.gn index 84beb134db7e..9031aeaa3cb9 100644 --- a/components/webcompat_reporter/browser/BUILD.gn +++ b/components/webcompat_reporter/browser/BUILD.gn @@ -9,6 +9,8 @@ assert(!is_android) static_library("browser") { sources = [ + "fields.cc", + "fields.h", "webcompat_report_uploader.cc", "webcompat_report_uploader.h", ] @@ -16,6 +18,7 @@ static_library("browser") { deps = [ "//base", "//brave/components/brave_referrals/browser", + "//brave/components/brave_shields/common:mojom", "//brave/components/brave_stats/browser", "//brave/components/constants", "//brave/components/webcompat_reporter/buildflags", diff --git a/components/webcompat_reporter/browser/fields.cc b/components/webcompat_reporter/browser/fields.cc new file mode 100644 index 000000000000..f145870335db --- /dev/null +++ b/components/webcompat_reporter/browser/fields.cc @@ -0,0 +1,61 @@ +/* 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/components/webcompat_reporter/browser/fields.h" + +#include "base/notreached.h" +#include "brave/components/brave_shields/common/brave_shields_panel.mojom-shared.h" + +namespace webcompat_reporter { + +namespace { + +const char kAggressive[] = "aggressive"; +const char kStandard[] = "standard"; +const char kAllow[] = "allow"; + +} // namespace + +const char kFPBlockSettingField[] = "fpBlockSetting"; +const char kAdBlockSettingField[] = "adBlockSetting"; +const char kAdBlockListsField[] = "adBlockLists"; +const char kShieldsEnabledField[] = "shieldsEnabled"; +const char kLanguagesField[] = "languages"; +const char kLanguageFarblingField[] = "languageFarblingEnabled"; +const char kBraveVPNEnabledField[] = "braveVPNEnabled"; + +const char kSiteURLField[] = "url"; +const char kDomainField[] = "domain"; +const char kDetailsField[] = "additionalDetails"; +const char kContactField[] = "contactInfo"; +const char kApiKeyField[] = "api_key"; + +const char* GetAdBlockModeString( + brave_shields::mojom::AdBlockMode ad_block_mode) { + switch (ad_block_mode) { + case brave_shields::mojom::AdBlockMode::AGGRESSIVE: + return kAggressive; + case brave_shields::mojom::AdBlockMode::STANDARD: + return kStandard; + case brave_shields::mojom::AdBlockMode::ALLOW: + return kAllow; + } + NOTREACHED(); +} + +const char* GetFingerprintModeString( + brave_shields::mojom::FingerprintMode fp_block_mode) { + switch (fp_block_mode) { + case brave_shields::mojom::FingerprintMode::STRICT: + return kAggressive; + case brave_shields::mojom::FingerprintMode::STANDARD: + return kStandard; + case brave_shields::mojom::FingerprintMode::ALLOW: + return kAllow; + } + NOTREACHED(); +} + +} // namespace webcompat_reporter diff --git a/components/webcompat_reporter/browser/fields.h b/components/webcompat_reporter/browser/fields.h new file mode 100644 index 000000000000..35979f5878cd --- /dev/null +++ b/components/webcompat_reporter/browser/fields.h @@ -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_COMPONENTS_WEBCOMPAT_REPORTER_BROWSER_FIELDS_H_ +#define BRAVE_COMPONENTS_WEBCOMPAT_REPORTER_BROWSER_FIELDS_H_ + +#include "brave/components/brave_shields/common/brave_shields_panel.mojom.h" + +namespace webcompat_reporter { + +extern const char kFPBlockSettingField[]; +extern const char kAdBlockSettingField[]; +extern const char kAdBlockListsField[]; +extern const char kShieldsEnabledField[]; +extern const char kLanguagesField[]; +extern const char kLanguageFarblingField[]; +extern const char kBraveVPNEnabledField[]; + +extern const char kSiteURLField[]; +extern const char kDetailsField[]; +extern const char kContactField[]; +extern const char kDomainField[]; +extern const char kApiKeyField[]; + +const char* GetAdBlockModeString( + brave_shields::mojom::AdBlockMode ad_block_mode); +const char* GetFingerprintModeString( + brave_shields::mojom::FingerprintMode fp_block_mode); + +} // namespace webcompat_reporter + +#endif // BRAVE_COMPONENTS_WEBCOMPAT_REPORTER_BROWSER_FIELDS_H_ diff --git a/components/webcompat_reporter/browser/webcompat_report_uploader.cc b/components/webcompat_reporter/browser/webcompat_report_uploader.cc index 1b522c19a926..4bca9e070f39 100644 --- a/components/webcompat_reporter/browser/webcompat_report_uploader.cc +++ b/components/webcompat_reporter/browser/webcompat_report_uploader.cc @@ -13,6 +13,7 @@ #include "base/json/json_writer.h" #include "brave/components/brave_referrals/browser/brave_referrals_service.h" #include "brave/components/brave_stats/browser/brave_stats_updater_util.h" +#include "brave/components/webcompat_reporter/browser/fields.h" #include "brave/components/webcompat_reporter/buildflags/buildflags.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -25,7 +26,7 @@ #include "url/gurl.h" #include "url/origin.h" -namespace brave { +namespace webcompat_reporter { WebcompatReportUploader::WebcompatReportUploader( scoped_refptr factory) @@ -33,9 +34,17 @@ WebcompatReportUploader::WebcompatReportUploader( WebcompatReportUploader::~WebcompatReportUploader() = default; -void WebcompatReportUploader::SubmitReport(const GURL& report_url, - const base::Value& details, - const base::Value& contact) { +void WebcompatReportUploader::SubmitReport( + const GURL& report_url, + const bool shields_enabled, + const std::string& ad_block_setting, + const std::string& fp_block_setting, + const std::string& ad_block_list_names, + const std::string& languages, + const bool language_farbling, + const bool brave_vpn_connected, + const base::Value& details, + const base::Value& contact) { std::string api_key = brave_stats::GetAPIKey(); const GURL upload_url(BUILDFLAG(WEBCOMPAT_REPORT_ENDPOINT)); @@ -43,11 +52,20 @@ void WebcompatReportUploader::SubmitReport(const GURL& report_url, url::Origin report_url_origin = url::Origin::Create(report_url); base::Value::Dict post_data_obj; - post_data_obj.Set("url", base::Value(report_url.spec())); - post_data_obj.Set("domain", base::Value(report_url_origin.Serialize())); - post_data_obj.Set("additionalDetails", details.Clone()); - post_data_obj.Set("contactInfo", contact.Clone()); - post_data_obj.Set("api_key", base::Value(api_key)); + post_data_obj.Set(kSiteURLField, report_url.spec()); + post_data_obj.Set(kDomainField, report_url_origin.Serialize()); + post_data_obj.Set(kDetailsField, details.Clone()); + post_data_obj.Set(kContactField, contact.Clone()); + + post_data_obj.Set(kShieldsEnabledField, shields_enabled); + post_data_obj.Set(kAdBlockSettingField, ad_block_setting); + post_data_obj.Set(kFPBlockSettingField, fp_block_setting); + post_data_obj.Set(kAdBlockListsField, ad_block_list_names); + post_data_obj.Set(kLanguagesField, languages); + post_data_obj.Set(kLanguageFarblingField, language_farbling); + post_data_obj.Set(kBraveVPNEnabledField, brave_vpn_connected); + + post_data_obj.Set(kApiKeyField, base::Value(api_key)); std::string post_data; base::JSONWriter::Write(post_data_obj, &post_data); @@ -62,6 +80,9 @@ void WebcompatReportUploader::CreateAndStartURLLoader( std::string content_type = "application/json"; auto resource_request = std::make_unique(); + // upload_url only includes the origin and path, and not the fragment or + // query. The fragment and query are removed from the URL in + // OpenReporterDialog. resource_request->url = GURL(upload_url); resource_request->method = "POST"; resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit; @@ -78,7 +99,9 @@ void WebcompatReportUploader::CreateAndStartURLLoader( trigger: "Though the 'Report a Broken Site' option of the help menu or" "the Brave Shields panel." - data: "Broken URL, IP address; user provided additional details and contact information." + data: "Broken URL, IP address, Shields settings, language settings," + "Brave VPN connection status; user provided additional details" + "and contact information." destination: OTHER destination_other: "Brave developers" } @@ -109,4 +132,4 @@ void WebcompatReportUploader::OnSimpleURLLoaderComplete( } } -} // namespace brave +} // namespace webcompat_reporter diff --git a/components/webcompat_reporter/browser/webcompat_report_uploader.h b/components/webcompat_reporter/browser/webcompat_report_uploader.h index 530d9573f372..51d88e9229ab 100644 --- a/components/webcompat_reporter/browser/webcompat_report_uploader.h +++ b/components/webcompat_reporter/browser/webcompat_report_uploader.h @@ -11,6 +11,7 @@ #include "base/memory/ref_counted.h" #include "base/values.h" +#include "brave/components/brave_shields/common/brave_shields.mojom.h" #include "url/gurl.h" namespace network { @@ -18,7 +19,7 @@ class SharedURLLoaderFactory; class SimpleURLLoader; } // namespace network -namespace brave { +namespace webcompat_reporter { class WebcompatReportUploader { public: @@ -29,6 +30,13 @@ class WebcompatReportUploader { ~WebcompatReportUploader(); void SubmitReport(const GURL& report_url, + const bool shields_enabled, + const std::string& ad_block_setting, + const std::string& fp_block_setting, + const std::string& ad_block_list_names, + const std::string& languages, + const bool language_farbling, + const bool brave_vpn_connected, const base::Value& details, const base::Value& contact); @@ -40,6 +48,6 @@ class WebcompatReportUploader { void OnSimpleURLLoaderComplete(std::unique_ptr response_body); }; -} // namespace brave +} // namespace webcompat_reporter #endif // BRAVE_COMPONENTS_WEBCOMPAT_REPORTER_BROWSER_WEBCOMPAT_REPORT_UPLOADER_H_ diff --git a/components/webcompat_reporter/ui/actions/webcompatreporter_actions.ts b/components/webcompat_reporter/ui/actions/webcompatreporter_actions.ts index e628c2b2e29a..12d5c496a8c2 100644 --- a/components/webcompat_reporter/ui/actions/webcompatreporter_actions.ts +++ b/components/webcompat_reporter/ui/actions/webcompatreporter_actions.ts @@ -8,9 +8,9 @@ import { action } from 'typesafe-actions' // Constants import { types } from '../constants/webcompatreporter_types' -export const setSiteUrl = (siteUrl: string) => { - return action(types.WEBCOMPATREPORTER_SET_SITE_URL, { - siteUrl +export const setDialogArgs = (dialogArgs: WebcompatReporter.DialogArgs) => { + return action(types.WEBCOMPATREPORTER_SET_DIALOG_ARGS, { + dialogArgs }) } diff --git a/components/webcompat_reporter/ui/constants/webcompatreporter_types.ts b/components/webcompat_reporter/ui/constants/webcompatreporter_types.ts index 36d65420d4db..0f7d854da165 100644 --- a/components/webcompat_reporter/ui/constants/webcompatreporter_types.ts +++ b/components/webcompat_reporter/ui/constants/webcompatreporter_types.ts @@ -5,6 +5,6 @@ export const enum types { WEBCOMPATREPORTER_ON_SUBMIT_REPORT = '@@webcompatreporter/WEBCOMPATREPORTER_ON_SUBMIT_REPORT', - WEBCOMPATREPORTER_SET_SITE_URL = '@@webcompatreporter/WEBCOMPATREPORTER_SET_SITE_URL', + WEBCOMPATREPORTER_SET_DIALOG_ARGS = '@@webcompatreporter/WEBCOMPATREPORTER_SET_DIALOG_ARGS', WEBCOMPATREPORTER_ON_CLOSE = '@@webcompatreporter/WEBCOMPATREPORTER_ON_CLOSE' } diff --git a/components/webcompat_reporter/ui/containers/App.tsx b/components/webcompat_reporter/ui/containers/App.tsx index 90acbcde3fc4..5a94fcb35021 100644 --- a/components/webcompat_reporter/ui/containers/App.tsx +++ b/components/webcompat_reporter/ui/containers/App.tsx @@ -31,7 +31,7 @@ class WebcompatReportContainer extends React.Component { const { actions, reporterState } = this.props return ( = ( switch (action.type) { case types.WEBCOMPATREPORTER_ON_SUBMIT_REPORT: chrome.send('webcompat_reporter.submitReport', [ - state.siteUrl, - action.payload.details || null, - action.payload.contact || null + { + ...state.dialogArgs, + additionalDetails: action.payload.details || null, + contactInfo: action.payload.contact || null + } ]) state = { ...state, @@ -27,10 +34,10 @@ const webcompatReporterReducer: Reducer = ( } setTimeout(() => chrome.send('dialogClose'), 5000) break - case types.WEBCOMPATREPORTER_SET_SITE_URL: + case types.WEBCOMPATREPORTER_SET_DIALOG_ARGS: state = { ...state, - siteUrl: action.payload.siteUrl + dialogArgs: action.payload.dialogArgs } break case types.WEBCOMPATREPORTER_ON_CLOSE: diff --git a/components/webcompat_reporter/ui/stories/modal/fakeLocale.ts b/components/webcompat_reporter/ui/stories/modal/fakeLocale.ts index 8428d3d5a6bb..6a3bfad5f5e4 100644 --- a/components/webcompat_reporter/ui/stories/modal/fakeLocale.ts +++ b/components/webcompat_reporter/ui/stories/modal/fakeLocale.ts @@ -7,7 +7,7 @@ const locale: { [key: string]: string } = { // Report modal reportModalTitle: 'Report a broken site', reportExplanation: 'Let Brave\'s developers know that this site doesn\'t work properly with Shields:', - reportDisclaimer: 'Note: This site address will be submitted with your Brave version number and your IP address (which will not be stored).', + reportDisclaimer: 'Note: The report sent to Brave servers will include the site address, Brave version number, Shields settings, VPN status and language settings. The IP address will be transmitted but not stored.', reportDetails: 'Additional details (optional)', reportContactPlaceholder: 'Email, Twitter, etc.', reportContactLabel: 'Contact me at: (optional)', diff --git a/components/webcompat_reporter/ui/webcompat_reporter.tsx b/components/webcompat_reporter/ui/webcompat_reporter.tsx index 49e1682c87fd..13724558030b 100644 --- a/components/webcompat_reporter/ui/webcompat_reporter.tsx +++ b/components/webcompat_reporter/ui/webcompat_reporter.tsx @@ -39,7 +39,7 @@ function loadDialogArgs () { console.error('Error parsing incoming dialog args: ', dialogArgsRaw, e) } - getActions().setSiteUrl(dialogArgs.siteUrl) + getActions().setDialogArgs(dialogArgs) } function initialize () {