mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Improve thread safety and documentation and add support for thread-specific APIs (issue #175).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@174 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -48,6 +48,8 @@ ClientHandler::~ClientHandler()
|
||||
CefHandler::RetVal ClientHandler::HandleAfterCreated(
|
||||
CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
Lock();
|
||||
if(!browser->IsPopup())
|
||||
{
|
||||
@@ -62,6 +64,8 @@ CefHandler::RetVal ClientHandler::HandleAfterCreated(
|
||||
CefHandler::RetVal ClientHandler::HandleLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, bool isMainContent)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && !frame.get())
|
||||
{
|
||||
Lock();
|
||||
@@ -77,6 +81,8 @@ CefHandler::RetVal ClientHandler::HandleLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefHandler::RetVal ClientHandler::HandleLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, bool isMainContent, int httpStatusCode)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(!browser->IsPopup() && !frame.get())
|
||||
{
|
||||
Lock();
|
||||
@@ -93,6 +99,8 @@ CefHandler::RetVal ClientHandler::HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& failedUrl,
|
||||
CefString& errorText)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(errorCode == ERR_CACHE_MISS)
|
||||
{
|
||||
// Usually caused by navigating to a page with POST data via back or
|
||||
@@ -123,6 +131,8 @@ CefHandler::RetVal ClientHandler::HandleDownloadResponse(
|
||||
const CefString& fileName, int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Create the handler for the file download.
|
||||
handler = CreateDownloadHandler(m_DownloadListener, fileName);
|
||||
return RV_CONTINUE;
|
||||
@@ -135,6 +145,8 @@ CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter(
|
||||
CefString& topCenter, CefString& topRight, CefString& bottomLeft,
|
||||
CefString& bottomCenter, CefString& bottomRight)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Place the page title at top left
|
||||
topLeft = title;
|
||||
// Place the page URL at top right
|
||||
@@ -151,6 +163,8 @@ CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter(
|
||||
CefHandler::RetVal ClientHandler::HandleJSBinding(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Value> object)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Add the V8 bindings.
|
||||
InitBindingTest(browser, frame, object);
|
||||
|
||||
@@ -160,6 +174,8 @@ CefHandler::RetVal ClientHandler::HandleJSBinding(CefRefPtr<CefBrowser> browser,
|
||||
CefHandler::RetVal ClientHandler::HandleBeforeWindowClose(
|
||||
CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle())
|
||||
{
|
||||
// Free the browser pointer so that the browser can be destroyed
|
||||
@@ -172,6 +188,8 @@ CefHandler::RetVal ClientHandler::HandleConsoleMessage(
|
||||
CefRefPtr<CefBrowser> browser, const CefString& message,
|
||||
const CefString& source, int line)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
Lock();
|
||||
bool first_message = m_LogFile.empty();
|
||||
if(first_message) {
|
||||
@@ -271,28 +289,52 @@ CefWindowHandle AppGetMainHwnd()
|
||||
return g_handler->GetMainHwnd();
|
||||
}
|
||||
|
||||
void RunGetSourceTest(CefRefPtr<CefFrame> frame)
|
||||
void RunGetSourceTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
// Retrieve the current page source and display.
|
||||
std::string source = frame->GetSource();
|
||||
source = StringReplace(source, "<", "<");
|
||||
source = StringReplace(source, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Source:" << "<pre>" << source
|
||||
<< "</pre></body></html>";
|
||||
frame->LoadString(ss.str(), "http://tests/getsource");
|
||||
// Execute the GetSource() call on the UI thread.
|
||||
class ExecTask : public CefThreadSafeBase<CefTask>
|
||||
{
|
||||
public:
|
||||
ExecTask(CefRefPtr<CefFrame> frame) : m_Frame(frame) {}
|
||||
virtual void Execute(CefThreadId threadId)
|
||||
{
|
||||
// Retrieve the current page source and display.
|
||||
std::string source = m_Frame->GetSource();
|
||||
source = StringReplace(source, "<", "<");
|
||||
source = StringReplace(source, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Source:" << "<pre>" << source
|
||||
<< "</pre></body></html>";
|
||||
m_Frame->LoadString(ss.str(), "http://tests/getsource");
|
||||
}
|
||||
private:
|
||||
CefRefPtr<CefFrame> m_Frame;
|
||||
};
|
||||
CefPostTask(TID_UI, new ExecTask(browser->GetMainFrame()));
|
||||
}
|
||||
|
||||
void RunGetTextTest(CefRefPtr<CefFrame> frame)
|
||||
void RunGetTextTest(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
// Retrieve the current page text and display.
|
||||
std::string text = frame->GetText();
|
||||
text = StringReplace(text, "<", "<");
|
||||
text = StringReplace(text, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Text:" << "<pre>" << text
|
||||
<< "</pre></body></html>";
|
||||
frame->LoadString(ss.str(), "http://tests/gettext");
|
||||
// Execute the GetText() call on the UI thread.
|
||||
class ExecTask : public CefThreadSafeBase<CefTask>
|
||||
{
|
||||
public:
|
||||
ExecTask(CefRefPtr<CefFrame> frame) : m_Frame(frame) {}
|
||||
virtual void Execute(CefThreadId threadId)
|
||||
{
|
||||
// Retrieve the current page text and display.
|
||||
std::string text = m_Frame->GetText();
|
||||
text = StringReplace(text, "<", "<");
|
||||
text = StringReplace(text, ">", ">");
|
||||
std::stringstream ss;
|
||||
ss << "<html><body>Text:" << "<pre>" << text
|
||||
<< "</pre></body></html>";
|
||||
m_Frame->LoadString(ss.str(), "http://tests/gettext");
|
||||
}
|
||||
private:
|
||||
CefRefPtr<CefFrame> m_Frame;
|
||||
};
|
||||
CefPostTask(TID_UI, new ExecTask(browser->GetMainFrame()));
|
||||
}
|
||||
|
||||
void RunRequestTest(CefRefPtr<CefBrowser> browser)
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "download_handler.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
// Client implementation of the browser handler class
|
||||
class ClientHandler : public CefThreadSafeBase<CefHandler>
|
||||
@@ -32,14 +32,16 @@ public:
|
||||
ClientHandler();
|
||||
~ClientHandler();
|
||||
|
||||
// Event called before a new window is created. The |parentBrowser| parameter
|
||||
// will point to the parent browser window, if any. The |popup| parameter
|
||||
// will be true if the new window is a popup window. If you create the window
|
||||
// yourself you should populate the window handle member of |createInfo| and
|
||||
// return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will
|
||||
// create the window. By default, a newly created window will recieve the
|
||||
// same handler as the parent window. To change the handler for the new
|
||||
// window modify the object that |handler| points to.
|
||||
// Called on the UI thread before a new window is created. The |parentBrowser|
|
||||
// parameter will point to the parent browser window, if any. The |popup|
|
||||
// parameter will be true if the new window is a popup window, in which case
|
||||
// |popupFeatures| will contain information about the style of popup window
|
||||
// requested. If you create the window yourself you should populate the window
|
||||
// handle member of |createInfo| and return RV_HANDLED. Otherwise, return
|
||||
// RV_CONTINUE and the framework will create the window. By default, a newly
|
||||
// created window will recieve the same handler as the parent window. To
|
||||
// change the handler for the new window modify the object that |handler|
|
||||
// points to.
|
||||
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
|
||||
CefWindowInfo& createInfo, bool popup,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
@@ -47,68 +49,73 @@ public:
|
||||
CefString& url,
|
||||
CefBrowserSettings& settings);
|
||||
|
||||
// Event called after a new window is created. The return value is currently
|
||||
// ignored.
|
||||
// Called on the UI thread after a new window is created. The return value is
|
||||
// currently ignored.
|
||||
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
// Event called when the address bar changes. The return value is currently
|
||||
// ignored.
|
||||
// Called on the UI thread when a frame's address has changed. The return
|
||||
// value is currently ignored.
|
||||
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url);
|
||||
|
||||
// Event called when the page title changes. The return value is currently
|
||||
// ignored.
|
||||
// Called on the UI thread when the page title changes. The return value is
|
||||
// currently ignored.
|
||||
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title);
|
||||
|
||||
// Event called before browser navigation. The client has an opportunity to
|
||||
// modify the |request| object if desired. Return RV_HANDLED to cancel
|
||||
// navigation.
|
||||
// Called on the UI thread before browser navigation. The client has an
|
||||
// opportunity to modify the |request| object if desired. Return RV_HANDLED
|
||||
// to cancel navigation.
|
||||
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavType navType, bool isRedirect)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called when the browser begins loading a page. The |frame| pointer
|
||||
// will be empty if the event represents the overall load status and not the
|
||||
// load status for a particular frame. |isMainContent| will be true if this
|
||||
// load is for the main content area and not an iframe. This method may not
|
||||
// be called if the load request fails. The return value is currently ignored.
|
||||
// Called on the UI thread when the browser begins loading a page. The |frame|
|
||||
// pointer will be empty if the event represents the overall load status and
|
||||
// not the load status for a particular frame. |isMainContent| will be true if
|
||||
// this load is for the main content area and not an iframe. This method may
|
||||
// not be called if the load request fails. The return value is currently
|
||||
// ignored.
|
||||
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
bool isMainContent);
|
||||
|
||||
// Event called when the browser is done loading a page. The |frame| pointer
|
||||
// will be empty if the event represents the overall load status and not the
|
||||
// load status for a particular frame. |isMainContent| will be true if this
|
||||
// load is for the main content area and not an iframe. This method will be
|
||||
// called irrespective of whether the request completes successfully. The
|
||||
// return value is currently ignored.
|
||||
// Called on the UI thread when the browser is done loading a page. The
|
||||
// |frame| pointer will be empty if the event represents the overall load
|
||||
// status and not the load status for a particular frame. |isMainContent| will
|
||||
// be true if this load is for the main content area and not an iframe. This
|
||||
// method will be called irrespective of whether the request completes
|
||||
// successfully. The return value is currently ignored.
|
||||
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
bool isMainContent,
|
||||
int httpStatusCode);
|
||||
|
||||
// Called when the browser fails to load a resource. |errorCode| is the
|
||||
// error code number and |failedUrl| is the URL that failed to load. To
|
||||
// provide custom error text assign the text to |errorText| and return
|
||||
// RV_HANDLED. Otherwise, return RV_CONTINUE for the default error text.
|
||||
// Called on the UI thread when the browser fails to load a resource.
|
||||
// |errorCode| is the error code number and |failedUrl| is the URL that failed
|
||||
// to load. To provide custom error text assign the text to |errorText| and
|
||||
// return RV_HANDLED. Otherwise, return RV_CONTINUE for the default error
|
||||
// text.
|
||||
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
ErrorCode errorCode,
|
||||
const CefString& failedUrl,
|
||||
CefString& errorText);
|
||||
|
||||
// Event called before a resource is loaded. To allow the resource to load
|
||||
// normally return RV_CONTINUE. To redirect the resource to a new url
|
||||
// populate the |redirectUrl| value and return RV_CONTINUE. To specify
|
||||
// data for the resource return a CefStream object in |resourceStream|, set
|
||||
// 'mimeType| to the resource stream's mime type, and return RV_CONTINUE.
|
||||
// To cancel loading of the resource return RV_HANDLED.
|
||||
// Called on the IO thread before a resource is loaded. To allow the resource
|
||||
// to load normally return RV_CONTINUE. To redirect the resource to a new url
|
||||
// populate the |redirectUrl| value and return RV_CONTINUE. To specify data
|
||||
// for the resource return a CefStream object in |resourceStream|, set
|
||||
// |mimeType| to the resource stream's mime type, and return RV_CONTINUE. To
|
||||
// cancel loading of the resource return RV_HANDLED. Any modifications to
|
||||
// |request| will be observed. If the URL in |request| is changed and
|
||||
// |redirectUrl| is also set, the URL in |request| will be used.
|
||||
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefString& redirectUrl,
|
||||
@@ -116,39 +123,40 @@ public:
|
||||
CefString& mimeType,
|
||||
int loadFlags);
|
||||
|
||||
// Called to handle requests for URLs with an unknown protocol component.
|
||||
// Return RV_HANDLED to indicate that the request should succeed because it
|
||||
// was externally handled. Set |allow_os_execution| to true and return
|
||||
// RV_CONTINUE to attempt execution via the registered OS protocol handler,
|
||||
// if any. If RV_CONTINUE is returned and either |allow_os_execution| is false
|
||||
// or OS protocol handler execution fails then the request will fail with an
|
||||
// error condition.
|
||||
// Called on the IO thread to handle requests for URLs with an unknown
|
||||
// protocol component. Return RV_HANDLED to indicate that the request should
|
||||
// succeed because it was externally handled. Set |allow_os_execution| to true
|
||||
// and return RV_CONTINUE to attempt execution via the registered OS protocol
|
||||
// handler, if any. If RV_CONTINUE is returned and either |allow_os_execution|
|
||||
// is false or OS protocol handler execution fails then the request will fail
|
||||
// with an error condition.
|
||||
// SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED
|
||||
// ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.
|
||||
virtual RetVal HandleProtocolExecution(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url,
|
||||
bool* allow_os_execution)
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Called when a server indicates via the 'Content-Disposition' header that a
|
||||
// response represents a file to download. |mime_type| is the mime type for
|
||||
// the download, |file_name| is the suggested target file name and
|
||||
// |content_length| is either the value of the 'Content-Size' header or -1 if
|
||||
// no size was provided. Set |handler| to the CefDownloadHandler instance that
|
||||
// will recieve the file contents. Return RV_CONTINUE to download the file
|
||||
// or RV_HANDLED to cancel the file download.
|
||||
// Called on the UI thread when a server indicates via the
|
||||
// 'Content-Disposition' header that a response represents a file to download.
|
||||
// |mimeType| is the mime type for the download, |fileName| is the suggested
|
||||
// target file name and |contentLength| is either the value of the
|
||||
// 'Content-Size' header or -1 if no size was provided. Set |handler| to the
|
||||
// CefDownloadHandler instance that will recieve the file contents. Return
|
||||
// RV_CONTINUE to download the file or RV_HANDLED to cancel the file download.
|
||||
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& mimeType,
|
||||
const CefString& fileName,
|
||||
int64 contentLength,
|
||||
CefRefPtr<CefDownloadHandler>& handler);
|
||||
|
||||
// Called when the browser needs credentials from the user. |isProxy|
|
||||
// indicates whether the host is a proxy server. |host| contains the hostname
|
||||
// and port number. Set |username| and |password| and return RV_HANDLED to
|
||||
// handle the request. Return RV_CONTINUE to cancel the request.
|
||||
// Called on the IO thread when the browser needs credentials from the user.
|
||||
// |isProxy| indicates whether the host is a proxy server. |host| contains the
|
||||
// hostname and port number. Set |username| and |password| and return
|
||||
// RV_HANDLED to handle the request. Return RV_CONTINUE to cancel the request.
|
||||
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
|
||||
bool isProxy,
|
||||
const CefString& host,
|
||||
@@ -157,55 +165,60 @@ public:
|
||||
CefString& username,
|
||||
CefString& password)
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called before a context menu is displayed. To cancel display of the
|
||||
// default context menu return RV_HANDLED.
|
||||
// Called on the UI thread before a context menu is displayed. To cancel
|
||||
// display of the default context menu return RV_HANDLED.
|
||||
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
|
||||
const MenuInfo& menuInfo)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called to optionally override the default text for a context menu
|
||||
// item. |label| contains the default text and may be modified to substitute
|
||||
// alternate text. The return value is currently ignored.
|
||||
// Called on the UI thread to optionally override the default text for a
|
||||
// context menu item. |label| contains the default text and may be modified to
|
||||
// substitute alternate text. The return value is currently ignored.
|
||||
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId, CefString& label)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called when an option is selected from the default context menu.
|
||||
// Return RV_HANDLED to cancel default handling of the action.
|
||||
// Called on the UI thread when an option is selected from the default context
|
||||
// menu. Return RV_HANDLED to cancel default handling of the action.
|
||||
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
|
||||
MenuId menuId)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called to allow customization of standard print options before the
|
||||
// print dialog is displayed. |printOptions| allows specification of paper
|
||||
// size, orientation and margins. Note that the specified margins may be
|
||||
// adjusted if they are outside the range supported by the printer. All units
|
||||
// are in inches. Return RV_CONTINUE to display the default print options or
|
||||
// RV_HANDLED to display the modified |printOptions|.
|
||||
// Called on the UI thread to allow customization of standard print options
|
||||
// before the print dialog is displayed. |printOptions| allows specification
|
||||
// of paper size, orientation and margins. Note that the specified margins may
|
||||
// be adjusted if they are outside the range supported by the printer. All
|
||||
// units are in inches. Return RV_CONTINUE to display the default print
|
||||
// options or RV_HANDLED to display the modified |printOptions|.
|
||||
virtual RetVal HandlePrintOptions(CefRefPtr<CefBrowser> browser,
|
||||
CefPrintOptions& printOptions)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called to format print headers and footers. |printInfo| contains
|
||||
// platform-specific information about the printer context. |url| is the
|
||||
// URL if the currently printing page, |title| is the title of the currently
|
||||
// printing page, |currentPage| is the current page number and |maxPages| is
|
||||
// the total number of pages. Six default header locations are provided
|
||||
// by the implementation: top left, top center, top right, bottom left,
|
||||
// bottom center and bottom right. To use one of these default locations
|
||||
// just assign a string to the appropriate variable. To draw the header
|
||||
// and footer yourself return RV_HANDLED. Otherwise, populate the approprate
|
||||
// Called on the UI thread to format print headers and footers. |printInfo|
|
||||
// contains platform-specific information about the printer context. |url| is
|
||||
// the URL if the currently printing page, |title| is the title of the
|
||||
// currently printing page, |currentPage| is the current page number and
|
||||
// |maxPages| is the total number of pages. Six default header locations are
|
||||
// provided by the implementation: top left, top center, top right, bottom
|
||||
// left, bottom center and bottom right. To use one of these default locations
|
||||
// just assign a string to the appropriate variable. To draw the header and
|
||||
// footer yourself return RV_HANDLED. Otherwise, populate the approprate
|
||||
// variables and return RV_CONTINUE.
|
||||
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
@@ -220,29 +233,32 @@ public:
|
||||
CefString& bottomCenter,
|
||||
CefString& bottomRight);
|
||||
|
||||
// Run a JS alert message. Return RV_CONTINUE to display the default alert
|
||||
// or RV_HANDLED if you displayed a custom alert.
|
||||
// Called on the UI thread to run a JS alert message. Return RV_CONTINUE to
|
||||
// display the default alert or RV_HANDLED if you displayed a custom alert.
|
||||
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& message)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Run a JS confirm request. Return RV_CONTINUE to display the default alert
|
||||
// or RV_HANDLED if you displayed a custom alert. If you handled the alert
|
||||
// set |retval| to true if the user accepted the confirmation.
|
||||
// Called on the UI thread to run a JS confirm request. Return RV_CONTINUE to
|
||||
// display the default alert or RV_HANDLED if you displayed a custom alert. If
|
||||
// you handled the alert set |retval| to true if the user accepted the
|
||||
// confirmation.
|
||||
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& message, bool& retval)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Run a JS prompt request. Return RV_CONTINUE to display the default prompt
|
||||
// or RV_HANDLED if you displayed a custom prompt. If you handled the prompt
|
||||
// set |retval| to true if the user accepted the prompt and request and
|
||||
// |result| to the resulting value.
|
||||
// Called on the UI thread to run a JS prompt request. Return RV_CONTINUE to
|
||||
// display the default prompt or RV_HANDLED if you displayed a custom prompt.
|
||||
// If you handled the prompt set |retval| to true if the user accepted the
|
||||
// prompt and request and |result| to the resulting value.
|
||||
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& message,
|
||||
@@ -250,92 +266,99 @@ public:
|
||||
bool& retval,
|
||||
CefString& result)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called for binding to a frame's JavaScript global object. The
|
||||
// return value is currently ignored.
|
||||
// Called on the UI thread for adding values to a frame's JavaScript 'window'
|
||||
// object. The return value is currently ignored.
|
||||
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Value> object);
|
||||
|
||||
// Called just before a window is closed. The return value is currently
|
||||
// ignored.
|
||||
// Called on the UI thread just before a window is closed. The return value is
|
||||
// currently ignored.
|
||||
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
// Called when the browser component is about to loose focus. For instance,
|
||||
// if focus was on the last HTML element and the user pressed the TAB key.
|
||||
// The return value is currently ignored.
|
||||
// Called on the UI thread when the browser component is about to loose focus.
|
||||
// For instance, if focus was on the last HTML element and the user pressed
|
||||
// the TAB key. The return value is currently ignored.
|
||||
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser, bool reverse)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Called when the browser component is requesting focus. |isWidget| will be
|
||||
// true if the focus is requested for a child widget of the browser window.
|
||||
// Return RV_CONTINUE to allow the focus to be set or RV_HANDLED to cancel
|
||||
// setting the focus.
|
||||
// Called on the UI thread when the browser component is requesting focus.
|
||||
// |isWidget| will be true if the focus is requested for a child widget of the
|
||||
// browser window. Return RV_CONTINUE to allow the focus to be set or
|
||||
// RV_HANDLED to cancel setting the focus.
|
||||
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser,
|
||||
bool isWidget)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called when the browser is about to display a tooltip. |text|
|
||||
// contains the text that will be displayed in the tooltip. To handle
|
||||
// the display of the tooltip yourself return RV_HANDLED. Otherwise,
|
||||
// you can optionally modify |text| and then return RV_CONTINUE to allow
|
||||
// the browser to display the tooltip.
|
||||
// Called on the UI thread when the browser component receives a keyboard
|
||||
// event. |type| is the type of keyboard event, |code| is the windows scan-
|
||||
// code for the event, |modifiers| is a set of bit-flags describing any
|
||||
// pressed modifier keys and |isSystemKey| is true if Windows considers this a
|
||||
// 'system key' message (see
|
||||
// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx). Return
|
||||
// RV_HANDLED if the keyboard event was handled or RV_CONTINUE to allow the
|
||||
// browser component to handle the event.
|
||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type,
|
||||
int code,
|
||||
int modifiers,
|
||||
bool isSystemKey)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Called on the UI thread when the browser is about to display a tooltip.
|
||||
// |text| contains the text that will be displayed in the tooltip. To handle
|
||||
// the display of the tooltip yourself return RV_HANDLED. Otherwise, you can
|
||||
// optionally modify |text| and then return RV_CONTINUE to allow the browser
|
||||
// to display the tooltip.
|
||||
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||
CefString& text)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Event called when the browser has a status message. |text| contains the
|
||||
// text that will be displayed in the status message and |type| indicates the
|
||||
// status message type. The return value is currently ignored.
|
||||
/*--cef()--*/
|
||||
// Called on the UI thread when the browser has a status message. |text|
|
||||
// contains the text that will be displayed in the status message and |type|
|
||||
// indicates the status message type. The return value is currently ignored.
|
||||
virtual RetVal HandleStatus(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& text, StatusType type)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Called when the browser component receives a keyboard event.
|
||||
// |type| is the type of keyboard event (see |KeyEventType|).
|
||||
// |code| is the windows scan-code for the event.
|
||||
// |modifiers| is a set of bit-flags describing any pressed modifier keys.
|
||||
// |isSystemKey| is set if Windows considers this a 'system key' message;
|
||||
// (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx)
|
||||
// Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE
|
||||
// to allow the browser component to handle the event.
|
||||
RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
KeyEventType type,
|
||||
int code,
|
||||
int modifiers,
|
||||
bool isSystemKey)
|
||||
{
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
// Called on the UI thread to display a console message. Return RV_HANDLED to
|
||||
// stop the message from being output to the console.
|
||||
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& message,
|
||||
const CefString& source, int line);
|
||||
|
||||
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||
// from being output to the console.
|
||||
RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& message,
|
||||
const CefString& source, int line);
|
||||
|
||||
// Called to report find results returned by CefBrowser::Find(). |identifer|
|
||||
// is the identifier passed to CefBrowser::Find(), |count| is the number of
|
||||
// matches currently identified, |selectionRect| is the location of where the
|
||||
// match was found (in window coordinates), |activeMatchOrdinal| is the
|
||||
// current position in the search results, and |finalUpdate| is true if this
|
||||
// is the last find notification. The return value is currently ignored.
|
||||
// Called on the UI thread to report find results returned by
|
||||
// CefBrowser::Find(). |identifer| is the identifier passed to
|
||||
// CefBrowser::Find(), |count| is the number of matches currently identified,
|
||||
// |selectionRect| is the location of where the match was found (in window
|
||||
// coordinates), |activeMatchOrdinal| is the current position in the search
|
||||
// results, and |finalUpdate| is true if this is the last find notification.
|
||||
// The return value is currently ignored.
|
||||
virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser,
|
||||
int identifier, int count,
|
||||
const CefRect& selectionRect,
|
||||
int activeMatchOrdinal, bool finalUpdate)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -400,8 +423,8 @@ CefWindowHandle AppGetMainHwnd();
|
||||
std::string AppGetWorkingDirectory();
|
||||
|
||||
// Implementations for various tests.
|
||||
void RunGetSourceTest(CefRefPtr<CefFrame> frame);
|
||||
void RunGetTextTest(CefRefPtr<CefFrame> frame);
|
||||
void RunGetSourceTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunGetTextTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunRequestTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser);
|
||||
void RunPopupTest(CefRefPtr<CefBrowser> browser);
|
||||
|
@@ -292,12 +292,12 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
|
||||
- (IBAction)testGetSource:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetSourceTest(g_handler->GetBrowser()->GetMainFrame());
|
||||
RunGetSourceTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testGetText:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunGetTextTest(g_handler->GetBrowser()->GetMainFrame());
|
||||
RunGetTextTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testJSBinding:(id)sender {
|
||||
@@ -372,6 +372,7 @@ CefHandler::RetVal ClientHandler::HandleBeforeCreated(
|
||||
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
|
||||
CefString& url, CefBrowserSettings& settings)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -379,6 +380,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
|
||||
{
|
||||
// Set the edit window text
|
||||
@@ -393,6 +396,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
CefRefPtr<CefBrowser> browser, const CefString& title)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
// Set the frame window title bar
|
||||
NSWindow* window = (NSWindow*)m_MainHwnd;
|
||||
std::string titleStr(title);
|
||||
@@ -406,6 +411,8 @@ CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
|
||||
CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefString& mimeType, int loadFlags)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
std::string url = request->GetURL();
|
||||
if(url == "http://tests/request") {
|
||||
// Show the request contents
|
||||
|
@@ -472,50 +472,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
browser->StopLoad();
|
||||
return 0;
|
||||
case ID_TESTS_GETSOURCE: // Test the GetSource function
|
||||
if(browser.get()) {
|
||||
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
RunGetSourceTest(browser->GetMainFrame());
|
||||
#else // !TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
// Execute the GetSource() call on the FILE thread to avoid blocking
|
||||
// the UI thread when using a multi-threaded message loop
|
||||
// (issue #79).
|
||||
class ExecTask : public CefThreadSafeBase<CefTask>
|
||||
{
|
||||
public:
|
||||
ExecTask(CefRefPtr<CefFrame> frame) : m_Frame(frame) {}
|
||||
virtual void Execute(CefThreadId threadId)
|
||||
{
|
||||
RunGetSourceTest(m_Frame);
|
||||
}
|
||||
private:
|
||||
CefRefPtr<CefFrame> m_Frame;
|
||||
};
|
||||
CefPostTask(TID_FILE, new ExecTask(browser->GetMainFrame()));
|
||||
#endif // !TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
}
|
||||
if(browser.get())
|
||||
RunGetSourceTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_GETTEXT: // Test the GetText function
|
||||
if(browser.get()) {
|
||||
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
RunGetTextTest(browser->GetMainFrame());
|
||||
#else // !TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
// Execute the GetText() call on the FILE thread to avoid blocking
|
||||
// the UI thread when using a multi-threaded message loop
|
||||
// (issue #79).
|
||||
class ExecTask : public CefThreadSafeBase<CefTask>
|
||||
{
|
||||
public:
|
||||
ExecTask(CefRefPtr<CefFrame> frame) : m_Frame(frame) {}
|
||||
virtual void Execute(CefThreadId threadId)
|
||||
{
|
||||
RunGetTextTest(m_Frame);
|
||||
}
|
||||
private:
|
||||
CefRefPtr<CefFrame> m_Frame;
|
||||
};
|
||||
CefPostTask(TID_FILE, new ExecTask(browser->GetMainFrame()));
|
||||
#endif // !TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
}
|
||||
if(browser.get())
|
||||
RunGetTextTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler
|
||||
if(browser.get())
|
||||
@@ -679,6 +641,8 @@ CefHandler::RetVal ClientHandler::HandleBeforeCreated(
|
||||
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
|
||||
CefString& url, CefBrowserSettings& settings)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(popup) {
|
||||
if(popupFeatures.xSet)
|
||||
createInfo.m_x = popupFeatures.x;
|
||||
@@ -697,6 +661,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
|
||||
{
|
||||
// Set the edit window text
|
||||
@@ -708,6 +674,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
CefRefPtr<CefBrowser> browser, const CefString& title)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the frame window title bar
|
||||
CefWindowHandle hwnd = browser->GetWindowHandle();
|
||||
if(!browser->IsPopup())
|
||||
@@ -724,6 +692,8 @@ CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
|
||||
CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefString& mimeType, int loadFlags)
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
DWORD dwSize;
|
||||
LPBYTE pBytes;
|
||||
|
||||
|
@@ -96,7 +96,7 @@ public:
|
||||
// continue receiving data and |false| to cancel.
|
||||
virtual bool ReceivedData(void* data, int data_size)
|
||||
{
|
||||
ASSERT(CefCurrentlyOn(TID_UI));
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(data_size == 0)
|
||||
return true;
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
// The download is complete.
|
||||
virtual void Complete()
|
||||
{
|
||||
ASSERT(CefCurrentlyOn(TID_UI));
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Flush and close the file on the FILE thread.
|
||||
PostOnThread(TID_FILE, this, &ClientDownloadHandler::OnComplete);
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
|
||||
void OnOpen()
|
||||
{
|
||||
ASSERT(CefCurrentlyOn(TID_FILE));
|
||||
REQUIRE_FILE_THREAD();
|
||||
|
||||
if(file_)
|
||||
return;
|
||||
@@ -179,7 +179,7 @@ public:
|
||||
|
||||
void OnComplete()
|
||||
{
|
||||
ASSERT(CefCurrentlyOn(TID_FILE));
|
||||
REQUIRE_FILE_THREAD();
|
||||
|
||||
if(!file_)
|
||||
return;
|
||||
@@ -196,7 +196,7 @@ public:
|
||||
|
||||
void OnReceivedData()
|
||||
{
|
||||
ASSERT(CefCurrentlyOn(TID_FILE));
|
||||
REQUIRE_FILE_THREAD();
|
||||
|
||||
std::vector<std::vector<char>*> data;
|
||||
|
||||
|
@@ -3,9 +3,10 @@
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "include/cef_wrapper.h"
|
||||
#include "resource_util.h"
|
||||
#include "scheme_test.h"
|
||||
#include "string_util.h"
|
||||
#include "resource_util.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "resource.h"
|
||||
@@ -30,6 +31,8 @@ public:
|
||||
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
|
||||
CefString& mime_type, int* response_length)
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
bool handled = false;
|
||||
|
||||
Lock();
|
||||
@@ -91,6 +94,7 @@ public:
|
||||
// Cancel processing of the request.
|
||||
virtual void Cancel()
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
}
|
||||
|
||||
// Copy up to |bytes_to_read| bytes into |data_out|. If the copy succeeds
|
||||
@@ -99,6 +103,8 @@ public:
|
||||
virtual bool ReadResponse(void* data_out, int bytes_to_read,
|
||||
int* bytes_read)
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
|
||||
bool has_data = false;
|
||||
*bytes_read = 0;
|
||||
|
||||
@@ -134,6 +140,7 @@ public:
|
||||
// Return a new scheme handler instance to handle the request.
|
||||
virtual CefRefPtr<CefSchemeHandler> Create()
|
||||
{
|
||||
REQUIRE_IO_THREAD();
|
||||
return new ClientSchemeHandler();
|
||||
}
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2010 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -6,6 +6,8 @@
|
||||
#ifndef _CEFCLIENT_UTIL_H
|
||||
#define _CEFCLIENT_UTIL_H
|
||||
|
||||
#include "include/cef.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
@@ -56,4 +58,8 @@
|
||||
|
||||
#endif // !_WIN32
|
||||
|
||||
#define REQUIRE_UI_THREAD() ASSERT(CefCurrentlyOn(TID_UI));
|
||||
#define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO));
|
||||
#define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE));
|
||||
|
||||
#endif // _CEFCLIENT_UTIL_H
|
||||
|
Reference in New Issue
Block a user