forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebBrowserEmulationMode.cs
82 lines (72 loc) · 3.33 KB
/
WebBrowserEmulationMode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.ComponentModel;
using GitExtUtils;
using Microsoft.Win32;
namespace GitUI
{
public static class WebBrowserEmulationMode
{
public static void SetBrowserFeatureControl()
{
// Fix for issue #2654:
// Set the emulation mode for the embedded .NET WebBrowser control to the IE version installed on the machine.
// http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx
// Only when not running inside Visual Studio Designer
if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
{
return;
}
// FeatureControl settings are per-process
var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
const string featureControlRegKey = @"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\";
if (TryGetBrowserEmulationMode(out var emulationMode))
{
try
{
Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION", appName, emulationMode, RegistryValueKind.DWord);
}
catch (System.UnauthorizedAccessException)
{
// Don't fail when user have no rights to update the registry...
}
}
}
private static bool TryGetBrowserEmulationMode(out uint emulationMode)
{
// https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
// http://stackoverflow.com/questions/28526826/web-browser-control-emulation-issue-feature-browser-emulation/28626667#28626667
emulationMode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode.
try
{
int browserVersion;
using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
RegistryKeyPermissionCheck.ReadSubTree,
System.Security.AccessControl.RegistryRights.QueryValues))
{
var version = ieKey.GetValue("svcVersion");
if (version is null)
{
version = ieKey.GetValue("Version");
if (version is null)
{
return false;
}
}
int.TryParse(version.ToString().LazySplit('.').First(), out browserVersion);
}
emulationMode = browserVersion switch
{
7 => 7000, // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
8 => 8000, // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
9 => 9000, // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
10 => 10000, // Internet Explorer 10.
_ => emulationMode
};
return true;
}
catch
{
return false;
}
}
}
}