forked from cefsharp/CefSharp.MinimalExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
report the cefsharp cookie filter issue in cefsharp/CefSharp#4074
- Loading branch information
CORP\jzeng
committed
Apr 27, 2022
1 parent
e72cfbc
commit dfc1049
Showing
7 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace CefSharp.MinimalExample.Wpf | ||
{ | ||
public class CookieFilter : ICookieAccessFilter | ||
{ | ||
/// <summary> | ||
/// Called on the CEF IO thread after a resource response is received. | ||
/// </summary> | ||
/// <param name="chromiumWebBrowser">The ChromiumWebBrowser control</param> | ||
/// <param name="browser">the browser object - may be null if originating from ServiceWorker or CefURLRequest</param> | ||
/// <param name="frame">the frame object - may be null if originating from ServiceWorker or CefURLRequest</param> | ||
/// <param name="request">the request object - cannot be modified in this callback</param> | ||
/// <param name="response">the response object - cannot be modified in this callback</param> | ||
/// <param name="cookie">the cookie object</param> | ||
/// <returns> | ||
/// Return true if the specified cookie returned with the response can be saved or false otherwise. | ||
/// </returns> | ||
/// Created By: jzeng On: 4/27/2022 | ||
public bool CanSaveCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, Cookie cookie) | ||
{ | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Called on the CEF IO thread before a resource request is sent. | ||
/// </summary> | ||
/// <param name="chromiumWebBrowser">The ChromiumWebBrowser control</param> | ||
/// <param name="browser">the browser object - may be null if originating from ServiceWorker or CefURLRequest</param> | ||
/// <param name="frame">the frame object - may be null if originating from ServiceWorker or CefURLRequest</param> | ||
/// <param name="request">the request object - cannot be modified in this callback</param> | ||
/// <param name="cookie">the cookie object</param> | ||
/// <returns> | ||
/// Return true if the specified cookie can be sent with the request or false otherwise. | ||
/// </returns> | ||
/// Created By: jzeng On: 4/27/2022 | ||
public bool CanSendCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, Cookie cookie) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using CefSharp.Handler; | ||
|
||
namespace CefSharp.MinimalExample.Wpf | ||
{ | ||
public class DefaultMenuHandler : ContextMenuHandler | ||
{ | ||
protected override void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) | ||
{ | ||
base.OnBeforeContextMenu(chromiumWebBrowser, browser, frame, parameters, model); | ||
|
||
// Add a separator in case that there are more items on the list | ||
if (model.Count > 0) | ||
{ | ||
model.AddSeparator(); | ||
} | ||
|
||
// Add a new item to the list using the AddItem method of the model | ||
model.AddItem(CefMenuCommand.Reload, "Reload"); | ||
} | ||
|
||
protected override bool OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) | ||
{ | ||
if (commandId == CefMenuCommand.Reload) | ||
{ | ||
chromiumWebBrowser.Reload(); | ||
return true; | ||
} | ||
|
||
return base.OnContextMenuCommand(chromiumWebBrowser, browser, frame, parameters, commandId, eventFlags); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using CefSharp.Handler; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CefSharp.MinimalExample.Wpf | ||
{ | ||
public class DefaultRequestHandler : RequestHandler | ||
{ | ||
protected override bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) | ||
{ | ||
callback.Continue("", ""); | ||
return true; | ||
} | ||
|
||
protected override bool OnCertificateError(IWebBrowser chromiumWebBrowser, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) | ||
{ | ||
return base.OnCertificateError(chromiumWebBrowser, browser, errorCode, requestUrl, sslInfo, callback); | ||
} | ||
protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) | ||
{ | ||
return new DefaultResourceRequestHandler(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
CefSharp.MinimalExample.Wpf/DefaultResourceRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using CefSharp.Handler; | ||
|
||
namespace CefSharp.MinimalExample.Wpf | ||
{ | ||
public class DefaultResourceRequestHandler : ResourceRequestHandler | ||
{ | ||
protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) | ||
{ | ||
// change the library login request to post method | ||
if (request.Url == TestUrl.TestLink && request.Method == "GET") | ||
{ | ||
request.Method = "POST"; | ||
} | ||
return CefReturnValue.Continue; | ||
} | ||
protected override ICookieAccessFilter GetCookieAccessFilter(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request) | ||
{ | ||
// return null; | ||
// return new CookieAccessFilter(); | ||
return new CookieFilter(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace CefSharp.MinimalExample.Wpf | ||
{ | ||
public static class TestUrl | ||
{ | ||
public static string TestLink = "https://mstra.rjrpub.com/MicroStrategyLibrary/?loginMode=1048576"; | ||
} | ||
} |