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

Display IPFS interstitial page when failed to use local node #6782

Merged
merged 5 commits into from
Oct 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_IPFS_RESOLVE_OPTION_DISABLED" desc="Select control value for which IPFS resolve method to use">
Disabled
</message>
<message name="IDS_SETTINGS_IPFS_AUTO_FALLBACK_TO_GATEWAY_LABEL" desc="The text label for IPFS public gateway fallback switch">
IPFS public gateway fallback
</message>
<message name="IDS_SETTINGS_IPFS_AUTO_FALLBACK_TO_GATEWAY_DESC" desc="The description for the switch of automatically fallback to IPFS public gateway">
Automatically fallback to IPFS public gateway when the local node cannot be accessed.
</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 Down
2 changes: 2 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
#if BUILDFLAG(IPFS_ENABLED)
(*s_brave_whitelist)[kIPFSResolveMethod] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_brave_whitelist)[kIPFSAutoFallbackToGateway] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
#endif
// Media Router Pref
(*s_brave_whitelist)[kBraveEnabledMediaRouter] =
Expand Down
2 changes: 1 addition & 1 deletion browser/ipfs/content_browser_client_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "brave/browser/profiles/profile_util.h"
#include "brave/common/url_constants.h"
#include "brave/components/ipfs/browser/ipfs_service.h"
#include "brave/components/ipfs/browser/translate_ipfs_uri.h"
#include "brave/components/ipfs/common/ipfs_constants.h"
#include "brave/components/ipfs/common/pref_names.h"
#include "brave/components/ipfs/common/translate_ipfs_uri.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ source_set("net") {
"ipfs_redirect_network_delegate_helper.h",
]
deps += [
"//brave/components/ipfs/browser",
"//brave/components/ipfs/common",
]
}

Expand Down
2 changes: 1 addition & 1 deletion browser/net/ipfs_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "brave/browser/net/ipfs_redirect_network_delegate_helper.h"

#include "brave/components/ipfs/browser/translate_ipfs_uri.h"
#include "brave/components/ipfs/common/translate_ipfs_uri.h"
#include "net/base/net_errors.h"

namespace ipfs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
menu-options="[[ipfsResolveMethod_]]">
</settings-dropdown-menu>
</div>
<settings-toggle-button id="ipfsAutoGatewayFallbackEnabled"
class="cr-row"
pref="{{prefs.brave.ipfs.auto_fallback_to_gateway}}"
label=$i18n{ipfsAutoFallbackToGatewayLabel}
sub-label=$i18n{ipfsAutoFallbackToGatewayDesc}>
</settings-toggle-button>
</template>
<settings-toggle-button id="ipfsCompanionEnabled"
class="cr-row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_HANGOUTS_ENABLED_DESC},
{"resolveIPFSURLDesc",
IDS_SETTINGS_RESOLVE_IPFS_URLS_DESC},
{"ipfsAutoFallbackToGatewayLabel",
IDS_SETTINGS_IPFS_AUTO_FALLBACK_TO_GATEWAY_LABEL},
{"ipfsAutoFallbackToGatewayDesc",
IDS_SETTINGS_IPFS_AUTO_FALLBACK_TO_GATEWAY_DESC},
Copy link
Member Author

@yrliou yrliou Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @bridiver here for chromium_src owner review.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for @bridiver to review this particular chromium_src change. The codeowner file has some false positives in some cases like this which doesn't need his review.

