Skip to content

Use interstitial page instead of infobar for ipfs #7918

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

Merged
merged 16 commits into from
Feb 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1013,21 +1013,12 @@ up to 6x faster on major news sites.
Don't ask again
</message>
<!-- IPFS -->
<message name="IDS_BRAVE_IPFS_INSTALL" desc="Install IPFS daemon infobar text">
IPFS resources detected. Would you like Brave to load them using a local IPFS node?
</message>
<message name="IDS_BRAVE_WALLET_SETTINGS_SECTION" desc="Open Wallet settings section">
Wallet Settings
</message>
<message name="IDS_BRAVE_IPFS_SETTINGS_SECTION" desc="Open IPFS settings section">
IPFS Settings
</message>
<message name="IDS_BRAVE_IPFS_SETTINGS" desc="Open IPFS settings">
Settings
</message>
<message name="IDS_BRAVE_IPFS_ENABLE_IPFS" desc="Install and Enable IPFS">
Enable IPFS
</message>
<message name="IDS_BRAVE_IPFS_LEARN_MORE">
Learn more about IPFS and privacy
</message>
Expand Down
1 change: 0 additions & 1 deletion browser/brave_tab_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#endif

#if BUILDFLAG(IPFS_ENABLED)
#include "brave/browser/infobars/ipfs_infobar_delegate.h"
#include "brave/browser/ipfs/ipfs_service_factory.h"
#include "brave/browser/ipfs/ipfs_tab_helper.h"
#endif
Expand Down
16 changes: 6 additions & 10 deletions browser/infobars/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import("//build/config/features.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/buildflags/buildflags.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//build/config/features.gni")

source_set("infobars") {
# Remove when https://github.com/brave/brave-browser/issues/10649 is resolved
Expand All @@ -14,9 +14,9 @@ source_set("infobars") {

deps = [
"//base",
"//brave/app:brave_generated_resources_grit",
"//brave/browser/ui",
"//brave/components/p3a",
"//brave/app:brave_generated_resources_grit",
"//chrome/app:chromium_strings",
"//chrome/browser/ui",
"//components/infobars/core",
Expand All @@ -43,13 +43,9 @@ source_set("infobars") {
}

if (ipfs_enabled) {
sources += [
"ipfs_infobar_delegate.cc",
"ipfs_infobar_delegate.h",
]
deps += [
"//brave/components/ipfs",
"//components/user_prefs"
"//components/user_prefs",
]
}

Expand All @@ -60,8 +56,8 @@ source_set("infobars") {
]

deps += [
"//brave/components/brave_wayback_machine",
"//brave/common:switches",
"//brave/components/brave_wayback_machine",
]
}

Expand Down
122 changes: 0 additions & 122 deletions browser/infobars/ipfs_infobar_delegate.cc

This file was deleted.

46 changes: 0 additions & 46 deletions browser/infobars/ipfs_infobar_delegate.h

This file was deleted.

42 changes: 32 additions & 10 deletions browser/ipfs/ipfs_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,42 @@

#include "brave/browser/ipfs/ipfs_tab_helper.h"

#include <string>
#include <vector>

#include "brave/browser/infobars/ipfs_infobar_delegate.h"
#include "brave/browser/ipfs/ipfs_service_factory.h"
#include "brave/components/ipfs/ipfs_constants.h"
#include "brave/components/ipfs/ipfs_service.h"
#include "brave/components/ipfs/ipfs_utils.h"
#include "brave/components/ipfs/pref_names.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/shell_integration.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.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

namespace ipfs {

IPFSTabHelper::~IPFSTabHelper() = default;
Expand Down Expand Up @@ -48,16 +70,16 @@ void IPFSTabHelper::DidFinishNavigation(content::NavigationHandle* handle) {

auto resolve_method = static_cast<ipfs::IPFSResolveMethodTypes>(
pref_service_->GetInteger(kIPFSResolveMethod));
auto* browser_context = web_contents()->GetBrowserContext();
if (resolve_method == ipfs::IPFSResolveMethodTypes::IPFS_ASK &&
handle->GetResponseHeaders() &&
handle->GetResponseHeaders()->HasHeader("x-ipfs-path") &&
IsDefaultGatewayURL(handle->GetURL(),
web_contents()->GetBrowserContext())) {
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents());
if (infobar_service) {
auto* browser_context = web_contents()->GetBrowserContext();
IPFSInfoBarDelegate::Create(infobar_service, browser_context);
IsDefaultGatewayURL(handle->GetURL(), browser_context)) {
auto infobar_count = pref_service_->GetInteger(kIPFSInfobarCount);
if (!infobar_count) {
pref_service_->SetInteger(kIPFSInfobarCount, infobar_count + 1);
SetupIPFSProtocolHandler(ipfs::kIPFSScheme);
SetupIPFSProtocolHandler(ipfs::kIPNSScheme);
}
}
}
Expand Down
Loading