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

Commit 88e4543

Browse files
committed
[[ BrowserWidget ]] Add browser extension library, initially linked to kernel.
[[ BrowserWidget ]] Modify browser widget to use browser extension library functions.
1 parent 43c805d commit 88e4543

14 files changed

+312
-20
lines changed

engine/engine-sources.gypi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@
887887
'src/module-canvas.cpp',
888888
'src/module-engine.cpp',
889889
'src/module-resources.cpp',
890+
891+
'src/module-browser.cpp',
890892
],
891893

892894
# Engine LCB files containing syntax
@@ -900,7 +902,7 @@
900902
# Other engine LCB files
901903
'engine_other_lcb_files':
902904
[
903-
905+
'src/browser.lcb',
904906
],
905907
},
906908

engine/kernel-mode-template.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
'../libfoundation/libfoundation.gyp:libFoundation',
77
'../libgraphics/libgraphics.gyp:libGraphics',
88
'../libscript/libscript.gyp:libScript',
9+
10+
'../libbrowser/libbrowser.gyp:libbrowser',
911
],
1012

1113
'conditions':

engine/kernel.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
'../libgraphics/libgraphics.gyp:libGraphics',
1313
'../libscript/libscript.gyp:libScript',
1414

15+
'../libbrowser/libbrowser.gyp:libbrowser',
16+
1517
'../thirdparty/libgif/libgif.gyp:libgif',
1618
'../thirdparty/libjpeg/libjpeg.gyp:libjpeg',
1719
'../thirdparty/libopenssl/libopenssl.gyp:libopenssl',

