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"
|
2020-06-22 16:35:24 +00:00
|
|
|
#include "shell/browser/javascript_environment.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;
|
|
|
|
}
|
|
|
|
|
2020-06-22 16:35:24 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2020-03-11 01:16:58 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2020-07-16 23:16:05 +00:00
|
|
|
api::WebContents* api_contents = api::WebContents::From(contents);
|
|
|
|
if (!api_contents) {
|
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
|