mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Merge pull request #3832 from sylveon/master
Add support for Edge webview in website capture
This commit is contained in:
commit
28dbc0274c
9 changed files with 224 additions and 38 deletions
|
@ -100,7 +100,7 @@ private void InitializeComponent()
|
|||
//
|
||||
resources.ApplyResources(this.nudWebpageWidth, "nudWebpageWidth");
|
||||
this.nudWebpageWidth.Maximum = new decimal(new int[] {
|
||||
10000,
|
||||
15000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
|
@ -121,7 +121,7 @@ private void InitializeComponent()
|
|||
//
|
||||
resources.ApplyResources(this.nudWebpageHeight, "nudWebpageHeight");
|
||||
this.nudWebpageHeight.Maximum = new decimal(new int[] {
|
||||
10000,
|
||||
15000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
|
|
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.ScreenCaptureLib.Properties;
|
||||
using ShareX.ScreenCaptureLib.WebpageCapture;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
@ -39,7 +40,7 @@ public partial class WebpageCaptureForm : Form
|
|||
public WebpageCaptureOptions Options { get; set; }
|
||||
public bool IsBusy { get; private set; }
|
||||
|
||||
private WebpageCapture webpageCapture;
|
||||
private WebpageCaptureBase webpageCapture;
|
||||
private bool stopRequested;
|
||||
|
||||
public WebpageCaptureForm(WebpageCaptureOptions options)
|
||||
|
@ -48,7 +49,7 @@ public WebpageCaptureForm(WebpageCaptureOptions options)
|
|||
Icon = ShareXResources.Icon;
|
||||
Options = options;
|
||||
LoadSettings();
|
||||
webpageCapture = new WebpageCapture();
|
||||
webpageCapture = WebpageCaptureBase.Create();
|
||||
webpageCapture.CaptureCompleted += webpageCapture_CaptureCompleted;
|
||||
}
|
||||
|
||||
|
@ -133,7 +134,7 @@ private void StartCapture()
|
|||
}
|
||||
|
||||
webpageCapture.CaptureDelay = (int)nudCaptureDelay.Value * 1000;
|
||||
webpageCapture.CapturePage(txtURL.Text, new Size((int)nudWebpageWidth.Value, (int)nudWebpageWidth.Value));
|
||||
webpageCapture.CapturePage(txtURL.Text, new Size((int)nudWebpageWidth.Value, (int)nudWebpageHeight.Value));
|
||||
}
|
||||
|
||||
private void StopCapture()
|
||||
|
|
|
@ -75,8 +75,25 @@
|
|||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Design" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="windows">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Facade\windows.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Windows.Foundation.FoundationContract">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Windows.Foundation.UniversalApiContract">
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.17763.0\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SharedAssemblyInfo.cs">
|
||||
|
@ -85,6 +102,7 @@
|
|||
<Compile Include="Animations\BaseAnimation.cs" />
|
||||
<Compile Include="Animations\PointAnimation.cs" />
|
||||
<Compile Include="Animations\RectangleAnimation.cs" />
|
||||
<Compile Include="WebpageCapture\EdgeWebpageCapture.cs" />
|
||||
<Compile Include="Forms\CanvasSizeForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -223,8 +241,9 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Screenshot_Transparent.cs" />
|
||||
<Compile Include="Animations\TextAnimation.cs" />
|
||||
<Compile Include="WebpageCapture.cs" />
|
||||
<Compile Include="WebpageCaptureOptions.cs" />
|
||||
<Compile Include="WebpageCapture\InternetExplorerWebpageCapture.cs" />
|
||||
<Compile Include="WebpageCapture\WebpageCaptureBase.cs" />
|
||||
<Compile Include="WebpageCapture\WebpageCaptureOptions.cs" />
|
||||
<Compile Include="RegionHelpers\WindowsList.cs" />
|
||||
<Compile Include="RegionHelpers\WindowsRectangleList.cs" />
|
||||
</ItemGroup>
|
||||
|
|
103
ShareX.ScreenCaptureLib/WebpageCapture/EdgeWebpageCapture.cs
Normal file
103
ShareX.ScreenCaptureLib/WebpageCapture/EdgeWebpageCapture.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2018 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Windows.Foundation;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.Web.UI;
|
||||
using Windows.Web.UI.Interop;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib.WebpageCapture
|
||||
{
|
||||
public class EdgeWebpageCapture : WebpageCaptureBase
|
||||
{
|
||||
private WebViewControl webView;
|
||||
private WebViewControlProcess viewProcess;
|
||||
private Control viewHost;
|
||||
|
||||
public EdgeWebpageCapture()
|
||||
{
|
||||
viewProcess = new WebViewControlProcess();
|
||||
viewHost = new Control();
|
||||
|
||||
webView = viewProcess.CreateWebViewControlAsync(viewHost.Handle.ToInt64(), new Rect()).GetAwaiter().GetResult();
|
||||
webView.LongRunningScriptDetected += (s, e) => e.StopPageScriptExecution = true;
|
||||
webView.NavigationCompleted += webView_NavigationCompleted;
|
||||
}
|
||||
|
||||
public override void CapturePage(string url, System.Drawing.Size browserSize)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
webView.Bounds = new Rect(0, 0, browserSize.Width, browserSize.Height);
|
||||
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
url = "about:blank";
|
||||
}
|
||||
|
||||
webView.Navigate(new Uri(url, UriKind.Absolute));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
webView.Stop();
|
||||
}
|
||||
|
||||
private async void webView_NavigationCompleted(object sender, WebViewControlNavigationCompletedEventArgs e)
|
||||
{
|
||||
if (e.IsSuccess)
|
||||
{
|
||||
await Task.Delay(CaptureDelay);
|
||||
|
||||
using (IRandomAccessStream stream = new InMemoryRandomAccessStream())
|
||||
{
|
||||
await webView.CapturePreviewToStreamAsync(stream);
|
||||
OnCaptureCompleted(new Bitmap(stream.AsStream()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnCaptureCompleted(null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
webView.Close();
|
||||
viewHost.Dispose();
|
||||
|
||||
if (viewProcess.ProcessId != 0)
|
||||
{
|
||||
viewProcess.Terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,17 +29,13 @@ You should have received a copy of the GNU General Public License
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
namespace ShareX.ScreenCaptureLib.WebpageCapture
|
||||
{
|
||||
public class WebpageCapture : IDisposable
|
||||
public class InternetExplorerWebpageCapture : WebpageCaptureBase
|
||||
{
|
||||
public event Action<Bitmap> CaptureCompleted;
|
||||
|
||||
public int CaptureDelay { get; set; }
|
||||
|
||||
private WebBrowser webBrowser;
|
||||
|
||||
public WebpageCapture()
|
||||
public InternetExplorerWebpageCapture()
|
||||
{
|
||||
webBrowser = new WebBrowser();
|
||||
webBrowser.AllowNavigation = true;
|
||||
|
@ -48,12 +44,7 @@ public WebpageCapture()
|
|||
webBrowser.DocumentCompleted += webBrowser_DocumentCompleted;
|
||||
}
|
||||
|
||||
public void CapturePage(string url)
|
||||
{
|
||||
CapturePage(url, Screen.PrimaryScreen.Bounds.Size);
|
||||
}
|
||||
|
||||
public void CapturePage(string url, Size browserSize)
|
||||
public override void CapturePage(string url, Size browserSize)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
|
@ -62,7 +53,7 @@ public void CapturePage(string url, Size browserSize)
|
|||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
public override void Stop()
|
||||
{
|
||||
webBrowser.Stop();
|
||||
}
|
||||
|
@ -131,19 +122,7 @@ private static void GetImage(object obj, Image destination, Color backgroundColo
|
|||
}
|
||||
}
|
||||
|
||||
protected void OnCaptureCompleted(Bitmap bmp)
|
||||
{
|
||||
if (CaptureCompleted != null)
|
||||
{
|
||||
CaptureCompleted(bmp);
|
||||
}
|
||||
else if (bmp != null)
|
||||
{
|
||||
bmp.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public override void Dispose()
|
||||
{
|
||||
if (webBrowser != null)
|
||||
{
|
84
ShareX.ScreenCaptureLib/WebpageCapture/WebpageCaptureBase.cs
Normal file
84
ShareX.ScreenCaptureLib/WebpageCapture/WebpageCaptureBase.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2018 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Windows.Foundation.Metadata;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib.WebpageCapture
|
||||
{
|
||||
public abstract class WebpageCaptureBase : IDisposable
|
||||
{
|
||||
public event Action<Bitmap> CaptureCompleted;
|
||||
|
||||
public int CaptureDelay { get; set; }
|
||||
|
||||
public abstract void CapturePage(string url, Size browserSize);
|
||||
|
||||
public abstract void Stop();
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public void CapturePage(string url)
|
||||
{
|
||||
CapturePage(url, Screen.PrimaryScreen.Bounds.Size);
|
||||
}
|
||||
|
||||
protected void OnCaptureCompleted(Bitmap bmp)
|
||||
{
|
||||
if (CaptureCompleted != null)
|
||||
{
|
||||
CaptureCompleted(bmp);
|
||||
}
|
||||
else if (bmp != null)
|
||||
{
|
||||
bmp.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool WebViewSupported()
|
||||
{
|
||||
return ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 6) && // 6th API contract is minimum for WebView support.
|
||||
File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "edgehtml.dll")); // Make sure EdgeHTML is present.
|
||||
}
|
||||
|
||||
public static WebpageCaptureBase Create()
|
||||
{
|
||||
if (Helpers.IsWindows10OrGreater() && WebViewSupported())
|
||||
{
|
||||
try
|
||||
{
|
||||
return new EdgeWebpageCapture();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return new InternetExplorerWebpageCapture();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using System.Drawing;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
namespace ShareX.ScreenCaptureLib.WebpageCapture
|
||||
{
|
||||
public class WebpageCaptureOptions
|
||||
{
|
|
@ -25,7 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.HistoryLib;
|
||||
using ShareX.ScreenCaptureLib;
|
||||
using ShareX.ScreenCaptureLib.WebpageCapture;
|
||||
using ShareX.UploadersLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -118,9 +118,9 @@
|
|||
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="windows">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD</HintPath>
|
||||
<HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Facade\windows.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Windows.ApplicationModel.Activation.ActivatedEventsContract">
|
||||
|
|
Loading…
Reference in a new issue