Skip to content

Commit b53ff70

Browse files
committed
Core - IRequestContext add new GetWebsiteSetting/SetWebsiteSetting and GetContentSetting/SetContentSetting
Resolves #4991
1 parent 2ebad4d commit b53ff70

File tree

7 files changed

+839
-0
lines changed

7 files changed

+839
-0
lines changed

CefSharp.Core.Runtime.RefAssembly/CefSharp.Core.Runtime.netcore.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,18 @@ public void Dispose() { }
272272
protected virtual void Dispose(bool A_0) { }
273273
~RequestContext() { }
274274
public virtual System.Collections.Generic.IDictionary<string, object> GetAllPreferences(bool includeDefaults) { throw null; }
275+
public virtual CefSharp.Enums.ContentSettingValues GetContentSetting(string requestingUrl, string topLevelUrl, CefSharp.Enums.ContentSettingTypes contentType) { throw null; }
275276
public virtual CefSharp.ICookieManager GetCookieManager(CefSharp.ICompletionCallback callback) { throw null; }
276277
public virtual object GetPreference(string name) { throw null; }
278+
public virtual object GetWebsiteSetting(string requestingUrl, string topLevelUrl, CefSharp.Enums.ContentSettingTypes contentType) { throw null; }
277279
public virtual bool HasPreference(string name) { throw null; }
278280
public virtual bool IsSame(CefSharp.IRequestContext context) { throw null; }
279281
public virtual bool IsSharingWith(CefSharp.IRequestContext context) { throw null; }
280282
public virtual bool RegisterSchemeHandlerFactory(string schemeName, string domainName, CefSharp.ISchemeHandlerFactory factory) { throw null; }
281283
public virtual System.Threading.Tasks.Task<CefSharp.ResolveCallbackResult> ResolveHostAsync(System.Uri origin) { throw null; }
284+
public virtual void SetContentSetting(string requestingUrl, string topLevelUrl, CefSharp.Enums.ContentSettingTypes contentType, CefSharp.Enums.ContentSettingValues value) { }
282285
public virtual bool SetPreference(string name, object value, out string error) { throw null; }
286+
public virtual void SetWebsiteSetting(string requestingUrl, string topLevelUrl, CefSharp.Enums.ContentSettingTypes contentType, object value) { }
283287
public virtual CefSharp.IRequestContext UnWrap() { throw null; }
284288
}
285289
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]

CefSharp.Core.Runtime/RequestContext.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,40 @@ namespace CefSharp
164164
return callback->Task;
165165
}
166166

