2018-09-15 15:42:43 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/atom_navigation_throttle.h"
|
2018-09-15 15:42:43 +00:00
|
|
|
|
|
|
|
#include "content/public/browser/navigation_handle.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/atom_api_web_contents.h"
|
2018-09-15 15:42:43 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-09-15 15:42:43 +00:00
|
|
|
|
|
|
|
AtomNavigationThrottle::AtomNavigationThrottle(
|
|
|
|
content::NavigationHandle* navigation_handle)
|
|
|
|
: content::NavigationThrottle(navigation_handle) {}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
AtomNavigationThrottle::~AtomNavigationThrottle() = default;
|
2018-09-15 15:42:43 +00:00
|
|
|
|
|
|
|
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 =
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::api::WebContents::From(v8::Isolate::GetCurrent(), contents);
|
2018-09-15 15:42:43 +00:00
|
|
|
if (api_contents.IsEmpty()) {
|
2018-10-19 08:52:07 +00:00
|
|
|
// No need to emit any event if the WebContents is not available in JS.
|
2018-09-15 15:42:43 +00:00
|
|
|
return PROCEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api_contents->EmitNavigationEvent("will-redirect", handle)) {
|
|
|
|
return CANCEL;
|
|
|
|
}
|
|
|
|
return PROCEED;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|