Skip to content

Commit 8ceda28

Browse files
committed
Add setting "chrome.runtime_style" and improve main window logic.
By default runtime style is `alloy`. Alternative runtime style is `chrome` which provides more features and looks similar to native Chromium.
1 parent 1e9ca5b commit 8ceda28

File tree

6 files changed

+46
-28
lines changed

6 files changed

+46
-28
lines changed

cef/app.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include "client_handler.h"
1717
#include "../settings.h"
1818
#include "javascript_api.h"
19+
#include "../main_window.h"
20+
#include "../executable.h"
21+
22+
extern HINSTANCE g_hInstance; // main.cpp
1923

2024
// ----------------------------------------------------------------------------
2125
// CefRenderProcessHandler methods
@@ -58,7 +62,7 @@ void App::OnContextCreated(CefRefPtr<CefBrowser> browser,
5862
CefRefPtr<CefFrame> frame,
5963
CefRefPtr<CefV8Context> context) {
6064
// RENDERER PROCESS.
61-
LOGGER_DEBUG << "OnContextCreated()";
65+
LOGGER_DEBUG << "V8 context created";
6266
CefRefPtr<CefV8Value> window = context->GetGlobal();
6367
CefRefPtr<CefV8Handler> handler = GetJavascriptApi(browser);
6468
if (!handler.get()) {
@@ -174,7 +178,14 @@ void App::OnBeforeCommandLineProcessing(
174178
// has been initialized.
175179
///
176180
void App::OnContextInitialized() {
177-
REQUIRE_UI_THREAD();
178-
LOGGER_DEBUG << "App::OnContextInitialized()";
179-
}
181+
REQUIRE_UI_THREAD();
182+
LOGGER_DEBUG << "App context initialized";
180183

184+
// Create main window
185+
json_value* appSettings = GetApplicationSettings();
186+
std::string main_window_title = (*appSettings)["main_window"]["title"];
187+
if (main_window_title.empty()) {
188+
main_window_title = GetExecutableName();
189+
}
190+
CreateMainWindow(g_hInstance, SW_SHOWDEFAULT, main_window_title);
191+
}

cef/browser_window.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ BrowserWindow* GetBrowserWindow(HWND hwnd) {
5555
}
5656
// GetBrowserWindow() may fail during window creation, so log
5757
// severity is only DEBUG.
58-
LOGGER_DEBUG << "GetBrowserWindow(): not found, hwnd = " << (uintptr_t) hwnd;
58+
LOGGER_DEBUG << "Browser window not found, hwnd = " << (uintptr_t) hwnd;
5959
return NULL;
6060
}
6161
void StoreBrowserWindow(HWND hwnd, BrowserWindow* browser) {
62-
LOGGER_DEBUG << "StoreBrowserWindow(): hwnd = " << (uintptr_t) hwnd;
62+
LOGGER_DEBUG << "Store browser window, hwnd = " << (uintptr_t) 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-
LOGGER_WARNING << "StoreBrowserWindow() failed: already stored";
68+
LOGGER_WARNING << "Storing browser window failed: already stored";
6969
}
7070
}
7171
void RemoveBrowserWindow(HWND hwnd) {
@@ -147,20 +147,30 @@ void BrowserWindow::SetCefBrowser(CefRefPtr<CefBrowser> cefBrowser) {
147147
this->OnSize();
148148
}
149149
bool BrowserWindow::CreateBrowserControl(const wchar_t* navigateUrl) {
150-
LOGGER_DEBUG << "BrowserWindow::CreateBrowserControl()";
150+
LOGGER_DEBUG << "Create main browser";
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-
LOGGER_ERROR << "GetWindowRect() failed in "
158-
"BrowserWindow::CreateBrowserControl()";
157+
LOGGER_ERROR << "GetWindowRect() failed while creating browser";
159158
}
160159

161160
// Information used when creating the native window.
161+
json_value* settings = GetApplicationSettings();
162+
std::string runtime_style = (*settings)["chrome"]["runtime_style"];
162163
CefWindowInfo window_info;
163-
window_info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
164+
if (runtime_style == "alloy") {
165+
LOGGER_INFO << "Runtime style: alloy";
166+
window_info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
167+
} else if (runtime_style == "chrome") {
168+
LOGGER_INFO << "Runtime style: chrome";
169+
window_info.runtime_style = CEF_RUNTIME_STYLE_CHROME;
170+
} else {
171+
LOGGER_INFO << "Invalid runtime style in settings.json: " << runtime_style;
172+
window_info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
173+
}
164174
int width = rect.right - rect.left;
165175
int height = rect.bottom - rect.top;
166176
CefRect cef_rect(rect.left, rect.top, width, height);
@@ -169,7 +179,7 @@ bool BrowserWindow::CreateBrowserControl(const wchar_t* navigateUrl) {
169179
CefRefPtr<ClientHandler> handler(new ClientHandler());
170180
// Specify CEF browser settings here.
171181
CefBrowserSettings browser_settings;
172-
// Create the first browser window.
182+
// Create the first browser.
173183
CefBrowserHost::CreateBrowser(
174184
window_info, handler.get(),
175185
GetWebServerUrl(), browser_settings, nullptr, nullptr);

cef/client_handler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> cefBrowser,
126126
///
127127
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> cefBrowser) {
128128
REQUIRE_UI_THREAD();
129-
LOGGER_DEBUG << "ClientHandler::OnAfterCreated()";
129+
LOGGER_DEBUG << "Browser was created";
130130
json_value* appSettings = GetApplicationSettings();
131131
bool center_relative_to_parent = \
132132
(*appSettings)["popup_window"]["center_relative_to_parent"];
@@ -136,8 +136,7 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> cefBrowser) {
136136
// This block of code gets called for Main window & Devtools window.
137137
ASSERT(!phpBrowser->GetCefBrowser().get());
138138
if (!phpBrowser->GetCefBrowser().get()) {
139-
LOGGER_DEBUG << "SetCefBrowser() called in "
140-
"ClientHandler::OnAfterCreated()";
139+
LOGGER_DEBUG << "Set browser for window";
141140
phpBrowser->SetCefBrowser(cefBrowser);
142141
}
143142
} else {

main.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
8989
if (browser && browser->GetCefBrowser()) {
9090
browser->OnSize();
9191
} else if (!browser) {
92-
LOGGER_WARNING << "WindowProc() WM_SIZE: could not fetch BrowserWindow";
92+
LOGGER_WARNING << "Event WM_SIZE: could not fetch browser window";
9393
}
9494
break;
9595
case WM_MOVE:
@@ -99,7 +99,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
9999
if (browser && browser->GetCefBrowser()) {
100100
browser->GetCefBrowser()->GetHost()->NotifyMoveOrResizeStarted();
101101
} else if (!browser) {
102-
LOGGER_WARNING << "WindowProc() WM_MOVE: could not fetch BrowserWindow";
102+
LOGGER_WARNING << "Event WM_MOVE: could not fetch browser window";
103103
}
104104
return 0;
105105
case WM_CREATE:
@@ -142,8 +142,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
142142
} else {
143143
// GetMinMaxInfo may fail during window creation, so
144144
// log severity is only DEBUG.
145-
LOGGER_DEBUG << "WindowProc(): event WM_GETMINMAXINFO: "
146-
"could not fetch BrowserWindow";
145+
LOGGER_DEBUG << "Event WM_GETMINMAXINFO: could not fetch browser window";
147146
}
148147
break;
149148
case WM_SETFOCUS:
@@ -152,8 +151,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
152151
browser->SetFocus();
153152
return 0;
154153
} else {
155-
LOGGER_DEBUG << "WindowProc(): event WM_SETFOCUS: "
156-
"could not fetch BrowserWindow";
154+
LOGGER_DEBUG << "Event WM_SETFOCUS: could not fetch browser window";
157155
}
158156
break;
159157
case WM_ERASEBKGND:
@@ -298,11 +296,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
298296
LOGGER_INFO << "Log level = "
299297
<< FILELog::ToString(FILELog::ReportingLevel());
300298

