Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 83356f0

Browse files
committed
[[ revBrowserCEF ]] OSX Cocoa implementation of revbrowser-cef
[[ revBrowserCEF ]] Revise JavaScript handler commands to add handler to current browser JS context [[ revBrowserCEF ]] Don't shut down CEF library when last browser window closes as this causes errors on next browser open
1 parent 092444b commit 83356f0

File tree

12 files changed

+762
-115
lines changed

12 files changed

+762
-115
lines changed

revbrowser/cefprocess_w32.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include <include/cef_app.h>
18+
19+
#include <Windows.h>
20+
21+
////////////////////////////////////////////////////////////////////////////////
22+
23+
extern bool MCCefCreateApp(CefRefPtr<CefApp> &r_app);
24+
25+
////////////////////////////////////////////////////////////////////////////////
26+
27+
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
28+
{
29+
CefMainArgs t_args(hInstance);
30+
31+
CefRefPtr<CefApp> t_app;
32+
if (!MCCefCreateApp(t_app))
33+
return -1;
34+
35+
return CefExecuteProcess(t_args, t_app);
36+
}
37+
38+
////////////////////////////////////////////////////////////////////////////////
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>${EXECUTABLE_NAME}</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.runrev.${PRODUCT_NAME:rfc1034identifier}</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundlePackageType</key>
14+
<string>APPL</string>
15+
<key>CFBundleSignature</key>
16+
<string>????</string>
17+
<key>CFBundleVersion</key>
18+
<string>1</string>
19+
<key>LSUIElement</key>
20+
<true/>
21+
</dict>
22+
</plist>

revbrowser/revbrowser.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
_getXtable
22
_shutdownXtable
3+
_setExternalInterfaceVersion

revbrowser/revbrowser.xcodeproj/project.pbxproj

Lines changed: 289 additions & 2 deletions
Large diffs are not rendered by default.

revbrowser/src/cefbrowser.cpp

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,26 @@ static bool MCCefStringFromCString(const char *p_c_string, CefString &r_cef_stri
7878
// Cef initialization / shutdown handling
7979

8080
static bool s_cef_initialised = false;
81+
static bool s_cefbrowser_initialised = false;
82+
8183
static uint32_t s_instance_count = 0;
8284
static MCRunloopActionRef s_runloop_action = nil;
8385

84-
void MCCefBrowserInit(void)
86+
void MCCefBrowserExternalInit(void)
8587
{
8688
// set up static vars
8789
s_cef_initialised = false;
90+
s_cefbrowser_initialised = false;
8891
s_instance_count = 0;
92+
s_runloop_action = nil;
8993
}
9094

9195
void MCCefBrowserRunloopAction(void *p_context)
9296
{
9397
CefDoMessageLoopWork();
9498
}
9599

100+
// IM-2014-03-13: [[ revBrowserCEF ]] Initialisation of the CEF library
96101
bool MCCefInitialise(void)
97102
{
98103
if (s_cef_initialised)
@@ -114,34 +119,64 @@ bool MCCefInitialise(void)
114119
if (t_success)
115120
t_success = CefInitialize(t_args, t_settings, t_app);
116121

122+
s_cef_initialised = t_success;
123+
124+
return s_cef_initialised;
125+
}
126+
127+
// IM-2014-03-13: [[ revBrowserCEF ]] Initialise CEF & install the runloop action
128+
bool MCCefBrowserInitialise(void)
129+
{
130+
if (s_cefbrowser_initialised)
131+
return true;
132+
133+
bool t_success;
134+
t_success = true;
135+
136+
t_success = MCCefInitialise();
137+
117138
if (t_success)
118139
{
119140
int t_result;
120141
AddRunloopAction(MCCefBrowserRunloopAction, nil, &s_runloop_action, &t_result);
121142
}
122143

123-
s_cef_initialised = t_success;
144+
s_cefbrowser_initialised = t_success;
124145

125-
return s_cef_initialised;
146+
return s_cefbrowser_initialised;
126147
}
127148

149+
// IM-2014-03-13: [[ revBrowserCEF ]] Shutdown the CEF library
128150
void MCCefFinalise(void)
129151
{
130152
if (!s_cef_initialised)
131153
return;
132154

133155
CefShutdown();
134156

157+
s_cef_initialised = false;
158+
}
159+
160+
// IM-2014-03-13: [[ revBrowserCEF ]] Shut down the browser
161+
void MCCefBrowserFinalise(void)
162+
{
163+
if (!s_cefbrowser_initialised)
164+
return;
165+
166+
// IM-2014-03-13: [[ revBrowserCEF ]] CEF library can't be cleanly shutdown and restarted - don't call finalise
167+
// MCCefFinalise();
168+
135169
int t_result;
136170
/* UNCHECKED */ RemoveRunloopAction(s_runloop_action, &t_result);
137-
138-
s_cef_initialised = false;
171+
s_runloop_action = nil;
172+
173+
s_cefbrowser_initialised = false;
139174
}
140175

141176
void MCCefIncrementInstanceCount(void)
142177
{
143178
if (s_instance_count == 0)
144-
/* UNCHECKED */ MCCefInitialise();
179+
/* UNCHECKED */ MCCefBrowserInitialise();
145180

146181
s_instance_count++;
147182
}
@@ -154,7 +189,7 @@ void MCCefDecrementInstanceCount(void)
154189
s_instance_count--;
155190

156191
if (s_instance_count == 0)
157-
MCCefFinalise();
192+
MCCefBrowserFinalise();
158193
}
159194

160195
////////////////////////////////////////////////////////////////////////////////