engine/src/browser.lcb

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
/*
2+
Copyright (C) 2015 Runtime Revolution Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
/*
19+
Module: com.livecode.extensions.libbrowser
20+
21+
Type: library
22+
23+
Description: Provide access to native C browser API from LCB.
24+
*/
25+
26+
--
27+
module com.livecode.extensions.libbrowser
28+
--
29+
30+
-- dependancy declarations
31+
use com.livecode.foreign
32+
use com.livecode.widget
33+
use com.livecode.engine
34+
--
35+
36+
-- metadata
37+
metadata title is "libBrowser"
38+
metadata author is "Ian Macphail"
39+
metadata version is "1.0.0"
40+
--
41+
42+
--------------------------------------------------------------------------------
43+
44+
-- foreign types
45+
public type MCBrowserFactoryRef is Pointer
46+
public type MCBrowserRef is Pointer
47+
48+
public type MCBrowserListRef is Pointer
49+
50+
public type MCBrowserProperty is CInt
51+
public type MCBrowserValueType is CInt
52+
public type MCBrowserRequestType is CInt
53+
public type MCBrowserRequestState is CInt
54+
55+
--
56+
57+
public foreign handler MCBrowserLibraryInitialize() returns CBool binds to "<builtin>"
58+
public foreign handler MCBrowserLibraryFinalize() returns nothing binds to "<builtin>"
59+
60+
public foreign handler MCBrowserFactoryGet(in pFactoryId as NativeCString, out rFactory as MCBrowserFactoryRef) returns CBool binds to "<builtin>"
61+
public foreign handler MCBrowserFactoryCreateBrowser(in pFactory as MCBrowserFactoryRef, out rBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
62+
63+
public foreign handler MCBrowserRetain(in pBrowser as MCBrowserRef) returns MCBrowserRef binds to "<builtin>"
64+
public foreign handler MCBrowserRelease(in pBrowser as MCBrowserRef) returns nothing binds to "<builtin>"
65+
66+
public foreign handler MCBrowserGetNativeLayer(in pBrowser as MCBrowserRef) returns Pointer binds to "<builtin>"
67+
68+
public foreign handler MCBrowserGetBoolProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as CBool) returns CBool binds to "<builtin>"
69+
public foreign handler MCBrowserSetBoolProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as CBool) returns CBool binds to "<builtin>"
70+
71+
public foreign handler MCBrowserGetStringProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as NativeCString) returns CBool binds to "<builtin>"
72+
public foreign handler MCBrowserSetStringProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as NativeCString) returns CBool binds to "<builtin>"
73+
74+
public foreign handler MCBrowserGoBack(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
75+
public foreign handler MCBrowserGoForward(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
76+
public foreign handler MCBrowserGoToURL(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
77+
public foreign handler MCBrowserEvaluateJavaScript(in pBrowser as MCBrowserRef, in pScript as NativeCString, out rResult as NativeCString) returns CBool binds to "<builtin>"
78+
79+
----------
80+
81+
public foreign handler MCBrowserListGetSize(in pList as MCBrowserListRef, out pSize as CUInt) returns CBool binds to "<builtin>"
82+
public foreign handler MCBrowserListGetType(in pList as MCBrowserListRef, in pIndex as CUInt, out pType as MCBrowserValueType) returns CBool binds to "<builtin>"
83+
public foreign handler MCBrowserListGetBoolean(in pList as MCBrowserListRef, in pIndex as CUInt, out pValue as CBool) returns CBool binds to "<builtin>"
84+
public foreign handler MCBrowserListGetInteger(in pList as MCBrowserListRef, in pIndex as CUInt, out pValue as CInt) returns CBool binds to "<builtin>"
85+
public foreign handler MCBrowserListGetDouble(in pList as MCBrowserListRef, in pIndex as CUInt, out pValue as CDouble) returns CBool binds to "<builtin>"
86+
public foreign handler MCBrowserListGetUTF8String(in pList as MCBrowserListRef, in pIndex as CUInt, out pValue as ZStringNative) returns CBool binds to "<builtin>"
87+
public foreign handler MCBrowserListGetList(in pList as MCBrowserListRef, in pIndex as CUInt, out pValue as MCBrowserListRef) returns CBool binds to "<builtin>"
88+
89+
public foreign handler MCBrowserSetRequestHandler(in pBrowser as MCBrowserRef, in pCallback as Pointer, in pContext as optional Pointer) returns CBool binds to "<builtin>"
90+
public foreign handler MCBrowserSetJavaScriptHandler(in pBrowser as MCBrowserRef, in pCallback as Pointer, in pContext as optional Pointer) returns CBool binds to "<builtin>"
91+
92+
--------------------------------------------------------------------------------
93+
94+
public constant kMCBrowserValueTypeNone is 0
95+
public constant kMCBrowserValueTypeBoolean is 1
96+
public constant kMCBrowserValueTypeInteger is 2
97+
public constant kMCBrowserValueTypeDouble is 3
98+
public constant kMCBrowserValueTypeUTF8String is 4
99+
public constant kMCBrowserValueTypeList is 5
100+
101+
--
102+
103+
public constant kMCBrowserPropertyScrollbars is 0
104+
public constant kMCBrowserPropertyAllowNewWindows is 1
105+
public constant kMCBrowserPropertyEnableContextMenu is 2
106+
public constant kMCBrowserPropertyUrl is 3
107+
public constant kMCBrowserPropertyHtmlText is 4
108+
public constant kMCBrowserPropertyUserAgent is 5
109+
public constant kMCBrowserPropertyJavaScriptHandlers is 6
110+
111+
public constant kMCBrowserPropertyMap is ["scrollbars", "allowNewWindows", "enableContextMenu", "url", "htmlText", "userAgent", "javaScriptHandlers"]
112+
113+
--
114+
115+
public constant kMCBrowserRequestTypeNavigate is 0
116+
public constant kMCBrowserRequestTypeDocumentLoad is 1
117+
118+
public constant kMCBrowserRequestTypeMap is ["navigate", "documentLoad"]
119+
120+
--
121+
122+
public constant kMCBrowserRequestStateBegin is 0
123+
public constant kMCBrowserRequestStateComplete is 1
124+
public constant kMCBrowserRequestStateFailed is 2
125+
126+
public constant kMCBrowserRequestStateMap is ["begin", "complete", "failed"]
127+
128+
--
129+
130+
constant kStringProps is ["url", "htmlText", "userAgent", "javaScriptHandlers"]
131+
constant kBoolProps is ["scrollbars", "allowNewWindows", "enableContextMenu"]
132+
133+
--------------------------------------------------------------------------------
134+
135+
public handler browserListToLCBList(in pBrowserList as MCBrowserListRef, out rList as List) returns Boolean
136+
variable tList as List
137+
put the empty list into tList
138+
139+
variable tCount as CUInt
140+
if not MCBrowserListGetSize(pBrowserList, tCount) then
141+
log "couldn't get size"
142+
return false
143+
end if
144+
145+
variable i
146+
repeat with i from 0 up to tCount - 1
147+
variable tType as MCBrowserValueType
148+
if not MCBrowserListGetType(pBrowserList, i, tType) then
149+
log "couldn't get type of %@" with [i]
150+
return false
151+
end if
152+
153+
if tType is kValueTypeBoolean then
154+
variable tBoolean as CBool
155+
if not MCBrowserListGetBoolean(pBrowserList, i, tBoolean) then
156+
log "couldn't get boolean %@" with [i]
157+
return false
158+
end if
159+
push tBoolean onto tList
160+
else if tType is kValueTypeInteger then
161+
variable tInteger as CInt
162+
if not MCBrowserListGetInteger(pBrowserList, i, tInteger) then
163+
log "couldn't get integer %@" with [i]
164+
return false
165+
end if
166+
push tInteger onto tList
167+
else if tType is kValueTypeDouble then
168+
variable tDouble as CDouble
169+
if not MCBrowserListGetDouble(pBrowserList, i, tDouble) then
170+
log "couldn't get double %@" with [i]
171+
return false
172+
end if
173+
push tDouble onto tList
174+
else if tType is kValueTypeUTF8String then
175+
variable tUTF8String as ZStringNative
176+
if not MCBrowserListGetUTF8String(pBrowserList, i, tUTF8String) then
177+
log "couldn't get string %@" with [i]
178+
return false
179+
end if
180+
push tUTF8String onto tList
181+
else if tType is kValueTypeList then
182+
variable tBrowserList as MCBrowserListRef
183+
if not MCBrowserListGetList(pBrowserList, i, tBrowserList) then
184+
log "couldn't get list %@" with [i]
185+
return false
186+
end if
187+
variable tConvertedList as List
188+
if not browserListToLCBList(tBrowserList, tConvertedList) then
189+
log "couldn't convert list %@" with [i]
190+
return false
191+
end if
192+
push tConvertedList onto tList
193+
else
194+
log "unrecognised type %@" with [tType]
195+
return false
196+
end if
197+
end repeat
198+
199+
put tList into rList
200+
201+
return true
202+
end handler
203+
204+
----------
205+
206+
private handler browserLookupProperty(in pProp as String, out rProp as MCBrowserProperty) returns Boolean
207+
variable tIndex as Integer
208+
put the index of pProp in kPropertyMap into tIndex
209+
210+
if tIndex is 0 then
211+
return false
212+
end if
213+
214+
put tIndex - 1 into rProp
215+
return true
216+
end handler
217+
218+
----------
219+
220+
public handler browserGetProperty(in pBrowser as MCBrowserRef, in pProperty as String, out rValue as optional any) returns Boolean
221+
variable tProperty as MCBrowserProperty
222+
if not browserLookupProperty(pProperty, tProperty) then
223+
return false
224+
end if
225+
226+
if pProperty is in kStringProps then
227+
return MCBrowserGetStringProperty(pBrowser, tProperty, rValue)
228+
else if pProperty is in kBoolProps then
229+
return MCBrowserGetBoolProperty(pBrowser, tProperty, rValue)
230+
end if
231+
232+
return false
233+
end handler
234+
235+
public handler browserSetProperty(in pBrowser as MCBrowserRef, in pProperty as String, in pValue as any) returns Boolean
236+
variable tProperty as MCBrowserProperty
237+
if not browserLookupProperty(pProperty, tProperty) then
238+
return false
239+
end if
240+
241+
if pProperty is in kStringProps then
242+
return MCBrowserSetStringProperty(pBrowser, tProperty, pValue)
243+
else if pProperty is in kBoolProps then
244+
return MCBrowserSetBoolProperty(pBrowser, tProperty, pValue)
245+
end if
246+
247+
return false
248+
end handler
249+
250+
----------
251+
252+
end module

engine/src/module-browser.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright (C) 2015 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 "prefix.h"
18+
19+
#include <libbrowser.h>
20+
21+
////////////////////////////////////////////////////////////////////////////////
22+
23+
extern "C" bool com_livecode_extensions_libbrowser_Initialize()
24+
{
25+
return MCBrowserLibraryInitialize();
26+
}
27+
28+
extern "C" void com_livecode_extensions_libbrowser_Finalize(void)
29+
{
30+
MCBrowserLibraryFinalize();
31+
}
32+
33+
////////////////////////////////////////////////////////////////////////////////

libbrowser/include/libbrowser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#ifndef __LIBBROWSER_H__
1818
#define __LIBBROWSER_H__
1919

20-
#include "core.h"
21-
2220
// C++ Implementation Class API
2321

2422
class MCBrowserRefCounted

libbrowser/libbrowser.gyp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'dependencies':
1414
[
1515
'../libcore/libcore.gyp:libCore',
16-
'../prebuilt/libcef.gyp:libcef',
1716
'../thirdparty/libcef/libcef.gyp:libcef_library_wrapper',
1817
'../thirdparty/libcef/libcef.gyp:libcef_stubs',
1918
],
@@ -25,6 +24,8 @@
2524

2625
'sources':
2726
[
27+
'include/libbrowser.h',
28+
2829
'src/libbrowser.cpp',
2930
'src/libbrowser_cef.cpp',
3031
'src/libbrowser_cef.h',

libbrowser/src/libbrowser.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
You should have received a copy of the GNU General Public License
1515
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1616

17-
#include "libbrowser.h"
17+
#include <core.h>
18+
19+
#include <libbrowser.h>
1820

1921
// Browser base implementation
2022

@@ -109,11 +111,9 @@ void MCBrowser::OnJavaScriptCall(const char *p_handler, MCBrowserListRef p_param
109111

110112
static MCBrowserFactoryRef s_browser_factory = nil;
111113

112-
extern bool MCCefBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
113114
bool MCBrowserLibraryInitialize()
114115
{
115-
s_browser_factory = nil;
116-
return MCCefBrowserFactoryCreate(s_browser_factory);
116+
return true;
117117
}
118118

119119
void MCBrowserLibraryFinalize()
@@ -124,10 +124,10 @@ void MCBrowserLibraryFinalize()
124124

125125
// Factory
126126

127+
extern bool MCCefBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
127128
bool MCBrowserFactoryGet(const char *p_factory, MCBrowserFactoryRef &r_factory)
128129
{
129-
// TODO - platform specific implementation
130-
if (s_browser_factory == nil)
130+
if (s_browser_factory == nil && !MCCefBrowserFactoryCreate(s_browser_factory))
131131
return false;
132132

133133
r_factory = s_browser_factory;
@@ -365,3 +365,4 @@ bool MCBrowserSetJavaScriptHandler(MCBrowserRef p_browser, MCBrowserJavaScriptCa
365365
((MCBrowser*)p_browser)->SetJavaScriptHandler(t_wrapper);
366366
return true;
367367
}
368+

0 commit comments

Comments
 (0)