-
Notifications
You must be signed in to change notification settings - Fork 922
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
Changes from all commits
10c3c72
b9431fb
6849210
3157a2e
cb284f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. basically there is no need to split a component into There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
] | ||
|
||
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", | ||
] | ||
} |
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 |
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_ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.