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

Add webcompat issue reporting dialog #3420

Merged
merged 5 commits into from
Nov 27, 2019
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
1 change: 1 addition & 0 deletions app/brave_command_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define IDC_SHOW_BRAVE_WALLET 56006
#define IDC_ADD_NEW_PROFILE 56007
#define IDC_OPEN_GUEST_PROFILE 56008
#define IDC_SHOW_BRAVE_WEBCOMPAT_REPORTER 56009

#define IDC_BRAVE_COMMANDS_LAST 57000

Expand Down
9 changes: 9 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<message name="IDS_SHOW_BRAVE_ADBLOCK" desc="The show Brave Ad Block menu in the app menu">
Brave Ad Block
</message>
<message name="IDS_SHOW_BRAVE_WEBCOMPAT_REPORTER" desc="The menu item to report a broken site in the app menu">
Report a Broken Site
</message>
<message name="IDS_SHOW_BRAVE_SYNC" desc="The show brave sync menu in the app menu">
Sync
</message>
Expand Down Expand Up @@ -422,6 +425,12 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Same as macOS
</message>
</if>
<!-- Mac Menubar Menus -->
<if expr="is_macosx">
<message name="IDS_REPORT_BROKEN_SITE_MAC" desc="The Mac menu item to report a broken site in the Help menu.">
Report a Broken Site
</message>
</if>
<!-- Brave Default Extensions -->
<message name="IDS_SETTINGS_BRAVE_DEFAULT_EXTENSIONS_TITLE" desc="The title for Brave default extensions in settings">
Extensions
Expand Down
1 change: 1 addition & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ source_set("extensions") {
deps = [
"//base",
"//brave/app:brave_generated_resources_grit",
"//brave/browser/webcompat_reporter",
"//brave/common",
"//brave/common:pref_names",
"//brave/common/extensions/api",
Expand Down
25 changes: 25 additions & 0 deletions browser/extensions/api/brave_shields_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "base/strings/string_number_conversions.h"
#include "brave/browser/extensions/api/brave_action_api.h"
#include "brave/browser/webcompat_reporter/webcompat_reporter_dialog.h"
#include "brave/common/extensions/api/brave_shields.h"
#include "brave/common/extensions/extension_constants.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
Expand Down Expand Up @@ -326,5 +327,29 @@ BraveShieldsOnShieldsPanelShownFunction::Run() {
return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction BraveShieldsReportBrokenSiteFunction::Run() {
std::unique_ptr<brave_shields::ReportBrokenSite::Params> params(
brave_shields::ReportBrokenSite::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

// Get web contents for this tab
content::WebContents* contents = nullptr;
if (!ExtensionTabUtil::GetTabById(
params->tab_id,
Profile::FromBrowserContext(browser_context()),
false,
nullptr,
nullptr,
&contents,
nullptr)) {
return RespondNow(Error(tabs_constants::kTabNotFoundError,
base::NumberToString(params->tab_id)));
}

OpenWebcompatReporterDialog(contents);

return RespondNow(NoArguments());
}

} // namespace api
} // namespace extensions
11 changes: 10 additions & 1 deletion browser/extensions/api/brave_shields_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class BraveShieldsGetNoScriptControlTypeFunction : public ExtensionFunction {
ResponseAction Run() override;
};


// Notifies the browser that the shields panel was shown to the user.
class BraveShieldsOnShieldsPanelShownFunction : public ExtensionFunction {
public:
Expand All @@ -171,6 +170,16 @@ class BraveShieldsOnShieldsPanelShownFunction : public ExtensionFunction {
ResponseAction Run() override;
};

class BraveShieldsReportBrokenSiteFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.reportBrokenSite", UNKNOWN)

protected:
~BraveShieldsReportBrokenSiteFunction() override {}

ResponseAction Run() override;
};

} // namespace api
} // namespace extensions

