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

Native IPFS support in Brave behind a feature flag #5820

Merged
merged 31 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
34197b2
base files for ipfs CRX mgmt
drbh Sep 8, 2018
1cf5307
Buildflags and rebasing for IPFS support
bbondy May 26, 2020
8c54a09
Use valid component IDs for public keys
bbondy Jun 11, 2020
3c0a59c
Add IpfsServiceFactory and IpfsService placeholders
yrliou Jun 12, 2020
570e6ac
Add an IPFS infobar
bbondy Jun 17, 2020
fdf7973
Move ipfs_tab_helper into ipfs/browser target and add deps.
yrliou Jun 26, 2020
808e730
Implement IPFS service in utility process
yrliou Jun 26, 2020
96079d5
Implement ipfs service in browser process
yrliou Jun 26, 2020
e103071
Add IPFS protocol support with gateway
bbondy Jul 13, 2020
8a2e98e
Lint fixes
bbondy Jul 13, 2020
cf14609
Add IPFS feature flag which is disabled by default
yrliou Jul 20, 2020
aaf5a7a
Add IPFS WebUI page
bbondy Aug 10, 2020
fbb39dd
Implement GetConnectedPeers
yrliou Aug 13, 2020
c85e8ae
Fix build error on C85
yrliou Aug 14, 2020
d4619b2
gn check fixes
yrliou Aug 14, 2020
d9563f9
Create ipfs::ContentBrowserClientHelper class to wrap static functions
yrliou Aug 15, 2020
50b5494
Lint fix for IPFSJSONParser
yrliou Aug 15, 2020
48d5ba0
Add setting and resolve IPNS too
bbondy Aug 24, 2020
9cb0a21
Remove logging
bbondy Aug 25, 2020
a4b04e8
Fix tests for BraveIpfsClientUpdaterTest
bbondy Aug 25, 2020
c2ce55d
Add daemon status & control, addresses config in brave://ipfs page.
yrliou Aug 26, 2020
013872b
Update License format in ipfs_ui component
yrliou Aug 26, 2020
b35637b
Launch IPFS daemon when navigating to an IPFS URL if gateway setting …
yrliou Aug 27, 2020
7470850
Add IpfsServiceBrowserTest and more unit tests
yrliou Aug 28, 2020
91bda06
Add IPFS infobar test
bbondy Aug 31, 2020
2a1efdf
Add tests for TranslateIPFSURL
bbondy Aug 31, 2020
4638435
Fix tslint
bbondy Aug 31, 2020
c05dc6e
Use 2020 in new files' license
yrliou Aug 31, 2020
30ac73e
Remove unnecessary headers and user BrowserContext directly without P…
yrliou Aug 31, 2020
749129e
Add IPNS to autocomplete scheme classifier
bbondy Sep 2, 2020
2137752
Remove trailing "/" for Origin header in HTTP requests
yrliou Sep 2, 2020
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
28 changes: 26 additions & 2 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_UTILITY_PROCESS_LEDGER_NAME" desc="The utility process running ledger">
Bat Ledger Service
</message>
<message name="IDS_UTILITY_PROCESS_IPFS_NAME" desc="The utility process which manages IPFS daemon">
IPFS Service
</message>
<message name="IDS_SETTINGS_BRAVE_GET_STARTED_TITLE" desc="The title for the Get Started section in settings">
Get started
</message>
Expand Down Expand Up @@ -656,6 +659,18 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_GOOGLE_LOGIN_FOR_EXTENSIONS" desc="Label for a switch control which allows Google login for extension">
Allow Google login for extensions
</message>
<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_GATEWAY" desc="Select control value for which IPFS resolve method to use">
Gateway
</message>
<message name="IDS_IPFS_RESOLVE_OPTION_LOCAL" desc="Select control value for which IPFS resolve method to use">
Local node
</message>
<message name="IDS_IPFS_RESOLVE_OPTION_DISABLED" desc="Select control value for which IPFS resolve method to use">
Disabled
</message>
<message name="IDS_SETTINGS_HANGOUTS_ENABLED_DESC" desc="The description for Hangouts switch in settings">
Uses Hangouts component to enable screen sharing and other features in the browser.
</message>
Expand All @@ -669,7 +684,7 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Relaunch Now
</message>
<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.
Uses IPFS companion extension to enhance IPFS support in the browser.
</message>
<message name="IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL" desc="The label of manage extensions link in settings">
Manage extensions
Expand Down Expand Up @@ -876,7 +891,16 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_BRAVE_CRYPTO_WALLETS_SETTINGS" desc="Open Crypto Wallets settings">
Settings
</message>

