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 IPFS option for Gateway vs Ask #6583

Merged
merged 1 commit into from
Sep 8, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Expand Up @@ -662,6 +662,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_RESOLVE_IPFS_URLS_DESC" desc="The description for how to handle IPFS URIs">
Method to resolve IPFS locations
</message>
<message name="IDS_IPFS_RESOLVE_OPTION_ASK" desc="Select control value for which IPFS resolve method to use">
Ask
</message>
<message name="IDS_IPFS_RESOLVE_OPTION_GATEWAY" desc="Select control value for which IPFS resolve method to use">
Gateway
</message>
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_profile_prefs_browsertest.cc
Expand Up @@ -70,7 +70,7 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
#if BUILDFLAG(IPFS_ENABLED)
EXPECT_EQ(
browser()->profile()->GetPrefs()->GetInteger(kIPFSResolveMethod),
static_cast<int>((ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY)));
static_cast<int>((ipfs::IPFSResolveMethodTypes::IPFS_ASK)));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kIPFSBinaryAvailable));
#endif
Expand Down
3 changes: 3 additions & 0 deletions browser/extensions/api/ipfs_api.cc
Expand Up @@ -42,6 +42,9 @@ namespace api {
ExtensionFunction::ResponseAction
IpfsGetIPFSResolveMethodListFunction::Run() {
base::Value list(base::Value::Type::LIST);
list.Append(MakeSelectValue(
l10n_util::GetStringUTF16(IDS_IPFS_RESOLVE_OPTION_ASK),
ipfs::IPFSResolveMethodTypes::IPFS_ASK));
list.Append(MakeSelectValue(
l10n_util::GetStringUTF16(IDS_IPFS_RESOLVE_OPTION_GATEWAY),
ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY));
Expand Down
18 changes: 17 additions & 1 deletion browser/ipfs/ipfs_navigation_throttle_unittest.cc
Expand Up @@ -129,7 +129,7 @@ TEST_F(IpfsNavigationThrottleUnitTest, DeferUntilIpfsProcessLaunched) {
<< GetIPNSURL();
}

TEST_F(IpfsNavigationThrottleUnitTest, ProceedForNonLocalNodeMode) {
TEST_F(IpfsNavigationThrottleUnitTest, ProceedForGatewayNodeMode) {
profile()->GetPrefs()->SetInteger(kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));

Expand All @@ -145,4 +145,20 @@ TEST_F(IpfsNavigationThrottleUnitTest, ProceedForNonLocalNodeMode) {
<< GetIPFSURL();
}

TEST_F(IpfsNavigationThrottleUnitTest, ProceedForAskNodeMode) {
profile()->GetPrefs()->SetInteger(kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_ASK));

content::MockNavigationHandle test_handle(web_contents());
test_handle.set_url(GetIPFSURL());
auto throttle = std::make_unique<IpfsNavigationThrottle>(&test_handle);
EXPECT_EQ(NavigationThrottle::PROCEED, throttle->WillStartRequest().action())
<< GetIPFSURL();

profile()->GetPrefs()->SetInteger(kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_DISABLED));
EXPECT_EQ(NavigationThrottle::PROCEED, throttle->WillStartRequest().action())
<< GetIPFSURL();
}

} // namespace ipfs
2 changes: 1 addition & 1 deletion browser/ipfs/ipfs_service.cc
Expand Up @@ -90,7 +90,7 @@ IpfsService::~IpfsService() = default;
// static
void IpfsService::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(kIPFSResolveMethod,
static_cast<int>(ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY));
static_cast<int>(ipfs::IPFSResolveMethodTypes::IPFS_ASK));
registry->RegisterBooleanPref(kIPFSBinaryAvailable, false);
}

Expand Down
5 changes: 4 additions & 1 deletion browser/ipfs/ipfs_tab_helper.cc
Expand Up @@ -10,6 +10,7 @@
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/infobars/ipfs_infobar_delegate.h"
#include "brave/common/pref_names.h"
#include "brave/components/ipfs/common/ipfs_constants.h"
#include "brave/components/ipfs/common/ipfs_utils.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "components/prefs/pref_service.h"
Expand All @@ -30,7 +31,9 @@ void IPFSTabHelper::UpdateActiveState(content::NavigationHandle* handle) {
DCHECK(handle);
DCHECK(handle->IsInMainFrame());
active_ = true;
if (!pref_service_->GetBoolean(kIPFSBinaryAvailable) &&
auto resolve_method = static_cast<ipfs::IPFSResolveMethodTypes>(
pref_service_->GetInteger(kIPFSResolveMethod));
if (resolve_method == ipfs::IPFSResolveMethodTypes::IPFS_ASK &&
IpfsUtils::IsIPFSURL(handle->GetURL())) {
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents());
Expand Down
2 changes: 1 addition & 1 deletion browser/ipfs/ipfs_tab_helper_browsertest.cc
Expand Up @@ -160,7 +160,7 @@ IN_PROC_BROWSER_TEST_F(IPFSTabHelperTest, InfobarAddWithSettings) {
// Pref for Wallet should still be ask by default
auto method = static_cast<ipfs::IPFSResolveMethodTypes>(
browser()->profile()->GetPrefs()->GetInteger(kIPFSResolveMethod));
ASSERT_EQ(method, ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY);
ASSERT_EQ(method, ipfs::IPFSResolveMethodTypes::IPFS_ASK);
WaitForTabCount(2);
RemoveInfoBarObserver(infobar_service);
}
1 change: 1 addition & 0 deletions components/ipfs/common/ipfs_constants.h
Expand Up @@ -16,6 +16,7 @@ extern const char kAddressesField[];
extern const char kShutdownPath[];

enum class IPFSResolveMethodTypes {
IPFS_ASK,
IPFS_GATEWAY,
IPFS_LOCAL,
IPFS_DISABLED,
Expand Down