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

Promoting Snowflake in Brave #15907

Merged
merged 10 commits into from
Nov 20, 2022
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
9 changes: 9 additions & 0 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@
<message name="IDS_SETTINGS_ENABLE_TOR_DESC" desc="Text fragment for enabling tor component">
Tor hides your IP address from the sites you visit.
</message>
<message name="IDS_SETTINGS_TOR_SNOWFLAKE_EXTENSION_TITLE" desc="">
Volunteer to help others connect to the Tor network
</message>
<message name="IDS_SETTINGS_TOR_SNOWFLAKE_EXTENSION_DESC" desc="">
Enable the Snowflake extension to allow users in censored countries to connect to the Tor network via your network connection.
</message>
<message name="IDS_SETTINGS_TOR_USE_BRIDGES_TITLE" desc="">
Use Bridges
</message>
Expand All @@ -738,6 +744,9 @@
<message name="IDS_SETTINGS_TOR_CONNECTION_SETTINGS_DESC" desc="">
Controls how Private Windows with Tor connect to the Tor network
</message>
<message name="IDS_SETTINGS_TOR_SNOWFLAKE_INSTALL_FAILED" desc="">
The Snowflake extension necessary for this functionality could not be downloaded. Please check your Internet connection and try again.
</message>
<message name="IDS_SETTINGS_TOR_SELECT_BUILT_IN_RADIO" desc="">
Select a built-in bridge
</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface BraveTorBrowserProxy {
setTorEnabled(value: boolean)
isTorEnabled(): Promise<boolean>
isTorManaged(): Promise<boolean>
isSnowflakeExtensionAllowed(): Promise<boolean>
isSnowflakeExtensionEnabled(): Promise<boolean>
enableSnowflakeExtension(enable: boolean): Promise<boolean>
}

export class BraveTorBrowserProxyImpl implements BraveTorBrowserProxy {
Expand Down Expand Up @@ -49,6 +52,18 @@ export class BraveTorBrowserProxyImpl implements BraveTorBrowserProxy {
isTorManaged() {
return sendWithPromise('brave_tor.isTorManaged')
}

isSnowflakeExtensionAllowed() {
return sendWithPromise('brave_tor.isSnowflakeExtensionAllowed')
}

isSnowflakeExtensionEnabled(): Promise<boolean> {
return sendWithPromise('brave_tor.isSnowflakeExtensionEnabled')
}

enableSnowflakeExtension(enable): Promise<boolean> {
return sendWithPromise('brave_tor.enableSnowflakeExtension', enable)
}
}

let instance: BraveTorBrowserProxy|null = null
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<style include="settings-shared">
</style>
<cr-dialog id="dialog" show-close-button show-on-attach>
<div slot="title"></div>
<div slot="body">
<div>$i18n{torSnowflakeInstallFailed}</div>
</div>
<div slot="button-container">
<cr-button class="cancel-button" id="cancel" on-click="cancelClicked_">OK</cr-button>
</div>
</cr-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2022 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/.

// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck

import 'chrome://resources/cr_elements/cr_button/cr_button.js'
import 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js'
import '../settings_shared.css.js'

import { PolymerElement } from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'
import { I18nMixin } from 'chrome://resources/cr_elements/i18n_mixin.js'
import { getTemplate } from './brave_tor_snowflake_install_failed_dialog.html.js'

const DialogBase = I18nMixin(PolymerElement)

class TorSnowflakeInstallFailedDialog extends DialogBase {
static get is() {
return 'tor-snowflake-install-failed-dialog'
}

static get template() {
return getTemplate()
}

static get properties() {
return {}
}

cancelClicked_() {
this.$.dialog.close()
}
}

customElements.define(
TorSnowflakeInstallFailedDialog.is, TorSnowflakeInstallFailedDialog)
17 changes: 16 additions & 1 deletion browser/resources/settings/brave_tor_page/brave_tor_subpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
<settings-toggle-button pref="{{prefs.tor.auto_onion_location}}" class="cr-row" label="$i18n{autoOnionLocationLabel}"
sub-label="$i18n{autoOnionLocationDesc}" disabled="[[!torEnabledPref_.value]]">
</settings-toggle-button>
<if expr="enable_extensions">
<settings-toggle-button id="torSnowflake" pref="[[torSnowflakeExtensionEnabledPref_]]"
label="$i18n{torSnowflakeExtensionLabel}" sub-label="$i18n{torSnowflakeExtensionDesc}"
disabled="[[!torSnowflakeExtensionAllowed_]]" on-settings-boolean-control-change="onTorSnowflakeExtensionChange_"
learn-more-url="https://support.brave.com/hc/en-us/articles/9059440641421">
</settings-toggle-button>
</if>
<settings-toggle-button id="useBridges" class="cr-row" label="$i18n{torUseBridgesTitle}"
sub-label="$i18n{torUseBridgesDesc}" learn-more-url="https://support.brave.com/hc/en-us/articles/7816553516045"
pref="{{isUsingBridgesPref_}}" disabled="[[!torEnabledPref_.value]]"
Expand Down Expand Up @@ -89,4 +96,12 @@
<template is="dom-if" if="[[showRequestBridgesDialog_]]" restamp>
<request-bridges-dialog id="requestBridgesDialog" on-close="showRequestBridgesDialogClosed_">
</request-bridges-dialog>
</template>
</template>

<if expr="enable_extensions">
<template is="dom-if" if="[[showTorSnowflakeInstallFailed_]]" restamp>
<tor-snowflake-install-failed-dialog id="torSnowflakeInstallFailedDialog"
on-close="torSnowflakeInstallFailedDialogClosed_">
</tor-snowflake-install-failed-dialog>
</template>
</if>
63 changes: 62 additions & 1 deletion browser/resources/settings/brave_tor_page/brave_tor_subpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { RouteObserverMixin } from '../router.js'
import { PrefsMixin } from '../prefs/prefs_mixin.js'
import { BraveTorBrowserProxyImpl } from './brave_tor_browser_proxy.js'
import './brave_tor_bridges_dialog.js'
import './brave_tor_snowflake_install_failed_dialog.js'
import {getTemplate} from './brave_tor_subpage.html.js'
import { loadTimeData } from '../i18n_setup.js'

const SettingBraveTorPageElementBase = I18nMixin(RouteObserverMixin(WebUIListenerMixin(PrefsMixin(PolymerElement))))

Expand Down Expand Up @@ -115,14 +117,32 @@ class SettingsBraveTorPageElement extends SettingBraveTorPageElementBase {
},
},