<!-- IPFS -->
<message name="IDS_BRAVE_IPFS_INSTALL" desc="Install IPFS daemon infobar text">
Would you like to enable IPFS local daemon support in Brave?
</message>
<message name="IDS_BRAVE_IPFS_SETTINGS" desc="Open IPFS settings">
Settings
</message>
<message name="IDS_BRAVE_IPFS_ENABLE_IPFS" desc="Instal or Enable IPFS">
Enable IPFS
</message>
<!-- Brave Wayback Machine -->
<message name="IDS_BRAVE_WAYBACK_MACHINE_INFOBAR_PAGE_MISSING_TEXT" desc="The label for sorry message when page is not available on infobar">
Sorry, that page is missing.
Expand Down
27 changes: 27 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//brave/components/greaselion/browser/buildflags/buildflags.gni")
import("//brave/components/ipfs/browser/buildflags/buildflags.gni")
import("//brave/components/speedreader/buildflags.gni")
import("//build/buildflag_header.gni")
import("//build/config/features.gni")
Expand Down Expand Up @@ -136,6 +137,7 @@ source_set("browser_process") {
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/content_settings/core/browser",
"//brave/components/greaselion/browser/buildflags",
"//brave/components/ipfs/browser/buildflags",
"//brave/components/l10n/browser",
"//brave/components/ntp_background_images/browser",
"//brave/components/ntp_tiles",
Expand Down Expand Up @@ -308,6 +310,31 @@ source_set("browser_process") {
]
}

