-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindowClient.cpp
77 lines (63 loc) · 1.88 KB
/
WindowClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "WindowClient.h"
#include "include/base/cef_bind.h"
#include "include/wrapper/cef_closure_task.h"
WindowClient::WindowClient() {
}
WindowClient::~WindowClient() {
}
CefRefPtr<CefDisplayHandler> WindowClient::GetDisplayHandler() {
return this;
}
CefRefPtr<CefLifeSpanHandler> WindowClient::GetLifeSpanHandler() {
return this;
}
void WindowClient::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
browsers_.push_back(browser);
}
void WindowClient::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
for (BrowserList::iterator i = browsers_.begin(); i != browsers_.end(); ++i) {
if ((*i)->IsSame(browser)) {
browsers_.erase(i);
break;
}
}
if (browsers_.empty()) {
CefQuitMessageLoop();
}
}
bool WindowClient::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
int line
) {
return true;
}
bool WindowClient::OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message
) {
if (message->GetName() == "quit") {
s_result = message->GetArgumentList()->GetInt(0);
printf("Quitting with value %d\n", s_result);
printf("Log:\n%S", message->GetArgumentList()->GetString(1).ToWString().c_str());
CloseAllBrowsers();
} else {
printf("Unknown message %s\n", message->GetName().ToString().c_str());
}
return false;
}
void WindowClient::CloseAllBrowsers() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI,
base::Bind(&WindowClient::CloseAllBrowsers, this));
return;
}
if (browsers_.empty()) {
CefQuitMessageLoop();
}
for (BrowserList::const_iterator i = browsers_.begin(); i != browsers_.end(); ++i) {
(*i)->GetHost()->CloseBrowser(true);
}
}