torSnowflakeExtensionEnabledPref_: {
type: Object,
value() {
return {
key: '',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: false,
}
},
},

torSnowflakeExtensionAllowed_: {
type: Boolean,
value: false,
},

showRequestBridgesDialog_: Boolean,

isConfigChanged_: {
type: Boolean,
computed: 'computeIsConfigChanged_(useBridges_, builtinBridges_, requestedBridges_, providedBridges_, loadedConfig_, shouldShowBridgesGroup_, torEnabledPref_.value)',
value: false,
notify: true
}
},

showTorSnowflakeInstallFailed_: Boolean,
}
}

Expand All @@ -136,6 +156,12 @@ class SettingsBraveTorPageElement extends SettingBraveTorPageElementBase {

ready() {
super.ready()

if (loadTimeData.getBoolean('shouldExposeElementsForTesting')) {
window.testing = window.testing || {}
window.testing[`torSubpage`] = this.shadowRoot
}

this.browserProxy_.getBridgesConfig().then((config) => {
this.loadedConfig_ = config
this.isUsingBridgesPref_ = {
Expand All @@ -160,6 +186,18 @@ class SettingsBraveTorPageElement extends SettingBraveTorPageElementBase {
this.browserProxy_.isTorManaged().then(managed => {
this.disableTorOption_ = managed
})

if (loadTimeData.getBoolean('enable_extensions')) {
this.browserProxy_.isSnowflakeExtensionAllowed().then(allowed => {
this.torSnowflakeExtensionAllowed_ = allowed
})
this.addWebUIListener('tor-snowflake-extension-enabled', enabled => {
this.setTorSnowflakeExtensionEnabledPref_(enabled)
})
this.browserProxy_.isSnowflakeExtensionEnabled().then(enabled => {
this.setTorSnowflakeExtensionEnabledPref_(enabled)
})
}
}

onSlotClick_(e) {
Expand Down Expand Up @@ -321,6 +359,29 @@ class SettingsBraveTorPageElement extends SettingBraveTorPageElementBase {
}
}

setTorSnowflakeExtensionEnabledPref_(enabled: boolean) {
const pref = {
key: '',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: enabled,
}
this.torSnowflakeExtensionEnabledPref_ = pref
}

onTorSnowflakeExtensionChange_(e: Event) {
e.stopPropagation()
this.browserProxy_.enableSnowflakeExtension(e.target.checked).
catch((reason: String) => {
console.log(reason)
this.setTorSnowflakeExtensionEnabledPref_(false)
this.showTorSnowflakeInstallFailed_ = true
})
}

torSnowflakeInstallFailedDialogClosed_() {
this.showTorSnowflakeInstallFailed_ = false
}

currentRouteChanged() {
// This is intentional. currentRouteChanged() should be overridden.
}
Expand Down
1 change: 1 addition & 0 deletions browser/resources/settings/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ brave_settings_web_component_files = [
"brave_sync_page/brave_sync_setup.ts",
"brave_sync_page/brave_sync_subpage.ts",
"brave_tor_page/brave_tor_bridges_dialog.ts",
"brave_tor_page/brave_tor_snowflake_install_failed_dialog.ts",
"brave_tor_page/brave_tor_subpage.ts",
"brave_wallet_page/add_wallet_network_dialog.ts",
"brave_wallet_page/brave_wallet_page.ts",
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ source_set("ui") {
"webui/settings/brave_tor_handler.h",
]
}
if (enable_extensions) {
sources += [
"webui/settings/brave_tor_snowflake_extension_handler.cc",
"webui/settings/brave_tor_snowflake_extension_handler.h",
]
}

public_deps += [ "//brave/vendor/bat-native-ads" ]
} # !is_android
Expand Down
11 changes: 11 additions & 0 deletions browser/ui/webui/brave_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "components/sync/base/command_line_switches.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h"
#include "extensions/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_PIN_SHORTCUT)
#include "brave/browser/ui/webui/settings/pin_shortcut_handler.h"
Expand All @@ -54,6 +55,10 @@
#include "brave/browser/ui/webui/settings/brave_tor_handler.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "brave/browser/ui/webui/settings/brave_tor_snowflake_extension_handler.h"
#endif

using ntp_background_images::ViewCounterServiceFactory;

BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
Expand All @@ -71,6 +76,10 @@ BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
#if BUILDFLAG(ENABLE_TOR)
web_ui->AddMessageHandler(std::make_unique<BraveTorHandler>());
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
web_ui->AddMessageHandler(
std::make_unique<BraveTorSnowflakeExtensionHandler>());
#endif
#if BUILDFLAG(ENABLE_PIN_SHORTCUT)
web_ui->AddMessageHandler(std::make_unique<PinShortcutHandler>());
#endif
Expand Down Expand Up @@ -123,6 +132,8 @@ void BraveSettingsUI::AddResources(content::WebUIDataSource* html_source,

html_source->AddBoolean("shouldExposeElementsForTesting",
ShouldExposeElementsForTesting());

html_source->AddBoolean("enable_extensions", BUILDFLAG(ENABLE_EXTENSIONS));
}

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"torEnabledDesc", IDS_SETTINGS_ENABLE_TOR_DESC},
{"torConnectionSettingsTitle", IDS_SETTINGS_TOR_CONNECTION_SETTINGS_TITLE},
{"torConnectionSettingsDesc", IDS_SETTINGS_TOR_CONNECTION_SETTINGS_DESC},
{"torSnowflakeExtensionLabel", IDS_SETTINGS_TOR_SNOWFLAKE_EXTENSION_TITLE},
{"torSnowflakeExtensionDesc", IDS_SETTINGS_TOR_SNOWFLAKE_EXTENSION_DESC},
{"torSnowflakeInstallFailed", IDS_SETTINGS_TOR_SNOWFLAKE_INSTALL_FAILED},
{"torUseBridgesTitle", IDS_SETTINGS_TOR_USE_BRIDGES_TITLE},
{"torUseBridgesDesc", IDS_SETTINGS_TOR_USE_BRIDGES_DESC},
{"torSelectBuiltInRadio", IDS_SETTINGS_TOR_SELECT_BUILT_IN_RADIO},
Expand Down
1 change: 0 additions & 1 deletion browser/ui/webui/settings/brave_tor_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <memory>

#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "components/prefs/pref_change_registrar.h"
Expand Down
Loading