Permalink
Show file tree
Hide file tree
18 changes: 17 additions & 1 deletion
18
browser/net/ipfs_redirect_network_delegate_helper_unittest.cc
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #14484 from brave/pr14313_brave_24211_1.43.x
Do not commit subframe navigations for ipfs (uplift to 1.43.x)
- Loading branch information
Showing
7 changed files
with
212 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* Copyright (c) 2022 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/browser/ipfs/ipfs_subframe_navigation_throttle.h" | ||
|
|
||
| #include "brave/components/ipfs/ipfs_constants.h" | ||
|
|
||
| namespace ipfs { | ||
|
|
||
| // static | ||
| std::unique_ptr<IpfsSubframeNavigationThrottle> | ||
| IpfsSubframeNavigationThrottle::CreateThrottleFor( | ||
| content::NavigationHandle* navigation_handle) { | ||
| return std::make_unique<IpfsSubframeNavigationThrottle>(navigation_handle); | ||
| } | ||
|
|
||
| IpfsSubframeNavigationThrottle::IpfsSubframeNavigationThrottle( | ||
| content::NavigationHandle* navigation_handle) | ||
| : content::NavigationThrottle(navigation_handle) {} | ||
|
|
||
| IpfsSubframeNavigationThrottle::~IpfsSubframeNavigationThrottle() {} | ||
|
|
||
| // content::NavigationThrottle implementation: | ||
| content::NavigationThrottle::ThrottleCheckResult | ||
| IpfsSubframeNavigationThrottle::WillFailRequest() { | ||
| // Ignores subframe ipfs:// navigation. It is ok to commit toplevel | ||
| // navigation. | ||
| if (!navigation_handle()->IsInMainFrame() && | ||
| (navigation_handle()->GetURL().SchemeIs(ipfs::kIPFSScheme) || | ||
| navigation_handle()->GetURL().SchemeIs(ipfs::kIPNSScheme))) { | ||
| return {content::NavigationThrottle::CANCEL_AND_IGNORE, | ||
| navigation_handle()->GetNetErrorCode()}; | ||
| } | ||
| return content::NavigationThrottle::PROCEED; | ||
| } | ||
|
|
||
| const char* IpfsSubframeNavigationThrottle::GetNameForLogging() { | ||
| return "IpfsSubframeNavigationThrottle"; | ||
| } | ||
|
|
||
| } // namespace ipfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* Copyright (c) 2022 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_BROWSER_IPFS_IPFS_SUBFRAME_NAVIGATION_THROTTLE_H_ | ||
| #define BRAVE_BROWSER_IPFS_IPFS_SUBFRAME_NAVIGATION_THROTTLE_H_ | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "content/public/browser/navigation_handle.h" | ||
| #include "content/public/browser/navigation_throttle.h" | ||
|
|
||
| namespace ipfs { | ||
|
|
||
| // Prevents commiting of subframe IPFS navigations. | ||
| // IPFS urls must be changed to proper gateway urls. | ||
| // See ipfs_redirect_network_delegate_helper.h for example. | ||
| class IpfsSubframeNavigationThrottle : public content::NavigationThrottle { | ||
| public: | ||
| static std::unique_ptr<IpfsSubframeNavigationThrottle> CreateThrottleFor( | ||
| content::NavigationHandle* navigation_handle); | ||
|
|
||
| explicit IpfsSubframeNavigationThrottle( | ||
| content::NavigationHandle* navigation_handle); | ||
| ~IpfsSubframeNavigationThrottle() override; | ||
|
|
||
| IpfsSubframeNavigationThrottle(const IpfsSubframeNavigationThrottle&) = | ||
| delete; | ||
| IpfsSubframeNavigationThrottle& operator=( | ||
| const IpfsSubframeNavigationThrottle&) = delete; | ||
|
|
||
| // content::NavigationThrottle implementation: | ||
| // This is called before navigation commits with error. | ||
| // Here we can cancel subframe navigation for ipfs:// urls. | ||
| content::NavigationThrottle::ThrottleCheckResult WillFailRequest() override; | ||
| const char* GetNameForLogging() override; | ||
| }; | ||
|
|
||
| } // namespace ipfs | ||
|
|
||
| #endif // BRAVE_BROWSER_IPFS_IPFS_SUBFRAME_NAVIGATION_THROTTLE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters