Remove external protocol handling

This commit is contained in:
Brian R. Bondy
2020-11-27 10:35:59 -05:00
parent b21980cb62
commit 1df479bbd1
5 changed files with 1 additions and 189 deletions
-9
View File
@@ -191,15 +191,6 @@ bool BraveContentBrowserClient::HandleExternalProtocol(
return true;
}
#endif
#if BUILDFLAG(IPFS_ENABLED)
if (ipfs::IsIPFSProtocol(url) && is_main_frame) {
ipfs::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)) {
+1 -52
View File
@@ -56,7 +56,7 @@ bool HandleIPFSURLRewrite(
if (!IpfsServiceFactory::IsIpfsResolveMethodDisabled(browser_context) &&
// When it's not the local gateway we don't want to show a ipfs:// URL.
// We instead will translate the URL later in LoadOrLaunchIPFSURL.
// We instead will translate the URL later.
IsIPFSLocalGateway(browser_context) &&
(url->SchemeIs(kIPFSScheme) || url->SchemeIs(kIPNSScheme))) {
return TranslateIPFSURI(*url, url,
@@ -93,55 +93,4 @@ bool HandleIPFSURLReverseRewrite(
return true;
}
bool ShouldNavigateIPFSURI(
const GURL& url,
GURL* new_url,
content::BrowserContext* browser_context) {
*new_url = url;
bool is_ipfs_scheme = url.SchemeIs(kIPFSScheme) || url.SchemeIs(kIPNSScheme);
GURL gateway_url = IsIPFSLocalGateway(browser_context)
? GetDefaultIPFSLocalGateway(chrome::GetChannel())
: GetDefaultIPFSGateway();
return !IpfsServiceFactory::IsIpfsResolveMethodDisabled(browser_context) &&
(!is_ipfs_scheme || TranslateIPFSURI(url, new_url, gateway_url));
}
void LoadOrLaunchIPFSURL(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
ui::PageTransition page_transition,
bool has_user_gesture,
const base::Optional<url::Origin>& initiating_origin) {
content::WebContents* web_contents = std::move(web_contents_getter).Run();
if (!web_contents)
return;
GURL new_url(url);
if (ShouldNavigateIPFSURI(url, &new_url, web_contents->GetBrowserContext())) {
web_contents->GetController().LoadURL(new_url, content::Referrer(),
page_transition, std::string());
} else {
ExternalProtocolHandler::LaunchUrl(
new_url, web_contents->GetRenderViewHost()->GetProcess()->GetID(),
web_contents->GetRenderViewHost()->GetRoutingID(), page_transition,
has_user_gesture, initiating_origin);
}
}
void HandleIPFSProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
ui::PageTransition page_transition,
bool has_user_gesture,
const base::Optional<url::Origin>& initiating_origin) {
DCHECK(url.SchemeIs(kIPFSScheme) || url.SchemeIs(kIPNSScheme));
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&LoadOrLaunchIPFSURL, url, std::move(web_contents_getter),
page_transition, has_user_gesture, initiating_origin));
}
bool IsIPFSProtocol(const GURL& url) {
return TranslateIPFSURI(url, nullptr, GetDefaultIPFSGateway());
}
} // namespace ipfs
@@ -25,10 +25,6 @@ class Origin;
namespace ipfs {
bool ShouldNavigateIPFSURI(const GURL& url,
GURL* new_url,
content::BrowserContext* browser_context);
bool HandleIPFSURLReverseRewrite(
GURL* url,
content::BrowserContext* browser_context);
@@ -43,15 +39,6 @@ void LoadOrLaunchIPFSURL(
bool HandleIPFSURLRewrite(GURL* url,
content::BrowserContext* browser_context);
void HandleIPFSProtocol(
const GURL& url,
content::WebContents::OnceGetter web_contents_getter,
ui::PageTransition page_transition,
bool has_user_gesture,
const base::Optional<url::Origin>& initiating_origin);
bool IsIPFSProtocol(const GURL& url);
} // namespace ipfs
#endif // BRAVE_BROWSER_IPFS_CONTENT_BROWSER_CLIENT_HELPER_H_
@@ -39,47 +39,12 @@ const GURL& GetIPFSURI() {
return ipfs_url;
}
const GURL& GetIPFSGatewayURL() {
static const GURL ipfs_url(
"https://dweb.link/ipfs/"
"bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/"
"Vincent_van_Gogh.html"); // NOLINT
return ipfs_url;
}
const GURL& GetIPFSLocalURL() {
static const GURL ipfs_url(
ipfs::GetDefaultIPFSLocalGateway(chrome::GetChannel()).spec() +
"ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/"
"Vincent_van_Gogh.html"); // NOLINT
return ipfs_url;
}
const GURL& GetIPNSURI() {
static const GURL ipns_url(
"ipns://tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html"); // NOLINT
return ipns_url;
}
const GURL& GetIPNSGatewayURL() {
static const GURL ipns_url(
"https://dweb.link/ipns/tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html"); // NOLINT
return ipns_url;
}
const GURL& GetIPFSLocalhostURL() {
static const GURL ipfs_url(
"http://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq."
"ipfs.localhost/wiki/Vincent_van_Gogh.html");
return ipfs_url;
}
const GURL& GetIPNSLocalhostURL() {
static const GURL ipns_url(
"http://tr.wikipedia-on-ipfs.org.ipns.localhost/wiki/Anasayfa.html");
return ipns_url;
}
} // namespace
using content::NavigationThrottle;
@@ -173,72 +138,4 @@ TEST_F(ContentBrowserClientHelperUnitTest, HandleIPNSURLRewriteLocal) {
ASSERT_TRUE(HandleIPFSURLRewrite(&ipns_uri, browser_context()));
}
TEST_F(ContentBrowserClientHelperUnitTest, ShouldNavigateIPFSURIDisabled) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_DISABLED));
GURL new_url;
ASSERT_FALSE(
ShouldNavigateIPFSURI(GetIPFSURI(), &new_url, browser_context()));
}
TEST_F(ContentBrowserClientHelperUnitTest,
ShouldNavigateIPFSURIGatewayIPFSURI) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
GURL new_url;
ASSERT_TRUE(ShouldNavigateIPFSURI(GetIPFSURI(), &new_url, browser_context()));
ASSERT_EQ(new_url, GetIPFSGatewayURL());
}
TEST_F(ContentBrowserClientHelperUnitTest,
ShouldNavigateIPFSURIGatewayIPFSHTTPURI) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
GURL new_url;
ASSERT_TRUE(
ShouldNavigateIPFSURI(GetIPFSGatewayURL(), &new_url, browser_context()));
ASSERT_EQ(new_url, GetIPFSGatewayURL());
}
TEST_F(ContentBrowserClientHelperUnitTest, ShouldNavigateIPFSURILocalIPFSURI) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod, static_cast<int>(IPFSResolveMethodTypes::IPFS_LOCAL));
GURL new_url;
ASSERT_TRUE(ShouldNavigateIPFSURI(GetIPFSURI(), &new_url, browser_context()));
ASSERT_EQ(new_url, GetIPFSLocalURL());
}
TEST_F(ContentBrowserClientHelperUnitTest,
ShouldNavigateIPFSURILocalIPFSHTTPURI) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod, static_cast<int>(IPFSResolveMethodTypes::IPFS_LOCAL));
GURL new_url;
ASSERT_TRUE(
ShouldNavigateIPFSURI(GetIPFSLocalURL(), &new_url, browser_context()));
ASSERT_EQ(new_url, GetIPFSLocalURL());
}
TEST_F(ContentBrowserClientHelperUnitTest,
ShouldNavigateIPFSURIGatewayIPNSURI) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod,
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
GURL new_url;
ASSERT_TRUE(ShouldNavigateIPFSURI(GetIPNSURI(), &new_url, browser_context()));
ASSERT_EQ(new_url, GetIPNSGatewayURL());
}
TEST_F(ContentBrowserClientHelperUnitTest, HandleIPFSURLReverseRewrite) {
GURL url = GetIPFSLocalhostURL();
ASSERT_TRUE(HandleIPFSURLReverseRewrite(&url, browser_context()));
ASSERT_EQ(url, GetIPFSURI());
url = GetIPNSLocalhostURL();
ASSERT_TRUE(HandleIPFSURLReverseRewrite(&url, browser_context()));
ASSERT_EQ(url, GetIPNSURI());
}
} // namespace ipfs
-12
View File
@@ -159,16 +159,4 @@ IN_PROC_BROWSER_TEST_F(IpfsDisabledPolicyTest, HandleIPFSURLRewrite) {
EXPECT_FALSE(ipfs::HandleIPFSURLRewrite(&url, browser_context()));
}
IN_PROC_BROWSER_TEST_F(IpfsEnabledPolicyTest, ShouldNavigateIPFSURI) {
GURL new_url;
EXPECT_TRUE(
ipfs::ShouldNavigateIPFSURI(ipfs_url(), &new_url, browser_context()));
}
IN_PROC_BROWSER_TEST_F(IpfsDisabledPolicyTest, ShouldNavigateIPFSURI) {
GURL new_url;
EXPECT_FALSE(
ipfs::ShouldNavigateIPFSURI(ipfs_url(), &new_url, browser_context()));
}
} // namespace policy