diff --git a/cef.gyp b/cef.gyp index 1909488aa..3c9ed20e5 100644 --- a/cef.gyp +++ b/cef.gyp @@ -185,6 +185,7 @@ 'tests/unittests/test_suite.h', 'tests/unittests/url_unittest.cc', 'tests/unittests/v8_unittest.cc', + 'tests/unittests/web_urlrequest_unittest.cc', 'tests/unittests/xml_reader_unittest.cc', 'tests/unittests/zip_reader_unittest.cc', ], @@ -305,12 +306,16 @@ 'libcef_dll/cpptoc/post_data_element_cpptoc.h', 'libcef_dll/cpptoc/request_cpptoc.cc', '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.h', 'libcef_dll/cpptoc/stream_writer_cpptoc.cc', 'libcef_dll/cpptoc/stream_writer_cpptoc.h', 'libcef_dll/cpptoc/v8value_cpptoc.cc', '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.h', 'libcef_dll/cpptoc/zip_reader_cpptoc.cc', @@ -330,6 +335,8 @@ 'libcef_dll/ctocpp/task_ctocpp.h', 'libcef_dll/ctocpp/v8handler_ctocpp.cc', '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.h', 'libcef_dll/libcef_dll.cc', @@ -387,8 +394,12 @@ 'libcef_dll/cpptoc/scheme_handler_cpptoc.h', 'libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc', '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.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.h', 'libcef_dll/ctocpp/browser_ctocpp.cc', @@ -402,14 +413,16 @@ 'libcef_dll/ctocpp/post_data_element_ctocpp.h', 'libcef_dll/ctocpp/request_ctocpp.cc', '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.h', 'libcef_dll/ctocpp/stream_writer_ctocpp.cc', '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.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.h', 'libcef_dll/ctocpp/zip_reader_ctocpp.cc', @@ -544,8 +557,12 @@ 'libcef/dom_storage_namespace.cc', 'libcef/dom_storage_namespace.h', 'libcef/external_protocol_handler.h', + 'libcef/http_header_utils.cc', + 'libcef/http_header_utils.h', 'libcef/request_impl.cc', 'libcef/request_impl.h', + 'libcef/response_impl.cc', + 'libcef/response_impl.h', 'libcef/scheme_impl.cc', 'libcef/simple_clipboard_impl.cc', 'libcef/stream_impl.cc', @@ -553,6 +570,8 @@ 'libcef/tracker.h', 'libcef/v8_impl.cc', 'libcef/v8_impl.h', + 'libcef/web_urlrequest_impl.cc', + 'libcef/web_urlrequest_impl.h', 'libcef/webview_host.h', 'libcef/webwidget_host.h', 'libcef/xml_reader_impl.cc', diff --git a/include/cef.h b/include/cef.h index 68df98fcd..251d4b697 100644 --- a/include/cef.h +++ b/include/cef.h @@ -53,6 +53,7 @@ class CefPopupFeatures; class CefPostData; class CefPostDataElement; class CefRequest; +class CefResponse; class CefSchemeHandler; class CefSchemeHandlerFactory; class CefSettings; @@ -62,6 +63,8 @@ class CefTask; class CefURLParts; class CefV8Handler; class CefV8Value; +class CefWebURLRequest; +class CefWebURLRequestClient; // This function should be called on the main application thread to initialize @@ -911,6 +914,7 @@ class CefRequest : public CefBase { public: typedef std::map HeaderMap; + typedef cef_weburlrequest_flags_t RequestFlags; // Create a new CefRequest object. /*--cef()--*/ @@ -947,6 +951,19 @@ public: const CefString& method, CefRefPtr postData, 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 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 // methods of this class may be called on any thread. /*--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 CreateWebURLRequest( + CefRefPtr request, + CefRefPtr 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 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 requester, + CefRefPtr request, + CefRefPtr response) =0; + + // Notifies the client of the response data. + /*--cef()--*/ + virtual void OnHeadersReceived(CefRefPtr requester, + CefRefPtr response) =0; + + // Notifies the client of the upload progress. + /*--cef()--*/ + virtual void OnProgress(CefRefPtr requester, + uint64 bytesSent, uint64 totalBytesToBeSent) =0; + + // Notifies the client that content has been received. + /*--cef()--*/ + virtual void OnData(CefRefPtr 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 requester, + ErrorCode errorCode) =0; +}; + + // 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 object. diff --git a/include/cef_capi.h b/include/cef_capi.h index 6ccb65ff7..82d86b23d 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -709,6 +709,20 @@ typedef struct _cef_request_t const cef_string_t* method, struct _cef_post_data_t* postData, 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; @@ -792,6 +806,33 @@ typedef struct _cef_post_data_element_t 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 // functions of this structure may be called on any thread. typedef struct _cef_read_handler_t @@ -1098,6 +1139,74 @@ typedef struct _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. // The functions of this structure should only be called on the thread that // creates the object. diff --git a/include/cef_types.h b/include/cef_types.h index 82d8ed696..ec5a3f906 100644 --- a/include/cef_types.h +++ b/include/cef_types.h @@ -46,8 +46,10 @@ // not have typedef mismatches, we do the same on LP64. #if __LP64__ typedef long int64; +typedef unsigned long uint64; #else typedef long long int64; +typedef unsigned long long uint64; #endif #ifdef __cplusplus @@ -431,6 +433,28 @@ enum cef_postdataelement_type_t 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. enum cef_handler_keyevent_type_t { diff --git a/libcef/browser_resource_loader_bridge.cc b/libcef/browser_resource_loader_bridge.cc index 0823f6adb..43a48ac10 100644 --- a/libcef/browser_resource_loader_bridge.cc +++ b/libcef/browser_resource_loader_bridge.cc @@ -42,6 +42,7 @@ #include "cef_process_io_thread.h" #include "external_protocol_handler.h" #include "request_impl.h" +#include "http_header_utils.h" #include "base/file_path.h" #include "base/file_util.h" @@ -294,7 +295,7 @@ class RequestProxy : public net::URLRequest::Delegate, // Transfer request headers CefRequest::HeaderMap headerMap; - CefRequestImpl::ParseHeaders(params->headers, headerMap); + HttpHeaderUtils::ParseHeaders(params->headers, headerMap); headerMap.insert(std::make_pair("Referrer", params->referrer.spec())); requestimpl->SetHeaderMap(headerMap); @@ -338,7 +339,7 @@ class RequestProxy : public net::URLRequest::Delegate, params->referrer = GURL(std::string(referrer->second)); headerMap.erase(referrer); } - params->headers = CefRequestImpl::GenerateHeaders(headerMap); + params->headers = HttpHeaderUtils::GenerateHeaders(headerMap); // Observe post data from request. CefRefPtr postData = request->GetPostData(); diff --git a/libcef/browser_webkit_glue.cc b/libcef/browser_webkit_glue.cc index be80d8fa0..5058bc83b 100644 --- a/libcef/browser_webkit_glue.cc +++ b/libcef/browser_webkit_glue.cc @@ -7,6 +7,7 @@ #include "third_party/WebKit/Source/WebCore/config.h" MSVC_PUSH_WARNING_LEVEL(0); +#include "DocumentLoader.h" #include "MemoryCache.h" #include "TextEncoding.h" #include "third_party/WebKit/WebKit/chromium/src/WebFrameImpl.h" @@ -121,6 +122,14 @@ FrameLoadType GetFrameLoadType(WebKit::WebFrame* frame) return FLT_UNKNOWN; } +bool FrameHasSubsituteData(WebKit::WebFrame* frame) +{ + WebFrameImpl* webFrameImpl = static_cast(frame); + WebCore::DocumentLoader* docLoader = + webFrameImpl->frame()->loader()->documentLoader(); + return docLoader->substituteData().isValid(); +} + void CloseIdleConnections() { // Used in benchmarking, Ignored for CEF. } diff --git a/libcef/browser_webkit_glue.h b/libcef/browser_webkit_glue.h index 3349c7614..a9d8a7b69 100644 --- a/libcef/browser_webkit_glue.h +++ b/libcef/browser_webkit_glue.h @@ -50,6 +50,9 @@ enum FrameLoadType { // Returns the frame load type. FrameLoadType GetFrameLoadType(WebKit::WebFrame* frame); +// Returns true if the frame is loading substitute data. +bool FrameHasSubsituteData(WebKit::WebFrame* frame); + // Clear all cached data. void ClearCache(); diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index 8627473d1..cc1c788f9 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -717,6 +717,9 @@ void BrowserWebViewDelegate::didCommitProvisionalLoad( if (is_new_navigation) { // New navigations will be the main content. is_main_content_ = true; + } else if(webkit_glue::FrameHasSubsituteData(frame)) { + // Loading from a string will be main content. + is_main_content_ = true; } else { // Session history navigations and reloads will be the main content. webkit_glue::FrameLoadType load_type = diff --git a/libcef/http_header_utils.cc b/libcef/http_header_utils.cc new file mode 100644 index 000000000..89e5b389b --- /dev/null +++ b/libcef/http_header_utils.cc @@ -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 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 diff --git a/libcef/http_header_utils.h b/libcef/http_header_utils.h new file mode 100644 index 000000000..1f022c87d --- /dev/null +++ b/libcef/http_header_utils.h @@ -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 diff --git a/libcef/request_impl.cc b/libcef/request_impl.cc index ad1cbaed3..3e452e497 100644 --- a/libcef/request_impl.cc +++ b/libcef/request_impl.cc @@ -6,13 +6,13 @@ #include "browser_webkit_glue.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 "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" - -using net::HttpResponseHeaders; +#include "http_header_utils.h" +using WebKit::WebHTTPBody; +using WebKit::WebString; +using WebKit::WebURL; +using WebKit::WebURLRequest; CefRefPtr CefRequest::CreateRequest() { @@ -21,66 +21,56 @@ CefRefPtr CefRequest::CreateRequest() } CefRequestImpl::CefRequestImpl() + : method_("GET"), flags_(WUR_FLAG_NONE) { } CefString CefRequestImpl::GetURL() { - Lock(); - CefString url = url_; - Unlock(); - return url; + AutoLock lock_scope(this); + return url_; } void CefRequestImpl::SetURL(const CefString& url) { - Lock(); + AutoLock lock_scope(this); url_ = url; - Unlock(); } CefString CefRequestImpl::GetMethod() { - Lock(); - CefString method = method_; - Unlock(); - return method; + AutoLock lock_scope(this); + return method_; } void CefRequestImpl::SetMethod(const CefString& method) { - Lock(); + AutoLock lock_scope(this); method_ = method; - Unlock(); } CefRefPtr CefRequestImpl::GetPostData() { - Lock(); - CefRefPtr postData = postdata_; - Unlock(); - return postData; + AutoLock lock_scope(this); + return postdata_; } void CefRequestImpl::SetPostData(CefRefPtr postData) { - Lock(); + AutoLock lock_scope(this); postdata_ = postData; - Unlock(); } void CefRequestImpl::GetHeaderMap(HeaderMap& headerMap) { - Lock(); + AutoLock lock_scope(this); headerMap = headermap_; - Unlock(); } void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap) { - Lock(); + AutoLock lock_scope(this); headermap_ = headerMap; - Unlock(); } void CefRequestImpl::Set(const CefString& url, @@ -88,36 +78,141 @@ void CefRequestImpl::Set(const CefString& url, CefRefPtr postData, const HeaderMap& headerMap) { - Lock(); + AutoLock lock_scope(this); url_ = url; method_ = method; postdata_ = postData; headermap_ = headerMap; - Unlock(); } void CefRequestImpl::Set(net::URLRequest* request) { - SetURL(request->url().spec()); - SetMethod(request->method()); + AutoLock lock_scope(this); + + url_ = request->url().spec(); + method_ = request->method(); // Transfer request headers - HeaderMap headerMap; - GetHeaderMap(request->extra_request_headers(), headerMap); - headerMap.insert(std::make_pair(L"Referrer", request->referrer())); - SetHeaderMap(headerMap); - + GetHeaderMap(request->extra_request_headers(), headermap_); + headermap_.insert(std::make_pair(L"Referrer", request->referrer())); + // Transfer post data, if any net::UploadData* data = request->get_upload(); if (data) { - CefRefPtr postdata(CefPostData::CreatePostData()); - static_cast(postdata.get())->Set(*data); - SetPostData(postdata); + postdata_ = CefPostData::CreatePostData(); + static_cast(postdata_.get())->Set(*data); } } +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(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(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(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); do { @@ -125,26 +220,15 @@ void CefRequestImpl::GetHeaderMap(const net::HttpRequestHeaders& headers, Header } while (it.GetNext()); } +// static void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request, HeaderMap& map) { - class CefHTTPHeaderVisitor : public WebKit::WebHTTPHeaderVisitor { - 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); + HttpHeaderUtils::HeaderVisitor visitor(&map); request.visitHTTPHeaderFields(&visitor); } +// static void CefRequestImpl::SetHeaderMap(const HeaderMap& map, WebKit::WebURLRequest& request) { @@ -153,42 +237,6 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& map, 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 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::CreatePostData() { CefRefPtr postdata(new CefPostDataImpl()); @@ -201,44 +249,36 @@ CefPostDataImpl::CefPostDataImpl() size_t CefPostDataImpl::GetElementCount() { - Lock(); - size_t ct = elements_.size(); - Unlock(); - return ct; + AutoLock lock_scope(this); + return elements_.size(); } void CefPostDataImpl::GetElements(ElementVector& elements) { - Lock(); + AutoLock lock_scope(this); elements = elements_; - Unlock(); } bool CefPostDataImpl::RemoveElement(CefRefPtr element) { - bool deleted = false; - - Lock(); + AutoLock lock_scope(this); ElementVector::iterator it = elements_.begin(); for(; it != elements_.end(); ++it) { if(it->get() == element.get()) { elements_.erase(it); - deleted = true; - break; + return true; } } - Unlock(); - - return deleted; + return false; } bool CefPostDataImpl::AddElement(CefRefPtr element) { bool found = false; - Lock(); + AutoLock lock_scope(this); // check that the element isn't already in the list before adding ElementVector::const_iterator it = elements_.begin(); @@ -252,20 +292,18 @@ bool CefPostDataImpl::AddElement(CefRefPtr element) if(!found) elements_.push_back(element); - Unlock(); return !found; } void CefPostDataImpl::RemoveElements() { - Lock(); + AutoLock lock_scope(this); elements_.clear(); - Unlock(); } void CefPostDataImpl::Set(net::UploadData& data) { - Lock(); + AutoLock lock_scope(this); CefRefPtr postelem; @@ -276,13 +314,11 @@ void CefPostDataImpl::Set(net::UploadData& data) static_cast(postelem.get())->Set(*it); AddElement(postelem); } - - Unlock(); } void CefPostDataImpl::Get(net::UploadData& data) { - Lock(); + AutoLock lock_scope(this); net::UploadData::Element element; std::vector data_elements; @@ -292,13 +328,11 @@ void CefPostDataImpl::Get(net::UploadData& data) data_elements.push_back(element); } data.SetElements(data_elements); - - Unlock(); } void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data) { - Lock(); + AutoLock lock_scope(this); CefRefPtr postelem; WebKit::WebHTTPBody::Element element; @@ -310,13 +344,11 @@ void CefPostDataImpl::Set(const WebKit::WebHTTPBody& data) AddElement(postelem); } } - - Unlock(); } void CefPostDataImpl::Get(WebKit::WebHTTPBody& data) { - Lock(); + AutoLock lock_scope(this); WebKit::WebHTTPBody::Element element; ElementVector::iterator it = elements_.begin(); @@ -330,8 +362,6 @@ void CefPostDataImpl::Get(WebKit::WebHTTPBody& data) NOTREACHED(); } } - - Unlock(); } CefRefPtr CefPostDataElement::CreatePostDataElement() @@ -353,31 +383,29 @@ CefPostDataElementImpl::~CefPostDataElementImpl() void CefPostDataElementImpl::SetToEmpty() { - Lock(); + AutoLock lock_scope(this); if(type_ == PDE_TYPE_BYTES) free(data_.bytes.bytes); else if(type_ == PDE_TYPE_FILE) cef_string_clear(&data_.filename); type_ = PDE_TYPE_EMPTY; memset(&data_, 0, sizeof(data_)); - Unlock(); } void CefPostDataElementImpl::SetToFile(const CefString& fileName) { - Lock(); + AutoLock lock_scope(this); // Clear any data currently in the element SetToEmpty(); // Assign the new data type_ = PDE_TYPE_FILE; cef_string_copy(fileName.c_str(), fileName.length(), &data_.filename); - Unlock(); } void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes) { - Lock(); + AutoLock lock_scope(this); // Clear any data currently in the element SetToEmpty(); @@ -392,55 +420,49 @@ void CefPostDataElementImpl::SetToBytes(size_t size, const void* bytes) type_ = PDE_TYPE_BYTES; data_.bytes.bytes = data; data_.bytes.size = size; - Unlock(); } CefPostDataElement::Type CefPostDataElementImpl::GetType() { - Lock(); - CefPostDataElement::Type type = type_; - Unlock(); - return type; + AutoLock lock_scope(this); + return type_; } CefString CefPostDataElementImpl::GetFile() { - Lock(); + AutoLock lock_scope(this); DCHECK(type_ == PDE_TYPE_FILE); CefString filename; if(type_ == PDE_TYPE_FILE) filename.FromString(data_.filename.str, data_.filename.length, false); - Unlock(); return filename; } size_t CefPostDataElementImpl::GetBytesCount() { - Lock(); + AutoLock lock_scope(this); DCHECK(type_ == PDE_TYPE_BYTES); size_t size = 0; if(type_ == PDE_TYPE_BYTES) size = data_.bytes.size; - Unlock(); return size; } size_t CefPostDataElementImpl::GetBytes(size_t size, void* bytes) { - Lock(); + AutoLock lock_scope(this); DCHECK(type_ == PDE_TYPE_BYTES); size_t rv = 0; if(type_ == PDE_TYPE_BYTES) { rv = (size < data_.bytes.size ? size : data_.bytes.size); memcpy(bytes, data_.bytes.bytes, rv); } - Unlock(); return rv; } void CefPostDataElementImpl::Set(const net::UploadData::Element& element) { - Lock(); + AutoLock lock_scope(this); if (element.type() == net::UploadData::TYPE_BYTES) { SetToBytes(element.bytes().size(), @@ -452,13 +474,11 @@ void CefPostDataElementImpl::Set(const net::UploadData::Element& element) } else { NOTREACHED(); } - - Unlock(); } void CefPostDataElementImpl::Get(net::UploadData::Element& element) { - Lock(); + AutoLock lock_scope(this); if(type_ == PDE_TYPE_BYTES) { element.SetToBytes(static_cast(data_.bytes.bytes), data_.bytes.size); @@ -468,13 +488,11 @@ void CefPostDataElementImpl::Get(net::UploadData::Element& element) } else { NOTREACHED(); } - - Unlock(); } void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element) { - Lock(); + AutoLock lock_scope(this); if(element.type == WebKit::WebHTTPBody::Element::TypeData) { SetToBytes(element.data.size(), @@ -484,13 +502,11 @@ void CefPostDataElementImpl::Set(const WebKit::WebHTTPBody::Element& element) } else { NOTREACHED(); } - - Unlock(); } void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element) { - Lock(); + AutoLock lock_scope(this); if(type_ == PDE_TYPE_BYTES) { element.type = WebKit::WebHTTPBody::Element::TypeData; @@ -502,6 +518,4 @@ void CefPostDataElementImpl::Get(WebKit::WebHTTPBody::Element& element) } else { NOTREACHED(); } - - Unlock(); } diff --git a/libcef/request_impl.h b/libcef/request_impl.h index cd5b3828e..c79b809fe 100644 --- a/libcef/request_impl.h +++ b/libcef/request_impl.h @@ -5,7 +5,7 @@ #ifndef _REQUEST_IMPL_H #define _REQUEST_IMPL_H -#include "../include/cef.h" +#include "include/cef.h" #include "net/base/upload_data.h" #include "net/http/http_request_headers.h" #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h" @@ -34,8 +34,14 @@ public: const CefString& method, CefRefPtr postData, 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(const WebKit::WebURLRequest& request); + void Get(WebKit::WebURLRequest& request); static void GetHeaderMap(const net::HttpRequestHeaders& headers, HeaderMap& map); @@ -44,14 +50,15 @@ public: static void SetHeaderMap(const HeaderMap& map, WebKit::WebURLRequest& request); - static std::string GenerateHeaders(const HeaderMap& map); - static void ParseHeaders(const std::string& header_str, HeaderMap& map); - protected: CefString url_; CefString method_; CefRefPtr postdata_; HeaderMap headermap_; + + // The below methods are used by WebURLRequest. + RequestFlags flags_; + CefString first_party_for_cookies_; }; // Implementation of CefPostData diff --git a/libcef/response_impl.cc b/libcef/response_impl.cc new file mode 100644 index 000000000..e1d474d35 --- /dev/null +++ b/libcef/response_impl.cc @@ -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_; +} diff --git a/libcef/response_impl.h b/libcef/response_impl.h new file mode 100644 index 000000000..9c09b7547 --- /dev/null +++ b/libcef/response_impl.h @@ -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 +{ +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 diff --git a/libcef/web_urlrequest_impl.cc b/libcef/web_urlrequest_impl.cc new file mode 100644 index 000000000..8497db4c8 --- /dev/null +++ b/libcef/web_urlrequest_impl.cc @@ -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 +{ +public: + Context(CefRefPtr client) + : client_(client) + { + } + virtual ~Context() + { + } + + void initialize(CefRefPtr request); + void destroy(); + void cancel(); + + CefRefPtr client() { return client_; } + +protected: + CefRefPtr client_; + scoped_ptr url_loader_; + scoped_ptr 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 client = context_->client(); + if (client.get()) { + CefRefPtr handler = client->GetHandler(); + if (handler.get()) { + CefRefPtr cefRequest(new CefRequestImpl()); + CefRefPtr 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 client = context_->client(); + if (client.get()) { + CefRefPtr 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 client = context_->client(); + if (client.get()) { + client->DoStateChange(WUR_STATE_HEADERS_RECEIVED); + CefRefPtr handler = client->GetHandler(); + if (handler.get()) { + CefRefPtr 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 client = context_->client(); + if (client.get()) { + client->DoStateChange(WUR_STATE_LOADING); + CefRefPtr 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 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 client = context_->client(); + if (client.get() && client->GetState() != WUR_STATE_ABORT) { + client->DoStateChange(WUR_STATE_ERROR); + CefRefPtr handler = client->GetHandler(); + if (handler.get()) { + handler->OnError(client.get(), + static_cast(error.reason)); + } + } + + complete(); + } + + void complete() + { + context_->destroy(); + context_ = NULL; + } + +protected: + scoped_refptr context_; +}; + +} // namespace + + +// CefWebURLManager + +void CefWebURLRequestImpl::Context::initialize( + CefRefPtr request) +{ + REQUIRE_UIT(); + + url_loader_.reset(new webkit_glue::WebURLLoaderImpl()); + url_client_.reset(new CefWebURLLoaderClientImpl(this)); + + WebURLRequest urlRequest; + static_cast(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::CreateWebURLRequest( + CefRefPtr request, CefRefPtr client) +{ + CefRefPtr 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 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 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); +} diff --git a/libcef/web_urlrequest_impl.h b/libcef/web_urlrequest_impl.h new file mode 100644 index 000000000..e41477e47 --- /dev/null +++ b/libcef/web_urlrequest_impl.h @@ -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 +{ +public: + class Context; + + explicit CefWebURLRequestImpl( + CefRefPtr 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 request); + void DoCancel(); + void DoStateChange(RequestState newState); + + CefRefPtr GetHandler() { return handler_; } + + static bool ImplementsThreadSafeReferenceCounting() { return true; } + +protected: + CefRefPtr handler_; + + // The below parameters are only modified on the UI thread. + RequestState state_; + scoped_refptr context_; +}; + +#endif // _WEB_URL_REQUEST_CLIENT_IMPL_H diff --git a/libcef_dll/cpptoc/request_cpptoc.cc b/libcef_dll/cpptoc/request_cpptoc.cc index 32a43c866..30374b4c1 100644 --- a/libcef_dll/cpptoc/request_cpptoc.cc +++ b/libcef_dll/cpptoc/request_cpptoc.cc @@ -144,6 +144,47 @@ void CEF_CALLBACK request_set(struct _cef_request_t* self, 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. @@ -159,6 +200,12 @@ CefRequestCppToC::CefRequestCppToC(CefRequest* cls) struct_.struct_.get_header_map = request_get_header_map; struct_.struct_.set_header_map = request_set_header_map; 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 diff --git a/libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc b/libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc new file mode 100644 index 000000000..8dd846ab2 --- /dev/null +++ b/libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc @@ -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(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::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h b/libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h new file mode 100644 index 000000000..626cbe372 --- /dev/null +++ b/libcef_dll/cpptoc/web_urlrequest_client_cpptoc.h @@ -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 +{ +public: + CefWebURLRequestClientCppToC(CefWebURLRequestClient* cls); + virtual ~CefWebURLRequestClientCppToC() {} +}; + +#endif // USING_CEF_SHARED +#endif // _WEBURLREQUESTCLIENT_CPPTOC_H + diff --git a/libcef_dll/cpptoc/web_urlrequest_cpptoc.cc b/libcef_dll/cpptoc/web_urlrequest_cpptoc.cc new file mode 100644 index 000000000..8f0aa6435 --- /dev/null +++ b/libcef_dll/cpptoc/web_urlrequest_cpptoc.cc @@ -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 requestPtr = CefRequestCppToC::Unwrap(request); + + CefRefPtr clientPtr; + if(client) + clientPtr = CefWebURLRequestClientCToCpp::Wrap(client); + + CefRefPtr 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( + cls) +{ + struct_.struct_.cancel = web_urlrequest_cancel; + struct_.struct_.get_state = web_urlrequest_get_state; +} + +#ifdef _DEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/web_urlrequest_cpptoc.h b/libcef_dll/cpptoc/web_urlrequest_cpptoc.h new file mode 100644 index 000000000..6e73d1b60 --- /dev/null +++ b/libcef_dll/cpptoc/web_urlrequest_cpptoc.h @@ -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 +{ +public: + CefWebURLRequestCppToC(CefWebURLRequest* cls); + virtual ~CefWebURLRequestCppToC() {} +}; + +#endif // BUILDING_CEF_SHARED +#endif // _WEBURLREQUEST_CPPTOC_H + diff --git a/libcef_dll/ctocpp/request_ctocpp.cc b/libcef_dll/ctocpp/request_ctocpp.cc index c1d4b82a7..4c9190d3d 100644 --- a/libcef_dll/ctocpp/request_ctocpp.cc +++ b/libcef_dll/ctocpp/request_ctocpp.cc @@ -147,6 +147,41 @@ void CefRequestCToCpp::Set(const CefString& url, const CefString& method, 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 template<> long CefCToCpp 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 diff --git a/libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc b/libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc new file mode 100644 index 000000000..7b5a88384 --- /dev/null +++ b/libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc @@ -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 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 requester, CefRefPtr request, + CefRefPtr 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 requester, CefRefPtr 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 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 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 requester, ErrorCode errorCode) +{ + if(CEF_MEMBER_MISSING(struct_, on_error)) + return; + + struct_->on_error(struct_, CefWebURLRequestCppToC::Wrap(requester), + errorCode); +} + + +#ifdef _DEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h b/libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h new file mode 100644 index 000000000..55af0df84 --- /dev/null +++ b/libcef_dll/ctocpp/web_urlrequest_client_ctocpp.h @@ -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 +{ +public: + CefWebURLRequestClientCToCpp(cef_web_urlrequest_client_t* str) + : CefCToCpp(str) {} + virtual ~CefWebURLRequestClientCToCpp() {} + + // CefWebURLRequestClient methods + virtual void OnStateChange(CefRefPtr requester, + RequestState state); + virtual void OnRedirect(CefRefPtr requester, + CefRefPtr request, CefRefPtr response); + virtual void OnHeadersReceived(CefRefPtr requester, + CefRefPtr response); + virtual void OnProgress(CefRefPtr requester, + uint64 bytesSent, uint64 totalBytesToBeSent); + virtual void OnData(CefRefPtr requester, const void* data, + int dataLength); + virtual void OnError(CefRefPtr requester, + ErrorCode errorCode); +}; + +#endif // BUILDING_CEF_SHARED +#endif // _WEBURLREQUESTCLIENT_CTOCPP_H + diff --git a/libcef_dll/ctocpp/web_urlrequest_ctocpp.cc b/libcef_dll/ctocpp/web_urlrequest_ctocpp.cc new file mode 100644 index 000000000..7c7b701d9 --- /dev/null +++ b/libcef_dll/ctocpp/web_urlrequest_ctocpp.cc @@ -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::CreateWebURLRequest( + CefRefPtr request, CefRefPtr 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::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/web_urlrequest_ctocpp.h b/libcef_dll/ctocpp/web_urlrequest_ctocpp.h new file mode 100644 index 000000000..761d32064 --- /dev/null +++ b/libcef_dll/ctocpp/web_urlrequest_ctocpp.h @@ -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 +{ +public: + CefWebURLRequestCToCpp(cef_web_urlrequest_t* str) + : CefCToCpp(str) {} + virtual ~CefWebURLRequestCToCpp() {} + + // CefWebURLRequest methods + virtual void Cancel(); + virtual RequestState GetState(); +}; + +#endif // USING_CEF_SHARED +#endif // _WEBURLREQUEST_CTOCPP_H + diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index 9284f4335..a06f64ccd 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -400,3 +400,74 @@ void RunXMLHTTPRequestTest(CefRefPtr browser) { browser->GetMainFrame()->LoadURL("http://tests/xmlhttprequest"); } + +void RunWebURLRequestTest(CefRefPtr browser) +{ + class RequestClient : public CefThreadSafeBase + { + public: + RequestClient(CefRefPtr browser) : browser_(browser) {} + + virtual void OnStateChange(CefRefPtr requester, + RequestState state) + { + REQUIRE_UI_THREAD(); + if (state == WUR_STATE_DONE) { + buffer_ = StringReplace(buffer_, "<", "<"); + buffer_ = StringReplace(buffer_, ">", ">"); + std::stringstream ss; + ss << "Source:
" << buffer_ << "
"; + + browser_->GetMainFrame()->LoadString(ss.str(), + "http://tests/weburlrequest"); + } + } + + virtual void OnRedirect(CefRefPtr requester, + CefRefPtr request, + CefRefPtr response) + { + REQUIRE_UI_THREAD(); + } + + virtual void OnHeadersReceived(CefRefPtr requester, + CefRefPtr response) + { + REQUIRE_UI_THREAD(); + } + + virtual void OnProgress(CefRefPtr requester, + uint64 bytesSent, uint64 totalBytesToBeSent) + { + REQUIRE_UI_THREAD(); + } + + virtual void OnData(CefRefPtr requester, + const void* data, int dataLength) + { + REQUIRE_UI_THREAD(); + buffer_.append(static_cast(data), dataLength); + } + + virtual void OnError(CefRefPtr 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 browser_; + std::string buffer_; + }; + + CefRefPtr request(CefRequest::CreateRequest()); + request->SetURL("http://www.google.com"); + + CefRefPtr client(new RequestClient(browser)); + CefRefPtr requester( + CefWebURLRequest::CreateWebURLRequest(request, client)); +} diff --git a/tests/cefclient/cefclient.h b/tests/cefclient/cefclient.h index 34064ca1b..98256a67d 100644 --- a/tests/cefclient/cefclient.h +++ b/tests/cefclient/cefclient.h @@ -438,5 +438,6 @@ void RunAcceleratedLayersTest(CefRefPtr browser); void RunWebGLTest(CefRefPtr browser); void RunHTML5VideoTest(CefRefPtr browser); void RunXMLHTTPRequestTest(CefRefPtr browser); +void RunWebURLRequestTest(CefRefPtr browser); #endif // _CEFCLIENT_H diff --git a/tests/cefclient/cefclient.rc b/tests/cefclient/cefclient.rc index d5aefadf0..b8f62908c 100644 --- a/tests/cefclient/cefclient.rc +++ b/tests/cefclient/cefclient.rc @@ -77,6 +77,7 @@ BEGIN MENUITEM "UI App Example", ID_TESTS_UIAPP MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST + MENUITEM "WebURLRequest", ID_TESTS_WEBURLREQUEST MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS MENUITEM "Accelerated Layers", ID_TESTS_ACCELERATEDLAYERS MENUITEM "WebGL", ID_TESTS_WEBGL diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index 191eb3166..d5c601a8e 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -535,6 +535,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if(browser.get()) RunXMLHTTPRequestTest(browser); return 0; + case ID_TESTS_WEBURLREQUEST: + if (browser.get()) + RunWebURLRequestTest(browser); + return 0; case ID_TESTS_ZOOM_IN: if(browser.get()) browser->SetZoomLevel(browser->GetZoomLevel() + 0.5); diff --git a/tests/cefclient/resource.h b/tests/cefclient/resource.h index 3598d237b..16a04d8ec 100644 --- a/tests/cefclient/resource.h +++ b/tests/cefclient/resource.h @@ -47,6 +47,7 @@ #define ID_TESTS_ZOOM_RESET 32787 #define ID_TESTS_DEVTOOLS_SHOW 32788 #define ID_TESTS_DEVTOOLS_CLOSE 32789 +#define ID_TESTS_WEBURLREQUEST 32790 #define IDC_STATIC -1 #define IDS_LOGO 1000 #define IDS_UIPLUGIN 1001 diff --git a/tests/unittests/request_unittest.cc b/tests/unittests/request_unittest.cc index 788d8584a..52ef5cd7d 100644 --- a/tests/unittests/request_unittest.cc +++ b/tests/unittests/request_unittest.cc @@ -298,6 +298,9 @@ TEST(RequestTest, SendRecv) ASSERT_TRUE(g_RequestSendRecvTestHandlerHandleBeforeResourceLoadCalled); } +// Enable this test if you have applied the patches for issue #42. +#if 0 + bool g_RequestHistoryNavTestDidLoadRequest; bool g_RequestHistoryNavTestDidReloadRequest; @@ -430,3 +433,5 @@ TEST(RequestTest, HistoryNav) ASSERT_TRUE(g_RequestHistoryNavTestDidLoadRequest); ASSERT_TRUE(g_RequestHistoryNavTestDidReloadRequest); } + +#endif // 0 diff --git a/tests/unittests/web_urlrequest_unittest.cc b/tests/unittests/web_urlrequest_unittest.cc new file mode 100644 index 000000000..9692ba1fe --- /dev/null +++ b/tests/unittests/web_urlrequest_unittest.cc @@ -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 << + "" + "

