mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-01 08:34:11 +02:00
Redo external link handling using ILifeSpanHandler instead of hacky JS code
This commit is contained in:
parent
2e13d08018
commit
3a7a0f63de
@ -44,7 +44,8 @@ public FormBrowser(PluginManager pluginManager){
|
|||||||
|
|
||||||
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){
|
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){
|
||||||
MenuHandler = new ContextMenuBrowser(this),
|
MenuHandler = new ContextMenuBrowser(this),
|
||||||
DialogHandler = new DialogHandlerBrowser(this)
|
DialogHandler = new DialogHandlerBrowser(this),
|
||||||
|
LifeSpanHandler = new LifeSpanHandler()
|
||||||
};
|
};
|
||||||
|
|
||||||
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||||
|
@ -70,7 +70,11 @@ public FormNotification(Form owner, TweetDeckBridge bridge, PluginManager plugin
|
|||||||
notificationJS = ScriptLoader.LoadResource(NotificationScriptFile);
|
notificationJS = ScriptLoader.LoadResource(NotificationScriptFile);
|
||||||
pluginJS = ScriptLoader.LoadResource(PluginManager.PluginNotificationScriptFile);
|
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.FrameLoadEnd += Browser_FrameLoadEnd;
|
||||||
browser.RegisterJsObject("$TD",bridge);
|
browser.RegisterJsObject("$TD",bridge);
|
||||||
|
|
||||||
|
30
Core/Handling/LifeSpanHandler.cs
Normal file
30
Core/Handling/LifeSpanHandler.cs
Normal file
@ -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){}
|
||||||
|
}
|
||||||
|
}
|
@ -161,51 +161,6 @@
|
|||||||
return true;
|
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.
|
// Block: Expand shortened links on hover or display tooltip.
|
||||||
//
|
//
|
||||||
|
@ -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.
|
// Block: Allow bypassing of t.co in context menus.
|
||||||
//
|
//
|
||||||
|
@ -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">
|
<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.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')" />
|
<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>
|
||||||
<Compile Include="Core\Handling\ContextMenuNotification.cs" />
|
<Compile Include="Core\Handling\ContextMenuNotification.cs" />
|
||||||
<Compile Include="Core\Handling\DialogHandlerBrowser.cs" />
|
<Compile Include="Core\Handling\DialogHandlerBrowser.cs" />
|
||||||
|
<Compile Include="Core\Handling\LifeSpanHandler.cs" />
|
||||||
<Compile Include="Core\Handling\TweetNotification.cs" />
|
<Compile Include="Core\Handling\TweetNotification.cs" />
|
||||||
<Compile Include="Core\Controls\RichTextLabel.cs">
|
<Compile Include="Core\Controls\RichTextLabel.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
|
Loading…
Reference in New Issue
Block a user