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:
Marshall Greenblatt 2011-01-29 01:42:59 +00:00
parent c89349cf5a
commit 7f1694fb68
20 changed files with 1207 additions and 1128 deletions

View File

@ -63,27 +63,29 @@ class CefV8Handler;
class CefV8Value; class CefV8Value;
// This function should be called once when the application is started to // This function should be called on the main application thread to initialize
// initialize CEF. A return value of true indicates that it succeeded and // CEF when the application is started. A return value of true indicates that
// false indicates that it failed. // it succeeded and false indicates that it failed.
/*--cef()--*/ /*--cef()--*/
bool CefInitialize(const CefSettings& settings, bool CefInitialize(const CefSettings& settings,
const CefBrowserSettings& browser_defaults); const CefBrowserSettings& browser_defaults);
// This function should be called once before the application exits to shut down // This function should be called on the main application thread to shut down
// CEF. // CEF before the application exits.
/*--cef()--*/ /*--cef()--*/
void CefShutdown(); void CefShutdown();
// Perform message loop processing. Has no affect if the browser UI loop is // Perform message loop processing. This function must be called on the main
// running in a separate thread. // application thread if CefInitialize() is called with a
// CefSettings.multi_threaded_message_loop value of false.
/*--cef()--*/ /*--cef()--*/
void CefDoMessageLoopWork(); void CefDoMessageLoopWork();
// Register a new V8 extension with the specified JavaScript extension code and // Register a new V8 extension with the specified JavaScript extension code and
// handler. Functions implemented by the handler are prototyped using the // handler. Functions implemented by the handler are prototyped using the
// keyword 'native'. The calling of a native function is restricted to the scope // keyword 'native'. The calling of a native function is restricted to the scope
// in which the prototype of the native function is defined. // in which the prototype of the native function is defined. This function may
// be called on any thread.
// //
// Example JavaScript extension code: // Example JavaScript extension code:
// //
@ -145,7 +147,8 @@ bool CefRegisterExtension(const CefString& extension_name,
// Register a custom scheme handler factory for the specified |scheme_name| and // Register a custom scheme handler factory for the specified |scheme_name| and
// |host_name|. All URLs beginning with scheme_name://host_name/ can be handled // |host_name|. All URLs beginning with scheme_name://host_name/ can be handled
// by CefSchemeHandler instances returned by the factory. Specify an empty // by CefSchemeHandler instances returned by the factory. Specify an empty
// |host_name| value to match all host names. // |host_name| value to match all host names. This function may be called on any
// thread.
/*--cef()--*/ /*--cef()--*/
bool CefRegisterScheme(const CefString& scheme_name, bool CefRegisterScheme(const CefString& scheme_name,
const CefString& host_name, const CefString& host_name,
@ -158,18 +161,20 @@ typedef cef_thread_id_t CefThreadId;
// types of tasks. The UI thread creates the browser window and is used for all // types of tasks. The UI thread creates the browser window and is used for all
// interaction with the WebKit rendering engine and V8 JavaScript engine (The // interaction with the WebKit rendering engine and V8 JavaScript engine (The
// UI thread will be the same as the main application thread if CefInitialize() // UI thread will be the same as the main application thread if CefInitialize()
// was called with a |multi_threaded_message_loop| value of false.) The IO // is called with a CefSettings.multi_threaded_message_loop value of false.) The
// thread is used for handling schema and network requests. The FILE thread is // IO thread is used for handling schema and network requests. The FILE thread
// used for the application cache and other miscellaneous activities. This // is used for the application cache and other miscellaneous activities. This
// method will return true if called on the specified thread. // function will return true if called on the specified thread.
/*--cef()--*/ /*--cef()--*/
bool CefCurrentlyOn(CefThreadId threadId); bool CefCurrentlyOn(CefThreadId threadId);
// Post a task for execution on the specified thread. // Post a task for execution on the specified thread. This function may be
// called on any thread.
/*--cef()--*/ /*--cef()--*/
bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task); bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task);
// Post a task for delayed execution on the specified thread. // Post a task for delayed execution on the specified thread. This function may
// be called on any thread.
/*--cef()--*/ /*--cef()--*/
bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task, bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
long delay_ms); long delay_ms);
@ -329,7 +334,8 @@ inline bool operator!=(const CefRect& a, const CefRect& b)
return !(a == b); return !(a == b);
} }
// Implement this interface for task execution. // Implement this interface for task execution. The methods of this class may
// be called on any thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefTask : public CefBase class CefTask : public CefBase
{ {
@ -340,26 +346,24 @@ public:
}; };
// Class used to represent a browser window. All methods exposed by this class // Class used to represent a browser window. The methods of this class may be
// should be thread safe. // called on any thread unless otherwise indicated in the comments.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefBrowser : public CefBase class CefBrowser : public CefBase
{ {
public: public:
// Create a new browser window using the window parameters specified // Create a new browser window using the window parameters specified by
// by |windowInfo|. All values will be copied internally and the actual // |windowInfo|. All values will be copied internally and the actual window
// window will be created on the UI thread. The |popup| parameter should // will be created on the UI thread. The |popup| parameter should be true if
// be true if the new window is a popup window. This method call will not // the new window is a popup window. This method call will not block.
// block.
/*--cef()--*/ /*--cef()--*/
static bool CreateBrowser(CefWindowInfo& windowInfo, bool popup, static bool CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler, CefRefPtr<CefHandler> handler,
const CefString& url); const CefString& url);
// Create a new browser window using the window parameters specified // Create a new browser window using the window parameters specified by
// by |windowInfo|. The |popup| parameter should be true if the new window is // |windowInfo|. The |popup| parameter should be true if the new window is a
// a popup window. This method call will block and can only be used if // popup window. This method should only be called on the UI thread.
// the |multi_threaded_message_loop| parameter to CefInitialize() is false.
/*--cef()--*/ /*--cef()--*/
static CefRefPtr<CefBrowser> CreateBrowserSync(CefWindowInfo& windowInfo, static CefRefPtr<CefBrowser> CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, bool popup,
@ -388,8 +392,8 @@ public:
/*--cef()--*/ /*--cef()--*/
virtual void StopLoad() =0; virtual void StopLoad() =0;
// Set focus for the browser window. If |enable| is true focus will be set // Set focus for the browser window. If |enable| is true focus will be set to
// to the window. Otherwise, focus will be removed. // the window. Otherwise, focus will be removed.
/*--cef()--*/ /*--cef()--*/
virtual void SetFocus(bool enable) =0; virtual void SetFocus(bool enable) =0;
@ -409,15 +413,18 @@ public:
/*--cef()--*/ /*--cef()--*/
virtual CefRefPtr<CefFrame> GetMainFrame() =0; virtual CefRefPtr<CefFrame> GetMainFrame() =0;
// Returns the focused frame for the browser window. // Returns the focused frame for the browser window. This method should only
// be called on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual CefRefPtr<CefFrame> GetFocusedFrame() =0; virtual CefRefPtr<CefFrame> GetFocusedFrame() =0;
// Returns the frame with the specified name, or NULL if not found. // Returns the frame with the specified name, or NULL if not found. This
// method should only be called on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual CefRefPtr<CefFrame> GetFrame(const CefString& name) =0; virtual CefRefPtr<CefFrame> GetFrame(const CefString& name) =0;
// Returns the names of all existing frames. // Returns the names of all existing frames. This method should only be called
// on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual void GetFrameNames(std::vector<CefString>& names) =0; virtual void GetFrameNames(std::vector<CefString>& names) =0;
@ -453,8 +460,8 @@ public:
}; };
// Class used to represent a frame in the browser window. All methods exposed // Class used to represent a frame in the browser window. The methods of this
// by this class should be thread safe. // class may be called on any thread unless otherwise indicated in the comments.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefFrame : public CefBase class CefFrame : public CefBase
{ {
@ -491,11 +498,13 @@ public:
/*--cef()--*/ /*--cef()--*/
virtual void ViewSource() =0; virtual void ViewSource() =0;
// Returns this frame's HTML source as a string. // Returns this frame's HTML source as a string. This method should only be
// called on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual CefString GetSource() =0; virtual CefString GetSource() =0;
// Returns this frame's display text as a string. // Returns this frame's display text as a string. This method should only be
// called on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual CefString GetText() =0; virtual CefString GetText() =0;
@ -531,7 +540,8 @@ public:
/*--cef()--*/ /*--cef()--*/
virtual bool IsMain() =0; virtual bool IsMain() =0;
// Returns true if this is the focused frame. // Returns true if this is the focused frame. This method should only be
// called on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual bool IsFocused() =0; virtual bool IsFocused() =0;
@ -539,15 +549,16 @@ public:
/*--cef()--*/ /*--cef()--*/
virtual CefString GetName() =0; virtual CefString GetName() =0;
// Return the URL currently loaded in this frame. // Return the URL currently loaded in this frame. This method should only be
// called on the UI thread.
/*--cef()--*/ /*--cef()--*/
virtual CefString GetURL() =0; virtual CefString GetURL() =0;
}; };
// Interface that should be implemented to handle events generated by the // Interface that should be implemented to handle events generated by the
// browser window. All methods exposed by this class should be thread safe. // browser window. The methods of this class will be called on the thread
// Each method in the interface returns a RetVal value. // indicated in the method comments.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefHandler : public CefBase class CefHandler : public CefBase
{ {
@ -559,9 +570,9 @@ public:
// should be called. // should be called.
typedef cef_retval_t RetVal; typedef cef_retval_t RetVal;
// Event called before a new window is created. The |parentBrowser| parameter // Called on the UI thread before a new window is created. The |parentBrowser|
// will point to the parent browser window, if any. The |popup| parameter // parameter will point to the parent browser window, if any. The |popup|
// will be true if the new window is a popup window, in which case // 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 // |popupFeatures| will contain information about the style of popup window
// requested. If you create the window yourself you should populate the window // requested. If you create the window yourself you should populate the window
// handle member of |createInfo| and return RV_HANDLED. Otherwise, return // handle member of |createInfo| and return RV_HANDLED. Otherwise, return
@ -577,20 +588,20 @@ public:
CefString& url, CefString& url,
CefBrowserSettings& settings) =0; CefBrowserSettings& settings) =0;
// Event called after a new window is created. The return value is currently // Called on the UI thread after a new window is created. The return value is
// ignored. // currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser) =0; virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser) =0;
// Event called when a frame's address has changed. The return value is // Called on the UI thread when a frame's address has changed. The return
// currently ignored. // value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser, virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& url) =0; const CefString& url) =0;
// Event called when the page title changes. The return value is currently // Called on the UI thread when the page title changes. The return value is
// ignored. // currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser, virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) =0; const CefString& title) =0;
@ -598,31 +609,32 @@ public:
// Various browser navigation types supported by chrome. // Various browser navigation types supported by chrome.
typedef cef_handler_navtype_t NavType; typedef cef_handler_navtype_t NavType;
// Event called before browser navigation. The client has an opportunity to // Called on the UI thread before browser navigation. The client has an
// modify the |request| object if desired. Return RV_HANDLED to cancel // opportunity to modify the |request| object if desired. Return RV_HANDLED
// navigation. // to cancel navigation.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser, virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request, CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect) =0; NavType navType, bool isRedirect) =0;
// Event called when the browser begins loading a page. The |frame| pointer // Called on the UI thread when the browser begins loading a page. The |frame|
// will be empty if the event represents the overall load status and not the // pointer will be empty if the event represents the overall load status and
// load status for a particular frame. |isMainContent| will be true if this // not the load status for a particular frame. |isMainContent| will be true if
// load is for the main content area and not an iframe. This method may not // this load is for the main content area and not an iframe. This method may
// be called if the load request fails. The return value is currently ignored. // not be called if the load request fails. The return value is currently
// ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser, virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
bool isMainContent) =0; bool isMainContent) =0;
// Event called when the browser is done loading a page. The |frame| pointer // Called on the UI thread when the browser is done loading a page. The
// will be empty if the event represents the overall load status and not the // |frame| pointer will be empty if the event represents the overall load
// load status for a particular frame. |isMainContent| will be true if this // status and not the load status for a particular frame. |isMainContent| will
// load is for the main content area and not an iframe. This method will be // be true if this load is for the main content area and not an iframe. This
// called irrespective of whether the request completes successfully. The // method will be called irrespective of whether the request completes
// return value is currently ignored. // successfully. The return value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser, virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
@ -633,10 +645,11 @@ public:
// descriptions of the error codes. // descriptions of the error codes.
typedef cef_handler_errorcode_t ErrorCode; typedef cef_handler_errorcode_t ErrorCode;
// Called when the browser fails to load a resource. |errorCode| is the // Called on the UI thread when the browser fails to load a resource.
// error code number and |failedUrl| is the URL that failed to load. To // |errorCode| is the error code number and |failedUrl| is the URL that failed
// provide custom error text assign the text to |errorText| and return // to load. To provide custom error text assign the text to |errorText| and
// RV_HANDLED. Otherwise, return RV_CONTINUE for the default error text. // return RV_HANDLED. Otherwise, return RV_CONTINUE for the default error
// text.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser, virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
@ -644,13 +657,13 @@ public:
const CefString& failedUrl, const CefString& failedUrl,
CefString& errorText) =0; CefString& errorText) =0;
// Event called before a resource is loaded. To allow the resource to load // Called on the IO thread before a resource is loaded. To allow the resource
// normally return RV_CONTINUE. To redirect the resource to a new url // to load normally return RV_CONTINUE. To redirect the resource to a new url
// populate the |redirectUrl| value and return RV_CONTINUE. To specify // populate the |redirectUrl| value and return RV_CONTINUE. To specify data
// data for the resource return a CefStream object in |resourceStream|, set // for the resource return a CefStream object in |resourceStream|, set
// |mimeType| to the resource stream's mime type, and return RV_CONTINUE. // |mimeType| to the resource stream's mime type, and return RV_CONTINUE. To
// To cancel loading of the resource return RV_HANDLED. Any modifications // cancel loading of the resource return RV_HANDLED. Any modifications to
// to |request| will be observed. If the URL in |request| is changed and // |request| will be observed. If the URL in |request| is changed and
// |redirectUrl| is also set, the URL in |request| will be used. // |redirectUrl| is also set, the URL in |request| will be used.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser, virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
@ -660,13 +673,13 @@ public:
CefString& mimeType, CefString& mimeType,
int loadFlags) =0; int loadFlags) =0;
// Called to handle requests for URLs with an unknown protocol component. // Called on the IO thread to handle requests for URLs with an unknown
// Return RV_HANDLED to indicate that the request should succeed because it // protocol component. Return RV_HANDLED to indicate that the request should
// was externally handled. Set |allow_os_execution| to true and return // succeed because it was externally handled. Set |allow_os_execution| to true
// RV_CONTINUE to attempt execution via the registered OS protocol handler, // and return RV_CONTINUE to attempt execution via the registered OS protocol
// if any. If RV_CONTINUE is returned and either |allow_os_execution| is false // handler, if any. If RV_CONTINUE is returned and either |allow_os_execution|
// or OS protocol handler execution fails then the request will fail with an // is false or OS protocol handler execution fails then the request will fail
// error condition. // with an error condition.
// SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED // SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED
// ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION. // ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.
/*--cef()--*/ /*--cef()--*/
@ -674,13 +687,13 @@ public:
const CefString& url, const CefString& url,
bool* allow_os_execution) =0; bool* allow_os_execution) =0;
// Called when a server indicates via the 'Content-Disposition' header that a // Called on the UI thread when a server indicates via the
// response represents a file to download. |mimeType| is the mime type for // 'Content-Disposition' header that a response represents a file to download.
// the download, |fileName| is the suggested target file name and // |mimeType| is the mime type for the download, |fileName| is the suggested
// |contentLength| is either the value of the 'Content-Size' header or -1 if // target file name and |contentLength| is either the value of the
// no size was provided. Set |handler| to the CefDownloadHandler instance that // 'Content-Size' header or -1 if no size was provided. Set |handler| to the
// will recieve the file contents. Return RV_CONTINUE to download the file // CefDownloadHandler instance that will recieve the file contents. Return
// or RV_HANDLED to cancel the file download. // RV_CONTINUE to download the file or RV_HANDLED to cancel the file download.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser, virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
const CefString& mimeType, const CefString& mimeType,
@ -688,10 +701,10 @@ public:
int64 contentLength, int64 contentLength,
CefRefPtr<CefDownloadHandler>& handler) =0; CefRefPtr<CefDownloadHandler>& handler) =0;
// Called when the browser needs credentials from the user. |isProxy| // Called on the IO thread when the browser needs credentials from the user.
// indicates whether the host is a proxy server. |host| contains the hostname // |isProxy| indicates whether the host is a proxy server. |host| contains the
// and port number. Set |username| and |password| and return RV_HANDLED to // hostname and port number. Set |username| and |password| and return
// handle the request. Return RV_CONTINUE to cancel the request. // RV_HANDLED to handle the request. Return RV_CONTINUE to cancel the request.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser, virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
bool isProxy, bool isProxy,
@ -704,8 +717,8 @@ public:
// Structure representing menu information. // Structure representing menu information.
typedef cef_handler_menuinfo_t MenuInfo; typedef cef_handler_menuinfo_t MenuInfo;
// Event called before a context menu is displayed. To cancel display of the // Called on the UI thread before a context menu is displayed. To cancel
// default context menu return RV_HANDLED. // display of the default context menu return RV_HANDLED.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser, virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
const MenuInfo& menuInfo) =0; const MenuInfo& menuInfo) =0;
@ -713,15 +726,15 @@ public:
// Supported menu ID values. // Supported menu ID values.
typedef cef_handler_menuid_t MenuId; typedef cef_handler_menuid_t MenuId;
// Event called to optionally override the default text for a context menu // Called on the UI thread to optionally override the default text for a
// item. |label| contains the default text and may be modified to substitute // context menu item. |label| contains the default text and may be modified to
// alternate text. The return value is currently ignored. // substitute alternate text. The return value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser, virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
MenuId menuId, CefString& label) =0; MenuId menuId, CefString& label) =0;
// Event called when an option is selected from the default context menu. // Called on the UI thread when an option is selected from the default context
// Return RV_HANDLED to cancel default handling of the action. // menu. Return RV_HANDLED to cancel default handling of the action.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser, virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
MenuId menuId) =0; MenuId menuId) =0;
@ -729,25 +742,25 @@ public:
// Structure representing print options. // Structure representing print options.
typedef cef_print_options_t CefPrintOptions; typedef cef_print_options_t CefPrintOptions;
// Event called to allow customization of standard print options before the // Called on the UI thread to allow customization of standard print options
// print dialog is displayed. |printOptions| allows specification of paper // before the print dialog is displayed. |printOptions| allows specification
// size, orientation and margins. Note that the specified margins may be // of paper size, orientation and margins. Note that the specified margins may
// adjusted if they are outside the range supported by the printer. All units // be adjusted if they are outside the range supported by the printer. All
// are in inches. Return RV_CONTINUE to display the default print options or // units are in inches. Return RV_CONTINUE to display the default print
// RV_HANDLED to display the modified |printOptions|. // options or RV_HANDLED to display the modified |printOptions|.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandlePrintOptions(CefRefPtr<CefBrowser> browser, virtual RetVal HandlePrintOptions(CefRefPtr<CefBrowser> browser,
CefPrintOptions& printOptions) = 0; CefPrintOptions& printOptions) = 0;
// Event called to format print headers and footers. |printInfo| contains // Called on the UI thread to format print headers and footers. |printInfo|
// platform-specific information about the printer context. |url| is the // contains platform-specific information about the printer context. |url| is
// URL if the currently printing page, |title| is the title of the currently // the URL if the currently printing page, |title| is the title of the
// printing page, |currentPage| is the current page number and |maxPages| is // currently printing page, |currentPage| is the current page number and
// the total number of pages. Six default header locations are provided // |maxPages| is the total number of pages. Six default header locations are
// by the implementation: top left, top center, top right, bottom left, // provided by the implementation: top left, top center, top right, bottom
// bottom center and bottom right. To use one of these default locations // 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 // just assign a string to the appropriate variable. To draw the header and
// and footer yourself return RV_HANDLED. Otherwise, populate the approprate // footer yourself return RV_HANDLED. Otherwise, populate the approprate
// variables and return RV_CONTINUE. // variables and return RV_CONTINUE.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser, virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
@ -763,25 +776,26 @@ public:
CefString& bottomCenter, CefString& bottomCenter,
CefString& bottomRight) =0; CefString& bottomRight) =0;
// Run a JS alert message. Return RV_CONTINUE to display the default alert // Called on the UI thread to run a JS alert message. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom alert. // display the default alert or RV_HANDLED if you displayed a custom alert.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& message) =0; const CefString& message) =0;
// Run a JS confirm request. Return RV_CONTINUE to display the default alert // Called on the UI thread to run a JS confirm request. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom alert. If you handled the alert // display the default alert or RV_HANDLED if you displayed a custom alert. If
// set |retval| to true if the user accepted the confirmation. // you handled the alert set |retval| to true if the user accepted the
// confirmation.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& message, bool& retval) =0; const CefString& message, bool& retval) =0;
// Run a JS prompt request. Return RV_CONTINUE to display the default prompt // Called on the UI thread to run a JS prompt request. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom prompt. If you handled the prompt // display the default prompt or RV_HANDLED if you displayed a custom prompt.
// set |retval| to true if the user accepted the prompt and request and // If you handled the prompt set |retval| to true if the user accepted the
// |result| to the resulting value. // prompt and request and |result| to the resulting value.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
@ -790,29 +804,29 @@ public:
bool& retval, bool& retval,
CefString& result) =0; CefString& result) =0;
// Event called for adding values to a frame's JavaScript 'window' object. The // Called on the UI thread for adding values to a frame's JavaScript 'window'
// return value is currently ignored. // object. The return value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object) =0; CefRefPtr<CefV8Value> object) =0;
// Called just before a window is closed. The return value is currently // Called on the UI thread just before a window is closed. The return value is
// ignored. // currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser) =0; virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser) =0;
// Called when the browser component is about to loose focus. For instance, // Called on the UI thread when the browser component is about to loose focus.
// if focus was on the last HTML element and the user pressed the TAB key. // For instance, if focus was on the last HTML element and the user pressed
// The return value is currently ignored. // the TAB key. The return value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser, virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser,
bool reverse) =0; bool reverse) =0;
// Called when the browser component is requesting focus. |isWidget| will be // Called on the UI thread when the browser component is requesting focus.
// true if the focus is requested for a child widget of the browser window. // |isWidget| will be true if the focus is requested for a child widget of the
// Return RV_CONTINUE to allow the focus to be set or RV_HANDLED to cancel // browser window. Return RV_CONTINUE to allow the focus to be set or
// setting the focus. // RV_HANDLED to cancel setting the focus.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser,
bool isWidget) =0; bool isWidget) =0;
@ -820,14 +834,14 @@ public:
// Supported keyboard event types. // Supported keyboard event types.
typedef cef_handler_keyevent_type_t KeyEventType; typedef cef_handler_keyevent_type_t KeyEventType;
// Called when the browser component receives a keyboard event. // Called on the UI thread when the browser component receives a keyboard
// |type| is the type of keyboard event (see |KeyEventType|). // event. |type| is the type of keyboard event, |code| is the windows scan-
// |code| is the windows scan-code for the event. // code for the event, |modifiers| is a set of bit-flags describing any
// |modifiers| is a set of bit-flags describing any pressed modifier keys. // pressed modifier keys and |isSystemKey| is true if Windows considers this a
// |isSystemKey| is set if Windows considers this a 'system key' message; // 'system key' message (see
// (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx) // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx). Return
// Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE // RV_HANDLED if the keyboard event was handled or RV_CONTINUE to allow the
// to allow the browser component to handle the event. // browser component to handle the event.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser, virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
KeyEventType type, KeyEventType type,
@ -835,11 +849,11 @@ public:
int modifiers, int modifiers,
bool isSystemKey) =0; bool isSystemKey) =0;
// Event called when the browser is about to display a tooltip. |text| // Called on the UI thread when the browser is about to display a tooltip.
// contains the text that will be displayed in the tooltip. To handle // |text| contains the text that will be displayed in the tooltip. To handle
// the display of the tooltip yourself return RV_HANDLED. Otherwise, // the display of the tooltip yourself return RV_HANDLED. Otherwise, you can
// you can optionally modify |text| and then return RV_CONTINUE to allow // optionally modify |text| and then return RV_CONTINUE to allow the browser
// the browser to display the tooltip. // to display the tooltip.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser, virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
CefString& text) =0; CefString& text) =0;
@ -847,27 +861,28 @@ public:
// Status message types. // Status message types.
typedef cef_handler_statustype_t StatusType; typedef cef_handler_statustype_t StatusType;
// Event called when the browser has a status message. |text| contains the // Called on the UI thread when the browser has a status message. |text|
// text that will be displayed in the status message and |type| indicates the // contains the text that will be displayed in the status message and |type|
// status message type. The return value is currently ignored. // indicates the status message type. The return value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleStatus(CefRefPtr<CefBrowser> browser, virtual RetVal HandleStatus(CefRefPtr<CefBrowser> browser,
const CefString& value, const CefString& value,
StatusType type) =0; StatusType type) =0;
// Called to display a console message. Return RV_HANDLED to stop the message // Called on the UI thread to display a console message. Return RV_HANDLED to
// from being output to the console. // stop the message from being output to the console.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser, virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message, const CefString& message,
const CefString& source, int line) =0; const CefString& source, int line) =0;
// Called to report find results returned by CefBrowser::Find(). |identifer| // Called on the UI thread to report find results returned by
// is the identifier passed to CefBrowser::Find(), |count| is the number of // CefBrowser::Find(). |identifer| is the identifier passed to
// matches currently identified, |selectionRect| is the location of where the // CefBrowser::Find(), |count| is the number of matches currently identified,
// match was found (in window coordinates), |activeMatchOrdinal| is the // |selectionRect| is the location of where the match was found (in window
// current position in the search results, and |finalUpdate| is true if this // coordinates), |activeMatchOrdinal| is the current position in the search
// is the last find notification. The return value is currently ignored. // results, and |finalUpdate| is true if this is the last find notification.
// The return value is currently ignored.
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser, virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser,
int identifier, int count, int identifier, int count,
@ -876,7 +891,8 @@ public:
}; };
// Class used to represent a web request. // Class used to represent a web request. The methods of this class may be
// called on any thread.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefRequest : public CefBase class CefRequest : public CefBase
{ {
@ -921,7 +937,8 @@ public:
}; };
// Class used to represent post data for a web request. // Class used to represent post data for a web request. The methods of this
// class may be called on any thread.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefPostData : public CefBase class CefPostData : public CefBase
{ {
@ -955,7 +972,8 @@ public:
}; };
// Class used to represent a single element in the request post data. // Class used to represent a single element in the request post data. The
// methods of this class may be called on any thread.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefPostDataElement : public CefBase class CefPostDataElement : public CefBase
{ {
@ -999,7 +1017,8 @@ public:
}; };
// Interface the client can implement to provide a custom stream reader. // Interface the client can implement to provide a custom stream reader. The
// methods of this class may be called on any thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefReadHandler : public CefBase class CefReadHandler : public CefBase
{ {
@ -1023,7 +1042,8 @@ public:
}; };
// Class used to read data from a stream. // Class used to read data from a stream. The methods of this class may be
// called on any thread.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefStreamReader : public CefBase class CefStreamReader : public CefBase
{ {
@ -1034,7 +1054,8 @@ public:
/*--cef()--*/ /*--cef()--*/
static CefRefPtr<CefStreamReader> CreateForData(void* data, size_t size); static CefRefPtr<CefStreamReader> CreateForData(void* data, size_t size);
/*--cef()--*/ /*--cef()--*/
static CefRefPtr<CefStreamReader> CreateForHandler(CefRefPtr<CefReadHandler> handler); static CefRefPtr<CefStreamReader> CreateForHandler(
CefRefPtr<CefReadHandler> handler);
// Read raw binary data. // Read raw binary data.
/*--cef()--*/ /*--cef()--*/
@ -1056,7 +1077,8 @@ public:
}; };
// Interface the client can implement to provide a custom stream writer. // Interface the client can implement to provide a custom stream writer. The
// methods of this class may be called on any thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefWriteHandler : public CefBase class CefWriteHandler : public CefBase
{ {
@ -1080,7 +1102,8 @@ public:
}; };
// Class used to write data to a stream. // Class used to write data to a stream. The methods of this class may be called
// on any thread.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefStreamWriter : public CefBase class CefStreamWriter : public CefBase
{ {
@ -1089,7 +1112,8 @@ public:
/*--cef()--*/ /*--cef()--*/
static CefRefPtr<CefStreamWriter> CreateForFile(const CefString& fileName); static CefRefPtr<CefStreamWriter> CreateForFile(const CefString& fileName);
/*--cef()--*/ /*--cef()--*/
static CefRefPtr<CefStreamWriter> CreateForHandler(CefRefPtr<CefWriteHandler> handler); static CefRefPtr<CefStreamWriter> CreateForHandler(
CefRefPtr<CefWriteHandler> handler);
// Write raw binary data. // Write raw binary data.
/*--cef()--*/ /*--cef()--*/
@ -1112,7 +1136,8 @@ public:
typedef std::vector<CefRefPtr<CefV8Value> > CefV8ValueList; typedef std::vector<CefRefPtr<CefV8Value> > CefV8ValueList;
// Interface that should be implemented to handle V8 function calls. // Interface that should be implemented to handle V8 function calls. The methods
// of this class will always be called on the UI thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefV8Handler : public CefBase class CefV8Handler : public CefBase
{ {
@ -1128,7 +1153,8 @@ public:
}; };
// Class representing a V8 value. // Class representing a V8 value. The methods of this class should only be
// called on the UI thread.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefV8Value : public CefBase class CefV8Value : public CefBase
{ {
@ -1254,7 +1280,8 @@ public:
}; };
// Class that creates CefSchemeHandler instances. // Class that creates CefSchemeHandler instances. The methods of this class will
// always be called on the IO thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefSchemeHandlerFactory : public CefBase class CefSchemeHandlerFactory : public CefBase
{ {
@ -1265,7 +1292,8 @@ public:
}; };
// Class used to represent a custom scheme handler interface. // Class used to represent a custom scheme handler interface. The methods of
// this class will always be called on the IO thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefSchemeHandler : public CefBase class CefSchemeHandler : public CefBase
{ {
@ -1296,7 +1324,8 @@ public:
}; };
// Class used to handle file downloads. // Class used to handle file downloads. The methods of this class will always be
// called on the UI thread.
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefDownloadHandler : public CefBase class CefDownloadHandler : public CefBase
{ {
@ -1314,6 +1343,8 @@ public:
// Class that supports the reading of XML data via the libxml streaming API. // Class that supports the reading of XML data via the libxml streaming API.
// The methods of this class should only be called on the thread that creates
// the object.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefXmlReader : public CefBase class CefXmlReader : public CefBase
{ {
@ -1476,6 +1507,8 @@ public:
// Class that supports the reading of zip archives via the zlib unzip API. // Class that supports the reading of zip archives via the zlib unzip API.
// The methods of this class should only be called on the thread that creates
// the object.
/*--cef(source=library)--*/ /*--cef(source=library)--*/
class CefZipReader : public CefBase class CefZipReader : public CefBase
{ {

View File

@ -48,24 +48,26 @@ extern "C" {
#include "cef_types.h" #include "cef_types.h"
// This function should be called once when the application is started to // This function should be called on the main application thread to initialize
// initialize CEF. A return value of true (1) indicates that it succeeded and // CEF when the application is started. A return value of true (1) indicates
// false (0) indicates that it failed. // that it succeeded and false (0) indicates that it failed.
CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings, CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings,
const struct _cef_browser_settings_t* browser_defaults); const struct _cef_browser_settings_t* browser_defaults);
// This function should be called once before the application exits to shut down // This function should be called on the main application thread to shut down
// CEF. // CEF before the application exits.
CEF_EXPORT void cef_shutdown(); CEF_EXPORT void cef_shutdown();
// Perform message loop processing. Has no affect if the browser UI loop is // Perform message loop processing. This function must be called on the main
// running in a separate thread. // application thread if cef_initialize() is called with a
// CefSettings.multi_threaded_message_loop value of false (0).
CEF_EXPORT void cef_do_message_loop_work(); CEF_EXPORT void cef_do_message_loop_work();
// Register a new V8 extension with the specified JavaScript extension code and // Register a new V8 extension with the specified JavaScript extension code and
// handler. Functions implemented by the handler are prototyped using the // handler. Functions implemented by the handler are prototyped using the
// keyword 'native'. The calling of a native function is restricted to the scope // keyword 'native'. The calling of a native function is restricted to the scope
// in which the prototype of the native function is defined. // in which the prototype of the native function is defined. This function may
// be called on any thread.
// //
// Example JavaScript extension code: // Example JavaScript extension code:
// //
@ -124,7 +126,8 @@ CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name,
// Register a custom scheme handler factory for the specified |scheme_name| and // Register a custom scheme handler factory for the specified |scheme_name| and
// |host_name|. All URLs beginning with scheme_name://host_name/ can be handled // |host_name|. All URLs beginning with scheme_name://host_name/ can be handled
// by cef_scheme_handler_t instances returned by the factory. Specify an NULL // by cef_scheme_handler_t instances returned by the factory. Specify an NULL
// |host_name| value to match all host names. // |host_name| value to match all host names. This function may be called on any
// thread.
CEF_EXPORT int cef_register_scheme(const cef_string_t* scheme_name, CEF_EXPORT int cef_register_scheme(const cef_string_t* scheme_name,
const cef_string_t* host_name, const cef_string_t* host_name,
struct _cef_scheme_handler_factory_t* factory); struct _cef_scheme_handler_factory_t* factory);
@ -132,18 +135,20 @@ CEF_EXPORT int cef_register_scheme(const cef_string_t* scheme_name,
// CEF maintains multiple internal threads that are used for handling different // CEF maintains multiple internal threads that are used for handling different
// types of tasks. The UI thread creates the browser window and is used for all // types of tasks. The UI thread creates the browser window and is used for all
// interaction with the WebKit rendering engine and V8 JavaScript engine (The UI // interaction with the WebKit rendering engine and V8 JavaScript engine (The UI
// thread will be the same as the main application thread if cef_initialize() // thread will be the same as the main application thread if cef_initialize() is
// was called with a |multi_threaded_message_loop| value of false (0).) The IO // called with a CefSettings.multi_threaded_message_loop value of false (0).)
// thread is used for handling schema and network requests. The FILE thread is // The IO thread is used for handling schema and network requests. The FILE
// used for the application cache and other miscellaneous activities. This // thread is used for the application cache and other miscellaneous activities.
// function will return true (1) if called on the specified thread. // This function will return true (1) if called on the specified thread.
CEF_EXPORT int cef_currently_on(cef_thread_id_t threadId); CEF_EXPORT int cef_currently_on(cef_thread_id_t threadId);
// Post a task for execution on the specified thread. // Post a task for execution on the specified thread. This function may be
// called on any thread.
CEF_EXPORT int cef_post_task(cef_thread_id_t threadId, CEF_EXPORT int cef_post_task(cef_thread_id_t threadId,
struct _cef_task_t* task); struct _cef_task_t* task);
// Post a task for delayed execution on the specified thread. // Post a task for delayed execution on the specified thread. This function may
// be called on any thread.
CEF_EXPORT int cef_post_delayed_task(cef_thread_id_t threadId, CEF_EXPORT int cef_post_delayed_task(cef_thread_id_t threadId,
struct _cef_task_t* task, long delay_ms); struct _cef_task_t* task, long delay_ms);
@ -171,7 +176,8 @@ typedef struct _cef_base_t
#define CEF_MEMBER_MISSING(s, f) (!CEF_MEMBER_EXISTS(s, f) || !((s)->f)) #define CEF_MEMBER_MISSING(s, f) (!CEF_MEMBER_EXISTS(s, f) || !((s)->f))
// Implement this structure for task execution. // Implement this structure for task execution. The functions of this structure
// may be called on any thread.
typedef struct _cef_task_t typedef struct _cef_task_t
{ {
// Base structure. // Base structure.
@ -184,8 +190,8 @@ typedef struct _cef_task_t
} cef_task_t; } cef_task_t;
// Structure used to represent a browser window. All functions exposed by this // Structure used to represent a browser window. The functions of this structure
// structure should be thread safe. // may be called on any thread unless otherwise indicated in the comments.
typedef struct _cef_browser_t typedef struct _cef_browser_t
{ {
// Base structure. // Base structure.
@ -212,8 +218,8 @@ typedef struct _cef_browser_t
// Stop loading the page. // Stop loading the page.
void (CEF_CALLBACK *stop_load)(struct _cef_browser_t* self); void (CEF_CALLBACK *stop_load)(struct _cef_browser_t* self);
// Set focus for the browser window. If |enable| is true (1) focus will be // Set focus for the browser window. If |enable| is true (1) focus will be set
// set to the window. Otherwise, focus will be removed. // to the window. Otherwise, focus will be removed.
void (CEF_CALLBACK *set_focus)(struct _cef_browser_t* self, int enable); void (CEF_CALLBACK *set_focus)(struct _cef_browser_t* self, int enable);
// Retrieve the window handle for this browser. // Retrieve the window handle for this browser.
@ -231,15 +237,18 @@ typedef struct _cef_browser_t
struct _cef_frame_t* (CEF_CALLBACK *get_main_frame)( struct _cef_frame_t* (CEF_CALLBACK *get_main_frame)(
struct _cef_browser_t* self); struct _cef_browser_t* self);
// Returns the focused frame for the browser window. // Returns the focused frame for the browser window. This function should only
// be called on the UI thread.
struct _cef_frame_t* (CEF_CALLBACK *get_focused_frame)( struct _cef_frame_t* (CEF_CALLBACK *get_focused_frame)(
struct _cef_browser_t* self); struct _cef_browser_t* self);
// Returns the frame with the specified name, or NULL if not found. // Returns the frame with the specified name, or NULL if not found. This
// function should only be called on the UI thread.
struct _cef_frame_t* (CEF_CALLBACK *get_frame)(struct _cef_browser_t* self, struct _cef_frame_t* (CEF_CALLBACK *get_frame)(struct _cef_browser_t* self,
const cef_string_t* name); const cef_string_t* name);
// Returns the names of all existing frames. // Returns the names of all existing frames. This function should only be
// called on the UI thread.
void (CEF_CALLBACK *get_frame_names)(struct _cef_browser_t* self, void (CEF_CALLBACK *get_frame_names)(struct _cef_browser_t* self,
cef_string_list_t names); cef_string_list_t names);
@ -275,21 +284,21 @@ typedef struct _cef_browser_t
// Create a new browser window using the window parameters specified by // Create a new browser window using the window parameters specified by
// |windowInfo|. All values will be copied internally and the actual window will // |windowInfo|. All values will be copied internally and the actual window will
// be created on the UI thread. The |popup| parameter should be true (1) if the // be created on the UI thread. The |popup| parameter should be true (1) if the
// new window is a popup window. This function call will not block. // new window is a popup window. This function call will not block.
CEF_EXPORT int cef_browser_create(cef_window_info_t* windowInfo, int popup, CEF_EXPORT int cef_browser_create(cef_window_info_t* windowInfo, int popup,
struct _cef_handler_t* handler, const cef_string_t* url); struct _cef_handler_t* handler, const cef_string_t* url);
// Create a new browser window using the window parameters specified by // Create a new browser window using the window parameters specified by
// |windowInfo|. The |popup| parameter should be true (1) if the new window is a // |windowInfo|. The |popup| parameter should be true (1) if the new window is a
// popup window. This function call will block and can only be used if the // popup window. This function should only be called on the UI thread.
// |multi_threaded_message_loop| parameter to cef_initialize() is false (0).
CEF_EXPORT cef_browser_t* cef_browser_create_sync(cef_window_info_t* windowInfo, CEF_EXPORT cef_browser_t* cef_browser_create_sync(cef_window_info_t* windowInfo,
int popup, struct _cef_handler_t* handler, const cef_string_t* url); int popup, struct _cef_handler_t* handler, const cef_string_t* url);
// Structure used to represent a frame in the browser window. All functions // Structure used to represent a frame in the browser window. The functions of
// exposed by this structure should be thread safe. // this structure may be called on any thread unless otherwise indicated in the
// comments.
typedef struct _cef_frame_t typedef struct _cef_frame_t
{ {
// Base structure. // Base structure.
@ -324,11 +333,13 @@ typedef struct _cef_frame_t
// default text viewing application. // default text viewing application.
void (CEF_CALLBACK *view_source)(struct _cef_frame_t* self); void (CEF_CALLBACK *view_source)(struct _cef_frame_t* self);
// Returns this frame's HTML source as a string. // Returns this frame's HTML source as a string. This function should only be
// called on the UI thread.
// The resulting string must be freed by calling cef_string_userfree_free(). // The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_source)(struct _cef_frame_t* self); cef_string_userfree_t (CEF_CALLBACK *get_source)(struct _cef_frame_t* self);
// Returns this frame's display text as a string. // Returns this frame's display text as a string. This function should only be
// called on the UI thread.
// The resulting string must be freed by calling cef_string_userfree_free(). // The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_text)(struct _cef_frame_t* self); cef_string_userfree_t (CEF_CALLBACK *get_text)(struct _cef_frame_t* self);
@ -360,14 +371,16 @@ typedef struct _cef_frame_t
// Returns true (1) if this is the main frame. // Returns true (1) if this is the main frame.
int (CEF_CALLBACK *is_main)(struct _cef_frame_t* self); int (CEF_CALLBACK *is_main)(struct _cef_frame_t* self);
// Returns true (1) if this is the focused frame. // Returns true (1) if this is the focused frame. This function should only be
// called on the UI thread.
int (CEF_CALLBACK *is_focused)(struct _cef_frame_t* self); int (CEF_CALLBACK *is_focused)(struct _cef_frame_t* self);
// Returns this frame's name. // Returns this frame's name.
// The resulting string must be freed by calling cef_string_userfree_free(). // The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_name)(struct _cef_frame_t* self); cef_string_userfree_t (CEF_CALLBACK *get_name)(struct _cef_frame_t* self);
// Return the URL currently loaded in this frame. // Return the URL currently loaded in this frame. This function should only be
// called on the UI thread.
// The resulting string must be freed by calling cef_string_userfree_free(). // The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_url)(struct _cef_frame_t* self); cef_string_userfree_t (CEF_CALLBACK *get_url)(struct _cef_frame_t* self);
@ -375,22 +388,22 @@ typedef struct _cef_frame_t
// Structure that should be implemented to handle events generated by the // Structure that should be implemented to handle events generated by the
// browser window. All functions exposed by this structure should be thread // browser window. The functions of this structure will be called on the thread
// safe. Each function in the structure returns a RetVal value. // indicated in the function comments.
typedef struct _cef_handler_t typedef struct _cef_handler_t
{ {
// Base structure. // Base structure.
cef_base_t base; cef_base_t base;
// Event called before a new window is created. The |parentBrowser| parameter // Called on the UI thread before a new window is created. The |parentBrowser|
// will point to the parent browser window, if any. The |popup| parameter will // parameter will point to the parent browser window, if any. The |popup|
// be true (1) if the new window is a popup window, in which case // parameter will be true (1) if the new window is a popup window, in which
// |popupFeatures| will contain information about the style of popup window // case |popupFeatures| will contain information about the style of popup
// requested. If you create the window yourself you should populate the window // window requested. If you create the window yourself you should populate the
// handle member of |createInfo| and return RV_HANDLED. Otherwise, return // window handle member of |createInfo| and return RV_HANDLED. Otherwise,
// RV_CONTINUE and the framework will create the window. By default, a newly // return RV_CONTINUE and the framework will create the window. By default, a
// created window will recieve the same handler as the parent window. To // newly created window will recieve the same handler as the parent window.
// change the handler for the new window modify the object that |handler| // To change the handler for the new window modify the object that |handler|
// points to. // points to.
enum cef_retval_t (CEF_CALLBACK *handle_before_created)( enum cef_retval_t (CEF_CALLBACK *handle_before_created)(
struct _cef_handler_t* self, struct _cef_browser_t* parentBrowser, struct _cef_handler_t* self, struct _cef_browser_t* parentBrowser,
@ -399,148 +412,149 @@ typedef struct _cef_handler_t
struct _cef_handler_t** handler, cef_string_t* url, struct _cef_handler_t** handler, cef_string_t* url,
struct _cef_browser_settings_t* settings); struct _cef_browser_settings_t* settings);
// Event called after a new window is created. The return value is currently // Called on the UI thread after a new window is created. The return value is
// ignored. // currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_after_created)( enum cef_retval_t (CEF_CALLBACK *handle_after_created)(
struct _cef_handler_t* self, struct _cef_browser_t* browser); struct _cef_handler_t* self, struct _cef_browser_t* browser);
// Event called when a frame's address has changed. The return value is // Called on the UI thread when a frame's address has changed. The return
// currently ignored. // value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_address_change)( enum cef_retval_t (CEF_CALLBACK *handle_address_change)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, const cef_string_t* url); struct _cef_frame_t* frame, const cef_string_t* url);
// Event called when the page title changes. The return value is currently // Called on the UI thread when the page title changes. The return value is
// ignored. // currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_title_change)( enum cef_retval_t (CEF_CALLBACK *handle_title_change)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
const cef_string_t* title); const cef_string_t* title);
// Event called before browser navigation. The client has an opportunity to // Called on the UI thread before browser navigation. The client has an
// modify the |request| object if desired. Return RV_HANDLED to cancel // opportunity to modify the |request| object if desired. Return RV_HANDLED
// navigation. // to cancel navigation.
enum cef_retval_t (CEF_CALLBACK *handle_before_browse)( enum cef_retval_t (CEF_CALLBACK *handle_before_browse)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, struct _cef_request_t* request, struct _cef_frame_t* frame, struct _cef_request_t* request,
enum cef_handler_navtype_t navType, int isRedirect); enum cef_handler_navtype_t navType, int isRedirect);
// Event called when the browser begins loading a page. The |frame| pointer // Called on the UI thread when the browser begins loading a page. The |frame|
// will be NULL if the event represents the overall load status and not the // pointer will be NULL if the event represents the overall load status and
// load status for a particular frame. |isMainContent| will be true (1) if // not the load status for a particular frame. |isMainContent| will be true
// this load is for the main content area and not an iframe. This function may // (1) if this load is for the main content area and not an iframe. This
// not be called if the load request fails. The return value is currently // function may not be called if the load request fails. The return value is
// ignored. // currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_load_start)( enum cef_retval_t (CEF_CALLBACK *handle_load_start)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, int isMainContent); struct _cef_frame_t* frame, int isMainContent);
// Event called when the browser is done loading a page. The |frame| pointer // Called on the UI thread when the browser is done loading a page. The
// will be NULL if the event represents the overall load status and not the // |frame| pointer will be NULL if the event represents the overall load
// load status for a particular frame. |isMainContent| will be true (1) if // status and not the load status for a particular frame. |isMainContent| will
// this load is for the main content area and not an iframe. This function // be true (1) if this load is for the main content area and not an iframe.
// will be called irrespective of whether the request completes successfully. // This function will be called irrespective of whether the request completes
// The return value is currently ignored. // successfully. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_load_end)(struct _cef_handler_t* self, enum cef_retval_t (CEF_CALLBACK *handle_load_end)(struct _cef_handler_t* self,
struct _cef_browser_t* browser, struct _cef_frame_t* frame, struct _cef_browser_t* browser, struct _cef_frame_t* frame,
int isMainContent, int httpStatusCode); int isMainContent, int httpStatusCode);
// Called when the browser fails to load a resource. |errorCode| is the error // Called on the UI thread when the browser fails to load a resource.
// code number and |failedUrl| is the URL that failed to load. To provide // |errorCode| is the error code number and |failedUrl| is the URL that failed
// custom error text assign the text to |errorText| and return RV_HANDLED. // to load. To provide custom error text assign the text to |errorText| and
// Otherwise, return RV_CONTINUE for the default error text. // return RV_HANDLED. Otherwise, return RV_CONTINUE for the default error
// text.
enum cef_retval_t (CEF_CALLBACK *handle_load_error)( enum cef_retval_t (CEF_CALLBACK *handle_load_error)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, enum cef_handler_errorcode_t errorCode, struct _cef_frame_t* frame, enum cef_handler_errorcode_t errorCode,
const cef_string_t* failedUrl, cef_string_t* errorText); const cef_string_t* failedUrl, cef_string_t* errorText);
// Event called before a resource is loaded. To allow the resource to load // Called on the IO thread before a resource is loaded. To allow the resource
// normally return RV_CONTINUE. To redirect the resource to a new url populate // to load normally return RV_CONTINUE. To redirect the resource to a new url
// the |redirectUrl| value and return RV_CONTINUE. To specify data for the // populate the |redirectUrl| value and return RV_CONTINUE. To specify data
// resource return a CefStream object in |resourceStream|, set |mimeType| to // for the resource return a CefStream object in |resourceStream|, set
// the resource stream's mime type, and return RV_CONTINUE. To cancel loading // |mimeType| to the resource stream's mime type, and return RV_CONTINUE. To
// of the resource return RV_HANDLED. Any modifications to |request| will be // cancel loading of the resource return RV_HANDLED. Any modifications to
// observed. If the URL in |request| is changed and |redirectUrl| is also // |request| will be observed. If the URL in |request| is changed and
// set, the URL in |request| will be used. // |redirectUrl| is also set, the URL in |request| will be used.
enum cef_retval_t (CEF_CALLBACK *handle_before_resource_load)( enum cef_retval_t (CEF_CALLBACK *handle_before_resource_load)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_request_t* request, cef_string_t* redirectUrl, struct _cef_request_t* request, cef_string_t* redirectUrl,
struct _cef_stream_reader_t** resourceStream, cef_string_t* mimeType, struct _cef_stream_reader_t** resourceStream, cef_string_t* mimeType,
int loadFlags); int loadFlags);
// Called to handle requests for URLs with an unknown protocol component. // Called on the IO thread to handle requests for URLs with an unknown
// Return RV_HANDLED to indicate that the request should succeed because it // protocol component. Return RV_HANDLED to indicate that the request should
// was externally handled. Set |allow_os_execution| to true (1) and return // succeed because it was externally handled. Set |allow_os_execution| to true
// RV_CONTINUE to attempt execution via the registered OS protocol handler, if // (1) and return RV_CONTINUE to attempt execution via the registered OS
// any. If RV_CONTINUE is returned and either |allow_os_execution| is false // protocol handler, if any. If RV_CONTINUE is returned and either
// (0) or OS protocol handler execution fails then the request will fail with // |allow_os_execution| is false (0) or OS protocol handler execution fails
// an error condition. SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE // then the request will fail with an error condition. SECURITY WARNING: YOU
// RESTRICTIONS BASED ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS // SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED ON SCHEME, HOST OR
// EXECUTION. // OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.
enum cef_retval_t (CEF_CALLBACK *handle_protocol_execution)( enum cef_retval_t (CEF_CALLBACK *handle_protocol_execution)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
const cef_string_t* url, int* allow_os_execution); const cef_string_t* url, int* allow_os_execution);
// Called when a server indicates via the 'Content-Disposition' header that a // Called on the UI thread when a server indicates via the 'Content-
// response represents a file to download. |mimeType| is the mime type for the // Disposition' header that a response represents a file to download.
// download, |fileName| is the suggested target file name and |contentLength| // |mimeType| is the mime type for the download, |fileName| is the suggested
// is either the value of the 'Content-Size' header or -1 if no size was // target file name and |contentLength| is either the value of the 'Content-
// provided. Set |handler| to the cef_download_handler_t instance that will // Size' header or -1 if no size was provided. Set |handler| to the
// recieve the file contents. Return RV_CONTINUE to download the file or // cef_download_handler_t instance that will recieve the file contents. Return
// RV_HANDLED to cancel the file download. // RV_CONTINUE to download the file or RV_HANDLED to cancel the file download.
enum cef_retval_t (CEF_CALLBACK *handle_download_response)( enum cef_retval_t (CEF_CALLBACK *handle_download_response)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
const cef_string_t* mimeType, const cef_string_t* fileName, const cef_string_t* mimeType, const cef_string_t* fileName,
int64 contentLength, struct _cef_download_handler_t** handler); int64 contentLength, struct _cef_download_handler_t** handler);
// Called when the browser needs credentials from the user. |isProxy| // Called on the IO thread when the browser needs credentials from the user.
// indicates whether the host is a proxy server. |host| contains the hostname // |isProxy| indicates whether the host is a proxy server. |host| contains the
// and port number. Set |username| and |password| and return RV_HANDLED to // hostname and port number. Set |username| and |password| and return
// handle the request. Return RV_CONTINUE to cancel the request. // RV_HANDLED to handle the request. Return RV_CONTINUE to cancel the request.
enum cef_retval_t (CEF_CALLBACK *handle_authentication_request)( enum cef_retval_t (CEF_CALLBACK *handle_authentication_request)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, int isProxy, struct _cef_handler_t* self, struct _cef_browser_t* browser, int isProxy,
const cef_string_t* host, const cef_string_t* realm, const cef_string_t* host, const cef_string_t* realm,
const cef_string_t* scheme, cef_string_t* username, const cef_string_t* scheme, cef_string_t* username,
cef_string_t* password); cef_string_t* password);
// Event called before a context menu is displayed. To cancel display of the // Called on the UI thread before a context menu is displayed. To cancel
// default context menu return RV_HANDLED. // display of the default context menu return RV_HANDLED.
enum cef_retval_t (CEF_CALLBACK *handle_before_menu)( enum cef_retval_t (CEF_CALLBACK *handle_before_menu)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
const struct _cef_handler_menuinfo_t* menuInfo); const struct _cef_handler_menuinfo_t* menuInfo);
// Event called to optionally override the default text for a context menu // Called on the UI thread to optionally override the default text for a
// item. |label| contains the default text and may be modified to substitute // context menu item. |label| contains the default text and may be modified to
// alternate text. The return value is currently ignored. // substitute alternate text. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_get_menu_label)( enum cef_retval_t (CEF_CALLBACK *handle_get_menu_label)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
enum cef_handler_menuid_t menuId, cef_string_t* label); enum cef_handler_menuid_t menuId, cef_string_t* label);
// Event called when an option is selected from the default context menu. // Called on the UI thread when an option is selected from the default context
// Return RV_HANDLED to cancel default handling of the action. // menu. Return RV_HANDLED to cancel default handling of the action.
enum cef_retval_t (CEF_CALLBACK *handle_menu_action)( enum cef_retval_t (CEF_CALLBACK *handle_menu_action)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
enum cef_handler_menuid_t menuId); enum cef_handler_menuid_t menuId);
// Event called to allow customization of standard print options before the // Called on the UI thread to allow customization of standard print options
// print dialog is displayed. |printOptions| allows specification of paper // before the print dialog is displayed. |printOptions| allows specification
// size, orientation and margins. Note that the specified margins may be // of paper size, orientation and margins. Note that the specified margins may
// adjusted if they are outside the range supported by the printer. All units // be adjusted if they are outside the range supported by the printer. All
// are in inches. Return RV_CONTINUE to display the default print options or // units are in inches. Return RV_CONTINUE to display the default print
// RV_HANDLED to display the modified |printOptions|. // options or RV_HANDLED to display the modified |printOptions|.
enum cef_retval_t (CEF_CALLBACK *handle_print_options)( enum cef_retval_t (CEF_CALLBACK *handle_print_options)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_print_options_t* printOptions); struct _cef_print_options_t* printOptions);
// Event called to format print headers and footers. |printInfo| contains // Called on the UI thread to format print headers and footers. |printInfo|
// platform-specific information about the printer context. |url| is the URL // contains platform-specific information about the printer context. |url| is
// if the currently printing page, |title| is the title of the currently // the URL if the currently printing page, |title| is the title of the
// printing page, |currentPage| is the current page number and |maxPages| is // currently printing page, |currentPage| is the current page number and
// the total number of pages. Six default header locations are provided by // |maxPages| is the total number of pages. Six default header locations are
// the implementation: top left, top center, top right, bottom left, bottom // provided by the implementation: top left, top center, top right, bottom
// center and bottom right. To use one of these default locations just assign // left, bottom center and bottom right. To use one of these default locations
// a string to the appropriate variable. To draw the header and footer // just assign a string to the appropriate variable. To draw the header and
// yourself return RV_HANDLED. Otherwise, populate the approprate variables // footer yourself return RV_HANDLED. Otherwise, populate the approprate
// and return RV_CONTINUE. // variables and return RV_CONTINUE.
enum cef_retval_t (CEF_CALLBACK *handle_print_header_footer)( enum cef_retval_t (CEF_CALLBACK *handle_print_header_footer)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, struct _cef_print_info_t* printInfo, struct _cef_frame_t* frame, struct _cef_print_info_t* printInfo,
@ -549,95 +563,96 @@ typedef struct _cef_handler_t
cef_string_t* topRight, cef_string_t* bottomLeft, cef_string_t* topRight, cef_string_t* bottomLeft,
cef_string_t* bottomCenter, cef_string_t* bottomRight); cef_string_t* bottomCenter, cef_string_t* bottomRight);
// Run a JS alert message. Return RV_CONTINUE to display the default alert or // Called on the UI thread to run a JS alert message. Return RV_CONTINUE to
// RV_HANDLED if you displayed a custom alert. // display the default alert or RV_HANDLED if you displayed a custom alert.
enum cef_retval_t (CEF_CALLBACK *handle_jsalert)(struct _cef_handler_t* self, enum cef_retval_t (CEF_CALLBACK *handle_jsalert)(struct _cef_handler_t* self,
struct _cef_browser_t* browser, struct _cef_frame_t* frame, struct _cef_browser_t* browser, struct _cef_frame_t* frame,
const cef_string_t* message); const cef_string_t* message);
// Run a JS confirm request. Return RV_CONTINUE to display the default alert // Called on the UI thread to run a JS confirm request. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom alert. If you handled the alert // display the default alert or RV_HANDLED if you displayed a custom alert. If
// set |retval| to true (1) if the user accepted the confirmation. // you handled the alert set |retval| to true (1) if the user accepted the
// confirmation.
enum cef_retval_t (CEF_CALLBACK *handle_jsconfirm)( enum cef_retval_t (CEF_CALLBACK *handle_jsconfirm)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, const cef_string_t* message, int* retval); struct _cef_frame_t* frame, const cef_string_t* message, int* retval);
// Run a JS prompt request. Return RV_CONTINUE to display the default prompt // Called on the UI thread to run a JS prompt request. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom prompt. If you handled the prompt // display the default prompt or RV_HANDLED if you displayed a custom prompt.
// set |retval| to true (1) if the user accepted the prompt and request and // If you handled the prompt set |retval| to true (1) if the user accepted the
// |result| to the resulting value. // prompt and request and |result| to the resulting value.
enum cef_retval_t (CEF_CALLBACK *handle_jsprompt)(struct _cef_handler_t* self, enum cef_retval_t (CEF_CALLBACK *handle_jsprompt)(struct _cef_handler_t* self,
struct _cef_browser_t* browser, struct _cef_frame_t* frame, struct _cef_browser_t* browser, struct _cef_frame_t* frame,
const cef_string_t* message, const cef_string_t* defaultValue, const cef_string_t* message, const cef_string_t* defaultValue,
int* retval, cef_string_t* result); int* retval, cef_string_t* result);
// Event called for adding values to a frame's JavaScript 'window' object. The // Called on the UI thread for adding values to a frame's JavaScript 'window'
// return value is currently ignored. // object. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_jsbinding)( enum cef_retval_t (CEF_CALLBACK *handle_jsbinding)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, struct _cef_v8value_t* object); struct _cef_frame_t* frame, struct _cef_v8value_t* object);
// Called just before a window is closed. The return value is currently // Called on the UI thread just before a window is closed. The return value is
// ignored. // currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_before_window_close)( enum cef_retval_t (CEF_CALLBACK *handle_before_window_close)(
struct _cef_handler_t* self, struct _cef_browser_t* browser); struct _cef_handler_t* self, struct _cef_browser_t* browser);
// Called when the browser component is about to loose focus. For instance, if // Called on the UI thread when the browser component is about to loose focus.
// focus was on the last HTML element and the user pressed the TAB key. The // For instance, if focus was on the last HTML element and the user pressed
// return value is currently ignored. // the TAB key. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_take_focus)( enum cef_retval_t (CEF_CALLBACK *handle_take_focus)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
int reverse); int reverse);
// Called when the browser component is requesting focus. |isWidget| will be // Called on the UI thread when the browser component is requesting focus.
// true (1) if the focus is requested for a child widget of the browser // |isWidget| will be true (1) if the focus is requested for a child widget of
// window. Return RV_CONTINUE to allow the focus to be set or RV_HANDLED to // the browser window. Return RV_CONTINUE to allow the focus to be set or
// cancel setting the focus. // RV_HANDLED to cancel setting the focus.
enum cef_retval_t (CEF_CALLBACK *handle_set_focus)( enum cef_retval_t (CEF_CALLBACK *handle_set_focus)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
int isWidget); int isWidget);
// Called when the browser component receives a keyboard event. |type| is the // Called on the UI thread when the browser component receives a keyboard
// type of keyboard event (see |KeyEventType|). |code| is the windows scan- // 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 // code for the event, |modifiers| is a set of bit-flags describing any
// pressed modifier keys. |isSystemKey| is set if Windows considers this a // pressed modifier keys and |isSystemKey| is true (1) if Windows considers
// 'system key' message; // this a 'system key' message (see http://msdn.microsoft.com/en-
// (see http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx) // us/library/ms646286(VS.85).aspx). Return RV_HANDLED if the keyboard event
// Return RV_HANDLED if the keyboard event was handled or RV_CONTINUE to allow // was handled or RV_CONTINUE to allow the browser component to handle the
// the browser component to handle the event. // event.
enum cef_retval_t (CEF_CALLBACK *handle_key_event)( enum cef_retval_t (CEF_CALLBACK *handle_key_event)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
enum cef_handler_keyevent_type_t type, int code, int modifiers, enum cef_handler_keyevent_type_t type, int code, int modifiers,
int isSystemKey); int isSystemKey);
// Event called when the browser is about to display a tooltip. |text| // Called on the UI thread when the browser is about to display a tooltip.
// contains the text that will be displayed in the tooltip. To handle the // |text| contains the text that will be displayed in the tooltip. To handle
// display of the tooltip yourself return RV_HANDLED. Otherwise, you can // the display of the tooltip yourself return RV_HANDLED. Otherwise, you can
// optionally modify |text| and then return RV_CONTINUE to allow the browser // optionally modify |text| and then return RV_CONTINUE to allow the browser
// to display the tooltip. // to display the tooltip.
enum cef_retval_t (CEF_CALLBACK *handle_tooltip)(struct _cef_handler_t* self, enum cef_retval_t (CEF_CALLBACK *handle_tooltip)(struct _cef_handler_t* self,
struct _cef_browser_t* browser, cef_string_t* text); struct _cef_browser_t* browser, cef_string_t* text);
// Event called when the browser has a status message. |text| contains the // Called on the UI thread when the browser has a status message. |text|
// text that will be displayed in the status message and |type| indicates the // contains the text that will be displayed in the status message and |type|
// status message type. The return value is currently ignored. // indicates the status message type. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_status)(struct _cef_handler_t* self, enum cef_retval_t (CEF_CALLBACK *handle_status)(struct _cef_handler_t* self,
struct _cef_browser_t* browser, const cef_string_t* value, struct _cef_browser_t* browser, const cef_string_t* value,
enum cef_handler_statustype_t type); enum cef_handler_statustype_t type);
// Called to display a console message. Return RV_HANDLED to stop the message // Called on the UI thread to display a console message. Return RV_HANDLED to
// from being output to the console. // stop the message from being output to the console.
enum cef_retval_t (CEF_CALLBACK *handle_console_message)( enum cef_retval_t (CEF_CALLBACK *handle_console_message)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
const cef_string_t* message, const cef_string_t* source, int line); const cef_string_t* message, const cef_string_t* source, int line);
// Called to report find results returned by cef_browser_t::find(). // Called on the UI thread to report find results returned by
// |identifer| is the identifier passed to cef_browser_t::find(), |count| is // cef_browser_t::find(). |identifer| is the identifier passed to
// the number of matches currently identified, |selectionRect| is the location // cef_browser_t::find(), |count| is the number of matches currently
// of where the match was found (in window coordinates), |activeMatchOrdinal| // identified, |selectionRect| is the location of where the match was found
// is the current position in the search results, and |finalUpdate| is true // (in window coordinates), |activeMatchOrdinal| is the current position in
// (1) if this is the last find notification. The return value is currently // the search results, and |finalUpdate| is true (1) if this is the last find
// ignored. // notification. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_find_result)( enum cef_retval_t (CEF_CALLBACK *handle_find_result)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
int identifier, int count, const cef_rect_t* selectionRect, int identifier, int count, const cef_rect_t* selectionRect,
@ -646,7 +661,8 @@ typedef struct _cef_handler_t
} cef_handler_t; } cef_handler_t;
// Structure used to represent a web request. // Structure used to represent a web request. The functions of this structure
// may be called on any thread.
typedef struct _cef_request_t typedef struct _cef_request_t
{ {
// Base structure. // Base structure.
@ -689,7 +705,8 @@ typedef struct _cef_request_t
CEF_EXPORT cef_request_t* cef_request_create(); CEF_EXPORT cef_request_t* cef_request_create();
// Structure used to represent post data for a web request. // Structure used to represent post data for a web request. The functions of
// this structure may be called on any thread.
typedef struct _cef_post_data_t typedef struct _cef_post_data_t
{ {
// Base structure. // Base structure.
@ -721,7 +738,8 @@ typedef struct _cef_post_data_t
CEF_EXPORT cef_post_data_t* cef_post_data_create(); CEF_EXPORT cef_post_data_t* cef_post_data_create();
// Structure used to represent a single element in the request post data. // Structure used to represent a single element in the request post data. The
// functions of this structure may be called on any thread.
typedef struct _cef_post_data_element_t typedef struct _cef_post_data_element_t
{ {
// Base structure. // Base structure.
@ -763,7 +781,8 @@ typedef struct _cef_post_data_element_t
CEF_EXPORT cef_post_data_element_t* cef_post_data_element_create(); CEF_EXPORT cef_post_data_element_t* cef_post_data_element_create();
// Structure the client can implement to provide a custom stream reader. // Structure the client can implement to provide a custom stream reader. The
// functions of this structure may be called on any thread.
typedef struct _cef_read_handler_t typedef struct _cef_read_handler_t
{ {
// Base structure. // Base structure.
@ -787,7 +806,8 @@ typedef struct _cef_read_handler_t
} cef_read_handler_t; } cef_read_handler_t;
// Structure used to read data from a stream. // Structure used to read data from a stream. The functions of this structure
// may be called on any thread.
typedef struct _cef_stream_reader_t typedef struct _cef_stream_reader_t
{ {
// Base structure. // Base structure.
@ -820,7 +840,8 @@ CEF_EXPORT cef_stream_reader_t* cef_stream_reader_create_for_handler(
cef_read_handler_t* handler); cef_read_handler_t* handler);
// Structure the client can implement to provide a custom stream writer. // Structure the client can implement to provide a custom stream writer. The
// functions of this structure may be called on any thread.
typedef struct _cef_write_handler_t typedef struct _cef_write_handler_t
{ {
// Base structure. // Base structure.
@ -844,7 +865,8 @@ typedef struct _cef_write_handler_t
} cef_write_handler_t; } cef_write_handler_t;
// Structure used to write data to a stream. // Structure used to write data to a stream. The functions of this structure may
// be called on any thread.
typedef struct _cef_stream_writer_t typedef struct _cef_stream_writer_t
{ {
// Base structure. // Base structure.
@ -875,7 +897,8 @@ CEF_EXPORT cef_stream_writer_t* cef_stream_writer_create_for_handler(
cef_write_handler_t* handler); cef_write_handler_t* handler);
// Structure that should be implemented to handle V8 function calls. // Structure that should be implemented to handle V8 function calls. The
// functions of this structure will always be called on the UI thread.
typedef struct _cef_v8handler_t typedef struct _cef_v8handler_t
{ {
// Base structure. // Base structure.
@ -891,7 +914,8 @@ typedef struct _cef_v8handler_t
} cef_v8handler_t; } cef_v8handler_t;
// Structure representing a V8 value. // Structure representing a V8 value. The functions of this structure should
// only be called on the UI thread.
typedef struct _cef_v8value_t typedef struct _cef_v8value_t
{ {
// Base structure. // Base structure.
@ -998,7 +1022,8 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_function(const cef_string_t* name,
cef_v8handler_t* handler); cef_v8handler_t* handler);
// Structure that creates cef_scheme_handler_t instances. // Structure that creates cef_scheme_handler_t instances. The functions of this
// structure will always be called on the IO thread.
typedef struct _cef_scheme_handler_factory_t typedef struct _cef_scheme_handler_factory_t
{ {
// Base structure. // Base structure.
@ -1011,7 +1036,8 @@ typedef struct _cef_scheme_handler_factory_t
} cef_scheme_handler_factory_t; } cef_scheme_handler_factory_t;
// Structure used to represent a custom scheme handler structure. // Structure used to represent a custom scheme handler structure. The functions
// of this structure will always be called on the IO thread.
typedef struct _cef_scheme_handler_t typedef struct _cef_scheme_handler_t
{ {
// Base structure. // Base structure.
@ -1042,7 +1068,8 @@ typedef struct _cef_scheme_handler_t
} cef_scheme_handler_t; } cef_scheme_handler_t;
// Structure used to handle file downloads. // Structure used to handle file downloads. The functions of this structure will
// always be called on the UI thread.
typedef struct _cef_download_handler_t typedef struct _cef_download_handler_t
{ {
// Base structure. // Base structure.
@ -1061,6 +1088,8 @@ typedef struct _cef_download_handler_t
// Structure that supports the reading of XML data via the libxml streaming API. // Structure that supports the reading of XML data via the libxml streaming API.
// The functions of this structure should only be called on the thread that
// creates the object.
typedef struct _cef_xml_reader_t typedef struct _cef_xml_reader_t
{ {
// Base structure. // Base structure.
@ -1222,6 +1251,8 @@ CEF_EXPORT cef_xml_reader_t* cef_xml_reader_create(cef_stream_reader_t* stream,
// Structure that supports the reading of zip archives via the zlib unzip API. // Structure that supports the reading of zip archives via the zlib unzip API.
// The functions of this structure should only be called on the thread that
// creates the object.
typedef struct _cef_zip_reader_t typedef struct _cef_zip_reader_t
{ {
// Base structure. // Base structure.

View File

@ -29,7 +29,7 @@ BrowserDevToolsClient::BrowserDevToolsClient(CefBrowserImpl* browser,
: ALLOW_THIS_IN_INITIALIZER_LIST(call_method_factory_(this)), : ALLOW_THIS_IN_INITIALIZER_LIST(call_method_factory_(this)),
browser_(browser), browser_(browser),
dev_tools_agent_(agent), dev_tools_agent_(agent),
web_view_(browser->GetWebView()) { web_view_(browser->UIT_GetWebView()) {
web_tools_frontend_.reset(WebDevToolsFrontend::create(web_view_, this, web_tools_frontend_.reset(WebDevToolsFrontend::create(web_view_, this,
WebString::fromUTF8("en-US"))); WebString::fromUTF8("en-US")));
dev_tools_agent_->attach(this); dev_tools_agent_->attach(this);

View File

@ -44,12 +44,95 @@ using WebKit::WebURL;
using WebKit::WebURLRequest; using WebKit::WebURLRequest;
using WebKit::WebView; using WebKit::WebView;
namespace {
class CreateBrowserHelper
{
public:
CreateBrowserHelper(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler, const CefString& url)
: window_info_(windowInfo), popup_(popup),
handler_(handler), url_(url) {}
CefWindowInfo window_info_;
bool popup_;
CefRefPtr<CefHandler> handler_;
CefString url_;
};
void UIT_CreateBrowserWithHelper(CreateBrowserHelper* helper)
{
CefBrowser::CreateBrowserSync(helper->window_info_, helper->popup_,
helper->handler_, helper->url_);
delete helper;
}
} // namespace
// static
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const CefString& url)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
}
// Create the browser on the UI thread.
CreateBrowserHelper* helper =
new CreateBrowserHelper(windowInfo, popup, handler, url);
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableFunction(
UIT_CreateBrowserWithHelper, helper));
return true;
}
// static
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, CefRefPtr<CefHandler> handler, const CefString& url)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return NULL;
}
// Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
CefString newUrl = url;
CefRefPtr<CefBrowser> alternateBrowser;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
{
// Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED)
return false;
}
CefRefPtr<CefBrowser> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
return browser;
}
CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo, CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
const CefBrowserSettings& settings, bool popup, const CefBrowserSettings& settings, bool popup,
CefRefPtr<CefHandler> handler) CefRefPtr<CefHandler> handler)
: window_info_(windowInfo), settings_(settings), is_popup_(popup), : window_info_(windowInfo), settings_(settings), is_popup_(popup),
is_modal_(false), handler_(handler), webviewhost_(NULL), popuphost_(NULL), is_modal_(false), handler_(handler), webviewhost_(NULL), popuphost_(NULL),
frame_main_(NULL), unique_id_(0) zoom_level_(0.0), can_go_back_(false), can_go_forward_(false),
main_frame_(NULL), unique_id_(0)
{ {
delegate_.reset(new BrowserWebViewDelegate(this)); delegate_.reset(new BrowserWebViewDelegate(this));
popup_delegate_.reset(new BrowserWebViewDelegate(this)); popup_delegate_.reset(new BrowserWebViewDelegate(this));
@ -62,69 +145,12 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
} }
} }
bool CefBrowserImpl::CanGoBack()
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
// We need to send the request to the UI thread and wait for the result
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
bool retVal = true;
// Request the data from the UI thread
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_CanGoBackNotify, &retVal, &event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return retVal;
}
else
{
// Call the method directly
return UIT_CanGoBack();
}
}
void CefBrowserImpl::GoBack() void CefBrowserImpl::GoBack()
{ {
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_BACK)); &CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_BACK));
} }
bool CefBrowserImpl::CanGoForward()
{
if(!CefThread::CurrentlyOn(CefThread::UI))
{
// We need to send the request to the UI thread and wait for the result
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
bool retVal = true;
// Request the data from the UI thread
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_CanGoForwardNotify, &retVal, &event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return retVal;
}
else
{
// Call the method directly
return UIT_CanGoForward();
}
}
void CefBrowserImpl::GoForward() void CefBrowserImpl::GoForward()
{ {
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
@ -151,55 +177,53 @@ void CefBrowserImpl::StopLoad()
void CefBrowserImpl::SetFocus(bool enable) void CefBrowserImpl::SetFocus(bool enable)
{ {
if (CefThread::CurrentlyOn(CefThread::UI)) if (CefThread::CurrentlyOn(CefThread::UI)) {
{ UIT_SetFocus(UIT_GetWebViewHost(), enable);
UIT_SetFocus(GetWebViewHost(), enable); } else {
}
else
{
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_SetFocus, GetWebViewHost(), enable)); &CefBrowserImpl::UIT_SetFocus, UIT_GetWebViewHost(), enable));
} }
} }
bool CefBrowserImpl::IsPopup()
{
Lock();
bool popup = is_popup_;
Unlock();
return popup;
}
CefRefPtr<CefHandler> CefBrowserImpl::GetHandler()
{
return handler_;
}
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame()
{
return GetWebView() ? GetCefFrame(GetWebView()->mainFrame()) : NULL;
}
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame() CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame()
{ {
return GetWebView() ? GetCefFrame(GetWebView()->focusedFrame()) : NULL; // Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
WebView* view = UIT_GetWebView();
return view ? UIT_GetCefFrame(view->focusedFrame()) : NULL;
} }
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const CefString& name) CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const CefString& name)
{ {
WebView* view = GetWebView(); // Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return NULL;
}
WebView* view = UIT_GetWebView();
if (!view) if (!view)
return NULL; return NULL;
WebFrame* frame = view->findFrameByName(string16(name)); WebFrame* frame = view->findFrameByName(string16(name));
if(frame) if(frame)
return GetCefFrame(frame); return UIT_GetCefFrame(frame);
return NULL; return NULL;
} }
void CefBrowserImpl::GetFrameNames(std::vector<CefString>& names) void CefBrowserImpl::GetFrameNames(std::vector<CefString>& names)
{ {
WebView* view = GetWebView(); // Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return;
}
WebView* view = UIT_GetWebView();
if (!view) if (!view)
return; return;
@ -234,6 +258,12 @@ void CefBrowserImpl::StopFinding(bool clearSelection)
&CefBrowserImpl::UIT_StopFinding, clearSelection)); &CefBrowserImpl::UIT_StopFinding, clearSelection));
} }
void CefBrowserImpl::SetZoomLevel(double zoomLevel)
{
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_SetZoomLevel, zoomLevel));
}
void CefBrowserImpl::ShowDevTools() void CefBrowserImpl::ShowDevTools()
{ {
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
@ -246,63 +276,6 @@ void CefBrowserImpl::CloseDevTools()
&CefBrowserImpl::UIT_CloseDevTools)); &CefBrowserImpl::UIT_CloseDevTools));
} }
CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
{
CefRefPtr<CefFrame> cef_frame;
Lock();
WebView *view = GetWebView();
if(view) {
if(frame == view->mainFrame()) {
// Use or create the single main frame reference.
if(frame_main_ == NULL)
frame_main_ = new CefFrameImpl(this, CefString());
cef_frame = frame_main_;
} else {
// Locate or create the appropriate named reference.
CefString name = string16(frame->name());
DCHECK(!name.empty());
FrameMap::const_iterator it = frames_.find(name);
if(it != frames_.end())
cef_frame = it->second;
else {
cef_frame = new CefFrameImpl(this, name);
frames_.insert(std::make_pair(name, cef_frame.get()));
}
}
}
Unlock();
return cef_frame;
}
void CefBrowserImpl::RemoveCefFrame(const CefString& name)
{
Lock();
if(name.empty())
frame_main_ = NULL;
else {
FrameMap::iterator it = frames_.find(name);
if(it != frames_.end())
frames_.erase(it);
}
Unlock();
}
WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr<CefFrame> frame)
{
WebView* view = GetWebView();
if (!view)
return NULL;
CefString name = frame->GetName();
if(name.empty())
return view ->mainFrame();
return view ->findFrameByName(string16(name));
}
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame) void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame)
{ {
frame->AddRef(); frame->AddRef();
@ -369,70 +342,32 @@ void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame)
CefString CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame) CefString CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
{ {
if(!CefThread::CurrentlyOn(CefThread::UI)) // Verify that this method is being called on the UI thread.
{ if (!CefThread::CurrentlyOn(CefThread::UI)) {
// We need to send the request to the UI thread and wait for the result NOTREACHED();
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
// Request the data from the UI thread
frame->AddRef();
stream->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_GetDocumentStringNotify, frame.get(), stream.get(),
&event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return static_cast<CefBytesWriter*>(stream.get())->GetDataString();
}
else
{
// Retrieve the document string directly
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return string16(web_frame->contentAsMarkup());
return CefString(); return CefString();
} }
// Retrieve the document string directly
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
return string16(web_frame->contentAsMarkup());
return CefString();
} }
CefString CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame) CefString CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
{ {
if(!CefThread::CurrentlyOn(CefThread::UI)) // Verify that this method is being called on the UI thread.
{ if (!CefThread::CurrentlyOn(CefThread::UI)) {
// We need to send the request to the UI thread and wait for the result NOTREACHED();
// Event that will be used to signal that data is available. Start
// in non-signaled mode so that the event will block.
base::WaitableEvent event(false, false);
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
// Request the data from the UI thread
frame->AddRef();
stream->AddRef();
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
&CefBrowserImpl::UIT_GetDocumentTextNotify, frame.get(), stream.get(),
&event));
// Wait for the UI thread callback to tell us that the data is available
event.Wait();
return static_cast<CefBytesWriter*>(stream.get())->GetDataString();
}
else
{
// Retrieve the document text directly
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame)
return webkit_glue::DumpDocumentText(web_frame);
return CefString(); return CefString();
} }
// Retrieve the document text directly
WebKit::WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame)
return webkit_glue::DumpDocumentText(web_frame);
return CefString();
} }
void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame, void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
@ -487,96 +422,107 @@ void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
CefString CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame) CefString CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
{ {
WebFrame* web_frame = GetWebFrame(frame); // Verify that this method is being called on the UI thread.
if (!CefThread::CurrentlyOn(CefThread::UI)) {
NOTREACHED();
return CefString();
}
WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame) if(web_frame)
return std::string(web_frame->url().spec()); return std::string(web_frame->url().spec());
return CefString(); return CefString();
} }
double CefBrowserImpl::GetZoomLevel() CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(const CefString& name)
{ {
WebKit::WebFrame* web_frame = GetWebFrame(this->GetMainFrame()); CefRefPtr<CefFrame> cef_frame;
if(web_frame && web_frame->view()) if(name.empty()) {
return web_frame->view()->zoomLevel(); // Use the single main frame reference.
cef_frame = GetMainCefFrame();
return 0.0; } else {
} // Locate or create the appropriate named reference.
AutoLock lock_scope(this);
void CefBrowserImpl::SetZoomLevel(double zoomLevel) FrameMap::const_iterator it = frames_.find(name);
{ if(it != frames_.end())
CefRefPtr<CefFrame> frame = this->GetMainFrame(); cef_frame = it->second;
frame->AddRef(); else {
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, cef_frame = new CefFrameImpl(this, name);
&CefBrowserImpl::UIT_SetZoomLevel, frame.get(), zoomLevel)); frames_.insert(std::make_pair(name, cef_frame.get()));
} }
// static
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler,
const CefString& url)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
} }
CefString newUrl = url; return cef_frame;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
{
// Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED)
return false;
}
CefRefPtr<CefBrowserImpl> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(browser.get(),
&CefBrowserImpl::UIT_CreateBrowser, newUrl));
return true;
} }
// static void CefBrowserImpl::RemoveCefFrame(const CefString& name)
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, CefRefPtr<CefHandler> handler, const CefString& url)
{ {
// Verify that the context is in a valid state. AutoLock lock_scope(this);
if (!CONTEXT_STATE_VALID()) { if(name.empty()) {
NOTREACHED(); // Clear the single main frame reference.
main_frame_ = NULL;
} else {
// Remove the appropriate named reference.
FrameMap::iterator it = frames_.find(name);
if(it != frames_.end())
frames_.erase(it);
}
}
CefRefPtr<CefFrame> CefBrowserImpl::GetMainCefFrame()
{
// Return the single main frame reference.
AutoLock lock_scope(this);
if(main_frame_ == NULL)
main_frame_ = new CefFrameImpl(this, CefString());
return main_frame_;
}
CefRefPtr<CefFrame> CefBrowserImpl::UIT_GetCefFrame(WebFrame* frame)
{
REQUIRE_UIT();
CefRefPtr<CefFrame> cef_frame;
WebView *view = UIT_GetWebView();
if(view) {
if(frame == view->mainFrame()) {
// Use the single main frame reference.
cef_frame = GetMainCefFrame();
} else {
// Locate or create the appropriate named reference.
CefString name = string16(frame->name());
DCHECK(!name.empty());
cef_frame = GetCefFrame(name);
}
}
return cef_frame;
}
WebFrame* CefBrowserImpl::UIT_GetMainWebFrame()
{
REQUIRE_UIT();
WebView* view = UIT_GetWebView();
if (view)
return view ->mainFrame();
return NULL;
}
WebFrame* CefBrowserImpl::UIT_GetWebFrame(CefRefPtr<CefFrame> frame)
{
REQUIRE_UIT();
WebView* view = UIT_GetWebView();
if (!view)
return NULL; return NULL;
}
// Verify that this method is being called on the UI thread. CefString name = frame->GetName();
if (!CefThread::CurrentlyOn(CefThread::UI)) { if(name.empty())
NOTREACHED(); return view ->mainFrame();
return NULL; return view ->findFrameByName(string16(name));
}
CefString newUrl = url;
CefRefPtr<CefBrowser> alternateBrowser;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get())
{
// Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED)
return false;
}
CefRefPtr<CefBrowser> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
return browser;
} }
void CefBrowserImpl::UIT_DestroyBrowser() void CefBrowserImpl::UIT_DestroyBrowser()
@ -585,7 +531,7 @@ void CefBrowserImpl::UIT_DestroyBrowser()
// Notify the handler that the window is about to be closed. // Notify the handler that the window is about to be closed.
handler_->HandleBeforeWindowClose(this); handler_->HandleBeforeWindowClose(this);
} }
GetWebViewDelegate()->RevokeDragDrop(); UIT_GetWebViewDelegate()->RevokeDragDrop();
if (dev_tools_agent_.get()) { if (dev_tools_agent_.get()) {
BrowserDevToolsClient* client = dev_tools_agent_->client(); BrowserDevToolsClient* client = dev_tools_agent_->client();
@ -594,7 +540,7 @@ void CefBrowserImpl::UIT_DestroyBrowser()
} }
// Clean up anything associated with the WebViewHost widget. // Clean up anything associated with the WebViewHost widget.
GetWebViewHost()->webwidget()->close(); UIT_GetWebViewHost()->webwidget()->close();
webviewhost_.reset(); webviewhost_.reset();
// Remove the reference added in UIT_CreateBrowser(). // Remove the reference added in UIT_CreateBrowser().
@ -680,7 +626,7 @@ void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame,
return; return;
} }
WebFrame* web_frame = GetWebFrame(frame); WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame) if(web_frame)
web_frame->loadHTMLString(std::string(html), gurl); web_frame->loadHTMLString(std::string(html), gurl);
@ -717,7 +663,7 @@ void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
} }
while(read > 0); while(read > 0);
WebFrame* web_frame = GetWebFrame(frame); WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame) if(web_frame)
web_frame->loadHTMLString(ss.str(), gurl); web_frame->loadHTMLString(ss.str(), gurl);
@ -732,7 +678,7 @@ void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame,
{ {
REQUIRE_UIT(); REQUIRE_UIT();
WebFrame* web_frame = GetWebFrame(frame); WebFrame* web_frame = UIT_GetWebFrame(frame);
if(web_frame) { if(web_frame) {
web_frame->executeScript(WebScriptSource(string16(js_code), web_frame->executeScript(WebScriptSource(string16(js_code),
WebURL(GURL(std::string(script_url))), start_line)); WebURL(GURL(std::string(script_url))), start_line));
@ -759,7 +705,7 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
{ {
REQUIRE_UIT(); REQUIRE_UIT();
WebView* view = GetWebView(); WebView* view = UIT_GetWebView();
if (!view) if (!view)
return false; return false;
@ -830,7 +776,7 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
// thread for additional details: // thread for additional details:
// http://groups.google.com/group/chromium-dev/browse_thread/thread/42bcd31b59e3a168 // http://groups.google.com/group/chromium-dev/browse_thread/thread/42bcd31b59e3a168
view->setFocusedFrame(frame); view->setFocusedFrame(frame);
UIT_SetFocus(GetWebViewHost(), true); UIT_SetFocus(UIT_GetWebViewHost(), true);
} }
return true; return true;
@ -886,7 +832,7 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
WebFrame* web_frame = NULL; WebFrame* web_frame = NULL;
if(frame) if(frame)
web_frame = GetWebFrame(frame); web_frame = UIT_GetWebFrame(frame);
switch(menuId) switch(menuId)
{ {
@ -903,8 +849,8 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
UIT_Reload(true); UIT_Reload(true);
break; break;
case MENU_ID_NAV_STOP: case MENU_ID_NAV_STOP:
if (GetWebView()) if (UIT_GetWebView())
GetWebView()->mainFrame()->stopLoading(); UIT_GetWebView()->mainFrame()->stopLoading();
break; break;
case MENU_ID_UNDO: case MENU_ID_UNDO:
if(web_frame) if(web_frame)
@ -948,76 +894,10 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
frame->Release(); frame->Release();
} }
void CefBrowserImpl::UIT_GetDocumentStringNotify(CefFrame* frame,
CefStreamWriter* writer,
base::WaitableEvent* event)
{
REQUIRE_UIT();
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
std::string markup = web_frame->contentAsMarkup().utf8();
// Write the document string to the stream
writer->Write(markup.c_str(), markup.size(), 1);
}
// Notify the calling thread that the data is now available
event->Signal();
writer->Release();
frame->Release();
}
void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
CefStreamWriter* writer,
base::WaitableEvent* event)
{
REQUIRE_UIT();
WebKit::WebFrame* web_frame = GetWebFrame(frame);
if(web_frame) {
// Retrieve the document string
string16 wstr = webkit_glue::DumpDocumentText(web_frame);
std::string str;
UTF16ToUTF8(wstr.c_str(), wstr.length(), &str);
// Write the document string to the stream
writer->Write(str.c_str(), str.size(), 1);
}
// Notify the calling thread that the data is now available
event->Signal();
writer->Release();
frame->Release();
}
void CefBrowserImpl::UIT_CanGoBackNotify(bool *retVal,
base::WaitableEvent* event)
{
REQUIRE_UIT();
*retVal = UIT_CanGoBack();
// Notify the calling thread that the data is now available
event->Signal();
}
void CefBrowserImpl::UIT_CanGoForwardNotify(bool *retVal,
base::WaitableEvent* event)
{
REQUIRE_UIT();
*retVal = UIT_CanGoForward();
// Notify the calling thread that the data is now available
event->Signal();
}
void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text, void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text,
const WebKit::WebFindOptions& options) const WebKit::WebFindOptions& options)
{ {
WebView* view = GetWebView(); WebView* view = UIT_GetWebView();
if (!view) if (!view)
return; return;
@ -1140,7 +1020,7 @@ void CefBrowserImpl::UIT_Find(int identifier, const CefString& search_text,
void CefBrowserImpl::UIT_StopFinding(bool clear_selection) void CefBrowserImpl::UIT_StopFinding(bool clear_selection)
{ {
WebView* view = GetWebView(); WebView* view = UIT_GetWebView();
if (!view) if (!view)
return; return;
@ -1169,8 +1049,7 @@ void CefBrowserImpl::UIT_NotifyFindStatus(int identifier, int count,
int active_match_ordinal, int active_match_ordinal,
bool final_update) bool final_update)
{ {
if(handler_.get()) if(handler_.get()) {
{
CefRect rect(selection_rect.x, selection_rect.y, selection_rect.width, CefRect rect(selection_rect.x, selection_rect.y, selection_rect.width,
selection_rect.height); selection_rect.height);
handler_->HandleFindResult(this, identifier, count, rect, handler_->HandleFindResult(this, identifier, count, rect,
@ -1178,17 +1057,15 @@ void CefBrowserImpl::UIT_NotifyFindStatus(int identifier, int count,
} }
} }
void CefBrowserImpl::UIT_SetZoomLevel(CefFrame* frame, double zoomLevel) void CefBrowserImpl::UIT_SetZoomLevel(double zoomLevel)
{ {
REQUIRE_UIT(); REQUIRE_UIT();
WebKit::WebFrame* web_frame = GetWebFrame(frame); WebKit::WebFrame* web_frame = UIT_GetMainWebFrame();
if(web_frame) {
if(web_frame && web_frame->view()) {
web_frame->view()->setZoomLevel(false, zoomLevel); web_frame->view()->setZoomLevel(false, zoomLevel);
ZoomMap::GetInstance()->set(web_frame->url(), zoomLevel); ZoomMap::GetInstance()->set(web_frame->url(), zoomLevel);
set_zoom_level(zoomLevel);
} }
frame->Release();
} }
void CefBrowserImpl::UIT_ShowDevTools() void CefBrowserImpl::UIT_ShowDevTools()
@ -1209,7 +1086,7 @@ void CefBrowserImpl::UIT_ShowDevTools()
CefPopupFeatures features; CefPopupFeatures features;
CefRefPtr<CefBrowserImpl> browser = CefRefPtr<CefBrowserImpl> browser =
UIT_CreatePopupWindow(devtools_path.value(), features); UIT_CreatePopupWindow(devtools_path.value(), features);
browser->CreateDevToolsClient(dev_tools_agent_.get()); browser->UIT_CreateDevToolsClient(dev_tools_agent_.get());
browser->UIT_Show(WebKit::WebNavigationPolicyNewWindow); browser->UIT_Show(WebKit::WebNavigationPolicyNewWindow);
} else { } else {
// Give focus to the existing inspector window. // Give focus to the existing inspector window.
@ -1217,7 +1094,38 @@ void CefBrowserImpl::UIT_ShowDevTools()
} }
} }
void CefBrowserImpl::CreateDevToolsClient(BrowserDevToolsAgent *agent) void CefBrowserImpl::set_zoom_level(double zoomLevel)
{
AutoLock lock_scope(this);
zoom_level_ = zoomLevel;
}
double CefBrowserImpl::zoom_level()
{
AutoLock lock_scope(this);
return zoom_level_;
}
void CefBrowserImpl::set_nav_state(bool can_go_back, bool can_go_forward)
{
AutoLock lock_scope(this);
can_go_back_ = can_go_back;
can_go_forward_ = can_go_forward;
}
bool CefBrowserImpl::can_go_back()
{
AutoLock lock_scope(this);
return can_go_back_;
}
bool CefBrowserImpl::can_go_forward()
{
AutoLock lock_scope(this);
return can_go_forward_;
}
void CefBrowserImpl::UIT_CreateDevToolsClient(BrowserDevToolsAgent *agent)
{ {
dev_tools_client_.reset(new BrowserDevToolsClient(this, agent)); dev_tools_client_.reset(new BrowserDevToolsClient(this, agent));
} }
@ -1225,9 +1133,25 @@ void CefBrowserImpl::CreateDevToolsClient(BrowserDevToolsAgent *agent)
// CefFrameImpl // CefFrameImpl
CefFrameImpl::CefFrameImpl(CefBrowserImpl* browser, const CefString& name)
: browser_(browser), name_(name)
{
}
CefFrameImpl::~CefFrameImpl()
{
browser_->RemoveCefFrame(name_);
}
bool CefFrameImpl::IsFocused() bool CefFrameImpl::IsFocused()
{ {
return (browser_->GetWebView() && // Verify that this method is being called on the UI thread.
(browser_->GetWebFrame(this) == if (!CefThread::CurrentlyOn(CefThread::UI)) {
browser_->GetWebView()->focusedFrame())); NOTREACHED();
return false;
}
return (browser_->UIT_GetWebView() &&
(browser_->UIT_GetWebFrame(this) ==
browser_->UIT_GetWebView()->focusedFrame()));
} }

View File

@ -47,41 +47,29 @@ public:
#endif #endif
// CefBrowser methods // CefBrowser methods
virtual bool CanGoBack(); virtual bool CanGoBack() { return can_go_back(); }
virtual void GoBack(); virtual void GoBack();
virtual bool CanGoForward(); virtual bool CanGoForward() { return can_go_forward(); }
virtual void GoForward(); virtual void GoForward();
virtual void Reload(); virtual void Reload();
virtual void ReloadIgnoreCache(); virtual void ReloadIgnoreCache();
virtual void StopLoad(); virtual void StopLoad();
virtual void SetFocus(bool enable); virtual void SetFocus(bool enable);
virtual CefWindowHandle GetWindowHandle(); virtual CefWindowHandle GetWindowHandle();
virtual bool IsPopup(); virtual bool IsPopup() { return is_popup(); }
virtual CefRefPtr<CefHandler> GetHandler(); virtual CefRefPtr<CefHandler> GetHandler() { return handler_; }
virtual CefRefPtr<CefFrame> GetMainFrame(); virtual CefRefPtr<CefFrame> GetMainFrame() { return GetMainCefFrame(); }
virtual CefRefPtr<CefFrame> GetFocusedFrame(); virtual CefRefPtr<CefFrame> GetFocusedFrame();
virtual CefRefPtr<CefFrame> GetFrame(const CefString& name); virtual CefRefPtr<CefFrame> GetFrame(const CefString& name);
virtual void GetFrameNames(std::vector<CefString>& names); virtual void GetFrameNames(std::vector<CefString>& names);
virtual void Find(int identifier, const CefString& searchText, virtual void Find(int identifier, const CefString& searchText,
bool forward, bool matchCase, bool findNext); bool forward, bool matchCase, bool findNext);
virtual void StopFinding(bool clearSelection); virtual void StopFinding(bool clearSelection);
virtual double GetZoomLevel(); virtual double GetZoomLevel() { return zoom_level(); }
virtual void SetZoomLevel(double zoomLevel); virtual void SetZoomLevel(double zoomLevel);
virtual void ShowDevTools(); virtual void ShowDevTools();
virtual void CloseDevTools(); virtual void CloseDevTools();
// CefFrames are light-weight objects managed by the browser and loosely
// coupled to a WebFrame object by name. If a CefFrame object does not
// already exist for the specified WebFrame one will be created. There is no
// guarantee that the same CefFrame object will be returned across different
// calls to this function.
CefRefPtr<CefFrame> GetCefFrame(WebKit::WebFrame* frame);
void RemoveCefFrame(const CefString& name);
// Return the WebFrame object associated with the specified CefFrame. This
// may return NULL if no WebFrame with the CefFrame's name exists.
WebKit::WebFrame* GetWebFrame(CefRefPtr<CefFrame> frame);
// Frame-related methods // Frame-related methods
void Undo(CefRefPtr<CefFrame> frame); void Undo(CefRefPtr<CefFrame> frame);
void Redo(CefRefPtr<CefFrame> frame); void Redo(CefRefPtr<CefFrame> frame);
@ -110,36 +98,62 @@ public:
int startLine); int startLine);
CefString GetURL(CefRefPtr<CefFrame> frame); CefString GetURL(CefRefPtr<CefFrame> frame);
WebKit::WebView* GetWebView() const { // CefFrames are light-weight objects managed by the browser and loosely
return webviewhost_.get() ? webviewhost_->webview() : NULL; // coupled to a WebFrame object by name. If a CefFrame object does not
} // already exist for the specified name one will be created. There is no
WebViewHost* GetWebViewHost() const { // guarantee that the same CefFrame object will be returned across different
return webviewhost_.get(); // calls to this function.
} CefRefPtr<CefFrame> GetCefFrame(const CefString& name);
BrowserWebViewDelegate* GetWebViewDelegate() const { void RemoveCefFrame(const CefString& name);
return delegate_.get(); CefRefPtr<CefFrame> GetMainCefFrame();
}
gfx::NativeView GetWebViewWndHandle() const {
return webviewhost_->view_handle();
}
WebKit::WebWidget* GetPopup() const {
return popuphost_ ? popuphost_->webwidget() : NULL;
}
WebWidgetHost* GetPopupHost() const {
return popuphost_;
}
BrowserWebViewDelegate* GetPopupDelegate() const {
return popup_delegate_.get();
}
gfx::NativeView GetPopupWndHandle() const {
return popuphost_->view_handle();
}
gfx::NativeWindow GetMainWndHandle() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// ALL UIT_* METHODS MUST ONLY BE CALLED ON THE UI THREAD // // ALL UIT_* METHODS MUST ONLY BE CALLED ON THE UI THREAD //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CefRefPtr<CefFrame> UIT_GetCefFrame(WebKit::WebFrame* frame);
// Return the main WebFrame object.
WebKit::WebFrame* UIT_GetMainWebFrame();
// Return the WebFrame object associated with the specified CefFrame. This
// may return NULL if no WebFrame with the CefFrame's name exists.
WebKit::WebFrame* UIT_GetWebFrame(CefRefPtr<CefFrame> frame);
WebKit::WebView* UIT_GetWebView() const {
REQUIRE_UIT();
return webviewhost_.get() ? webviewhost_->webview() : NULL;
}
WebViewHost* UIT_GetWebViewHost() const {
REQUIRE_UIT();
return webviewhost_.get();
}
BrowserWebViewDelegate* UIT_GetWebViewDelegate() const {
REQUIRE_UIT();
return delegate_.get();
}
gfx::NativeView UIT_GetWebViewWndHandle() const {
REQUIRE_UIT();
return webviewhost_->view_handle();
}
WebKit::WebWidget* UIT_GetPopup() const {
REQUIRE_UIT();
return popuphost_ ? popuphost_->webwidget() : NULL;
}
WebWidgetHost* UIT_GetPopupHost() const {
REQUIRE_UIT();
return popuphost_;
}
BrowserWebViewDelegate* UIT_GetPopupDelegate() const {
REQUIRE_UIT();
return popup_delegate_.get();
}
gfx::NativeView UIT_GetPopupWndHandle() const {
REQUIRE_UIT();
return popuphost_->view_handle();
}
gfx::NativeWindow UIT_GetMainWndHandle() const;
BrowserNavigationController* UIT_GetNavigationController() { BrowserNavigationController* UIT_GetNavigationController() {
REQUIRE_UIT(); REQUIRE_UIT();
return nav_controller_.get(); return nav_controller_.get();
@ -157,14 +171,14 @@ public:
is_modal_ = val; is_modal_ = val;
} }
void UIT_SetTitle(const CefString& title) {
REQUIRE_UIT();
title_ = title;
}
CefString UIT_GetTitle() { CefString UIT_GetTitle() {
REQUIRE_UIT(); REQUIRE_UIT();
return title_; return title_;
} }
void UIT_SetTitle(const CefString& title) {
REQUIRE_UIT();
title_ = title;
}
void UIT_CreateBrowser(const CefString& url); void UIT_CreateBrowser(const CefString& url);
void UIT_DestroyBrowser(); void UIT_DestroyBrowser();
@ -209,13 +223,6 @@ public:
// Save the document HTML to a temporary file and open in the default viewing // Save the document HTML to a temporary file and open in the default viewing
// application // application
bool UIT_ViewDocumentString(WebKit::WebFrame *frame); bool UIT_ViewDocumentString(WebKit::WebFrame *frame);
void UIT_GetDocumentStringNotify(CefFrame* frame,
CefStreamWriter* writer,
base::WaitableEvent* event);
void UIT_GetDocumentTextNotify(CefFrame* frame, CefStreamWriter* writer,
base::WaitableEvent* event);
void UIT_CanGoBackNotify(bool *retVal, base::WaitableEvent* event);
void UIT_CanGoForwardNotify(bool *retVal, base::WaitableEvent* event);
bool UIT_CanGoBack() { return !nav_controller_->IsAtStart(); } bool UIT_CanGoBack() { return !nav_controller_->IsAtStart(); }
bool UIT_CanGoForward() { return !nav_controller_->IsAtEnd(); } bool UIT_CanGoForward() { return !nav_controller_->IsAtEnd(); }
@ -235,17 +242,26 @@ public:
void UIT_NotifyFindStatus(int identifier, int count, void UIT_NotifyFindStatus(int identifier, int count,
const WebKit::WebRect& selection_rect, const WebKit::WebRect& selection_rect,
int active_match_ordinal, bool final_update); int active_match_ordinal, bool final_update);
void UIT_SetZoomLevel(CefFrame* frame, double zoomLevel); void UIT_SetZoomLevel(double zoomLevel);
void UIT_ShowDevTools(); void UIT_ShowDevTools();
void UIT_CloseDevTools(); void UIT_CloseDevTools();
static bool ImplementsThreadSafeReferenceCounting() { return true; } // These variables are read-only.
const CefBrowserSettings& settings() const { return settings_; } const CefBrowserSettings& settings() const { return settings_; }
const FilePath& file_system_root() const { return file_system_root_.path(); } const FilePath& file_system_root() const { return file_system_root_.path(); }
bool is_popup() { return is_popup_; }
// These variables may be read/written from multiple threads.
void set_zoom_level(double zoomLevel);
double zoom_level();
void set_nav_state(bool can_go_back, bool can_go_forward);
bool can_go_back();
bool can_go_forward();
static bool ImplementsThreadSafeReferenceCounting() { return true; }
protected: protected:
void CreateDevToolsClient(BrowserDevToolsAgent* agent); void UIT_CreateDevToolsClient(BrowserDevToolsAgent* agent);
protected: protected:
CefWindowInfo window_info_; CefWindowInfo window_info_;
@ -264,6 +280,10 @@ protected:
CefString title_; CefString title_;
double zoom_level_;
bool can_go_back_;
bool can_go_forward_;
#if defined(OS_WIN) #if defined(OS_WIN)
// Context object used to manage printing. // Context object used to manage printing.
printing::PrintingContext print_context_; printing::PrintingContext print_context_;
@ -271,7 +291,7 @@ protected:
typedef std::map<CefString, CefFrame*> FrameMap; typedef std::map<CefString, CefFrame*> FrameMap;
FrameMap frames_; FrameMap frames_;
CefFrame* frame_main_; CefFrame* main_frame_;
// Unique browser ID assigned by the context. // Unique browser ID assigned by the context.
int unique_id_; int unique_id_;
@ -285,9 +305,8 @@ protected:
class CefFrameImpl : public CefThreadSafeBase<CefFrame> class CefFrameImpl : public CefThreadSafeBase<CefFrame>
{ {
public: public:
CefFrameImpl(CefBrowserImpl* browser, const CefString& name) CefFrameImpl(CefBrowserImpl* browser, const CefString& name);
: browser_(browser), name_(name) {} virtual ~CefFrameImpl();
virtual ~CefFrameImpl() { browser_->RemoveCefFrame(name_); }
// CefFrame methods // CefFrame methods
virtual void Undo() { browser_->Undo(this); } virtual void Undo() { browser_->Undo(this); }

View File

@ -20,13 +20,12 @@ using WebKit::WebSize;
CefWindowHandle CefBrowserImpl::GetWindowHandle() CefWindowHandle CefBrowserImpl::GetWindowHandle()
{ {
Lock(); AutoLock lock_scope(this);
CefWindowHandle handle = window_info_.m_Widget; return window_info_.m_Widget;
Unlock();
return handle;
} }
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const { gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT();
GtkWidget* toplevel = gtk_widget_get_ancestor(window_info_.m_Widget, GtkWidget* toplevel = gtk_widget_get_ancestor(window_info_.m_Widget,
GTK_TYPE_WINDOW); GTK_TYPE_WINDOW);
return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL;
@ -35,7 +34,8 @@ gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const {
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{ {
REQUIRE_UIT(); REQUIRE_UIT();
Lock();
// Add a reference that will be released in UIT_DestroyBrowser(). // Add a reference that will be released in UIT_DestroyBrowser().
AddRef(); AddRef();
@ -58,7 +58,9 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
dev_tools_agent_->SetWebView(webviewhost_->webview()); dev_tools_agent_->SetWebView(webviewhost_->webview());
window_info_.m_Widget = webviewhost_->view_handle(); window_info_.m_Widget = webviewhost_->view_handle();
Unlock();
if(handler_.get()) { if(handler_.get()) {
// Notify the handler that we're done creating the new window // Notify the handler that we're done creating the new window
handler_->HandleAfterCreated(this); handler_->HandleAfterCreated(this);

View File

@ -21,20 +21,20 @@ using WebKit::WebSize;
CefWindowHandle CefBrowserImpl::GetWindowHandle() CefWindowHandle CefBrowserImpl::GetWindowHandle()
{ {
Lock(); AutoLock lock_scope(this);
CefWindowHandle handle = window_info_.m_View; return window_info_.m_View;
Unlock();
return handle;
} }
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const { gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT();
return (NSWindow*)window_info_.m_View; return (NSWindow*)window_info_.m_View;
} }
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{ {
REQUIRE_UIT(); REQUIRE_UIT();
Lock();
// Add a reference that will be released in UIT_DestroyBrowser(). // Add a reference that will be released in UIT_DestroyBrowser().
AddRef(); AddRef();
@ -63,7 +63,9 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle(); BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
browserView.browser = this; browserView.browser = this;
window_info_.m_View = (void*)browserView; window_info_.m_View = (void*)browserView;
Unlock();
if(handler_.get()) { if(handler_.get()) {
// Notify the handler that we're done creating the new window // Notify the handler that we're done creating the new window
handler_->HandleAfterCreated(this); handler_->HandleAfterCreated(this);

View File

@ -57,23 +57,23 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
return 0; return 0;
case WM_SIZE: case WM_SIZE:
if (browser && browser->GetWebView()) { if (browser && browser->UIT_GetWebView()) {
// resize the web view window to the full size of the browser window // resize the web view window to the full size of the browser window
RECT rc; RECT rc;
GetClientRect(browser->GetMainWndHandle(), &rc); GetClientRect(browser->UIT_GetMainWndHandle(), &rc);
MoveWindow(browser->GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom, MoveWindow(browser->UIT_GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
TRUE); TRUE);
} }
return 0; return 0;
case WM_SETFOCUS: case WM_SETFOCUS:
if (browser && browser->GetWebView()) if (browser && browser->UIT_GetWebView())
browser->GetWebView()->setFocus(true); browser->UIT_GetWebView()->setFocus(true);
return 0; return 0;
case WM_KILLFOCUS: case WM_KILLFOCUS:
if (browser && browser->GetWebView()) if (browser && browser->UIT_GetWebView())
browser->GetWebView()->setFocus(false); browser->UIT_GetWebView()->setFocus(false);
return 0; return 0;
case WM_ERASEBKGND: case WM_ERASEBKGND:
@ -85,19 +85,19 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
CefWindowHandle CefBrowserImpl::GetWindowHandle() CefWindowHandle CefBrowserImpl::GetWindowHandle()
{ {
Lock(); AutoLock lock_scope(this);
CefWindowHandle handle = window_info_.m_hWnd; return window_info_.m_hWnd;
Unlock();
return handle;
} }
gfx::NativeWindow CefBrowserImpl::GetMainWndHandle() const { gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT();
return window_info_.m_hWnd; return window_info_.m_hWnd;
} }
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
{ {
REQUIRE_UIT(); REQUIRE_UIT();
Lock();
std::wstring windowName(CefString(&window_info_.m_windowName)); std::wstring windowName(CefString(&window_info_.m_windowName));
@ -136,10 +136,12 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
if (!settings_.drag_drop_disabled) if (!settings_.drag_drop_disabled)
delegate_->RegisterDragDrop(); delegate_->RegisterDragDrop();
Unlock();
// Size the web view window to the browser window // Size the web view window to the browser window
RECT cr; RECT cr;
GetClientRect(window_info_.m_hWnd, &cr); GetClientRect(window_info_.m_hWnd, &cr);
SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right, SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
if(handler_.get()) { if(handler_.get()) {
@ -172,7 +174,7 @@ WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget()
DCHECK(!popuphost_); DCHECK(!popuphost_);
popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get()); popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get());
ShowWindow(GetPopupWndHandle(), SW_SHOW); ShowWindow(UIT_GetPopupWndHandle(), SW_SHOW);
return popuphost_->webwidget(); return popuphost_->webwidget();
} }
@ -181,7 +183,7 @@ void CefBrowserImpl::UIT_ClosePopupWidget()
{ {
REQUIRE_UIT(); REQUIRE_UIT();
PostMessage(GetPopupWndHandle(), WM_CLOSE, 0, 0); PostMessage(UIT_GetPopupWndHandle(), WM_CLOSE, 0, 0);
popuphost_ = NULL; popuphost_ = NULL;
} }
@ -225,7 +227,7 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame)
std::string markup = frame->contentAsMarkup().utf8(); std::string markup = frame->contentAsMarkup().utf8();
WriteTextToFile(markup, szTempName); WriteTextToFile(markup, szTempName);
int errorCode = (int)ShellExecute(GetMainWndHandle(), L"open", szTempName, int errorCode = (int)ShellExecute(UIT_GetMainWndHandle(), L"open", szTempName,
NULL, NULL, SW_SHOWNORMAL); NULL, NULL, SW_SHOWNORMAL);
if(errorCode <= 32) if(errorCode <= 32)
return false; return false;
@ -322,7 +324,7 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
// allow the handler to format print header and/or footer // allow the handler to format print header and/or footer
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this, CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages, UIT_GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight); topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight);
if(rv != RV_HANDLED) { if(rv != RV_HANDLED) {
@ -408,7 +410,7 @@ void CefBrowserImpl::UIT_PrintPages(WebKit::WebFrame* frame) {
} }
if(print_context_.AskUserForSettings( if(print_context_.AskUserForSettings(
GetMainWndHandle(), UIT_GetPagesCount(frame), false) UIT_GetMainWndHandle(), UIT_GetPagesCount(frame), false)
!= printing::PrintingContext::OK) != printing::PrintingContext::OK)
return; return;
@ -497,5 +499,5 @@ void CefBrowserImpl::UIT_CloseDevTools()
BrowserDevToolsClient* client = dev_tools_agent_->client(); BrowserDevToolsClient* client = dev_tools_agent_->client();
if (client) if (client)
PostMessage(client->browser()->GetMainWndHandle(), WM_CLOSE, 0, 0); PostMessage(client->browser()->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0);
} }

View File

@ -172,7 +172,7 @@ WebView* BrowserWebViewDelegate::createView(WebFrame* creator,
TranslatePopupFeatures(features, cefFeatures); TranslatePopupFeatures(features, cefFeatures);
CefRefPtr<CefBrowserImpl> browser = CefRefPtr<CefBrowserImpl> browser =
browser_->UIT_CreatePopupWindow(url, cefFeatures); browser_->UIT_CreatePopupWindow(url, cefFeatures);
return browser.get() ? browser->GetWebView() : NULL; return browser.get() ? browser->UIT_GetWebView() : NULL;
} }
WebWidget* BrowserWebViewDelegate::createPopupMenu(WebPopupType popup_type) { WebWidget* BrowserWebViewDelegate::createPopupMenu(WebPopupType popup_type) {
@ -215,8 +215,11 @@ void BrowserWebViewDelegate::didAddMessageToConsole(
} }
void BrowserWebViewDelegate::printPage(WebFrame* frame) { void BrowserWebViewDelegate::printPage(WebFrame* frame) {
if (!frame) if (!frame) {
frame = browser_->GetWebView() ? browser_->GetWebView()->mainFrame() : NULL; WebView* view = browser_->UIT_GetWebView();
if (view)
frame = view->mainFrame();
}
if (frame) if (frame)
browser_->UIT_PrintPages(frame); browser_->UIT_PrintPages(frame);
} }
@ -299,8 +302,10 @@ bool BrowserWebViewDelegate::handleCurrentKeyboardEvent() {
if (edit_command_name_.empty()) if (edit_command_name_.empty())
return false; return false;
WebFrame* frame = browser_->GetWebView() ? WebView* view = browser_->UIT_GetWebView();
browser_->GetWebView()->focusedFrame() : NULL; WebFrame* frame = NULL;
if (view)
frame = view->focusedFrame();
if (!frame) if (!frame)
return false; return false;
@ -335,7 +340,7 @@ void BrowserWebViewDelegate::runModalAlertDialog(
CefString messageStr = string16(message); CefString messageStr = string16(message);
CefRefPtr<CefHandler> handler = browser_->GetHandler(); CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) { if(handler.get()) {
rv = handler->HandleJSAlert(browser_, browser_->GetCefFrame(frame), rv = handler->HandleJSAlert(browser_, browser_->UIT_GetCefFrame(frame),
messageStr); messageStr);
} }
if(rv != RV_HANDLED) if(rv != RV_HANDLED)
@ -349,7 +354,7 @@ bool BrowserWebViewDelegate::runModalConfirmDialog(
bool retval = false; bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler(); CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) { if(handler.get()) {
rv = handler->HandleJSConfirm(browser_, browser_->GetCefFrame(frame), rv = handler->HandleJSConfirm(browser_, browser_->UIT_GetCefFrame(frame),
messageStr, retval); messageStr, retval);
} }
if(rv != RV_HANDLED) if(rv != RV_HANDLED)
@ -370,7 +375,7 @@ bool BrowserWebViewDelegate::runModalPromptDialog(
bool retval = false; bool retval = false;
CefRefPtr<CefHandler> handler = browser_->GetHandler(); CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) { if(handler.get()) {
rv = handler->HandleJSPrompt(browser_, browser_->GetCefFrame(frame), rv = handler->HandleJSPrompt(browser_, browser_->UIT_GetCefFrame(frame),
messageStr, defaultValueStr, retval, actualValueStr); messageStr, defaultValueStr, retval, actualValueStr);
} }
if(rv != RV_HANDLED) { if(rv != RV_HANDLED) {
@ -426,8 +431,9 @@ void BrowserWebViewDelegate::startDragging(
//HRESULT res = DoDragDrop(drop_data.data_object, drag_delegate_.get(), //HRESULT res = DoDragDrop(drop_data.data_object, drag_delegate_.get(),
// ok_effect, &effect); // ok_effect, &effect);
//DCHECK(DRAGDROP_S_DROP == res || DRAGDROP_S_CANCEL == res); //DCHECK(DRAGDROP_S_DROP == res || DRAGDROP_S_CANCEL == res);
if (browser_->GetWebView()) WebView* view = browser_->UIT_GetWebView();
browser_->GetWebView()->dragSourceSystemDragEnded(); if (view)
view->dragSourceSystemDragEnded();
} }
void BrowserWebViewDelegate::focusNext() { void BrowserWebViewDelegate::focusNext() {
@ -591,7 +597,7 @@ WebNavigationPolicy BrowserWebViewDelegate::decidePolicyForNavigation(
// Notify the handler of a browse request // Notify the handler of a browse request
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_, CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_,
browser_->GetCefFrame(frame), req, (CefHandler::NavType)type, browser_->UIT_GetCefFrame(frame), req, (CefHandler::NavType)type,
is_redirect); is_redirect);
if(rv == RV_HANDLED) if(rv == RV_HANDLED)
return WebKit::WebNavigationPolicyIgnore; return WebKit::WebNavigationPolicyIgnore;
@ -673,7 +679,7 @@ void BrowserWebViewDelegate::didFailProvisionalLoad(
if(handler.get()) { if(handler.get()) {
// give the handler an opportunity to generate a custom error message // give the handler an opportunity to generate a custom error message
rv = handler->HandleLoadError(browser_, rv = handler->HandleLoadError(browser_,
browser_->GetCefFrame(frame), browser_->UIT_GetCefFrame(frame),
static_cast<CefHandler::ErrorCode>(error.reason), static_cast<CefHandler::ErrorCode>(error.reason),
std::string(failed_ds->request().url().spec().data()), errorStr); std::string(failed_ds->request().url().spec().data()), errorStr);
} }
@ -724,18 +730,17 @@ void BrowserWebViewDelegate::didCommitProvisionalLoad(
if(handler.get()) { if(handler.get()) {
// Notify the handler that loading has started. // Notify the handler that loading has started.
handler->HandleLoadStart(browser_, handler->HandleLoadStart(browser_,
(frame == top_loading_frame_) ? NULL : browser_->GetCefFrame(frame), (frame == top_loading_frame_) ? NULL : browser_->UIT_GetCefFrame(frame),
is_main_content_); is_main_content_);
} }
// Apply zoom settings only on top-level frames. // Apply zoom settings only on top-level frames.
if(frame->parent() == NULL) { if(frame->parent() == NULL) {
// Restore the zoom value that we have for this URL, if any. // Restore the zoom value that we have for this URL, if any.
double zoomLevel; double zoomLevel = 0.0;
if(ZoomMap::GetInstance()->get(frame->url(), zoomLevel)) ZoomMap::GetInstance()->get(frame->url(), zoomLevel);
frame->view()->setZoomLevel(false, zoomLevel); frame->view()->setZoomLevel(false, zoomLevel);
else browser_->set_zoom_level(zoomLevel);
frame->view()->setZoomLevel(false, 0.0);
} }
} }
@ -749,7 +754,7 @@ void BrowserWebViewDelegate::didClearWindowObject(WebFrame* frame) {
v8::Context::Scope scope(context); v8::Context::Scope scope(context);
CefRefPtr<CefFrame> cframe(browser_->GetCefFrame(frame)); CefRefPtr<CefFrame> cframe(browser_->UIT_GetCefFrame(frame));
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(context->Global()); CefRefPtr<CefV8Value> object = new CefV8ValueImpl(context->Global());
handler->HandleJSBinding(browser_, cframe, object); handler->HandleJSBinding(browser_, cframe, object);
} }
@ -869,15 +874,15 @@ void BrowserWebViewDelegate::RegisterDragDrop() {
#if defined(OS_WIN) #if defined(OS_WIN)
// TODO(port): add me once drag and drop works. // TODO(port): add me once drag and drop works.
DCHECK(!drop_delegate_); DCHECK(!drop_delegate_);
drop_delegate_ = new BrowserDropDelegate(browser_->GetWebViewWndHandle(), drop_delegate_ = new BrowserDropDelegate(browser_->UIT_GetWebViewWndHandle(),
browser_->GetWebView()); browser_->UIT_GetWebView());
#endif #endif
} }
void BrowserWebViewDelegate::RevokeDragDrop() { void BrowserWebViewDelegate::RevokeDragDrop() {
#if defined(OS_WIN) #if defined(OS_WIN)
if (drop_delegate_.get()) if (drop_delegate_.get())
::RevokeDragDrop(browser_->GetWebViewWndHandle()); ::RevokeDragDrop(browser_->UIT_GetWebViewWndHandle());
#endif #endif
} }
@ -926,8 +931,8 @@ void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
// Notify the handler that loading has ended. // Notify the handler that loading has ended.
int httpStatusCode = frame->dataSource()->response().httpStatusCode(); int httpStatusCode = frame->dataSource()->response().httpStatusCode();
handler->HandleLoadEnd(browser_, handler->HandleLoadEnd(browser_,
(is_top_frame) ? NULL : browser_->GetCefFrame(frame), is_main_content_, (is_top_frame) ? NULL : browser_->UIT_GetCefFrame(frame),
httpStatusCode); is_main_content_, httpStatusCode);
} }
if (is_top_frame && is_main_content_) if (is_top_frame && is_main_content_)
@ -935,10 +940,10 @@ void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
} }
WebWidgetHost* BrowserWebViewDelegate::GetWidgetHost() { WebWidgetHost* BrowserWebViewDelegate::GetWidgetHost() {
if (this == browser_->GetWebViewDelegate()) if (this == browser_->UIT_GetWebViewDelegate())
return browser_->GetWebViewHost(); return browser_->UIT_GetWebViewHost();
if (this == browser_->GetPopupDelegate()) if (this == browser_->UIT_GetPopupDelegate())
return browser_->GetPopupHost(); return browser_->UIT_GetPopupHost();
return NULL; return NULL;
} }
@ -989,7 +994,8 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
if(handler.get()) { if(handler.get()) {
// Notify the handler of an address change // Notify the handler of an address change
std::string url = std::string(entry->GetURL().spec().c_str()); std::string url = std::string(entry->GetURL().spec().c_str());
handler->HandleAddressChange(browser_, browser_->GetCefFrame(frame), url); handler->HandleAddressChange(browser_, browser_->UIT_GetCefFrame(frame),
url);
} }
} }
@ -997,7 +1003,10 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
if (!history_item.isNull()) if (!history_item.isNull())
entry->SetContentState(webkit_glue::HistoryItemToString(history_item)); entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
browser_->UIT_GetNavigationController()->DidNavigateToEntry(entry.release()); BrowserNavigationController* controller =
browser_->UIT_GetNavigationController();
controller->DidNavigateToEntry(entry.release());
browser_->set_nav_state(!controller->IsAtStart(), !controller->IsAtEnd());
last_page_id_updated_ = std::max(last_page_id_updated_, page_id_); last_page_id_updated_ = std::max(last_page_id_updated_, page_id_);
} }
@ -1014,11 +1023,11 @@ void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
if (!entry) if (!entry)
return; return;
if (!browser_->GetWebView()) WebView* view = browser_->UIT_GetWebView();
if (!view)
return; return;
const WebHistoryItem& history_item = const WebHistoryItem& history_item = view->mainFrame()->previousHistoryItem();
browser_->GetWebView()->mainFrame()->previousHistoryItem();
if (history_item.isNull()) if (history_item.isNull())
return; return;