167+
Object^ RequestContext::GetWebsiteSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType)
168+
{
169+
ThrowIfDisposed();
170+
171+
auto result = _requestContext->GetWebsiteSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType);
172+
173+
return TypeConversion::FromNative(result);
174+
}
175+
176+
void RequestContext::SetWebsiteSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType, Object^ value)
177+
{
178+
ThrowIfDisposed();
179+
180+
auto nativeValue = TypeConversion::ToNative(value);
181+
182+
_requestContext->SetWebsiteSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType, nativeValue);
183+
}
184+
185+
Enums::ContentSettingValues RequestContext::GetContentSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType)
186+
{
187+
ThrowIfDisposed();
188+
189+
auto result = _requestContext->GetContentSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType);
190+
191+
return (Enums::ContentSettingValues)result;
192+
}
193+
194+
void RequestContext::SetContentSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType, Enums::ContentSettingValues value)
195+
{
196+
ThrowIfDisposed();
197+
198+
_requestContext->SetContentSetting(StringUtils::ToNative(requestingUrl), StringUtils::ToNative(topLevelUrl), (cef_content_setting_types_t)contentType, (cef_content_setting_values_t)value);
199+
}
200+
167201
IRequestContext^ RequestContext::UnWrap()
168202
{
169203
return this;

CefSharp.Core.Runtime/RequestContext.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,73 @@ namespace CefSharp
306306
/// <returns>A task that represents the Resoolve Host operation. The value of the TResult parameter contains ResolveCallbackResult.</returns>
307307
virtual Task<ResolveCallbackResult>^ ResolveHostAsync(Uri^ origin);
308308

309+
/// <summary>
310+
/// Returns the current value for <paramref name="contentType"/> that applies for the
311+
/// specified URLs. If both URLs are empty the default value will be returned.
312+
/// Returns null if no value is configured.
313+
/// Must be called on the browser
314+
/// process UI thread.
315+
/// </summary>
316+
/// <param name="requestingUrl">Requesting url</param>
317+
/// <param name="topLevelUrl">Top level url</param>
318+
/// <param name="contentType">Content type</param>
319+
/// <returns>Returns the current value for <paramref name="contentType"/> that applies for the
320+
/// specified URLs.</returns>
321+
virtual Object^ GetWebsiteSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType);
322+
323+
/// <summary>
324+
/// Sets the current value for <paramref name="contentType"/> for the specified URLs in the
325+
/// default scope. If both URLs are empty, and the context is not incognito,
326+
/// the default value will be set. Pass null for <paramref name="value"/> to remove the
327+
/// default value for this content type.
328+
///
329+
/// WARNING: Incorrect usage of this method may cause instability or security
330+
/// issues in Chromium. Make sure that you first understand the potential
331+
/// impact of any changes to <paramref name="contentType"/> by reviewing the related source
332+
/// code in Chromium. For example, if you plan to modify
333+
/// <see cref="ContentSettingTypes.Popups"/>, first review and understand the usage of
334+
/// ContentSettingsType::POPUPS in Chromium:
335+
/// https://source.chromium.org/search?q=ContentSettingsType::POPUPS
336+
/// </summary>
337+
/// <param name="requestingUrl">Requesting url</param>
338+
/// <param name="topLevelUrl">Top level url</param>
339+
/// <param name="contentType">Content type</param>
340+
/// <param name="value">value </param>
341+
virtual void SetWebsiteSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType, Object^ value);
342+
343+
/// <summary>
344+
/// Returns the current value for <paramref name="contentType"/> that applies for the
345+
/// specified URLs. If both URLs are empty the default value will be returned.
346+
/// Returns <see cref="ContentSettingValues.Default"/> if no value is configured. Must
347+
/// be called on the browser process UI thread.
348+
/// </summary>
349+
/// <param name="requestingUrl">Requesting url</param>
350+
/// <param name="topLevelUrl">Top level url</param>
351+
/// <param name="contentType">Content type</param>
352+
/// <returns>Returns the current value for <paramref name="contentType"/> that applies for the
353+
/// specified URLs.</returns>
354+
virtual Enums::ContentSettingValues GetContentSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType);
355+
356+
/// <summary>
357+
/// Sets the current value for <paramref name="contentType"/> for the specified URLs in the
358+
/// default scope. If both URLs are empty, and the context is not incognito,
359+
/// the default value will be set. Pass <see cref="ContentSettingValues.Default"/> for
360+
/// <paramref name="value"/> to use the default value for this content type.
361+
///
362+
/// WARNING: Incorrect usage of this method may cause instability or security
363+
/// issues in Chromium. Make sure that you first understand the potential
364+
/// impact of any changes to |content_type| by reviewing the related source
365+
/// code in Chromium. For example, if you plan to modify
366+
/// <see cref="ContentSettingTypes.Popups"/>, first review and understand the usage of
367+
/// ContentSettingsType::POPUPS in Chromium:
368+
/// https://source.chromium.org/search?q=ContentSettingsType::POPUPS
369+
/// </summary>
370+
/// <param name="requestingUrl">Requesting url</param>
371+
/// <param name="topLevelUrl">Top level url</param>
372+
/// <param name="contentType">Content type</param>
373+
/// <param name="value">value</param>
374+
virtual void SetContentSetting(String^ requestingUrl, String^ topLevelUrl, Enums::ContentSettingTypes contentType, Enums::ContentSettingValues value);
375+
309376
/// <summary>
310377
/// Gets the inner most instance
311378
/// </summary>

CefSharp.Core/RequestContext.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Threading.Tasks;
10+
using CefSharp.Enums;
1011

1112
namespace CefSharp
1213
{
@@ -197,6 +198,26 @@ public Task<ResolveCallbackResult> ResolveHostAsync(Uri origin)
197198
return requestContext.ResolveHostAsync(origin);
198199
}
199200

201+
public object GetWebsiteSetting(string requestingUrl, string topLevelUrl, ContentSettingTypes contentType)
202+
{
203+
return requestContext.GetWebsiteSetting(requestingUrl, topLevelUrl, contentType);
204+
}
205+
206+
public void SetWebsiteSetting(string requestingUrl, string topLevelUrl, ContentSettingTypes contentType, object value)
207+
{
208+
requestContext.SetWebsiteSetting(requestingUrl, topLevelUrl, contentType, value);
209+
}
210+
211+
public ContentSettingValues GetContentSetting(string requestingUrl, string topLevelUrl, ContentSettingTypes contentType)
212+
{
213+
return requestContext.GetContentSetting(requestingUrl, topLevelUrl, contentType);
214+
}
215+
216+
public void SetContentSetting(string requestingUrl, string topLevelUrl, ContentSettingTypes contentType, ContentSettingValues value)
217+
{
218+
requestContext.SetContentSetting(requestingUrl, topLevelUrl, contentType, value);
219+
}
220+
200221
/// <inheritdoc/>
201222
public void Dispose()
202223
{

0 commit comments

Comments
 (0)