mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	- Add support for returning an HTTP status code from HandleBeforeResourceLoad and custom scheme handlers via the CefResponse class (issue #202).
- Add unit tests for custom scheme handlers (issue #221). - Fix reversed enable/disable of stop and reload buttons in cefclient. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@222 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
		@@ -15,6 +15,7 @@
 | 
			
		||||
#include "libcef_dll/ctocpp/browser_ctocpp.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/frame_ctocpp.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/response_ctocpp.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/stream_reader_ctocpp.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
 | 
			
		||||
 | 
			
		||||
@@ -197,25 +198,24 @@ enum cef_retval_t CEF_CALLBACK handler_handle_load_error(
 | 
			
		||||
enum cef_retval_t CEF_CALLBACK handler_handle_before_resource_load(
 | 
			
		||||
    struct _cef_handler_t* self, cef_browser_t* browser,
 | 
			
		||||
    struct _cef_request_t* request, cef_string_t* redirectUrl,
 | 
			
		||||
    struct _cef_stream_reader_t** resourceStream, cef_string_t* mimeType,
 | 
			
		||||
    int loadFlags)
 | 
			
		||||
    struct _cef_stream_reader_t** resourceStream,
 | 
			
		||||
    struct _cef_response_t* response, int loadFlags)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  DCHECK(browser);
 | 
			
		||||
  DCHECK(redirectUrl);
 | 
			
		||||
  DCHECK(resourceStream);
 | 
			
		||||
  DCHECK(mimeType);
 | 
			
		||||
  if(!self || !browser || !redirectUrl || !resourceStream || !mimeType)
 | 
			
		||||
  DCHECK(response);
 | 
			
		||||
  if(!self || !browser || !redirectUrl || !resourceStream || !response)
 | 
			
		||||
    return RV_CONTINUE;
 | 
			
		||||
 | 
			
		||||
  CefRefPtr<CefStreamReader> streamPtr;
 | 
			
		||||
 | 
			
		||||
  CefString redirectUrlStr(redirectUrl);
 | 
			
		||||
  CefString mimeTypeStr(mimeType);
 | 
			
		||||
  enum cef_retval_t rv = CefHandlerCppToC::Get(self)->
 | 
			
		||||
      HandleBeforeResourceLoad(CefBrowserCToCpp::Wrap(browser),
 | 
			
		||||
      CefRequestCToCpp::Wrap(request), redirectUrlStr, streamPtr, mimeTypeStr,
 | 
			
		||||
      loadFlags);
 | 
			
		||||
      CefRequestCToCpp::Wrap(request), redirectUrlStr, streamPtr,
 | 
			
		||||
      CefResponseCToCpp::Wrap(response), loadFlags);
 | 
			
		||||
 | 
			
		||||
  if(streamPtr.get())
 | 
			
		||||
    *resourceStream = CefStreamReaderCToCpp::Unwrap(streamPtr);
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,15 @@ int CEF_CALLBACK response_get_status(struct _cef_response_t* self)
 | 
			
		||||
  return CefResponseCppToC::Get(self)->GetStatus();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CEF_CALLBACK response_set_status(struct _cef_response_t* self, int status)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  if(!self)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  CefResponseCppToC::Get(self)->SetStatus(status);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
cef_string_userfree_t CEF_CALLBACK response_get_status_text(
 | 
			
		||||
    struct _cef_response_t* self)
 | 
			
		||||
{
 | 
			
		||||
@@ -36,6 +45,37 @@ cef_string_userfree_t CEF_CALLBACK response_get_status_text(
 | 
			
		||||
  return text.DetachToUserFree();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CEF_CALLBACK response_set_status_text(struct _cef_response_t* self,
 | 
			
		||||
    const cef_string_t* statusText)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  if(!self)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  CefResponseCppToC::Get(self)->SetStatusText(CefString(statusText));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
cef_string_userfree_t CEF_CALLBACK response_get_mime_type(
 | 
			
		||||
    struct _cef_response_t* self)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  if(!self)
 | 
			
		||||
    return NULL;
 | 
			
		||||
 | 
			
		||||
  CefString text = CefResponseCppToC::Get(self)->GetMimeType();
 | 
			
		||||
  return text.DetachToUserFree();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CEF_CALLBACK response_set_mime_type(struct _cef_response_t* self,
 | 
			
		||||
    const cef_string_t* mimeType)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  if(!self)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  CefResponseCppToC::Get(self)->SetMimeType(CefString(mimeType));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
cef_string_userfree_t CEF_CALLBACK response_get_header(
 | 
			
		||||
    struct _cef_response_t* self, const cef_string_t* name)
 | 
			
		||||
{
 | 
			
		||||
@@ -59,6 +99,20 @@ void CEF_CALLBACK response_get_header_map(struct _cef_response_t* self,
 | 
			
		||||
  transfer_string_map_contents(map, headerMap);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CEF_CALLBACK response_set_header_map(struct _cef_response_t* self,
 | 
			
		||||
    cef_string_map_t headerMap)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  if(!self)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  CefResponse::HeaderMap map;
 | 
			
		||||
  if(headerMap)
 | 
			
		||||
    transfer_string_map_contents(headerMap, map);
 | 
			
		||||
 | 
			
		||||
  CefResponseCppToC::Get(self)->SetHeaderMap(map);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// CONSTRUCTOR - Do not edit by hand.
 | 
			
		||||
 | 
			
		||||
@@ -66,9 +120,14 @@ CefResponseCppToC::CefResponseCppToC(CefResponse* cls)
 | 
			
		||||
    : CefCppToC<CefResponseCppToC, CefResponse, cef_response_t>(cls)
 | 
			
		||||
{
 | 
			
		||||
  struct_.struct_.get_status = response_get_status;
 | 
			
		||||
  struct_.struct_.set_status = response_set_status;
 | 
			
		||||
  struct_.struct_.get_status_text = response_get_status_text;
 | 
			
		||||
  struct_.struct_.set_status_text = response_set_status_text;
 | 
			
		||||
  struct_.struct_.get_mime_type = response_get_mime_type;
 | 
			
		||||
  struct_.struct_.set_mime_type = response_set_mime_type;
 | 
			
		||||
  struct_.struct_.get_header = response_get_header;
 | 
			
		||||
  struct_.struct_.get_header_map = response_get_header_map;
 | 
			
		||||
  struct_.struct_.set_header_map = response_set_header_map;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef _DEBUG
 | 
			
		||||
 
 | 
			
		||||
@@ -12,24 +12,25 @@
 | 
			
		||||
 | 
			
		||||
#include "libcef_dll/cpptoc/scheme_handler_cpptoc.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
 | 
			
		||||
#include "libcef_dll/ctocpp/response_ctocpp.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// MEMBER FUNCTIONS - Body may be edited by hand.
 | 
			
		||||
 | 
			
		||||
int CEF_CALLBACK scheme_handler_process_request(
 | 
			
		||||
    struct _cef_scheme_handler_t* self, cef_request_t* request,
 | 
			
		||||
    cef_string_t* mime_type, int* response_length)
 | 
			
		||||
    cef_response_t* response, int* response_length)
 | 
			
		||||
{
 | 
			
		||||
  DCHECK(self);
 | 
			
		||||
  DCHECK(request);
 | 
			
		||||
  DCHECK(mime_type);
 | 
			
		||||
  DCHECK(response);
 | 
			
		||||
  DCHECK(response_length);
 | 
			
		||||
  if(!self || !request || !mime_type || !response_length)
 | 
			
		||||
  if(!self || !request || !response || !response_length)
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
  CefString mimeTypeStr(mime_type);
 | 
			
		||||
  return CefSchemeHandlerCppToC::Get(self)->ProcessRequest(
 | 
			
		||||
      CefRequestCToCpp::Wrap(request), mimeTypeStr, response_length);
 | 
			
		||||
      CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response),
 | 
			
		||||
      response_length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CEF_CALLBACK scheme_handler_cancel(struct _cef_scheme_handler_t* self)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user