mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-11 03:15:44 +02:00
36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using CefSharp;
|
|
using CefSharp.Handler;
|
|
using TweetDuck.Controls;
|
|
using TweetDuck.Utils;
|
|
|
|
namespace TweetDuck.Browser.Handling.General {
|
|
sealed class CustomLifeSpanHandler : LifeSpanHandler {
|
|
private static bool IsPopupAllowed(string url) {
|
|
return url.StartsWith("https://twitter.com/teams/authorize?");
|
|
}
|
|
|
|
public static bool HandleLinkClick(IWebBrowser browserControl, WindowOpenDisposition targetDisposition, string targetUrl) {
|
|
switch (targetDisposition) {
|
|
case WindowOpenDisposition.NewBackgroundTab:
|
|
case WindowOpenDisposition.NewForegroundTab:
|
|
case WindowOpenDisposition.NewPopup when !IsPopupAllowed(targetUrl):
|
|
case WindowOpenDisposition.NewWindow:
|
|
browserControl.AsControl().InvokeAsyncSafe(() => BrowserUtils.OpenExternalBrowser(targetUrl));
|
|
return true;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected override bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) {
|
|
newBrowser = null;
|
|
return HandleLinkClick(browserControl, targetDisposition, targetUrl);
|
|
}
|
|
|
|
protected override bool DoClose(IWebBrowser browserControl, IBrowser browser) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|