mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add CefWebURLRequest implementation (issue #51).
- Default new CefRequest objects to the "GET" method. - Send URL and title change notifications for CefFrame::LoadString(). - Disable the RequestTest.HistoryNav test which requires WebKit patches. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@184 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
23
cef.gyp
23
cef.gyp
@ -185,6 +185,7 @@
|
|||||||
'tests/unittests/test_suite.h',
|
'tests/unittests/test_suite.h',
|
||||||
'tests/unittests/url_unittest.cc',
|
'tests/unittests/url_unittest.cc',
|
||||||
'tests/unittests/v8_unittest.cc',
|
'tests/unittests/v8_unittest.cc',
|
||||||
|
'tests/unittests/web_urlrequest_unittest.cc',
|
||||||
'tests/unittests/xml_reader_unittest.cc',
|
'tests/unittests/xml_reader_unittest.cc',
|
||||||
'tests/unittests/zip_reader_unittest.cc',
|
'tests/unittests/zip_reader_unittest.cc',
|
||||||
],
|
],
|
||||||
@ -305,12 +306,16 @@
|
|||||||
'libcef_dll/cpptoc/post_data_element_cpptoc.h',
|
'libcef_dll/cpptoc/post_data_element_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/request_cpptoc.cc',
|
'libcef_dll/cpptoc/request_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/request_cpptoc.h',
|
'libcef_dll/cpptoc/request_cpptoc.h',
|
||||||
|
'libcef_dll/cpptoc/response_cpptoc.cc',
|
||||||
|
'libcef_dll/cpptoc/response_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/stream_reader_cpptoc.cc',
|
'libcef_dll/cpptoc/stream_reader_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/stream_reader_cpptoc.h',
|
'libcef_dll/cpptoc/stream_reader_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/stream_writer_cpptoc.cc',
|
'libcef_dll/cpptoc/stream_writer_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/stream_writer_cpptoc.h',
|
'libcef_dll/cpptoc/stream_writer_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/v8value_cpptoc.cc',
|
'libcef_dll/cpptoc/v8value_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/v8value_cpptoc.h',
|
'libcef_dll/cpptoc/v8value_cpptoc.h',
|
||||||
|
'libcef_dll/cpptoc/web_urlrequest_cpptoc.cc',
|
||||||
|
'libcef_dll/cpptoc/web_urlrequest_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/xml_reader_cpptoc.cc',
|
'libcef_dll/cpptoc/xml_reader_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/xml_reader_cpptoc.h',
|
'libcef_dll/cpptoc/xml_reader_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/zip_reader_cpptoc.cc',
|
'libcef_dll/cpptoc/zip_reader_cpptoc.cc',
|
||||||
@ -330,6 +335,8 @@
|
|||||||
'libcef_dll/ctocpp/task_ctocpp.h',
|
'libcef_dll/ctocpp/task_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/v8handler_ctocpp.cc',
|
'libcef_dll/ctocpp/v8handler_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/v8handler_ctocpp.h',
|
'libcef_dll/ctocpp/v8handler_ctocpp.h',
|
||||||
|
'libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc',
|
||||||
|
'libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/write_handler_ctocpp.cc',
|
'libcef_dll/ctocpp/write_handler_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/write_handler_ctocpp.h',
|
'libcef_dll/ctocpp/write_handler_ctocpp.h',
|
||||||
'libcef_dll/libcef_dll.cc',
|
'libcef_dll/libcef_dll.cc',
|
||||||
@ -387,8 +394,12 @@
|
|||||||
'libcef_dll/cpptoc/scheme_handler_cpptoc.h',
|
'libcef_dll/cpptoc/scheme_handler_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc',
|
'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h',
|
'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h',
|
||||||
|
'libcef_dll/cpptoc/task_cpptoc.cc',
|
||||||
|
'libcef_dll/cpptoc/task_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/v8handler_cpptoc.cc',
|
'libcef_dll/cpptoc/v8handler_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/v8handler_cpptoc.h',
|
'libcef_dll/cpptoc/v8handler_cpptoc.h',
|
||||||
|
'libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc',
|
||||||
|
'libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h',
|
||||||
'libcef_dll/cpptoc/write_handler_cpptoc.cc',
|
'libcef_dll/cpptoc/write_handler_cpptoc.cc',
|
||||||
'libcef_dll/cpptoc/write_handler_cpptoc.h',
|
'libcef_dll/cpptoc/write_handler_cpptoc.h',
|
||||||
'libcef_dll/ctocpp/browser_ctocpp.cc',
|
'libcef_dll/ctocpp/browser_ctocpp.cc',
|
||||||
@ -402,14 +413,16 @@
|
|||||||
'libcef_dll/ctocpp/post_data_element_ctocpp.h',
|
'libcef_dll/ctocpp/post_data_element_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/request_ctocpp.cc',
|
'libcef_dll/ctocpp/request_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/request_ctocpp.h',
|
'libcef_dll/ctocpp/request_ctocpp.h',
|
||||||
|
'libcef_dll/ctocpp/response_ctocpp.cc',
|
||||||
|
'libcef_dll/ctocpp/response_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/stream_reader_ctocpp.cc',
|
'libcef_dll/ctocpp/stream_reader_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/stream_reader_ctocpp.h',
|
'libcef_dll/ctocpp/stream_reader_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/stream_writer_ctocpp.cc',
|
'libcef_dll/ctocpp/stream_writer_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/stream_writer_ctocpp.h',
|
'libcef_dll/ctocpp/stream_writer_ctocpp.h',
|
||||||
'libcef_dll/cpptoc/task_cpptoc.cc',
|
|
||||||
'libcef_dll/cpptoc/task_cpptoc.h',
|
|
||||||
'libcef_dll/ctocpp/v8value_ctocpp.cc',
|
'libcef_dll/ctocpp/v8value_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/v8value_ctocpp.h',
|
'libcef_dll/ctocpp/v8value_ctocpp.h',
|
||||||
|
'libcef_dll/ctocpp/web_urlrequest_ctocpp.cc',
|
||||||
|
'libcef_dll/ctocpp/web_urlrequest_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/xml_reader_ctocpp.cc',
|
'libcef_dll/ctocpp/xml_reader_ctocpp.cc',
|
||||||
'libcef_dll/ctocpp/xml_reader_ctocpp.h',
|
'libcef_dll/ctocpp/xml_reader_ctocpp.h',
|
||||||
'libcef_dll/ctocpp/zip_reader_ctocpp.cc',
|
'libcef_dll/ctocpp/zip_reader_ctocpp.cc',
|
||||||
@ -544,8 +557,12 @@
|
|||||||
'libcef/dom_storage_namespace.cc',
|
'libcef/dom_storage_namespace.cc',
|
||||||
'libcef/dom_storage_namespace.h',
|
'libcef/dom_storage_namespace.h',
|
||||||
'libcef/external_protocol_handler.h',
|
'libcef/external_protocol_handler.h',
|
||||||
|
'libcef/http_header_utils.cc',
|
||||||
|
'libcef/http_header_utils.h',
|
||||||
'libcef/request_impl.cc',
|
'libcef/request_impl.cc',
|
||||||
'libcef/request_impl.h',
|
'libcef/request_impl.h',
|
||||||
|
'libcef/response_impl.cc',
|
||||||
|
'libcef/response_impl.h',
|
||||||
'libcef/scheme_impl.cc',
|
'libcef/scheme_impl.cc',
|
||||||
'libcef/simple_clipboard_impl.cc',
|
'libcef/simple_clipboard_impl.cc',
|
||||||
'libcef/stream_impl.cc',
|
'libcef/stream_impl.cc',
|
||||||
@ -553,6 +570,8 @@
|
|||||||
'libcef/tracker.h',
|
'libcef/tracker.h',
|
||||||
'libcef/v8_impl.cc',
|
'libcef/v8_impl.cc',
|
||||||
'libcef/v8_impl.h',
|
'libcef/v8_impl.h',
|
||||||
|
'libcef/web_urlrequest_impl.cc',
|
||||||
|
'libcef/web_urlrequest_impl.h',
|
||||||
'libcef/webview_host.h',
|
'libcef/webview_host.h',
|
||||||
'libcef/webwidget_host.h',
|
'libcef/webwidget_host.h',
|
||||||
'libcef/xml_reader_impl.cc',
|
'libcef/xml_reader_impl.cc',
|
||||||
|
115
include/cef.h
115
include/cef.h
@ -53,6 +53,7 @@ class CefPopupFeatures;
|
|||||||
class CefPostData;
|
class CefPostData;
|
||||||
class CefPostDataElement;
|
class CefPostDataElement;
|
||||||
class CefRequest;
|
class CefRequest;
|
||||||
|
class CefResponse;
|
||||||
class CefSchemeHandler;
|
class CefSchemeHandler;
|
||||||
class CefSchemeHandlerFactory;
|
class CefSchemeHandlerFactory;
|
||||||
class CefSettings;
|
class CefSettings;
|
||||||
@ -62,6 +63,8 @@ class CefTask;
|
|||||||
class CefURLParts;
|
class CefURLParts;
|
||||||
class CefV8Handler;
|
class CefV8Handler;
|
||||||
class CefV8Value;
|
class CefV8Value;
|
||||||
|
class CefWebURLRequest;
|
||||||
|
class CefWebURLRequestClient;
|
||||||
|
|
||||||
|
|
||||||
// This function should be called on the main application thread to initialize
|
// This function should be called on the main application thread to initialize
|
||||||
@ -911,6 +914,7 @@ class CefRequest : public CefBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::map<CefString,CefString> HeaderMap;
|
typedef std::map<CefString,CefString> HeaderMap;
|
||||||
|
typedef cef_weburlrequest_flags_t RequestFlags;
|
||||||
|
|
||||||
// Create a new CefRequest object.
|
// Create a new CefRequest object.
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
@ -947,6 +951,19 @@ public:
|
|||||||
const CefString& method,
|
const CefString& method,
|
||||||
CefRefPtr<CefPostData> postData,
|
CefRefPtr<CefPostData> postData,
|
||||||
const HeaderMap& headerMap) =0;
|
const HeaderMap& headerMap) =0;
|
||||||
|
|
||||||
|
// Optional flags. Used in combination with CefWebURLRequest.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual RequestFlags GetFlags() = 0;
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void SetFlags(RequestFlags flags) = 0;
|
||||||
|
|
||||||
|
// Optional URL to the first party for cookies. Used in combination with
|
||||||
|
// CefWebURLRequest.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual CefString GetFirstPartyForCookies() = 0;
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void SetFirstPartyForCookies(const CefString& url) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1030,6 +1047,32 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Class used to represent a web response. The methods of this class may be
|
||||||
|
// called on any thread.
|
||||||
|
/*--cef(source=library)--*/
|
||||||
|
class CefResponse : public CefBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::map<CefString,CefString> HeaderMap;
|
||||||
|
|
||||||
|
// Returns the response status code.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual int GetStatus() = 0;
|
||||||
|
|
||||||
|
// Returns the response status text.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual CefString GetStatusText() = 0;
|
||||||
|
|
||||||
|
// Returns the value for the specified response header field.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual CefString GetHeader(const CefString& name) = 0;
|
||||||
|
|
||||||
|
// Retrieves a map of all response header fields.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void GetHeaderMap(HeaderMap& headerMap) =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Interface the client can implement to provide a custom stream reader. The
|
// Interface the client can implement to provide a custom stream reader. The
|
||||||
// methods of this class may be called on any thread.
|
// methods of this class may be called on any thread.
|
||||||
/*--cef(source=client)--*/
|
/*--cef(source=client)--*/
|
||||||
@ -1355,6 +1398,78 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Class used to make a Web URL request. Web URL requests are not associated
|
||||||
|
// with a browser instance so no CefHandler callbacks will be executed. The
|
||||||
|
// methods of this class may be called on any thread.
|
||||||
|
/*--cef(source=library)--*/
|
||||||
|
class CefWebURLRequest : public CefBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef cef_weburlrequest_state_t RequestState;
|
||||||
|
|
||||||
|
// Create a new CefWebUrlReqeust object.
|
||||||
|
/*--cef()--*/
|
||||||
|
static CefRefPtr<CefWebURLRequest> CreateWebURLRequest(
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefWebURLRequestClient> client);
|
||||||
|
|
||||||
|
// Cancels the request.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void Cancel() =0;
|
||||||
|
|
||||||
|
// Returns the current ready state of the request.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual RequestState GetState() =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Interface that should be implemented by the CefWebURLRequest client. The
|
||||||
|
// methods of this class will always be called on the UI thread.
|
||||||
|
/*--cef(source=client)--*/
|
||||||
|
class CefWebURLRequestClient : public CefBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef cef_weburlrequest_state_t RequestState;
|
||||||
|
|
||||||
|
// Notifies the client that the request state has changed. State change
|
||||||
|
// notifications will always be sent before the below notification methods
|
||||||
|
// are called.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
RequestState state) =0;
|
||||||
|
|
||||||
|
// Notifies the client that the request has been redirected and provides a
|
||||||
|
// chance to change the request parameters.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefResponse> response) =0;
|
||||||
|
|
||||||
|
// Notifies the client of the response data.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefResponse> response) =0;
|
||||||
|
|
||||||
|
// Notifies the client of the upload progress.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
uint64 bytesSent, uint64 totalBytesToBeSent) =0;
|
||||||
|
|
||||||
|
// Notifies the client that content has been received.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
const void* data, int dataLength) =0;
|
||||||
|
|
||||||
|
// Supported error code values. See net\base\net_error_list.h for complete
|
||||||
|
// descriptions of the error codes.
|
||||||
|
typedef cef_handler_errorcode_t ErrorCode;
|
||||||
|
|
||||||
|
// Notifies the client that the request ended with an error.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
ErrorCode errorCode) =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Class that supports the reading of XML data via the libxml streaming API.
|
// Class that supports the reading of XML data via the libxml streaming API.
|
||||||
// The methods of this class should only be called on the thread that creates
|
// The methods of this class should only be called on the thread that creates
|
||||||
// the object.
|
// the object.
|
||||||
|
@ -709,6 +709,20 @@ typedef struct _cef_request_t
|
|||||||
const cef_string_t* method, struct _cef_post_data_t* postData,
|
const cef_string_t* method, struct _cef_post_data_t* postData,
|
||||||
cef_string_map_t headerMap);
|
cef_string_map_t headerMap);
|
||||||
|
|
||||||
|
// Optional flags. Used in combination with cef_web_urlrequest_t.
|
||||||
|
enum cef_weburlrequest_flags_t (CEF_CALLBACK *get_flags)(
|
||||||
|
struct _cef_request_t* self);
|
||||||
|
void (CEF_CALLBACK *set_flags)(struct _cef_request_t* self,
|
||||||
|
enum cef_weburlrequest_flags_t flags);
|
||||||
|
|
||||||
|
// Optional URL to the first party for cookies. Used in combination with
|
||||||
|
// cef_web_urlrequest_t.
|
||||||
|
// The resulting string must be freed by calling cef_string_userfree_free().
|
||||||
|
cef_string_userfree_t (CEF_CALLBACK *get_first_party_for_cookies)(
|
||||||
|
struct _cef_request_t* self);
|
||||||
|
void (CEF_CALLBACK *set_first_party_for_cookies)(struct _cef_request_t* self,
|
||||||
|
const cef_string_t* url);
|
||||||
|
|
||||||
} cef_request_t;
|
} cef_request_t;
|
||||||
|
|
||||||
|
|
||||||
@ -792,6 +806,33 @@ typedef struct _cef_post_data_element_t
|
|||||||
CEF_EXPORT cef_post_data_element_t* cef_post_data_element_create();
|
CEF_EXPORT cef_post_data_element_t* cef_post_data_element_create();
|
||||||
|
|
||||||
|
|
||||||
|
// Structure used to represent a web response. The functions of this structure
|
||||||
|
// may be called on any thread.
|
||||||
|
typedef struct _cef_response_t
|
||||||
|
{
|
||||||
|
// Base structure.
|
||||||
|
cef_base_t base;
|
||||||
|
|
||||||
|
// Returns the response status code.
|
||||||
|
int (CEF_CALLBACK *get_status)(struct _cef_response_t* self);
|
||||||
|
|
||||||
|
// Returns the response status text.
|
||||||
|
// The resulting string must be freed by calling cef_string_userfree_free().
|
||||||
|
cef_string_userfree_t (CEF_CALLBACK *get_status_text)(
|
||||||
|
struct _cef_response_t* self);
|
||||||
|
|
||||||
|
// Returns the value for the specified response header field.
|
||||||
|
// The resulting string must be freed by calling cef_string_userfree_free().
|
||||||
|
cef_string_userfree_t (CEF_CALLBACK *get_header)(struct _cef_response_t* self,
|
||||||
|
const cef_string_t* name);
|
||||||
|
|
||||||
|
// Retrieves a map of all response header fields.
|
||||||
|
void (CEF_CALLBACK *get_header_map)(struct _cef_response_t* self,
|
||||||
|
cef_string_map_t headerMap);
|
||||||
|
|
||||||
|
} cef_response_t;
|
||||||
|
|
||||||
|
|
||||||
// Structure the client can implement to provide a custom stream reader. The
|
// Structure the client can implement to provide a custom stream reader. The
|
||||||
// functions of this structure may be called on any thread.
|
// functions of this structure may be called on any thread.
|
||||||
typedef struct _cef_read_handler_t
|
typedef struct _cef_read_handler_t
|
||||||
@ -1098,6 +1139,74 @@ typedef struct _cef_download_handler_t
|
|||||||
} cef_download_handler_t;
|
} cef_download_handler_t;
|
||||||
|
|
||||||
|
|
||||||
|
// Structure used to make a Web URL request. Web URL requests are not associated
|
||||||
|
// with a browser instance so no cef_handler_t callbacks will be executed. The
|
||||||
|
// functions of this structure may be called on any thread.
|
||||||
|
typedef struct _cef_web_urlrequest_t
|
||||||
|
{
|
||||||
|
// Base structure.
|
||||||
|
cef_base_t base;
|
||||||
|
|
||||||
|
// Cancels the request.
|
||||||
|
void (CEF_CALLBACK *cancel)(struct _cef_web_urlrequest_t* self);
|
||||||
|
|
||||||
|
// Returns the current ready state of the request.
|
||||||
|
enum cef_weburlrequest_state_t (CEF_CALLBACK *get_state)(
|
||||||
|
struct _cef_web_urlrequest_t* self);
|
||||||
|
|
||||||
|
} cef_web_urlrequest_t;
|
||||||
|
|
||||||
|
|
||||||
|
// Create a new CefWebUrlReqeust object.
|
||||||
|
CEF_EXPORT cef_web_urlrequest_t* cef_web_urlrequest_create(
|
||||||
|
cef_request_t* request, struct _cef_web_urlrequest_client_t* client);
|
||||||
|
|
||||||
|
|
||||||
|
// Structure that should be implemented by the cef_web_urlrequest_t client. The
|
||||||
|
// functions of this structure will always be called on the UI thread.
|
||||||
|
typedef struct _cef_web_urlrequest_client_t
|
||||||
|
{
|
||||||
|
// Base structure.
|
||||||
|
cef_base_t base;
|
||||||
|
|
||||||
|
// Notifies the client that the request state has changed. State change
|
||||||
|
// notifications will always be sent before the below notification functions
|
||||||
|
// are called.
|
||||||
|
void (CEF_CALLBACK *on_state_change)(
|
||||||
|
struct _cef_web_urlrequest_client_t* self,
|
||||||
|
struct _cef_web_urlrequest_t* requester,
|
||||||
|
enum cef_weburlrequest_state_t state);
|
||||||
|
|
||||||
|
// Notifies the client that the request has been redirected and provides a
|
||||||
|
// chance to change the request parameters.
|
||||||
|
void (CEF_CALLBACK *on_redirect)(struct _cef_web_urlrequest_client_t* self,
|
||||||
|
struct _cef_web_urlrequest_t* requester, struct _cef_request_t* request,
|
||||||
|
struct _cef_response_t* response);
|
||||||
|
|
||||||
|
// Notifies the client of the response data.
|
||||||
|
void (CEF_CALLBACK *on_headers_received)(
|
||||||
|
struct _cef_web_urlrequest_client_t* self,
|
||||||
|
struct _cef_web_urlrequest_t* requester,
|
||||||
|
struct _cef_response_t* response);
|
||||||
|
|
||||||
|
// Notifies the client of the upload progress.
|
||||||
|
void (CEF_CALLBACK *on_progress)(struct _cef_web_urlrequest_client_t* self,
|
||||||
|
struct _cef_web_urlrequest_t* requester, uint64 bytesSent,
|
||||||
|
uint64 totalBytesToBeSent);
|
||||||
|
|
||||||
|
// Notifies the client that content has been received.
|
||||||
|
void (CEF_CALLBACK *on_data)(struct _cef_web_urlrequest_client_t* self,
|
||||||
|
struct _cef_web_urlrequest_t* requester, const void* data,
|
||||||
|
int dataLength);
|
||||||
|
|
||||||
|
// Notifies the client that the request ended with an error.
|
||||||
|
void (CEF_CALLBACK *on_error)(struct _cef_web_urlrequest_client_t* self,
|
||||||
|
struct _cef_web_urlrequest_t* requester,
|
||||||
|
enum cef_handler_errorcode_t errorCode);
|
||||||
|
|
||||||
|
} cef_web_urlrequest_client_t;
|
||||||
|
|
||||||
|
|
||||||
// Structure that supports the reading of XML data via the libxml streaming API.
|
// Structure that supports the reading of XML data via the libxml streaming API.
|
||||||
// The functions of this structure should only be called on the thread that
|
// The functions of this structure should only be called on the thread that
|
||||||
// creates the object.
|
// creates the object.
|
||||||
|
@ -46,8 +46,10 @@
|
|||||||
// not have typedef mismatches, we do the same on LP64.
|
// not have typedef mismatches, we do the same on LP64.
|
||||||
#if __LP64__
|
#if __LP64__
|
||||||
typedef long int64;
|
typedef long int64;
|
||||||
|
typedef unsigned long uint64;
|
||||||
#else
|
#else
|
||||||
typedef long long int64;
|
typedef long long int64;
|
||||||
|
typedef unsigned long long uint64;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -431,6 +433,28 @@ enum cef_postdataelement_type_t
|
|||||||
PDE_TYPE_FILE,
|
PDE_TYPE_FILE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum cef_weburlrequest_flags_t
|
||||||
|
{
|
||||||
|
WUR_FLAG_NONE = 0,
|
||||||
|
WUR_FLAG_SKIP_CACHE = 0x1,
|
||||||
|
WUR_FLAG_ALLOW_CACHED_CREDENTIALS = 0x2,
|
||||||
|
WUR_FLAG_ALLOW_COOKIES = 0x4,
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS = 0x8,
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING = 0x10,
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS = 0x20
|
||||||
|
};
|
||||||
|
|
||||||
|
enum cef_weburlrequest_state_t
|
||||||
|
{
|
||||||
|
WUR_STATE_UNSENT = 0,
|
||||||
|
WUR_STATE_STARTED = 1,
|
||||||
|
WUR_STATE_HEADERS_RECEIVED = 2,
|
||||||
|
WUR_STATE_LOADING = 3,
|
||||||
|
WUR_STATE_DONE = 4,
|
||||||
|
WUR_STATE_ERROR = 5,
|
||||||
|
WUR_STATE_ABORT = 6,
|
||||||
|
};
|
||||||
|
|
||||||
// Key event types.
|
// Key event types.
|
||||||
enum cef_handler_keyevent_type_t
|
enum cef_handler_keyevent_type_t
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "cef_process_io_thread.h"
|
#include "cef_process_io_thread.h"
|
||||||
#include "external_protocol_handler.h"
|
#include "external_protocol_handler.h"
|
||||||
#include "request_impl.h"
|
#include "request_impl.h"
|
||||||
|
#include "http_header_utils.h"
|
||||||
|
|
||||||
#include "base/file_path.h"
|
#include "base/file_path.h"
|
||||||
#include "base/file_util.h"
|
#include "base/file_util.h"
|
||||||
@ -294,7 +295,7 @@ class RequestProxy : public net::URLRequest::Delegate,
|
|||||||
|
|
||||||
// Transfer request headers
|
// Transfer request headers
|
||||||
CefRequest::HeaderMap headerMap;
|
CefRequest::HeaderMap headerMap;
|
||||||
CefRequestImpl::ParseHeaders(params->headers, headerMap);
|
HttpHeaderUtils::ParseHeaders(params->headers, headerMap);
|
||||||
headerMap.insert(std::make_pair("Referrer", params->referrer.spec()));
|
headerMap.insert(std::make_pair("Referrer", params->referrer.spec()));
|
||||||
requestimpl->SetHeaderMap(headerMap);
|
requestimpl->SetHeaderMap(headerMap);
|
||||||
|
|
||||||
@ -338,7 +339,7 @@ class RequestProxy : public net::URLRequest::Delegate,
|
|||||||
params->referrer = GURL(std::string(referrer->second));
|
params->referrer = GURL(std::string(referrer->second));
|
||||||
headerMap.erase(referrer);
|
headerMap.erase(referrer);
|
||||||
}
|
}
|
||||||
params->headers = CefRequestImpl::GenerateHeaders(headerMap);
|
params->headers = HttpHeaderUtils::GenerateHeaders(headerMap);
|
||||||
|
|
||||||
// Observe post data from request.
|
// Observe post data from request.
|
||||||
CefRefPtr<CefPostData> postData = request->GetPostData();
|
CefRefPtr<CefPostData> postData = request->GetPostData();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "third_party/WebKit/Source/WebCore/config.h"
|
#include "third_party/WebKit/Source/WebCore/config.h"
|
||||||
MSVC_PUSH_WARNING_LEVEL(0);
|
MSVC_PUSH_WARNING_LEVEL(0);
|
||||||
|
#include "DocumentLoader.h"
|
||||||
#include "MemoryCache.h"
|
#include "MemoryCache.h"
|
||||||
#include "TextEncoding.h"
|
#include "TextEncoding.h"
|
||||||
#include "third_party/WebKit/WebKit/chromium/src/WebFrameImpl.h"
|
#include "third_party/WebKit/WebKit/chromium/src/WebFrameImpl.h"
|
||||||
@ -121,6 +122,14 @@ FrameLoadType GetFrameLoadType(WebKit::WebFrame* frame)
|
|||||||
return FLT_UNKNOWN;
|
return FLT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FrameHasSubsituteData(WebKit::WebFrame* frame)
|
||||||
|
{
|
||||||
|
WebFrameImpl* webFrameImpl = static_cast<WebFrameImpl*>(frame);
|
||||||
|
WebCore::DocumentLoader* docLoader =
|
||||||
|
webFrameImpl->frame()->loader()->documentLoader();
|
||||||
|
return docLoader->substituteData().isValid();
|
||||||
|
}
|
||||||
|
|
||||||
void CloseIdleConnections() {
|
void CloseIdleConnections() {
|
||||||
// Used in benchmarking, Ignored for CEF.
|
// Used in benchmarking, Ignored for CEF.
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,9 @@ enum FrameLoadType {
|
|||||||
// Returns the frame load type.
|
// Returns the frame load type.
|
||||||
FrameLoadType GetFrameLoadType(WebKit::WebFrame* frame);
|
FrameLoadType GetFrameLoadType(WebKit::WebFrame* frame);
|
||||||
|
|
||||||
|
// Returns true if the frame is loading substitute data.
|
||||||
|
bool FrameHasSubsituteData(WebKit::WebFrame* frame);
|
||||||
|
|
||||||
// Clear all cached data.
|
// Clear all cached data.
|
||||||
void ClearCache();
|
void ClearCache();
|
||||||
|
|
||||||
|
@ -717,6 +717,9 @@ void BrowserWebViewDelegate::didCommitProvisionalLoad(
|
|||||||
if (is_new_navigation) {
|
if (is_new_navigation) {
|
||||||
// New navigations will be the main content.
|
// New navigations will be the main content.
|
||||||
is_main_content_ = true;
|
is_main_content_ = true;
|
||||||
|
} else if(webkit_glue::FrameHasSubsituteData(frame)) {
|
||||||
|
// Loading from a string will be main content.
|
||||||
|
is_main_content_ = true;
|
||||||
} else {
|
} else {
|
||||||
// Session history navigations and reloads will be the main content.
|
// Session history navigations and reloads will be the main content.
|
||||||
webkit_glue::FrameLoadType load_type =
|
webkit_glue::FrameLoadType load_type =
|
||||||
|
51
libcef/http_header_utils.cc
Normal file
51
libcef/http_header_utils.cc
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright (c) 2011 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.
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "http_header_utils.h"
|
||||||
|
#include "net/http/http_response_headers.h"
|
||||||
|
#include "net/http/http_util.h"
|
||||||
|
|
||||||
|
using net::HttpResponseHeaders;
|
||||||
|
|
||||||
|
namespace HttpHeaderUtils {
|
||||||
|
|
||||||
|
std::string GenerateHeaders(const HeaderMap& map)
|
||||||
|
{
|
||||||
|
std::string headers;
|
||||||
|
|
||||||
|
for(HeaderMap::const_iterator header = map.begin();
|
||||||
|
header != map.end();
|
||||||
|
++header) {
|
||||||
|
const CefString& key = header->first;
|
||||||
|
const CefString& value = header->second;
|
||||||
|
|
||||||
|
if(!key.empty()) {
|
||||||
|
// Delimit with "\r\n".
|
||||||
|
if(!headers.empty())
|
||||||
|
headers += "\r\n";
|
||||||
|
|
||||||
|
headers += std::string(key) + ": " + std::string(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParseHeaders(const std::string& header_str,
|
||||||
|
HeaderMap& map)
|
||||||
|
{
|
||||||
|
// Parse the request header values
|
||||||
|
std::string headerStr = "HTTP/1.1 200 OK\n";
|
||||||
|
headerStr += header_str;
|
||||||
|
scoped_refptr<net::HttpResponseHeaders> headers =
|
||||||
|
new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
|
||||||
|
headerStr.c_str(), headerStr.length()));
|
||||||
|
void* iter = NULL;
|
||||||
|
std::string name, value;
|
||||||
|
while(headers->EnumerateHeaderLines(&iter, &name, &value))
|
||||||
|
map.insert(std::make_pair(name, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace HttpHeaderUtils
|
35
libcef/http_header_utils.h
Normal file
35
libcef/http_header_utils.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2011 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 _HTTP_HEADER_UTILS_H
|
||||||
|
#define _HTTP_HEADER_UTILS_H
|
||||||
|
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
|
||||||
|
|
||||||
|
namespace HttpHeaderUtils {
|
||||||
|
|
||||||
|
typedef CefRequest::HeaderMap HeaderMap;
|
||||||
|
|
||||||
|
class HeaderVisitor : public WebKit::WebHTTPHeaderVisitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HeaderVisitor(HeaderMap* map) : map_(map) {}
|
||||||
|
|
||||||
|
virtual void visitHeader(const WebKit::WebString& name,
|
||||||
|
const WebKit::WebString& value)
|
||||||
|
{
|
||||||
|
map_->insert(std::make_pair(string16(name), string16(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
HeaderMap* map_;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string GenerateHeaders(const HeaderMap& map);
|
||||||
|
void ParseHeaders(const std::string& header_str, HeaderMap& map);
|
||||||
|
|
||||||
|
}; // namespace HttpHeaderUtils
|
||||||
|
|
||||||
|
#endif // _HTTP_HEADER_UTILS_H
|
@ -6,13 +6,13 @@
|
|||||||
#include "browser_webkit_glue.h"
|
#include "browser_webkit_glue.h"
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "net/http/http_response_headers.h"
|
|
||||||
#include "net/http/http_util.h"
|
|
||||||
#include "net/url_request/url_request.h"
|
#include "net/url_request/url_request.h"
|
||||||
#include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h"
|
#include "http_header_utils.h"
|
||||||
|
|
||||||
using net::HttpResponseHeaders;
|
|
||||||
|
|
||||||
|
using WebKit::WebHTTPBody;
|
||||||
|
using WebKit::WebString;
|
||||||
|
using WebKit::WebURL;
|
||||||
|
using WebKit::WebURLRequest;
|
||||||
|
|
||||||
CefRefPtr<CefRequest> CefRequest::CreateRequest()
|
CefRefPtr<CefRequest> CefRequest::CreateRequest()
|
||||||
{
|
{
|
||||||
@ -21,66 +21,56 @@ CefRefPtr<CefRequest> CefRequest::CreateRequest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
CefRequestImpl::CefRequestImpl()
|
CefRequestImpl::CefRequestImpl()
|
||||||
|
: method_("GET"), flags_(WUR_FLAG_NONE)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CefString CefRequestImpl::GetURL()
|
CefString CefRequestImpl::GetURL()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
CefString url = url_;
|
return url_;
|
||||||
Unlock();
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::SetURL(const CefString& url)
|
void CefRequestImpl::SetURL(const CefString& url)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
url_ = url;
|
url_ = url;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefString CefRequestImpl::GetMethod()
|
CefString CefRequestImpl::GetMethod()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
CefString method = method_;
|
return method_;
|
||||||
Unlock();
|
|
||||||
return method;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::SetMethod(const CefString& method)
|
void CefRequestImpl::SetMethod(const CefString& method)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
method_ = method;
|
method_ = method;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefRefPtr<CefPostData> CefRequestImpl::GetPostData()
|
CefRefPtr<CefPostData> CefRequestImpl::GetPostData()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
CefRefPtr<CefPostData> postData = postdata_;
|
return postdata_;
|
||||||
Unlock();
|
|
||||||
return postData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::SetPostData(CefRefPtr<CefPostData> postData)
|
void CefRequestImpl::SetPostData(CefRefPtr<CefPostData> postData)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
postdata_ = postData;
|
postdata_ = postData;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::GetHeaderMap(HeaderMap& headerMap)
|
void CefRequestImpl::GetHeaderMap(HeaderMap& headerMap)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
headerMap = headermap_;
|
headerMap = headermap_;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap)
|
void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
headermap_ = headerMap;
|
headermap_ = headerMap;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::Set(const CefString& url,
|
void CefRequestImpl::Set(const CefString& url,
|
||||||
@ -88,36 +78,141 @@ void CefRequestImpl::Set(const CefString& url,
|
|||||||
CefRefPtr<CefPostData> postData,
|
CefRefPtr<CefPostData> postData,
|
||||||
const HeaderMap& headerMap)
|
const HeaderMap& headerMap)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
url_ = url;
|
url_ = url;
|
||||||
method_ = method;
|
method_ = method;
|
||||||
postdata_ = postData;
|
postdata_ = postData;
|
||||||
headermap_ = headerMap;
|
headermap_ = headerMap;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestImpl::Set(net::URLRequest* request)
|
void CefRequestImpl::Set(net::URLRequest* request)
|
||||||
{
|
{
|
||||||
SetURL(request->url().spec());
|
AutoLock lock_scope(this);
|
||||||
SetMethod(request->method());
|
|
||||||
|
url_ = request->url().spec();
|
||||||
|
method_ = request->method();
|
||||||
|
|
||||||
// Transfer request headers
|
// Transfer request headers
|
||||||
HeaderMap headerMap;
|
GetHeaderMap(request->extra_request_headers(), headermap_);
|
||||||
GetHeaderMap(request->extra_request_headers(), headerMap);
|
headermap_.insert(std::make_pair(L"Referrer", request->referrer()));
|
||||||
headerMap.insert(std::make_pair(L"Referrer", request->referrer()));
|
|
||||||
SetHeaderMap(headerMap);
|
|
||||||
|
|
||||||
// Transfer post data, if any
|
// Transfer post data, if any
|
||||||
net::UploadData* data = request->get_upload();
|
net::UploadData* data = request->get_upload();
|
||||||
if (data) {
|
if (data) {
|
||||||
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
|
postdata_ = CefPostData::CreatePostData();
|
||||||
static_cast<CefPostDataImpl*>(postdata.get())->Set(*data);
|
static_cast<CefPostDataImpl*>(postdata_.get())->Set(*data);
|
||||||
SetPostData(postdata);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CefRequestImpl::Set(const WebKit::WebURLRequest& request)
|
||||||
|
{
|
||||||
|
DCHECK(!request.isNull());
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers, HeaderMap& map)
|
url_ = request.url().spec().utf16();
|
||||||
|
method_ = request.httpMethod();
|
||||||
|
|
||||||
|
WebHTTPBody& body = request.httpBody();
|
||||||
|
if (!body.isNull()) {
|
||||||
|
postdata_ = new CefPostDataImpl();
|
||||||
|
static_cast<CefPostDataImpl*>(postdata_.get())->Set(body);
|
||||||
|
} else if(postdata_.get()) {
|
||||||
|
postdata_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
headermap_.clear();
|
||||||
|
GetHeaderMap(request, headermap_);
|
||||||
|
|
||||||
|
int flags = WUR_FLAG_NONE;
|
||||||
|
if (request.cachePolicy() == WebURLRequest::ReloadIgnoringCacheData)
|
||||||
|
flags |= WUR_FLAG_SKIP_CACHE;
|
||||||
|
if (request.allowStoredCredentials())
|
||||||
|
flags |= WUR_FLAG_ALLOW_CACHED_CREDENTIALS;
|
||||||
|
if (request.allowCookies())
|
||||||
|
flags |= WUR_FLAG_ALLOW_COOKIES;
|
||||||
|
if (request.reportUploadProgress())
|
||||||
|
flags |= WUR_FLAG_REPORT_UPLOAD_PROGRESS;
|
||||||
|
if (request.reportLoadTiming())
|
||||||
|
flags |= WUR_FLAG_REPORT_LOAD_TIMING;
|
||||||
|
if (request.reportRawHeaders())
|
||||||
|
flags |= WUR_FLAG_REPORT_RAW_HEADERS;
|
||||||
|
flags_ = static_cast<cef_weburlrequest_flags_t>(flags);
|
||||||
|
|
||||||
|
first_party_for_cookies_ = request.firstPartyForCookies().spec().utf16();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SETBOOLFLAG(obj, flags, method, FLAG) \
|
||||||
|
obj.method((flags & (FLAG)) == (FLAG))
|
||||||
|
|
||||||
|
void CefRequestImpl::Get(WebKit::WebURLRequest& request)
|
||||||
|
{
|
||||||
|
request.initialize();
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
|
std::string urlStr(url_);
|
||||||
|
GURL gurl = GURL(urlStr);
|
||||||
|
request.setURL(WebURL(gurl));
|
||||||
|
|
||||||
|
std::string method(method_);
|
||||||
|
request.setHTTPMethod(WebString::fromUTF8(method.c_str()));
|
||||||
|
request.setTargetType(WebURLRequest::TargetIsMainFrame);
|
||||||
|
|
||||||
|
WebHTTPBody body;
|
||||||
|
if (postdata_.get()) {
|
||||||
|
body.initialize();
|
||||||
|
static_cast<CefPostDataImpl*>(postdata_.get())->Get(body);
|
||||||
|
request.setHTTPBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetHeaderMap(headermap_, request);
|
||||||
|
|
||||||
|
request.setCachePolicy((flags_ & WUR_FLAG_SKIP_CACHE) ?
|
||||||
|
WebURLRequest::ReloadIgnoringCacheData :
|
||||||
|
WebURLRequest::UseProtocolCachePolicy);
|
||||||
|
|
||||||
|
SETBOOLFLAG(request, flags_, setAllowStoredCredentials,
|
||||||
|
WUR_FLAG_ALLOW_CACHED_CREDENTIALS);
|
||||||
|
SETBOOLFLAG(request, flags_, setAllowCookies,
|
||||||
|
WUR_FLAG_ALLOW_COOKIES);
|
||||||
|
SETBOOLFLAG(request, flags_, setReportUploadProgress,
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS);
|
||||||
|
SETBOOLFLAG(request, flags_, setReportLoadTiming,
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING);
|
||||||
|
SETBOOLFLAG(request, flags_, setReportRawHeaders,
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS);
|
||||||
|
|
||||||
|
if (!first_party_for_cookies_.empty()) {
|
||||||
|
std::string cookiesStr(first_party_for_cookies_);
|
||||||
|
GURL gurl = GURL(cookiesStr);
|
||||||
|
request.setFirstPartyForCookies(WebURL(gurl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CefRequest::RequestFlags CefRequestImpl::GetFlags()
|
||||||
|
{
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
return flags_;
|
||||||
|
}
|
||||||
|
void CefRequestImpl::SetFlags(RequestFlags flags)
|
||||||
|
{
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
flags_ = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
CefString CefRequestImpl::GetFirstPartyForCookies()
|
||||||
|
{
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
return first_party_for_cookies_;
|
||||||
|
}
|
||||||
|
void CefRequestImpl::SetFirstPartyForCookies(const CefString& url)
|
||||||
|
{
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
first_party_for_cookies_ = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers,
|
||||||
|
HeaderMap& map)
|
||||||
{
|
{
|
||||||
net::HttpRequestHeaders::Iterator it(headers);
|
net::HttpRequestHeaders::Iterator it(headers);
|
||||||
do {
|
do {
|
||||||
@ -125,26 +220,15 @@ void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers, Header
|
|||||||
} while (it.GetNext());
|
} while (it.GetNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
|
void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
|
||||||
HeaderMap& map)
|
HeaderMap& map)
|
||||||
{
|
{
|
||||||
class CefHTTPHeaderVisitor : public WebKit::WebHTTPHeaderVisitor {
|
HttpHeaderUtils::HeaderVisitor visitor(&map);
|
||||||
public:
|
|
||||||
CefHTTPHeaderVisitor(HeaderMap* map) : map_(map) {}
|
|
||||||
|
|
||||||
virtual void visitHeader(const WebKit::WebString& name,
|
|
||||||
const WebKit::WebString& value) {
|
|
||||||
map_->insert(std::make_pair(string16(name), string16(value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
HeaderMap* map_;
|
|
||||||
};
|
|
||||||
|
|
||||||
CefHTTPHeaderVisitor visitor(&map);
|
|
||||||
request.visitHTTPHeaderFields(&visitor);
|
request.visitHTTPHeaderFields(&visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
||||||
WebKit::WebURLRequest& request)
|
WebKit::WebURLRequest& request)
|
||||||
{
|
{
|
||||||
@ -153,42 +237,6 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
|
|||||||
request.setHTTPHeaderField(string16(it->first), string16(it->second));
|
request.setHTTPHeaderField(string16(it->first), string16(it->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CefRequestImpl::GenerateHeaders(const HeaderMap& map)
|
|
||||||
{
|
|
||||||
std::string headers;
|
|
||||||
|
|
||||||
for(HeaderMap::const_iterator header = map.begin();
|
|
||||||
header != map.end();
|
|
||||||
++header) {
|
|
||||||
const CefString& key = header->first;
|
|
||||||
const CefString& value = header->second;
|
|
||||||
|
|
||||||
if(!key.empty()) {
|
|
||||||
// Delimit with "\r\n".
|
|
||||||
if(!headers.empty())
|
|
||||||
headers += "\r\n";
|
|
||||||
|
|
||||||
headers += std::string(key) + ": " + std::string(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CefRequestImpl::ParseHeaders(const std::string& header_str, HeaderMap& map)
|
|
||||||
{
|
|
||||||
// Parse the request header values
|
|
||||||
std::string headerStr = "HTTP/1.1 200 OK\n";
|
|
||||||
headerStr += header_str;
|
|
||||||
scoped_refptr<net::HttpResponseHeaders> headers =
|
|
||||||
new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
|
|
||||||
headerStr.c_str(), headerStr.length()));
|
|
||||||
void* iter = NULL;
|
|
||||||
std::string name, value;
|
|
||||||
while(headers->EnumerateHeaderLines(&iter, &name, &value))
|
|
||||||
map.insert(std::make_pair(name, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
CefRefPtr<CefPostData> CefPostData::CreatePostData()
|
CefRefPtr<CefPostData> CefPostData::CreatePostData()
|
||||||
{
|
{
|
||||||
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
||||||
@ -201,44 +249,36 @@ CefPostDataImpl::CefPostDataImpl()
|
|||||||
|
|
||||||
size_t CefPostDataImpl::GetElementCount()
|
size_t CefPostDataImpl::GetElementCount()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
size_t ct = elements_.size();
|
return elements_.size();
|
||||||
Unlock();
|
|
||||||
return ct;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataImpl::GetElements(ElementVector& elements)
|
void CefPostDataImpl::GetElements(ElementVector& elements)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
elements = elements_;
|
elements = elements_;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefPostDataImpl::RemoveElement(CefRefPtr<CefPostDataElement> element)
|
bool CefPostDataImpl::RemoveElement(CefRefPtr<CefPostDataElement> element)
|
||||||
{
|
{
|
||||||
bool deleted = false;
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
Lock();
|
|
||||||
|
|
||||||
ElementVector::iterator it = elements_.begin();
|
ElementVector::iterator it = elements_.begin();
|
||||||
for(; it != elements_.end(); ++it) {
|
for(; it != elements_.end(); ++it) {
|
||||||
if(it->get() == element.get()) {
|
if(it->get() == element.get()) {
|
||||||
elements_.erase(it);
|
elements_.erase(it);
|
||||||
deleted = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
return false;
|
||||||
|
|
||||||
return deleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element)
|
bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
// check that the element isn't already in the list before adding
|
// check that the element isn't already in the list before adding
|
||||||
ElementVector::const_iterator it = elements_.begin();
|
ElementVector::const_iterator it = elements_.begin();
|
||||||
@ -252,20 +292,18 @@ bool CefPostDataImpl::AddElement(CefRefPtr<CefPostDataElement> element)
|
|||||||
if(!found)
|
if(!found)
|
||||||
elements_.push_back(element);
|
elements_.push_back(element);
|
||||||
|
|
||||||
Unlock();
|
|
||||||
return !found;
|
return !found;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataImpl::RemoveElements()
|
void CefPostDataImpl::RemoveElements()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
elements_.clear();
|
elements_.clear();
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataImpl::Set(net::UploadData& data)
|
void CefPostDataImpl::Set(net::UploadData& data)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
CefRefPtr<CefPostDataElement> postelem;
|
CefRefPtr<CefPostDataElement> postelem;
|
||||||
|
|
||||||
@ -276,13 +314,11 @@ void CefPostDataImpl::Set(net::UploadData& data)
|
|||||||
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(*it);
|
static_cast<CefPostDataElementImpl*>(postelem.get())->Set(*it);
|
||||||
AddElement(postelem);
|
AddElement(postelem);
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataImpl::Get(net::UploadData& data)
|
void CefPostDataImpl::Get(net::UploadData& data)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
net::UploadData::Element element;
|
net::UploadData::Element element;
|
||||||
std::vector<net::UploadData::Element> data_elements;
|
std::vector<net::UploadData::Element> data_elements;
|
||||||
@ -292,13 +328,11 @@ void CefPostDataImpl::Get(net::UploadData& data)
|
|||||||
data_elements.push_back(element);
|
data_elements.push_back(element);
|
||||||
}
|
}
|
||||||
data.SetElements(data_elements);
|
data.SetElements(data_elements);
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data)
|
void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
CefRefPtr<CefPostDataElement> postelem;
|
CefRefPtr<CefPostDataElement> postelem;
|
||||||
WebKit::WebHTTPBody::Element element;
|
WebKit::WebHTTPBody::Element element;
|
||||||
@ -310,13 +344,11 @@ void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data)
|
|||||||
AddElement(postelem);
|
AddElement(postelem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataImpl::Get(WebKit::WebHTTPBody& data)
|
void CefPostDataImpl::Get(WebKit::WebHTTPBody& data)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
WebKit::WebHTTPBody::Element element;
|
WebKit::WebHTTPBody::Element element;
|
||||||
ElementVector::iterator it = elements_.begin();
|
ElementVector::iterator it = elements_.begin();
|
||||||
@ -330,8 +362,6 @@ void CefPostDataImpl::Get(WebKit::WebHTTPBody& data)
|
|||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefRefPtr<CefPostDataElement> CefPostDataElement::CreatePostDataElement()
|
CefRefPtr<CefPostDataElement> CefPostDataElement::CreatePostDataElement()
|
||||||
@ -353,31 +383,29 @@ CefPostDataElementImpl::~CefPostDataElementImpl()
|
|||||||
|
|
||||||
void CefPostDataElementImpl::SetToEmpty()
|
void CefPostDataElementImpl::SetToEmpty()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
if(type_ == PDE_TYPE_BYTES)
|
if(type_ == PDE_TYPE_BYTES)
|
||||||
free(data_.bytes.bytes);
|
free(data_.bytes.bytes);
|
||||||
else if(type_ == PDE_TYPE_FILE)
|
else if(type_ == PDE_TYPE_FILE)
|
||||||
cef_string_clear(&data_.filename);
|
cef_string_clear(&data_.filename);
|
||||||
type_ = PDE_TYPE_EMPTY;
|
type_ = PDE_TYPE_EMPTY;
|
||||||
memset(&data_, 0, sizeof(data_));
|
memset(&data_, 0, sizeof(data_));
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataElementImpl::SetToFile(const CefString& fileName)
|
void CefPostDataElementImpl::SetToFile(const CefString& fileName)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
// Clear any data currently in the element
|
// Clear any data currently in the element
|
||||||
SetToEmpty();
|
SetToEmpty();
|
||||||
|
|
||||||
// Assign the new data
|
// Assign the new data
|
||||||
type_ = PDE_TYPE_FILE;
|
type_ = PDE_TYPE_FILE;
|
||||||
cef_string_copy(fileName.c_str(), fileName.length(), &data_.filename);
|
cef_string_copy(fileName.c_str(), fileName.length(), &data_.filename);
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes)
|
void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
// Clear any data currently in the element
|
// Clear any data currently in the element
|
||||||
SetToEmpty();
|
SetToEmpty();
|
||||||
|
|
||||||
@ -392,55 +420,49 @@ void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes)
|
|||||||
type_ = PDE_TYPE_BYTES;
|
type_ = PDE_TYPE_BYTES;
|
||||||
data_.bytes.bytes = data;
|
data_.bytes.bytes = data;
|
||||||
data_.bytes.size = size;
|
data_.bytes.size = size;
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefPostDataElement::Type CefPostDataElementImpl::GetType()
|
CefPostDataElement::Type CefPostDataElementImpl::GetType()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
CefPostDataElement::Type type = type_;
|
return type_;
|
||||||
Unlock();
|
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CefString CefPostDataElementImpl::GetFile()
|
CefString CefPostDataElementImpl::GetFile()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
DCHECK(type_ == PDE_TYPE_FILE);
|
DCHECK(type_ == PDE_TYPE_FILE);
|
||||||
CefString filename;
|
CefString filename;
|
||||||
if(type_ == PDE_TYPE_FILE)
|
if(type_ == PDE_TYPE_FILE)
|
||||||
filename.FromString(data_.filename.str, data_.filename.length, false);
|
filename.FromString(data_.filename.str, data_.filename.length, false);
|
||||||
Unlock();
|
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CefPostDataElementImpl::GetBytesCount()
|
size_t CefPostDataElementImpl::GetBytesCount()
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
DCHECK(type_ == PDE_TYPE_BYTES);
|
DCHECK(type_ == PDE_TYPE_BYTES);
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if(type_ == PDE_TYPE_BYTES)
|
if(type_ == PDE_TYPE_BYTES)
|
||||||
size = data_.bytes.size;
|
size = data_.bytes.size;
|
||||||
Unlock();
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CefPostDataElementImpl::GetBytes(size_t size, void* bytes)
|
size_t CefPostDataElementImpl::GetBytes(size_t size, void* bytes)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
DCHECK(type_ == PDE_TYPE_BYTES);
|
DCHECK(type_ == PDE_TYPE_BYTES);
|
||||||
size_t rv = 0;
|
size_t rv = 0;
|
||||||
if(type_ == PDE_TYPE_BYTES) {
|
if(type_ == PDE_TYPE_BYTES) {
|
||||||
rv = (size < data_.bytes.size ? size : data_.bytes.size);
|
rv = (size < data_.bytes.size ? size : data_.bytes.size);
|
||||||
memcpy(bytes, data_.bytes.bytes, rv);
|
memcpy(bytes, data_.bytes.bytes, rv);
|
||||||
}
|
}
|
||||||
Unlock();
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataElementImpl::Set(const net::UploadData::Element& element)
|
void CefPostDataElementImpl::Set(const net::UploadData::Element& element)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
if (element.type() == net::UploadData::TYPE_BYTES) {
|
if (element.type() == net::UploadData::TYPE_BYTES) {
|
||||||
SetToBytes(element.bytes().size(),
|
SetToBytes(element.bytes().size(),
|
||||||
@ -452,13 +474,11 @@ void CefPostDataElementImpl::Set(const net::UploadData::Element& element)
|
|||||||
} else {
|
} else {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataElementImpl::Get(net::UploadData::Element& element)
|
void CefPostDataElementImpl::Get(net::UploadData::Element& element)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
if(type_ == PDE_TYPE_BYTES) {
|
if(type_ == PDE_TYPE_BYTES) {
|
||||||
element.SetToBytes(static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
element.SetToBytes(static_cast<char*>(data_.bytes.bytes), data_.bytes.size);
|
||||||
@ -468,13 +488,11 @@ void CefPostDataElementImpl::Get(net::UploadData::Element& element)
|
|||||||
} else {
|
} else {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element)
|
void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
if(element.type == WebKit::WebHTTPBody::Element::TypeData) {
|
if(element.type == WebKit::WebHTTPBody::Element::TypeData) {
|
||||||
SetToBytes(element.data.size(),
|
SetToBytes(element.data.size(),
|
||||||
@ -484,13 +502,11 @@ void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element)
|
|||||||
} else {
|
} else {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element)
|
void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element)
|
||||||
{
|
{
|
||||||
Lock();
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
if(type_ == PDE_TYPE_BYTES) {
|
if(type_ == PDE_TYPE_BYTES) {
|
||||||
element.type = WebKit::WebHTTPBody::Element::TypeData;
|
element.type = WebKit::WebHTTPBody::Element::TypeData;
|
||||||
@ -502,6 +518,4 @@ void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element)
|
|||||||
} else {
|
} else {
|
||||||
NOTREACHED();
|
NOTREACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#ifndef _REQUEST_IMPL_H
|
#ifndef _REQUEST_IMPL_H
|
||||||
#define _REQUEST_IMPL_H
|
#define _REQUEST_IMPL_H
|
||||||
|
|
||||||
#include "../include/cef.h"
|
#include "include/cef.h"
|
||||||
#include "net/base/upload_data.h"
|
#include "net/base/upload_data.h"
|
||||||
#include "net/http/http_request_headers.h"
|
#include "net/http/http_request_headers.h"
|
||||||
#include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h"
|
#include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h"
|
||||||
@ -34,8 +34,14 @@ public:
|
|||||||
const CefString& method,
|
const CefString& method,
|
||||||
CefRefPtr<CefPostData> postData,
|
CefRefPtr<CefPostData> postData,
|
||||||
const HeaderMap& headerMap);
|
const HeaderMap& headerMap);
|
||||||
|
virtual RequestFlags GetFlags();
|
||||||
|
virtual void SetFlags(RequestFlags flags);
|
||||||
|
virtual CefString GetFirstPartyForCookies();
|
||||||
|
virtual void SetFirstPartyForCookies(const CefString& url);
|
||||||
|
|
||||||
void Set(net::URLRequest* request);
|
void Set(net::URLRequest* request);
|
||||||
|
void Set(const WebKit::WebURLRequest& request);
|
||||||
|
void Get(WebKit::WebURLRequest& request);
|
||||||
|
|
||||||
static void GetHeaderMap(const net::HttpRequestHeaders& headers,
|
static void GetHeaderMap(const net::HttpRequestHeaders& headers,
|
||||||
HeaderMap& map);
|
HeaderMap& map);
|
||||||
@ -44,14 +50,15 @@ public:
|
|||||||
static void SetHeaderMap(const HeaderMap& map,
|
static void SetHeaderMap(const HeaderMap& map,
|
||||||
WebKit::WebURLRequest& request);
|
WebKit::WebURLRequest& request);
|
||||||
|
|
||||||
static std::string GenerateHeaders(const HeaderMap& map);
|
|
||||||
static void ParseHeaders(const std::string& header_str, HeaderMap& map);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CefString url_;
|
CefString url_;
|
||||||
CefString method_;
|
CefString method_;
|
||||||
CefRefPtr<CefPostData> postdata_;
|
CefRefPtr<CefPostData> postdata_;
|
||||||
HeaderMap headermap_;
|
HeaderMap headermap_;
|
||||||
|
|
||||||
|
// The below methods are used by WebURLRequest.
|
||||||
|
RequestFlags flags_;
|
||||||
|
CefString first_party_for_cookies_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Implementation of CefPostData
|
// Implementation of CefPostData
|
||||||
|
50
libcef/response_impl.cc
Normal file
50
libcef/response_impl.cc
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) 2011 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.
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "response_impl.h"
|
||||||
|
|
||||||
|
#include "base/logging.h"
|
||||||
|
#include "http_header_utils.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
|
||||||
|
|
||||||
|
CefResponseImpl::CefResponseImpl(const WebKit::WebURLResponse &response)
|
||||||
|
{
|
||||||
|
DCHECK(!response.isNull());
|
||||||
|
|
||||||
|
WebKit::WebString str;
|
||||||
|
status_code_ = response.httpStatusCode();
|
||||||
|
str = response.httpStatusText();
|
||||||
|
status_text_ = CefString(str);
|
||||||
|
|
||||||
|
HttpHeaderUtils::HeaderVisitor visitor(&header_map_);
|
||||||
|
response.visitHTTPHeaderFields(&visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CefResponseImpl::GetStatus()
|
||||||
|
{
|
||||||
|
return status_code_;
|
||||||
|
}
|
||||||
|
|
||||||
|
CefString CefResponseImpl::GetStatusText()
|
||||||
|
{
|
||||||
|
return status_text_;
|
||||||
|
}
|
||||||
|
|
||||||
|
CefString CefResponseImpl::GetHeader(const CefString& name)
|
||||||
|
{
|
||||||
|
CefString value;
|
||||||
|
|
||||||
|
HeaderMap::const_iterator it = header_map_.find(name);
|
||||||
|
if (it != header_map_.end())
|
||||||
|
value = it->second;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefResponseImpl::GetHeaderMap(HeaderMap& map)
|
||||||
|
{
|
||||||
|
map = header_map_;
|
||||||
|
}
|
33
libcef/response_impl.h
Normal file
33
libcef/response_impl.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (c) 2011 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 _RESPONSE_IMPL_H
|
||||||
|
#define _RESPONSE_IMPL_H
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
|
||||||
|
namespace WebKit {
|
||||||
|
class WebURLResponse;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Implementation of CefResponse.
|
||||||
|
class CefResponseImpl : public CefThreadSafeBase<CefResponse>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefResponseImpl(const WebKit::WebURLResponse& response);
|
||||||
|
~CefResponseImpl() {}
|
||||||
|
|
||||||
|
// CefResponse API
|
||||||
|
virtual int GetStatus();
|
||||||
|
virtual CefString GetStatusText();
|
||||||
|
virtual CefString GetHeader(const CefString& name);
|
||||||
|
virtual void GetHeaderMap(HeaderMap& headerMap);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int status_code_;
|
||||||
|
CefString status_text_;
|
||||||
|
HeaderMap header_map_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _RESPONSE_IMPL_H
|
322
libcef/web_urlrequest_impl.cc
Normal file
322
libcef/web_urlrequest_impl.cc
Normal file
@ -0,0 +1,322 @@
|
|||||||
|
// Copyright (c) 2011 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.
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "web_urlrequest_impl.h"
|
||||||
|
#include "cef_thread.h"
|
||||||
|
#include "request_impl.h"
|
||||||
|
#include "response_impl.h"
|
||||||
|
|
||||||
|
#include "base/logging.h"
|
||||||
|
#include "base/scoped_ptr.h"
|
||||||
|
#include "googleurl/src/gurl.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
|
||||||
|
#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
|
||||||
|
#include "webkit/glue/weburlloader_impl.h"
|
||||||
|
|
||||||
|
using WebKit::WebURLError;
|
||||||
|
using WebKit::WebURLLoader;
|
||||||
|
using WebKit::WebURLRequest;
|
||||||
|
using WebKit::WebURLResponse;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class CefWebURLLoaderClientImpl;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Manages the lifespan of WebKit objects. Methods of this class will only be
|
||||||
|
// called on the UI thread.
|
||||||
|
class CefWebURLRequestImpl::Context :
|
||||||
|
public base::RefCountedThreadSafe<CefWebURLRequestImpl::Context,
|
||||||
|
CefThread::DeleteOnUIThread>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Context(CefRefPtr<CefWebURLRequestImpl> client)
|
||||||
|
: client_(client)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~Context()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize(CefRefPtr<CefRequest> request);
|
||||||
|
void destroy();
|
||||||
|
void cancel();
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client() { return client_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client_;
|
||||||
|
scoped_ptr<webkit_glue::WebURLLoaderImpl> url_loader_;
|
||||||
|
scoped_ptr<CefWebURLLoaderClientImpl> url_client_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Implements the WebURLLoaderClient interface. Methods of this class will only
|
||||||
|
// be called on the UI thread.
|
||||||
|
class CefWebURLLoaderClientImpl : public WebKit::WebURLLoaderClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefWebURLLoaderClientImpl(CefWebURLRequestImpl::Context* context)
|
||||||
|
: context_(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~CefWebURLLoaderClientImpl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================
|
||||||
|
// WebKit::WebURLLoaderClient API
|
||||||
|
//
|
||||||
|
|
||||||
|
// Called when following a redirect. |newRequest| contains the request
|
||||||
|
// generated by the redirect. The client may modify |newRequest|.
|
||||||
|
void willSendRequest(WebKit::WebURLLoader*, WebKit::WebURLRequest& newRequest,
|
||||||
|
const WebKit::WebURLResponse& redirectResponse)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
if(!context_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client = context_->client();
|
||||||
|
if (client.get()) {
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler = client->GetHandler();
|
||||||
|
if (handler.get()) {
|
||||||
|
CefRefPtr<CefRequestImpl> cefRequest(new CefRequestImpl());
|
||||||
|
CefRefPtr<CefResponse> cefResponse(
|
||||||
|
new CefResponseImpl(redirectResponse));
|
||||||
|
|
||||||
|
cefRequest->Set(newRequest);
|
||||||
|
handler->OnRedirect(client.get(), cefRequest.get(), cefResponse);
|
||||||
|
cefRequest->Get(newRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called to report upload progress. The bytes reported correspond to
|
||||||
|
// the HTTP message body.
|
||||||
|
void didSendData(WebKit::WebURLLoader*, unsigned long long bytesSent,
|
||||||
|
unsigned long long totalBytesToBeSent)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
if(!context_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client = context_->client();
|
||||||
|
if (client.get()) {
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler = client->GetHandler();
|
||||||
|
if (handler.get())
|
||||||
|
handler->OnProgress(client.get(), bytesSent, totalBytesToBeSent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when response headers are received.
|
||||||
|
void didReceiveResponse(WebKit::WebURLLoader*,
|
||||||
|
const WebKit::WebURLResponse& response)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
if(!context_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client = context_->client();
|
||||||
|
if (client.get()) {
|
||||||
|
client->DoStateChange(WUR_STATE_HEADERS_RECEIVED);
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler = client->GetHandler();
|
||||||
|
if (handler.get()) {
|
||||||
|
CefRefPtr<CefResponse> cefResponse(new CefResponseImpl(response));
|
||||||
|
handler->OnHeadersReceived(client.get(), cefResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a chunk of response data is downloaded. This is only called
|
||||||
|
// if WebURLRequest's downloadToFile flag was set to true.
|
||||||
|
void didDownloadData(WebKit::WebURLLoader*, int dataLength)
|
||||||
|
{
|
||||||
|
NOTREACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a chunk of response data is received.
|
||||||
|
void didReceiveData(WebKit::WebURLLoader*, const char* data, int dataLength)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
if(!context_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client = context_->client();
|
||||||
|
if (client.get()) {
|
||||||
|
client->DoStateChange(WUR_STATE_LOADING);
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler = client->GetHandler();
|
||||||
|
if (handler.get()) {
|
||||||
|
handler->OnData(client.get(), data, dataLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a chunk of renderer-generated metadata is received from
|
||||||
|
// the cache.
|
||||||
|
void didReceiveCachedMetadata(WebKit::WebURLLoader*, const char* data,
|
||||||
|
int dataLength)
|
||||||
|
{
|
||||||
|
NOTREACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the load completes successfully.
|
||||||
|
void didFinishLoading(WebKit::WebURLLoader*, double finishTime)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
if(!context_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client = context_->client();
|
||||||
|
if (client.get())
|
||||||
|
client->DoStateChange(WUR_STATE_DONE);
|
||||||
|
|
||||||
|
complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the load completes with an error.
|
||||||
|
void didFail(WebKit::WebURLLoader*, const WebKit::WebURLError& error)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
if(!context_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> client = context_->client();
|
||||||
|
if (client.get() && client->GetState() != WUR_STATE_ABORT) {
|
||||||
|
client->DoStateChange(WUR_STATE_ERROR);
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler = client->GetHandler();
|
||||||
|
if (handler.get()) {
|
||||||
|
handler->OnError(client.get(),
|
||||||
|
static_cast<CefWebURLRequestClient::ErrorCode>(error.reason));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete()
|
||||||
|
{
|
||||||
|
context_->destroy();
|
||||||
|
context_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
scoped_refptr<CefWebURLRequestImpl::Context> context_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
// CefWebURLManager
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::Context::initialize(
|
||||||
|
CefRefPtr<CefRequest> request)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
|
||||||
|
url_loader_.reset(new webkit_glue::WebURLLoaderImpl());
|
||||||
|
url_client_.reset(new CefWebURLLoaderClientImpl(this));
|
||||||
|
|
||||||
|
WebURLRequest urlRequest;
|
||||||
|
static_cast<CefRequestImpl*>(request.get())->Get(urlRequest);
|
||||||
|
url_loader_->loadAsynchronously(urlRequest, url_client_.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::Context::destroy()
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
client_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::Context::cancel()
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
url_loader_->cancel();
|
||||||
|
url_client_->complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CefWebURLRequest
|
||||||
|
|
||||||
|
// static
|
||||||
|
CefRefPtr<CefWebURLRequest>
|
||||||
|
CefWebURLRequest::CreateWebURLRequest(
|
||||||
|
CefRefPtr<CefRequest> request, CefRefPtr<CefWebURLRequestClient> client)
|
||||||
|
{
|
||||||
|
CefRefPtr<CefWebURLRequestImpl> requester = new CefWebURLRequestImpl(client);
|
||||||
|
|
||||||
|
// Send the request from the UI thread.
|
||||||
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
||||||
|
NewRunnableMethod(requester.get(), &CefWebURLRequestImpl::DoSend,
|
||||||
|
request));
|
||||||
|
|
||||||
|
return requester.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CefWebURLRequestImpl
|
||||||
|
|
||||||
|
CefWebURLRequestImpl::CefWebURLRequestImpl(
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler)
|
||||||
|
: handler_(handler),
|
||||||
|
state_(WUR_STATE_UNSENT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CefWebURLRequestImpl::~CefWebURLRequestImpl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CefWebURLRequestImpl::RequestState CefWebURLRequestImpl::GetState()
|
||||||
|
{
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
return state_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::Cancel()
|
||||||
|
{
|
||||||
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
||||||
|
NewRunnableMethod(this, &CefWebURLRequestImpl::DoCancel));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::DoSend(CefRefPtr<CefRequest> request)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
DCHECK(state_ == WUR_STATE_UNSENT);
|
||||||
|
|
||||||
|
context_ = new CefWebURLRequestImpl::Context(this);
|
||||||
|
context_->initialize(request);
|
||||||
|
|
||||||
|
DoStateChange(WUR_STATE_STARTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::DoCancel()
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
|
||||||
|
if (state_ < WUR_STATE_DONE) {
|
||||||
|
DoStateChange(WUR_STATE_ABORT);
|
||||||
|
context_->cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestImpl::DoStateChange(RequestState newState)
|
||||||
|
{
|
||||||
|
REQUIRE_UIT();
|
||||||
|
|
||||||
|
if (state_ == newState)
|
||||||
|
return;
|
||||||
|
|
||||||
|
{
|
||||||
|
AutoLock lock_scope(this);
|
||||||
|
state_ = newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handler_.get())
|
||||||
|
handler_->OnStateChange(this, newState);
|
||||||
|
}
|
42
libcef/web_urlrequest_impl.h
Normal file
42
libcef/web_urlrequest_impl.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2011 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 _WEB_URL_REQUEST_CLIENT_IMPL_H
|
||||||
|
#define _WEB_URL_REQUEST_CLIENT_IMPL_H
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "base/ref_counted.h"
|
||||||
|
|
||||||
|
class CefWebURLRequestImpl :
|
||||||
|
public CefThreadSafeBase<CefWebURLRequest>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class Context;
|
||||||
|
|
||||||
|
explicit CefWebURLRequestImpl(
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler);
|
||||||
|
virtual ~CefWebURLRequestImpl();
|
||||||
|
|
||||||
|
// Can be called on any thread.
|
||||||
|
virtual RequestState GetState();
|
||||||
|
virtual void Cancel();
|
||||||
|
|
||||||
|
// Can only be called on the UI thread.
|
||||||
|
void DoSend(CefRefPtr<CefRequest> request);
|
||||||
|
void DoCancel();
|
||||||
|
void DoStateChange(RequestState newState);
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestClient> GetHandler() { return handler_; }
|
||||||
|
|
||||||
|
static bool ImplementsThreadSafeReferenceCounting() { return true; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CefRefPtr<CefWebURLRequestClient> handler_;
|
||||||
|
|
||||||
|
// The below parameters are only modified on the UI thread.
|
||||||
|
RequestState state_;
|
||||||
|
scoped_refptr<Context> context_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _WEB_URL_REQUEST_CLIENT_IMPL_H
|
@ -144,6 +144,47 @@ void CEF_CALLBACK request_set(struct _cef_request_t* self,
|
|||||||
postDataPtr, map);
|
postDataPtr, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum cef_weburlrequest_flags_t CEF_CALLBACK request_get_flags(
|
||||||
|
struct _cef_request_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return WUR_FLAG_NONE;
|
||||||
|
|
||||||
|
return CefRequestCppToC::Get(self)->GetFlags();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK request_set_flags(struct _cef_request_t* self,
|
||||||
|
enum cef_weburlrequest_flags_t flags)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRequestCppToC::Get(self)->SetFlags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
cef_string_userfree_t CEF_CALLBACK request_get_first_party_for_cookies(
|
||||||
|
struct _cef_request_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
CefString urlStr = CefRequestCppToC::Get(self)->GetFirstPartyForCookies();
|
||||||
|
return urlStr.DetachToUserFree();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK request_set_first_party_for_cookies(
|
||||||
|
struct _cef_request_t* self, const cef_string_t* url)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefRequestCppToC::Get(self)->SetFirstPartyForCookies(CefString(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
@ -159,6 +200,12 @@ CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
|
|||||||
struct_.struct_.get_header_map = request_get_header_map;
|
struct_.struct_.get_header_map = request_get_header_map;
|
||||||
struct_.struct_.set_header_map = request_set_header_map;
|
struct_.struct_.set_header_map = request_set_header_map;
|
||||||
struct_.struct_.set = request_set;
|
struct_.struct_.set = request_set;
|
||||||
|
struct_.struct_.get_flags = request_get_flags;
|
||||||
|
struct_.struct_.set_flags = request_set_flags;
|
||||||
|
struct_.struct_.get_first_party_for_cookies =
|
||||||
|
request_get_first_party_for_cookies;
|
||||||
|
struct_.struct_.set_first_party_for_cookies =
|
||||||
|
request_set_first_party_for_cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
125
libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc
Normal file
125
libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A portion of this file was generated by the CEF translator tool. When
|
||||||
|
// making changes by hand only do so within the body of existing function
|
||||||
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
|
// for more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||||
|
#include "libcef_dll/ctocpp/response_ctocpp.h"
|
||||||
|
#include "libcef_dll/ctocpp/web_urlrequest_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_client_on_state_change(
|
||||||
|
struct _cef_web_urlrequest_client_t* self, cef_web_urlrequest_t* requester,
|
||||||
|
enum cef_weburlrequest_state_t state)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(requester);
|
||||||
|
if(!self || !requester)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::Get(self)->OnStateChange(
|
||||||
|
CefWebURLRequestCToCpp::Wrap(requester), state );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_client_on_redirect(
|
||||||
|
struct _cef_web_urlrequest_client_t* self, cef_web_urlrequest_t* requester,
|
||||||
|
cef_request_t* request, cef_response_t* response)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(requester);
|
||||||
|
DCHECK(request);
|
||||||
|
DCHECK(response);
|
||||||
|
if(!self || !requester || !request || !response)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::Get(self)->OnRedirect(
|
||||||
|
CefWebURLRequestCToCpp::Wrap(requester), CefRequestCToCpp::Wrap(request),
|
||||||
|
CefResponseCToCpp::Wrap(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_client_on_headers_received(
|
||||||
|
struct _cef_web_urlrequest_client_t* self, cef_web_urlrequest_t* requester,
|
||||||
|
cef_response_t* response)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(requester);
|
||||||
|
DCHECK(response);
|
||||||
|
if(!self || !requester || !response)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::Get(self)->OnHeadersReceived(
|
||||||
|
CefWebURLRequestCToCpp::Wrap(requester),
|
||||||
|
CefResponseCToCpp::Wrap(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_client_on_progress(
|
||||||
|
struct _cef_web_urlrequest_client_t* self, cef_web_urlrequest_t* requester,
|
||||||
|
uint64 bytesSent, uint64 totalBytesToBeSent)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(requester);
|
||||||
|
if(!self || !requester)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::Get(self)->OnProgress(
|
||||||
|
CefWebURLRequestCToCpp::Wrap(requester), bytesSent, totalBytesToBeSent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_client_on_data(
|
||||||
|
struct _cef_web_urlrequest_client_t* self, cef_web_urlrequest_t* requester,
|
||||||
|
const void* data, int dataLength)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(requester);
|
||||||
|
if(!self || !requester)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::Get(self)->OnData(
|
||||||
|
CefWebURLRequestCToCpp::Wrap(requester), data, dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_client_on_error(
|
||||||
|
struct _cef_web_urlrequest_client_t* self, cef_web_urlrequest_t* requester,
|
||||||
|
enum cef_handler_errorcode_t errorCode)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(requester);
|
||||||
|
if(!self || !requester)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::Get(self)->OnError(
|
||||||
|
CefWebURLRequestCToCpp::Wrap(requester), errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
|
CefWebURLRequestClientCppToC::CefWebURLRequestClientCppToC(
|
||||||
|
CefWebURLRequestClient* cls)
|
||||||
|
: CefCppToC<CefWebURLRequestClientCppToC, CefWebURLRequestClient,
|
||||||
|
cef_web_urlrequest_client_t>(cls)
|
||||||
|
{
|
||||||
|
struct_.struct_.on_state_change = web_urlrequest_client_on_state_change;
|
||||||
|
struct_.struct_.on_redirect = web_urlrequest_client_on_redirect;
|
||||||
|
struct_.struct_.on_headers_received =
|
||||||
|
web_urlrequest_client_on_headers_received;
|
||||||
|
struct_.struct_.on_progress = web_urlrequest_client_on_progress;
|
||||||
|
struct_.struct_.on_data = web_urlrequest_client_on_data;
|
||||||
|
struct_.struct_.on_error = web_urlrequest_client_on_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
template<> long CefCppToC<CefWebURLRequestClientCppToC, CefWebURLRequestClient,
|
||||||
|
cef_web_urlrequest_client_t>::DebugObjCt = 0;
|
||||||
|
#endif
|
||||||
|
|
35
libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h
Normal file
35
libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file was generated by the CEF translator tool and should not edited
|
||||||
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
|
// more information.
|
||||||
|
//
|
||||||
|
#ifndef _WEBURLREQUESTCLIENT_CPPTOC_H
|
||||||
|
#define _WEBURLREQUESTCLIENT_CPPTOC_H
|
||||||
|
|
||||||
|
#ifndef USING_CEF_SHARED
|
||||||
|
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||||
|
#else // USING_CEF_SHARED
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "include/cef_capi.h"
|
||||||
|
#include "libcef_dll/cpptoc/cpptoc.h"
|
||||||
|
|
||||||
|
// Wrap a C++ class with a C structure.
|
||||||
|
// This class may be instantiated and accessed wrapper-side only.
|
||||||
|
class CefWebURLRequestClientCppToC
|
||||||
|
: public CefCppToC<CefWebURLRequestClientCppToC, CefWebURLRequestClient,
|
||||||
|
cef_web_urlrequest_client_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefWebURLRequestClientCppToC(CefWebURLRequestClient* cls);
|
||||||
|
virtual ~CefWebURLRequestClientCppToC() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USING_CEF_SHARED
|
||||||
|
#endif // _WEBURLREQUESTCLIENT_CPPTOC_H
|
||||||
|
|
73
libcef_dll/cpptoc/web_urlrequest_cpptoc.cc
Normal file
73
libcef_dll/cpptoc/web_urlrequest_cpptoc.cc
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A portion of this file was generated by the CEF translator tool. When
|
||||||
|
// making changes by hand only do so within the body of existing function
|
||||||
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
|
// for more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||||
|
#include "libcef_dll/cpptoc/web_urlrequest_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
// GLOBAL FUNCTIONS - Body may be edited by hand.
|
||||||
|
|
||||||
|
CEF_EXPORT cef_web_urlrequest_t* cef_web_urlrequest_create(
|
||||||
|
cef_request_t* request, struct _cef_web_urlrequest_client_t* client)
|
||||||
|
{
|
||||||
|
CefRefPtr<CefRequest> requestPtr = CefRequestCppToC::Unwrap(request);
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestClient> clientPtr;
|
||||||
|
if(client)
|
||||||
|
clientPtr = CefWebURLRequestClientCToCpp::Wrap(client);
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequest> impl =
|
||||||
|
CefWebURLRequest::CreateWebURLRequest(requestPtr, clientPtr);
|
||||||
|
if(impl.get())
|
||||||
|
return CefWebURLRequestCppToC::Wrap(impl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||||
|
|
||||||
|
void CEF_CALLBACK web_urlrequest_cancel(struct _cef_web_urlrequest_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefWebURLRequestCppToC::Get(self)->Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
enum cef_weburlrequest_state_t CEF_CALLBACK web_urlrequest_get_state(
|
||||||
|
struct _cef_web_urlrequest_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return WUR_STATE_UNSENT;
|
||||||
|
|
||||||
|
return CefWebURLRequestCppToC::Get(self)->GetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
|
CefWebURLRequestCppToC::CefWebURLRequestCppToC(CefWebURLRequest* cls)
|
||||||
|
: CefCppToC<CefWebURLRequestCppToC, CefWebURLRequest, cef_web_urlrequest_t>(
|
||||||
|
cls)
|
||||||
|
{
|
||||||
|
struct_.struct_.cancel = web_urlrequest_cancel;
|
||||||
|
struct_.struct_.get_state = web_urlrequest_get_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
template<> long CefCppToC<CefWebURLRequestCppToC, CefWebURLRequest,
|
||||||
|
cef_web_urlrequest_t>::DebugObjCt = 0;
|
||||||
|
#endif
|
||||||
|
|
35
libcef_dll/cpptoc/web_urlrequest_cpptoc.h
Normal file
35
libcef_dll/cpptoc/web_urlrequest_cpptoc.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file was generated by the CEF translator tool and should not edited
|
||||||
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
|
// more information.
|
||||||
|
//
|
||||||
|
#ifndef _WEBURLREQUEST_CPPTOC_H
|
||||||
|
#define _WEBURLREQUEST_CPPTOC_H
|
||||||
|
|
||||||
|
#ifndef BUILDING_CEF_SHARED
|
||||||
|
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
||||||
|
#else // BUILDING_CEF_SHARED
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "include/cef_capi.h"
|
||||||
|
#include "libcef_dll/cpptoc/cpptoc.h"
|
||||||
|
|
||||||
|
// Wrap a C++ class with a C structure.
|
||||||
|
// This class may be instantiated and accessed DLL-side only.
|
||||||
|
class CefWebURLRequestCppToC
|
||||||
|
: public CefCppToC<CefWebURLRequestCppToC, CefWebURLRequest,
|
||||||
|
cef_web_urlrequest_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefWebURLRequestCppToC(CefWebURLRequest* cls);
|
||||||
|
virtual ~CefWebURLRequestCppToC() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BUILDING_CEF_SHARED
|
||||||
|
#endif // _WEBURLREQUEST_CPPTOC_H
|
||||||
|
|
@ -147,6 +147,41 @@ void CefRequestCToCpp::Set(const CefString& url, const CefString& method,
|
|||||||
cef_string_map_free(map);
|
cef_string_map_free(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefRequest::RequestFlags CefRequestCToCpp::GetFlags()
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, get_flags))
|
||||||
|
return WUR_FLAG_NONE;
|
||||||
|
|
||||||
|
return struct_->get_flags(struct_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefRequestCToCpp::SetFlags(RequestFlags flags)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, set_flags))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->set_flags(struct_, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefString CefRequestCToCpp::GetFirstPartyForCookies()
|
||||||
|
{
|
||||||
|
CefString str;
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, get_first_party_for_cookies))
|
||||||
|
return str;
|
||||||
|
|
||||||
|
cef_string_userfree_t strPtr = struct_->get_first_party_for_cookies(struct_);
|
||||||
|
str.AttachToUserFree(strPtr);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefRequestCToCpp::SetFirstPartyForCookies(const CefString& url)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, set_first_party_for_cookies))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->set_first_party_for_cookies(struct_, url.GetStruct());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
template<> long CefCToCpp<CefRequestCToCpp, CefRequest,
|
template<> long CefCToCpp<CefRequestCToCpp, CefRequest,
|
||||||
|
@ -41,6 +41,10 @@ public:
|
|||||||
virtual void SetHeaderMap(const HeaderMap& headerMap);
|
virtual void SetHeaderMap(const HeaderMap& headerMap);
|
||||||
virtual void Set(const CefString& url, const CefString& method,
|
virtual void Set(const CefString& url, const CefString& method,
|
||||||
CefRefPtr<CefPostData> postData, const HeaderMap& headerMap);
|
CefRefPtr<CefPostData> postData, const HeaderMap& headerMap);
|
||||||
|
virtual RequestFlags GetFlags();
|
||||||
|
virtual void SetFlags(RequestFlags flags);
|
||||||
|
virtual CefString GetFirstPartyForCookies();
|
||||||
|
virtual void SetFirstPartyForCookies(const CefString& url);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USING_CEF_SHARED
|
#endif // USING_CEF_SHARED
|
||||||
|
88
libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc
Normal file
88
libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A portion of this file was generated by the CEF translator tool. When
|
||||||
|
// making changes by hand only do so within the body of existing static and
|
||||||
|
// virtual method implementations. See the translator.README.txt file in the
|
||||||
|
// tools directory for more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||||
|
#include "libcef_dll/cpptoc/response_cpptoc.h"
|
||||||
|
#include "libcef_dll/cpptoc/web_urlrequest_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
|
void CefWebURLRequestClientCToCpp::OnStateChange(
|
||||||
|
CefRefPtr<CefWebURLRequest> requester, RequestState state)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, on_state_change))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->on_state_change(struct_, CefWebURLRequestCppToC::Wrap(requester),
|
||||||
|
state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestClientCToCpp::OnRedirect(
|
||||||
|
CefRefPtr<CefWebURLRequest> requester, CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefResponse> response)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, on_redirect))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->on_redirect(struct_, CefWebURLRequestCppToC::Wrap(requester),
|
||||||
|
CefRequestCppToC::Wrap(request), CefResponseCppToC::Wrap(response) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestClientCToCpp::OnHeadersReceived(
|
||||||
|
CefRefPtr<CefWebURLRequest> requester, CefRefPtr<CefResponse> response)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, on_headers_received))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->on_headers_received(struct_, CefWebURLRequestCppToC::Wrap(requester),
|
||||||
|
CefResponseCppToC::Wrap(response) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestClientCToCpp::OnProgress(
|
||||||
|
CefRefPtr<CefWebURLRequest> requester, uint64 bytesSent,
|
||||||
|
uint64 totalBytesToBeSent)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, on_progress))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->on_progress(struct_, CefWebURLRequestCppToC::Wrap(requester),
|
||||||
|
bytesSent, totalBytesToBeSent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestClientCToCpp::OnData(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
const void* data, int dataLength)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, on_data))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->on_data(struct_, CefWebURLRequestCppToC::Wrap(requester),
|
||||||
|
data, dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CefWebURLRequestClientCToCpp::OnError(
|
||||||
|
CefRefPtr<CefWebURLRequest> requester, ErrorCode errorCode)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, on_error))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->on_error(struct_, CefWebURLRequestCppToC::Wrap(requester),
|
||||||
|
errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
template<> long CefCToCpp<CefWebURLRequestClientCToCpp, CefWebURLRequestClient,
|
||||||
|
cef_web_urlrequest_client_t>::DebugObjCt = 0;
|
||||||
|
#endif
|
||||||
|
|
52
libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h
Normal file
52
libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file was generated by the CEF translator tool and should not edited
|
||||||
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
|
// more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _WEBURLREQUESTCLIENT_CTOCPP_H
|
||||||
|
#define _WEBURLREQUESTCLIENT_CTOCPP_H
|
||||||
|
|
||||||
|
#ifndef BUILDING_CEF_SHARED
|
||||||
|
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
||||||
|
#else // BUILDING_CEF_SHARED
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "include/cef_capi.h"
|
||||||
|
#include "libcef_dll/ctocpp/ctocpp.h"
|
||||||
|
|
||||||
|
// Wrap a C structure with a C++ class.
|
||||||
|
// This class may be instantiated and accessed DLL-side only.
|
||||||
|
class CefWebURLRequestClientCToCpp
|
||||||
|
: public CefCToCpp<CefWebURLRequestClientCToCpp, CefWebURLRequestClient,
|
||||||
|
cef_web_urlrequest_client_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefWebURLRequestClientCToCpp(cef_web_urlrequest_client_t* str)
|
||||||
|
: CefCToCpp<CefWebURLRequestClientCToCpp, CefWebURLRequestClient,
|
||||||
|
cef_web_urlrequest_client_t>(str) {}
|
||||||
|
virtual ~CefWebURLRequestClientCToCpp() {}
|
||||||
|
|
||||||
|
// CefWebURLRequestClient methods
|
||||||
|
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
RequestState state);
|
||||||
|
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefRequest> request, CefRefPtr<CefResponse> response);
|
||||||
|
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefResponse> response);
|
||||||
|
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
uint64 bytesSent, uint64 totalBytesToBeSent);
|
||||||
|
virtual void OnData(CefRefPtr<CefWebURLRequest> requester, const void* data,
|
||||||
|
int dataLength);
|
||||||
|
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
ErrorCode errorCode);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BUILDING_CEF_SHARED
|
||||||
|
#endif // _WEBURLREQUESTCLIENT_CTOCPP_H
|
||||||
|
|
62
libcef_dll/ctocpp/web_urlrequest_ctocpp.cc
Normal file
62
libcef_dll/ctocpp/web_urlrequest_ctocpp.cc
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A portion of this file was generated by the CEF translator tool. When
|
||||||
|
// making changes by hand only do so within the body of existing static and
|
||||||
|
// virtual method implementations. See the translator.README.txt file in the
|
||||||
|
// tools directory for more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h"
|
||||||
|
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||||
|
#include "libcef_dll/ctocpp/web_urlrequest_ctocpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
// STATIC METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequest> CefWebURLRequest::CreateWebURLRequest(
|
||||||
|
CefRefPtr<CefRequest> request, CefRefPtr<CefWebURLRequestClient> client)
|
||||||
|
{
|
||||||
|
cef_request_t* requestStruct = NULL;
|
||||||
|
if(request.get())
|
||||||
|
requestStruct = CefRequestCToCpp::Unwrap(request);
|
||||||
|
|
||||||
|
cef_web_urlrequest_client_t* clientStruct = NULL;
|
||||||
|
if(client.get())
|
||||||
|
clientStruct = CefWebURLRequestClientCppToC::Wrap(client);
|
||||||
|
|
||||||
|
cef_web_urlrequest_t* impl =
|
||||||
|
cef_web_urlrequest_create(requestStruct, clientStruct);
|
||||||
|
if(impl)
|
||||||
|
return CefWebURLRequestCToCpp::Wrap(impl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
|
void CefWebURLRequestCToCpp::Cancel()
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, cancel))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->cancel(struct_);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefWebURLRequest::RequestState CefWebURLRequestCToCpp::GetState()
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, get_state))
|
||||||
|
return WUR_STATE_UNSENT;
|
||||||
|
|
||||||
|
return struct_->get_state(struct_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
template<> long CefCToCpp<CefWebURLRequestCToCpp, CefWebURLRequest,
|
||||||
|
cef_web_urlrequest_t>::DebugObjCt = 0;
|
||||||
|
#endif
|
||||||
|
|
42
libcef_dll/ctocpp/web_urlrequest_ctocpp.h
Normal file
42
libcef_dll/ctocpp/web_urlrequest_ctocpp.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2010 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.
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This file was generated by the CEF translator tool and should not edited
|
||||||
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
|
// more information.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef _WEBURLREQUEST_CTOCPP_H
|
||||||
|
#define _WEBURLREQUEST_CTOCPP_H
|
||||||
|
|
||||||
|
#ifndef USING_CEF_SHARED
|
||||||
|
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||||
|
#else // USING_CEF_SHARED
|
||||||
|
|
||||||
|
#include "include/cef.h"
|
||||||
|
#include "include/cef_capi.h"
|
||||||
|
#include "libcef_dll/ctocpp/ctocpp.h"
|
||||||
|
|
||||||
|
// Wrap a C structure with a C++ class.
|
||||||
|
// This class may be instantiated and accessed wrapper-side only.
|
||||||
|
class CefWebURLRequestCToCpp
|
||||||
|
: public CefCToCpp<CefWebURLRequestCToCpp, CefWebURLRequest,
|
||||||
|
cef_web_urlrequest_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CefWebURLRequestCToCpp(cef_web_urlrequest_t* str)
|
||||||
|
: CefCToCpp<CefWebURLRequestCToCpp, CefWebURLRequest,
|
||||||
|
cef_web_urlrequest_t>(str) {}
|
||||||
|
virtual ~CefWebURLRequestCToCpp() {}
|
||||||
|
|
||||||
|
// CefWebURLRequest methods
|
||||||
|
virtual void Cancel();
|
||||||
|
virtual RequestState GetState();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USING_CEF_SHARED
|
||||||
|
#endif // _WEBURLREQUEST_CTOCPP_H
|
||||||
|
|
@ -400,3 +400,74 @@ void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser)
|
|||||||
{
|
{
|
||||||
browser->GetMainFrame()->LoadURL("http://tests/xmlhttprequest");
|
browser->GetMainFrame()->LoadURL("http://tests/xmlhttprequest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
|
||||||
|
{
|
||||||
|
class RequestClient : public CefThreadSafeBase<CefWebURLRequestClient>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RequestClient(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
|
||||||
|
|
||||||
|
virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
RequestState state)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
if (state == WUR_STATE_DONE) {
|
||||||
|
buffer_ = StringReplace(buffer_, "<", "<");
|
||||||
|
buffer_ = StringReplace(buffer_, ">", ">");
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "<html><body>Source:<pre>" << buffer_ << "</pre></body></html>";
|
||||||
|
|
||||||
|
browser_->GetMainFrame()->LoadString(ss.str(),
|
||||||
|
"http://tests/weburlrequest");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefResponse> response)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefResponse> response)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
uint64 bytesSent, uint64 totalBytesToBeSent)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
const void* data, int dataLength)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
buffer_.append(static_cast<const char*>(data), dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
ErrorCode errorCode)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Load failed with error code " << errorCode;
|
||||||
|
browser_->GetMainFrame()->LoadString(ss.str(),
|
||||||
|
"http://tests/weburlrequest");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CefRefPtr<CefBrowser> browser_;
|
||||||
|
std::string buffer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
|
||||||
|
request->SetURL("http://www.google.com");
|
||||||
|
|
||||||
|
CefRefPtr<CefWebURLRequestClient> client(new RequestClient(browser));
|
||||||
|
CefRefPtr<CefWebURLRequest> requester(
|
||||||
|
CefWebURLRequest::CreateWebURLRequest(request, client));
|
||||||
|
}
|
||||||
|
@ -438,5 +438,6 @@ void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser);
|
|||||||
void RunWebGLTest(CefRefPtr<CefBrowser> browser);
|
void RunWebGLTest(CefRefPtr<CefBrowser> browser);
|
||||||
void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser);
|
void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser);
|
||||||
void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser);
|
void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser);
|
||||||
|
void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser);
|
||||||
|
|
||||||
#endif // _CEFCLIENT_H
|
#endif // _CEFCLIENT_H
|
||||||
|
@ -77,6 +77,7 @@ BEGIN
|
|||||||
MENUITEM "UI App Example", ID_TESTS_UIAPP
|
MENUITEM "UI App Example", ID_TESTS_UIAPP
|
||||||
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
|
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
|
||||||
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
|
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
|
||||||
|
MENUITEM "WebURLRequest", ID_TESTS_WEBURLREQUEST
|
||||||
MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS
|
MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS
|
||||||
MENUITEM "Accelerated Layers", ID_TESTS_ACCELERATEDLAYERS
|
MENUITEM "Accelerated Layers", ID_TESTS_ACCELERATEDLAYERS
|
||||||
MENUITEM "WebGL", ID_TESTS_WEBGL
|
MENUITEM "WebGL", ID_TESTS_WEBGL
|
||||||
|
@ -535,6 +535,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
if(browser.get())
|
if(browser.get())
|
||||||
RunXMLHTTPRequestTest(browser);
|
RunXMLHTTPRequestTest(browser);
|
||||||
return 0;
|
return 0;
|
||||||
|
case ID_TESTS_WEBURLREQUEST:
|
||||||
|
if (browser.get())
|
||||||
|
RunWebURLRequestTest(browser);
|
||||||
|
return 0;
|
||||||
case ID_TESTS_ZOOM_IN:
|
case ID_TESTS_ZOOM_IN:
|
||||||
if(browser.get())
|
if(browser.get())
|
||||||
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
|
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#define ID_TESTS_ZOOM_RESET 32787
|
#define ID_TESTS_ZOOM_RESET 32787
|
||||||
#define ID_TESTS_DEVTOOLS_SHOW 32788
|
#define ID_TESTS_DEVTOOLS_SHOW 32788
|
||||||
#define ID_TESTS_DEVTOOLS_CLOSE 32789
|
#define ID_TESTS_DEVTOOLS_CLOSE 32789
|
||||||
|
#define ID_TESTS_WEBURLREQUEST 32790
|
||||||
#define IDC_STATIC -1
|
#define IDC_STATIC -1
|
||||||
#define IDS_LOGO 1000
|
#define IDS_LOGO 1000
|
||||||
#define IDS_UIPLUGIN 1001
|
#define IDS_UIPLUGIN 1001
|
||||||
|
@ -298,6 +298,9 @@ TEST(RequestTest, SendRecv)
|
|||||||
ASSERT_TRUE(g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled);
|
ASSERT_TRUE(g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable this test if you have applied the patches for issue #42.
|
||||||
|
#if 0
|
||||||
|
|
||||||
bool g_RequestHistoryNavTestDidLoadRequest;
|
bool g_RequestHistoryNavTestDidLoadRequest;
|
||||||
bool g_RequestHistoryNavTestDidReloadRequest;
|
bool g_RequestHistoryNavTestDidReloadRequest;
|
||||||
|
|
||||||
@ -430,3 +433,5 @@ TEST(RequestTest, HistoryNav)
|
|||||||
ASSERT_TRUE(g_RequestHistoryNavTestDidLoadRequest);
|
ASSERT_TRUE(g_RequestHistoryNavTestDidLoadRequest);
|
||||||
ASSERT_TRUE(g_RequestHistoryNavTestDidReloadRequest);
|
ASSERT_TRUE(g_RequestHistoryNavTestDidReloadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // 0
|
||||||
|
560
tests/unittests/web_urlrequest_unittest.cc
Normal file
560
tests/unittests/web_urlrequest_unittest.cc
Normal file
@ -0,0 +1,560 @@
|
|||||||
|
// Copyright (c) 2011 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.
|
||||||
|
|
||||||
|
#include "test_handler.h"
|
||||||
|
|
||||||
|
//#define WEB_URLREQUEST_DEBUG
|
||||||
|
|
||||||
|
class TrackCallback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TrackCallback(): gotit_(false) {}
|
||||||
|
void yes() { gotit_ = true; }
|
||||||
|
bool isSet() { return gotit_; }
|
||||||
|
operator bool() const { return gotit_; }
|
||||||
|
protected:
|
||||||
|
bool gotit_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestResults
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestResults()
|
||||||
|
: errorCode(0), contentLength(0), statusCode(0), redirectCount(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int errorCode;
|
||||||
|
size_t contentLength;
|
||||||
|
int statusCode;
|
||||||
|
CefString statusText;
|
||||||
|
CefString contentLengthHeader;
|
||||||
|
CefString allHeaders;
|
||||||
|
CefResponse::HeaderMap headerMap;
|
||||||
|
|
||||||
|
int redirectCount;
|
||||||
|
|
||||||
|
TrackCallback
|
||||||
|
got_redirect,
|
||||||
|
got_deleted,
|
||||||
|
got_started,
|
||||||
|
got_headers,
|
||||||
|
got_loading,
|
||||||
|
got_done,
|
||||||
|
got_progress,
|
||||||
|
got_abort,
|
||||||
|
got_error;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BrowserTestHandler : public TestHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Cancel at state WUR_STATE_UNSENT means that no cancellation
|
||||||
|
// will occur since that state change is never fired.
|
||||||
|
BrowserTestHandler(TestResults &tr,
|
||||||
|
cef_weburlrequest_state_t cancelAtState = WUR_STATE_UNSENT):
|
||||||
|
test_results_(tr), cancelAtState_(cancelAtState) { }
|
||||||
|
|
||||||
|
virtual void RunTest()
|
||||||
|
{
|
||||||
|
std::stringstream testHtml;
|
||||||
|
testHtml <<
|
||||||
|
"<html><body>"
|
||||||
|
"<h1>Testing Web Url Request...</h1>"
|
||||||
|
"</body></html>";
|
||||||
|
|
||||||
|
AddResource("http://tests/run.html", testHtml.str(), "text/html");
|
||||||
|
CreateBrowser("http://tests/run.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
bool isMainContent,
|
||||||
|
int httpStatusCode)
|
||||||
|
{
|
||||||
|
StartTest();
|
||||||
|
return RV_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCompleted()
|
||||||
|
{
|
||||||
|
DestroyTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void StartTest() = 0;
|
||||||
|
|
||||||
|
cef_weburlrequest_state_t cancelAtState_;
|
||||||
|
|
||||||
|
TestResults& test_results_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestWebURLRequestClient:
|
||||||
|
public CefThreadSafeBase<CefWebURLRequestClient>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestWebURLRequestClient(TestResults& tr, BrowserTestHandler* browser):
|
||||||
|
test_results_(tr), browser_(browser), cancelAtState_(WUR_STATE_UNSENT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~TestWebURLRequestClient()
|
||||||
|
{
|
||||||
|
test_results_.got_deleted.yes();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MaybeCancelRequest(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
RequestState state)
|
||||||
|
{
|
||||||
|
if (cancelAtState_ == state) {
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf(" Cancelling at state %d\n", cancelAtState_);
|
||||||
|
#endif
|
||||||
|
requester->Cancel();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
RequestState state)
|
||||||
|
{
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("OnStateChange(0x%p, %d)\n", requester.get(), state);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (MaybeCancelRequest(requester, state))
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch ( state ) {
|
||||||
|
case WUR_STATE_STARTED:
|
||||||
|
test_results_.got_started.yes();
|
||||||
|
break;
|
||||||
|
case WUR_STATE_HEADERS_RECEIVED:
|
||||||
|
test_results_.got_headers.yes();
|
||||||
|
break;
|
||||||
|
case WUR_STATE_LOADING:
|
||||||
|
test_results_.got_loading.yes();
|
||||||
|
break;
|
||||||
|
case WUR_STATE_DONE:
|
||||||
|
test_results_.got_done.yes();
|
||||||
|
if ( contents_.length() ) {
|
||||||
|
size_t len = contents_.length();
|
||||||
|
test_results_.contentLength = len;
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("Response: %d - %s\n", len, contents_.c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
TestCompleted();
|
||||||
|
break;
|
||||||
|
case WUR_STATE_ABORT:
|
||||||
|
test_results_.got_abort.yes();
|
||||||
|
TestCompleted();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefResponse> response)
|
||||||
|
{
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("OnRedirect(0x%p, 0x%p, 0x%p)\n",
|
||||||
|
requester.get(), request.get(), response.get());
|
||||||
|
#endif
|
||||||
|
test_results_.got_redirect.yes();
|
||||||
|
++test_results_.redirectCount;
|
||||||
|
|
||||||
|
CefString url = request->GetURL();
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("URL = %s\n", url.ToString().c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefRefPtr<CefResponse> response)
|
||||||
|
{
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("OnHeadersReceived(0x%p, 0x%p)\n", requester.get(), response.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
test_results_.statusCode = response->GetStatus();
|
||||||
|
test_results_.statusText = response->GetStatusText();
|
||||||
|
test_results_.contentLengthHeader = response->GetHeader( "Content-Length" );
|
||||||
|
response->GetHeaderMap(test_results_.headerMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnData(CefRefPtr<CefWebURLRequest> requester, const void *data,
|
||||||
|
int dataLength)
|
||||||
|
{
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("OnData(0x%p, 0x%p, %d)\n", requester.get(), data, dataLength);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Add data to buffer, create if not already
|
||||||
|
contents_.append( (const char *) data, dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCompleted()
|
||||||
|
{
|
||||||
|
browser_->TestCompleted();
|
||||||
|
browser_ = NULL;
|
||||||
|
requester_ = NULL;
|
||||||
|
Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnProgress(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
uint64 bytesSent,
|
||||||
|
uint64 totalBytesToBeSent)
|
||||||
|
{
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("OnProgress(0x%p, %d, %d)\n", requester.get(),
|
||||||
|
(unsigned int)bytesSent, (unsigned int)totalBytesToBeSent);
|
||||||
|
#endif
|
||||||
|
test_results_.got_progress.yes();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnError(CefRefPtr<CefWebURLRequest> requester,
|
||||||
|
CefWebURLRequestClient::ErrorCode errorCode)
|
||||||
|
{
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("Error(0x%p, %d)\n", requester.get(), errorCode);
|
||||||
|
#endif
|
||||||
|
test_results_.errorCode = static_cast<int>(errorCode);
|
||||||
|
test_results_.got_error.yes();
|
||||||
|
TestCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Run(CefRefPtr<CefRequest> req, RequestState
|
||||||
|
cancelAtState=WUR_STATE_UNSENT)
|
||||||
|
{
|
||||||
|
if ( requester_.get() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cancelAtState_ = cancelAtState;
|
||||||
|
request_ = req;
|
||||||
|
|
||||||
|
// Keep ourselves alive... blanced in TestCompleted() when done.
|
||||||
|
AddRef();
|
||||||
|
|
||||||
|
requester_ = CefWebURLRequest::CreateWebURLRequest(request_, this);
|
||||||
|
#ifdef WEB_URLREQUEST_DEBUG
|
||||||
|
printf("Created requester at address 0x%p\n", requester_.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return requester_.get() != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TestResults &test_results_;
|
||||||
|
RequestState cancelAtState_;
|
||||||
|
|
||||||
|
CefRefPtr<BrowserTestHandler> browser_;
|
||||||
|
CefRefPtr<CefWebURLRequest> requester_;
|
||||||
|
CefRefPtr<CefRequest> request_;
|
||||||
|
std::string contents_;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(WebURLRequestTest, GET)
|
||||||
|
{
|
||||||
|
class BrowserForTest : public BrowserTestHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
|
||||||
|
|
||||||
|
void StartTest()
|
||||||
|
{
|
||||||
|
CefRefPtr<CefRequest> req;
|
||||||
|
CefRefPtr<CefPostData> postdata;
|
||||||
|
CefRequest::HeaderMap headers;
|
||||||
|
|
||||||
|
req = CefRequest::CreateRequest();
|
||||||
|
|
||||||
|
CefString url(
|
||||||
|
"http://search.twitter.com/search.json?result_type=popular&q=webkit");
|
||||||
|
CefString method("GET");
|
||||||
|
|
||||||
|
req->Set(url, method, postdata, headers);
|
||||||
|
|
||||||
|
CefRefPtr<TestWebURLRequestClient> handler =
|
||||||
|
new TestWebURLRequestClient(test_results_, this);
|
||||||
|
|
||||||
|
req->SetFlags((CefRequest::RequestFlags)(
|
||||||
|
WUR_FLAG_SKIP_CACHE |
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING |
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS |
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
|
||||||
|
|
||||||
|
ASSERT_TRUE(handler->Run(req));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TestResults tr;
|
||||||
|
CefRefPtr<BrowserForTest> browser = new BrowserForTest(tr);
|
||||||
|
browser->ExecuteTest();
|
||||||
|
|
||||||
|
EXPECT_TRUE(tr.got_started);
|
||||||
|
EXPECT_TRUE(tr.got_headers);
|
||||||
|
EXPECT_TRUE(tr.got_loading);
|
||||||
|
EXPECT_TRUE(tr.got_done);
|
||||||
|
EXPECT_TRUE(tr.got_deleted);
|
||||||
|
EXPECT_FALSE(tr.got_abort);
|
||||||
|
EXPECT_FALSE(tr.got_error);
|
||||||
|
EXPECT_FALSE(tr.got_redirect);
|
||||||
|
EXPECT_FALSE(tr.got_progress);
|
||||||
|
EXPECT_GT((int)tr.contentLength, 0);
|
||||||
|
EXPECT_EQ(200, tr.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WebURLRequestTest, POST)
|
||||||
|
{
|
||||||
|
class BrowserForTest : public BrowserTestHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
|
||||||
|
|
||||||
|
void StartTest()
|
||||||
|
{
|
||||||
|
CefRefPtr<CefRequest> req;
|
||||||
|
CefRefPtr<CefPostData> postdata;
|
||||||
|
CefRefPtr<CefPostDataElement> postitem;
|
||||||
|
CefRequest::HeaderMap headers;
|
||||||
|
|
||||||
|
headers.insert(std::make_pair("Content-Type",
|
||||||
|
"application/x-www-form-urlencoded"));
|
||||||
|
|
||||||
|
req = CefRequest::CreateRequest();
|
||||||
|
|
||||||
|
CefString url("http://pastebin.com/api_public.php");
|
||||||
|
CefString method("POST");
|
||||||
|
|
||||||
|
postdata = CefPostData::CreatePostData();
|
||||||
|
postitem = CefPostDataElement::CreatePostDataElement();
|
||||||
|
|
||||||
|
static char posttext[] =
|
||||||
|
"paste_name=CEF%20Test%20Post&paste_code=testing a post call.&paste_expire_date=10M";
|
||||||
|
|
||||||
|
postitem->SetToBytes(strlen(posttext), posttext);
|
||||||
|
postdata->AddElement(postitem);
|
||||||
|
|
||||||
|
req->Set(url, method, postdata, headers);
|
||||||
|
|
||||||
|
CefRefPtr<TestWebURLRequestClient> handler =
|
||||||
|
new TestWebURLRequestClient(test_results_, this);
|
||||||
|
|
||||||
|
req->SetFlags((CefRequest::RequestFlags)(
|
||||||
|
WUR_FLAG_SKIP_CACHE |
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING |
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS |
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
|
||||||
|
|
||||||
|
ASSERT_TRUE(handler->Run(req));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TestResults tr;
|
||||||
|
CefRefPtr<BrowserForTest> browser = new BrowserForTest(tr);
|
||||||
|
browser->ExecuteTest();
|
||||||
|
|
||||||
|
EXPECT_TRUE(tr.got_started);
|
||||||
|
EXPECT_TRUE(tr.got_headers);
|
||||||
|
EXPECT_TRUE(tr.got_loading);
|
||||||
|
EXPECT_TRUE(tr.got_done);
|
||||||
|
EXPECT_TRUE(tr.got_deleted);
|
||||||
|
EXPECT_FALSE(tr.got_redirect);
|
||||||
|
EXPECT_TRUE(tr.got_progress);
|
||||||
|
EXPECT_FALSE(tr.got_error);
|
||||||
|
EXPECT_FALSE(tr.got_abort);
|
||||||
|
EXPECT_GT((int)tr.contentLength, 0);
|
||||||
|
EXPECT_EQ(200, tr.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WebURLRequestTest, BADHOST)
|
||||||
|
{
|
||||||
|
class BrowserForTest : public BrowserTestHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
|
||||||
|
|
||||||
|
void StartTest()
|
||||||
|
{
|
||||||
|
CefRefPtr<CefRequest> req;
|
||||||
|
CefRefPtr<CefPostData> postdata;
|
||||||
|
CefRefPtr<CefPostDataElement> postitem;
|
||||||
|
CefRequest::HeaderMap headers;
|
||||||
|
|
||||||
|
req = CefRequest::CreateRequest();
|
||||||
|
|
||||||
|
CefString url("http://this.host.does.not.exist/not/really/here");
|
||||||
|
CefString method("GET");
|
||||||
|
|
||||||
|
req->Set(url, method, postdata, headers);
|
||||||
|
|
||||||
|
CefRefPtr<TestWebURLRequestClient> handler =
|
||||||
|
new TestWebURLRequestClient(test_results_, this);
|
||||||
|
|
||||||
|
req->SetFlags((CefRequest::RequestFlags)(
|
||||||
|
WUR_FLAG_SKIP_CACHE |
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING |
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS |
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
|
||||||
|
|
||||||
|
ASSERT_TRUE(handler->Run(req));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TestResults tr;
|
||||||
|
CefRefPtr<BrowserForTest> browser = new BrowserForTest(tr);
|
||||||
|
browser->ExecuteTest();
|
||||||
|
|
||||||
|
// NOTE: THIS TEST WILL FAIL IF YOUR ISP REDIRECTS YOU TO
|
||||||
|
// THEIR SEARCH PAGE ON NXDOMAIN ERRORS.
|
||||||
|
EXPECT_TRUE(tr.got_started);
|
||||||
|
EXPECT_FALSE(tr.got_headers);
|
||||||
|
EXPECT_FALSE(tr.got_loading);
|
||||||
|
EXPECT_FALSE(tr.got_done);
|
||||||
|
EXPECT_TRUE(tr.got_deleted);
|
||||||
|
EXPECT_FALSE(tr.got_redirect);
|
||||||
|
EXPECT_FALSE(tr.got_progress);
|
||||||
|
EXPECT_FALSE(tr.got_abort);
|
||||||
|
EXPECT_TRUE(tr.got_error);
|
||||||
|
EXPECT_EQ(ERR_NAME_NOT_RESOLVED, tr.errorCode);
|
||||||
|
EXPECT_EQ(0, (int)tr.contentLength);
|
||||||
|
EXPECT_EQ(0, tr.statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define COUNTOF_(ar) (sizeof(ar)/sizeof(ar[0]))
|
||||||
|
|
||||||
|
TEST(WebURLRequestTest, CANCEL)
|
||||||
|
{
|
||||||
|
class BrowserForTest : public BrowserTestHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BrowserForTest(TestResults &tr, cef_weburlrequest_state_t cancelAtState)
|
||||||
|
: BrowserTestHandler(tr, cancelAtState)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartTest()
|
||||||
|
{
|
||||||
|
CefRefPtr<CefRequest> req;
|
||||||
|
CefRefPtr<CefPostData> postdata;
|
||||||
|
CefRefPtr<CefPostDataElement> postitem;
|
||||||
|
CefRequest::HeaderMap headers;
|
||||||
|
|
||||||
|
req = CefRequest::CreateRequest();
|
||||||
|
|
||||||
|
CefString url(
|
||||||
|
"http://search.twitter.com/search.json?result_type=popular&q=webkit");
|
||||||
|
CefString method("GET");
|
||||||
|
|
||||||
|
req->Set(url, method, postdata, headers);
|
||||||
|
|
||||||
|
CefRefPtr<TestWebURLRequestClient> handler =
|
||||||
|
new TestWebURLRequestClient(test_results_, this);
|
||||||
|
|
||||||
|
req->SetFlags((CefRequest::RequestFlags)(
|
||||||
|
WUR_FLAG_SKIP_CACHE |
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING |
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS |
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
|
||||||
|
|
||||||
|
ASSERT_TRUE(handler->Run(req, cancelAtState_));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
cef_weburlrequest_state_t cancelAt[] = {
|
||||||
|
WUR_STATE_STARTED,
|
||||||
|
WUR_STATE_HEADERS_RECEIVED,
|
||||||
|
WUR_STATE_LOADING
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i=0; i < COUNTOF_(cancelAt); ++i) {
|
||||||
|
TestResults tr;
|
||||||
|
CefRefPtr<BrowserForTest> browser = new BrowserForTest(tr, cancelAt[i]);
|
||||||
|
browser->ExecuteTest();
|
||||||
|
EXPECT_TRUE(tr.got_abort);
|
||||||
|
EXPECT_TRUE(tr.got_deleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable this test if you have installed the php test page.
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
TEST(WebURLRequestTest, REDIRECT)
|
||||||
|
{
|
||||||
|
/* // PHP Script for a local server to test this:
|
||||||
|
// You can run a zwamp server on windows to run this.
|
||||||
|
// http://sourceforge.net/projects/zwamp/
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$max = isset($_GET['max']) ? $_GET['max'] : 2;
|
||||||
|
$step = isset($_GET['step']) ? $_GET['step'] : 1;
|
||||||
|
|
||||||
|
if ($step < $max)
|
||||||
|
{
|
||||||
|
$url = $_SERVER['PHP_SELF'];
|
||||||
|
++$step;
|
||||||
|
header( $_SERVER["SERVER_PROTOCOL"] . " 301 Permanently moved");
|
||||||
|
header("Location: $url?max=$max&step=$step", true, 301);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
header("Content: text/plain");
|
||||||
|
echo "Redirect completed after $max times.";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class BrowserForTest : public BrowserTestHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { }
|
||||||
|
|
||||||
|
void StartTest()
|
||||||
|
{
|
||||||
|
CefRefPtr<CefRequest> req;
|
||||||
|
CefRefPtr<CefPostData> postdata;
|
||||||
|
CefRefPtr<CefPostDataElement> postitem;
|
||||||
|
CefRequest::HeaderMap headers;
|
||||||
|
|
||||||
|
req = CefRequest::CreateRequest();
|
||||||
|
|
||||||
|
CefString url("http://localhost/cef/redirect.php?max=4");
|
||||||
|
CefString method("GET");
|
||||||
|
|
||||||
|
req->Set(url, method, postdata, headers);
|
||||||
|
|
||||||
|
CefRefPtr<TestWebURLRequestClient> handler =
|
||||||
|
new TestWebURLRequestClient(test_results_, this);
|
||||||
|
|
||||||
|
req->SetFlags((CefRequest::RequestFlags)(
|
||||||
|
WUR_FLAG_SKIP_CACHE |
|
||||||
|
WUR_FLAG_REPORT_LOAD_TIMING |
|
||||||
|
WUR_FLAG_REPORT_RAW_HEADERS |
|
||||||
|
WUR_FLAG_REPORT_UPLOAD_PROGRESS));
|
||||||
|
|
||||||
|
ASSERT_TRUE(handler->Run(req, cancelAtState_));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TestResults tr;
|
||||||
|
CefRefPtr<BrowserForTest> browser = new BrowserForTest(tr);
|
||||||
|
browser->ExecuteTest();
|
||||||
|
EXPECT_TRUE(tr.got_started);
|
||||||
|
EXPECT_TRUE(tr.got_headers);
|
||||||
|
EXPECT_TRUE(tr.got_loading);
|
||||||
|
EXPECT_TRUE(tr.got_done);
|
||||||
|
EXPECT_TRUE(tr.got_deleted);
|
||||||
|
EXPECT_TRUE(tr.got_redirect);
|
||||||
|
EXPECT_FALSE(tr.got_progress);
|
||||||
|
EXPECT_FALSE(tr.got_error);
|
||||||
|
EXPECT_FALSE(tr.got_abort);
|
||||||
|
EXPECT_GT((int)tr.contentLength, 0);
|
||||||
|
EXPECT_EQ(200, tr.statusCode);
|
||||||
|
EXPECT_EQ(3, tr.redirectCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // 0
|
@ -1073,6 +1073,7 @@ class obj_analysis:
|
|||||||
'void' : 'void',
|
'void' : 'void',
|
||||||
'int' : 'int',
|
'int' : 'int',
|
||||||
'int64' : 'int64',
|
'int64' : 'int64',
|
||||||
|
'uint64' : 'uint64',
|
||||||
'double' : 'double',
|
'double' : 'double',
|
||||||
'long' : 'long',
|
'long' : 'long',
|
||||||
'unsigned long' : 'unsigned long',
|
'unsigned long' : 'unsigned long',
|
||||||
|
Reference in New Issue
Block a user