{"ipfsCompanionEnabledDesc",
IDS_SETTINGS_IPFS_COMPANION_ENABLED_DESC},
{"mediaRouterEnabledDesc",
Expand Down
13 changes: 10 additions & 3 deletions components/ipfs/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,38 @@ source_set("browser") {
"brave_ipfs_client_updater.h",
"features.cc",
"features.h",
"ipfs_interstitial_controller_client.cc",
"ipfs_interstitial_controller_client.h",
"ipfs_json_parser.cc",
"ipfs_json_parser.h",
"ipfs_navigation_throttle.cc",
"ipfs_navigation_throttle.h",
"ipfs_not_connected_page.cc",
"ipfs_not_connected_page.h",
"ipfs_service.cc",
"ipfs_service.h",
"ipfs_service_observer.h",
"translate_ipfs_uri.cc",
"translate_ipfs_uri.h",
Copy link
Contributor

@iefremov iefremov Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically there is no need to split a component into browser, common, etc unless all code lives in the browser process. This is needed only when there is something needed for renderer and something for browesr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbondy has a different PR in progress for moving all files into browser folder, I'll leave it as is here, I move this one to common in this PR because I'm using a function in translate_ipfs_uri.cc in ipfs_utils which is currently under common folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, np, just a side note. We basically can just keep everything in components/ipfs

]

deps = [
"//base",
"//brave/components/brave_component_updater/browser/",
"//brave/components/ipfs/common",
"//brave/components/resources:static_resources_grit",
"//brave/components/resources:static_resources",
"//brave/components/resources:strings",
"//brave/components/services/ipfs/public/mojom",
"//components/infobars/core",
"//components/keyed_service/core",
"//components/language/core/browser:browser",
"//components/prefs",
"//components/security_interstitials/content:security_interstitial_page",
"//components/security_interstitials/core",
"//components/user_prefs",
"//content/public/browser",
"//content/public/common",
"//services/network/public/cpp",
"//third_party/re2",
"//ui/base",
"//url",
]
}
57 changes: 57 additions & 0 deletions components/ipfs/browser/ipfs_interstitial_controller_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Copyright (c) 2020 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/components/ipfs/browser/ipfs_interstitial_controller_client.h"

#include "brave/components/ipfs/common/ipfs_utils.h"
#include "brave/components/ipfs/common/pref_names.h"
#include "components/language/core/browser/locale_util.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/referrer.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"

namespace ipfs {

// static
std::unique_ptr<security_interstitials::MetricsHelper>
IPFSInterstitialControllerClient::GetMetricsHelper(const GURL& url) {
security_interstitials::MetricsHelper::ReportDetails report_details;
report_details.metric_prefix = "ipfs";

return std::make_unique<security_interstitials::MetricsHelper>(
url, report_details, nullptr);
}

IPFSInterstitialControllerClient::IPFSInterstitialControllerClient(
content::WebContents* web_contents,
const GURL& request_url,
PrefService* prefs)
: security_interstitials::SecurityInterstitialControllerClient(
web_contents,
GetMetricsHelper(request_url),
prefs,
language::GetApplicationLocale(prefs),
GURL("about:blank") /* default_safe_page */),
request_url_(request_url) {}

void IPFSInterstitialControllerClient::Proceed() {
PrefService* prefs = GetPrefService();
DCHECK(prefs);
prefs->SetBoolean(kIPFSAutoFallbackToGateway, true);

GURL url = IpfsUtils::ToPublicGatewayURL(request_url_);
DCHECK(!url.is_empty());

content::OpenURLParams params(url, content::Referrer(),
WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_LINK, false);
web_contents_->OpenURL(params);
}

} // namespace ipfs
49 changes: 49 additions & 0 deletions components/ipfs/browser/ipfs_interstitial_controller_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright (c) 2020 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/. */

#ifndef BRAVE_COMPONENTS_IPFS_BROWSER_IPFS_INTERSTITIAL_CONTROLLER_CLIENT_H_
#define BRAVE_COMPONENTS_IPFS_BROWSER_IPFS_INTERSTITIAL_CONTROLLER_CLIENT_H_

#include <memory>

#include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "url/gurl.h"

namespace content {
class WebContents;
} // namespace content

namespace security_interstitials {
class MetricsHelper;
} // namespace security_interstitials

namespace ipfs {

class IPFSInterstitialControllerClient
: public security_interstitials::SecurityInterstitialControllerClient {
public:
static std::unique_ptr<security_interstitials::MetricsHelper>
GetMetricsHelper(const GURL& url);

IPFSInterstitialControllerClient(content::WebContents* web_contents,
const GURL& request_url,
PrefService* prefs);
~IPFSInterstitialControllerClient() override = default;

IPFSInterstitialControllerClient(const IPFSInterstitialControllerClient&) =
delete;
IPFSInterstitialControllerClient& operator=(
const IPFSInterstitialControllerClient&) = delete;

// security_interstitials::SecurityInterstitialControllerClient:
void Proceed() override;

private:
const GURL request_url_;
};

} // namespace ipfs

#endif // BRAVE_COMPONENTS_IPFS_BROWSER_IPFS_INTERSTITIAL_CONTROLLER_CLIENT_H_
Loading