X Tutup
Skip to content

Commit 4f7eb5d

Browse files
committed
Updated CEF Python to CEF branch 1650 revision 1646 on Windows.
Added High DPI support on Windows. See the wxpython example. See ApplicationSettings.auto_zooming. See the DpiAware wiki page. See also: Issue 112, Issue 128. Exposed API for posting tasks on various Browser process threads. See [cefpython].`PostTask()`. See Issue 61. Fixed problems with loading file protocol urls on Windows. Updated examples on Windows. Updated LICENSE files. Fixed compiler warnings (win) in javascript dialog handler.
1 parent e3dfa6a commit 4f7eb5d

40 files changed

+2054
-572
lines changed

cefpython/cef3/LOG_DEBUG.h

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// Taken from here: http://www.drdobbs.com/cpp/logging-in-c/201804215
2+
// Original author: Petru Marginean <petru.marginean@gmail.com>
3+
// Modified by: Czarek Tomczak <czarek.tomczak@gmail.com>
4+
5+
// Usage:
6+
// LOG_DEBUG << "Browser: someVar = " << someVar;
7+
// Warning:
8+
// Log is written when ~Log() destructor is called, which
9+
// occurs when outside of scope. This could result in log
10+
// not being written if program crashes before code goes
11+
// outside of current scope. You could embrace LOG_DEBUG
12+
// statements with braces {} to guarantee the log to be
13+
// written immediately.
14+
15+
#ifndef __LOG_H__
16+
#define __LOG_H__
17+
18+
#include <sstream>
19+
#include <string>
20+
#include <stdio.h>
21+
#include "DebugLog.h"
22+
23+
inline std::string NowTime();
24+
25+
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG,
26+
logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
27+
28+
template <typename T>
29+
class Log
30+
{
31+
public:
32+
Log();
33+
virtual ~Log();
34+
std::ostringstream& Get(TLogLevel level = logINFO);
35+
public:
36+
static TLogLevel& ReportingLevel();
37+
static std::string ToString(TLogLevel level);
38+
static TLogLevel FromString(const std::string& level);
39+
protected:
40+
std::ostringstream os;
41+
private:
42+
Log(const Log&);
43+
Log& operator =(const Log&);
44+
};
45+
46+
template <typename T>
47+
Log<T>::Log()
48+
{
49+
}
50+
51+
template <typename T>
52+
std::ostringstream& Log<T>::Get(TLogLevel level)
53+
{
54+
// os << "- " << NowTime();
55+
// os << " " << ToString(level) << ": ";
56+
// os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
57+
return os;
58+
}
59+
60+
template <typename T>
61+
Log<T>::~Log()
62+
{
63+
os << std::endl;
64+
/*
65+
if (T::Stream() != stderr) {
66+
fprintf(stderr, "%s", os.str().c_str());
67+
fflush(stderr);
68+
}
69+
T::Output(os.str());
70+
*/
71+
DebugLog(os.str().c_str());
72+
}
73+
74+
template <typename T>
75+
TLogLevel& Log<T>::ReportingLevel()
76+
{
77+
static TLogLevel reportingLevel = logDEBUG4;
78+
return reportingLevel;
79+
}
80+
81+
template <typename T>
82+
std::string Log<T>::ToString(TLogLevel level)
83+
{
84+
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG",
85+
"DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"};
86+
return buffer[level];
87+
}
88+
89+
template <typename T>
90+
TLogLevel Log<T>::FromString(const std::string& level)
91+
{
92+
if (level == "DEBUG4")
93+
return logDEBUG4;
94+
if (level == "DEBUG3")
95+
return logDEBUG3;
96+
if (level == "DEBUG2")
97+
return logDEBUG2;
98+
if (level == "DEBUG1")
99+
return logDEBUG1;
100+
if (level == "DEBUG")
101+
return logDEBUG;
102+
if (level == "INFO")
103+
return logINFO;
104+
if (level == "WARNING")
105+
return logWARNING;
106+
if (level == "ERROR")
107+
return logERROR;
108+
Log<T>().Get(logWARNING) << "Unknown logging level '" << level
109+
<< "'. Using INFO level as default.";
110+
return logINFO;
111+
}
112+
113+
class Output2FILE
114+
{
115+
public:
116+
static FILE*& Stream();
117+
static void Output(const std::string& msg);
118+
};
119+
120+
inline FILE*& Output2FILE::Stream()
121+
{
122+
static FILE* pStream = stderr;
123+
return pStream;
124+
}
125+
126+
inline void Output2FILE::Output(const std::string& msg)
127+
{
128+
/*
129+
FILE* pStream = Stream();
130+
if (!pStream)
131+
return;
132+
fprintf(pStream, "%s", msg.c_str());
133+
fflush(pStream);
134+
*/
135+
}
136+
137+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
138+
# if defined (BUILDING_FILELOG_DLL)
139+
# define FILELOG_DECLSPEC __declspec (dllexport)
140+
# elif defined (USING_FILELOG_DLL)
141+
# define FILELOG_DECLSPEC __declspec (dllimport)
142+
# else
143+
# define FILELOG_DECLSPEC
144+
# endif // BUILDING_DBSIMPLE_DLL
145+
#else
146+
# define FILELOG_DECLSPEC
147+
#endif // _WIN32
148+
149+
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
150+
//typedef Log<Output2FILE> FILELog;
151+
152+
#ifndef FILELOG_MAX_LEVEL
153+
#define FILELOG_MAX_LEVEL logDEBUG4
154+
#endif
155+
156+
#define LOG(level) \
157+
if (level > FILELOG_MAX_LEVEL) ;\
158+
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
159+
else FILELog().Get(level) \
160+
161+
#define LOG_ERROR LOG(logERROR)
162+
#define LOG_WARNING LOG(logWARNING)
163+
#define LOG_INFO LOG(logINFO)
164+
#define LOG_DEBUG LOG(logDEBUG)
165+
166+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
167+
168+
#include <windows.h>
169+
170+
inline std::string NowTime()
171+
{
172+
const int MAX_LEN = 200;
173+
char buffer[MAX_LEN];
174+
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
175+
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
176+
return "Error in NowTime()";
177+
178+
char result[100] = {0};
179+
static DWORD first = GetTickCount();
180+
#pragma warning(suppress: 4996)
181+
sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
182+
return result;
183+
}
184+
185+
#else
186+
187+
#include <sys/time.h>
188+
189+
inline std::string NowTime()
190+
{
191+
char buffer[11];
192+
time_t t;
193+
time(&t);
194+
tm r = {0};
195+
strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r));
196+
struct timeval tv;
197+
gettimeofday(&tv, 0);
198+
char result[100] = {0};
199+
std::sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000);
200+
return result;
201+
}
202+
203+
#endif //WIN32
204+
205+
#endif //__LOG_H__

