From 270640f9a3de412b5465d521af112ecfcacb8dc6 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 8 Jul 2020 12:47:17 +1000 Subject: [PATCH] Migrate to SDK Style Project format - Migrate to SDK Style Project format - Upgrade to CefSharp.Common 83.4.20 --- CefSharp.Wpf.HwndHost.Example/App.config | 5 - CefSharp.Wpf.HwndHost.Example/App.xaml | 2 +- CefSharp.Wpf.HwndHost.Example/App.xaml.cs | 47 +++++-- CefSharp.Wpf.HwndHost.Example/AssemblyInfo.cs | 14 +++ .../CefSharp.Wpf.HwndHost.Example.csproj | 118 ++---------------- .../Properties/AssemblyInfo.cs | 55 -------- .../Properties/Resources.Designer.cs | 71 ----------- .../Properties/Resources.resx | 117 ----------------- .../Properties/Settings.Designer.cs | 30 ----- .../Properties/Settings.settings | 7 -- CefSharp.Wpf.HwndHost.Example/packages.config | 6 - CefSharp.Wpf.HwndHost.sln | 6 +- CefSharp.Wpf.HwndHost/CefSettings.cs | 2 +- .../CefSharp.Wpf.HwndHost.csproj | 66 +--------- CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs | 20 ++- .../Properties/AssemblyInfo.cs | 36 ------ 16 files changed, 94 insertions(+), 508 deletions(-) create mode 100644 CefSharp.Wpf.HwndHost.Example/AssemblyInfo.cs delete mode 100644 CefSharp.Wpf.HwndHost.Example/Properties/AssemblyInfo.cs delete mode 100644 CefSharp.Wpf.HwndHost.Example/Properties/Resources.Designer.cs delete mode 100644 CefSharp.Wpf.HwndHost.Example/Properties/Resources.resx delete mode 100644 CefSharp.Wpf.HwndHost.Example/Properties/Settings.Designer.cs delete mode 100644 CefSharp.Wpf.HwndHost.Example/Properties/Settings.settings delete mode 100644 CefSharp.Wpf.HwndHost.Example/packages.config delete mode 100644 CefSharp.Wpf.HwndHost/Properties/AssemblyInfo.cs diff --git a/CefSharp.Wpf.HwndHost.Example/App.config b/CefSharp.Wpf.HwndHost.Example/App.config index b70bf62..1e89887 100644 --- a/CefSharp.Wpf.HwndHost.Example/App.config +++ b/CefSharp.Wpf.HwndHost.Example/App.config @@ -3,9 +3,4 @@ - - - - - diff --git a/CefSharp.Wpf.HwndHost.Example/App.xaml b/CefSharp.Wpf.HwndHost.Example/App.xaml index f65bb61..a6c1bcc 100644 --- a/CefSharp.Wpf.HwndHost.Example/App.xaml +++ b/CefSharp.Wpf.HwndHost.Example/App.xaml @@ -1,4 +1,4 @@ - public partial class App : Application { - protected override void OnStartup(StartupEventArgs e) + public App() { - base.OnStartup(e); + //Add Custom assembly resolver + AppDomain.CurrentDomain.AssemblyResolve += Resolver; + + //Any CefSharp references have to be in another method with NonInlining + // attribute so the assembly rolver has time to do it's thing. + InitializeCefSharp(); + } + [MethodImpl(MethodImplOptions.NoInlining)] + private static void InitializeCefSharp() + { var settings = new CefSettings(); - settings.BrowserSubprocessPath = Path.GetFullPath(@"x86\CefSharp.BrowserSubprocess.exe"); - Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); + // Set BrowserSubProcessPath based on app bitness at runtime + settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, + Environment.Is64BitProcess ? "x64" : "x86", + "CefSharp.BrowserSubprocess.exe"); + + // Make sure you set performDependencyCheck false + Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); } - protected override void OnExit(ExitEventArgs e) + // Will attempt to load missing assembly from either x86 or x64 subdir + // Required by CefSharp to load the unmanaged dependencies when running using AnyCPU + private static Assembly Resolver(object sender, ResolveEventArgs args) { - base.OnExit(e); + if (args.Name.StartsWith("CefSharp")) + { + string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll"; + string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, + Environment.Is64BitProcess ? "x64" : "x86", + assemblyName); + + return File.Exists(archSpecificPath) + ? Assembly.LoadFile(archSpecificPath) + : null; + } - Cef.Shutdown(); + return null; } } } diff --git a/CefSharp.Wpf.HwndHost.Example/AssemblyInfo.cs b/CefSharp.Wpf.HwndHost.Example/AssemblyInfo.cs new file mode 100644 index 0000000..ed33db9 --- /dev/null +++ b/CefSharp.Wpf.HwndHost.Example/AssemblyInfo.cs @@ -0,0 +1,14 @@ +// Copyright © 2019 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/CefSharp.Wpf.HwndHost.Example/CefSharp.Wpf.HwndHost.Example.csproj b/CefSharp.Wpf.HwndHost.Example/CefSharp.Wpf.HwndHost.Example.csproj index 8455671..ceeae0a 100644 --- a/CefSharp.Wpf.HwndHost.Example/CefSharp.Wpf.HwndHost.Example.csproj +++ b/CefSharp.Wpf.HwndHost.Example/CefSharp.Wpf.HwndHost.Example.csproj @@ -1,117 +1,19 @@ - - - - - - + - Debug - AnyCPU - {9F7C8D25-3BD2-414B-9C6C-52E371E0C5E8} WinExe + true + net462 + CefSharp.Wpf.HwndHost.Example - CefSharp.Wpf.HwndHost.Example - v4.6.2 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - true - true - - - true + true + CefSharp.Wpf.HwndHost.Example.App + AnyCPU - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - Off - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - app.manifest - - - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - + + - - {b0942de1-d92a-4eb4-a407-47d2e223108b} - CefSharp.Wpf.HwndHost - + - - \ No newline at end of file diff --git a/CefSharp.Wpf.HwndHost.Example/Properties/AssemblyInfo.cs b/CefSharp.Wpf.HwndHost.Example/Properties/AssemblyInfo.cs deleted file mode 100644 index c4c22e3..0000000 --- a/CefSharp.Wpf.HwndHost.Example/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("CefSharp.Wpf.HwndHost.Example")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CefSharp.Wpf.HwndHost.Example")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CefSharp.Wpf.HwndHost.Example/Properties/Resources.Designer.cs b/CefSharp.Wpf.HwndHost.Example/Properties/Resources.Designer.cs deleted file mode 100644 index 7e620f1..0000000 --- a/CefSharp.Wpf.HwndHost.Example/Properties/Resources.Designer.cs +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace CefSharp.Wpf.HwndHost.Example.Properties -{ - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CefSharp.Wpf.HwndHost.Example.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/CefSharp.Wpf.HwndHost.Example/Properties/Resources.resx b/CefSharp.Wpf.HwndHost.Example/Properties/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/CefSharp.Wpf.HwndHost.Example/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/CefSharp.Wpf.HwndHost.Example/Properties/Settings.Designer.cs b/CefSharp.Wpf.HwndHost.Example/Properties/Settings.Designer.cs deleted file mode 100644 index 62eb995..0000000 --- a/CefSharp.Wpf.HwndHost.Example/Properties/Settings.Designer.cs +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace CefSharp.Wpf.HwndHost.Example.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/CefSharp.Wpf.HwndHost.Example/Properties/Settings.settings b/CefSharp.Wpf.HwndHost.Example/Properties/Settings.settings deleted file mode 100644 index 033d7a5..0000000 --- a/CefSharp.Wpf.HwndHost.Example/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/CefSharp.Wpf.HwndHost.Example/packages.config b/CefSharp.Wpf.HwndHost.Example/packages.config deleted file mode 100644 index 16ea9cb..0000000 --- a/CefSharp.Wpf.HwndHost.Example/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CefSharp.Wpf.HwndHost.sln b/CefSharp.Wpf.HwndHost.sln index f4b6541..82503c1 100644 --- a/CefSharp.Wpf.HwndHost.sln +++ b/CefSharp.Wpf.HwndHost.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.645 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.Wpf.HwndHost", "CefSharp.Wpf.HwndHost\CefSharp.Wpf.HwndHost.csproj", "{B0942DE1-D92A-4EB4-A407-47D2E223108B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.Wpf.HwndHost", "CefSharp.Wpf.HwndHost\CefSharp.Wpf.HwndHost.csproj", "{B0942DE1-D92A-4EB4-A407-47D2E223108B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.Wpf.HwndHost.Example", "CefSharp.Wpf.HwndHost.Example\CefSharp.Wpf.HwndHost.Example.csproj", "{9F7C8D25-3BD2-414B-9C6C-52E371E0C5E8}" EndProject diff --git a/CefSharp.Wpf.HwndHost/CefSettings.cs b/CefSharp.Wpf.HwndHost/CefSettings.cs index df6570d..9fd120e 100644 --- a/CefSharp.Wpf.HwndHost/CefSettings.cs +++ b/CefSharp.Wpf.HwndHost/CefSettings.cs @@ -7,7 +7,7 @@ namespace CefSharp.Wpf.HwndHost /// /// Initialization settings. Many of these and other settings can also configured using command-line switches. /// - public class CefSettings : AbstractCefSettings + public class CefSettings : CefSettingsBase { } } diff --git a/CefSharp.Wpf.HwndHost/CefSharp.Wpf.HwndHost.csproj b/CefSharp.Wpf.HwndHost/CefSharp.Wpf.HwndHost.csproj index 72d9ccf..a784304 100644 --- a/CefSharp.Wpf.HwndHost/CefSharp.Wpf.HwndHost.csproj +++ b/CefSharp.Wpf.HwndHost/CefSharp.Wpf.HwndHost.csproj @@ -1,66 +1,12 @@ - - - + - Debug - AnyCPU - {B0942DE1-D92A-4EB4-A407-47D2E223108B} - Library - Properties + net462 + true CefSharp.Wpf.HwndHost - CefSharp.Wpf.HwndHost - v4.6.2 - 512 - true - - - true + true - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - ..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\PresentationFramework.dll - - - - - - - - - - - - - - + - - - 79.1.360 - + - \ No newline at end of file diff --git a/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs b/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs index f7f333b..1047e77 100644 --- a/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf.HwndHost/ChromiumWebBrowser.cs @@ -447,6 +447,11 @@ public IRequestContext RequestContext /// The redo command. public ICommand RedoCommand { get; private set; } + /// + /// Used as workaround for issue https://github.com/cefsharp/CefSharp/issues/3021 + /// + private long canExecuteJavascriptInMainFrameId; + /// /// A flag that indicates if you can execute javascript in the main frame. /// Flag is set to true in IRenderProcessMessageHandler.OnContextCreated. @@ -836,8 +841,21 @@ void IWebBrowserInternal.OnLoadError(LoadErrorEventArgs args) LoadError?.Invoke(this, args); } - void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(bool canExecute) + void IWebBrowserInternal.SetCanExecuteJavascriptOnMainFrame(long frameId, bool canExecute) { + //When loading pages of a different origin the frameId changes + //For the first loading of a new origin the messages from the render process + //Arrive in a different order than expected, the OnContextCreated message + //arrives before the OnContextReleased, then the message for OnContextReleased + //incorrectly overrides the value + //https://github.com/cefsharp/CefSharp/issues/3021 + + if (frameId > canExecuteJavascriptInMainFrameId && !canExecute) + { + return; + } + + canExecuteJavascriptInMainFrameId = frameId; CanExecuteJavascriptInMainFrame = canExecute; } diff --git a/CefSharp.Wpf.HwndHost/Properties/AssemblyInfo.cs b/CefSharp.Wpf.HwndHost/Properties/AssemblyInfo.cs deleted file mode 100644 index 7e2b89b..0000000 --- a/CefSharp.Wpf.HwndHost/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("CefSharp.Wpf.HwndHost")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CefSharp.Wpf.HwndHost")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b0942de1-d92a-4eb4-a407-47d2e223108b")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")]