301-
// Main window title option.
302-
std::string main_window_title = (*appSettings)["main_window"]["title"];
303-
if (main_window_title.empty())
304-
main_window_title = GetExecutableName();
305-
306299
// Single instance guid option.
307300
const char* single_instance_guid =
308301
(*appSettings)["application"]["single_instance_guid"];
@@ -394,7 +387,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
394387
#endif
395388

396389
CefInitialize(main_args, cef_settings, app.get(), sandbox_info);
397-
CreateMainWindow(hInstance, nCmdShow, main_window_title);
390+
LOGGER_DEBUG << "nCmdShow=" << nCmdShow;
398391
CefRunMessageLoop();
399392
CefShutdown();
400393

main_window.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// License: New BSD License.
33
// Website: http://code.google.com/p/phpdesktop/
44

5+
#include "logger.h"
56
#include "main_window.h"
67
#include "settings.h"
78
#include "dpi_aware.h"
@@ -11,7 +12,9 @@
1112

1213
extern wchar_t g_windowClassName[256]; // main.cpp
1314

14-
HWND CreateMainWindow(HINSTANCE hInstance, int nCmdShow, std::string title) {
15+
HWND CreateMainWindow(HINSTANCE hInstance, int nCmdShow, std::string title)
16+
{
17+
LOGGER_INFO << "Create main window";
1518
json_value* appSettings = GetApplicationSettings();
1619
int default_width = static_cast<long>((*appSettings)["main_window"]["default_size"][0]);
1720
int default_height = static_cast<long>((*appSettings)["main_window"]["default_size"][1]);
@@ -66,5 +69,6 @@ HWND CreateMainWindow(HINSTANCE hInstance, int nCmdShow, std::string title) {
6669
ShowWindow(hwnd, nCmdShow);
6770
}
6871
UpdateWindow(hwnd);
72+
LOGGER_INFO << "Main window was created, hwnd=" << (uintptr_t) hwnd;
6973
return hwnd;
7074
}

settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"reload_page_F5": true,
4949
"devtools_F12": true,
5050
"remote_debugging_port": 0,
51+
"runtime_style": "alloy",
5152
"command_line_switches": {"disable-gpu": ""},
5253
"enable_downloads": true,
5354
"context_menu": {

0 commit comments

Comments
 (0)