Expand Down
4 changes: 4 additions & 0 deletions browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@
"<(ROOT_GEN_DIR)/brave/web-ui-brave_extension/brave_extension.grd": {
"includes": [44500],
},
# This file is generated during the build.
"<(ROOT_GEN_DIR)/brave/web-ui-webcompat_reporter/webcompat_reporter.grd": {
"includes": [45000],
},
}
4 changes: 4 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ source_set("ui") {
"webui/basic_ui.h",
"webui/brave_adblock_ui.cc",
"webui/brave_adblock_ui.h",
"webui/webcompat_reporter_ui.cc",
"webui/webcompat_reporter_ui.h",
"webui/brave_new_tab_message_handler.cc",
"webui/brave_new_tab_message_handler.h",
"webui/brave_new_tab_ui.cc",
Expand Down Expand Up @@ -164,9 +166,11 @@ source_set("ui") {
"//brave/browser/profiles",
"//brave/browser/resources/settings:resources",
"//brave/browser/tor",
"//brave/components/webcompat_reporter/browser",
"//brave/common",
"//brave/common:pref_names",
"//brave/components/brave_adblock_ui:generated_resources",
"//brave/components/webcompat_reporter/ui:generated_resources",
"//brave/components/brave_new_tab_ui:generated_resources",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_rewards/resources",
Expand Down
8 changes: 8 additions & 0 deletions browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void BraveBrowserCommandController::InitBraveCommandState() {
#endif
}
UpdateCommandForBraveAdblock();
UpdateCommandForWebcompatReporter();
#if BUILDFLAG(ENABLE_TOR)
UpdateCommandForTor();
#endif
Expand All @@ -138,6 +139,10 @@ void BraveBrowserCommandController::UpdateCommandForBraveAdblock() {
UpdateCommandEnabled(IDC_SHOW_BRAVE_ADBLOCK, true);
}

void BraveBrowserCommandController::UpdateCommandForWebcompatReporter() {
UpdateCommandEnabled(IDC_SHOW_BRAVE_WEBCOMPAT_REPORTER, true);
}

void BraveBrowserCommandController::UpdateCommandForTor() {
#if BUILDFLAG(ENABLE_TOR)
const bool is_tor_enabled = !tor::TorProfileService::IsTorDisabled();
Expand Down Expand Up @@ -187,6 +192,9 @@ bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
case IDC_SHOW_BRAVE_ADBLOCK:
brave::ShowBraveAdblock(browser_);
break;
case IDC_SHOW_BRAVE_WEBCOMPAT_REPORTER:
brave::ShowWebcompatReporter(browser_);
break;
case IDC_NEW_OFFTHERECORD_WINDOW_TOR:
brave::NewOffTheRecordWindowTor(browser_);
break;
Expand Down
1 change: 1 addition & 0 deletions browser/ui/brave_browser_command_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class BraveBrowserCommandController : public chrome::BrowserCommandController {
void InitBraveCommandState();
void UpdateCommandForBraveRewards();
void UpdateCommandForBraveAdblock();
void UpdateCommandForWebcompatReporter();
void UpdateCommandForTor();
void UpdateCommandForBraveSync();
void UpdateCommandForBraveWallet();
Expand Down
10 changes: 10 additions & 0 deletions browser/ui/brave_pages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "brave/browser/ui/brave_pages.h"

#include "brave/browser/webcompat_reporter/webcompat_reporter_dialog.h"
#include "brave/common/webui_url_constants.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/singleton_tabs.h"
Expand All @@ -24,6 +25,15 @@ void ShowBraveAdblock(Browser* browser) {
GetSingletonTabNavigateParams(browser, GURL(kBraveUIAdblockURL)));
}

void ShowWebcompatReporter(Browser* browser) {
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
if (!web_contents)
return;

OpenWebcompatReporterDialog(web_contents);
}

void ShowBraveSync(Browser* browser) {
ShowSingletonTabOverwritingNTP(
browser,
Expand Down
1 change: 1 addition & 0 deletions browser/ui/brave_pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Browser;
namespace brave {

void ShowBraveAdblock(Browser* browser);
void ShowWebcompatReporter(Browser* browser);
void ShowBraveRewards(Browser* browser);
void ShowBraveSync(Browser* browser);
void ShowBraveWallet(Browser* browser);
Expand Down
5 changes: 5 additions & 0 deletions browser/ui/toolbar/brave_app_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
IDC_NEW_OFFTHERECORD_WINDOW_TOR,
IDS_NEW_OFFTHERECORD_WINDOW_TOR);
}

InsertItemWithStringIdAt(
GetIndexOfCommandId(IDC_ABOUT),
IDC_SHOW_BRAVE_WEBCOMPAT_REPORTER,
IDS_SHOW_BRAVE_WEBCOMPAT_REPORTER);
}
4 changes: 4 additions & 0 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/memory/ptr_util.h"
#include "brave/browser/ui/webui/brave_adblock_ui.h"
#include "brave/browser/ui/webui/webcompat_reporter_ui.h"
#include "brave/browser/ui/webui/brave_new_tab_ui.h"
#include "brave/common/pref_names.h"
#include "brave/common/webui_url_constants.h"
Expand Down Expand Up @@ -61,6 +62,8 @@ WebUIController* NewWebUI<BasicUI>(WebUI* web_ui, const GURL& url) {
auto host = url.host_piece();
if (host == kAdblockHost) {
return new BraveAdblockUI(web_ui, url.host());
} else if (host == kWebcompatReporterHost) {
return new WebcompatReporterUI(web_ui, url.host());
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
} else if (host == kWalletHost) {
return new BraveWalletUI(web_ui, url.host());
Expand Down Expand Up @@ -98,6 +101,7 @@ WebUIController* NewWebUI<BasicUI>(WebUI* web_ui, const GURL& url) {
WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
const GURL& url) {
if (url.host_piece() == kAdblockHost ||
url.host_piece() == kWebcompatReporterHost ||
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
url.host_piece() == kWalletHost ||
#endif
Expand Down
13 changes: 13 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,19 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "viewingId", IDS_BRAVE_REWARDS_INTERNALS_VIEWING_ID },
{ "walletPaymentId", IDS_BRAVE_REWARDS_INTERNALS_WALLET_PAYMENT_ID },
}
}, {
std::string("webcompat"), {
// Report modal
{ "reportModalTitle", IDS_BRAVE_WEBCOMPATREPORTER_REPORT_MODAL_TITLE },
{ "reportExplanation", IDS_BRAVE_WEBCOMPATREPORTER_REPORT_EXPLANATION },
{ "reportDisclaimer", IDS_BRAVE_WEBCOMPATREPORTER_REPORT_DISCLAIMER },
{ "cancel", IDS_BRAVE_WEBCOMPATREPORTER_CANCEL },
{ "submit", IDS_BRAVE_WEBCOMPATREPORTER_SUBMIT },
// Confirmation modal
{ "thankYou", IDS_BRAVE_WEBCOMPATREPORTER_THANK_YOU },
{ "confirmationNotice",
IDS_BRAVE_WEBCOMPATREPORTER_CONFIRMATION_NOTICE },
}
}
};
AddLocalizedStringsBulk(source, localized_strings[name]);
Expand Down
75 changes: 75 additions & 0 deletions browser/ui/webui/webcompat_reporter_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* 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 <memory>

#include "brave/browser/ui/webui/basic_ui.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/webcompat_reporter/resources/grit/webcompat_reporter_generated_map.h"
#include "chrome/browser/browser_process.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 "brave/components/webcompat_reporter/browser/webcompat_report_uploader.h"

namespace {

class WebcompatReporterDOMHandler : public content::WebUIMessageHandler {
public:
WebcompatReporterDOMHandler();
~WebcompatReporterDOMHandler() override;

// WebUIMessageHandler implementation.
void RegisterMessages() override;

private:
void HandleSubmitReport(const base::ListValue* args);
std::unique_ptr<brave::WebcompatReportUploader> uploader_;

DISALLOW_COPY_AND_ASSIGN(WebcompatReporterDOMHandler);
};

WebcompatReporterDOMHandler::WebcompatReporterDOMHandler()
: uploader_(std::make_unique<brave::WebcompatReportUploader>(
g_browser_process->shared_url_loader_factory())) {}

WebcompatReporterDOMHandler::~WebcompatReporterDOMHandler() {}

void WebcompatReporterDOMHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"webcompat_reporter.submitReport",
base::BindRepeating(&WebcompatReporterDOMHandler::HandleSubmitReport,
base::Unretained(this)));
}

void WebcompatReporterDOMHandler::HandleSubmitReport(
const base::ListValue* args) {
DCHECK_EQ(args->GetSize(), 1U);
std::string site_url;
if (!args->GetString(0, &site_url))
return;

uploader_->SubmitReport(site_url);
}

} // namespace

WebcompatReporterUI::WebcompatReporterUI(content::WebUI* web_ui,
const std::string& name)
: ConstrainedWebDialogUI(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource* data_source = CreateBasicUIHTMLSource(
profile, name, kWebcompatReporterGenerated,
kWebcompatReporterGeneratedSize, IDR_WEBCOMPAT_REPORTER_HTML);
content::WebUIDataSource::Add(profile, data_source);

web_ui->AddMessageHandler(std::make_unique<WebcompatReporterDOMHandler>());
}

WebcompatReporterUI::~WebcompatReporterUI() {}
27 changes: 27 additions & 0 deletions browser/ui/webui/webcompat_reporter_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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/. */

#ifndef BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_UI_H_
#define BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_UI_H_

#include <string>

#include "base/macros.h"
#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"

namespace content {
class WebUI;
}

class WebcompatReporterUI : public ConstrainedWebDialogUI {
public:
WebcompatReporterUI(content::WebUI* web_ui, const std::string& host);
~WebcompatReporterUI() override;

private:
DISALLOW_COPY_AND_ASSIGN(WebcompatReporterUI);
};

#endif // BRAVE_BROWSER_UI_WEBUI_WEBCOMPAT_REPORTER_UI_H_
15 changes: 15 additions & 0 deletions browser/webcompat_reporter/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import("//build/config/features.gni")

source_set("webcompat_reporter") {
sources = [
"webcompat_reporter_dialog.cc",
"webcompat_reporter_dialog.h",
]

deps = [
"//base",
"//brave/common",
"//content/public/browser",
"//ui/web_dialogs",
]
}
Loading