Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,44 @@ SharpBrowser is the fastest open source C# web browser there is! Slightly faster
## Features

- HTML5, CSS3, JS, HTML5 Video, WebGL 3D, etc
- Tabbed browsing (open in new tab, etc)
- Address bar (also opens Google Search)
- Tabbed browsing
- Address bar (also opens Google)
- Back, Forward, Stop, Refresh
- Developer tools
- Downloads window (download progress, cancellation, etc)
- Search bar (also highlights all instances)
- Download manager
- Custom error pages
- Custom context menu
- Easy to add any vendor-specific buttons or commands
- Easily add vendor-specific branding, buttons or hotkeys
- View online & offline webpages

## Hotkeys

Hotkeys | Function
------------ | -------------
Ctrl+T | Add a new tab
Ctrl+N | Add a new window
Ctrl+W | Close active tab
F5 | Refresh active tab
F12 | Open developer tools
Ctrl+Tab | Switch to the next tab
Ctrl+Shift+Tab | Switch to the previous tab
Ctrl+F | Open search bar (Enter to find next, Esc to close)

## Code

- SharpBrowser uses CefSharp 51, NET Framework 4.5.2
- `MainForm.cs` - main web browser UI and related functionality
- `Handlers` - various handlers that we have registered with CefSharp that enable deeper integration between us and CefSharp
- `Data/JSON.cs` - fast JSON serializer/deserializer
- `bin` - Binaries are included in the `bin` folder due to the complex CefSharp setup required. Don't empty this folder.
- `bin/storage` - JS code and associated assets required for "downloads" page
- `bin/storage` - HTML and JS required for downloads manager and custom error pages

## Credits

- [Robin Rodricks](https://github.com/robinrodricks) - SharpBrowser project.
- [Alex Maitland](https://github.com/amaitland) - CefSharp project, wrapper for CEF embeddable browser.
- [Ahmet Uzun](https://github.com/postacik) - Original browser project.

## Screenshots

Expand All @@ -31,10 +54,21 @@ SharpBrowser is the fastest open source C# web browser there is! Slightly faster

![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/2.png)

### Search Bar

![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/search.png)

### Downloads Tab

![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/3.png)

### Developer Tools

![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/4.png)
![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/4.png)

### Custom Error Pages

![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/error1.png)

![](https://github.com/sharpbrowser/SharpBrowser/raw/master/images/error2.png)

Binary file added images/error1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/error2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<add key="torDefaultConfigurationFile" value=""/>
<add key="torPath" value="Tor\Tor\tor.exe"/>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>
121 changes: 121 additions & 0 deletions src/Handlers/ContextMenuHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CefSharp;
using System.Windows.Forms;
using CefSharp.WinForms;

namespace SharpBrowser {
internal class ContextMenuHandler : IContextMenuHandler {

private const int ShowDevTools = 26501;
private const int CloseDevTools = 26502;
private const int SaveImageAs = 26503;
private const int SaveAsPdf = 26504;
private const int SaveLinkAs = 26505;
private const int CopyLinkAddress = 26506;
private const int OpenLinkInNewTab = 26507;
private const int CloseTab = 40007;
private const int RefreshTab = 40008;
MainForm myForm;

private string lastSelText = "";

public ContextMenuHandler(MainForm form) {
myForm = form;
}

public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) {

// clear the menu
model.Clear();

// save text
lastSelText = parameters.SelectionText;

// to copy text
if (parameters.SelectionText.CheckIfValid()) {
model.AddItem(CefMenuCommand.Copy, "Copy");
model.AddSeparator();
}

//Removing existing menu item
//bool removed = model.Remove(CefMenuCommand.ViewSource); // Remove "View Source" option
if (parameters.LinkUrl != "") {
model.AddItem((CefMenuCommand)OpenLinkInNewTab, "Open link in new tab");
model.AddItem((CefMenuCommand)CopyLinkAddress, "Copy link");
model.AddSeparator();
}

if (parameters.HasImageContents && parameters.SourceUrl.CheckIfValid()) {

// RIGHT CLICKED ON IMAGE

}

if (parameters.SelectionText != null) {

// TEXT IS SELECTED

}

//Add new custom menu items
//#if DEBUG
model.AddItem((CefMenuCommand)ShowDevTools, "Developer tools");
model.AddItem(CefMenuCommand.ViewSource, "View source");
model.AddSeparator();
//#endif

model.AddItem((CefMenuCommand)RefreshTab, "Refresh tab");
model.AddItem((CefMenuCommand)CloseTab, "Close tab");

}

public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) {

int id = (int)commandId;

if (id == ShowDevTools) {
browser.ShowDevTools();
}
if (id == CloseDevTools) {
browser.CloseDevTools();
}
if (id == SaveImageAs) {
browser.GetHost().StartDownload(parameters.SourceUrl);
}
if (id == SaveLinkAs) {
browser.GetHost().StartDownload(parameters.LinkUrl);
}
if (id == OpenLinkInNewTab) {
ChromiumWebBrowser newBrowser = myForm.AddNewBrowserTab(parameters.LinkUrl, false, browser.MainFrame.Url);
}
if (id == CopyLinkAddress) {
Clipboard.SetText(parameters.LinkUrl);
}
if (id == CloseTab) {
myForm.InvokeOnParent(delegate() {
myForm.CloseActiveTab();
});
}
if (id == RefreshTab) {
myForm.InvokeOnParent(delegate() {
myForm.RefreshActiveTab();
});
}

return false;
}

public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame) {

}

public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) {

// show default menu
return false;
}
}
}
35 changes: 28 additions & 7 deletions src/Handlers/DownloadHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using CefSharp;

namespace SharpBrowser
{
public class DownloadHandler : IDownloadHandler
namespace SharpBrowser {
internal class DownloadHandler : IDownloadHandler
{
MainForm myForm;

Expand All @@ -11,22 +10,44 @@ public DownloadHandler(MainForm form)
myForm = form;
}

public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
public void OnBeforeDownload(IBrowser browser, DownloadItem item, IBeforeDownloadCallback callback)
{
if (!callback.IsDisposed)
{
using (callback)
{
myForm.UpdateDownloadItem(downloadItem);
callback.Continue(downloadItem.SuggestedFileName, showDialog: true);

myForm.UpdateDownloadItem(item);

// ask browser what path it wants to save the file into
string path = myForm.CalcDownloadPath(item);

// if file should not be saved, path will be null, so skip file
if (path != null) {

// skip file
callback.Continue(path, false);

} else {

// download file
callback.Dispose();

// open the downloads tab
myForm.OpenDownloadsTab();

}

}
}
}

public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
myForm.UpdateDownloadItem(downloadItem);
if (downloadItem.IsInProgress && myForm.CancelRequests.Contains(downloadItem.Id)) callback.Cancel();
if (downloadItem.IsInProgress && myForm.CancelRequests.Contains(downloadItem.Id)) {
callback.Cancel();
}
//Console.WriteLine(downloadItem.Url + " %" + downloadItem.PercentComplete + " complete");
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Handlers/HostHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SharpBrowser {
/// <summary>
/// functions in this class are accessible by JS using the code `host.X()`
/// </summary>
public class HostHandler {
internal class HostHandler {
MainForm myForm;

public HostHandler(MainForm form) {
Expand All @@ -34,6 +34,9 @@ public bool cancelDownload(int downloadId) {
}
return true;
}
public void refreshActiveTab() {
myForm.RefreshActiveTab();
}
}

}
Loading