Add OnRenderProcessTerminated and OnPluginCrashed notifications to CefLoadHandler (issue #633).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@710 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-06-25 19:49:17 +00:00
parent 6f2897cb50
commit 89c70a8b11
10 changed files with 179 additions and 0 deletions

View File

@ -88,6 +88,21 @@ typedef struct _cef_load_handler_t {
struct _cef_browser_t* browser, struct _cef_frame_t* frame,
enum cef_errorcode_t errorCode, const cef_string_t* errorText,
const cef_string_t* failedUrl);
///
// Called when the render process terminates unexpectedly. |status| indicates
// how the process terminated.
///
void (CEF_CALLBACK *on_render_process_terminated)(
struct _cef_load_handler_t* self, struct _cef_browser_t* browser,
enum cef_termination_status_t status);
///
// Called when a plugin has crashed. |plugin_path| is the path of the plugin
// that crashed.
///
void (CEF_CALLBACK *on_plugin_crashed)(struct _cef_load_handler_t* self,
struct _cef_browser_t* browser, const cef_string_t* plugin_path);
} cef_load_handler_t;

View File

@ -50,6 +50,7 @@
class CefLoadHandler : public virtual CefBase {
public:
typedef cef_errorcode_t ErrorCode;
typedef cef_termination_status_t TerminationStatus;
///
// Called when the browser begins loading a frame. The |frame| value will
@ -88,6 +89,22 @@ class CefLoadHandler : public virtual CefBase {
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) {}
///
// Called when the render process terminates unexpectedly. |status| indicates
// how the process terminated.
///
/*--cef()--*/
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
TerminationStatus status) {}
///
// Called when a plugin has crashed. |plugin_path| is the path of the plugin
// that crashed.
///
/*--cef()--*/
virtual void OnPluginCrashed(CefRefPtr<CefBrowser> browser,
const CefString& plugin_path) {}
};
#endif // CEF_INCLUDE_CEF_LOAD_HANDLER_H_

View File

@ -580,6 +580,26 @@ typedef struct _cef_cookie_t {
cef_time_t expires;
} cef_cookie_t;
///
// Process termination status values.
///
enum cef_termination_status_t {
///
// Non-zero exit status.
///
TS_ABNORMAL_TERMINATION,
///
// SIGKILL or task manager kill.
///
TS_PROCESS_WAS_KILLED,
///
// Segmentation fault.
///
TS_PROCESS_CRASHED,
};
///
// Storage types.
///

View File

@ -1125,6 +1125,20 @@ void CefBrowserHostImpl::RenderViewReady() {
void CefBrowserHostImpl::RenderViewGone(base::TerminationStatus status) {
queue_messages_ = true;
cef_termination_status_t ts = TS_ABNORMAL_TERMINATION;
if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED)
ts = TS_PROCESS_WAS_KILLED;
else if (status == base::TERMINATION_STATUS_PROCESS_CRASHED)
ts = TS_PROCESS_CRASHED;
else if (status != base::TERMINATION_STATUS_ABNORMAL_TERMINATION)
return;
if (client_.get()) {
CefRefPtr<CefLoadHandler> handler = client_->GetLoadHandler();
if (handler.get())
handler->OnRenderProcessTerminated(this, ts);
}
}
void CefBrowserHostImpl::DidCommitProvisionalLoadForFrame(
@ -1179,6 +1193,14 @@ void CefBrowserHostImpl::DidFailLoad(int64 frame_id,
OnLoadEnd(frame, validated_url);
}
void CefBrowserHostImpl::PluginCrashed(const FilePath& plugin_path) {
if (client_.get()) {
CefRefPtr<CefLoadHandler> handler = client_->GetLoadHandler();
if (handler.get())
handler->OnPluginCrashed(this, plugin_path.value());
}
}
bool CefBrowserHostImpl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(CefBrowserHostImpl, message)

View File

@ -262,6 +262,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
bool is_main_frame,
int error_code,
const string16& error_description) OVERRIDE;
virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// Override to provide a thread safe implementation.
virtual bool Send(IPC::Message* message) OVERRIDE;

