Skip to content

Commit 208ed60

Browse files
CzarekCzarek
authored andcommitted
Fixed errors when accessing mouse context menu and using <select>
controls. See Issue 156. Fixed CEF shutdown on Mac. Browsers were not closed correctly.
1 parent 142df92 commit 208ed60

File tree

12 files changed

+189
-50
lines changed

12 files changed

+189
-50
lines changed

cefpython/cef3/client_handler/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
# -fPIC -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions \
99
# -Wl,-z,relro
1010

11+
UNAME_S = $(shell uname -s)
12+
1113
CC = g++
1214
CCFLAGS = -g -fPIC -Wall -Werror $(CEF_CCFLAGS)
1315

1416
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
1517
web_request_client.cpp string_visitor.cpp request_context_handler.cpp \
1618
task.cpp
19+
1720
OBJ = $(SRC:.cpp=.o)
21+
22+
ifeq ($(UNAME_S), Darwin)
23+
OBJ += util_mac.o
24+
endif
25+
1826
OUT = libclient_handler.a
1927

2028
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 \
@@ -27,7 +35,16 @@ INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 \
2735
-I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include
2836

2937
.cpp.o:
38+
@echo [Makefile] Building $@ from $<...
3039
$(CC) $(CCFLAGS) $(INC) -c $< -o $@
3140

3241
$(OUT): $(OBJ)
42+
@echo [Makefile] Creating library $(OUT) from $(OBJ)...
3343
ar rcs $(OUT) $(OBJ)
44+
45+
util_mac.o: util_mac.mm
46+
@echo [Makefile] Building $@ from $<...
47+
$(CC) $(CCFLAGS) $(INC) -c $< -o $@
48+
49+
clean:
50+
rm *.o *.a

cefpython/cef3/client_handler/client_handler.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ void OpenInExternalBrowser(const std::string& url)
3535

3636
// xdg-open is a desktop-independent tool for running
3737
// default applications. Installed by default on Ubuntu.
38-
// xdg-open process is running in the backround until
38+
// xdg-open process is running in the backround until
3939
// cefpython app closes.
4040
std::string prog = "xdg-open";
4141

