mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Significant API changes for issue #218:
- Replace CefHandler with a new CefClient interface and separate handler interfaces. - Add support for virtual inheritance to allow multiple CefBase parented interfaces to be implemented in the same class. - Replace CefThreadSafeBase with IMPLEMENT_* macros to support virtual inheritance and to only provide locking implementations when needed. - Move the CefBrowserSettings parameter from CefInitialize to CreateBrowser. - Add a new cef_build.h header that provides platform-specific and OS_* defines. - Introduce the use of OVERRIDE to generate compiler errors on Windows if a child virtual method declaration doesn't match the parent declaration. - Use NDEBUG instead of _DEBUG because _DEBUG is not defined on Mac. (issue #240). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@235 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -21,8 +21,13 @@ protected:
|
||||
bool gotit_;
|
||||
};
|
||||
|
||||
// Base implementation of CefHandler for unit tests.
|
||||
class TestHandler : public CefThreadSafeBase<CefHandler>
|
||||
// Base implementation of CefClient for unit tests. Add new interfaces as needed
|
||||
// by test cases.
|
||||
class TestHandler : public CefClient,
|
||||
public CefLifeSpanHandler,
|
||||
public CefLoadHandler,
|
||||
public CefRequestHandler,
|
||||
public CefJSBindingHandler
|
||||
{
|
||||
public:
|
||||
TestHandler() : browser_hwnd_(NULL), completion_event_(true, false)
|
||||
@@ -36,86 +41,53 @@ public:
|
||||
// Implement this method to run the test
|
||||
virtual void RunTest() =0;
|
||||
|
||||
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
|
||||
CefWindowInfo& createInfo, bool popup,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefRefPtr<CefHandler>& handler,
|
||||
const CefString& url,
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
// CefClient methods. Add new methods as needed by test cases.
|
||||
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
||||
{ return this; }
|
||||
virtual CefRefPtr<CefJSBindingHandler> GetJSBindingHandler() OVERRIDE
|
||||
{ return this; }
|
||||
|
||||
// CefLifeSpanHandler methods
|
||||
|
||||
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser)
|
||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
|
||||
{
|
||||
Lock();
|
||||
AutoLock lock_scope(this);
|
||||
if(!browser->IsPopup())
|
||||
{
|
||||
// Keep the main child window, but not popup windows
|
||||
browser_ = browser;
|
||||
browser_hwnd_ = browser->GetWindowHandle();
|
||||
}
|
||||
Unlock();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
AutoLock lock_scope(this);
|
||||
if(browser_hwnd_ == browser->GetWindowHandle())
|
||||
{
|
||||
// Free the browser pointer so that the browser can be destroyed
|
||||
browser_ = NULL;
|
||||
browser_hwnd_ = NULL;
|
||||
|
||||
// Signal that the test is now complete.
|
||||
completion_event_.Signal();
|
||||
}
|
||||
}
|
||||
|
||||
virtual RetVal HandleNavStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool canGoBack, bool canGoForward)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
// CefRequestHandler methods
|
||||
|
||||
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavType navType, bool isRedirect)
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags) OVERRIDE
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
ErrorCode errorCode,
|
||||
const CefString& failedUrl,
|
||||
CefString& errorText)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response,
|
||||
int loadFlags)
|
||||
{
|
||||
Lock();
|
||||
AutoLock lock_scope(this);
|
||||
if(resource_map_.size() > 0) {
|
||||
CefString url = request->GetURL();
|
||||
ResourceMap::const_iterator it = resource_map_.find(url);
|
||||
@@ -127,201 +99,8 @@ public:
|
||||
response->SetStatus(200);
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleProtocolExecution(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url,
|
||||
bool& allow_os_execution)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& mimeType,
|
||||
const CefString& fileName,
|
||||
int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
|
||||
bool isProxy,
|
||||
const CefString& host,
|
||||
const CefString& realm,
|
||||
const CefString& scheme,
|
||||
CefString& username,
|
||||
CefString& password)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
|
||||
const MenuInfo& menuInfo)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId, CefString& label)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandlePrintOptions(CefRefPtr<CefBrowser> browser,
|
||||
CefPrintOptions& printOptions)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefPrintInfo& printInfo,
|
||||
const CefString& url,
|
||||
const CefString& title,
|
||||
int currentPage, int maxPages,
|
||||
CefString& topLeft,
|
||||
CefString& topCenter,
|
||||
CefString& topRight,
|
||||
CefString& bottomLeft,
|
||||
CefString& bottomCenter,
|
||||
CefString& bottomRight)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& message)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& message, bool& retval)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& message,
|
||||
const CefString& defaultValue,
|
||||
bool& retval,
|
||||
CefString& result)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Value> object)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
Lock();
|
||||
if(browser_hwnd_ == browser->GetWindowHandle())
|
||||
{
|
||||
// Free the browser pointer so that the browser can be destroyed
|
||||
browser_ = NULL;
|
||||
browser_hwnd_ = NULL;
|
||||
|
||||
// Signal that the test is now complete.
|
||||
completion_event_.Signal();
|
||||
}
|
||||
Unlock();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser, bool reverse)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser,
|
||||
bool isWidget)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type, int code,
|
||||
int modifiers, bool isSystemKey)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||
CefString& text)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleStatus(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& text, StatusType type)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& message,
|
||||
const CefString& source, int line)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser,
|
||||
int identifier, int count,
|
||||
const CefRect& selectionRect,
|
||||
int activeMatchOrdinal, bool finalUpdate)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleGetRect(CefRefPtr<CefBrowser> browser, bool screen,
|
||||
CefRect& rect)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleGetScreenPoint(CefRefPtr<CefBrowser> browser,
|
||||
int viewX, int viewY, int& screenX,
|
||||
int& screenY)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandlePopupChange(CefRefPtr<CefBrowser> browser, bool show,
|
||||
const CefRect& rect)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandlePaint(CefRefPtr<CefBrowser> browser,
|
||||
PaintElementType type, const CefRect& dirtyRect,
|
||||
const void* buffer)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
virtual RetVal HandleCursorChange(CefRefPtr<CefBrowser> browser,
|
||||
CefCursorHandle cursor)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
return false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> GetBrowser()
|
||||
@@ -362,11 +141,12 @@ protected:
|
||||
void CreateBrowser(const CefString& url)
|
||||
{
|
||||
CefWindowInfo windowInfo;
|
||||
CefBrowserSettings settings;
|
||||
#if defined(OS_WIN)
|
||||
windowInfo.SetAsPopup(NULL, "CefUnitTest");
|
||||
windowInfo.m_dwStyle |= WS_VISIBLE;
|
||||
#endif
|
||||
CefBrowser::CreateBrowser(windowInfo, false, this, url);
|
||||
CefBrowser::CreateBrowser(windowInfo, this, url, settings);
|
||||
}
|
||||
|
||||
void AddResource(const CefString& key, const std::string& value,
|
||||
@@ -393,6 +173,11 @@ private:
|
||||
// Map of resources that can be automatically loaded
|
||||
typedef std::map<CefString, std::pair<std::string, CefString> > ResourceMap;
|
||||
ResourceMap resource_map_;
|
||||
|
||||
// Include the default reference counting implementation.
|
||||
IMPLEMENT_REFCOUNTING(TestHandler);
|
||||
// Include the default locking implementation.
|
||||
IMPLEMENT_LOCKING(TestHandler);
|
||||
};
|
||||
|
||||
#endif // _TEST_HANDLER_H
|
||||
|
Reference in New Issue
Block a user