Testing Web Url Request...

" + ""; + + AddResource("http://tests/run.html", testHtml.str(), "text/html"); + CreateBrowser("http://tests/run.html"); + } + + virtual RetVal HandleLoadEnd(CefRefPtr browser, + CefRefPtr 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 +{ +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 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 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 requester, + CefRefPtr request, + CefRefPtr 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 requester, + CefRefPtr 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 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 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 requester, + CefWebURLRequestClient::ErrorCode errorCode) + { +#ifdef WEB_URLREQUEST_DEBUG + printf("Error(0x%p, %d)\n", requester.get(), errorCode); +#endif + test_results_.errorCode = static_cast(errorCode); + test_results_.got_error.yes(); + TestCompleted(); + } + + bool Run(CefRefPtr 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 browser_; + CefRefPtr requester_; + CefRefPtr request_; + std::string contents_; +}; + +TEST(WebURLRequestTest, GET) +{ + class BrowserForTest : public BrowserTestHandler + { + public: + BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { } + + void StartTest() + { + CefRefPtr req; + CefRefPtr 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 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 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 req; + CefRefPtr postdata; + CefRefPtr 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 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 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 req; + CefRefPtr postdata; + CefRefPtr 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 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 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 req; + CefRefPtr postdata; + CefRefPtr 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 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 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/ + + + */ + + + class BrowserForTest : public BrowserTestHandler + { + public: + BrowserForTest(TestResults &tr): BrowserTestHandler(tr) { } + + void StartTest() + { + CefRefPtr req; + CefRefPtr postdata; + CefRefPtr 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 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 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 diff --git a/tools/cef_parser.py b/tools/cef_parser.py index ff38a653f..11d91a715 100644 --- a/tools/cef_parser.py +++ b/tools/cef_parser.py @@ -1073,6 +1073,7 @@ class obj_analysis: 'void' : 'void', 'int' : 'int', 'int64' : 'int64', + 'uint64' : 'uint64', 'double' : 'double', 'long' : 'long', 'unsigned long' : 'unsigned long',