View File

@ -102,10 +102,10 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
} }
void BrowserWebViewDelegate::closeWidgetSoon() { void BrowserWebViewDelegate::closeWidgetSoon() {
if (this == browser_->GetWebViewDelegate()) { if (this == browser_->UIT_GetWebViewDelegate()) {
MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction( MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction(
&gtk_widget_destroy, GTK_WIDGET(browser_->GetMainWndHandle()))); &gtk_widget_destroy, GTK_WIDGET(browser_->UIT_GetMainWndHandle())));
} else if (this == browser_->GetPopupDelegate()) { } else if (this == browser_->UIT_GetPopupDelegate()) {
browser_->UIT_ClosePopupWidget(); browser_->UIT_ClosePopupWidget();
} }
} }
@ -132,7 +132,7 @@ void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
gdk_cursor = gfx::GetCursor(cursor_type); gdk_cursor = gfx::GetCursor(cursor_type);
} }
cursor_type_ = cursor_type; cursor_type_ = cursor_type;
gdk_window_set_cursor(browser_->GetWebViewWndHandle()->window, gdk_cursor); gdk_window_set_cursor(browser_->UIT_GetWebViewWndHandle()->window, gdk_cursor);
} }
WebRect BrowserWebViewDelegate::windowRect() { WebRect BrowserWebViewDelegate::windowRect() {
@ -152,9 +152,9 @@ WebRect BrowserWebViewDelegate::windowRect() {
} }
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) { void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
if (this == browser_->GetWebViewDelegate()) { if (this == browser_->UIT_GetWebViewDelegate()) {
// TODO(port): Set the window rectangle. // TODO(port): Set the window rectangle.
} else if (this == browser_->GetPopupDelegate()) { } else if (this == browser_->UIT_GetPopupDelegate()) {
WebWidgetHost* host = GetWidgetHost(); WebWidgetHost* host = GetWidgetHost();
GtkWidget* drawing_area = host->view_handle(); GtkWidget* drawing_area = host->view_handle();
GtkWidget* window = GtkWidget* window =
@ -198,7 +198,7 @@ webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
// TODO(evanm): we probably shouldn't be doing this mapping to X ids at // TODO(evanm): we probably shouldn't be doing this mapping to X ids at
// this level. // this level.
GdkNativeWindow plugin_parent = GdkNativeWindow plugin_parent =
GDK_WINDOW_XWINDOW(browser_->GetWebViewHost()->view_handle()->window); GDK_WINDOW_XWINDOW(browser_->UIT_GetWebViewHost()->view_handle()->window);
return webkit::npapi::WebPluginDelegateImpl::Create(path, mime_type, return webkit::npapi::WebPluginDelegateImpl::Create(path, mime_type,
plugin_parent); plugin_parent);
@ -206,12 +206,12 @@ webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
void BrowserWebViewDelegate::CreatedPluginWindow( void BrowserWebViewDelegate::CreatedPluginWindow(
gfx::PluginWindowHandle id) { gfx::PluginWindowHandle id) {
browser_->GetWebViewHost()->CreatePluginContainer(id); browser_->UIT_GetWebViewHost()->CreatePluginContainer(id);
} }
void BrowserWebViewDelegate::WillDestroyPluginWindow( void BrowserWebViewDelegate::WillDestroyPluginWindow(
gfx::PluginWindowHandle id) { gfx::PluginWindowHandle id) {
browser_->GetWebViewHost()->DestroyPluginContainer(id); browser_->UIT_GetWebViewHost()->DestroyPluginContainer(id);
} }
void BrowserWebViewDelegate::DidMovePlugin( void BrowserWebViewDelegate::DidMovePlugin(

View File

@ -42,7 +42,7 @@ void BrowserWebViewDelegate::showContextMenu(
void BrowserWebViewDelegate::show(WebNavigationPolicy policy) { void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
if (!popup_menu_info_.get()) if (!popup_menu_info_.get())
return; return;
if (this != browser_->GetPopupDelegate()) if (this != browser_->UIT_GetPopupDelegate())
return; return;
// Display a HTML select menu. // Display a HTML select menu.
@ -59,7 +59,7 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
const WebRect& bounds = popup_bounds_; const WebRect& bounds = popup_bounds_;
// Set up the menu position. // Set up the menu position.
NSView* web_view = browser_->GetWebViewWndHandle(); NSView* web_view = browser_->UIT_GetWebViewWndHandle();
NSRect view_rect = [web_view bounds]; NSRect view_rect = [web_view bounds];
int y_offset = bounds.y + bounds.height; int y_offset = bounds.y + bounds.height;
NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset, NSRect position = NSMakeRect(bounds.x, view_rect.size.height - y_offset,
@ -71,15 +71,15 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
fontSize:font_size fontSize:font_size
rightAligned:right_aligned]); rightAligned:right_aligned]);
[menu_runner runMenuInView:browser_->GetWebViewWndHandle() [menu_runner runMenuInView:browser_->UIT_GetWebViewWndHandle()
withBounds:position withBounds:position
initialIndex:selected_index]; initialIndex:selected_index];
// Get the selected item and forward to WebKit. WebKit expects an input event // Get the selected item and forward to WebKit. WebKit expects an input event
// (mouse down, keyboard activity) for this, so we calculate the proper // (mouse down, keyboard activity) for this, so we calculate the proper
// position based on the selected index and provided bounds. // position based on the selected index and provided bounds.
WebWidgetHost* popup = browser_->GetPopupHost(); WebWidgetHost* popup = browser_->UIT_GetPopupHost();
int window_num = [browser_->GetMainWndHandle() windowNumber]; int window_num = [browser_->UIT_GetMainWndHandle() windowNumber];
NSEvent* event = NSEvent* event =
webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen], webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen],
window_num, item_height, window_num, item_height,
@ -98,10 +98,10 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
} }
void BrowserWebViewDelegate::closeWidgetSoon() { void BrowserWebViewDelegate::closeWidgetSoon() {
if (this == browser_->GetWebViewDelegate()) { if (this == browser_->UIT_GetWebViewDelegate()) {
NSWindow *win = browser_->GetMainWndHandle(); NSWindow *win = browser_->UIT_GetMainWndHandle();
[win performSelector:@selector(performClose:) withObject:nil afterDelay:0]; [win performSelector:@selector(performClose:) withObject:nil afterDelay:0];
} else if (this == browser_->GetPopupDelegate()) { } else if (this == browser_->UIT_GetPopupDelegate()) {
browser_->UIT_ClosePopupWidget(); browser_->UIT_ClosePopupWidget();
} }
} }
@ -121,9 +121,9 @@ WebRect BrowserWebViewDelegate::windowRect() {
} }
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) { void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
if (this == browser_->GetWebViewDelegate()) { if (this == browser_->UIT_GetWebViewDelegate()) {
// TODO(port): Set the window rectangle. // TODO(port): Set the window rectangle.
} else if (this == browser_->GetPopupDelegate()) { } else if (this == browser_->UIT_GetPopupDelegate()) {
popup_bounds_ = rect; // The initial position of the popup. popup_bounds_ = rect; // The initial position of the popup.
} }
} }

