diff --git a/README.md b/README.md index e9175971..76696687 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/api/API-index.md b/api/API-index.md index 9535cb5b..542bfc6e 100644 --- a/api/API-index.md +++ b/api/API-index.md @@ -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) diff --git a/api/Request.md b/api/Request.md index d9d0ece3..d1cf2cbc 100644 --- a/api/Request.md +++ b/api/Request.md @@ -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) @@ -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 | | | diff --git a/src/compile_time_constants.pxi b/src/compile_time_constants.pxi index bf130d6e..023e1b0e 100644 --- a/src/compile_time_constants.pxi +++ b/src/compile_time_constants.pxi @@ -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": diff --git a/src/extern/cef/cef_request.pxd b/src/extern/cef/cef_request.pxd index e7bd336d..cbc59e90 100644 --- a/src/extern/cef/cef_request.pxd +++ b/src/extern/cef/cef_request.pxd @@ -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 @@ -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: @@ -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) diff --git a/src/extern/cef/cef_types.pxd b/src/extern/cef/cef_types.pxd index 6bd21ba4..81c259f2 100644 --- a/src/extern/cef/cef_types.pxd +++ b/src/extern/cef/cef_types.pxd @@ -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: diff --git a/src/request.pyx b/src/request.pyx index c0d2793c..0427561f 100644 --- a/src/request.pyx +++ b/src/request.pyx @@ -4,6 +4,8 @@ include "cefpython.pyx" +# noinspection PyUnresolvedReferences +from cef_types cimport ReferrerPolicy # noinspection PyUnresolvedReferences cimport cef_types @@ -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 @@ -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 = self.GetCefRequest().get().GetReferrerPolicy() + return rp + cpdef object GetPostData(self): if self.GetMethod() != "POST": return {}