2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_COMMON_REQUEST_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_COMMON_REQUEST_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_request.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
|
|
|
|
#include "base/synchronization/lock.h"
|
2021-05-14 18:58:55 +02:00
|
|
|
#include "cef/libcef/common/mojom/cef.mojom.h"
|
2020-03-04 01:29:39 +01:00
|
|
|
#include "net/cookies/site_for_cookies.h"
|
2018-11-03 02:15:09 +01:00
|
|
|
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
|
2016-10-28 20:15:26 +02:00
|
|
|
#include "url/gurl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
namespace blink {
|
|
|
|
class WebURLRequest;
|
|
|
|
} // namespace blink
|
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
namespace content {
|
|
|
|
class NavigationHandle;
|
|
|
|
} // namespace content
|
2015-10-09 17:23:12 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace net {
|
2012-11-30 20:08:20 +01:00
|
|
|
class HttpRequestHeaders;
|
2019-04-24 04:50:25 +02:00
|
|
|
struct RedirectInfo;
|
2019-03-13 22:27:37 +01:00
|
|
|
} // namespace net
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
namespace network {
|
|
|
|
class DataElement;
|
|
|
|
struct ResourceRequest;
|
|
|
|
class ResourceRequestBody;
|
|
|
|
} // namespace network
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Implementation of CefRequest
|
|
|
|
class CefRequestImpl : public CefRequest {
|
|
|
|
public:
|
2015-11-16 23:20:34 +01:00
|
|
|
enum Changes {
|
2017-05-17 11:29:28 +02:00
|
|
|
kChangedNone = 0,
|
|
|
|
kChangedUrl = 1 << 0,
|
|
|
|
kChangedMethod = 1 << 1,
|
|
|
|
kChangedReferrer = 1 << 2,
|
|
|
|
kChangedPostData = 1 << 3,
|
|
|
|
kChangedHeaderMap = 1 << 4,
|
|
|
|
kChangedFlags = 1 << 5,
|
2020-03-04 01:29:39 +01:00
|
|
|
kChangedSiteForCookies = 1 << 6,
|
2015-11-16 23:20:34 +01:00
|
|
|
};
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRequestImpl();
|
2014-11-12 20:25:15 +01:00
|
|
|
|
|
|
|
bool IsReadOnly() override;
|
|
|
|
CefString GetURL() override;
|
|
|
|
void SetURL(const CefString& url) override;
|
|
|
|
CefString GetMethod() override;
|
|
|
|
void SetMethod(const CefString& method) override;
|
2015-12-01 19:22:28 +01:00
|
|
|
void SetReferrer(const CefString& referrer_url,
|
|
|
|
ReferrerPolicy policy) override;
|
|
|
|
CefString GetReferrerURL() override;
|
|
|
|
ReferrerPolicy GetReferrerPolicy() override;
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefPostData> GetPostData() override;
|
|
|
|
void SetPostData(CefRefPtr<CefPostData> postData) override;
|
|
|
|
void GetHeaderMap(HeaderMap& headerMap) override;
|
|
|
|
void SetHeaderMap(const HeaderMap& headerMap) override;
|
2019-04-24 04:50:25 +02:00
|
|
|
CefString GetHeaderByName(const CefString& name) override;
|
|
|
|
void SetHeaderByName(const CefString& name,
|
|
|
|
const CefString& value,
|
|
|
|
bool overwrite) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void Set(const CefString& url,
|
|
|
|
const CefString& method,
|
|
|
|
CefRefPtr<CefPostData> postData,
|
|
|
|
const HeaderMap& headerMap) override;
|
|
|
|
int GetFlags() override;
|
|
|
|
void SetFlags(int flags) override;
|
|
|
|
CefString GetFirstPartyForCookies() override;
|
|
|
|
void SetFirstPartyForCookies(const CefString& url) override;
|
|
|
|
ResourceType GetResourceType() override;
|
|
|
|
TransitionType GetTransitionType() override;
|
2023-06-01 16:06:15 +02:00
|
|
|
uint64_t GetIdentifier() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
// Populate this object from the ResourceRequest object.
|
2023-06-01 16:06:15 +02:00
|
|
|
void Set(const network::ResourceRequest* request, uint64_t identifier);
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
// Populate the ResourceRequest object from this object.
|
2019-04-24 04:50:25 +02:00
|
|
|
// If |changed_only| is true then only the changed fields will be updated.
|
|
|
|
void Get(network::ResourceRequest* request, bool changed_only) const;
|
|
|
|
|
|
|
|
// Populate this object from the RedirectInfo object.
|
|
|
|
void Set(const net::RedirectInfo& redirect_info);
|
|
|
|
|
2022-07-29 18:14:16 +02:00
|
|
|
// Populate this object from the HttpRequestHeaders object.
|
2019-04-24 04:50:25 +02:00
|
|
|
void Set(const net::HttpRequestHeaders& headers);
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
// Populate this object from the NavigationParams object.
|
2022-03-26 02:12:30 +01:00
|
|
|
// Called from throttle_handler.cc NavigationOnUIThread().
|
|
|
|
void Set(content::NavigationHandle* navigation_handle);
|
2015-10-09 17:23:12 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// Populate the WebURLRequest object based on the contents of |params|.
|
|
|
|
// Called from CefBrowserImpl::LoadRequest().
|
2021-05-14 18:58:55 +02:00
|
|
|
static void Get(const cef::mojom::RequestParamsPtr& params,
|
2015-12-01 19:22:28 +01:00
|
|
|
blink::WebURLRequest& request);
|
|
|
|
|
2021-05-14 18:58:55 +02:00
|
|
|
// Populate the RequestParams object from this object.
|
2020-09-22 21:54:02 +02:00
|
|
|
// Called from CefFrameHostImpl::LoadRequest().
|
2021-05-14 18:58:55 +02:00
|
|
|
void Get(cef::mojom::RequestParamsPtr& params) const;
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void SetReadOnly(bool read_only);
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
// Enable or disable tracking of changes. If |track_changes| is true the
|
|
|
|
// status of changes will be tracked, and retrievable via GetChanges(). If
|
|
|
|
// |backup_on_change| is true the original value will be backed up before the
|
|
|
|
// first change. The original values can later be restored by calling
|
|
|
|
// RevertChanges() before calling SetTrackChanges(false).
|
|
|
|
void SetTrackChanges(bool track_changes, bool backup_on_change = false);
|
|
|
|
void RevertChanges();
|
|
|
|
void DiscardChanges();
|
2016-01-06 20:20:54 +01:00
|
|
|
uint8_t GetChanges() const;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
static network::mojom::ReferrerPolicy NetReferrerPolicyToBlinkReferrerPolicy(
|
2017-07-27 01:19:27 +02:00
|
|
|
cef_referrer_policy_t net_policy);
|
|
|
|
static cef_referrer_policy_t BlinkReferrerPolicyToNetReferrerPolicy(
|
2018-11-03 02:15:09 +01:00
|
|
|
network::mojom::ReferrerPolicy blink_policy);
|
2017-07-27 01:19:27 +02:00
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
private:
|
2019-04-24 04:50:25 +02:00
|
|
|
// Mark values as changed. Must be called before the new values are assigned.
|
2016-01-06 20:20:54 +01:00
|
|
|
void Changed(uint8_t changes);
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
// Used with the Set() methods that export data to other object types. Returns
|
|
|
|
// true if the values should be set on the export object. If |changed_only| is
|
|
|
|
// true then only return true if the value has been changed in combination
|
|
|
|
// with track changes.
|
2016-01-06 20:20:54 +01:00
|
|
|
bool ShouldSet(uint8_t changes, bool changed_only) const;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
void Reset();
|
|
|
|
|
2016-10-28 20:15:26 +02:00
|
|
|
GURL url_;
|
|
|
|
std::string method_;
|
|
|
|
GURL referrer_url_;
|
2015-12-01 19:22:28 +01:00
|
|
|
ReferrerPolicy referrer_policy_;
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefPostData> postdata_;
|
|
|
|
HeaderMap headermap_;
|
2013-09-10 21:42:53 +02:00
|
|
|
ResourceType resource_type_;
|
|
|
|
TransitionType transition_type_;
|
2023-06-01 16:06:15 +02:00
|
|
|
uint64_t identifier_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// The below members are used by CefURLRequest.
|
|
|
|
int flags_;
|
2020-03-04 01:29:39 +01:00
|
|
|
net::SiteForCookies site_for_cookies_;
|
2019-04-24 04:50:25 +02:00
|
|
|
|
|
|
|
// Stores backup of values for use with track changes.
|
|
|
|
struct Backup {
|
|
|
|
// Bitmask of values that have been backed up.
|
|
|
|
uint8_t backups_ = kChangedNone;
|
|
|
|
|
|
|
|
GURL url_;
|
|
|
|
std::string method_;
|
|
|
|
GURL referrer_url_;
|
|
|
|
ReferrerPolicy referrer_policy_;
|
|
|
|
CefRefPtr<CefPostData> postdata_;
|
|
|
|
std::unique_ptr<HeaderMap> headermap_;
|
|
|
|
int flags_;
|
2020-03-04 01:29:39 +01:00
|
|
|
net::SiteForCookies site_for_cookies_;
|
2019-04-24 04:50:25 +02:00
|
|
|
};
|
|
|
|
std::unique_ptr<Backup> backup_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// True if this object is read-only.
|
2019-04-24 04:50:25 +02:00
|
|
|
bool read_only_ = false;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
// True if this object should track changes.
|
2019-04-24 04:50:25 +02:00
|
|
|
bool track_changes_ = false;
|
|
|
|
|
|
|
|
// True if original values should be backed up when |track_changes_| is true.
|
|
|
|
bool backup_on_change_ = false;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
// Bitmask of |Changes| values which indicate which fields have changed.
|
2019-04-24 04:50:25 +02:00
|
|
|
uint8_t changes_ = kChangedNone;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
mutable base::Lock lock_;
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefRequestImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefPostData
|
|
|
|
class CefPostDataImpl : public CefPostData {
|
|
|
|
public:
|
|
|
|
CefPostDataImpl();
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsReadOnly() override;
|
2015-12-01 19:22:28 +01:00
|
|
|
bool HasExcludedElements() override;
|
2014-11-12 20:25:15 +01:00
|
|
|
size_t GetElementCount() override;
|
|
|
|
void GetElements(ElementVector& elements) override;
|
|
|
|
bool RemoveElement(CefRefPtr<CefPostDataElement> element) override;
|
|
|
|
bool AddElement(CefRefPtr<CefPostDataElement> element) override;
|
|
|
|
void RemoveElements() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void Set(const network::ResourceRequestBody& body);
|
|
|
|
scoped_refptr<network::ResourceRequestBody> GetBody() const;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
void SetReadOnly(bool read_only);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void SetTrackChanges(bool track_changes);
|
|
|
|
bool HasChanges() const;
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
private:
|
2015-11-16 23:20:34 +01:00
|
|
|
void Changed();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
ElementVector elements_;
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// True if this object is read-only.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool read_only_ = false;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
// True if this object has excluded elements.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool has_excluded_elements_ = false;
|
2015-12-01 19:22:28 +01:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
// True if this object should track changes.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool track_changes_ = false;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
// True if this object has changes.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool has_changes_ = false;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
mutable base::Lock lock_;
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefPostDataImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefPostDataElement
|
|
|
|
class CefPostDataElementImpl : public CefPostDataElement {
|
|
|
|
public:
|
|
|
|
CefPostDataElementImpl();
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefPostDataElementImpl() override;
|
|
|
|
|
|
|
|
bool IsReadOnly() override;
|
|
|
|
void SetToEmpty() override;
|
|
|
|
void SetToFile(const CefString& fileName) override;
|
|
|
|
void SetToBytes(size_t size, const void* bytes) override;
|
|
|
|
Type GetType() override;
|
|
|
|
CefString GetFile() override;
|
|
|
|
size_t GetBytesCount() override;
|
|
|
|
size_t GetBytes(size_t size, void* bytes) override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
void* GetBytes() { return data_.bytes.bytes; }
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void Set(const network::DataElement& element);
|
|
|
|
void Get(network::ResourceRequestBody& body) const;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
void SetReadOnly(bool read_only);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
void SetTrackChanges(bool track_changes);
|
|
|
|
bool HasChanges() const;
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
private:
|
2015-11-16 23:20:34 +01:00
|
|
|
void Changed();
|
2012-06-19 18:29:49 +02:00
|
|
|
void Cleanup();
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
Type type_ = PDE_TYPE_EMPTY;
|
2012-04-03 03:34:16 +02:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
void* bytes;
|
|
|
|
size_t size;
|
|
|
|
} bytes;
|
|
|
|
cef_string_t filename;
|
|
|
|
} data_;
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// True if this object is read-only.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool read_only_ = false;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-11-16 23:20:34 +01:00
|
|
|
// True if this object should track changes.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool track_changes_ = false;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
// True if this object has changes.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool has_changes_ = false;
|
2015-11-16 23:20:34 +01:00
|
|
|
|
|
|
|
mutable base::Lock lock_;
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefPostDataElementImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_COMMON_REQUEST_IMPL_H_
|