View File

@ -64,9 +64,9 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy) {
} }
void BrowserWebViewDelegate::closeWidgetSoon() { void BrowserWebViewDelegate::closeWidgetSoon() {
if (this == browser_->GetWebViewDelegate()) { if (this == browser_->UIT_GetWebViewDelegate()) {
PostMessage(browser_->GetMainWndHandle(), WM_CLOSE, 0, 0); PostMessage(browser_->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0);
} else if (this == browser_->GetPopupDelegate()) { } else if (this == browser_->UIT_GetPopupDelegate()) {
browser_->UIT_ClosePopupWidget(); browser_->UIT_ClosePopupWidget();
} }
} }
@ -91,10 +91,10 @@ WebRect BrowserWebViewDelegate::windowRect() {
} }
void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) { void BrowserWebViewDelegate::setWindowRect(const WebRect& rect) {
if (this == browser_->GetWebViewDelegate()) { if (this == browser_->UIT_GetWebViewDelegate()) {
// ignored // ignored
} else if (this == browser_->GetPopupDelegate()) { } else if (this == browser_->UIT_GetPopupDelegate()) {
MoveWindow(browser_->GetPopupWndHandle(), MoveWindow(browser_->UIT_GetPopupWndHandle(),
rect.x, rect.y, rect.width, rect.height, FALSE); rect.x, rect.y, rect.width, rect.height, FALSE);
} }
} }
@ -129,7 +129,7 @@ void BrowserWebViewDelegate::runModal() {
i = list->begin(); i = list->begin();
for (; i != list->end(); ++i) { for (; i != list->end(); ++i) {
if (i->get()->IsPopup()) if (i->get()->IsPopup())
EnableWindow(i->get()->GetMainWndHandle(), FALSE); EnableWindow(i->get()->UIT_GetMainWndHandle(), FALSE);
} }
_Context->Unlock(); _Context->Unlock();
@ -140,7 +140,7 @@ void BrowserWebViewDelegate::runModal() {
list = _Context->GetBrowserList(); list = _Context->GetBrowserList();
i = list->begin(); i = list->begin();
for (; i != list->end(); ++i) for (; i != list->end(); ++i)
EnableWindow(i->get()->GetMainWndHandle(), TRUE); EnableWindow(i->get()->UIT_GetMainWndHandle(), TRUE);
_Context->Unlock(); _Context->Unlock();
} }
@ -150,12 +150,13 @@ webkit::npapi::WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
const FilePath& file_path, const FilePath& file_path,
const std::string& mime_type) const std::string& mime_type)
{ {
HWND hwnd = browser_->GetWebViewHost() ? HWND hwnd = browser_->UIT_GetWebViewHost() ?
browser_->GetWebViewHost()->view_handle() : NULL; browser_->UIT_GetWebViewHost()->view_handle() : NULL;
if (!hwnd) if (!hwnd)
return NULL; return NULL;
return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type, hwnd); return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type,
hwnd);
} }
void BrowserWebViewDelegate::CreatedPluginWindow( void BrowserWebViewDelegate::CreatedPluginWindow(
@ -242,7 +243,7 @@ void BrowserWebViewDelegate::showContextMenu(
WebFrame* frame, const WebContextMenuData& data) WebFrame* frame, const WebContextMenuData& data)
{ {
POINT screen_pt = { data.mousePosition.x, data.mousePosition.y }; POINT screen_pt = { data.mousePosition.x, data.mousePosition.y };
MapWindowPoints(browser_->GetMainWndHandle(), HWND_DESKTOP, MapWindowPoints(browser_->UIT_GetMainWndHandle(), HWND_DESKTOP,
&screen_pt, 1); &screen_pt, 1);
HMENU menu = NULL; HMENU menu = NULL;
@ -356,7 +357,7 @@ void BrowserWebViewDelegate::showContextMenu(
// show the context menu // show the context menu
int selected_id = TrackPopupMenu(menu, int selected_id = TrackPopupMenu(menu,
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RECURSE, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RECURSE,
screen_pt.x, screen_pt.y, 0, browser_->GetMainWndHandle(), NULL); screen_pt.x, screen_pt.y, 0, browser_->UIT_GetMainWndHandle(), NULL);
if(selected_id != 0) { if(selected_id != 0) {
// An action was chosen // An action was chosen
@ -391,8 +392,8 @@ void BrowserWebViewDelegate::ShowJavaScriptAlert(WebFrame* webframe,
// TODO(cef): Think about what we should be showing as the prompt caption // TODO(cef): Think about what we should be showing as the prompt caption
std::wstring messageStr = message; std::wstring messageStr = message;
std::wstring titleStr = browser_->UIT_GetTitle(); std::wstring titleStr = browser_->UIT_GetTitle();
MessageBox(browser_->GetMainWndHandle(), messageStr.c_str(), titleStr.c_str(), MessageBox(browser_->UIT_GetMainWndHandle(), messageStr.c_str(),
MB_OK | MB_ICONWARNING); titleStr.c_str(), MB_OK | MB_ICONWARNING);
} }
bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe, bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
@ -401,7 +402,7 @@ bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
// TODO(cef): Think about what we should be showing as the prompt caption // TODO(cef): Think about what we should be showing as the prompt caption
std::wstring messageStr = message; std::wstring messageStr = message;
std::wstring titleStr = browser_->UIT_GetTitle(); std::wstring titleStr = browser_->UIT_GetTitle();
int rv = MessageBox(browser_->GetMainWndHandle(), messageStr.c_str(), int rv = MessageBox(browser_->UIT_GetMainWndHandle(), messageStr.c_str(),
titleStr.c_str(), MB_YESNO | MB_ICONQUESTION); titleStr.c_str(), MB_YESNO | MB_ICONQUESTION);
return (rv == IDYES); return (rv == IDYES);
} }
@ -511,11 +512,12 @@ bool BrowserWebViewDelegate::ShowFileChooser(std::vector<FilePath>& file_names,
bool result = false; bool result = false;
if (multi_select) { if (multi_select) {
result = RunOpenMultiFileDialog(L"", browser_->GetMainWndHandle(), result = RunOpenMultiFileDialog(L"", browser_->UIT_GetMainWndHandle(),
&file_names); &file_names);
} else { } else {
FilePath file_name; FilePath file_name;
result = RunOpenFileDialog(L"", browser_->GetMainWndHandle(), &file_name); result = RunOpenFileDialog(L"", browser_->UIT_GetMainWndHandle(),
&file_name);
if (result) if (result)
file_names.push_back(file_name); file_names.push_back(file_name);
} }

View File

@ -52,90 +52,90 @@
CGContextSetRGBFillColor (context, 1, 0, 1, 1); CGContextSetRGBFillColor (context, 1, 0, 1, 1);
CGContextFillRect(context, NSRectToCGRect(rect)); CGContextFillRect(context, NSRectToCGRect(rect));
if (browser_ && browser_->GetWebView()) { if (browser_ && browser_->UIT_GetWebView()) {
gfx::Rect client_rect(NSRectToCGRect(rect)); gfx::Rect client_rect(NSRectToCGRect(rect));
// flip from cocoa coordinates // flip from cocoa coordinates
client_rect.set_y([self frame].size.height - client_rect.set_y([self frame].size.height -
client_rect.height() - client_rect.y()); client_rect.height() - client_rect.y());
browser_->GetWebViewHost()->UpdatePaintRect(client_rect); browser_->UIT_GetWebViewHost()->UpdatePaintRect(client_rect);
browser_->GetWebViewHost()->Paint(); browser_->UIT_GetWebViewHost()->Paint();
} }
} }
- (void)mouseDown:(NSEvent *)theEvent { - (void)mouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)rightMouseDown:(NSEvent *)theEvent { - (void)rightMouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)otherMouseDown:(NSEvent *)theEvent { - (void)otherMouseDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)mouseUp:(NSEvent *)theEvent { - (void)mouseUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)rightMouseUp:(NSEvent *)theEvent { - (void)rightMouseUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)otherMouseUp:(NSEvent *)theEvent { - (void)otherMouseUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)mouseMoved:(NSEvent *)theEvent { - (void)mouseMoved:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)mouseDragged:(NSEvent *)theEvent { - (void)mouseDragged:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)scrollWheel:(NSEvent *)theEvent { - (void)scrollWheel:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->WheelEvent(theEvent); browser_->UIT_GetWebViewHost()->WheelEvent(theEvent);
} }
- (void)rightMouseDragged:(NSEvent *)theEvent { - (void)rightMouseDragged:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)otherMouseDragged:(NSEvent *)theEvent { - (void)otherMouseDragged:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)mouseEntered:(NSEvent *)theEvent { - (void)mouseEntered:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)mouseExited:(NSEvent *)theEvent { - (void)mouseExited:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->MouseEvent(theEvent); browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
} }
- (void)keyDown:(NSEvent *)theEvent { - (void)keyDown:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->KeyEvent(theEvent); browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
} }
- (void)keyUp:(NSEvent *)theEvent { - (void)keyUp:(NSEvent *)theEvent {
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->KeyEvent(theEvent); browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
} }
- (BOOL)isOpaque { - (BOOL)isOpaque {
@ -143,16 +143,16 @@
} }
- (BOOL)canBecomeKeyView { - (BOOL)canBecomeKeyView {
return browser_ && browser_->GetWebView(); return browser_ && browser_->UIT_GetWebView();
} }
- (BOOL)acceptsFirstResponder { - (BOOL)acceptsFirstResponder {
return browser_ && browser_->GetWebView(); return browser_ && browser_->UIT_GetWebView();
} }
- (BOOL)becomeFirstResponder { - (BOOL)becomeFirstResponder {
if (browser_ && browser_->GetWebView()) { if (browser_ && browser_->UIT_GetWebView()) {
browser_->GetWebViewHost()->SetFocus(YES); browser_->UIT_GetWebViewHost()->SetFocus(YES);
return YES; return YES;
} }
@ -160,8 +160,8 @@
} }
- (BOOL)resignFirstResponder { - (BOOL)resignFirstResponder {
if (browser_ && browser_->GetWebView()) { if (browser_ && browser_->UIT_GetWebView()) {
browser_->GetWebViewHost()->SetFocus(NO); browser_->UIT_GetWebViewHost()->SetFocus(NO);
return YES; return YES;
} }
@ -170,8 +170,8 @@
- (void)setFrame:(NSRect)frameRect { - (void)setFrame:(NSRect)frameRect {
[super setFrame:frameRect]; [super setFrame:frameRect];
if (browser_ && browser_->GetWebView()) if (browser_ && browser_->UIT_GetWebView())
browser_->GetWebViewHost()->Resize(gfx::Rect(NSRectToCGRect(frameRect))); browser_->UIT_GetWebViewHost()->Resize(gfx::Rect(NSRectToCGRect(frameRect)));
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }

View File

@ -48,6 +48,8 @@ ClientHandler::~ClientHandler()
CefHandler::RetVal ClientHandler::HandleAfterCreated( CefHandler::RetVal ClientHandler::HandleAfterCreated(
CefRefPtr<CefBrowser> browser) CefRefPtr<CefBrowser> browser)
{ {
REQUIRE_UI_THREAD();
Lock(); Lock();
if(!browser->IsPopup()) if(!browser->IsPopup())
{ {
@ -62,6 +64,8 @@ CefHandler::RetVal ClientHandler::HandleAfterCreated(
CefHandler::RetVal ClientHandler::HandleLoadStart(CefRefPtr<CefBrowser> browser, CefHandler::RetVal ClientHandler::HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, bool isMainContent) CefRefPtr<CefFrame> frame, bool isMainContent)
{ {
REQUIRE_UI_THREAD();
if(!browser->IsPopup() && !frame.get()) if(!browser->IsPopup() && !frame.get())
{ {
Lock(); Lock();
@ -77,6 +81,8 @@ CefHandler::RetVal ClientHandler::HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefHandler::RetVal ClientHandler::HandleLoadEnd(CefRefPtr<CefBrowser> browser, CefHandler::RetVal ClientHandler::HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, bool isMainContent, int httpStatusCode) CefRefPtr<CefFrame> frame, bool isMainContent, int httpStatusCode)
{ {
REQUIRE_UI_THREAD();
if(!browser->IsPopup() && !frame.get()) if(!browser->IsPopup() && !frame.get())
{ {
Lock(); Lock();
@ -93,6 +99,8 @@ CefHandler::RetVal ClientHandler::HandleLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& failedUrl, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& failedUrl,
CefString& errorText) CefString& errorText)
{ {
REQUIRE_UI_THREAD();
if(errorCode == ERR_CACHE_MISS) if(errorCode == ERR_CACHE_MISS)
{ {
// Usually caused by navigating to a page with POST data via back or // 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, const CefString& fileName, int64 contentLength,
CefRefPtr<CefDownloadHandler>& handler) CefRefPtr<CefDownloadHandler>& handler)
{ {
REQUIRE_UI_THREAD();
// Create the handler for the file download. // Create the handler for the file download.
handler = CreateDownloadHandler(m_DownloadListener, fileName); handler = CreateDownloadHandler(m_DownloadListener, fileName);
return RV_CONTINUE; return RV_CONTINUE;
@ -135,6 +145,8 @@ CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter(
CefString& topCenter, CefString& topRight, CefString& bottomLeft, CefString& topCenter, CefString& topRight, CefString& bottomLeft,
CefString& bottomCenter, CefString& bottomRight) CefString& bottomCenter, CefString& bottomRight)
{ {
REQUIRE_UI_THREAD();
// Place the page title at top left // Place the page title at top left
topLeft = title; topLeft = title;
// Place the page URL at top right // Place the page URL at top right
@ -151,6 +163,8 @@ CefHandler::RetVal ClientHandler::HandlePrintHeaderFooter(
CefHandler::RetVal ClientHandler::HandleJSBinding(CefRefPtr<CefBrowser> browser, CefHandler::RetVal ClientHandler::HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Value> object) CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Value> object)
{ {
REQUIRE_UI_THREAD();
// Add the V8 bindings. // Add the V8 bindings.
InitBindingTest(browser, frame, object); InitBindingTest(browser, frame, object);
@ -160,6 +174,8 @@ CefHandler::RetVal ClientHandler::HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefHandler::RetVal ClientHandler::HandleBeforeWindowClose( CefHandler::RetVal ClientHandler::HandleBeforeWindowClose(
CefRefPtr<CefBrowser> browser) CefRefPtr<CefBrowser> browser)
{ {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle()) if(m_BrowserHwnd == browser->GetWindowHandle())
{ {
// Free the browser pointer so that the browser can be destroyed // 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, CefRefPtr<CefBrowser> browser, const CefString& message,
const CefString& source, int line) const CefString& source, int line)
{ {
REQUIRE_UI_THREAD();
Lock(); Lock();
bool first_message = m_LogFile.empty(); bool first_message = m_LogFile.empty();
if(first_message) { if(first_message) {
@ -271,28 +289,52 @@ CefWindowHandle AppGetMainHwnd()
return g_handler->GetMainHwnd(); return g_handler->GetMainHwnd();
} }
void RunGetSourceTest(CefRefPtr<CefFrame> frame) void RunGetSourceTest(CefRefPtr<CefBrowser> browser)
{ {
// Retrieve the current page source and display. // Execute the GetSource() call on the UI thread.
std::string source = frame->GetSource(); class ExecTask : public CefThreadSafeBase<CefTask>
source = StringReplace(source, "<", "&lt;"); {
source = StringReplace(source, ">", "&gt;"); public:
std::stringstream ss; ExecTask(CefRefPtr<CefFrame> frame) : m_Frame(frame) {}
ss << "<html><body>Source:" << "<pre>" << source virtual void Execute(CefThreadId threadId)
<< "</pre></body></html>"; {
frame->LoadString(ss.str(), "http://tests/getsource"); // Retrieve the current page source and display.
std::string source = m_Frame->GetSource();
source = StringReplace(source, "<", "&lt;");
source = StringReplace(source, ">", "&gt;");
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. // Execute the GetText() call on the UI thread.
std::string text = frame->GetText(); class ExecTask : public CefThreadSafeBase<CefTask>
text = StringReplace(text, "<", "&lt;"); {
text = StringReplace(text, ">", "&gt;"); public:
std::stringstream ss; ExecTask(CefRefPtr<CefFrame> frame) : m_Frame(frame) {}
ss << "<html><body>Text:" << "<pre>" << text virtual void Execute(CefThreadId threadId)
<< "</pre></body></html>"; {
frame->LoadString(ss.str(), "http://tests/gettext"); // Retrieve the current page text and display.
std::string text = m_Frame->GetText();
text = StringReplace(text, "<", "&lt;");
text = StringReplace(text, ">", "&gt;");
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) void RunRequestTest(CefRefPtr<CefBrowser> browser)

View File

@ -7,7 +7,7 @@
#include "include/cef.h" #include "include/cef.h"
#include "download_handler.h" #include "download_handler.h"
#include "util.h"
// Client implementation of the browser handler class // Client implementation of the browser handler class
class ClientHandler : public CefThreadSafeBase<CefHandler> class ClientHandler : public CefThreadSafeBase<CefHandler>
@ -32,14 +32,16 @@ public:
ClientHandler(); ClientHandler();
~ClientHandler(); ~ClientHandler();
// Event called before a new window is created. The |parentBrowser| parameter // Called on the UI thread before a new window is created. The |parentBrowser|
// will point to the parent browser window, if any. The |popup| parameter // parameter will point to the parent browser window, if any. The |popup|
// will be true if the new window is a popup window. If you create the window // parameter will be true if the new window is a popup window, in which case
// yourself you should populate the window handle member of |createInfo| and // |popupFeatures| will contain information about the style of popup window
// return RV_HANDLED. Otherwise, return RV_CONTINUE and the framework will // requested. If you create the window yourself you should populate the window
// create the window. By default, a newly created window will recieve the // handle member of |createInfo| and return RV_HANDLED. Otherwise, return
// same handler as the parent window. To change the handler for the new // RV_CONTINUE and the framework will create the window. By default, a newly
// window modify the object that |handler| points to. // 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, virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& createInfo, bool popup, CefWindowInfo& createInfo, bool popup,
const CefPopupFeatures& popupFeatures, const CefPopupFeatures& popupFeatures,
@ -47,68 +49,73 @@ public:
CefString& url, CefString& url,
CefBrowserSettings& settings); CefBrowserSettings& settings);
// Event called after a new window is created. The return value is currently // Called on the UI thread after a new window is created. The return value is
// ignored. // currently ignored.
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser); virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
// Event called when the address bar changes. The return value is currently // Called on the UI thread when a frame's address has changed. The return
// ignored. // value is currently ignored.
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser, virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& url); const CefString& url);
// Event called when the page title changes. The return value is currently // Called on the UI thread when the page title changes. The return value is
// ignored. // currently ignored.
virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser, virtual RetVal HandleTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title); const CefString& title);
// Event called before browser navigation. The client has an opportunity to // Called on the UI thread before browser navigation. The client has an
// modify the |request| object if desired. Return RV_HANDLED to cancel // opportunity to modify the |request| object if desired. Return RV_HANDLED
// navigation. // to cancel navigation.
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser, virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request, CefRefPtr<CefRequest> request,
NavType navType, bool isRedirect) NavType navType, bool isRedirect)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called when the browser begins loading a page. The |frame| pointer // Called on the UI thread when the browser begins loading a page. The |frame|
// will be empty if the event represents the overall load status and not the // pointer will be empty if the event represents the overall load status and
// load status for a particular frame. |isMainContent| will be true if this // not the load status for a particular frame. |isMainContent| will be true if
// load is for the main content area and not an iframe. This method may not // this load is for the main content area and not an iframe. This method may
// be called if the load request fails. The return value is currently ignored. // not be called if the load request fails. The return value is currently
// ignored.
virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser, virtual RetVal HandleLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
bool isMainContent); bool isMainContent);
// Event called when the browser is done loading a page. The |frame| pointer // Called on the UI thread when the browser is done loading a page. The
// will be empty if the event represents the overall load status and not the // |frame| pointer will be empty if the event represents the overall load
// load status for a particular frame. |isMainContent| will be true if this // status and not the load status for a particular frame. |isMainContent| will
// load is for the main content area and not an iframe. This method will be // be true if this load is for the main content area and not an iframe. This
// called irrespective of whether the request completes successfully. The // method will be called irrespective of whether the request completes
// return value is currently ignored. // successfully. The return value is currently ignored.
virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser, virtual RetVal HandleLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
bool isMainContent, bool isMainContent,
int httpStatusCode); int httpStatusCode);
// Called when the browser fails to load a resource. |errorCode| is the // Called on the UI thread when the browser fails to load a resource.
// error code number and |failedUrl| is the URL that failed to load. To // |errorCode| is the error code number and |failedUrl| is the URL that failed
// provide custom error text assign the text to |errorText| and return // to load. To provide custom error text assign the text to |errorText| and
// RV_HANDLED. Otherwise, return RV_CONTINUE for the default error text. // return RV_HANDLED. Otherwise, return RV_CONTINUE for the default error
// text.
virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser, virtual RetVal HandleLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
ErrorCode errorCode, ErrorCode errorCode,
const CefString& failedUrl, const CefString& failedUrl,
CefString& errorText); CefString& errorText);
// Event called before a resource is loaded. To allow the resource to load // Called on the IO thread before a resource is loaded. To allow the resource
// normally return RV_CONTINUE. To redirect the resource to a new url // to load normally return RV_CONTINUE. To redirect the resource to a new url
// populate the |redirectUrl| value and return RV_CONTINUE. To specify // populate the |redirectUrl| value and return RV_CONTINUE. To specify data
// data for the resource return a CefStream object in |resourceStream|, set // for the resource return a CefStream object in |resourceStream|, set
// 'mimeType| to the resource stream's mime type, and return RV_CONTINUE. // |mimeType| to the resource stream's mime type, and return RV_CONTINUE. To
// To cancel loading of the resource return RV_HANDLED. // 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, virtual RetVal HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefRequest> request, CefRefPtr<CefRequest> request,
CefString& redirectUrl, CefString& redirectUrl,
@ -116,39 +123,40 @@ public:
CefString& mimeType, CefString& mimeType,
int loadFlags); int loadFlags);
// Called to handle requests for URLs with an unknown protocol component. // Called on the IO thread to handle requests for URLs with an unknown
// Return RV_HANDLED to indicate that the request should succeed because it // protocol component. Return RV_HANDLED to indicate that the request should
// was externally handled. Set |allow_os_execution| to true and return // succeed because it was externally handled. Set |allow_os_execution| to true
// RV_CONTINUE to attempt execution via the registered OS protocol handler, // and return RV_CONTINUE to attempt execution via the registered OS protocol
// if any. If RV_CONTINUE is returned and either |allow_os_execution| is false // handler, if any. If RV_CONTINUE is returned and either |allow_os_execution|
// or OS protocol handler execution fails then the request will fail with an // is false or OS protocol handler execution fails then the request will fail
// error condition. // with an error condition.
// SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED // SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED
// ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION. // ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.
virtual RetVal HandleProtocolExecution(CefRefPtr<CefBrowser> browser, virtual RetVal HandleProtocolExecution(CefRefPtr<CefBrowser> browser,
const CefString& url, const CefString& url,
bool* allow_os_execution) bool* allow_os_execution)
{ {
REQUIRE_IO_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Called when a server indicates via the 'Content-Disposition' header that a // Called on the UI thread when a server indicates via the
// response represents a file to download. |mime_type| is the mime type for // 'Content-Disposition' header that a response represents a file to download.
// the download, |file_name| is the suggested target file name and // |mimeType| is the mime type for the download, |fileName| is the suggested
// |content_length| is either the value of the 'Content-Size' header or -1 if // target file name and |contentLength| is either the value of the
// no size was provided. Set |handler| to the CefDownloadHandler instance that // 'Content-Size' header or -1 if no size was provided. Set |handler| to the
// will recieve the file contents. Return RV_CONTINUE to download the file // CefDownloadHandler instance that will recieve the file contents. Return
// or RV_HANDLED to cancel the file download. // RV_CONTINUE to download the file or RV_HANDLED to cancel the file download.
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser, virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
const CefString& mimeType, const CefString& mimeType,
const CefString& fileName, const CefString& fileName,
int64 contentLength, int64 contentLength,
CefRefPtr<CefDownloadHandler>& handler); CefRefPtr<CefDownloadHandler>& handler);
// Called when the browser needs credentials from the user. |isProxy| // Called on the IO thread when the browser needs credentials from the user.
// indicates whether the host is a proxy server. |host| contains the hostname // |isProxy| indicates whether the host is a proxy server. |host| contains the
// and port number. Set |username| and |password| and return RV_HANDLED to // hostname and port number. Set |username| and |password| and return
// handle the request. Return RV_CONTINUE to cancel the request. // RV_HANDLED to handle the request. Return RV_CONTINUE to cancel the request.
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser, virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
bool isProxy, bool isProxy,
const CefString& host, const CefString& host,
@ -157,55 +165,60 @@ public:
CefString& username, CefString& username,
CefString& password) CefString& password)
{ {
REQUIRE_IO_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called before a context menu is displayed. To cancel display of the // Called on the UI thread before a context menu is displayed. To cancel
// default context menu return RV_HANDLED. // display of the default context menu return RV_HANDLED.
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser, virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
const MenuInfo& menuInfo) const MenuInfo& menuInfo)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called to optionally override the default text for a context menu // Called on the UI thread to optionally override the default text for a
// item. |label| contains the default text and may be modified to substitute // context menu item. |label| contains the default text and may be modified to
// alternate text. The return value is currently ignored. // substitute alternate text. The return value is currently ignored.
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser, virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,
MenuId menuId, CefString& label) MenuId menuId, CefString& label)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called when an option is selected from the default context menu. // Called on the UI thread when an option is selected from the default context
// Return RV_HANDLED to cancel default handling of the action. // menu. Return RV_HANDLED to cancel default handling of the action.
virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser, virtual RetVal HandleMenuAction(CefRefPtr<CefBrowser> browser,
MenuId menuId) MenuId menuId)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called to allow customization of standard print options before the // Called on the UI thread to allow customization of standard print options
// print dialog is displayed. |printOptions| allows specification of paper // before the print dialog is displayed. |printOptions| allows specification
// size, orientation and margins. Note that the specified margins may be // of paper size, orientation and margins. Note that the specified margins may
// adjusted if they are outside the range supported by the printer. All units // be adjusted if they are outside the range supported by the printer. All
// are in inches. Return RV_CONTINUE to display the default print options or // units are in inches. Return RV_CONTINUE to display the default print
// RV_HANDLED to display the modified |printOptions|. // options or RV_HANDLED to display the modified |printOptions|.
virtual RetVal HandlePrintOptions(CefRefPtr<CefBrowser> browser, virtual RetVal HandlePrintOptions(CefRefPtr<CefBrowser> browser,
CefPrintOptions& printOptions) CefPrintOptions& printOptions)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called to format print headers and footers. |printInfo| contains // Called on the UI thread to format print headers and footers. |printInfo|
// platform-specific information about the printer context. |url| is the // contains platform-specific information about the printer context. |url| is
// URL if the currently printing page, |title| is the title of the currently // the URL if the currently printing page, |title| is the title of the
// printing page, |currentPage| is the current page number and |maxPages| is // currently printing page, |currentPage| is the current page number and
// the total number of pages. Six default header locations are provided // |maxPages| is the total number of pages. Six default header locations are
// by the implementation: top left, top center, top right, bottom left, // provided by the implementation: top left, top center, top right, bottom
// bottom center and bottom right. To use one of these default locations // 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 // just assign a string to the appropriate variable. To draw the header and
// and footer yourself return RV_HANDLED. Otherwise, populate the approprate // footer yourself return RV_HANDLED. Otherwise, populate the approprate
// variables and return RV_CONTINUE. // variables and return RV_CONTINUE.
virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser, virtual RetVal HandlePrintHeaderFooter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
@ -220,29 +233,32 @@ public:
CefString& bottomCenter, CefString& bottomCenter,
CefString& bottomRight); CefString& bottomRight);
// Run a JS alert message. Return RV_CONTINUE to display the default alert // Called on the UI thread to run a JS alert message. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom alert. // display the default alert or RV_HANDLED if you displayed a custom alert.
virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSAlert(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& message) const CefString& message)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Run a JS confirm request. Return RV_CONTINUE to display the default alert // Called on the UI thread to run a JS confirm request. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom alert. If you handled the alert // display the default alert or RV_HANDLED if you displayed a custom alert. If
// set |retval| to true if the user accepted the confirmation. // you handled the alert set |retval| to true if the user accepted the
// confirmation.
virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSConfirm(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& message, bool& retval) const CefString& message, bool& retval)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Run a JS prompt request. Return RV_CONTINUE to display the default prompt // Called on the UI thread to run a JS prompt request. Return RV_CONTINUE to
// or RV_HANDLED if you displayed a custom prompt. If you handled the prompt // display the default prompt or RV_HANDLED if you displayed a custom prompt.
// set |retval| to true if the user accepted the prompt and request and // If you handled the prompt set |retval| to true if the user accepted the
// |result| to the resulting value. // prompt and request and |result| to the resulting value.
virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSPrompt(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
const CefString& message, const CefString& message,
@ -250,92 +266,99 @@ public:
bool& retval, bool& retval,
CefString& result) CefString& result)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called for binding to a frame's JavaScript global object. The // Called on the UI thread for adding values to a frame's JavaScript 'window'
// return value is currently ignored. // object. The return value is currently ignored.
virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser, virtual RetVal HandleJSBinding(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object); CefRefPtr<CefV8Value> object);
// Called just before a window is closed. The return value is currently // Called on the UI thread just before a window is closed. The return value is
// ignored. // currently ignored.
virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser); virtual RetVal HandleBeforeWindowClose(CefRefPtr<CefBrowser> browser);
// Called when the browser component is about to loose focus. For instance, // Called on the UI thread when the browser component is about to loose focus.
// if focus was on the last HTML element and the user pressed the TAB key. // For instance, if focus was on the last HTML element and the user pressed
// The return value is currently ignored. // the TAB key. The return value is currently ignored.
virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser, bool reverse) virtual RetVal HandleTakeFocus(CefRefPtr<CefBrowser> browser, bool reverse)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Called when the browser component is requesting focus. |isWidget| will be // Called on the UI thread when the browser component is requesting focus.
// true if the focus is requested for a child widget of the browser window. // |isWidget| will be true if the focus is requested for a child widget of the
// Return RV_CONTINUE to allow the focus to be set or RV_HANDLED to cancel // browser window. Return RV_CONTINUE to allow the focus to be set or
// setting the focus. // RV_HANDLED to cancel setting the focus.
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser,
bool isWidget) bool isWidget)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called when the browser is about to display a tooltip. |text| // Called on the UI thread when the browser component receives a keyboard
// contains the text that will be displayed in the tooltip. To handle // event. |type| is the type of keyboard event, |code| is the windows scan-
// the display of the tooltip yourself return RV_HANDLED. Otherwise, // code for the event, |modifiers| is a set of bit-flags describing any
// you can optionally modify |text| and then return RV_CONTINUE to allow // pressed modifier keys and |isSystemKey| is true if Windows considers this a
// the browser to display the tooltip. // '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, virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
CefString& text) CefString& text)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Event called when the browser has a status message. |text| contains the // Called on the UI thread when the browser has a status message. |text|
// text that will be displayed in the status message and |type| indicates the // contains the text that will be displayed in the status message and |type|
// status message type. The return value is currently ignored. // indicates the status message type. The return value is currently ignored.
/*--cef()--*/
virtual RetVal HandleStatus(CefRefPtr<CefBrowser> browser, virtual RetVal HandleStatus(CefRefPtr<CefBrowser> browser,
const CefString& text, StatusType type) const CefString& text, StatusType type)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
// Called when the browser component receives a keyboard event. // Called on the UI thread to display a console message. Return RV_HANDLED to
// |type| is the type of keyboard event (see |KeyEventType|). // stop the message from being output to the console.
// |code| is the windows scan-code for the event. virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
// |modifiers| is a set of bit-flags describing any pressed modifier keys. const CefString& message,
// |isSystemKey| is set if Windows considers this a 'system key' message; const CefString& source, int line);
// (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 to display a console message. Return RV_HANDLED to stop the message // Called on the UI thread to report find results returned by
// from being output to the console. // CefBrowser::Find(). |identifer| is the identifier passed to
RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser, // CefBrowser::Find(), |count| is the number of matches currently identified,
const CefString& message, // |selectionRect| is the location of where the match was found (in window
const CefString& source, int line); // coordinates), |activeMatchOrdinal| is the current position in the search
// results, and |finalUpdate| is true if this is the last find notification.
// Called to report find results returned by CefBrowser::Find(). |identifer| // The return value is currently ignored.
// 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, virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser,
int identifier, int count, int identifier, int count,
const CefRect& selectionRect, const CefRect& selectionRect,
int activeMatchOrdinal, bool finalUpdate) int activeMatchOrdinal, bool finalUpdate)
{ {
REQUIRE_UI_THREAD();
return RV_CONTINUE; return RV_CONTINUE;
} }
@ -400,8 +423,8 @@ CefWindowHandle AppGetMainHwnd();
std::string AppGetWorkingDirectory(); std::string AppGetWorkingDirectory();
// Implementations for various tests. // Implementations for various tests.
void RunGetSourceTest(CefRefPtr<CefFrame> frame); void RunGetSourceTest(CefRefPtr<CefBrowser> browser);
void RunGetTextTest(CefRefPtr<CefFrame> frame); void RunGetTextTest(CefRefPtr<CefBrowser> browser);
void RunRequestTest(CefRefPtr<CefBrowser> browser); void RunRequestTest(CefRefPtr<CefBrowser> browser);
void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser); void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser);
void RunPopupTest(CefRefPtr<CefBrowser> browser); void RunPopupTest(CefRefPtr<CefBrowser> browser);

