Skip to content

Commit d27e2f0

Browse files
committed
Fix compile errors.
Fix LOG macros. Fix CEF callbacks signatures. Fix CefFrame.LoadString. Fix windowInfo.bounds. Ignore warnings.
1 parent 8777c95 commit d27e2f0

22 files changed

+197
-172
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ php/extras/
2424
!php/!README.txt
2525
.vs/
2626
phpdeskt.*
27+
.vscode/

cef/app.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "include/cef_browser.h"
1414
#include "include/cef_command_line.h"
1515
#include "app.h"
16-
#include "../log.h"
16+
#include "../logger.h"
1717
#include "client_handler.h"
1818
#include "../settings.h"
1919
#include "javascript_api.h"
@@ -29,9 +29,10 @@
2929
///
3030
/*--cef()--*/
3131
bool App::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
32+
CefRefPtr<CefFrame> frame,
3233
CefProcessId source_process,
3334
CefRefPtr<CefProcessMessage> message) {
34-
LOG_DEBUG << "renderer[" << browser->GetIdentifier() << "] "
35+
LOGGER_DEBUG << "renderer[" << browser->GetIdentifier() << "] "
3536
<< "OnProcessMessageReceived: " << message->GetName().ToString();
3637
if (message->GetName() == "SetIsFullscreen") {
3738
CefRefPtr<CefListValue> args = message->GetArgumentList();
@@ -42,7 +43,7 @@ bool App::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
4243
}
4344
return true;
4445
}
45-
LOG_ERROR << "Unhandled message in OnProcessMessageReceived";
46+
LOGGER_ERROR << "Unhandled message in OnProcessMessageReceived";
4647
return false;
4748
}
4849

