Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement will-redirect using NavigationThrottle instead of…
… PostTask This avoids a potential race condition and immediately cancels the navigation
- Loading branch information
1 parent
fba5fd3
commit aba6d24
Showing
7 changed files
with
84 additions
and
12 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,36 @@ | ||
// 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/net/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() {} | ||
|
||
content::NavigationThrottle::ThrottleCheckResult | ||
AtomNavigationThrottle::WillRedirectRequest() { | ||
auto* handle = navigation_handle(); | ||
auto* contents = handle->GetWebContents(); | ||
if (!contents) | ||
return PROCEED; | ||
|
||
auto api_contents = | ||
atom::api::WebContents::CreateFrom(v8::Isolate::GetCurrent(), contents); | ||
if (api_contents.IsEmpty()) | ||
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,29 @@ | ||
// 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_NET_ATOM_NAVIGATION_THROTTLE_H_ | ||
#define ATOM_BROWSER_NET_ATOM_NAVIGATION_THROTTLE_H_ | ||
|
||
#include "content/public/browser/navigation_throttle.h" | ||
|
||
class URLPattern; | ||
|
||
namespace atom { | ||
|
||
class AtomNavigationThrottle : public content::NavigationThrottle { | ||
public: | ||
AtomNavigationThrottle(content::NavigationHandle* handle); | ||
~AtomNavigationThrottle() override; | ||
|
||
AtomNavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; | ||
|
||
const char* GetNameForLogging() { return "AtomNavigationThrottle"; } | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(AtomNavigationThrottle); | ||
}; | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_BROWSER_NET_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