Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Request class methods SetReferrer, GetReferrerURL and GetReferrerPolicy #642

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ supporting this project actively on a daily basis.
* [SetUrl](api/Request.md#seturl)
* [GetMethod](api/Request.md#getmethod)
* [SetMethod](api/Request.md#setmethod)
* [SetReferrer](api/Request.md#setreferrer)
* [GetReferrerURL](api/Request.md#getreferrerurl)
* [GetReferrerPolicy](api/Request.md#getreferrerpolicy)
* [GetPostData](api/Request.md#getpostdata)
* [SetPostData](api/Request.md#setpostdata)
* [GetHeaderMap](api/Request.md#getheadermap)
Expand Down
3 changes: 3 additions & 0 deletions api/API-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@
* [SetUrl](Request.md#seturl)
* [GetMethod](Request.md#getmethod)
* [SetMethod](Request.md#setmethod)
* [SetReferrer](Request.md#setreferrer)
* [GetReferrerURL](Request.md#getreferrerurl)
* [GetReferrerPolicy](Request.md#getreferrerpolicy)
* [GetPostData](Request.md#getpostdata)
* [SetPostData](Request.md#setpostdata)
* [GetHeaderMap](Request.md#getheadermap)
Expand Down
46 changes: 46 additions & 0 deletions api/Request.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Table of contents:
* [SetUrl](#seturl)
* [GetMethod](#getmethod)
* [SetMethod](#setmethod)
* [SetReferrer](#setreferrer)
* [GetReferrerURL](#getreferrerurl)
* [GetReferrerPolicy](#getreferrerpolicy)
* [GetPostData](#getpostdata)
* [SetPostData](#setpostdata)
* [GetHeaderMap](#getheadermap)
Expand Down Expand Up @@ -89,6 +92,49 @@ if post data is provided and GET otherwise.
Set the request method type.


### SetReferrer

| Parameter | Type |
| --- | --- |
| referrer_url | string |
| policy | ReferrerPolicy |
| __Return__ | void |

Set the request referrer.

`referrer` must be a fully qualified url.

`ReferrerPolicy` constants in the cefpython module:
* **REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE**
* **REFERRER_POLICY_DEFAULT** - equivalent to REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE
* **REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN**
* **REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN**
* **REFERRER_POLICY_NEVER_CLEAR_REFERRER**
* **REFERRER_POLICY_ORIGIN**
* **REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN**
* **REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE**
* **REFERRER_POLICY_NO_REFERRER**
* **REFERRER_POLICY_LAST_VALUE**


### GetReferrerURL

| | |
| --- | --- |
| __Return__ | string |

Get the referrer url.


### GetReferrerPolicy

| | |
| --- | --- |
| __Return__ | ReferrerPolicy |

Get the referrer policy for this request.


### GetPostData

| | |
Expand Down
4 changes: 0 additions & 4 deletions src/compile_time_constants.pxi
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# This file was generated by setup.py

# Type this command to ignore changes to this file:
# git update-index --assume-unchanged src/compile_time_constants.pxi

DEF UNAME_SYSNAME = "Windows"
DEF PY_MAJOR_VERSION = 3
cdef extern from "limits.h":
Expand Down
6 changes: 5 additions & 1 deletion src/extern/cef/cef_request.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cef_ptr cimport CefRefPtr
from cef_string cimport CefString
# noinspection PyUnresolvedReferences
from cef_types cimport cef_urlrequest_flags_t, cef_postdataelement_type_t
from cef_types cimport cef_urlrequest_flags_t, cef_postdataelement_type_t, cef_referrer_policy_t
# noinspection PyUnresolvedReferences
from libcpp.vector cimport vector as cpp_vector
from libcpp cimport bool as cpp_bool
Expand All @@ -16,6 +16,7 @@ cdef extern from "include/cef_request.h":
# This types won't be visible in pyx files!
ctypedef cpp_multimap[CefString, CefString] HeaderMap
# ctypedef cef_urlrequest_flags_t CefRequestFlags
ctypedef cef_referrer_policy_t ReferrerPolicy

cdef CefRefPtr[CefRequest] CefRequest_Create "CefRequest::Create"()
cdef cppclass CefRequest:
Expand All @@ -24,6 +25,9 @@ cdef extern from "include/cef_request.h":
void SetURL(CefString& url)
CefString GetMethod()
void SetMethod(CefString& method)
void SetReferrer(CefString& referrer_url, ReferrerPolicy& policy)
CefString GetReferrerURL()
ReferrerPolicy GetReferrerPolicy()
CefRefPtr[CefPostData] GetPostData()
void SetPostData(CefRefPtr[CefPostData] postData)
void GetHeaderMap(HeaderMap& headerMap)
Expand Down
13 changes: 13 additions & 0 deletions src/extern/cef/cef_types.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ cdef extern from "include/internal/cef_types.h":
PLUGIN_POLICY_BLOCK,
PLUGIN_POLICY_DISABLE,

ctypedef enum cef_referrer_policy_t:
REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE
REFERRER_POLICY_DEFAULT = REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN,
REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN,
REFERRER_POLICY_NEVER_CLEAR_REFERRER,
REFERRER_POLICY_ORIGIN,
REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN,
REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
REFERRER_POLICY_NO_REFERRER,
REFERRER_POLICY_LAST_VALUE
ctypedef cef_referrer_policy_t ReferrerPolicy

# Drag & drop

ctypedef enum cef_drag_operations_mask_t:
Expand Down
26 changes: 26 additions & 0 deletions src/request.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

include "cefpython.pyx"

# noinspection PyUnresolvedReferences
from cef_types cimport ReferrerPolicy
# noinspection PyUnresolvedReferences
cimport cef_types

Expand All @@ -17,6 +19,17 @@ UR_FLAG_NO_DOWNLOAD_DATA = cef_types.UR_FLAG_NO_DOWNLOAD_DATA
UR_FLAG_NO_RETRY_ON_5XX = cef_types.UR_FLAG_NO_RETRY_ON_5XX
UR_FLAG_STOP_ON_REDIRECT = cef_types.UR_FLAG_STOP_ON_REDIRECT

# cef_referrer_policy_t
REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE = cef_types.REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE
REFERRER_POLICY_DEFAULT = cef_types.REFERRER_POLICY_DEFAULT
REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN = cef_types.REFERRER_POLICY_REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN
REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN = cef_types.REFERRER_POLICY_ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN
REFERRER_POLICY_NEVER_CLEAR_REFERRER = cef_types.REFERRER_POLICY_NEVER_CLEAR_REFERRER
REFERRER_POLICY_ORIGIN = cef_types.REFERRER_POLICY_ORIGIN
REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN = cef_types.REFERRER_POLICY_CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN
REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE = cef_types.REFERRER_POLICY_ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE
REFERRER_POLICY_NO_REFERRER = cef_types.REFERRER_POLICY_NO_REFERRER
REFERRER_POLICY_LAST_VALUE = cef_types.REFERRER_POLICY_LAST_VALUE

class Request:
# TODO: autocomplete in PyCharm doesn't work for these flags
Expand Down Expand Up @@ -80,6 +93,19 @@ cdef class PyRequest:
PyToCefString(method, cefMethod)
self.GetCefRequest().get().SetMethod(cefMethod)

cpdef py_void SetReferrer(self, py_string referrer_url, cef_types.cef_referrer_policy_t policy):
cdef CefString cefReferrerUrl
PyToCefString(referrer_url, cefReferrerUrl)
self.GetCefRequest().get().SetReferrer(cefReferrerUrl, policy)

cpdef str GetReferrerURL(self):
return CefToPyString(self.GetCefRequest().get().GetReferrerURL())

cpdef cef_types.cef_referrer_policy_t GetReferrerPolicy(self):
cdef cef_types.cef_referrer_policy_t rp
rp = <cef_types.cef_referrer_policy_t>self.GetCefRequest().get().GetReferrerPolicy()
return rp

cpdef object GetPostData(self):
if self.GetMethod() != "POST":
return {}
Expand Down