refactor: wire will-navigate up to a navigation throttle instead of OpenURL (#25065)
* refactor: wire will-navigate up to a navigation throttle instead of OpenURL * spec: add test for x-site _top navigation
This commit is contained in:
parent
a17e97c3b2
commit
b1e2185c5e
4 changed files with 65 additions and 6 deletions
|
@ -20,6 +20,30 @@ const char* ElectronNavigationThrottle::GetNameForLogging() {
|
|||
return "ElectronNavigationThrottle";
|
||||
}
|
||||
|
||||
content::NavigationThrottle::ThrottleCheckResult
|
||||
ElectronNavigationThrottle::WillStartRequest() {
|
||||
auto* handle = navigation_handle();
|
||||
auto* contents = handle->GetWebContents();
|
||||
if (!contents) {
|
||||
NOTREACHED();
|
||||
return PROCEED;
|
||||
}
|
||||
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
api::WebContents* api_contents = api::WebContents::From(contents);
|
||||
if (!api_contents) {
|
||||
// No need to emit any event if the WebContents is not available in JS.
|
||||
return PROCEED;
|
||||
}
|
||||
|
||||
if (handle->IsRendererInitiated() && handle->IsInMainFrame() &&
|
||||
api_contents->EmitNavigationEvent("will-navigate", handle)) {
|
||||
return CANCEL;
|
||||
}
|
||||
return PROCEED;
|
||||
}
|
||||
|
||||
content::NavigationThrottle::ThrottleCheckResult
|
||||
ElectronNavigationThrottle::WillRedirectRequest() {
|
||||
auto* handle = navigation_handle();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue