From fe80635c69ac159c8374590ecbe7b34ebd3317d0 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 8 Dec 2011 13:25:26 +0000 Subject: [PATCH] Add CefQuitMessageLoop function (issue #443). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@412 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/cef.h | 8 ++++++++ include/cef_capi.h | 7 +++++++ libcef/cef_context.cc | 17 +++++++++++++++++ libcef/cef_process.cc | 5 +++++ libcef/cef_process.h | 5 ++++- libcef_dll/libcef_dll.cc | 9 +++++++++ libcef_dll/wrapper/libcef_dll_wrapper.cc | 9 +++++++++ 7 files changed, 59 insertions(+), 1 deletion(-) diff --git a/include/cef.h b/include/cef.h index ef2d97c7f..ef66283a4 100644 --- a/include/cef.h +++ b/include/cef.h @@ -122,6 +122,14 @@ void CefDoMessageLoopWork(); /*--cef()--*/ void CefRunMessageLoop(); +/// +// Quit the CEF message loop that was started by calling CefRunMessageLoop(). +// This function should only be called on the main application thread and only +// if CefRunMessageLoop() was used. +/// +/*--cef()--*/ +void CefQuitMessageLoop(); + /// // Register a new V8 extension with the specified JavaScript extension code and // handler. Functions implemented by the handler are prototyped using the diff --git a/include/cef_capi.h b/include/cef_capi.h index 4345f498a..6bca5d1f2 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -84,6 +84,13 @@ CEF_EXPORT void cef_do_message_loop_work(); /// CEF_EXPORT void cef_run_message_loop(); +/// +// Quit the CEF message loop that was started by calling cef_run_message_loop(). +// This function should only be called on the main application thread and only +// if cef_run_message_loop() was used. +/// +CEF_EXPORT void cef_quit_message_loop(); + /// // Register a new V8 extension with the specified JavaScript extension code and // handler. Functions implemented by the handler are prototyped using the diff --git a/libcef/cef_context.cc b/libcef/cef_context.cc index 8350fbc1a..a04bdbe0e 100644 --- a/libcef/cef_context.cc +++ b/libcef/cef_context.cc @@ -421,6 +421,23 @@ void CefRunMessageLoop() _Context->process()->RunMessageLoop(); } +void CefQuitMessageLoop() +{ + // Verify that the context is in a valid state. + if (!CONTEXT_STATE_VALID()) { + NOTREACHED() << "context not valid"; + return; + } + + // Must always be called on the same thread as Initialize. + if(!_Context->process()->CalledOnValidThread()) { + NOTREACHED() << "called on invalid thread"; + return; + } + + _Context->process()->QuitMessageLoop(); +} + bool CefRegisterPlugin(const CefPluginInfo& plugin_info) { // Verify that the context is in a valid state. diff --git a/libcef/cef_process.cc b/libcef/cef_process.cc index d33aedefb..a8ec609b0 100644 --- a/libcef/cef_process.cc +++ b/libcef/cef_process.cc @@ -97,6 +97,11 @@ void CefProcess::RunMessageLoop() { ui_message_loop_->RunMessageLoop(); } +void CefProcess::QuitMessageLoop() { + DCHECK(CalledOnValidThread() && ui_message_loop_.get() != NULL); + ui_message_loop_->Quit(); +} + void CefProcess::CreateUIThread() { DCHECK(!created_ui_thread_ && ui_thread_.get() == NULL); created_ui_thread_ = true; diff --git a/libcef/cef_process.h b/libcef/cef_process.h index 84d6cffa7..d04aefdc0 100644 --- a/libcef/cef_process.h +++ b/libcef/cef_process.h @@ -60,9 +60,12 @@ class CefProcess : public base::NonThreadSafe { // RunMessageLoop() was called you do not need to call this method. void DoMessageLoopIteration(); - // Run the UI message loop for the on the current thread. + // Run the UI message loop on the current thread. void RunMessageLoop(); + // Quit the UI message loop on the current thread. + void QuitMessageLoop(); + // Returns the thread that we perform I/O coordination on (network requests, // communication with renderers, etc. // NOTE: You should ONLY use this to pass to IPC or other objects which must diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index a0f4c73c4..d43f8196c 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -166,6 +166,15 @@ CEF_EXPORT void cef_run_message_loop() } +CEF_EXPORT void cef_quit_message_loop() +{ + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + CefQuitMessageLoop(); +} + + CEF_EXPORT int cef_register_extension(const cef_string_t* extension_name, const cef_string_t* javascript_code, struct _cef_v8handler_t* handler) { diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index 810501225..6f2e49c22 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -168,6 +168,15 @@ CEF_GLOBAL void CefRunMessageLoop() } +CEF_GLOBAL void CefQuitMessageLoop() +{ + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_quit_message_loop(); +} + + CEF_GLOBAL bool CefRegisterExtension(const CefString& extension_name, const CefString& javascript_code, CefRefPtr handler) {