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 Privacy Pass extension #2576

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_IPFS_COMPANION_ENABLED_DESC" desc="The description for IPFS companion switch in settings">
Uses IPFS companion extension to support IPFS in the browser.
</message>
<message name="IDS_SETTINGS_PRIVACYPASS_ENABLED_DESC" desc="The description for Privacy Pass switch in settings">
Adds Privacy Pass extension to the browser.
</message>
<message name="IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL" desc="The label of manage extensions link in settings">
Manage extensions
</message>
Expand Down
3 changes: 3 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kNewTabPageShowClock, true);
registry->RegisterBooleanPref(kNewTabPageShowTopSites, true);
registry->RegisterBooleanPref(kNewTabPageShowStats, true);

// Privacy Pass extension
registry->RegisterBooleanPref(kPrivacyPassEnabled, false);
}

} // namespace brave
2 changes: 2 additions & 0 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
browser()->profile()->GetPrefs()->GetBoolean(kHideBraveRewardsButton));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kIPFSCompanionEnabled));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kPrivacyPassEnabled));
}

IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest,
Expand Down
3 changes: 3 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
// IPFS Companion pref
(*s_brave_whitelist)[kIPFSCompanionEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// Privacy Pass pref
(*s_brave_whitelist)[kPrivacyPassEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
return *s_brave_whitelist;
}

Expand Down
4 changes: 4 additions & 0 deletions browser/extensions/brave_extension_management.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void BraveExtensionManagement::OnExtensionLoaded(
const Extension* extension) {
if (extension->id() == ipfs_companion_extension_id)
pref_service_->SetBoolean(kIPFSCompanionEnabled, true);
if (extension->id() == privacypass_extension_id)
pref_service_->SetBoolean(kPrivacyPassEnabled, true);
}

void BraveExtensionManagement::OnExtensionUnloaded(
Expand All @@ -62,6 +64,8 @@ void BraveExtensionManagement::OnExtensionUnloaded(
UnloadedExtensionReason reason) {
if (extension->id() == ipfs_companion_extension_id)
pref_service_->SetBoolean(kIPFSCompanionEnabled, false);
if (extension->id() == privacypass_extension_id)
pref_service_->SetBoolean(kPrivacyPassEnabled, false);
}

} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cr.define('settings', function() {
setWebTorrentEnabled(value) {}
setHangoutsEnabled(value) {}
setIPFSCompanionEnabled(value) {}
setPrivacyPassEnabled(value) {}
}

/**
Expand All @@ -27,6 +28,9 @@ cr.define('settings', function() {
setIPFSCompanionEnabled(value) {
chrome.send('setIPFSCompanionEnabled', [value]);
}
setPrivacyPassEnabled(value) {
chrome.send('setPrivacyPassEnabled', [value]);
}
}

cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
sub-label="$i18n{ipfsCompanionEnabledDesc}"
on-settings-boolean-control-change="onIPFSCompanionEnabledChange_">
</settings-toggle-button>
<settings-toggle-button id="privacyPassEnabled"
pref="{{prefs.brave.privacypass_enabled}}"
label="Privacy Pass"
sub-label="$i18n{privacyPassEnabledDesc}"
on-settings-boolean-control-change="onPrivacyPassEnabledChange_">
</settings-toggle-button>
<div class="settings-row" id="manageExtensionsRow">
<cr-link-row icon-class="icon-external"
label="$i18n{manageExtensionsLabel}" on-click="openExtensionsPage_">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Polymer({
this.onWebTorrentEnabledChange_ = this.onWebTorrentEnabledChange_.bind(this)
this.onHangoutsEnabledChange_ = this.onHangoutsEnabledChange_.bind(this)
this.onIPFSCompanionEnabledChange_ = this.onIPFSCompanionEnabledChange_.bind(this)
this.onPrivacyPassEnabledChange_ = this.onPrivacyPassEnabledChange_.bind(this)
this.openExtensionsPage_ = this.openExtensionsPage_.bind(this)
},

Expand All @@ -40,6 +41,10 @@ Polymer({
this.browserProxy_.setIPFSCompanionEnabled(this.$.ipfsCompanionEnabled.checked);
},

onPrivacyPassEnabledChange_: function() {
this.browserProxy_.setPrivacyPassEnabled(this.$.privacyPassEnabled.checked);
},

openExtensionsPage_: function() {
window.open("chrome://extensions", "_self");
},
Expand Down
32 changes: 32 additions & 0 deletions browser/ui/webui/settings/brave_default_extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void BraveDefaultExtensionsHandler::RegisterMessages() {
base::BindRepeating(
&BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"setPrivacyPassEnabled",
base::BindRepeating(
&BraveDefaultExtensionsHandler::SetPrivacyPassEnabled,
base::Unretained(this)));
}

void BraveDefaultExtensionsHandler::SetWebTorrentEnabled(
Expand Down Expand Up @@ -136,3 +141,30 @@ void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled(
extensions::disable_reason::DisableReason::DISABLE_USER_ACTION);
}
}

void BraveDefaultExtensionsHandler::SetPrivacyPassEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
CHECK(profile_);
bool enabled;
args->GetBoolean(0, &enabled);

extensions::ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
if (enabled) {
if (!IsExtensionInstalled(privacypass_extension_id)) {
scoped_refptr<extensions::WebstoreInstallWithPrompt> installer =
new extensions::WebstoreInstallWithPrompt(
privacypass_extension_id, profile_,
base::BindOnce(&BraveDefaultExtensionsHandler::OnInstallResult,
weak_ptr_factory_.GetWeakPtr(),
kPrivacyPassEnabled));
installer->BeginInstall();
}
service->EnableExtension(privacypass_extension_id);
} else {
service->DisableExtension(
privacypass_extension_id,
extensions::disable_reason::DisableReason::DISABLE_USER_ACTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler {
void SetWebTorrentEnabled(const base::ListValue* args);
void SetHangoutsEnabled(const base::ListValue* args);
void SetIPFSCompanionEnabled(const base::ListValue* args);
void SetPrivacyPassEnabled(const base::ListValue* args);

bool IsExtensionInstalled(const std::string& extension_id) const;
void OnInstallResult(const std::string& pref_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_HANGOUTS_ENABLED_DESC},
{"ipfsCompanionEnabledDesc",
IDS_SETTINGS_IPFS_COMPANION_ENABLED_DESC},
{"privacyPassEnabledDesc",
IDS_SETTINGS_PRIVACYPASS_ENABLED_DESC},
{"manageExtensionsLabel",
IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL}
};
Expand Down
2 changes: 2 additions & 0 deletions common/extensions/extension_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ const char ipfs_companion_extension_public_key[] =

const char ipfs_companion_beta_extension_id[] =
"hjoieblefckbooibpepigmacodalfndh";

const char privacypass_extension_id[] = "ajhmfdgkijocedmfjonnpjfojldioehi";
2 changes: 2 additions & 0 deletions common/extensions/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ extern const char ipfs_companion_extension_public_key[];

extern const char ipfs_companion_beta_extension_id[];

extern const char privacypass_extension_id[];

#endif // BRAVE_COMMON_EXTENSIONS_EXTENSION_CONSTANTS_H_
1 change: 1 addition & 0 deletions common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ const char kNewTabPageShowBackgroundImage[] =
const char kNewTabPageShowClock[] = "brave.new_tab_page.show_clock";
const char kNewTabPageShowTopSites[] = "brave.new_tab_page.show_top_sites";
const char kNewTabPageShowStats[] = "brave.new_tab_page.show_stats";
const char kPrivacyPassEnabled[] = "brave.privacypass_enabled";
1 change: 1 addition & 0 deletions common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ extern const char kNewTabPageShowBackgroundImage[];
extern const char kNewTabPageShowClock[];
extern const char kNewTabPageShowTopSites[];
extern const char kNewTabPageShowStats[];
extern const char kPrivacyPassEnabled[];

#endif // BRAVE_COMMON_PREF_NAMES_H_