View File

@ -93,6 +93,48 @@ void CEF_CALLBACK load_handler_on_load_error(struct _cef_load_handler_t* self,
CefString(failedUrl));
}
void CEF_CALLBACK load_handler_on_render_process_terminated(
struct _cef_load_handler_t* self, cef_browser_t* browser,
enum cef_termination_status_t status) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Execute
CefLoadHandlerCppToC::Get(self)->OnRenderProcessTerminated(
CefBrowserCToCpp::Wrap(browser),
status);
}
void CEF_CALLBACK load_handler_on_plugin_crashed(
struct _cef_load_handler_t* self, cef_browser_t* browser,
const cef_string_t* plugin_path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Verify param: plugin_path; type: string_byref_const
DCHECK(plugin_path);
if (!plugin_path)
return;
// Execute
CefLoadHandlerCppToC::Get(self)->OnPluginCrashed(
CefBrowserCToCpp::Wrap(browser),
CefString(plugin_path));
}
// CONSTRUCTOR - Do not edit by hand.
@ -101,6 +143,9 @@ CefLoadHandlerCppToC::CefLoadHandlerCppToC(CefLoadHandler* cls)
struct_.struct_.on_load_start = load_handler_on_load_start;
struct_.struct_.on_load_end = load_handler_on_load_end;
struct_.struct_.on_load_error = load_handler_on_load_error;
struct_.struct_.on_render_process_terminated =
load_handler_on_render_process_terminated;
struct_.struct_.on_plugin_crashed = load_handler_on_plugin_crashed;
}
#ifndef NDEBUG

View File

@ -93,6 +93,46 @@ void CefLoadHandlerCToCpp::OnLoadError(CefRefPtr<CefBrowser> browser,
failedUrl.GetStruct());
}
void CefLoadHandlerCToCpp::OnRenderProcessTerminated(
CefRefPtr<CefBrowser> browser, TerminationStatus status) {
if (CEF_MEMBER_MISSING(struct_, on_render_process_terminated))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return;
// Execute
struct_->on_render_process_terminated(struct_,
CefBrowserCppToC::Wrap(browser),
status);
}
void CefLoadHandlerCToCpp::OnPluginCrashed(CefRefPtr<CefBrowser> browser,
const CefString& plugin_path) {
if (CEF_MEMBER_MISSING(struct_, on_plugin_crashed))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return;
// Verify param: plugin_path; type: string_byref_const
DCHECK(!plugin_path.empty());
if (plugin_path.empty())
return;
// Execute
struct_->on_plugin_crashed(struct_,
CefBrowserCppToC::Wrap(browser),
plugin_path.GetStruct());
}
#ifndef NDEBUG
template<> long CefCToCpp<CefLoadHandlerCToCpp, CefLoadHandler,

View File

@ -41,6 +41,10 @@ class CefLoadHandlerCToCpp
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, ErrorCode errorCode,
const CefString& errorText, const CefString& failedUrl) OVERRIDE;
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
TerminationStatus status) OVERRIDE;
virtual void OnPluginCrashed(CefRefPtr<CefBrowser> browser,
const CefString& plugin_path) OVERRIDE;
};
#endif // BUILDING_CEF_SHARED

View File

@ -3,6 +3,7 @@
// can be found in the LICENSE file.
#include "cefclient/client_handler.h"
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
@ -282,6 +283,18 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
frame->LoadString(ss.str(), failedUrl);
}
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
TerminationStatus status) {
// Load google.com if that's not the website that we terminated on.
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
std::string url = frame->GetURL();
std::transform(url.begin(), url.end(), url.begin(), tolower);
const char kLoadURL[] = "http://www.google.com";
if (url.find(kLoadURL) != 0)
frame->LoadURL(kLoadURL);
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,

View File

@ -149,6 +149,8 @@ class ClientHandler : public CefClient,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) OVERRIDE;
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
TerminationStatus status) OVERRIDE;
// CefRequestHandler methods
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(