4242
// Using system() opens up for bugs and exploits, not
4343
// recommended.
44-
44+
4545
// Fork yourself and run in parallel, do not block the
4646
// current proces.
4747
char *args[3];
@@ -198,7 +198,7 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
198198
// true to use a custom implementation.
199199
///
200200
/*--cef()--*/
201-
bool ClientHandler::RunModal(CefRefPtr<CefBrowser> browser) {
201+
bool ClientHandler::RunModal(CefRefPtr<CefBrowser> browser) {
202202
REQUIRE_UI_THREAD();
203203
return LifespanHandler_RunModal(browser);
204204
}
@@ -262,7 +262,7 @@ bool ClientHandler::RunModal(CefRefPtr<CefBrowser> browser) {
262262
// exist.
263263
///
264264
/*--cef()--*/
265-
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
265+
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
266266
REQUIRE_UI_THREAD();
267267
return LifespanHandler_DoClose(browser);
268268
}
@@ -481,7 +481,7 @@ bool ClientHandler::GetAuthCredentials(CefRefPtr<CefBrowser> browser,
481481
const CefString& scheme,
482482
CefRefPtr<CefAuthCallback> callback) {
483483
REQUIRE_IO_THREAD();
484-
return RequestHandler_GetAuthCredentials(browser, frame, isProxy, host,
484+
return RequestHandler_GetAuthCredentials(browser, frame, isProxy, host,
485485
port, realm, scheme, callback);
486486
// Default: return false;
487487
}
@@ -582,7 +582,7 @@ void ClientHandler::OnPluginCrashed(CefRefPtr<CefBrowser> browser,
582582
// --------------------------------------------------------------------------
583583

584584
///
585-
// Implement this interface to handle events related to browser load status.
585+
// Implement this interface to handle events related to browser load status.
586586
// The methods of this class will be called on the UI thread.
587587
///
588588

@@ -663,7 +663,7 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
663663
bool ClientHandler::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
664664
CefRect& rect) {
665665
REQUIRE_UI_THREAD();
666-
return RenderHandler_GetRootScreenRect(browser, rect);
666+
return RenderHandler_GetRootScreenRect(browser, rect);
667667
}
668668

669669
///
@@ -685,7 +685,7 @@ bool ClientHandler::GetScreenPoint(CefRefPtr<CefBrowser> browser,
685685
int viewX,
686686
int viewY,
687687
int& screenX,
688-
int& screenY) {
688+
int& screenY) {
689689
REQUIRE_UI_THREAD();
690690
return RenderHandler_GetScreenPoint(browser, viewX, viewY, screenX,
691691
screenY);
@@ -702,7 +702,7 @@ bool ClientHandler::GetScreenPoint(CefRefPtr<CefBrowser> browser,
702702
///
703703
/*--cef()--*/
704704
bool ClientHandler::GetScreenInfo(CefRefPtr<CefBrowser> browser,
705-
CefScreenInfo& screen_info) {
705+
CefScreenInfo& screen_info) {
706706
REQUIRE_UI_THREAD();
707707
return RenderHandler_GetScreenInfo(browser, screen_info);
708708
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
2+
// reserved. Use of this source code is governed by a BSD-style license that
3+
// can be found in the LICENSE file.
4+
5+
#ifndef CEFPYTHON_UTIL_MAC_H_
6+
#define CEFPYTHON_UTIL_MAC_H_
7+
8+
#include <string>
9+
#include "include/cef_base.h"
10+
#include "include/cef_app.h"
11+
12+
void MacInitialize();
13+
14+
#endif // CEFPYTHON_UTIL_MAC_H_
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
2+
// reserved. Use of this source code is governed by a BSD-style license that
3+
// can be found in the LICENSE file.
4+
5+
#import "util_mac.h"
6+
#import <Cocoa/Cocoa.h>
7+
#include <objc/runtime.h>
8+
#include "include/cef_app.h"
9+
#include "include/cef_application_mac.h"
10+
11+
namespace {
12+
13+
BOOL g_handling_send_event = false;
14+
15+
} // namespace
16+
17+
// Add the necessary CrAppControlProtocol
18+
// functionality to NSApplication using categories and swizzling.
19+
@interface NSApplication (CEFPythonApplication)
20+
21+
- (BOOL)isHandlingSendEvent;
22+
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
23+
- (void)_swizzled_sendEvent:(NSEvent*)event;
24+
- (void)_swizzled_terminate:(id)sender;
25+
26+
@end
27+
28+
@implementation NSApplication (CEFPythonApplication)
29+
30+
// This selector is called very early during the application initialization.
31+
+ (void)load {
32+
// Swap NSApplication::sendEvent with _swizzled_sendEvent.
33+
Method original = class_getInstanceMethod(self, @selector(sendEvent));
34+
Method swizzled =
35+
class_getInstanceMethod(self, @selector(_swizzled_sendEvent));
36+
method_exchangeImplementations(original, swizzled);
37+
38+
Method originalTerm = class_getInstanceMethod(self, @selector(terminate:));
39+
Method swizzledTerm =
40+
class_getInstanceMethod(self, @selector(_swizzled_terminate:));
41+
method_exchangeImplementations(originalTerm, swizzledTerm);
42+
}
43+
44+
- (BOOL)isHandlingSendEvent {
45+
return g_handling_send_event;
46+
}
47+
48+
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
49+
g_handling_send_event = handlingSendEvent;
50+
}
51+
52+
- (void)_swizzled_sendEvent:(NSEvent*)event {
53+
CefScopedSendingEvent sendingEventScoper;
54+
// Calls NSApplication::sendEvent due to the swizzling.
55+
[self _swizzled_sendEvent:event];
56+
}
57+
58+
- (void)_swizzled_terminate:(id)sender {
59+
[self _swizzled_terminate:sender];
60+
}
61+
62+
@end
63+
64+
void MacInitialize() {
65+
[NSApplication sharedApplication];
66+
}

cefpython/cef3/mac/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Resources/
22
*.dylib
33
*.so
44
subprocess
5+
webcache/

cefpython/cef3/mac/binaries_32bit/wxpython.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
</head>
3030
<body>
3131

32-
Use the Delete key on Mac to go back in history navigation.<br>
33-
Mouse context menu is currently disabled, see Issue 156.<br>
32+
Use mouse context menu to go Back/Forward in navigation history.<br>
3433

3534
<h2>Table of contents</h2>
3635
<ol>

0 commit comments

Comments
 (0)