View File

@ -292,12 +292,12 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
- (IBAction)testGetSource:(id)sender { - (IBAction)testGetSource:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) if(g_handler.get() && g_handler->GetBrowserHwnd())
RunGetSourceTest(g_handler->GetBrowser()->GetMainFrame()); RunGetSourceTest(g_handler->GetBrowser());
} }
- (IBAction)testGetText:(id)sender { - (IBAction)testGetText:(id)sender {
if(g_handler.get() && g_handler->GetBrowserHwnd()) if(g_handler.get() && g_handler->GetBrowserHwnd())
RunGetTextTest(g_handler->GetBrowser()->GetMainFrame()); RunGetTextTest(g_handler->GetBrowser());
} }
- (IBAction)testJSBinding:(id)sender { - (IBAction)testJSBinding:(id)sender {
@ -372,6 +372,7 @@ CefHandler::RetVal ClientHandler::HandleBeforeCreated(
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler, const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
CefString& url, CefBrowserSettings& settings) CefString& url, CefBrowserSettings& settings)
{ {
REQUIRE_UIT();
return RV_CONTINUE; return RV_CONTINUE;
} }
@ -379,6 +380,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const CefString& url) const CefString& url)
{ {
REQUIRE_UIT();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
{ {
// Set the edit window text // Set the edit window text
@ -393,6 +396,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
CefHandler::RetVal ClientHandler::HandleTitleChange( CefHandler::RetVal ClientHandler::HandleTitleChange(
CefRefPtr<CefBrowser> browser, const CefString& title) CefRefPtr<CefBrowser> browser, const CefString& title)
{ {
REQUIRE_UIT();
// Set the frame window title bar // Set the frame window title bar
NSWindow* window = (NSWindow*)m_MainHwnd; NSWindow* window = (NSWindow*)m_MainHwnd;
std::string titleStr(title); std::string titleStr(title);
@ -406,6 +411,8 @@ CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
CefString& mimeType, int loadFlags) CefString& mimeType, int loadFlags)
{ {
REQUIRE_UIT();
std::string url = request->GetURL(); std::string url = request->GetURL();
if(url == "http://tests/request") { if(url == "http://tests/request") {
// Show the request contents // Show the request contents

View File

@ -472,50 +472,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
browser->StopLoad(); browser->StopLoad();
return 0; return 0;
case ID_TESTS_GETSOURCE: // Test the GetSource function case ID_TESTS_GETSOURCE: // Test the GetSource function
if(browser.get()) { if(browser.get())
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP RunGetSourceTest(browser);
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
}
return 0; return 0;
case ID_TESTS_GETTEXT: // Test the GetText function case ID_TESTS_GETTEXT: // Test the GetText function
if(browser.get()) { if(browser.get())
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP RunGetTextTest(browser);
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
}
return 0; return 0;
case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler
if(browser.get()) if(browser.get())
@ -679,6 +641,8 @@ CefHandler::RetVal ClientHandler::HandleBeforeCreated(
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler, const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
CefString& url, CefBrowserSettings& settings) CefString& url, CefBrowserSettings& settings)
{ {
REQUIRE_UI_THREAD();
if(popup) { if(popup) {
if(popupFeatures.xSet) if(popupFeatures.xSet)
createInfo.m_x = popupFeatures.x; createInfo.m_x = popupFeatures.x;
@ -697,6 +661,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const CefString& url) const CefString& url)
{ {
REQUIRE_UI_THREAD();
if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain())
{ {
// Set the edit window text // Set the edit window text
@ -708,6 +674,8 @@ CefHandler::RetVal ClientHandler::HandleAddressChange(
CefHandler::RetVal ClientHandler::HandleTitleChange( CefHandler::RetVal ClientHandler::HandleTitleChange(
CefRefPtr<CefBrowser> browser, const CefString& title) CefRefPtr<CefBrowser> browser, const CefString& title)
{ {
REQUIRE_UI_THREAD();
// Set the frame window title bar // Set the frame window title bar
CefWindowHandle hwnd = browser->GetWindowHandle(); CefWindowHandle hwnd = browser->GetWindowHandle();
if(!browser->IsPopup()) if(!browser->IsPopup())
@ -724,6 +692,8 @@ CefHandler::RetVal ClientHandler::HandleBeforeResourceLoad(
CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
CefString& mimeType, int loadFlags) CefString& mimeType, int loadFlags)
{ {
REQUIRE_IO_THREAD();
DWORD dwSize; DWORD dwSize;
LPBYTE pBytes; LPBYTE pBytes;

View File

@ -96,7 +96,7 @@ public:
// continue receiving data and |false| to cancel. // continue receiving data and |false| to cancel.
virtual bool ReceivedData(void* data, int data_size) virtual bool ReceivedData(void* data, int data_size)
{ {
ASSERT(CefCurrentlyOn(TID_UI)); REQUIRE_UI_THREAD();
if(data_size == 0) if(data_size == 0)
return true; return true;
@ -118,7 +118,7 @@ public:
// The download is complete. // The download is complete.
virtual void Complete() virtual void Complete()
{ {
ASSERT(CefCurrentlyOn(TID_UI)); REQUIRE_UI_THREAD();
// Flush and close the file on the FILE thread. // Flush and close the file on the FILE thread.
PostOnThread(TID_FILE, this, &ClientDownloadHandler::OnComplete); PostOnThread(TID_FILE, this, &ClientDownloadHandler::OnComplete);
@ -130,7 +130,7 @@ public:
void OnOpen() void OnOpen()
{ {
ASSERT(CefCurrentlyOn(TID_FILE)); REQUIRE_FILE_THREAD();
if(file_) if(file_)
return; return;
@ -179,7 +179,7 @@ public:
void OnComplete() void OnComplete()
{ {
ASSERT(CefCurrentlyOn(TID_FILE)); REQUIRE_FILE_THREAD();
if(!file_) if(!file_)
return; return;
@ -196,7 +196,7 @@ public:
void OnReceivedData() void OnReceivedData()
{ {
ASSERT(CefCurrentlyOn(TID_FILE)); REQUIRE_FILE_THREAD();
std::vector<std::vector<char>*> data; std::vector<std::vector<char>*> data;

View File

@ -3,9 +3,10 @@
// can be found in the LICENSE file. // can be found in the LICENSE file.
#include "include/cef_wrapper.h" #include "include/cef_wrapper.h"
#include "resource_util.h"
#include "scheme_test.h" #include "scheme_test.h"
#include "string_util.h" #include "string_util.h"
#include "resource_util.h" #include "util.h"
#ifdef _WIN32 #ifdef _WIN32
#include "resource.h" #include "resource.h"
@ -30,6 +31,8 @@ public:
virtual bool ProcessRequest(CefRefPtr<CefRequest> request, virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefString& mime_type, int* response_length) CefString& mime_type, int* response_length)
{ {
REQUIRE_IO_THREAD();
bool handled = false; bool handled = false;
Lock(); Lock();
@ -91,6 +94,7 @@ public:
// Cancel processing of the request. // Cancel processing of the request.
virtual void Cancel() virtual void Cancel()
{ {
REQUIRE_IO_THREAD();
} }
// Copy up to |bytes_to_read| bytes into |data_out|. If the copy succeeds // 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, virtual bool ReadResponse(void* data_out, int bytes_to_read,
int* bytes_read) int* bytes_read)
{ {
REQUIRE_IO_THREAD();
bool has_data = false; bool has_data = false;
*bytes_read = 0; *bytes_read = 0;
@ -134,6 +140,7 @@ public:
// Return a new scheme handler instance to handle the request. // Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefSchemeHandler> Create() virtual CefRefPtr<CefSchemeHandler> Create()
{ {
REQUIRE_IO_THREAD();
return new ClientSchemeHandler(); return new ClientSchemeHandler();
} }
}; };

View File

@ -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. // 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
@ -6,6 +6,8 @@
#ifndef _CEFCLIENT_UTIL_H #ifndef _CEFCLIENT_UTIL_H
#define _CEFCLIENT_UTIL_H #define _CEFCLIENT_UTIL_H
#include "include/cef.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -56,4 +58,8 @@
#endif // !_WIN32 #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 #endif // _CEFCLIENT_UTIL_H