revbrowser/src/cefbrowser_osx.mm

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include "external.h"
18+
#include "cefbrowser.h"
19+
20+
#include <AppKit/AppKit.h>
21+
22+
#include <include/cef_app.h>
23+
24+
class MCCefBrowserOSX : public MCCefBrowserBase
25+
{
26+
public:
27+
MCCefBrowserOSX(CefWindowHandle p_parent_window);
28+
virtual ~MCCefBrowserOSX(void);
29+
30+
bool GetWindowHandle(CefWindowHandle &r_hwnd);
31+
32+
virtual void PlatformConfigureWindow(CefWindowInfo &r_info);
33+
34+
virtual bool PlatformSetVisible(bool p_visible);
35+
virtual bool PlatformGetVisible(bool &r_visible);
36+
37+
virtual bool PlatformGetRect(int32_t &r_left, int32_t &r_top, int32_t &r_right, int32_t &r_bottom);
38+
virtual bool PlatformSetRect(int32_t p_left, int32_t p_top, int32_t p_right, int32_t p_bottom);
39+
virtual bool PlatformGetWindowID(int32_t &r_id);
40+
41+
private:
42+
CefWindowHandle m_parent_window;
43+
};
44+
45+
const char *MCCefPlatformGetSubProcessName(void)
46+
{
47+
return "revbrowser-cefprocess.app/Contents/MacOS/revbrowser-cefprocess";
48+
}
49+
50+
bool MCCefPlatformCreateBrowser(int p_window_id, MCCefBrowserBase *&r_browser)
51+
{
52+
NSWindow *t_app_window;
53+
t_app_window = [NSApp windowWithWindowNumber:p_window_id];
54+
55+
if (t_app_window == nil)
56+
return false;
57+
58+
MCCefBrowserOSX *t_browser;
59+
t_browser = new MCCefBrowserOSX([t_app_window contentView]);
60+
61+
if (t_browser == nil)
62+
return false;
63+
64+
r_browser = t_browser;
65+
66+
return true;
67+
}
68+
69+
void MCCefBrowserOSX::PlatformConfigureWindow(CefWindowInfo &r_info)
70+
{
71+
r_info.SetAsChild(m_parent_window, 0,0,1,1);
72+
}
73+
74+
void MCCefPlatformCloseBrowserWindow(CefRefPtr<CefBrowser> p_browser)
75+
{
76+
NSView *t_handle;
77+
t_handle = p_browser->GetHost()->GetWindowHandle();
78+
if (t_handle == nil)
79+
return;
80+
81+
[t_handle removeFromSuperview];
82+
}
83+
84+
MCCefBrowserOSX::MCCefBrowserOSX(CefWindowHandle p_parent_window) : MCCefBrowserBase()
85+
{
86+
m_parent_window = p_parent_window;
87+
}
88+
89+
MCCefBrowserOSX::~MCCefBrowserOSX(void)
90+
{
91+
}
92+
93+
bool MCCefBrowserOSX::GetWindowHandle(CefWindowHandle &r_hwnd)
94+
{
95+
CefRefPtr<CefBrowser> t_browser;
96+
t_browser = GetCefBrowser();
97+
98+
if (t_browser == nil)
99+
return false;
100+
101+
CefWindowHandle t_handle;
102+
t_handle = t_browser->GetHost()->GetWindowHandle();
103+
104+
if (t_handle == nil)
105+
return false;
106+
107+
r_hwnd = t_handle;
108+
109+
return true;
110+
}
111+
112+
bool MCCefBrowserOSX::PlatformGetRect(int32_t &r_left, int32_t &r_top, int32_t &r_right, int32_t &r_bottom)
113+
{
114+
NSView *t_handle;
115+
if (!GetWindowHandle(t_handle))
116+
return false;
117+
118+
NSRect t_rect;
119+
t_rect = [t_handle frame];
120+
121+
NSRect t_win_rect;
122+
t_win_rect = [[[t_handle window] contentView] frame];
123+
124+
r_left = t_rect.origin.x;
125+
r_top = t_win_rect.size.height - t_rect.origin.y;
126+
r_right = r_left + t_rect.size.width;
127+
r_bottom = r_top + t_rect.size.height;
128+
129+
return true;
130+
}
131+
132+
bool MCCefBrowserOSX::PlatformSetRect(int32_t p_left, int32_t p_top, int32_t p_right, int32_t p_bottom)
133+
{
134+
NSView *t_handle;
135+
if (!GetWindowHandle(t_handle))
136+
return false;
137+
138+
NSRect t_win_rect;
139+
t_win_rect = [[[t_handle window] contentView] frame];
140+
141+
NSRect t_rect;
142+
t_rect = NSMakeRect(p_left, t_win_rect.size.height - p_bottom, p_right - p_left, p_bottom - p_top);
143+
144+
[t_handle setFrame:t_rect];
145+
146+
return true;
147+
}
148+
149+
bool MCCefBrowserOSX::PlatformGetVisible(bool &r_visible)
150+
{
151+
NSView *t_handle;
152+
if (!GetWindowHandle(t_handle))
153+
return false;
154+
155+
r_visible = ![t_handle isHidden];
156+
157+
return true;
158+
}
159+
160+
bool MCCefBrowserOSX::PlatformSetVisible(bool p_visible)
161+
{
162+
NSView *t_handle;
163+
if (!GetWindowHandle(t_handle))
164+
return false;
165+
166+
[t_handle setHidden:!p_visible];
167+
168+
return true;
169+
}
170+
171+
bool MCCefBrowserOSX::PlatformGetWindowID(int32_t &r_id)
172+
{
173+
r_id = (int32_t) [[m_parent_window window] windowNumber];
174+
175+
return true;
176+
}

0 commit comments

Comments
 (0)