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.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_navigation_throttle.h"
|
2018-09-15 15:42:43 +00:00
|
|
|
|
|
|
|
#include "content/public/browser/navigation_handle.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_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
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronNavigationThrottle::ElectronNavigationThrottle(
|
2018-09-15 15:42:43 +00:00
|
|
|
content::NavigationHandle* navigation_handle)
|
|
|
|
: content::NavigationThrottle(navigation_handle) {}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronNavigationThrottle::~ElectronNavigationThrottle() = default;
|
2018-09-15 15:42:43 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
const char* ElectronNavigationThrottle::GetNameForLogging() {
|
|
|
|
return "ElectronNavigationThrottle";
|
2018-09-15 15:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
content::NavigationThrottle::ThrottleCheckResult
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronNavigationThrottle::WillRedirectRequest() {
|
2018-09-15 15:42:43 +00:00
|
|
|
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
|