cefclient: Use test_runner::Alert instead of platform-specific notifications (issue #1500).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1984 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2015-01-22 21:39:36 +00:00
parent 1428f022af
commit af0635bb34
12 changed files with 65 additions and 195 deletions

View File

@ -37,6 +37,10 @@ ClientWindowHandle AppGetMainWindowHandle() {
return g_handler->GetMainWindowHandle();
}
std::string AppGetConsoleLogPath() {
return AppGetWorkingDirectory() + "console.log";
}
void AppInitCommandLine(int argc, const char* const* argv) {
g_command_line = CefCommandLine::CreateCommandLine();
#if defined(OS_WIN)

View File

@ -21,9 +21,12 @@ CefRefPtr<CefBrowser> AppGetBrowser();
// Returns the main application window handle.
ClientWindowHandle AppGetMainWindowHandle();
// Returns the application working directory.
// Returns the application working directory including trailing path separator.
std::string AppGetWorkingDirectory();
// Returns the full path to the console log file.
std::string AppGetConsoleLogPath();
// Initialize the application command line.
void AppInitCommandLine(int argc, const char* const* argv);

View File

@ -34,8 +34,6 @@ extern CefRefPtr<ClientHandler> g_handler;
namespace {
char szWorkingDir[512]; // The current working directory
// Height of the buttons at the top of the GTK window.
int g_toolbar_height = 0;
@ -334,9 +332,6 @@ int main(int argc, char* argv[]) {
if (exit_code >= 0)
return exit_code;
if (!getcwd(szWorkingDir, sizeof (szWorkingDir)))
return -1;
// Parse command line arguments.
AppInitCommandLine(argc, argv_copy);
@ -498,6 +493,15 @@ int main(int argc, char* argv[]) {
// Global functions
std::string AppGetWorkingDirectory() {
char szWorkingDir[256];
if (getcwd(szWorkingDir, sizeof(szWorkingDir) - 1) == NULL) {
szWorkingDir[0] = 0;
} else {
// Add trailing path separator.
size_t len = strlen(szWorkingDir);
szWorkingDir[len] = '/';
szWorkingDir[len + 1] = 0;
}
return szWorkingDir;
}

View File

@ -30,8 +30,6 @@ class MainBrowserProvider : public OSRBrowserProvider {
}
} g_main_browser_provider;
char szWorkingDir[512]; // The current working directory
// Sizes for URL bar layout
#define BUTTON_HEIGHT 22
#define BUTTON_WIDTH 72
@ -129,9 +127,6 @@ const int kWindowHeight = 600;
- (IBAction)stopLoading:(id)sender;
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender;
- (void)alert:(NSString*)title withMessage:(NSString*)message;
- (void)notifyConsoleMessage:(id)object;
- (void)notifyDownloadComplete:(id)object;
- (void)notifyDownloadError:(id)object;
@end
@implementation ClientWindowDelegate
@ -207,29 +202,6 @@ const int kWindowHeight = 600;
[alert runModal];
}
- (void)notifyConsoleMessage:(id)object {
std::stringstream ss;
ss << "Console messages will be written to " << g_handler->GetLogFile();
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
[self alert:@"Console Messages" withMessage:str];
}
- (void)notifyDownloadComplete:(id)object {
std::stringstream ss;
ss << "File \"" << g_handler->GetLastDownloadFile() <<
"\" downloaded successfully.";
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
[self alert:@"File Download" withMessage:str];
}
- (void)notifyDownloadError:(id)object {
std::stringstream ss;
ss << "File \"" << g_handler->GetLastDownloadFile() <<
"\" failed to download.";
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
[self alert:@"File Download" withMessage:str];
}
// Called when we are activated (when we gain focus).
- (void)windowDidBecomeKey:(NSNotification*)notification {
if (g_handler.get()) {
@ -517,9 +489,6 @@ int main(int argc, char* argv[]) {
if (exit_code >= 0)
return exit_code;
// Retrieve the current working directory.
getcwd(szWorkingDir, sizeof(szWorkingDir));
// Initialize the AutoRelease pool.
NSAutoreleasePool* autopool = [[NSAutoreleasePool alloc] init];
@ -575,6 +544,15 @@ int main(int argc, char* argv[]) {
// Global functions
std::string AppGetWorkingDirectory() {
char szWorkingDir[256];
if (getcwd(szWorkingDir, sizeof(szWorkingDir) - 1) == NULL) {
szWorkingDir[0] = 0;
} else {
// Add trailing path separator.
size_t len = strlen(szWorkingDir);
szWorkingDir[len] = '/';
szWorkingDir[len + 1] = 0;
}
return szWorkingDir;
}

View File

@ -51,7 +51,6 @@ HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
TCHAR szOSRWindowClass[MAX_LOADSTRING]; // the OSR window class name
char szWorkingDir[MAX_PATH]; // The current working directory
UINT uFindMsg; // Message identifier for find events.
HWND hFindDlg = NULL; // Handle for the find dialog.
@ -99,10 +98,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
if (exit_code >= 0)
return exit_code;
// Retrieve the current working directory.
if (_getcwd(szWorkingDir, MAX_PATH) == NULL)
szWorkingDir[0] = 0;
// Parse command line arguments. The passed in values are ignored on Windows.
AppInitCommandLine(0, NULL);
@ -214,46 +209,6 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {
return TRUE;
}
// Show a warning message on the UI thread.
static void ShowWarning(CefRefPtr<CefBrowser> browser, int id) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&ShowWarning, browser, id));
return;
}
if (!g_handler)
return;
std::wstring caption;
std::wstringstream message;
switch (id) {
case ID_WARN_CONSOLEMESSAGE:
caption = L"Console Messages";
message << L"Console messages will be written to " <<
std::wstring(CefString(g_handler->GetLogFile()));
break;
case ID_WARN_DOWNLOADCOMPLETE:
case ID_WARN_DOWNLOADERROR:
caption = L"File Download";
message << L"File \"" <<
std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
L"\" ";
if (id == ID_WARN_DOWNLOADCOMPLETE)
message << L"downloaded successfully.";
else
message << L"failed to download.";
break;
}
MessageBox(g_handler->GetMainWindowHandle(),
message.str().c_str(),
caption.c_str(),
MB_OK | MB_ICONINFORMATION);
}
// Set focus to |browser| on the UI thread.
static void SetFocusToBrowser(CefRefPtr<CefBrowser> browser) {
if (!CefCurrentlyOn(TID_UI)) {
@ -472,11 +427,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
if (g_handler.get())
g_handler->CloseAllBrowsers(false);
return 0;
case ID_WARN_CONSOLEMESSAGE:
case ID_WARN_DOWNLOADCOMPLETE:
case ID_WARN_DOWNLOADERROR:
ShowWarning(browser, wmId);
return 0;
case ID_FIND:
if (!hFindDlg) {
// Create the find dialog.
@ -682,6 +632,15 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
// Global functions
std::string AppGetWorkingDirectory() {
char szWorkingDir[MAX_PATH + 1];
if (_getcwd(szWorkingDir, MAX_PATH) == NULL) {
szWorkingDir[0] = 0;
} else {
// Add trailing path separator.
size_t len = strlen(szWorkingDir);
szWorkingDir[len] = '\\';
szWorkingDir[len + 1] = 0;
}
return szWorkingDir;
}

View File

@ -25,6 +25,12 @@
#include "cefclient/resource_util.h"
#include "cefclient/test_runner.h"
#if defined(OS_WIN)
#define NEWLINE "\r\n"
#else
#define NEWLINE "\n"
#endif
namespace {
// Custom menu command Ids.
@ -52,11 +58,15 @@ ClientHandler::ClientHandler()
forward_handle_(NULL),
stop_handle_(NULL),
reload_handle_(NULL),
console_log_file_(AppGetConsoleLogPath()),
first_console_message_(true),
focus_on_editable_field_(false) {
#if defined(OS_LINUX)
gtk_dialog_ = NULL;
#endif
DCHECK(!console_log_file_.empty());
// Read command line settings.
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
@ -166,36 +176,21 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
int line) {
CEF_REQUIRE_UI_THREAD();
bool first_message;
std::string logFile;
{
first_message = log_file_.empty();
if (first_message) {
std::stringstream ss;
ss << AppGetWorkingDirectory();
#if defined(OS_WIN)
ss << "\\";
#else
ss << "/";
#endif
ss << "console.log";
log_file_ = ss.str();
}
logFile = log_file_;
}
FILE* file = fopen(logFile.c_str(), "a");
FILE* file = fopen(console_log_file_.c_str(), "a");
if (file) {
std::stringstream ss;
ss << "Message: " << std::string(message) << "\r\nSource: " <<
std::string(source) << "\r\nLine: " << line <<
"\r\n-----------------------\r\n";
ss << "Message: " << message.ToString() << NEWLINE <<
"Source: " << source.ToString() << NEWLINE <<
"Line: " << line << NEWLINE <<
"-----------------------" << NEWLINE;
fputs(ss.str().c_str(), file);
fclose(file);
if (first_message)
SendNotification(NOTIFY_CONSOLE_MESSAGE);
if (first_console_message_) {
client::test_runner::Alert(
browser, "Console messages written to \"" + console_log_file_ + "\"");
first_console_message_ = false;
}
}
return false;
@ -219,8 +214,10 @@ void ClientHandler::OnDownloadUpdated(
CEF_REQUIRE_UI_THREAD();
if (download_item->IsComplete()) {
SetLastDownloadFile(download_item->GetFullPath());
SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
client::test_runner::Alert(
browser,
"File \"" + download_item->GetFullPath().ToString() +
"\" downloaded successfully.");
}
}
@ -699,21 +696,6 @@ bool ClientHandler::IsClosing() const {
return is_closing_;
}
std::string ClientHandler::GetLogFile() const {
CEF_REQUIRE_UI_THREAD();
return log_file_;
}
void ClientHandler::SetLastDownloadFile(const std::string& fileName) {
CEF_REQUIRE_UI_THREAD();
last_download_file_ = fileName;
}
std::string ClientHandler::GetLastDownloadFile() const {
CEF_REQUIRE_UI_THREAD();
return last_download_file_;
}
void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser,
const CefPoint& inspect_element_at) {
CefWindowInfo windowInfo;

View File

@ -271,20 +271,6 @@ class ClientHandler : public CefClient,
// 'onbeforeunload' JavaScript events during window close.
bool IsClosing() const;
std::string GetLogFile() const;
void SetLastDownloadFile(const std::string& fileName);
std::string GetLastDownloadFile() const;
// Send a notification to the application. Notifications should not block the
// caller.
enum NotificationType {
NOTIFY_CONSOLE_MESSAGE,
NOTIFY_DOWNLOAD_COMPLETE,
NOTIFY_DOWNLOAD_ERROR,
};
void SendNotification(NotificationType type);
void ShowDevTools(CefRefPtr<CefBrowser> browser,
const CefPoint& inspect_element_at);
void CloseDevTools(CefRefPtr<CefBrowser> browser);
@ -358,11 +344,9 @@ class ClientHandler : public CefClient,
// The handler for off-screen rendering, if any.
CefRefPtr<RenderHandler> osr_handler_;
// Support for logging.
std::string log_file_;
// Support for downloading files.
std::string last_download_file_;
// Used for console logging purposes.
const std::string console_log_file_;
bool first_console_message_;
// True if an editable field currently has focus.
bool focus_on_editable_field_;

View File

@ -456,10 +456,6 @@ void ClientHandler::OnDialogResponse(GtkDialog* dialog,
handler->OnResetDialogState(NULL);
}
void ClientHandler::SendNotification(NotificationType type) {
// TODO(port): Implement this method.
}
void ClientHandler::SetLoading(bool isLoading) {
CEF_REQUIRE_UI_THREAD();

View File

@ -35,28 +35,6 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
[window setTitle:str];
}
void ClientHandler::SendNotification(NotificationType type) {
SEL sel = nil;
switch(type) {
case NOTIFY_CONSOLE_MESSAGE:
sel = @selector(notifyConsoleMessage:);
break;
case NOTIFY_DOWNLOAD_COMPLETE:
sel = @selector(notifyDownloadComplete:);
break;
case NOTIFY_DOWNLOAD_ERROR:
sel = @selector(notifyDownloadError:);
break;
}
if (sel == nil)
return;
NSWindow* window = [AppGetMainWindowHandle() window];
NSObject* delegate = [window delegate];
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
}
void ClientHandler::SetLoading(bool isLoading) {
// TODO(port): Change button status.
}

View File

@ -35,24 +35,6 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
SetWindowText(hwnd, std::wstring(title).c_str());
}
void ClientHandler::SendNotification(NotificationType type) {
UINT id;
switch (type) {
case NOTIFY_CONSOLE_MESSAGE:
id = ID_WARN_CONSOLEMESSAGE;
break;
case NOTIFY_DOWNLOAD_COMPLETE:
id = ID_WARN_DOWNLOADCOMPLETE;
break;
case NOTIFY_DOWNLOAD_ERROR:
id = ID_WARN_DOWNLOADERROR;
break;
default:
return;
}
PostMessage(main_handle_, WM_COMMAND, id, 0);
}
void ClientHandler::SetLoading(bool isLoading) {
DCHECK(edit_handle_ != NULL && reload_handle_ != NULL &&
stop_handle_ != NULL);

View File

@ -12,6 +12,9 @@
std::string AppGetWorkingDirectory() {
return std::string();
}
std::string AppGetConsoleLogPath() {
return std::string();
}
std::string AppGetDownloadPath(const std::string& file_name) {
return std::string();
}

View File

@ -22,9 +22,6 @@
#define IDC_NAV_FORWARD 201
#define IDC_NAV_RELOAD 202
#define IDC_NAV_STOP 203
#define ID_WARN_CONSOLEMESSAGE 32000
#define ID_WARN_DOWNLOADCOMPLETE 32001
#define ID_WARN_DOWNLOADERROR 32002
#define ID_QUIT 32500
#define ID_FIND 32501
#define ID_TESTS_FIRST 32700