diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 00a18362..03dfa1f6 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -44,7 +44,8 @@ public FormBrowser(PluginManager pluginManager){ browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){ MenuHandler = new ContextMenuBrowser(this), - DialogHandler = new DialogHandlerBrowser(this) + DialogHandler = new DialogHandlerBrowser(this), + LifeSpanHandler = new LifeSpanHandler() }; browser.LoadingStateChanged += Browser_LoadingStateChanged; diff --git a/Core/FormNotification.cs b/Core/FormNotification.cs index f9e8a74c..d81bb0cc 100644 --- a/Core/FormNotification.cs +++ b/Core/FormNotification.cs @@ -70,7 +70,11 @@ public FormNotification(Form owner, TweetDeckBridge bridge, PluginManager plugin notificationJS = ScriptLoader.LoadResource(NotificationScriptFile); pluginJS = ScriptLoader.LoadResource(PluginManager.PluginNotificationScriptFile); - browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new ContextMenuNotification(this,autoHide) }; + browser = new ChromiumWebBrowser("about:blank"){ + MenuHandler = new ContextMenuNotification(this,autoHide), + LifeSpanHandler = new LifeSpanHandler() + }; + browser.FrameLoadEnd += Browser_FrameLoadEnd; browser.RegisterJsObject("$TD",bridge); diff --git a/Core/Handling/LifeSpanHandler.cs b/Core/Handling/LifeSpanHandler.cs new file mode 100644 index 00000000..f7e90d82 --- /dev/null +++ b/Core/Handling/LifeSpanHandler.cs @@ -0,0 +1,30 @@ +using CefSharp; +using TweetDck.Core.Utils; + +namespace TweetDck.Core.Handling{ + class LifeSpanHandler : ILifeSpanHandler{ + public 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; + + switch(targetDisposition){ + case WindowOpenDisposition.NewBackgroundTab: + case WindowOpenDisposition.NewForegroundTab: + case WindowOpenDisposition.NewPopup: + case WindowOpenDisposition.NewWindow: + BrowserUtils.OpenExternalBrowser(targetUrl); + return true; + + default: + return false; + } + } + + public void OnAfterCreated(IWebBrowser browserControl, IBrowser browser){} + + public bool DoClose(IWebBrowser browserControl, IBrowser browser){ + return false; + } + + public void OnBeforeClose(IWebBrowser browserControl, IBrowser browser){} + } +} diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js index 6e4ae3c5..29737aea 100644 --- a/Resources/Scripts/code.js +++ b/Resources/Scripts/code.js @@ -161,51 +161,6 @@ return true; }; - // - // Block: Hook into links to bypass default open function. - // - (function(){ - var urlWait = false; - - var onUrlOpened = function(){ - urlWait = true; - setTimeout(function(){ urlWait = false; },0); - }; - - $(document.body).delegate("a[target='_blank']","click",function(e){ - if (urlWait)return; - - var me = $(this); - var rel = me.attr("rel"); - - if (!me.is(".link-complex") && !(rel === "mediaPreview" && me.closest("#open-modal").length === 0) && rel !== "list" && rel !== "user" && rel !== "tweet"){ - $TD.openBrowser(me.attr("href")); - onUrlOpened(); - } - - e.preventDefault(); - }); - - window.open = function(url){ - if (urlWait)return; - - $TD.openBrowser(url); - onUrlOpened(); - }; - - TD.util.maybeOpenClickExternally = prependToFunction(TD.util.maybeOpenClickExternally,function(e){ - if (e.ctrlKey){ - if (urlWait)return; - - $TD.openBrowser(e.currentTarget.getAttribute("href")); - e.preventDefault(); - e.stopPropagation(); - e.stopImmediatePropagation(); - return true; - } - }); - })(); - // // Block: Expand shortened links on hover or display tooltip. // diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js index 9f8915d8..9278a139 100644 --- a/Resources/Scripts/notification.js +++ b/Resources/Scripts/notification.js @@ -13,14 +13,6 @@ } }; - // - // Block: Hook into links to bypass default open function. - // - addEventListener(links,"click",function(e){ - $TD.openBrowser(e.currentTarget.getAttribute("href")); - e.preventDefault(); - }); - // // Block: Allow bypassing of t.co in context menus. // diff --git a/TweetDck.csproj b/TweetDck.csproj index dbdc8c2e..1a6c73c2 100644 --- a/TweetDck.csproj +++ b/TweetDck.csproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="packages\CefSharp.WinForms.49.0.0-pre02\build\CefSharp.WinForms.props" Condition="Exists('packages\CefSharp.WinForms.49.0.0-pre02\build\CefSharp.WinForms.props')" /> <Import Project="packages\CefSharp.Common.49.0.0-pre02\build\CefSharp.Common.props" Condition="Exists('packages\CefSharp.Common.49.0.0-pre02\build\CefSharp.Common.props')" /> @@ -100,6 +100,7 @@ </Compile> <Compile Include="Core\Handling\ContextMenuNotification.cs" /> <Compile Include="Core\Handling\DialogHandlerBrowser.cs" /> + <Compile Include="Core\Handling\LifeSpanHandler.cs" /> <Compile Include="Core\Handling\TweetNotification.cs" /> <Compile Include="Core\Controls\RichTextLabel.cs"> <SubType>Component</SubType>