/main/src/addins/WindowsPlatform/WindowsAPICodePack/Shell/InternetExplorer/InternetExplorer.cs

https://github.com/directhex/monodevelop · C# · 77 lines · 41 code · 5 blank · 31 comment · 9 complexity · 3b6bb1e6646a71425c3000ad344e76c8 MD5 · raw file

  1. //
  2. // InternetExplorer.cs
  3. //
  4. // Author:
  5. // Vsevolod Kukol <sevoku@microsoft.com>
  6. //
  7. // Copyright (c) 2016 (c) Vsevolod Kukol
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using Microsoft.Win32;
  27. using System.IO;
  28. namespace Microsoft.WindowsAPICodePack.InternetExplorer
  29. {
  30. /// <summary>Internet Explorer Emulation Modes</summary>
  31. /// <remarks>https://msdn.microsoft.com/de-de/library/ee330730.aspx#browser_emulation</remarks>
  32. public enum IEEmulationMode
  33. {
  34. IE7 = 0x00001b58,
  35. IE8 = 0x00001f40,
  36. IE8Force = 0x000022b8,
  37. IE9 = 0x00002328,
  38. IE9Force = 0x0000270f,
  39. IE10 = 0x00002710,
  40. IE10Force = 0x00002711,
  41. IE11 = 0x00002af8,
  42. IE11Force = 0x00002af9,
  43. Default = IE7,
  44. }
  45. public static class InternetExplorer
  46. {
  47. static readonly string browserEmulationKeyPath = @"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION";
  48. /// <summary>
  49. /// Gets or sets the embedded IE emulation mode.
  50. /// </summary>
  51. /// <value>The emulation mode.</value>
  52. public static IEEmulationMode EmulationMode {
  53. get {
  54. var regKey = Registry.CurrentUser.OpenSubKey (browserEmulationKeyPath, false);
  55. if (regKey == null)
  56. return IEEmulationMode.Default;
  57. var myProgramName = Path.GetFileName (System.Reflection.Assembly.GetEntryAssembly ().Location);
  58. var currentValue = regKey.GetValue (myProgramName);
  59. return currentValue is int ? (IEEmulationMode)currentValue : IEEmulationMode.Default;
  60. }
  61. set {
  62. if (EmulationMode == value) // load current value and update it only if necessary
  63. return;
  64. var regKey = Registry.CurrentUser.CreateSubKey (browserEmulationKeyPath, RegistryKeyPermissionCheck.ReadWriteSubTree);
  65. var executableName = Path.GetFileName (System.Reflection.Assembly.GetEntryAssembly ().Location);
  66. var currentValue = regKey.GetValue (executableName);
  67. if (currentValue == null || !(currentValue is int) || (int)currentValue != (int)value)
  68. regKey.SetValue (executableName, (int)value, RegistryValueKind.DWord);
  69. }
  70. }
  71. }
  72. }