@@ -58,16 +59,16 @@ void App::OnContextCreated(CefRefPtr<CefBrowser> browser,
5859
CefRefPtr<CefFrame> frame,
5960
CefRefPtr<CefV8Context> context) {
6061
// RENDERER PROCESS.
61-
LOG_DEBUG << "OnContextCreated()";
62+
LOGGER_DEBUG << "OnContextCreated()";
6263
CefRefPtr<CefV8Value> window = context->GetGlobal();
6364
CefRefPtr<CefV8Handler> handler = GetJavascriptApi(browser);
6465
if (!handler.get()) {
65-
LOG_ERROR << "GetJavascriptApi() failed in OnContextCreated()";
66+
LOGGER_ERROR << "GetJavascriptApi() failed in OnContextCreated()";
6667
return;
6768
}
6869
// Javascipt bindings.
6970
// The phpdesktop object.
70-
CefRefPtr<CefV8Value> phpdesktop = CefV8Value::CreateObject(NULL, NULL);
71+
CefRefPtr<CefV8Value> phpdesktop = CefV8Value::CreateObject(nullptr, nullptr);
7172
window->SetValue("phpdesktop", phpdesktop, V8_PROPERTY_ATTRIBUTE_READONLY);
7273
// Methods.
7374
const char* methods[] = {
@@ -90,8 +91,8 @@ void App::OnContextCreated(CefRefPtr<CefBrowser> browser,
9091
// destroyed.
9192
///
9293
/*--cef()--*/
93-
void App::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
94-
LOG_DEBUG << "OnBrowserCreated()";
94+
void App::OnBrowserCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDictionaryValue> extra_info) {
95+
LOGGER_DEBUG << "OnBrowserCreated()";
9596
StoreJavascriptApi(browser, new JavascriptApi(browser));
9697
}
9798

@@ -100,7 +101,7 @@ void App::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
100101
///
101102
/*--cef()--*/
102103
void App::OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) {
103-
LOG_DEBUG << "OnBrowserDestroyed()";
104+
LOGGER_DEBUG << "OnBrowserDestroyed()";
104105
RemoveJavascriptApi(browser);
105106
}
106107

@@ -134,7 +135,7 @@ void App::OnBeforeCommandLineProcessing(
134135
std::string name = switches.u.object.values[i].name;
135136
std::string value = static_cast<const char*>(*switches.u.object.values[i].value);
136137
if (name.find("-") == 0) {
137-
LOG_WARNING << "Invalid command line switch: " << name;
138+
LOGGER_WARNING << "Invalid command line switch: " << name;
138139
continue;
139140
}
140141
if (command_line->HasSwitch(name)) {
@@ -161,8 +162,8 @@ void App::OnBeforeCommandLineProcessing(
161162
if (!process_type.empty()) {
162163
process_name = process_type;
163164
}
164-
LOG_DEBUG << "Command line string for the " << process_name << " process: "
165-
<< command_line->GetCommandLineString().ToString();
165+
LOGGER_DEBUG << "Command line string for the " << process_name << " process: "
166+
<< command_line->GetCommandLineString().ToString();
166167
}
167168

168169
// ----------------------------------------------------------------------------
@@ -175,6 +176,6 @@ void App::OnBeforeCommandLineProcessing(
175176
///
176177
void App::OnContextInitialized() {
177178
REQUIRE_UI_THREAD();
178-
LOG_DEBUG << "App::OnContextInitialized()";
179+
LOGGER_DEBUG << "App::OnContextInitialized()";
179180
}
180181

cef/app.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#include "include/cef_app.h"
99
#include <map>
1010
#include "javascript_api.h"
11-
#include "../log.h"
11+
#include "../logger.h"
1212

1313
class App : public CefApp,
1414
public CefBrowserProcessHandler,
1515
public CefRenderProcessHandler {
1616
public:
17-
App(){}
17+
App() noexcept {}
1818

1919
// CefApp methods:
2020
virtual void OnBeforeCommandLineProcessing(
@@ -32,13 +32,15 @@ class App : public CefApp,
3232

3333
// CefRenderProcessHandler methods:
3434
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
35+
CefRefPtr<CefFrame> frame,
3536
CefProcessId source_process,
3637
CefRefPtr<CefProcessMessage> message)
3738
override;
3839
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
3940
CefRefPtr<CefFrame> frame,
4041
CefRefPtr<CefV8Context> context) override;
41-
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) override;
42+
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser,
43+
CefRefPtr<CefDictionaryValue> extra_info) override;
4244
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override;
4345

4446
protected:
@@ -50,8 +52,8 @@ class App : public CefApp,
5052
if (it != javascriptApiMap_.end()) {
5153
return it->second;
5254
}
53-
LOG_ERROR << "GetJavascriptApi() failed, api not found";
54-
return NULL;
55+
LOGGER_ERROR << "GetJavascriptApi() failed, api not found";
56+
return nullptr;
5557
}
5658
void StoreJavascriptApi(CefRefPtr<CefBrowser> browser,
5759
CefRefPtr<JavascriptApi> javascriptApi) {
@@ -60,7 +62,7 @@ class App : public CefApp,
6062
if (it == javascriptApiMap_.end()) {
6163
javascriptApiMap_[browser->GetIdentifier()] = javascriptApi;
6264
} else {
63-
LOG_ERROR << "StoreJavascriptApi() failed, api already exists";
65+
LOGGER_ERROR << "StoreJavascriptApi() failed, api already exists";
6466
}
6567
}
6668
void RemoveJavascriptApi(CefRefPtr<CefBrowser> browser) {
@@ -69,7 +71,7 @@ class App : public CefApp,
6971
if (it != javascriptApiMap_.end()) {
7072
javascriptApiMap_.erase(it);
7173
} else {
72-
LOG_ERROR << "RemoveJavascriptApi() failed, api not found";
74+
LOGGER_ERROR << "RemoveJavascriptApi() failed, api not found";
7375
}
7476
}
7577

cef/browser_window.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string>
99

1010
#include "../executable.h"
11-
#include "../log.h"
11+
#include "../logger.h"
1212
#include "../settings.h"
1313
#include "../string_utils.h"
1414
#include "../fatal_error.h"
@@ -55,24 +55,24 @@ BrowserWindow* GetBrowserWindow(HWND hwnd) {
5555
}
5656
// GetBrowserWindow() may fail during window creation, so log
5757
// severity is only DEBUG.
58-
LOG_DEBUG << "GetBrowserWindow(): not found, hwnd = " << (int)hwnd;
58+
LOGGER_DEBUG << "GetBrowserWindow(): not found, hwnd = " << (char*)hwnd;
5959
return NULL;
6060
}
6161
void StoreBrowserWindow(HWND hwnd, BrowserWindow* browser) {
62-
LOG_DEBUG << "StoreBrowserWindow(): hwnd = " << (int)hwnd;
62+
LOGGER_DEBUG << "StoreBrowserWindow(): hwnd = " << (char*)hwnd;
6363
std::map<HWND, BrowserWindow*>::iterator it;
6464
it = g_browserWindows.find(hwnd);
6565
if (it == g_browserWindows.end()) {
6666
g_browserWindows[hwnd] = browser;
6767
} else {
68-
LOG_WARNING << "StoreBrowserWindow() failed: already stored";
68+
LOGGER_WARNING << "StoreBrowserWindow() failed: already stored";
6969
}
7070
}
7171
void RemoveBrowserWindow(HWND hwnd) {
72-
LOG_DEBUG << "RemoveBrowserWindow(): hwnd = " << (int)hwnd;
72+
LOGGER_DEBUG << "RemoveBrowserWindow(): hwnd = " << (char*)hwnd;
7373
BrowserWindow* browser = GetBrowserWindow(hwnd);
7474
if (!browser) {
75-
LOG_WARNING << "RemoveBrowserWindow() failed: "
75+
LOGGER_WARNING << "RemoveBrowserWindow() failed: "
7676
<< "GetBrowserWindow() failed";
7777
return;
7878
}
@@ -83,28 +83,28 @@ void RemoveBrowserWindow(HWND hwnd) {
8383
g_browserWindows.erase(it);
8484
delete browser;
8585
} else {
86-
LOG_WARNING << "RemoveBrowserWindow() failed: not found";
86+
LOGGER_WARNING << "RemoveBrowserWindow() failed: not found";
8787
}
8888
}
8989

