mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-23 23:47:43 +01:00
- Add CefHandler::HandleConsoleMessage callback for handling console messages (issue #90).
- Normalize newlines in browser_webkit_init.h. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@84 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
2799fccb7d
commit
de4cee4415
@ -630,6 +630,13 @@ public:
|
|||||||
int code,
|
int code,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
bool isSystemKey) =0;
|
bool isSystemKey) =0;
|
||||||
|
|
||||||
|
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||||
|
// from being output to the console.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||||
|
const std::wstring& message,
|
||||||
|
const std::wstring& source, int line) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -489,6 +489,12 @@ typedef struct _cef_handler_t
|
|||||||
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);
|
||||||
|
|
||||||
|
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||||
|
// from being output to the console.
|
||||||
|
enum cef_retval_t (CEF_CALLBACK *handle_console_message)(
|
||||||
|
struct _cef_handler_t* self, struct _cef_browser_t* browser,
|
||||||
|
const wchar_t* message, const wchar_t* source, int line);
|
||||||
|
|
||||||
} cef_handler_t;
|
} cef_handler_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,8 +93,8 @@ class BrowserWebKitInit : public webkit_glue::WebKitClientImpl {
|
|||||||
return &clipboard_;
|
return &clipboard_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual WebKit::WebFileSystem* fileSystem() {
|
virtual WebKit::WebFileSystem* fileSystem() {
|
||||||
return &file_system_;
|
return &file_system_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual WebKit::WebSandboxSupport* sandboxSupport() {
|
virtual WebKit::WebSandboxSupport* sandboxSupport() {
|
||||||
@ -178,8 +178,8 @@ class BrowserWebKitInit : public webkit_glue::WebKitClientImpl {
|
|||||||
WebKit::WebStorageNamespace::m_localStorageQuota);
|
WebKit::WebStorageNamespace::m_localStorageQuota);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual WebKit::WebIndexedDatabase* indexedDatabase() {
|
virtual WebKit::WebIndexedDatabase* indexedDatabase() {
|
||||||
return WebKit::WebIndexedDatabase::create();
|
return WebKit::WebIndexedDatabase::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -164,6 +164,17 @@ WebStorageNamespace* BrowserWebViewDelegate::createSessionStorageNamespace(
|
|||||||
void BrowserWebViewDelegate::didAddMessageToConsole(
|
void BrowserWebViewDelegate::didAddMessageToConsole(
|
||||||
const WebConsoleMessage& message, const WebString& source_name,
|
const WebConsoleMessage& message, const WebString& source_name,
|
||||||
unsigned source_line) {
|
unsigned source_line) {
|
||||||
|
std::wstring wmessage = UTF16ToWideHack(message.text);
|
||||||
|
std::wstring wsource = UTF16ToWideHack(source_name);
|
||||||
|
|
||||||
|
CefHandler::RetVal rv = RV_CONTINUE;
|
||||||
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||||
|
if(handler.get()) {
|
||||||
|
rv = handler->HandleConsoleMessage(browser_, wmessage, wsource,
|
||||||
|
source_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rv == RV_CONTINUE) {
|
||||||
logging::LogMessage("CONSOLE", 0).stream() << "\""
|
logging::LogMessage("CONSOLE", 0).stream() << "\""
|
||||||
<< message.text.utf8().data()
|
<< message.text.utf8().data()
|
||||||
<< ",\" source: "
|
<< ",\" source: "
|
||||||
@ -171,6 +182,7 @@ void BrowserWebViewDelegate::didAddMessageToConsole(
|
|||||||
<< "("
|
<< "("
|
||||||
<< source_line
|
<< source_line
|
||||||
<< ")";
|
<< ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWebViewDelegate::didStartLoading() {
|
void BrowserWebViewDelegate::didStartLoading() {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "libcef_dll/ctocpp/frame_ctocpp.h"
|
#include "libcef_dll/ctocpp/frame_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/stream_reader_ctocpp.h"
|
#include "libcef_dll/ctocpp/stream_reader_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
|
|
||||||
#include "libcef_dll/transfer_util.h"
|
#include "libcef_dll/transfer_util.h"
|
||||||
|
|
||||||
|
|
||||||
@ -458,6 +457,25 @@ enum cef_retval_t CEF_CALLBACK handler_handle_key_event(
|
|||||||
modifiers, isSystemKey?true:false);
|
modifiers, isSystemKey?true:false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum cef_retval_t CEF_CALLBACK handler_handle_console_message(
|
||||||
|
struct _cef_handler_t* self, cef_browser_t* browser, const wchar_t* message,
|
||||||
|
const wchar_t* source, int line)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(browser);
|
||||||
|
if(!self || !browser)
|
||||||
|
return RV_CONTINUE;
|
||||||
|
|
||||||
|
std::wstring messageStr, sourceStr;
|
||||||
|
if(message)
|
||||||
|
messageStr = message;
|
||||||
|
if(source)
|
||||||
|
sourceStr = source;
|
||||||
|
|
||||||
|
return CefHandlerCppToC::Get(self)->HandleConsoleMessage(
|
||||||
|
CefBrowserCToCpp::Wrap(browser), messageStr, sourceStr, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
@ -487,6 +505,7 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
|
|||||||
struct_.struct_.handle_take_focus = handler_handle_take_focus;
|
struct_.struct_.handle_take_focus = handler_handle_take_focus;
|
||||||
struct_.struct_.handle_set_focus = handler_handle_set_focus;
|
struct_.struct_.handle_set_focus = handler_handle_set_focus;
|
||||||
struct_.struct_.handle_key_event = handler_handle_key_event;
|
struct_.struct_.handle_key_event = handler_handle_key_event;
|
||||||
|
struct_.struct_.handle_console_message = handler_handle_console_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include "libcef_dll/cpptoc/frame_cpptoc.h"
|
#include "libcef_dll/cpptoc/frame_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/stream_reader_cpptoc.h"
|
#include "libcef_dll/cpptoc/stream_reader_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
|
|
||||||
#include "libcef_dll/ctocpp/handler_ctocpp.h"
|
#include "libcef_dll/ctocpp/handler_ctocpp.h"
|
||||||
#include "libcef_dll/transfer_util.h"
|
#include "libcef_dll/transfer_util.h"
|
||||||
|
|
||||||
@ -349,6 +348,17 @@ CefHandler::RetVal CefHandlerCToCpp::HandleKeyEvent(
|
|||||||
type, code, modifiers, isSystemKey);
|
type, code, modifiers, isSystemKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefHandler::RetVal CefHandlerCToCpp::HandleConsoleMessage(
|
||||||
|
CefRefPtr<CefBrowser> browser, const std::wstring& message,
|
||||||
|
const std::wstring& source, int line)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, handle_console_message))
|
||||||
|
return RV_CONTINUE;
|
||||||
|
|
||||||
|
return struct_->handle_console_message(struct_,
|
||||||
|
CefBrowserCppToC::Wrap(browser), message.c_str(), source.c_str(), line);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
long CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>::DebugObjCt = 0;
|
long CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>::DebugObjCt = 0;
|
||||||
|
@ -76,6 +76,8 @@ public:
|
|||||||
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, bool isWidget);
|
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, bool isWidget);
|
||||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||||
KeyEventType type, int code, int modifiers, bool isSystemKey);
|
KeyEventType type, int code, int modifiers, bool isSystemKey);
|
||||||
|
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||||
|
const std::wstring& message, const std::wstring& source, int line);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BUILDING_CEF_SHARED
|
#endif // BUILDING_CEF_SHARED
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
HINSTANCE hInst; // current instance
|
HINSTANCE hInst; // current instance
|
||||||
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
||||||
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
|
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
|
||||||
|
TCHAR szWorkingDir[MAX_PATH]; // The current working directory
|
||||||
|
|
||||||
// Forward declarations of functions included in this code module:
|
// Forward declarations of functions included in this code module:
|
||||||
ATOM MyRegisterClass(HINSTANCE hInstance);
|
ATOM MyRegisterClass(HINSTANCE hInstance);
|
||||||
@ -44,6 +45,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
|||||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||||
|
|
||||||
|
// Retrieve the current working directory.
|
||||||
|
if(_wgetcwd(szWorkingDir, MAX_PATH) == NULL)
|
||||||
|
szWorkingDir[0] = 0;
|
||||||
|
|
||||||
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||||
// Initialize the CEF with messages processed using the current application's
|
// Initialize the CEF with messages processed using the current application's
|
||||||
// message loop.
|
// message loop.
|
||||||
@ -522,6 +527,41 @@ public:
|
|||||||
return RV_CONTINUE;
|
return RV_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||||
|
// from being output to the console.
|
||||||
|
RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||||
|
const std::wstring& message,
|
||||||
|
const std::wstring& source, int line)
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
bool first_message = m_LogFile.empty();
|
||||||
|
if(first_message) {
|
||||||
|
std::wstringstream ss;
|
||||||
|
ss << szWorkingDir << L"\\console.log";
|
||||||
|
m_LogFile = ss.str();
|
||||||
|
}
|
||||||
|
std::wstring logFile = m_LogFile;
|
||||||
|
Unlock();
|
||||||
|
|
||||||
|
FILE* file = NULL;
|
||||||
|
_wfopen_s(&file, logFile.c_str(), L"a, ccs=UTF-8");
|
||||||
|
|
||||||
|
if(file) {
|
||||||
|
std::wstringstream ss;
|
||||||
|
ss << L"Message: " << message << L"\r\nSource: " << source <<
|
||||||
|
L"\r\nLine: " << line << L"\r\n-----------------------\r\n";
|
||||||
|
fputws(ss.str().c_str(), file);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
if(first_message) {
|
||||||
|
// Show the message box on the UI thread.
|
||||||
|
PostMessage(m_MainHwnd, WM_COMMAND, ID_WARN_CONSOLEMESSAGE, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RV_HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the current navigation state flags
|
// Retrieve the current navigation state flags
|
||||||
void GetNavState(bool &isLoading, bool &canGoBack, bool &canGoForward)
|
void GetNavState(bool &isLoading, bool &canGoBack, bool &canGoForward)
|
||||||
{
|
{
|
||||||
@ -557,6 +597,14 @@ public:
|
|||||||
return m_BrowserHwnd;
|
return m_BrowserHwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wstring GetLogFile()
|
||||||
|
{
|
||||||
|
Lock();
|
||||||
|
std::wstring str = m_LogFile;
|
||||||
|
Unlock();
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// The child browser window
|
// The child browser window
|
||||||
CefRefPtr<CefBrowser> m_Browser;
|
CefRefPtr<CefBrowser> m_Browser;
|
||||||
@ -576,6 +624,8 @@ protected:
|
|||||||
bool m_bCanGoBack;
|
bool m_bCanGoBack;
|
||||||
// True if the user can navigate forwards
|
// True if the user can navigate forwards
|
||||||
bool m_bCanGoForward;
|
bool m_bCanGoForward;
|
||||||
|
|
||||||
|
std::wstring m_LogFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
// global handler instance
|
// global handler instance
|
||||||
@ -765,6 +815,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case IDM_EXIT:
|
case IDM_EXIT:
|
||||||
DestroyWindow(hWnd);
|
DestroyWindow(hWnd);
|
||||||
return 0;
|
return 0;
|
||||||
|
case ID_WARN_CONSOLEMESSAGE:
|
||||||
|
if(g_handler.get()) {
|
||||||
|
std::wstringstream ss;
|
||||||
|
ss << L"Console messages will be written to "
|
||||||
|
<< g_handler->GetLogFile();
|
||||||
|
MessageBoxW(hWnd, ss.str().c_str(), L"Console Messages",
|
||||||
|
MB_OK | MB_ICONINFORMATION);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
case IDC_NAV_BACK: // Back button
|
case IDC_NAV_BACK: // Back button
|
||||||
if(browser.get())
|
if(browser.get())
|
||||||
browser->GoBack();
|
browser->GoBack();
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define IDC_NAV_FORWARD 201
|
#define IDC_NAV_FORWARD 201
|
||||||
#define IDC_NAV_RELOAD 202
|
#define IDC_NAV_RELOAD 202
|
||||||
#define IDC_NAV_STOP 203
|
#define IDC_NAV_STOP 203
|
||||||
|
#define ID_WARN_CONSOLEMESSAGE 32000
|
||||||
#define ID_TESTS_GETSOURCE 32769
|
#define ID_TESTS_GETSOURCE 32769
|
||||||
#define ID_TESTS_GETTEXT 32770
|
#define ID_TESTS_GETTEXT 32770
|
||||||
#define ID_TESTS_JAVASCRIPT_HANDLER 32771
|
#define ID_TESTS_JAVASCRIPT_HANDLER 32771
|
||||||
|
@ -202,6 +202,13 @@ public:
|
|||||||
return RV_CONTINUE;
|
return RV_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||||
|
const std::wstring& message,
|
||||||
|
const std::wstring& source, int line)
|
||||||
|
{
|
||||||
|
return RV_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
CefRefPtr<CefBrowser> GetBrowser()
|
CefRefPtr<CefBrowser> GetBrowser()
|
||||||
{
|
{
|
||||||
return browser_;
|
return browser_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user