forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrowser.lcb
More file actions
531 lines (447 loc) · 22.7 KB
/
browser.lcb
File metadata and controls
531 lines (447 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
/*
Copyright (C) 2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/*
Module: com.livecode.extensions.libbrowser
Type: library
Description: Provide access to native C browser API from LCB.
*/
--
module com.livecode.extensions.libbrowser
--
-- dependancy declarations
use com.livecode.foreign
use com.livecode.engine
--
-- metadata
metadata title is "libBrowser"
metadata author is "Ian Macphail"
metadata version is "1.0.0"
--
--------------------------------------------------------------------------------
-- foreign types
public type MCBrowserFactoryRef is Pointer
public type MCBrowserRef is Pointer
public type MCBrowserNavigationRequestRef is Pointer
public type MCBrowserListRef is Pointer
public type MCBrowserDictionaryRef is Pointer
public type MCBrowserProperty is CInt
public type MCBrowserValueType is CInt
public type MCBrowserNavigationEventType is CInt
public type MCBrowserNavigationState is CInt
public type MCBrowserNavigationType is CInt
--
public foreign handler MCBrowserLibraryInitialize() returns CBool binds to "<builtin>"
public foreign handler MCBrowserLibraryFinalize() returns nothing binds to "<builtin>"
public foreign handler type MCBrowserWaitFunction() returns CBool
public foreign handler type MCBrowserBreakWaitFunction() returns nothing
public foreign handler MCBrowserLibrarySetWaitFunction(in pWait as MCBrowserWaitFunction) returns nothing binds to "<builtin>"
public foreign handler MCBrowserLibrarySetBreakWaitFunction(in pBreakWait as MCBrowserBreakWaitFunction) returns nothing binds to "<builtin>"
public foreign handler MCBrowserLibraryGetRunloopCallback(out rCallback as Pointer, out rContext as optional Pointer) returns CBool binds to "<builtin>"
public foreign handler MCBrowserFactoryGet(in pFactoryId as ZStringUTF8, out rFactory as MCBrowserFactoryRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserFactoryCreateBrowser(in pFactory as MCBrowserFactoryRef, in pDisplay as optional Pointer, in pParentView as Pointer, out rBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserRetain(in pBrowser as MCBrowserRef) returns MCBrowserRef binds to "<builtin>"
public foreign handler MCBrowserRelease(in pBrowser as MCBrowserRef) returns nothing binds to "<builtin>"
public foreign handler MCBrowserGetNativeLayer(in pBrowser as MCBrowserRef) returns Pointer binds to "<builtin>"
public foreign handler MCBrowserGetBoolProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as CBool) returns CBool binds to "<builtin>"
public foreign handler MCBrowserSetBoolProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as CBool) returns CBool binds to "<builtin>"
public foreign handler MCBrowserGetStringProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserSetStringProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserGetIntegerProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as Int32) returns CBool binds to "<builtin>"
public foreign handler MCBrowserSetIntegerProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as Int32) returns CBool binds to "<builtin>"
public foreign handler MCBrowserGoBack(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserGoForward(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserGoToURL(in pBrowser as MCBrowserRef, in pURL as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserLoadHTMLText(in pBrowser as MCBrowserRef, in pHTMLText as ZStringUTF8, in pBaseURL as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserStopLoading(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserReload(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserEvaluateJavaScript(in pBrowser as MCBrowserRef, in pScript as ZStringUTF8, out rResult as ZStringUTF8) returns CBool binds to "<builtin>"
----------
public foreign handler MCBrowserNavigationRequestRetain(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns MCBrowserNavigationRequestRef binds to "<builtin>"
public foreign handler MCBrowserNavigationRequestRelease(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns nothing binds to "<builtin>"
public foreign handler MCBrowserNavigationRequestGetURL(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef, out rURL as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserNavigationRequestGetNavigationType(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef, out rType as MCBrowserNavigationType) returns CBool binds to "<builtin>"
public foreign handler MCBrowserNavigationRequestIsFrame(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef, out rIsFrame as CBool) returns CBool binds to "<builtin>"
public foreign handler MCBrowserNavigationRequestContinue(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserNavigationRequestCancel(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns CBool binds to "<builtin>"
----------
public foreign handler MCBrowserListGetSize(in pList as MCBrowserListRef, out rSize as UInt32) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetType(in pList as MCBrowserListRef, in pIndex as UInt32, out rType as MCBrowserValueType) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetBoolean(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as CBool) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetInteger(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as Int32) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetDouble(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as CDouble) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetUTF8String(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetList(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as MCBrowserListRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserListGetDictionary(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as MCBrowserDictionaryRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetKeys(in pDictionary as MCBrowserDictionaryRef, out rKeys as Pointer, out rCount as UInt32) returns CBool binds to "<builtin>"
/* WORKAROUND - Can't currently dereference a Pointer-to-CString at the moment so need to provide key accessor functions */
public foreign handler MCBrowserDictionaryGetKeyCount(in pDictionary as MCBrowserDictionaryRef, out rCount as UInt32) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetKey(in pDictionary as MCBrowserDictionaryRef, in pIndex as UInt32, out rKey as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetType(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rType as MCBrowserValueType) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetBoolean(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as CBool) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetInteger(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as Int32) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetDouble(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as CDouble) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetUTF8String(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as ZStringUTF8) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetList(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as MCBrowserListRef) returns CBool binds to "<builtin>"
public foreign handler MCBrowserDictionaryGetDictionary(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as MCBrowserDictionaryRef) returns CBool binds to "<builtin>"
public foreign handler type MCBrowserNavigationRequestCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pRequest as MCBrowserNavigationRequestRef) returns CBool
public foreign handler type MCBrowserNavigationCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pType as MCBrowserNavigationEventType, in pState as MCBrowserNavigationState, in pFrame as CBool, in pUrl as ZStringUTF8, in pError as optional ZStringUTF8) returns nothing
public foreign handler type MCBrowserJavaScriptCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pHandler as ZStringUTF8, in pParams as MCBrowserListRef) returns nothing
public foreign handler type MCBrowserProgressCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pUrl as ZStringUTF8, in pProgress as UInt32) returns nothing
public foreign handler MCBrowserSetNavigationRequestHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserNavigationRequestCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
public foreign handler MCBrowserSetNavigationHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserNavigationCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
public foreign handler MCBrowserSetJavaScriptHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserJavaScriptCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
public foreign handler MCBrowserSetProgressHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserProgressCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
--------------------------------------------------------------------------------
public constant kMCBrowserValueTypeNone is 0
public constant kMCBrowserValueTypeBoolean is 1
public constant kMCBrowserValueTypeInteger is 2
public constant kMCBrowserValueTypeDouble is 3
public constant kMCBrowserValueTypeUTF8String is 4
public constant kMCBrowserValueTypeList is 5
public constant kMCBrowserValueTypeDictionary is 6
--
public constant kMCBrowserPropertyVerticalScrollbarEnabled is 0
public constant kMCBrowserPropertyHorizontalScrollbarEnabled is 1
public constant kMCBrowserPropertyAllowNewWindows is 2
public constant kMCBrowserPropertyEnableContextMenu is 3
public constant kMCBrowserPropertyAllowUserInteraction is 4
public constant kMCBrowserPropertyIsSecure is 5
public constant kMCBrowserPropertyUrl is 6
public constant kMCBrowserPropertyHtmlText is 7
public constant kMCBrowserPropertyUserAgent is 8
public constant kMCBrowserPropertyJavaScriptHandlers is 9
public constant kMCBrowserPropertyiOSDelayRequests is 10
public constant kMCBrowserPropertyiOSAllowsInlineMediaPlayback is 11
public constant kMCBrowserPropertyiOSMediaPlaybackRequiresUserAction is 12
public constant kMCBrowserPropertyiOSAutoFit is 13
public constant kMCBrowserPropertyCanGoForward is 14
public constant kMCBrowserPropertyCanGoBack is 15
public constant kMCBrowserPropertyDataDetectorTypes is 16
public constant kMCBrowserPropertyScrollEnabled is 17
public constant kMCBrowserPropertyScrollCanBounce is 18
public constant kMCBrowserPropertyMap is [ \
"verticalScrollbarEnabled", \
"horizontalScrollbarEnabled", \
"allowNewWindows", \
"enableContextMenu", \
"allowUserInteraction", \
"isSecure", \
"url", \
"htmlText", \
"userAgent", \
"javaScriptHandlers", \
"delayRequests", \
"allowsInlineMediaPlayback", \
"mediaPlaybackRequiresUserAction", \
"autoFit", \
"canGoForward", \
"canGoBack", \
"dataDetectorTypes", \
"scrollEnabled", \
"scrollCanBounce" \
]
--
public constant kMCBrowserNavigationTypeFollowLink is 0
public constant kMCBrowserNavigationTypeSubmitForm is 1
public constant kMCBrowserNavigationTypeBackForward is 2
public constant kMCBrowserNavigationTypeReload is 3
public constant kMCBrowserNavigationTypeResubmitForm is 4
public constant kMCBrowserNavigationTypeOther is 5
public constant kMCBrowserNavigationTypeMap is ["followLink", "submitForm", "backForward", "reload", "resubmitForm", "other"]
--
public constant kMCBrowserNavigationEventTypeNavigate is 0
public constant kMCBrowserNavigationEventTypeDocumentLoad is 1
public constant kMCBrowserNavigationEventTypeMap is ["navigate", "documentLoad"]
--
public constant kMCBrowserNavigationStateBegin is 0
public constant kMCBrowserNavigationStateComplete is 1
public constant kMCBrowserNavigationStateFailed is 2
public constant kMCBrowserNavigationStateUnhandled is 3
public constant kMCBrowserNavigationStateMap is ["begin", "complete", "failed", "unhandled"]
--
-- constant kStringProps is ["url", "htmlText", "userAgent", "javaScriptHandlers"]
-- TODO - replace literal values with constants when possible
constant kStringProps is [6, 7, 8, 9]
-- constant kBoolProps is [ \
-- "verticalScrollbarEnabled", \
-- "horizontalScrollbarEnabled", \
-- "allowNewWindows", \
-- "enableContextMenu", \
-- "allowUserInteraction", \
-- "isSecure", \
-- "delayRequests", \
-- "allowsInlineMediaPlayback", \
-- "mediaPlaybackRequiresUserAction", \
-- "autoFit", \
-- "canGoForward", \
-- "canGoBack", \
-- "scrollEnabled", \
-- "scrollCanBounce", \
--]
-- TODO - replace literal values with constants when possible
constant kBoolProps is [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 17, 18]
-- constant kIntProps is [ "dataDetectorTypes" ]
-- TODO - replace literal values with constants when possible
constant kIntProps is [ 16 ]
--------------------------------------------------------------------------------
public handler browserListToLCBList(in pBrowserList as MCBrowserListRef, out rList as List) returns Boolean
variable tList as List
put the empty list into tList
variable tCount as CUInt
unsafe
if not MCBrowserListGetSize(pBrowserList, tCount) then
log "couldn't get size"
return false
end if
end unsafe
variable tIndex
repeat with tIndex from 0 up to tCount - 1
variable tType as MCBrowserValueType
unsafe
if not MCBrowserListGetType(pBrowserList, tIndex, tType) then
log "couldn't get type of %@" with [tIndex]
return false
end if
end unsafe
if tType is kMCBrowserValueTypeBoolean then
variable tBoolean as CBool
unsafe
if not MCBrowserListGetBoolean(pBrowserList, tIndex, tBoolean) then
log "couldn't get boolean %@" with [tIndex]
return false
end if
end unsafe
push tBoolean onto tList
else if tType is kMCBrowserValueTypeInteger then
variable tInteger as CInt
unsafe
if not MCBrowserListGetInteger(pBrowserList, tIndex, tInteger) then
log "couldn't get integer %@" with [tIndex]
return false
end if
end unsafe
push tInteger onto tList
else if tType is kMCBrowserValueTypeDouble then
variable tDouble as CDouble
unsafe
if not MCBrowserListGetDouble(pBrowserList, tIndex, tDouble) then
log "couldn't get double %@" with [tIndex]
return false
end if
end unsafe
push tDouble onto tList
else if tType is kMCBrowserValueTypeUTF8String then
variable tUTF8String as ZStringNative
unsafe
if not MCBrowserListGetUTF8String(pBrowserList, tIndex, tUTF8String) then
log "couldn't get string %@" with [tIndex]
return false
end if
end unsafe
push tUTF8String onto tList
else if tType is kMCBrowserValueTypeList then
variable tBrowserList as MCBrowserListRef
unsafe
if not MCBrowserListGetList(pBrowserList, tIndex, tBrowserList) then
log "couldn't get list %@" with [tIndex]
return false
end if
end unsafe
variable tConvertedList as List
if not browserListToLCBList(tBrowserList, tConvertedList) then
log "couldn't convert list %@" with [tIndex]
return false
end if
push tConvertedList onto tList
else if tType is kMCBrowserValueTypeDictionary then
variable tBrowserDict as MCBrowserDictionaryRef
unsafe
if not MCBrowserListGetDictionary(pBrowserList, tIndex, tBrowserDict) then
log "couldn't get dictionary %@" with [tIndex]
return false
end if
end unsafe
variable tConvertedDict as Array
if not browserDictionaryToLCBArray(tBrowserDict, tConvertedDict) then
log "couldn't convert dictionary %@" with [tIndex]
return false
end if
push tConvertedDict onto tList
else
log "unrecognised type %@" with [tType]
return false
end if
end repeat
put tList into rList
return true
end handler
public handler browserDictionaryToLCBArray(in pBrowserDict as MCBrowserDictionaryRef, out rArray as Array) returns Boolean
variable tArray as Array
put the empty array into tArray
variable tCount as CUInt
unsafe
if not MCBrowserDictionaryGetKeyCount(pBrowserDict, tCount) then
log "couldn't get size"
return false
end if
end unsafe
variable tIndex
repeat with tIndex from 0 up to tCount - 1
variable tKey as String
unsafe
if not MCBrowserDictionaryGetKey(pBrowserDict, tIndex, tKey) then
log "couldn't get key of %@" with [tIndex]
return false
end if
end unsafe
variable tType as MCBrowserValueType
unsafe
if not MCBrowserDictionaryGetType(pBrowserDict, tKey, tType) then
log "couldn't get type of %@" with [tIndex]
return false
end if
end unsafe
if tType is kMCBrowserValueTypeBoolean then
variable tBoolean as CBool
unsafe
if not MCBrowserDictionaryGetBoolean(pBrowserDict, tKey, tBoolean) then
log "couldn't get boolean %@" with [tIndex]
return false
end if
end unsafe
put tBoolean into tArray[tKey]
else if tType is kMCBrowserValueTypeInteger then
variable tInteger as CInt
unsafe
if not MCBrowserDictionaryGetInteger(pBrowserDict, tKey, tInteger) then
log "couldn't get integer %@" with [tIndex]
return false
end if
end unsafe
put tInteger into tArray[tKey]
else if tType is kMCBrowserValueTypeDouble then
variable tDouble as CDouble
unsafe
if not MCBrowserDictionaryGetDouble(pBrowserDict, tKey, tDouble) then
log "couldn't get double %@" with [tIndex]
return false
end if
end unsafe
put tDouble into tArray[tKey]
else if tType is kMCBrowserValueTypeUTF8String then
variable tUTF8String as ZStringNative
unsafe
if not MCBrowserDictionaryGetUTF8String(pBrowserDict, tKey, tUTF8String) then
log "couldn't get string %@" with [tIndex]
return false
end if
end unsafe
put tUTF8String into tArray[tKey]
else if tType is kMCBrowserValueTypeList then
variable tBrowserList as MCBrowserListRef
unsafe
if not MCBrowserDictionaryGetList(pBrowserDict, tKey, tBrowserList) then
log "couldn't get list %@" with [tIndex]
return false
end if
end unsafe
variable tConvertedList as List
if not browserListToLCBList(tBrowserList, tConvertedList) then
log "couldn't convert list %@" with [tIndex]
return false
end if
put tConvertedList into tArray[tKey]
else if tType is kMCBrowserValueTypeDictionary then
variable tBrowserDict as MCBrowserDictionaryRef
unsafe
if not MCBrowserDictionaryGetDictionary(pBrowserDict, tKey, tBrowserDict) then
log "couldn't get dictionary %@" with [tIndex]
return false
end if
end unsafe
variable tConvertedDict as Array
if not browserDictionaryToLCBArray(tBrowserDict, tConvertedDict) then
log "couldn't convert dictionary %@" with [tIndex]
return false
end if
put tConvertedDict into tArray[tKey]
else
log "unrecognised type %@" with [tType]
return false
end if
end repeat
put tArray into rArray
return true
end handler
----------
private handler browserLookupProperty(in pProp as String) returns MCBrowserProperty
variable tIndex as optional Integer
put the index of pProp in kMCBrowserPropertyMap into tIndex
if tIndex is 0 then
throw "Unknown property: " & pProp
end if
return tIndex - 1
end handler
----------
public handler browserGetEnumProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as optional any) returns Boolean
unsafe
if pProperty is in kStringProps then
return MCBrowserGetStringProperty(pBrowser, pProperty, rValue)
else if pProperty is in kBoolProps then
return MCBrowserGetBoolProperty(pBrowser, pProperty, rValue)
else if pProperty is in kIntProps then
return MCBrowserGetIntegerProperty(pBrowser, pProperty, rValue)
end if
end unsafe
return false
end handler
public handler browserGetProperty(in pBrowser as MCBrowserRef, in pProperty as String) returns any
variable tValue as any
if not browserGetEnumProperty(pBrowser, browserLookupProperty(pProperty), tValue) then
throw "Error retrieving browser property: " & pProperty
end if
return tValue
end handler
public handler browserSetEnumProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as any) returns Boolean
unsafe
if pProperty is in kStringProps then
return MCBrowserSetStringProperty(pBrowser, pProperty, pValue)
else if pProperty is in kBoolProps then
return MCBrowserSetBoolProperty(pBrowser, pProperty, pValue)
else if pProperty is in kIntProps then
return MCbrowserSetIntegerProperty(pBrowser, pProperty, pValue)
end if
end unsafe
return false
end handler
public handler browserSetProperty(in pBrowser as MCBrowserRef, in pProperty as String, in pValue as any)
variable tValue as any
if not browserSetEnumProperty(pBrowser, browserLookupProperty(pProperty), pValue) then
throw "Error setting browser property: " & pProperty
end if
end handler
----------
public foreign handler MCEngineBrowserLibrarySetupRunloop() returns CBool binds to "<builtin>"
public foreign handler MCEngineBrowserLibraryTeardownRunloop() returns nothing binds to "<builtin>"
private variable mInitialized as optional Boolean
public handler libbrowserInit() returns nothing
if mInitialized is not nothing then
return
end if
unsafe
MCEngineBrowserLibrarySetupRunloop()
end unsafe
put true into mInitialized
end handler
----------
end module