cefpython/cef3/client_handler/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ CC = g++
1212
CCFLAGS = -g -fPIC -Wall -Werror
1313

1414
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
15-
web_request_client.cpp string_visitor.cpp request_context_handler.cpp
15+
web_request_client.cpp string_visitor.cpp request_context_handler.cpp \
16+
task.cpp
1617
OBJ = $(SRC:.cpp=.o)
1718
OUT = libclient_handler.a
1819

cefpython/cef3/client_handler/client_handler.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#include "client_handler.h"
88
#include "cefpython_public_api.h"
99
#include "DebugLog.h"
10+
#include "LOG_DEBUG.h"
1011

1112
#if defined(OS_WIN)
1213
#include <Shellapi.h>
1314
#pragma comment(lib, "Shell32.lib")
15+
#include "dpi_aware.h"
1416
#elif defined(OS_LINUX)
1517
#include <unistd.h>
1618
#include <stdlib.h>
@@ -177,6 +179,15 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser,
177179
///
178180
/*--cef()--*/
179181
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
182+
#if defined(OS_WIN)
183+
// High DPI support.
184+
CefString auto_zooming = ApplicationSettings_GetString("auto_zooming");
185+
if (!auto_zooming.empty()) {
186+
LOG_DEBUG << "Browser: OnAfterCreated(): auto_zooming = "
187+
<< auto_zooming.ToString();
188+
SetBrowserDpiSettings(browser, auto_zooming);
189+
}
190+
#endif
180191
}
181192

182193
///
@@ -967,15 +978,15 @@ bool ClientHandler::OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
967978
EventFlags event_flags) {
968979
if (command_id == _MENU_ID_OPEN_PAGE_IN_EXTERNAL_BROWSER) {
969980
#if defined(OS_WIN)
970-
ShellExecute(0, L"open", params->GetPageUrl().ToWString().c_str(),
981+
ShellExecuteA(0, "open", params->GetPageUrl().ToString().c_str(),
971982
0, 0, SW_SHOWNORMAL);
972983
#elif defined(OS_LINUX)
973984
OpenInExternalBrowser(params->GetPageUrl().ToString());
974985
#endif
975986
return true;
976987
} else if (command_id == _MENU_ID_OPEN_FRAME_IN_EXTERNAL_BROWSER) {
977988
#if defined(OS_WIN)
978-
ShellExecute(0, L"open", params->GetFrameUrl().ToWString().c_str(),
989+
ShellExecuteA(0, "open", params->GetFrameUrl().ToString().c_str(),
979990
0, 0, SW_SHOWNORMAL);
980991
#elif defined(OS_LINUX)
981992
OpenInExternalBrowser(params->GetFrameUrl().ToString());

cefpython/cef3/client_handler/client_handler_py27.vcproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@
108108
<File
109109
RelativePath=".\request_context_handler.h"
110110
>
111+
</File>
112+
<File
113+
RelativePath=".\dpi_aware.h"
114+
>
115+
</File>
116+
<File
117+
RelativePath=".\task.h"
118+
>
111119
</File>
112120
</Filter>
113121
<Filter
@@ -144,6 +152,14 @@
144152
<File
145153
RelativePath=".\request_context_handler.cpp"
146154
>
155+
</File>
156+
<File
157+
RelativePath=".\dpi_aware.cpp"
158+
>
159+
</File>
160+
<File
161+
RelativePath=".\task.cpp"
162+
>
147163
</File>
148164
</Filter>
149165
</Files>

cefpython/cef3/client_handler/client_handler_py32.vcproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@
107107
<File
108108
RelativePath=".\request_context_handler.h"
109109
>
110+
</File>
111+
<File
112+
RelativePath=".\dpi_aware.h"
113+
>
114+
</File>
115+
<File
116+
RelativePath=".\task.h"
117+
>
110118
</File>
111119
</Filter>
112120
<Filter
@@ -143,6 +151,14 @@
143151
<File
144152
RelativePath=".\request_context_handler.cpp"
145153
>
154+
</File>
155+
<File
156+
RelativePath=".\dpi_aware.cpp"
157+
>
158+
</File>
159+
<File
160+
RelativePath=".\task.cpp"
161+
>
146162
</File>
147163
</Filter>
148164
</Files>

0 commit comments

Comments
 (0)
X Tutup