Skip to content

Commit

Permalink
Merge pull request #7864 from brave/protocol-associations
Browse files Browse the repository at this point in the history
Set ipns and ifps as default handlers
  • Loading branch information
bbondy authored Feb 11, 2021
2 parents fbd895b + a7f1d89 commit 2b7826e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
11 changes: 9 additions & 2 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include "brave/components/brave_sync/network_time_helper.h"
#include "brave/components/ntp_background_images/browser/features.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/brave_histogram_rewrite.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/services/network/public/cpp/system_request_handler.h"
#include "chrome/browser/component_updater/component_updater_utils.h"
#include "chrome/browser/net/system_network_context_manager.h"
Expand All @@ -41,6 +41,7 @@
#include "components/component_updater/component_updater_service.h"
#include "components/component_updater/timer_update_scheduler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

Expand Down Expand Up @@ -70,6 +71,7 @@

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

#if BUILDFLAG(ENABLE_SPEEDREADER)
Expand Down Expand Up @@ -145,7 +147,12 @@ BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data)

void BraveBrowserProcessImpl::Init() {
BrowserProcessImpl::Init();

#if BUILDFLAG(IPFS_ENABLED)
content::ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
ipfs::kIPFSScheme);
content::ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
ipfs::kIPNSScheme);
#endif
brave_component_updater::BraveOnDemandUpdater::GetInstance()->
RegisterOnDemandUpdateCallback(
base::BindRepeating(&component_updater::BraveOnDemandUpdate));
Expand Down
27 changes: 27 additions & 0 deletions browser/infobars/ipfs_infobar_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "brave/browser/infobars/ipfs_infobar_delegate.h"

#include <memory>
#include <string>
#include <utility>

#include "brave/browser/brave_browser_process_impl.h"
Expand All @@ -15,6 +16,7 @@
#include "brave/components/ipfs/pref_names.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser_finder.h"
#include "components/infobars/core/infobar.h"
#include "components/prefs/pref_service.h"
Expand All @@ -23,6 +25,29 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/vector_icons.h"

namespace {
// Sets current executable as default protocol handler in a system.
void SetupIPFSProtocolHandler(const std::string& protocol) {
auto isDefaultCallback = [](const std::string& protocol,
shell_integration::DefaultWebClientState state) {
if (state == shell_integration::IS_DEFAULT) {
VLOG(1) << protocol << " already has a handler";
return;
}
VLOG(1) << "Set as default handler for " << protocol;
// The worker pointer is reference counted. While it is running, the
// sequence it runs on will hold references it will be automatically
// freed once all its tasks have finished.
base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>(
protocol)
->StartSetAsDefault(base::NullCallback());
};

base::MakeRefCounted<shell_integration::DefaultProtocolClientWorker>(protocol)
->StartCheckIsDefault(base::BindOnce(isDefaultCallback, protocol));
}
} // namespace

// static
void IPFSInfoBarDelegate::Create(InfoBarService* infobar_service,
content::BrowserContext* browser_context) {
Expand Down Expand Up @@ -80,6 +105,8 @@ bool IPFSInfoBarDelegate::Accept() {
->SetInteger(kIPFSResolveMethod,
static_cast<int>(ipfs::IPFSResolveMethodTypes::IPFS_LOCAL));
g_brave_browser_process->ipfs_client_updater()->Register();
SetupIPFSProtocolHandler(ipfs::kIPFSScheme);
SetupIPFSProtocolHandler(ipfs::kIPNSScheme);
return true;
}

Expand Down
13 changes: 13 additions & 0 deletions patches/chrome-installer-linux-common-desktop.template.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/chrome/installer/linux/common/desktop.template b/chrome/installer/linux/common/desktop.template
index 73bb065f5c0d4c462ca2c6a872c56068ea98ec43..df5b8e18e2e288f21a0826c3e5b8f41c1d213e37 100644
--- a/chrome/installer/linux/common/desktop.template
+++ b/chrome/installer/linux/common/desktop.template
@@ -111,7 +111,7 @@ Terminal=false
Icon=@@PACKAGE@@
Type=Application
Categories=Network;WebBrowser;
-MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/ftp;x-scheme-handler/http;x-scheme-handler/https;
+MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/ftp;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns;
Actions=new-window;new-private-window;

[Desktop Action new-window]

0 comments on commit 2b7826e

Please sign in to comment.