Skip to content

Commit

Permalink
Add local node to list
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Mar 23, 2021
1 parent a44c16e commit 2550ca0
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 15 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_IPFS_PUBLIC_GATEWAY_DESC" desc="The description of changing IPFS public gateway">
IPFS public gateway address
</message>
<message name="IDS_SETTINGS_IPFS_METHOD_DESC" desc="The description of IPFS protocol on settings page">
<ph name="BEGIN_LINK_MPL">&lt;a target="_blank" rel="noopener noreferrer" href="$1"&gt;</ph>Learn More<ph name="END_LINK_MPL">&lt;/a&gt;</ph> about IPFS local node and gateway privacy considerations.
</message>
<message name="IDS_SETTINGS_IPFS_CHANGE_GATEWAY_BUTTON_LABEL" desc="The label of the button for changing IPFS gateway address">
Change
</message>
Expand Down
10 changes: 4 additions & 6 deletions browser/extensions/api/ipfs_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ ExtensionFunction::ResponseAction IpfsGetResolveMethodListFunction::Run() {
l10n_util::GetStringUTF16(IDS_IPFS_RESOLVE_OPTION_GATEWAY),
IPFSResolveMethodTypes::IPFS_GATEWAY));

if (GetIpfsService(browser_context()) &&
GetIpfsService(browser_context())->IsIPFSExecutableAvailable()) {
list.Append(MakeSelectValue(
l10n_util::GetStringUTF16(IDS_IPFS_RESOLVE_OPTION_LOCAL),
IPFSResolveMethodTypes::IPFS_LOCAL));
}
list.Append(
MakeSelectValue(l10n_util::GetStringUTF16(IDS_IPFS_RESOLVE_OPTION_LOCAL),
IPFSResolveMethodTypes::IPFS_LOCAL));

