Add CefResponse parameter to CefRequestHandler::OnResourceRedirect
This commit is contained in:
parent
69334e22c2
commit
3b5fb0d526
|
@ -146,12 +146,15 @@ typedef struct _cef_request_handler_t {
|
|||
///
|
||||
// Called on the IO thread when a resource load is redirected. The |request|
|
||||
// parameter will contain the old URL and other request-related information.
|
||||
// The |new_url| parameter will contain the new URL and can be changed if
|
||||
// desired. The |request| object cannot be modified in this callback.
|
||||
// The |response| parameter will contain the response that resulted in the
|
||||
// redirect. The |new_url| parameter will contain the new URL and can be
|
||||
// changed if desired. The |request| object cannot be modified in this
|
||||
// callback.
|
||||
///
|
||||
void (CEF_CALLBACK *on_resource_redirect)(struct _cef_request_handler_t* self,
|
||||
struct _cef_browser_t* browser, struct _cef_frame_t* frame,
|
||||
struct _cef_request_t* request, cef_string_t* new_url);
|
||||
struct _cef_request_t* request, struct _cef_response_t* response,
|
||||
cef_string_t* new_url);
|
||||
|
||||
///
|
||||
// Called on the IO thread when a resource response is received. To allow the
|
||||
|
|
|
@ -159,13 +159,16 @@ class CefRequestHandler : public virtual CefBase {
|
|||
///
|
||||
// Called on the IO thread when a resource load is redirected. The |request|
|
||||
// parameter will contain the old URL and other request-related information.
|
||||
// The |new_url| parameter will contain the new URL and can be changed if
|
||||
// desired. The |request| object cannot be modified in this callback.
|
||||
// The |response| parameter will contain the response that resulted in the
|
||||
// redirect. The |new_url| parameter will contain the new URL and can be
|
||||
// changed if desired. The |request| object cannot be modified in this
|
||||
// callback.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response,
|
||||
CefString& new_url) {}
|
||||
|
||||
///
|
||||
|
|
|
@ -73,10 +73,14 @@ net::URLRequestJob* CefRequestInterceptor::MaybeInterceptRedirect(
|
|||
static_cast<CefRequestImpl*>(cefRequest.get())->Set(request);
|
||||
static_cast<CefRequestImpl*>(cefRequest.get())->SetReadOnly(true);
|
||||
|
||||
CefRefPtr<CefResponse> cefResponse = new CefResponseImpl();
|
||||
static_cast<CefResponseImpl*>(cefResponse.get())->Set(request);
|
||||
static_cast<CefResponseImpl*>(cefResponse.get())->SetReadOnly(true);
|
||||
|
||||
// Give the client an opportunity to redirect the request.
|
||||
CefString newUrlStr = location.spec();
|
||||
handler->OnResourceRedirect(browser.get(), frame, cefRequest,
|
||||
newUrlStr);
|
||||
cefResponse, newUrlStr);
|
||||
if (newUrlStr != location.spec()) {
|
||||
const GURL new_url = GURL(newUrlStr.ToString());
|
||||
if (!new_url.is_empty() && new_url.is_valid()) {
|
||||
|
|
|
@ -164,7 +164,8 @@ struct _cef_resource_handler_t* CEF_CALLBACK request_handler_get_resource_handle
|
|||
|
||||
void CEF_CALLBACK request_handler_on_resource_redirect(
|
||||
struct _cef_request_handler_t* self, cef_browser_t* browser,
|
||||
cef_frame_t* frame, cef_request_t* request, cef_string_t* new_url) {
|
||||
cef_frame_t* frame, cef_request_t* request,
|
||||
struct _cef_response_t* response, cef_string_t* new_url) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
|
@ -182,6 +183,10 @@ void CEF_CALLBACK request_handler_on_resource_redirect(
|
|||
DCHECK(request);
|
||||
if (!request)
|
||||
return;
|
||||
// Verify param: response; type: refptr_diff
|
||||
DCHECK(response);
|
||||
if (!response)
|
||||
return;
|
||||
// Verify param: new_url; type: string_byref
|
||||
DCHECK(new_url);
|
||||
if (!new_url)
|
||||
|
@ -195,6 +200,7 @@ void CEF_CALLBACK request_handler_on_resource_redirect(
|
|||
CefBrowserCToCpp::Wrap(browser),
|
||||
CefFrameCToCpp::Wrap(frame),
|
||||
CefRequestCToCpp::Wrap(request),
|
||||
CefResponseCToCpp::Wrap(response),
|
||||
new_urlStr);
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ CefRefPtr<CefResourceHandler> CefRequestHandlerCToCpp::GetResourceHandler(
|
|||
|
||||
void CefRequestHandlerCToCpp::OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
|
||||
CefString& new_url) {
|
||||
CefRefPtr<CefResponse> response, CefString& new_url) {
|
||||
cef_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_resource_redirect))
|
||||
return;
|
||||
|
@ -181,12 +181,17 @@ void CefRequestHandlerCToCpp::OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
|||
DCHECK(request.get());
|
||||
if (!request.get())
|
||||
return;
|
||||
// Verify param: response; type: refptr_diff
|
||||
DCHECK(response.get());
|
||||
if (!response.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->on_resource_redirect(_struct,
|
||||
CefBrowserCppToC::Wrap(browser),
|
||||
CefFrameCppToC::Wrap(frame),
|
||||
CefRequestCppToC::Wrap(request),
|
||||
CefResponseCppToC::Wrap(response),
|
||||
new_url.GetWritableStruct());
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class CefRequestHandlerCToCpp
|
|||
CefRefPtr<CefRequest> request) override;
|
||||
void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
|
||||
CefString& new_url) override;
|
||||
CefRefPtr<CefResponse> response, CefString& new_url) override;
|
||||
bool OnResourceResponse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response) override;
|
||||
|
|
|
@ -780,6 +780,7 @@ class RedirectTestHandler : public TestHandler {
|
|||
void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response,
|
||||
CefString& new_url) override {
|
||||
// Should be called for each redirected URL.
|
||||
|
||||
|
@ -788,14 +789,29 @@ class RedirectTestHandler : public TestHandler {
|
|||
// Called due to the nav1 redirect response.
|
||||
got_nav1_redirect_.yes();
|
||||
|
||||
EXPECT_EQ(302, response->GetStatus());
|
||||
EXPECT_STREQ("Found", response->GetStatusText().ToString().c_str());
|
||||
EXPECT_STREQ("text/html", response->GetMimeType().ToString().c_str());
|
||||
EXPECT_STREQ(kRNav2, response->GetHeader("Location").ToString().c_str());
|
||||
|
||||
// Change the redirect to the 3rd URL.
|
||||
new_url = kRNav3;
|
||||
} else if (old_url == kRNav1 && new_url == kRNav3) {
|
||||
// Called due to the redirect change above.
|
||||
got_nav2_redirect_.yes();
|
||||
|
||||
EXPECT_EQ(307, response->GetStatus());
|
||||
EXPECT_STREQ("Internal Redirect",
|
||||
response->GetStatusText().ToString().c_str());
|
||||
EXPECT_TRUE(response->GetMimeType().empty());
|
||||
EXPECT_STREQ(kRNav3, response->GetHeader("Location").ToString().c_str());
|
||||
} else if (old_url == kRNav3 && new_url == kRNav4) {
|
||||
// Called due to the nav3 redirect response.
|
||||
got_nav3_redirect_.yes();
|
||||
|
||||
EXPECT_EQ(200, response->GetStatus());
|
||||
EXPECT_TRUE(response->GetStatusText().empty());
|
||||
EXPECT_STREQ("text/html", response->GetMimeType().ToString().c_str());
|
||||
} else {
|
||||
got_invalid_redirect_.yes();
|
||||
}
|
||||
|
@ -862,6 +878,7 @@ class RedirectDestroyTestHandler : public TestHandler {
|
|||
void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response,
|
||||
CefString& new_url) override {
|
||||
const std::string& old_url = request->GetURL();
|
||||
if (old_url == kRNav1 && new_url == kRNav2) {
|
||||
|
|
|
@ -643,6 +643,7 @@ class ResourceResponseTest : public TestHandler {
|
|||
void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response,
|
||||
CefString& new_url) override {
|
||||
EXPECT_IO_THREAD();
|
||||
EXPECT_EQ(browser_id_, browser->GetIdentifier());
|
||||
|
|
Loading…
Reference in New Issue