Skip to content

Commit

Permalink
Display .url files as webpage (QL-Win#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jethro-Alter authored and xupefei committed Sep 23, 2019
1 parent c5000d9 commit da02d6d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
22 changes: 21 additions & 1 deletion QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Paddy Xu
// Copyright © 2017 Paddy Xu
//
// This file is part of QuickLook program.
//
Expand Down Expand Up @@ -63,5 +63,25 @@ private static void SetBrowserFeatureControlKey(string feature, string appName,
key?.SetValue(appName, value, RegistryValueKind.DWord);
}
}

internal static string GetUrlPath(string url)
{
int index = -1;
string[] lines = File.ReadAllLines(url);
foreach (string line in lines)
{
if (line.ToLower().Contains("url="))
{
index = System.Array.IndexOf(lines, line);
break;
}
}
if (index != -1)
{
var fullLine = lines.GetValue(index);
return fullLine.ToString().Substring(fullLine.ToString().LastIndexOf('=') + 1);
}
return url;
}
}
}
8 changes: 6 additions & 2 deletions QuickLook.Plugin/QuickLook.Plugin.HtmlViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace QuickLook.Plugin.HtmlViewer
{
public class Plugin : IViewer
{
private static readonly string[] Extensions = { ".mht", ".mhtml", ".htm", ".html", ".svg" };
private static readonly string[] Extensions = { ".mht", ".mhtml", ".htm", ".html", ".svg", ".url" };

private WebpagePanel _panel;

Expand All @@ -44,7 +44,7 @@ public bool CanHandle(string path)

public void Prepare(string path, ContextObject context)
{
context.PreferredSize = new Size(1000, 600);
context.PreferredSize = new Size(1280, 720);
}

public void View(string path, ContextObject context)
Expand All @@ -53,6 +53,10 @@ public void View(string path, ContextObject context)
context.ViewerContent = _panel;
context.Title = Path.IsPathRooted(path) ? Path.GetFileName(path) : path;

if (path.ToLower().EndsWith(".url"))
{
path = Helper.GetUrlPath(path);
}
_panel.LoadFile(path);
_panel.Dispatcher.Invoke(() => { context.IsBusy = false; }, DispatcherPriority.Loaded);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ private void InnerBrowserLoadCompleted(object sender, NavigationEventArgs e)
private void InnerBrowserNavigating(object sender, NavigatingCancelEventArgs e)
{
if (_loaded)
if (_innerBrowser.Source.Scheme != e.Uri.Scheme ||
_innerBrowser.Source.AbsolutePath != e.Uri.AbsolutePath) // allow in-page navigation
e.Cancel = true;
if (_innerBrowser.Source != null)
if (_innerBrowser.Source.Scheme != e.Uri.Scheme ||
_innerBrowser.Source.AbsolutePath != e.Uri.AbsolutePath) // allow in-page navigation
e.Cancel = true;
_loaded = true;
}

Expand Down Expand Up @@ -169,7 +170,7 @@ public void Navigate(Stream stream)
// register script errors handler on DOM - document.window
private void RegisterWindowErrorHanlder_()
{
object parwin = ((dynamic) _innerBrowser.Document).parentWindow;
object parwin = ((dynamic)_innerBrowser.Document).parentWindow;
var cookie = new AxHost.ConnectionPointCookie(parwin, new HtmlWindowEvents2Impl(this),
typeof(IIntHTMLWindowEvents2));
// MemoryLEAK? No: cookie has a Finalize() to Disconnect istelf. We'll rely on that. If disconnected too early,
Expand All @@ -185,14 +186,14 @@ private void ApplyZoom()
// grab a handle to the underlying ActiveX object
IServiceProvider serviceProvider = null;
if (_innerBrowser.Document != null)
serviceProvider = (IServiceProvider) _innerBrowser.Document;
serviceProvider = (IServiceProvider)_innerBrowser.Document;
if (serviceProvider == null)
return;

var serviceGuid = SidSWebBrowserApp;
var iid = typeof(IWebBrowser2).GUID;
var browserInst =
(IWebBrowser2) serviceProvider.QueryService(ref serviceGuid, ref iid);
(IWebBrowser2)serviceProvider.QueryService(ref serviceGuid, ref iid);

try
{
Expand Down

0 comments on commit da02d6d

Please sign in to comment.