-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom context menu items Added full support for downloads Added browser settings to saved user preferences Fixed initalization and deinitalization of CefSharp (no more lingering processes) Updated Readme to reflect changes
- Loading branch information
1 parent
f95512a
commit ce3b95b
Showing
19 changed files
with
1,843 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Opeity_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using CefSharp; | ||
|
||
namespace Opeity.Handlers | ||
{ | ||
public class RequestContextHandler : IRequestContextHandler | ||
{ | ||
private ICookieManager customCookieManager; | ||
|
||
public ICookieManager GetCookieManager() | ||
{ | ||
if (customCookieManager == null) | ||
customCookieManager = new CookieManager(null, persistSessionCookies: false, callback: null); | ||
|
||
return customCookieManager; | ||
} | ||
|
||
public bool OnBeforePluginLoad(string mimeType, string url, bool isMainFrame, string topOriginUrl, WebPluginInfo pluginInfo, ref PluginPolicy pluginPolicy) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using CefSharp; | ||
using CefSharp.Wpf; | ||
using System.Diagnostics; | ||
using System.Windows; | ||
|
||
namespace Opeity.Handlers | ||
{ | ||
public class ContextMenuHandler : IContextMenuHandler | ||
{ | ||
public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) | ||
{ | ||
if (model.Count > 0) | ||
{ | ||
model.AddSeparator(); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(parameters.UnfilteredLinkUrl)) | ||
model.AddItem((CefMenuCommand)26501, "Copy Link Address"); | ||
|
||
if (!string.IsNullOrEmpty(parameters.LinkUrl)) | ||
model.AddItem((CefMenuCommand)26502, "Open Link in New Window"); | ||
|
||
if (!string.IsNullOrEmpty(parameters.UnfilteredLinkUrl) || !string.IsNullOrEmpty(parameters.LinkUrl)) | ||
model.AddSeparator(); | ||
|
||
var dev = model.AddSubMenu((CefMenuCommand)26503, "Developer Tools"); | ||
dev.AddItem((CefMenuCommand)26504, "Inspector"); | ||
} | ||
|
||
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) | ||
{ | ||
switch (commandId) | ||
{ | ||
case (CefMenuCommand)26501: | ||
Clipboard.SetText(parameters.UnfilteredLinkUrl); | ||
return true; | ||
|
||
case (CefMenuCommand)26502: | ||
Process.Start(new ProcessStartInfo() | ||
{ | ||
FileName = System.Reflection.Assembly.GetExecutingAssembly().Location, | ||
Arguments = $"-o \"{parameters.LinkUrl}\"" | ||
}); | ||
|
||
return true; | ||
|
||
case (CefMenuCommand)26504: | ||
if (browser.GetHost().HasDevTools) | ||
browser.GetHost().CloseDevTools(); | ||
|
||
if (!browser.GetHost().HasDevTools) | ||
browser.GetHost().ShowDevTools(); | ||
|
||
return true; | ||
|
||
default: return false; | ||
} | ||
} | ||
|
||
public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame) | ||
{ | ||
var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; | ||
|
||
chromiumWebBrowser.Dispatcher.Invoke(() => | ||
{ | ||
chromiumWebBrowser.ContextMenu = null; | ||
}); | ||
} | ||
|
||
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Opeity.Helpers | ||
{ | ||
public class FileSizeHelper | ||
{ | ||
// | ||
// Source: https://stackoverflow.com/a/11124118 | ||
// | ||
// Returns the human-readable file size for an arbitrary, 64-bit file size | ||
// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB" | ||
public static string GetBytesReadable(long i) | ||
{ | ||
var absoluteI = (i < 0 ? -i : i); | ||
|
||
string suffix; | ||
double readable; | ||
|
||
if (absoluteI >= 0x1000000000000000) | ||
{ | ||
suffix = "EBps"; | ||
readable = (i >> 50); | ||
} | ||
else if (absoluteI >= 0x4000000000000) | ||
{ | ||
suffix = "PBps"; | ||
readable = (i >> 40); | ||
} | ||
else if (absoluteI >= 0x10000000000) | ||
{ | ||
suffix = "TBps"; | ||
readable = (i >> 30); | ||
} | ||
else if (absoluteI >= 0x40000000) | ||
{ | ||
suffix = "GBps"; | ||
readable = (i >> 20); | ||
} | ||
else if (absoluteI >= 0x100000) | ||
{ | ||
suffix = "MBps"; | ||
readable = (i >> 10); | ||
} | ||
else if (absoluteI >= 0x400) | ||
{ | ||
suffix = "KBps"; | ||
readable = i; | ||
} | ||
else | ||
{ | ||
return i.ToString("0 Bps"); | ||
} | ||
|
||
readable = readable / 1024; | ||
return readable.ToString("0.# ") + suffix; | ||
} | ||
} | ||
} |
Oops, something went wrong.