Pass the |redirectUrl| parameter to GetResponseHeaders() instead of ProcessRequest() (issue #414).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@362 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
ae5371dd09
commit
8e45560a02
|
@ -2679,13 +2679,10 @@ public:
|
||||||
// Begin processing the request. To handle the request return true and call
|
// Begin processing the request. To handle the request return true and call
|
||||||
// HeadersAvailable() once the response header information is available
|
// HeadersAvailable() once the response header information is available
|
||||||
// (HeadersAvailable() can also be called from inside this method if header
|
// (HeadersAvailable() can also be called from inside this method if header
|
||||||
// information is available immediately). To redirect the request to a new
|
// information is available immediately). To cancel the request return false.
|
||||||
// URL set |redirectUrl| to the new URL and return true. To cancel the request
|
|
||||||
// return false.
|
|
||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
CefString& redirectUrl,
|
|
||||||
CefRefPtr<CefSchemeHandlerCallback> callback) =0;
|
CefRefPtr<CefSchemeHandlerCallback> callback) =0;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -2695,11 +2692,13 @@ public:
|
||||||
// to a positive value and ReadResponse() will be called until it returns
|
// to a positive value and ReadResponse() will be called until it returns
|
||||||
// false or the specified number of bytes have been read. Use the |response|
|
// false or the specified number of bytes have been read. Use the |response|
|
||||||
// object to set the mime type, http status code and other optional header
|
// object to set the mime type, http status code and other optional header
|
||||||
// values.
|
// values. To redirect the request to a new URL set |redirectUrl| to the new
|
||||||
|
// URL.
|
||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||||
int64& response_length) =0;
|
int64& response_length,
|
||||||
|
CefString& redirectUrl) =0;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Read response data. If data is available immediately copy up to
|
// Read response data. If data is available immediately copy up to
|
||||||
|
|
|
@ -2462,12 +2462,11 @@ typedef struct _cef_scheme_handler_t
|
||||||
// Begin processing the request. To handle the request return true (1) and
|
// Begin processing the request. To handle the request return true (1) and
|
||||||
// call headers_available() once the response header information is available
|
// call headers_available() once the response header information is available
|
||||||
// (headers_available() can also be called from inside this function if header
|
// (headers_available() can also be called from inside this function if header
|
||||||
// information is available immediately). To redirect the request to a new URL
|
// information is available immediately). To cancel the request return false
|
||||||
// set |redirectUrl| to the new URL and return true (1). To cancel the request
|
// (0).
|
||||||
// return false (0).
|
|
||||||
///
|
///
|
||||||
int (CEF_CALLBACK *process_request)(struct _cef_scheme_handler_t* self,
|
int (CEF_CALLBACK *process_request)(struct _cef_scheme_handler_t* self,
|
||||||
struct _cef_request_t* request, cef_string_t* redirectUrl,
|
struct _cef_request_t* request,
|
||||||
struct _cef_scheme_handler_callback_t* callback);
|
struct _cef_scheme_handler_callback_t* callback);
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -2477,10 +2476,12 @@ typedef struct _cef_scheme_handler_t
|
||||||
// a positive value and read_response() will be called until it returns false
|
// a positive value and read_response() will be called until it returns false
|
||||||
// (0) or the specified number of bytes have been read. Use the |response|
|
// (0) or the specified number of bytes have been read. Use the |response|
|
||||||
// object to set the mime type, http status code and other optional header
|
// object to set the mime type, http status code and other optional header
|
||||||
// values.
|
// values. To redirect the request to a new URL set |redirectUrl| to the new
|
||||||
|
// URL.
|
||||||
///
|
///
|
||||||
void (CEF_CALLBACK *get_response_headers)(struct _cef_scheme_handler_t* self,
|
void (CEF_CALLBACK *get_response_headers)(struct _cef_scheme_handler_t* self,
|
||||||
struct _cef_response_t* response, int64* response_length);
|
struct _cef_response_t* response, int64* response_length,
|
||||||
|
cef_string_t* redirectUrl);
|
||||||
|
|
||||||
///
|
///
|
||||||
// Read response data. If data is available immediately copy up to
|
// Read response data. If data is available immediately copy up to
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
CefString& redirectUrl,
|
|
||||||
CefRefPtr<CefSchemeHandlerCallback> callback)
|
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||||
OVERRIDE
|
OVERRIDE
|
||||||
{
|
{
|
||||||
|
@ -39,7 +38,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||||
int64& response_length) OVERRIDE
|
int64& response_length,
|
||||||
|
CefString& redirectUrl) OVERRIDE
|
||||||
{
|
{
|
||||||
response_length = size_;
|
response_length = size_;
|
||||||
|
|
||||||
|
|
|
@ -126,21 +126,15 @@ public:
|
||||||
callback_ = new Callback(this);
|
callback_ = new Callback(this);
|
||||||
|
|
||||||
CefRefPtr<CefRequest> req(CefRequest::CreateRequest());
|
CefRefPtr<CefRequest> req(CefRequest::CreateRequest());
|
||||||
CefString redirectUrl;
|
|
||||||
|
|
||||||
// Populate the request data.
|
// Populate the request data.
|
||||||
static_cast<CefRequestImpl*>(req.get())->Set(request());
|
static_cast<CefRequestImpl*>(req.get())->Set(request());
|
||||||
|
|
||||||
// Handler can decide whether to process the request.
|
// Handler can decide whether to process the request.
|
||||||
bool rv = handler_->ProcessRequest(req, redirectUrl, callback_.get());
|
bool rv = handler_->ProcessRequest(req, callback_.get());
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
// Cancel the request.
|
// Cancel the request.
|
||||||
NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, ERR_ABORTED));
|
NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, ERR_ABORTED));
|
||||||
} else if (!redirectUrl.empty()) {
|
|
||||||
// Treat the request as a redirect.
|
|
||||||
std::string redirectUrlStr = redirectUrl;
|
|
||||||
redirect_url_ = GURL(redirectUrlStr);
|
|
||||||
NotifyHeadersComplete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -253,8 +247,14 @@ private:
|
||||||
response_ = new CefResponseImpl();
|
response_ = new CefResponseImpl();
|
||||||
remaining_bytes_ = 0;
|
remaining_bytes_ = 0;
|
||||||
|
|
||||||
|
CefString redirectUrl;
|
||||||
|
|
||||||
// Get header information from the handler.
|
// Get header information from the handler.
|
||||||
handler_->GetResponseHeaders(response_, remaining_bytes_);
|
handler_->GetResponseHeaders(response_, remaining_bytes_, redirectUrl);
|
||||||
|
if (!redirectUrl.empty()) {
|
||||||
|
std::string redirectUrlStr = redirectUrl;
|
||||||
|
redirect_url_ = GURL(redirectUrlStr);
|
||||||
|
}
|
||||||
|
|
||||||
if (remaining_bytes_ > 0)
|
if (remaining_bytes_ > 0)
|
||||||
set_expected_content_size(remaining_bytes_);
|
set_expected_content_size(remaining_bytes_);
|
||||||
|
|
|
@ -20,32 +20,32 @@
|
||||||
|
|
||||||
int CEF_CALLBACK scheme_handler_process_request(
|
int CEF_CALLBACK scheme_handler_process_request(
|
||||||
struct _cef_scheme_handler_t* self, cef_request_t* request,
|
struct _cef_scheme_handler_t* self, cef_request_t* request,
|
||||||
cef_string_t* redirectUrl, cef_scheme_handler_callback_t* callback)
|
cef_scheme_handler_callback_t* callback)
|
||||||
{
|
{
|
||||||
DCHECK(self);
|
DCHECK(self);
|
||||||
DCHECK(request);
|
DCHECK(request);
|
||||||
DCHECK(redirectUrl);
|
if(!self || !request)
|
||||||
if(!self || !request || !redirectUrl)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CefString redirectUrlStr(redirectUrl);
|
|
||||||
return CefSchemeHandlerCppToC::Get(self)->ProcessRequest(
|
return CefSchemeHandlerCppToC::Get(self)->ProcessRequest(
|
||||||
CefRequestCToCpp::Wrap(request), redirectUrlStr,
|
CefRequestCToCpp::Wrap(request),
|
||||||
CefSchemeHandlerCallbackCToCpp::Wrap(callback));
|
CefSchemeHandlerCallbackCToCpp::Wrap(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEF_CALLBACK scheme_handler_get_response_headers(
|
void CEF_CALLBACK scheme_handler_get_response_headers(
|
||||||
struct _cef_scheme_handler_t* self, cef_response_t* response,
|
struct _cef_scheme_handler_t* self, cef_response_t* response,
|
||||||
int64* response_length)
|
int64* response_length, cef_string_t* redirectUrl)
|
||||||
{
|
{
|
||||||
DCHECK(self);
|
DCHECK(self);
|
||||||
DCHECK(response);
|
DCHECK(response);
|
||||||
DCHECK(response_length);
|
DCHECK(response_length);
|
||||||
if (!self || !response || !response_length)
|
DCHECK(redirectUrl);
|
||||||
|
if (!self || !response || !response_length || !redirectUrl)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
CefString redirectUrlStr(redirectUrl);
|
||||||
CefSchemeHandlerCppToC::Get(self)->GetResponseHeaders(
|
CefSchemeHandlerCppToC::Get(self)->GetResponseHeaders(
|
||||||
CefResponseCToCpp::Wrap(response), *response_length);
|
CefResponseCToCpp::Wrap(response), *response_length, redirectUrlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CEF_CALLBACK scheme_handler_read_response(
|
int CEF_CALLBACK scheme_handler_read_response(
|
||||||
|
|
|
@ -19,24 +19,23 @@
|
||||||
// VIRTUAL METHODS - Body may be edited by hand.
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
bool CefSchemeHandlerCToCpp::ProcessRequest(CefRefPtr<CefRequest> request,
|
bool CefSchemeHandlerCToCpp::ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
CefString& redirectUrl, CefRefPtr<CefSchemeHandlerCallback> callback)
|
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||||
{
|
{
|
||||||
if(CEF_MEMBER_MISSING(struct_, process_request))
|
if(CEF_MEMBER_MISSING(struct_, process_request))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return struct_->process_request(struct_, CefRequestCppToC::Wrap(request),
|
return struct_->process_request(struct_, CefRequestCppToC::Wrap(request),
|
||||||
redirectUrl.GetWritableStruct(),
|
|
||||||
CefSchemeHandlerCallbackCppToC::Wrap(callback)) ? true : false;
|
CefSchemeHandlerCallbackCppToC::Wrap(callback)) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefSchemeHandlerCToCpp::GetResponseHeaders(CefRefPtr<CefResponse> response,
|
void CefSchemeHandlerCToCpp::GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||||
int64& response_length)
|
int64& response_length, CefString& redirectUrl)
|
||||||
{
|
{
|
||||||
if (CEF_MEMBER_MISSING(struct_, get_response_headers))
|
if (CEF_MEMBER_MISSING(struct_, get_response_headers))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct_->get_response_headers(struct_, CefResponseCppToC::Wrap(response),
|
struct_->get_response_headers(struct_, CefResponseCppToC::Wrap(response),
|
||||||
&response_length);
|
&response_length, redirectUrl.GetWritableStruct());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefSchemeHandlerCToCpp::ReadResponse(void* data_out, int bytes_to_read,
|
bool CefSchemeHandlerCToCpp::ReadResponse(void* data_out, int bytes_to_read,
|
||||||
|
|
|
@ -34,10 +34,9 @@ public:
|
||||||
|
|
||||||
// CefSchemeHandler methods
|
// CefSchemeHandler methods
|
||||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
CefString& redirectUrl,
|
|
||||||
CefRefPtr<CefSchemeHandlerCallback> callback) OVERRIDE;
|
CefRefPtr<CefSchemeHandlerCallback> callback) OVERRIDE;
|
||||||
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||||
int64& response_length) OVERRIDE;
|
int64& response_length, CefString& redirectUrl) OVERRIDE;
|
||||||
virtual bool ReadResponse(void* data_out, int bytes_to_read, int& bytes_read,
|
virtual bool ReadResponse(void* data_out, int bytes_to_read, int& bytes_read,
|
||||||
CefRefPtr<CefSchemeHandlerCallback> callback) OVERRIDE;
|
CefRefPtr<CefSchemeHandlerCallback> callback) OVERRIDE;
|
||||||
virtual void Cancel() OVERRIDE;
|
virtual void Cancel() OVERRIDE;
|
||||||
|
|
|
@ -20,7 +20,6 @@ public:
|
||||||
ClientSchemeHandler() : offset_(0) {}
|
ClientSchemeHandler() : offset_(0) {}
|
||||||
|
|
||||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
CefString& redirectUrl,
|
|
||||||
CefRefPtr<CefSchemeHandlerCallback> callback)
|
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||||
OVERRIDE
|
OVERRIDE
|
||||||
{
|
{
|
||||||
|
@ -88,7 +87,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||||
int64& response_length) OVERRIDE
|
int64& response_length,
|
||||||
|
CefString& redirectUrl) OVERRIDE
|
||||||
{
|
{
|
||||||
REQUIRE_IO_THREAD();
|
REQUIRE_IO_THREAD();
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,6 @@ public:
|
||||||
: test_results_(tr), offset_(0), is_sub_(false), has_delayed_(false) {}
|
: test_results_(tr), offset_(0), is_sub_(false), has_delayed_(false) {}
|
||||||
|
|
||||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
CefString& redirectUrl,
|
|
||||||
CefRefPtr<CefSchemeHandlerCallback> callback)
|
CefRefPtr<CefSchemeHandlerCallback> callback)
|
||||||
OVERRIDE
|
OVERRIDE
|
||||||
{
|
{
|
||||||
|
@ -192,13 +191,9 @@ public:
|
||||||
|
|
||||||
test_results_->got_request.yes();
|
test_results_->got_request.yes();
|
||||||
|
|
||||||
if (!test_results_->redirect_url.empty()) {
|
if (!test_results_->html.empty())
|
||||||
redirectUrl = test_results_->redirect_url;
|
|
||||||
return true; // don't call Continue() for URL redirects.
|
|
||||||
} else if (!test_results_->html.empty()) {
|
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (handled) {
|
if (handled) {
|
||||||
if (test_results_->delay > 0) {
|
if (test_results_->delay > 0) {
|
||||||
|
@ -219,7 +214,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
|
||||||
int64& response_length) OVERRIDE
|
int64& response_length,
|
||||||
|
CefString& redirectUrl) OVERRIDE
|
||||||
{
|
{
|
||||||
if (is_sub_) {
|
if (is_sub_) {
|
||||||
response->SetStatus(test_results_->sub_status_code);
|
response->SetStatus(test_results_->sub_status_code);
|
||||||
|
@ -237,6 +233,8 @@ public:
|
||||||
response->SetMimeType("text/html");
|
response->SetMimeType("text/html");
|
||||||
response_length = test_results_->sub_html.size();
|
response_length = test_results_->sub_html.size();
|
||||||
}
|
}
|
||||||
|
} else if (!test_results_->redirect_url.empty()) {
|
||||||
|
redirectUrl = test_results_->redirect_url;
|
||||||
} else {
|
} else {
|
||||||
response->SetStatus(test_results_->status_code);
|
response->SetStatus(test_results_->status_code);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue