Skip to content

Commit

Permalink
Add IPFS gateway support on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Mar 17, 2021
1 parent da80cbe commit 7f0bc31
Show file tree
Hide file tree
Showing 27 changed files with 166 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public void setHTTPSEEnabled(boolean enabled) {
BravePrefServiceBridgeJni.get().setHTTPSEEnabled(enabled);
}

/**
* @param whether the IPFS gateway should be enabled.
*/
public void setIpfsGatewayEnabled(boolean enabled) {
BravePrefServiceBridgeJni.get().setIpfsGatewayEnabled(enabled);
}

/**
* @param whether google login is enabled on third party sites.
*/
Expand Down Expand Up @@ -198,6 +205,7 @@ public boolean getP3ANoticeAcknowledged() {
@NativeMethods
interface Natives {
void setHTTPSEEnabled(boolean enabled);
void setIpfsGatewayEnabled(boolean enabled);
void setAdBlockEnabled(boolean enabled);
void setFingerprintingProtectionEnabled(boolean enabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

public class BravePrivacySettings extends PrivacySettings {
private static final String PREF_HTTPSE = "httpse";
private static final String PREF_IPFS_GATEWAY = "ipfs_gateway";
private static final String PREF_AD_BLOCK = "ad_block";
private static final String PREF_FINGERPRINTING_PROTECTION = "fingerprinting_protection";
private static final String PREF_CLOSE_TABS_ON_EXIT = "close_tabs_on_exit";
Expand All @@ -50,6 +51,7 @@ public class BravePrivacySettings extends PrivacySettings {
private ChromeSwitchPreference mAutocompleteTopSites;
private ChromeSwitchPreference mAutocompleteBraveSuggestedSites;
private ChromeBaseCheckBoxPreference mHttpsePref;
private ChromeBaseCheckBoxPreference mIpfsGatewayPref;
private ChromeBaseCheckBoxPreference mAdBlockPref;
private ChromeBaseCheckBoxPreference mFingerprintingProtectionPref;
private ChromeBaseCheckBoxPreference mCloseTabsOnExitPref;
Expand All @@ -69,6 +71,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
mHttpsePref = (ChromeBaseCheckBoxPreference) findPreference(PREF_HTTPSE);
mHttpsePref.setOnPreferenceChangeListener(this);

mIpfsGatewayPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_IPFS_GATEWAY);
mIpfsGatewayPref.setOnPreferenceChangeListener(this);

mAdBlockPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_AD_BLOCK);
mAdBlockPref.setOnPreferenceChangeListener(this);

Expand Down Expand Up @@ -119,6 +124,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (PREF_HTTPSE.equals(key)) {
BravePrefServiceBridge.getInstance().setHTTPSEEnabled((boolean) newValue);
} else if (PREF_IPFS_GATEWAY.equals(key)) {
BravePrefServiceBridge.getInstance().setIpfsGatewayEnabled((boolean) newValue);
} else if (PREF_AD_BLOCK.equals(key)) {
BravePrefServiceBridge.getInstance().setAdBlockEnabled((boolean) newValue);
} else if (PREF_FINGERPRINTING_PROTECTION.equals(key)) {
Expand Down Expand Up @@ -173,6 +180,7 @@ private void updatePreferences() {
getPreferenceScreen().removePreference(mSendP3A);
}
mHttpsePref.setOrder(++order);
mIpfsGatewayPref.setOrder(++order);
mAdBlockPref.setOrder(++order);
mFingerprintingProtectionPref.setOrder(++order);
mSearchSuggestions.setOrder(++order);
Expand Down
5 changes: 5 additions & 0 deletions android/java/res/xml/brave_privacy_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
android:title="@string/httpse_title"
android:summary="@string/httpse_summary"
android:defaultValue="true" />
<org.chromium.components.browser_ui.settings.ChromeBaseCheckBoxPreference
android:key="ipfs_gateway"
android:title="@string/ipfs_gateway_title"
android:summary="@string/ipfs_gateway_summary"
android:defaultValue="true" />
<org.chromium.components.browser_ui.settings.ChromeBaseCheckBoxPreference
android:key="ad_block"
android:title="@string/ad_block_title"
Expand Down
14 changes: 11 additions & 3 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,21 @@ source_set("browser_process") {
]

deps += [
"//brave/browser/infobars",
"//brave/components/ipfs",
"//brave/components/services/ipfs/public/mojom",
"//components/user_prefs",
"//extensions/browser",
"//extensions/common",
]

if (enable_extensions) {
deps += [
"//extensions/browser",
"//extensions/common",
]
}

if (!is_android) {
deps += [ "//brave/browser/infobars" ]
}
}

if (brave_together_enabled) {
Expand Down
21 changes: 19 additions & 2 deletions browser/android/preferences/brave_pref_service_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

#include "brave/build/android/jni_headers/BravePrefServiceBridge_jni.h"

#include "build/build_config.h"
#include "base/android/jni_string.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
#include "brave/components/brave_referrals/common/pref_names.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/p3a/buildflags.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand All @@ -30,6 +31,11 @@
#include "brave/components/p3a/pref_names.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/pref_names.h"
#endif

using base::android::ConvertUTF8ToJavaString;
using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef;
Expand Down Expand Up @@ -57,6 +63,17 @@ void JNI_BravePrefServiceBridge_SetHTTPSEEnabled(
g_browser_process->local_state());
}

void JNI_BravePrefServiceBridge_SetIpfsGatewayEnabled(JNIEnv* env,
jboolean enabled) {
#if BUILDFLAG(IPFS_ENABLED)
ipfs::IPFSResolveMethodTypes type =
enabled ? ipfs::IPFSResolveMethodTypes::IPFS_ASK
: ipfs::IPFSResolveMethodTypes::IPFS_DISABLED;
GetOriginalProfile()->GetPrefs()->SetInteger(kIPFSResolveMethod,
static_cast<int>(type));
#endif
}

void JNI_BravePrefServiceBridge_SetThirdPartyGoogleLoginEnabled(
JNIEnv* env,
jboolean enabled) {
Expand Down
6 changes: 6 additions & 0 deletions browser/ipfs/ipfs_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_paths.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_system_provider.h"
#include "extensions/browser/extensions_browser_client.h"
#endif

namespace ipfs {

Expand All @@ -39,9 +43,11 @@ IpfsServiceFactory::IpfsServiceFactory()
: BrowserContextKeyedServiceFactory(
"IpfsService",
BrowserContextDependencyManager::GetInstance()) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
DependsOn(
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
#endif
}

IpfsServiceFactory::~IpfsServiceFactory() {}
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
<message name="IDS_HTTPSE_SUMMARY" desc="Summary for HTTPS Everywhere.">
Opens supported sites using HTTPS instead of HTTP when possible
</message>
<message name="IDS_IPFS_GATEWAY_TITLE" desc="Title for IPFS setting.">
IPFS Gateway
</message>
<message name="IDS_IPFS_GATEWAY_SUMMARY" desc="Summary for IPFS gateway setting.">
Allows for navigation to IPFS resources through an IPFS Gateway
</message>
<message name="IDS_AD_BLOCK_TITLE" desc="Title for ad block.">
Ad Block
</message>
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "walletStatusPending", IDS_BRAVE_REWARDS_INTERNALS_WALLET_STATUS_PENDING }, // NOLINT
}
}, {
#if BUILDFLAG(IPFS_ENABLED)
#if BUILDFLAG(ENABLE_TOR)
std::string("tor-internals"), {
{ "tabGeneralInfo", IDS_TOR_INTERNALS_TAB_GENERAL_INFO },
{ "tabLogs", IDS_TOR_INTERNALS_TAB_LOGS },
Expand Down
1 change: 1 addition & 0 deletions chromium_src/chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_rules = [
"+../../../../chrome/browser",
"+../../../../../chrome/browser/android",
"+../../../../../../chrome/browser/android/browsing_data",
"+../../../../../../chrome/browser/android/omnibox",
"+../../../../../../chrome/browser/android/preferences",
"+../../../../../../chrome/browser/android/signin",
"+../../../../../chrome/browser/autocomplete",
Expand Down
3 changes: 2 additions & 1 deletion chromium_src/chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
#define BRAVE_IPFS_FEATURE_ENTRIES \
{"brave-ipfs", \
flag_descriptions::kBraveIpfsName, \
flag_descriptions::kBraveIpfsDescription, kOsDesktop, \
flag_descriptions::kBraveIpfsDescription, \
kOsDesktop | kOsAndroid, \
FEATURE_VALUE_TYPE(ipfs::features::kIpfsFeature)},
#else
#define BRAVE_IPFS_FEATURE_ENTRIES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Copyright (c) 2021 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/autocomplete/brave_autocomplete_scheme_classifier.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"

#define ChromeAutocompleteSchemeClassifier BraveAutocompleteSchemeClassifier
#include "../../../../../../chrome/browser/android/omnibox/autocomplete_controller_android.cc"
#undef ChromeAutocompleteSchemeClassifier
2 changes: 2 additions & 0 deletions chromium_src/chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
if (scheme == kBraveUIScheme)
return true;
if (scheme == "ipfs" || scheme == "ipns")
return true;
return IsHandledProtocol_ChromiumImpl(scheme);
}

Expand Down
4 changes: 3 additions & 1 deletion common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ source_set("common") {
"//brave/components/external_intents/android",
"//brave/components/webcompat_reporter/browser",
"//brave/chromium_src/third_party/blink/renderer/modules:browser_tests",
"//brave/components/ipfs/test:brave_ipfs_browser_tests",
]
if (!is_android && !is_ios) {
visibility += [ "//brave/components/ipfs/test:brave_ipfs_browser_tests" ]
}

# Remove when https://github.com/brave/brave-browser/issues/10653 is resolved
check_includes = false
Expand Down
7 changes: 3 additions & 4 deletions components/ipfs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ source_set("ipfs") {
"//brave/components/resources:static_resources",
"//brave/components/resources:strings",
"//brave/components/services/ipfs/public/mojom",
"//brave/extensions:common",
"//components/component_updater:component_updater",
"//components/infobars/core",
"//components/keyed_service/core",
Expand All @@ -54,6 +55,7 @@ source_set("ipfs") {
"//components/version_info",
"//content/public/browser",
"//content/public/common",
"//extensions/buildflags",
"//net",
"//services/network/public/cpp",
"//third_party/re2",
Expand All @@ -63,9 +65,6 @@ source_set("ipfs") {
]

if (enable_extensions) {
deps += [
"//extensions/browser",
"//extensions/common",
]
deps += [ "//extensions/browser" ]
}
}
1 change: 1 addition & 0 deletions components/ipfs/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_rules = [
"+content/public/browser",
"+content/public/common",
"+extensions/browser",
"+extensions/buildflags",
"+extensions/common",
"+third_party/re2",
"+services/network/public",
Expand Down
5 changes: 5 additions & 0 deletions components/ipfs/brave_ipfs_client_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ static const char kIpfsClientComponentBase64PublicKey[] =
"J9HIuxTzVft5v5Ys0S0Kqorn2xo+lFpVzZT7sV2orDHaLiVB5uqCMWhXehVixfRp"
"BuPGdwSuzJsNkV5aGOObKfoLr1zUgstJYMLB0uWNXTfuKM4EibWUMLMqlCYVzs2R"
"ewIDAQAB";
#elif defined(OS_ANDROID)
// Not used yet
static const char kIpfsClientComponentName[] = "";
static const char kIpfsClientComponentId[] = "";
static const char kIpfsClientComponentBase64PublicKey[] = "";
#endif

class BraveIpfsClientUpdater : public BraveComponent,
Expand Down
2 changes: 1 addition & 1 deletion components/ipfs/buildflags/buildflags.gni
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import("//build/config/features.gni")

declare_args() {
ipfs_enabled = is_mac || is_linux || is_win
ipfs_enabled = !is_ios
}
4 changes: 2 additions & 2 deletions components/ipfs/ipfs_navigation_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ IpfsNavigationThrottle::MaybeCreateThrottleFor(
const std::string& locale) {
if (!ipfs_service)
return nullptr;

return std::make_unique<IpfsNavigationThrottle>(navigation_handle,
ipfs_service, locale);
}
Expand Down Expand Up @@ -107,8 +106,9 @@ IpfsNavigationThrottle::WillStartRequest() {
pref_service_->GetInteger(kIPFSResolveMethod) ==
static_cast<int>(ipfs::IPFSResolveMethodTypes::IPFS_ASK);

if (IsIPFSScheme(url) && should_ask)
if (IsIPFSScheme(url) && should_ask) {
return ShowIPFSOnboardingInterstitial();
}

if (!IsLocalGatewayURL(url)) {
return content::NavigationThrottle::PROCEED;
Expand Down
6 changes: 6 additions & 0 deletions components/ipfs/ipfs_onboarding_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ IPFSOnboardingPage::IPFSOnboardingPage(
std::move(controller)),
ipfs_service_(ipfs_service) {
service_observer_.Observe(ipfs_service_);
#if !defined(OS_ANDROID)
theme_observer_.Observe(ui::NativeTheme::GetInstanceForNativeUi());
#endif
}

IPFSOnboardingPage::~IPFSOnboardingPage() = default;
Expand Down Expand Up @@ -250,8 +252,12 @@ void IPFSOnboardingPage::PopulateInterstitialStrings(
load_time_data->SetString(
"tryAgainText", l10n_util::GetStringUTF16(IDS_IPFS_ONBOARDING_TRY_AGAIN));

#if !defined(OS_ANDROID)
load_time_data->SetString(
"braveTheme", GetThemeType(ui::NativeTheme::GetInstanceForNativeUi()));
#else
load_time_data->SetString("braveTheme", "light");
#endif
}

int IPFSOnboardingPage::GetHTMLTemplateId() {
Expand Down
6 changes: 6 additions & 0 deletions components/ipfs/ipfs_p3a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "extensions/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry.h"
#endif

namespace ipfs {

Expand All @@ -20,11 +24,13 @@ constexpr size_t kP3ATimerInterval = 1;
// IPFS companion installed?
// i) No, ii) Yes
void RecordIPFSCompanionInstalled(content::BrowserContext* context) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
const char ipfs_companion_extension_id[] = "nibjojkomfdiaoajekhjakgkdhaomnch";
auto* registry = extensions::ExtensionRegistry::Get(context);
bool installed =
registry->enabled_extensions().Contains(ipfs_companion_extension_id);
UMA_HISTOGRAM_BOOLEAN("Brave.IPFS.IPFSCompanionInstalled", installed);
#endif
}

int GetIPFSDetectionPromptBucket(PrefService* prefs) {
Expand Down
4 changes: 2 additions & 2 deletions components/ipfs/resources/onboarding/ipfs_onboarding.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</div>
</div>
<div class="nav-wrapper">
<div class="control-box">
<div class="control-box" id="local-node-box">
<div class="button-wrapper">
<button class="button" id="local-node-button">
$i18n{localNodeButton}
Expand All @@ -53,7 +53,7 @@
</div>
</div>
</div>
<div class="footer">
<div class="footer" id="footer">
<p class="copy">
$i18nRaw{footerText}
<a id="open-settings"
Expand Down
Loading

0 comments on commit 7f0bc31

Please sign in to comment.