Skip to content

Commit def7c6c

Browse files
committed
Add SetReferrer, ReferrerUrl and ReferrerPolicy
Resolves #1464
1 parent 70121a5 commit def7c6c

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

CefSharp.Core/Internals/CefRequestWrapper.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ namespace CefSharp
5151
_wrappedRequest->SetMethod(StringUtils::ToNative(method));
5252
}
5353

54+
void CefRequestWrapper::SetReferrer(String^ referrerUrl, CefSharp::ReferrerPolicy policy)
55+
{
56+
ThrowIfDisposed();
57+
58+
_wrappedRequest->SetReferrer(StringUtils::ToNative(referrerUrl), (cef_referrer_policy_t)policy);
59+
}
60+
61+
String^ CefRequestWrapper::ReferrerUrl::get()
62+
{
63+
ThrowIfDisposed();
64+
65+
return StringUtils::ToClr(_wrappedRequest->GetReferrerURL());
66+
}
67+
68+
CefSharp::ReferrerPolicy CefRequestWrapper::ReferrerPolicy::get()
69+
{
70+
ThrowIfDisposed();
71+
72+
return (CefSharp::ReferrerPolicy)_wrappedRequest->GetReferrerPolicy();
73+
}
74+
5475
NameValueCollection^ CefRequestWrapper::Headers::get()
5576
{
5677
ThrowIfDisposed();

CefSharp.Core/Internals/CefRequestWrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ namespace CefSharp
4242
public:
4343
virtual property String^ Url { String^ get(); void set(String^ url); }
4444
virtual property String^ Method { String^ get(); void set(String^ method); }
45+
virtual void SetReferrer(String^ referrerUrl, CefSharp::ReferrerPolicy policy);
46+
virtual property String^ ReferrerUrl { String^ get(); }
47+
virtual property ReferrerPolicy ReferrerPolicy { CefSharp::ReferrerPolicy get(); }
4548
virtual property NameValueCollection^ Headers { NameValueCollection^ get(); void set(NameValueCollection^ url); }
4649
virtual property TransitionType TransitionType { CefSharp::TransitionType get(); }
4750
virtual property IPostData^ PostData { IPostData^ get(); }

CefSharp/CefSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<Compile Include="PluginPolicy.cs" />
171171
<Compile Include="PostDataElementType.cs" />
172172
<Compile Include="PostDataExtensions.cs" />
173+
<Compile Include="ReferrerPolicy.cs" />
173174
<Compile Include="ResourceHandler.cs" />
174175
<Compile Include="ResourceHandlerType.cs" />
175176
<Compile Include="ResponseAction.cs" />

CefSharp/IRequest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ public interface IRequest : IDisposable
1919
/// </summary>
2020
string Method { get; set; }
2121

22+
/// <summary>
23+
/// Set the referrer URL and policy. If non-empty the referrer URL must be
24+
/// fully qualified with an HTTP or HTTPS scheme component. Any username,
25+
/// password or ref component will be removed.
26+
/// </summary>
27+
/// <param name="referrerUrl">the referrer url</param>
28+
/// <param name="policy">referrer policy</param>
29+
void SetReferrer(string referrerUrl, ReferrerPolicy policy);
30+
31+
/// <summary>
32+
/// Get the referrer URL.
33+
/// </summary>
34+
string ReferrerUrl { get; }
35+
36+
37+
/// <summary>
38+
/// Get the referrer policy.
39+
/// </summary>
40+
ReferrerPolicy ReferrerPolicy { get; }
41+
2242
/// <summary>
2343
/// Header Collection
2444
/// NOTE: This collection is a copy of the underlying type, to make changes, take a reference to the collection,

CefSharp/ReferrerPolicy.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
namespace CefSharp
6+
{
7+
public enum ReferrerPolicy
8+
{
9+
/// <summary>
10+
/// Always send the complete Referrer value.
11+
/// </summary>
12+
Always = 0,
13+
14+
/// <summary>
15+
//// Use the default policy. This is OriginWhenCrossOrigin
16+
/// when the `--reduced-referrer-granularity` command-line flag is specified
17+
/// and NoReferrerWhenDowngrade otherwise.
18+
/// </summary>
19+
Default,
20+
21+
/// <summary>
22+
/// When navigating from HTTPS to HTTP do not send the Referrer value.
23+
/// Otherwise, send the complete Referrer value.
24+
/// </summary>
25+
NoReferrerWhenDowngrade,
26+
27+
/// <summary>
28+
/// Never send the Referrer value.
29+
/// </summary>
30+
Never,
31+
32+
/// <summary>
33+
/// Only send the origin component of the Referrer value.
34+
/// </summary>
35+
Origin,
36+
37+
/// <summary>
38+
/// When navigating cross-origin only send the origin component of the Referrer value. Otherwise, send the complete Referrer value.
39+
/// </summary>
40+
OriginWhenCrossOrigin
41+
}
42+
}

0 commit comments

Comments
 (0)