if (ipfs_enabled) {
sources += [
"ipfs/content_browser_client_helper.cc",
"ipfs/content_browser_client_helper.h",
"ipfs/ipfs_navigation_throttle.cc",
"ipfs/ipfs_navigation_throttle.h",
"ipfs/ipfs_service.cc",
"ipfs/ipfs_service.h",
"ipfs/ipfs_service_factory.cc",
"ipfs/ipfs_service_factory.h",
"ipfs/ipfs_service_observer.h",
"ipfs/ipfs_tab_helper.cc",
"ipfs/ipfs_tab_helper.h",
]

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

if (brave_together_enabled) {
deps += [
"//brave/components/brave_together/browser",
Expand Down
10 changes: 10 additions & 0 deletions browser/autocomplete/brave_autocomplete_scheme_classifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/strings/string_util.h"
#include "brave/common/url_constants.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "chrome/browser/profiles/profile.h"

#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
Expand Down Expand Up @@ -46,5 +47,14 @@ BraveAutocompleteSchemeClassifier::GetInputTypeForScheme(
}
#endif

#if BUILDFLAG(IPFS_ENABLED)
if (base::IsStringASCII(scheme) &&
(base::LowerCaseEqualsASCII(scheme, kIPFSScheme) ||
base::LowerCaseEqualsASCII(scheme, kIPNSScheme))) {
return metrics::OmniboxInputType::URL;
}
#endif


return ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme(scheme);
}
16 changes: 16 additions & 0 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
#include "brave/common/tor/pref_names.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
#include "brave/components/ipfs/browser/brave_ipfs_client_updater.h"
#endif

#if BUILDFLAG(ENABLE_SPEEDREADER)
#include "brave/components/speedreader/speedreader_rewriter_service.h"
#endif
Expand Down Expand Up @@ -410,3 +414,15 @@ BraveBrowserProcessImpl::user_model_file_service() {
}

#endif // BUILDFLAG(BRAVE_ADS_ENABLED)

#if BUILDFLAG(IPFS_ENABLED)
ipfs::BraveIpfsClientUpdater*
BraveBrowserProcessImpl::ipfs_client_updater() {
if (ipfs_client_updater_)
return ipfs_client_updater_.get();

ipfs_client_updater_ = ipfs::BraveIpfsClientUpdaterFactory(
brave_component_updater_delegate());
return ipfs_client_updater_.get();
}
#endif // BUILDFLAG(IPFS_ENABLED)
11 changes: 11 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "chrome/browser/browser_process_impl.h"
#include "extensions/buildflags/buildflags.h"
Expand Down Expand Up @@ -58,6 +59,10 @@ namespace extensions {
class BraveTorClientUpdater;
}

namespace ipfs {
class BraveIpfsClientUpdater;
}

namespace speedreader {
class SpeedreaderRewriterService;
}
Expand Down Expand Up @@ -93,6 +98,9 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
brave_component_updater::LocalDataFilesService* local_data_files_service();
#if BUILDFLAG(ENABLE_TOR)
extensions::BraveTorClientUpdater* tor_client_updater();
#endif
#if BUILDFLAG(IPFS_ENABLED)
ipfs::BraveIpfsClientUpdater* ipfs_client_updater();
#endif
brave::BraveP3AService* brave_p3a_service();
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
Expand Down Expand Up @@ -151,6 +159,9 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
#if BUILDFLAG(ENABLE_TOR)
std::unique_ptr<extensions::BraveTorClientUpdater> tor_client_updater_;
#endif
#if BUILDFLAG(IPFS_ENABLED)
std::unique_ptr<ipfs::BraveIpfsClientUpdater> ipfs_client_updater_;
#endif
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
std::unique_ptr<BraveWidevineBundleManager> brave_widevine_bundle_manager_;
#endif
Expand Down
33 changes: 33 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "base/bind.h"
#include "base/feature_list.h"
#include "base/json/json_reader.h"
#include "base/rand_util.h"
#include "base/task/post_task.h"
Expand All @@ -31,6 +32,8 @@
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/features.h"
#include "brave/components/services/brave_content_browser_overlay_manifest.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/grit/brave_generated_resources.h"
Expand Down Expand Up @@ -83,6 +86,11 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#include "brave/browser/extensions/brave_webtorrent_navigation_throttle.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
#include "brave/browser/ipfs/content_browser_client_helper.h"
#include "brave/browser/ipfs/ipfs_navigation_throttle.h"
#endif

#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
#include "brave/components/brave_rewards/browser/rewards_protocol_handler.h"
#endif
Expand Down Expand Up @@ -159,6 +167,16 @@ void BraveContentBrowserClient::BrowserURLHandlerCreated(
content::BrowserURLHandler::null_handler());
handler->AddHandlerPair(&webtorrent::HandleTorrentURLRewrite,
&webtorrent::HandleTorrentURLReverseRewrite);
#endif
#if BUILDFLAG(IPFS_ENABLED)
if (base::FeatureList::IsEnabled(ipfs::features::kIpfsFeature)) {
handler->AddHandlerPair(
&ipfs::ContentBrowserClientHelper::HandleIPFSURLRewrite,
content::BrowserURLHandler::null_handler());
handler->AddHandlerPair(
&ipfs::ContentBrowserClientHelper::HandleIPFSURLRewrite,
&ipfs::ContentBrowserClientHelper::HandleIPFSURLReverseRewrite);
}
#endif
handler->AddHandlerPair(&HandleURLRewrite, &HandleURLReverseOverrideRewrite);
ChromeContentBrowserClient::BrowserURLHandlerCreated(handler);
Expand Down Expand Up @@ -190,6 +208,16 @@ bool BraveContentBrowserClient::HandleExternalProtocol(
return true;
}
#endif
#if BUILDFLAG(IPFS_ENABLED)
if (base::FeatureList::IsEnabled(ipfs::features::kIpfsFeature) &&
ipfs::ContentBrowserClientHelper::IsIPFSProtocol(url)) {
ipfs::ContentBrowserClientHelper::HandleIPFSProtocol(url,
std::move(web_contents_getter),
page_transition, has_user_gesture,
initiating_origin);
return true;
}
#endif

#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
if (brave_rewards::IsRewardsProtocol(url)) {
Expand Down Expand Up @@ -492,5 +520,10 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
throttles.push_back(std::move(tor_navigation_throttle));
#endif

#if BUILDFLAG(IPFS_ENABLED)
throttles.push_back(
std::make_unique<ipfs::IpfsNavigationThrottle>(handle));
#endif

return throttles;
}
9 changes: 9 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefs/session_startup_pref.h"
Expand Down Expand Up @@ -48,6 +49,10 @@
#include "brave/components/brave_wayback_machine/pref_names.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
#include "brave/browser/ipfs/ipfs_service.h"
#endif

#if BUILDFLAG(BRAVE_WALLET_ENABLED)
#include "brave/browser/brave_wallet/brave_wallet_utils.h"
#endif
Expand Down Expand Up @@ -135,6 +140,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kTwitterEmbedControlType, true);
registry->RegisterBooleanPref(kLinkedInEmbedControlType, false);

#if BUILDFLAG(IPFS_ENABLED)
ipfs::IpfsService::RegisterPrefs(registry);
#endif

// WebTorrent
#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
webtorrent::RegisterProfilePrefs(registry);
Expand Down
12 changes: 12 additions & 0 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "brave/common/pref_names.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "brave/common/brave_wallet_constants.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -21,6 +22,10 @@
#include "components/sync/base/pref_names.h"
#include "content/public/test/browser_test.h"

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

#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
#include "brave/components/brave_wayback_machine/pref_names.h"
#endif
Expand Down Expand Up @@ -62,6 +67,13 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(
brave_rewards::prefs::kHideBraveRewardsButton));
#if BUILDFLAG(IPFS_ENABLED)
EXPECT_EQ(
browser()->profile()->GetPrefs()->GetInteger(kIPFSResolveMethod),
static_cast<int>((ipfs::IPFSResolveMethodTypes::IPFS_GATEWAY)));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kIPFSBinaryAvailable));
#endif
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kIPFSCompanionEnabled));
EXPECT_EQ(
Expand Down
17 changes: 17 additions & 0 deletions browser/brave_tab_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

#include "brave/browser/brave_tab_helpers.h"

#include "base/command_line.h"
#include "base/feature_list.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/ui/bookmark/brave_bookmark_tab_helper.h"
#include "brave/common/brave_switches.h"
#include "brave/components/brave_ads/browser/ads_tab_helper.h"
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/browser/features.h"
#include "brave/components/speedreader/buildflags.h"
#include "content/public/browser/web_contents.h"
#include "third_party/widevine/cdm/buildflags.h"
Expand Down Expand Up @@ -56,6 +61,10 @@
#include "brave/browser/tor/tor_tab_helper.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
#include "brave/browser/ipfs/ipfs_tab_helper.h"
#endif

namespace brave {

void AttachTabHelpers(content::WebContents* web_contents) {
Expand Down Expand Up @@ -106,6 +115,14 @@ void AttachTabHelpers(content::WebContents* web_contents) {
#if BUILDFLAG(ENABLE_TOR)
tor::TorTabHelper::MaybeCreateForWebContents(web_contents);
#endif

#if BUILDFLAG(IPFS_ENABLED)
if (base::FeatureList::IsEnabled(ipfs::features::kIpfsFeature) &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableIpfsClientUpdaterExtension)) {
ipfs::IPFSTabHelper::CreateForWebContents(web_contents);
}
#endif
}

} // namespace brave
Loading