list.Append(MakeSelectValue(
l10n_util::GetStringUTF16(IDS_IPFS_RESOLVE_OPTION_DISABLED),
IPFSResolveMethodTypes::IPFS_DISABLED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class BraveIPFSBrowserProxyImpl {
chrome.send('setIPFSStorageMax', [value])
}

launchIPFSService (value) {
chrome.send('launchIPFSService', [value])
}

/** @override */
getIPFSResolveMethodList () {
return new Promise(resolve => {
Expand Down
12 changes: 9 additions & 3 deletions browser/resources/settings/brave_ipfs_page/brave_ipfs_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@
.storage-input {
display: flex;
}
</style>
<div class="settings-box first">
<div class="start">$i18n{resolveIPFSURLDesc}</div>
</style>
<div class="settings-box first">
<div class="flex cr-padded-text">
<div class="start">$i18n{resolveIPFSURLDesc}</div>
<div class="secondary" id="defaultIPFSGateway">
$i18nRaw{ipfsMethodDesc}
</div>
</div>
<settings-dropdown-menu id="ipfsResolveMethodType"
pref="{{prefs.brave.ipfs.resolve_method}}"
menu-options="[[ipfsResolveMethod_]]"
on-settings-control-change="onChangeIpfsMethod_">
</settings-dropdown-menu>
</div>

<div class="settings-box">
<div class="flex cr-padded-text">
<div>$i18n{ipfsPublicGatewayDesc}</div>
Expand Down
36 changes: 31 additions & 5 deletions browser/resources/settings/brave_ipfs_page/brave_ipfs_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ Polymer({
WebUIListenerBehavior,
PrefsBehavior
],


/**
* Keep it same as in IPFSResolveMethodTypes
* in brave\components\ipfs\ipfs_constants.h */
IPFSResolveMethodTypes: {
IPFS_ASK: 0,
IPFS_GATEWAY: 1,
IPFS_LOCAL: 2,
IPFS_DISABLED: 3
},

properties: {
ipfsEnabled_: Boolean,
showChangeIPFSGatewayDialog_: Boolean,
isStorageMaxEnabled_: Boolean
isStorageMaxEnabled_: Boolean,
showIPFSLearnMoreLink_: Boolean
},

/** @private {?settings.BraveIPFSBrowserProxy} */
Expand Down Expand Up @@ -51,16 +62,31 @@ Polymer({

onLoad_: function() {
this.isStorageMaxEnabled_ =
this.getPref('brave.ipfs.resolve_method').value == 2;
this.getPref('brave.ipfs.resolve_method').value ==
this.IPFSResolveMethodTypes.IPFS_LOCAL;
// Check if IPFS method is ASK
this.showIPFSLearnMoreLink_ =
this.getPref('brave.ipfs.resolve_method').value ==
this.IPFSResolveMethodTypes.IPFS_ASK;

this.$.ipfsStorageMax.value =
this.getPref('brave.ipfs.storage_max').value;
},

onChangeIpfsMethod_: function() {
// Check if IPFS method is LOCAL_NODE
this.isStorageMaxEnabled_ =
this.getPref('brave.ipfs.resolve_method').value == 2;
const local_node_enabled =
this.getPref('brave.ipfs.resolve_method').value ==
this.IPFSResolveMethodTypes.IPFS_LOCAL;
// Check if IPFS method is ASK
this.showIPFSLearnMoreLink_ =
this.getPref('brave.ipfs.resolve_method').value ==
this.IPFSResolveMethodTypes.IPFS_ASK;

this.isStorageMaxEnabled_ = local_node_enabled;
if (local_node_enabled)
this.browserProxy_.launchIPFSService();

},

onChangeIpfsStorageMax_: function() {
Expand Down
15 changes: 15 additions & 0 deletions browser/ui/webui/settings/brave_default_extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ void BraveDefaultExtensionsHandler::RegisterMessages() {
"setIPFSStorageMax",
base::BindRepeating(&BraveDefaultExtensionsHandler::SetIPFSStorageMax,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"launchIPFSService",
base::BindRepeating(&BraveDefaultExtensionsHandler::LaunchIPFSService,
base::Unretained(this)));

// TODO(petemill): If anything outside this handler is responsible for causing
// restart-neccessary actions, then this should be moved to a generic handler
Expand Down Expand Up @@ -364,6 +368,17 @@ void BraveDefaultExtensionsHandler::OnWidevineEnabledChanged() {
}
}

void BraveDefaultExtensionsHandler::LaunchIPFSService(
const base::ListValue* args) {
ipfs::IpfsService* service =
ipfs::IpfsServiceFactory::GetForContext(profile_);
if (!service) {
return;
}
if (!service->IsDaemonLaunched())
service->LaunchDaemon(base::NullCallback());
}

void BraveDefaultExtensionsHandler::SetIPFSStorageMax(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler {
void SetIPFSCompanionEnabled(const base::ListValue* args);
void SetMediaRouterEnabled(const base::ListValue* args);
void SetIPFSStorageMax(const base::ListValue* args);
void LaunchIPFSService(const base::ListValue* args);
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
void SetBraveWalletEnabled(const base::ListValue* args);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
#include "brave/browser/version_info.h"
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/pref_names.h"
#include "brave/components/sidebar/buildflags/buildflags.h"
#include "chrome/browser/ui/webui/webui_util.h"
Expand Down Expand Up @@ -275,7 +276,6 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
base::ASCIIToUTF16(kGoogleLoginLearnMoreURL));
html_source->AddString("ipfsDNSLinkLearnMoreURL",
base::UTF8ToUTF16(kDNSLinkLearnMoreURL));

html_source->AddString(
"getMoreExtensionsUrl",
base::ASCIIToUTF16(
Expand All @@ -286,6 +286,11 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
html_source->AddString(
"ipfsStorageMaxValue",
std::to_string(profile->GetPrefs()->GetInteger(kIpfsStorageMax)));

base::string16 ipfs_method_desc =
l10n_util::GetStringFUTF16(IDS_SETTINGS_IPFS_METHOD_DESC,
base::ASCIIToUTF16(ipfs::kIPFSLearnMoreURL));
html_source->AddString("ipfsMethodDesc", ipfs_method_desc);
}

void BraveAddResources(content::WebUIDataSource* html_source,
Expand Down
2 changes: 2 additions & 0 deletions components/ipfs/ipfs_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern const char kLocalhostIP[];
extern const char kLocalhostDomain[];
extern const char kGarbageCollectionPath[];

// Keep it synced with IPFSResolveMethodTypes in
// browser/resources/settings/brave_ipfs_page/brave_ipfs_page.js
enum class IPFSResolveMethodTypes {
IPFS_ASK,
IPFS_GATEWAY,
Expand Down

0 comments on commit 2550ca0

Please sign in to comment.