mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
refactor: wire will-navigate up to a navigation throttle instead of OpenURL (#25108)
* 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 * chore: old code be old
This commit is contained in:
@@ -743,12 +743,6 @@ content::WebContents* WebContents::OpenURLFromTab(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Give user a chance to cancel navigation.
|
||||
if (Emit("will-navigate", params.url))
|
||||
return nullptr;
|
||||
|
||||
// Don't load the URL if the web contents was marked as destroyed from a
|
||||
// will-navigate event listener
|
||||
if (IsDestroyed())
|
||||
return nullptr;
|
||||
|
||||
|
||||
@@ -19,6 +19,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 = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
auto api_contents = electron::api::WebContents::From(isolate, contents);
|
||||
if (api_contents.IsEmpty()) {
|
||||
// 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();
|
||||
|
||||
@@ -14,6 +14,8 @@ class ElectronNavigationThrottle : public content::NavigationThrottle {
|
||||
explicit ElectronNavigationThrottle(content::NavigationHandle* handle);
|
||||
~ElectronNavigationThrottle() override;
|
||||
|
||||
ElectronNavigationThrottle::ThrottleCheckResult WillStartRequest() override;
|
||||
|
||||
ElectronNavigationThrottle::ThrottleCheckResult WillRedirectRequest()
|
||||
override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user