7065093869
* 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
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
// 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
|