Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add will-redirect to allow people to prevent 30X redirects * spec: add tests for the will-redirect event * refactor: implement will-redirect using NavigationThrottle instead of PostTask This avoids a potential race condition and immediately cancels the navigation * docs: add docs for did-redirect-navigation * refactor: move AtomNavigationThrottle out of net folder * refactor: update header guard for atom_navigation_throttle.h * refactor: fix chromium style errors in the GN build * refactor: update throttle impl to NOTREACHED and std::make_unqique
- Loading branch information
1 parent
6ad8583
commit 7065093
Showing
10 changed files
with
222 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2015 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/browser/atom_navigation_throttle.h" | ||
|
||
#include "atom/browser/api/atom_api_web_contents.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
|
||
namespace atom { | ||
|
||
AtomNavigationThrottle::AtomNavigationThrottle( | ||
content::NavigationHandle* navigation_handle) | ||
: content::NavigationThrottle(navigation_handle) {} | ||
|
||
AtomNavigationThrottle::~AtomNavigationThrottle() {} | ||
|
||
const char* AtomNavigationThrottle::GetNameForLogging() { | ||
return "AtomNavigationThrottle"; | ||
} | ||
|
||
content::NavigationThrottle::ThrottleCheckResult | ||
AtomNavigationThrottle::WillRedirectRequest() { | ||
auto* handle = navigation_handle(); | ||
auto* contents = handle->GetWebContents(); | ||
if (!contents) { | ||
NOTREACHED(); | ||
return PROCEED; | ||
} | ||
|
||
auto api_contents = | ||
atom::api::WebContents::CreateFrom(v8::Isolate::GetCurrent(), contents); | ||
if (api_contents.IsEmpty()) { | ||
NOTREACHED(); | ||
return PROCEED; | ||
} | ||
|
||
if (api_contents->EmitNavigationEvent("will-redirect", handle)) { | ||
return CANCEL; | ||
} | ||
return PROCEED; | ||
} | ||
|
||
} // namespace atom |
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,27 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_BROWSER_ATOM_NAVIGATION_THROTTLE_H_ | ||
#define ATOM_BROWSER_ATOM_NAVIGATION_THROTTLE_H_ | ||
|
||
#include "content/public/browser/navigation_throttle.h" | ||
|
||
namespace atom { | ||
|
||
class AtomNavigationThrottle : public content::NavigationThrottle { | ||
public: | ||
explicit AtomNavigationThrottle(content::NavigationHandle* handle); | ||
~AtomNavigationThrottle() override; | ||
|
||
AtomNavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | ||
|
||
const char* GetNameForLogging() override; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(AtomNavigationThrottle); | ||
}; | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_BROWSER_ATOM_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