90-
int CountBrowserWindows()
90+
size_t CountBrowserWindows()
9191
{
9292
return g_browserWindows.size();
9393
}
9494

9595
BrowserWindow::BrowserWindow(HWND inWindowHandle, bool isPopup)
9696
: windowHandle_(inWindowHandle),
9797
isPopup_(isPopup),
98-
cefBrowser_(NULL),
99-
fullscreen_(NULL)
98+
cefBrowser_(nullptr),
99+
fullscreen_(nullptr)
100100
{
101101
_ASSERT(windowHandle_);
102102

103103
SetTitleFromSettings();
104104
SetIconFromSettings();
105105

106106
if (IsPopup()) {
107-
LOG_DEBUG << "BrowserWindow::BrowserWindow() created for Popup";
107+
LOGGER_DEBUG << "BrowserWindow::BrowserWindow() created for Popup";
108108
} else {
109109
if (!CreateBrowserControl(Utf8ToWide(GetWebServerUrl()).c_str())) {
110110
FatalError(windowHandle_, "Could not create Browser control.\n"
@@ -124,7 +124,7 @@ void BrowserWindow::SetCefBrowser(CefRefPtr<CefBrowser> cefBrowser) {
124124
// Called from ClientHandler::OnAfterCreated().
125125
_ASSERT(!cefBrowser_);
126126
if (cefBrowser_) {
127-
LOG_ERROR << "BrowserWindow::SetCefBrowser() called, "
127+
LOGGER_ERROR << "BrowserWindow::SetCefBrowser() called, "
128128
<< "but it is already set";
129129
return;
130130
}
@@ -138,7 +138,7 @@ void BrowserWindow::SetCefBrowser(CefRefPtr<CefBrowser> cefBrowser) {
138138
CefRefPtr<CefProcessMessage> message = \
139139
CefProcessMessage::Create("SetIsFullscreen");
140140
message->GetArgumentList()->SetBool(0, fullscreen_->IsFullscreen());
141-
cefBrowser->SendProcessMessage(PID_RENDERER, message);
141+
cefBrowser->GetMainFrame()->SendProcessMessage(PID_RENDERER, message);
142142
}
143143
}
144144

@@ -147,28 +147,31 @@ void BrowserWindow::SetCefBrowser(CefRefPtr<CefBrowser> cefBrowser) {
147147
this->OnSize();
148148
}
149149
bool BrowserWindow::CreateBrowserControl(const wchar_t* navigateUrl) {
150-
LOG_DEBUG << "BrowserWindow::CreateBrowserControl()";
150+
LOGGER_DEBUG << "BrowserWindow::CreateBrowserControl()";
151151
// This is called only for the main window.
152152
// Popup cef browsers are created internally by CEF,
153153
// see OnBeforePopup, OnAfterCreated.
154154
RECT rect;
155155
BOOL b = GetWindowRect(windowHandle_, &rect);
156156
if (!b) {
157-
LOG_ERROR << "GetWindowRect() failed in "
157+
LOGGER_ERROR << "GetWindowRect() failed in "
158158
"BrowserWindow::CreateBrowserControl()";
159159
}
160160

161161
// Information used when creating the native window.
162162
CefWindowInfo window_info;
163-
window_info.SetAsChild(windowHandle_, rect);
163+
int width = rect.right - rect.left;
164+
int height = rect.bottom - rect.top;
165+
CefRect cef_rect(rect.left, rect.top, width, height);
166+
window_info.SetAsChild(windowHandle_, cef_rect);
164167
// SimpleHandler implements browser-level callbacks.
165168
CefRefPtr<ClientHandler> handler(new ClientHandler());
166169
// Specify CEF browser settings here.
167170
CefBrowserSettings browser_settings;
168171
// Create the first browser window.
169172
CefBrowserHost::CreateBrowser(
170173
window_info, handler.get(),
171-
GetWebServerUrl(), browser_settings, NULL);
174+
GetWebServerUrl(), browser_settings, nullptr, nullptr);
172175

173176
return true;
174177
}
@@ -227,7 +230,7 @@ void BrowserWindow::OnSize() {
227230
SWP_NOZORDER);
228231
EndDeferWindowPos(hdwp);
229232
} else {
230-
LOG_DEBUG << "BrowserWindow::OnSize(): "
233+
LOGGER_DEBUG << "BrowserWindow::OnSize(): "
231234
"CefBrowser object not yet created";
232235
}
233236
}
@@ -260,7 +263,7 @@ void BrowserWindow::SetIconFromSettings() {
260263
if (bigIcon) {
261264
SendMessage(windowHandle_, WM_SETICON, ICON_BIG, (LPARAM)bigIcon);
262265
} else {
263-
LOG_WARNING << "Setting icon from settings file failed "
266+
LOGGER_WARNING << "Setting icon from settings file failed "
264267
"(ICON_BIG)";
265268
}
266269
int smallX = GetSystemMetrics(SM_CXSMICON);
@@ -270,7 +273,7 @@ void BrowserWindow::SetIconFromSettings() {
270273
if (smallIcon) {
271274
SendMessage(windowHandle_, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon);
272275
} else {
273-
LOG_WARNING << "Setting icon from settings file failed "
276+
LOGGER_WARNING << "Setting icon from settings file failed "
274277
"(ICON_SMALL)";
275278
}
276279
} else if (IsPopup()) {
@@ -280,7 +283,7 @@ void BrowserWindow::SetIconFromSettings() {
280283
if (smallIcon) {
281284
SendMessage(windowHandle_, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon);
282285
} else {
283-
LOG_WARNING << "LoadIcon(IDR_MAINWINDOW) failed "
286+
LOGGER_WARNING << "LoadIcon(IDR_MAINWINDOW) failed "
284287
<< "in BrowserWindow::SetIconFromSettings()";
285288
}
286289
}

cef/browser_window.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@ class BrowserWindow;
1717
BrowserWindow* GetBrowserWindow(HWND hwnd);
1818
void StoreBrowserWindow(HWND hwnd, BrowserWindow* browser);
1919
void RemoveBrowserWindow(HWND hwnd);
20-
int CountBrowserWindows();
20+
size_t CountBrowserWindows();
2121

2222
class BrowserWindow {
2323
private:
2424
HWND windowHandle_;
2525
bool isPopup_;
2626
CefRefPtr<CefBrowser> cefBrowser_; // may be empty, always check using .get()
27-
std::tr1::shared_ptr<Fullscreen> fullscreen_; // may be empty
27+
std::shared_ptr<Fullscreen> fullscreen_; // may be empty
2828
public:
2929
BrowserWindow(HWND inWindowHandle, bool isPopup);
3030
~BrowserWindow();
3131
CefRefPtr<CefBrowser> GetCefBrowser();
3232
void SetCefBrowser(CefRefPtr<CefBrowser> cefBrowser);
3333
bool CreateBrowserControl(const wchar_t* navigateUrl);
34-
void CloseBrowserControl();
3534
HWND GetWindowHandle();
3635
void SetTitle(const wchar_t* title);
3736
bool IsPopup();

0 commit comments

Comments
 (0)