Skip to content

Commit 36dc1b7

Browse files
committed
Core - Add Cef.ApiHash
Issue #5066
1 parent 3123817 commit 36dc1b7

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

CefSharp.Core.Runtime/Cef.h

+53
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,37 @@ namespace CefSharp
125125
}
126126
}
127127

128+
/// <summary>
129+
/// API version that will be compiled client-side. The experimental (unversioned)
130+
/// API is selected by default. Clients can set the CEF_API_VERSION value in
131+
/// their project configuration to configure an explicit API version. Unlike
132+
/// the experimental API, explicit API versions are back/forward compatible with
133+
/// a specific range of CEF versions.
134+
/// </summary>
135+
static property int ApiVersion
136+
{
137+
int get()
138+
{
139+
return CEF_API_VERSION;
140+
}
141+
}
142+
143+
/// <summary>
144+
/// API hashes for the selected CEF_API_VERSION. API hashes are created for
145+
/// each version by analyzing CEF header files for C API type definitions. The
146+
/// hash value will change when header files are modified in a way that may
147+
/// cause binary incompatibility with other builds.
148+
/// </summary>
149+
static property String^ ApiHashPlatform
150+
{
151+
String^ get()
152+
{
153+
auto hash = CEF_API_HASH_PLATFORM;
154+
155+
return gcnew String(hash);
156+
}
157+
}
158+
128159
/// <summary>Gets a value that indicates the Chromium version currently being used.</summary>
129160
/// <value>The Chromium version.</value>
130161
static property String^ ChromiumVersion
@@ -149,6 +180,28 @@ namespace CefSharp
149180
}
150181
}
151182

183+
/// <summary>
184+
/// Configures the CEF API version and returns API hashes for the libcef
185+
/// library. The entry parameter describes which hash value will be returned:
186+
///
187+
/// 0 - CEF_API_HASH_PLATFORM
188+
/// 1 - CEF_API_HASH_UNIVERSAL (deprecated, same as CEF_API_HASH_PLATFORM)
189+
/// 2 - CEF_COMMIT_HASH (from cef_version.h)
190+
///
191+
/// </summary>
192+
/// <param name="version">parameter should be CEF_API_VERSION and any changes to this value will be ignored after the first call to this method.</param>
193+
/// <param name="entry">The entry parameter describes which hash value will be returned:</param>
194+
/// <returns>
195+
/// returns API hashes for the libcef library.
196+
/// The returned string is owned by the library and should not be freed.
197+
/// </returns>
198+
static String^ ApiHash(int version, int entry)
199+
{
200+
auto response = cef_api_hash(version, entry);
201+
202+
return gcnew String(response);
203+
}
204+
152205
/// <summary>
153206
/// Parse the specified url into its component parts.
154207
/// Uses a GURL to parse the Url. GURL is Google's URL parsing library.

CefSharp.Core/Cef.cs

+58
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ public static string CefVersion
8181
get { return Core.Cef.CefVersion; }
8282
}
8383

84+
/// <summary>
85+
/// API version that will be compiled client-side. The experimental (unversioned)
86+
/// API is selected by default. Clients can set the CEF_API_VERSION value in
87+
/// their project configuration to configure an explicit API version. Unlike
88+
/// the experimental API, explicit API versions are back/forward compatible with
89+
/// a specific range of CEF versions.
90+
/// </summary>
91+
public static int ApiVersion
92+
{
93+
get { return Core.Cef.ApiVersion; }
94+
}
95+
96+
97+
/// <summary>
98+
/// API hashes for the selected CEF_API_VERSION. API hashes are created for
99+
/// each version by analyzing CEF header files for C API type definitions. The
100+
/// hash value will change when header files are modified in a way that may
101+
/// cause binary incompatibility with other builds.
102+
/// </summary>
103+
public static string ApiHashPlatform
104+
{
105+
get { return Core.Cef.ApiHashPlatform; }
106+
}
107+
84108
/// <summary>Gets a value that indicates the Chromium version currently being used.</summary>
85109
/// <value>The Chromium version.</value>
86110
public static string ChromiumVersion
@@ -97,6 +121,40 @@ public static string CefCommitHash
97121
get { return Core.Cef.CefCommitHash; }
98122
}
99123

124+
/// <summary>
125+
/// Configures the CEF API version and returns API hashes for the libcef
126+
/// library. Defaults to CEF_API_HASH_PLATFORM
127+
/// </summary>
128+
/// <param name="version">parameter should be CEF_API_VERSION and any changes to this value will be ignored after the first call to this method.</param>
129+
/// <returns>
130+
/// returns API hashes for the libcef library.
131+
/// The returned string is owned by the library and should not be freed.
132+
/// </returns>
133+
public static string ApiHash(int version)
134+
{
135+
return ApiHash(version, 0);
136+
}
137+
138+
/// <summary>
139+
/// Configures the CEF API version and returns API hashes for the libcef
140+
/// library. The entry parameter describes which hash value will be returned:
141+
///
142+
/// 0 - CEF_API_HASH_PLATFORM
143+
/// 1 - CEF_API_HASH_UNIVERSAL (deprecated, same as CEF_API_HASH_PLATFORM)
144+
/// 2 - CEF_COMMIT_HASH (from cef_version.h)
145+
///
146+
/// </summary>
147+
/// <param name="version">parameter should be CEF_API_VERSION and any changes to this value will be ignored after the first call to this method.</param>
148+
/// <param name="entry">The entry parameter describes which hash value will be returned:</param>
149+
/// <returns>
150+
/// returns API hashes for the libcef library.
151+
/// The returned string is owned by the library and should not be freed.
152+
/// </returns>
153+
public static string ApiHash(int version, int entry)
154+
{
155+
return Core.Cef.ApiHash(version, entry);
156+
}
157+
100158
/// <summary>
101159
/// Parse the specified url into its component parts.
102160
/// Uses a GURL to parse the Url. GURL is Google's URL parsing library.

CefSharp.Test/CefSharpFixture.cs

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ private void CefInitialize()
3939
throw new Exception(@"Add <add key=""xunit.appDomain"" value=""denied""/> to your app.config to disable appdomains");
4040
}
4141

42+
var apiHash = Cef.ApiHash(Cef.ApiVersion);
43+
44+
if (Cef.ApiHashPlatform != apiHash)
45+
{
46+
throw new Exception($"CEF API Has does not match expected. {apiHash} {Cef.ApiHashPlatform}");
47+
}
48+
4249
Cef.EnableWaitForBrowsersToClose();
4350
CefSharp.Internals.BrowserRefCounter.Instance.EnableLogging();
4451

0 commit comments

Comments
 (0)