Add CefDisplayHandler::OnLoadingProgressChange callback (issue #2382)

This commit is contained in:
Mike Wiedenbauer 2018-04-10 13:52:15 -04:00 committed by Marshall Greenblatt
parent 90863b8c5d
commit bb28b85bdd
8 changed files with 143 additions and 4 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=ab31ef5d72b4b1c9809698e5fbbdae21918af713$
// $hash=c7641e41aca6bf30b9c36092861f061d2b16ff82$
//
#ifndef CEF_INCLUDE_CAPI_CEF_DISPLAY_HANDLER_CAPI_H_
@ -132,6 +132,15 @@ typedef struct _cef_display_handler_t {
int(CEF_CALLBACK* on_auto_resize)(struct _cef_display_handler_t* self,
struct _cef_browser_t* browser,
const cef_size_t* new_size);
///
// Called when the overall page loading progress has changed. |progress|
// ranges from 0.0 to 1.0.
///
void(CEF_CALLBACK* on_loading_progress_change)(
struct _cef_display_handler_t* self,
struct _cef_browser_t* browser,
double progress);
} cef_display_handler_t;
#ifdef __cplusplus

View File

@ -127,6 +127,14 @@ class CefDisplayHandler : public virtual CefBaseRefCounted {
const CefSize& new_size) {
return false;
}
///
// Called when the overall page loading progress has changed. |progress|
// ranges from 0.0 to 1.0.
///
/*--cef()--*/
virtual void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
double progress) {}
};
#endif // CEF_INCLUDE_CEF_DISPLAY_HANDLER_H_

View File

@ -2221,6 +2221,16 @@ void CefBrowserHostImpl::LoadingStateChanged(content::WebContents* source,
}
}
void CefBrowserHostImpl::LoadProgressChanged(content::WebContents* source,
double progress) {
if (client_.get()) {
CefRefPtr<CefDisplayHandler> handler = client_->GetDisplayHandler();
if (handler.get()) {
handler->OnLoadingProgressChange(this, progress);
}
}
}
void CefBrowserHostImpl::CloseContents(content::WebContents* source) {
CEF_REQUIRE_UIT();

View File

@ -407,6 +407,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
bool* was_blocked) override;
void LoadingStateChanged(content::WebContents* source,
bool to_different_document) override;
void LoadProgressChanged(content::WebContents* source,
double progress) override;
void CloseContents(content::WebContents* source) override;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool DidAddMessageToConsole(content::WebContents* source,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=f0405e9e04f7eaa587fefd5f00abeed44704773b$
// $hash=0ba45406ca1fcca29b4d8085d6f7b3280477e13f$
//
#include "libcef_dll/cpptoc/display_handler_cpptoc.h"
@ -214,6 +214,25 @@ display_handler_on_auto_resize(struct _cef_display_handler_t* self,
return _retval;
}
void CEF_CALLBACK
display_handler_on_loading_progress_change(struct _cef_display_handler_t* self,
cef_browser_t* browser,
double progress) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Execute
CefDisplayHandlerCppToC::Get(self)->OnLoadingProgressChange(
CefBrowserCToCpp::Wrap(browser), progress);
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
@ -228,6 +247,8 @@ CefDisplayHandlerCppToC::CefDisplayHandlerCppToC() {
GetStruct()->on_status_message = display_handler_on_status_message;
GetStruct()->on_console_message = display_handler_on_console_message;
GetStruct()->on_auto_resize = display_handler_on_auto_resize;
GetStruct()->on_loading_progress_change =
display_handler_on_loading_progress_change;
}
template <>

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=ca92b50b1b21d6de1a591edce5025267abdd2342$
// $hash=9506e4c51606a428b82d70eb5a2366fed4c1c61e$
//
#include "libcef_dll/ctocpp/display_handler_ctocpp.h"
@ -202,6 +202,25 @@ bool CefDisplayHandlerCToCpp::OnAutoResize(CefRefPtr<CefBrowser> browser,
return _retval ? true : false;
}
void CefDisplayHandlerCToCpp::OnLoadingProgressChange(
CefRefPtr<CefBrowser> browser,
double progress) {
cef_display_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_loading_progress_change))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return;
// Execute
_struct->on_loading_progress_change(_struct, CefBrowserCppToC::Wrap(browser),
progress);
}
// CONSTRUCTOR - Do not edit by hand.
CefDisplayHandlerCToCpp::CefDisplayHandlerCToCpp() {}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=f0d07bdd6b1de086c06a2e5ad7960d7cd7409894$
// $hash=6fc6aa5750ef1aa3353c78daa018f761a7ba22a3$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_DISPLAY_HANDLER_CTOCPP_H_
@ -54,6 +54,8 @@ class CefDisplayHandlerCToCpp
int line) override;
bool OnAutoResize(CefRefPtr<CefBrowser> browser,
const CefSize& new_size) override;
void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
double progress) override;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_DISPLAY_HANDLER_CTOCPP_H_

View File

@ -456,3 +456,71 @@ TEST(DisplayTest, OnConsoleMessageAssert) {
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
namespace {
const char kLoadinProgressUrl[] = "http://tests-display/loading-progress.html";
// Browser side.
class LoadingProgressTestHandler : public TestHandler {
public:
LoadingProgressTestHandler() {}
void RunTest() override {
// Add the resources that we will navigate to/from.
AddResource(kLoadinProgressUrl,
"<html><head><style>"
"body {overflow:hidden;margin:0px;padding:0px;}"
"</style></head><body><div id=a>Content</div></body></html>",
"text/html");
// Create the browser.
CreateBrowser(kLoadinProgressUrl);
// Time out the test after a reasonable period of time.
SetTestTimeout();
}
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward) override {
if (isLoading)
return;
DestroyTest();
}
void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser,
double progress) override {
if (!got_loading_progress_change0_) {
got_loading_progress_change0_.yes();
EXPECT_GE(progress, 0.0);
} else if (!got_loading_progress_change1_) {
got_loading_progress_change1_.yes();
EXPECT_LE(progress, 1.0);
}
}
void DestroyTest() override {
EXPECT_TRUE(got_loading_progress_change0_);
EXPECT_TRUE(got_loading_progress_change1_);
TestHandler::DestroyTest();
}
private:
TrackCallback got_loading_progress_change0_;
TrackCallback got_loading_progress_change1_;
IMPLEMENT_REFCOUNTING(LoadingProgressTestHandler);
};
} // namespace
// Test OnLoadingProgressChange notification.
TEST(DisplayTest, LoadingProgress) {
CefRefPtr<LoadingProgressTestHandler> handler =
new LoadingProgressTestHandler();
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}