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

Commit 0485c50

Browse files
Merge pull request livecode#7222 from livecodeian/feature-libbrowser-wkwebview
[[ libbrowser ]] Update iOS browser implementation to use WKWebView
2 parents c6a7bb7 + 114f494 commit 0485c50

29 files changed

+2894
-871
lines changed

docs/dictionary/command/mobileControlDo.lcdoc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,16 @@ are defined in the <action> listing section below.
5353
**<action> listing: **
5454

5555
**Browser Specific Actions**
56-
- "advance": Move forward through the history (wraps the goForward
57-
method of UIWebView).
58-
- "retreat": Move backward through the history (wraps the goBack
59-
method of UIWebView).
60-
- "reload": Reload the current page (wraps the reload method of
61-
UIWebView).
62-
- "stop": Stop loading the current page (wraps the stopLoading method
63-
of UIWebView).
56+
- "advance": Move forward through the history.
57+
- "retreat": Move backward through the history.
58+
- "reload": Reload the current page.
59+
- "stop": Stop loading the current page.
6460
- "load", *baseUrl*, *htmlText*: Loads as page consisting of the given
65-
htmlText with the given baseUrl (wraps theloadHtmlString method of
66-
UIWebView). Takes the following additional parameters:
61+
htmlText with the given baseUrl. Takes the following additional parameters:
6762
- *baseUrl*
6863
- "*htmlText*
6964
- "execute", *script*: <evaluate|Evaluates> the given JavaScript script in the
70-
context of the current page (wraps the
71-
stringByEvaluationJavaScriptFromString method of UIWebView). Takes
72-
the following additional parameter:
65+
context of the current page. Takes the following additional parameter:
7366
- *script*
7467

7568
**Scroller Specific Actions (iOS Only)**

docs/dictionary/command/mobileControlSet.lcdoc

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,14 @@ control is no longer on the current view.
7373

7474
- "URL": the URL to be loaded into the web-view.
7575
- "autoFit" (iOS Only): set to true or false to determine whether the
76-
page is scaled to fit the rect of the control (wraps the scalesPageToFit
77-
property of UIWebView).
76+
page is scaled to fit the rect of the control.
7877

7978
- "delayRequests" (iOS Only): set to true to cause the loadRequest
80-
message to be sent. Note: In this mode, web-pages that trigger
81-
sub-document loads (such as those containing iframes) do not load
82-
correctly.
79+
message to be sent.
8380

8481
- "dataDetectorTypes" (iOS Only): Use this property to specify the types
8582
of data that should be automatically converted to clickable URLs in the
86-
web-view. This property wraps the dataDetectorTypes property of
87-
UIWebView. It is specified as a comma-delimited list of one or more of
83+
web-view. It is specified as a comma-delimited list of one or more of
8884
the following properties:
8985

9086
- "phone number":
@@ -94,14 +90,10 @@ the following properties:
9490

9591

9692
- "allowsInlinePlayback" (iOS Only): set to true if the web-view should
97-
allow media files to be played 'inline' in the page (wraps the
98-
allowsInlineMediaPlayback property of the UIWebView). This property is
99-
only available on iOS4.0 and later
93+
allow media files to be played 'inline' in the page.
10094

10195
- "mediaPlaybackRequiresUserAction" (iOS Only): set to false to allow
102-
media files to play automatically in the webview (wraps the
103-
mediaPlaybackRequiresUserAction property of the UIWebView). This
104-
property is only available on iOS4.0 and later.
96+
media files to play automatically in the webview.
10597

10698
- "scrollingEnabled": specifies whether or not the browser can be
10799
scrolled (boolean).

docs/dictionary/message/browserLoadRequest.lcdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Handle the <browserLoadRequest> message to perform an action when a URL
4141
has been requested.
4242

4343
The <browserLoadRequest> message is sent to the object containing the
44-
script that created the UIWebView browser control after a url has been
44+
script that created the mobile browser control after a url has been
4545
requested.
4646

4747
Not passing the message causes the load request to not go ahead.

docs/dictionary/message/browserLoadRequested.lcdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Handle the <browserLoadRequested> message to perform an action when a
3636
URL has been requested.
3737

3838
The <browserLoadRequested> message is sent to the object containing the
39-
script that created the UIWebView browser control after a url has been
39+
script that created the mobile browser control after a url has been
4040
requested and passed for loading.
4141

4242
If <delayRequests(command)> has been set to false,

docs/dictionary/object/iosBrowser.lcdoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Type: object
55
Syntax: iosBrowser
66

77
Summary:
8-
A native iOS control, UIWebView, that displays a browser.
8+
A native iOS control that displays a browser.
99

1010
Introduced: 4.5.3
1111

@@ -23,10 +23,11 @@ mobileControlSet sBrowserID, "visible", "true"
2323
mobileControlSet sBrowserID, "url", "http://www.livecode.com"
2424

2525
Description:
26-
An iosBrowser(UIWebView) control is created using a control type of
26+
An iosBrowser control is created using a control type of
2727
"browser".
2828

29-
>*Note:* For full details of what the UIWebView control is capable of,
29+
>*Note:* The iOS browser control is based on WKWebView.
30+
> For full details of what the WKWebView control is capable of,
3031
> and background about it see the iOS reference document.
3132

3233
References: mobileControlDelete (command), mobileControlDo (command),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Mobile browser control iOS update.
2+
3+
The mobile browser control has been updated to use the WebKit framework on iOS.
4+
This provides better performance on iOS devices.

engine/src/browser.lcb

Lines changed: 101 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ metadata version is "1.0.0"
4343
-- foreign types
4444
public type MCBrowserFactoryRef is Pointer
4545
public type MCBrowserRef is Pointer
46+
public type MCBrowserNavigationRequestRef is Pointer
4647

4748
public type MCBrowserListRef is Pointer
4849
public type MCBrowserDictionaryRef is Pointer
4950

5051
public type MCBrowserProperty is CInt
5152
public type MCBrowserValueType is CInt
52-
public type MCBrowserRequestType is CInt
53-
public type MCBrowserRequestState is CInt
53+
public type MCBrowserNavigationEventType is CInt
54+
public type MCBrowserNavigationState is CInt
55+
public type MCBrowserNavigationType is CInt
5456

5557
--
5658

@@ -74,17 +76,31 @@ public foreign handler MCBrowserGetNativeLayer(in pBrowser as MCBrowserRef) retu
7476

7577
public foreign handler MCBrowserGetBoolProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as CBool) returns CBool binds to "<builtin>"
7678
public foreign handler MCBrowserSetBoolProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as CBool) returns CBool binds to "<builtin>"
77-
7879
public foreign handler MCBrowserGetStringProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as ZStringUTF8) returns CBool binds to "<builtin>"
7980
public foreign handler MCBrowserSetStringProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as ZStringUTF8) returns CBool binds to "<builtin>"
81+
public foreign handler MCBrowserGetIntegerProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, out rValue as Int32) returns CBool binds to "<builtin>"
82+
public foreign handler MCBrowserSetIntegerProperty(in pBrowser as MCBrowserRef, in pProperty as MCBrowserProperty, in pValue as Int32) returns CBool binds to "<builtin>"
8083

8184
public foreign handler MCBrowserGoBack(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
8285
public foreign handler MCBrowserGoForward(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
8386
public foreign handler MCBrowserGoToURL(in pBrowser as MCBrowserRef, in pURL as ZStringUTF8) returns CBool binds to "<builtin>"
87+
public foreign handler MCBrowserLoadHTMLText(in pBrowser as MCBrowserRef, in pHTMLText as ZStringUTF8, in pBaseURL as ZStringUTF8) returns CBool binds to "<builtin>"
88+
public foreign handler MCBrowserStopLoading(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
89+
public foreign handler MCBrowserReload(in pBrowser as MCBrowserRef) returns CBool binds to "<builtin>"
8490
public foreign handler MCBrowserEvaluateJavaScript(in pBrowser as MCBrowserRef, in pScript as ZStringUTF8, out rResult as ZStringUTF8) returns CBool binds to "<builtin>"
8591

8692
----------
8793

94+
public foreign handler MCBrowserNavigationRequestRetain(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns MCBrowserNavigationRequestRef binds to "<builtin>"
95+
public foreign handler MCBrowserNavigationRequestRelease(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns nothing binds to "<builtin>"
96+
public foreign handler MCBrowserNavigationRequestGetURL(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef, out rURL as ZStringUTF8) returns CBool binds to "<builtin>"
97+
public foreign handler MCBrowserNavigationRequestGetNavigationType(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef, out rType as MCBrowserNavigationType) returns CBool binds to "<builtin>"
98+
public foreign handler MCBrowserNavigationRequestIsFrame(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef, out rIsFrame as CBool) returns CBool binds to "<builtin>"
99+
public foreign handler MCBrowserNavigationRequestContinue(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns CBool binds to "<builtin>"
100+
public foreign handler MCBrowserNavigationRequestCancel(in pBrowserNavigationRequestRef as MCBrowserNavigationRequestRef) returns CBool binds to "<builtin>"
101+
102+
----------
103+
88104
public foreign handler MCBrowserListGetSize(in pList as MCBrowserListRef, out rSize as UInt32) returns CBool binds to "<builtin>"
89105
public foreign handler MCBrowserListGetType(in pList as MCBrowserListRef, in pIndex as UInt32, out rType as MCBrowserValueType) returns CBool binds to "<builtin>"
90106
public foreign handler MCBrowserListGetBoolean(in pList as MCBrowserListRef, in pIndex as UInt32, out rValue as CBool) returns CBool binds to "<builtin>"
@@ -108,11 +124,13 @@ public foreign handler MCBrowserDictionaryGetUTF8String(in pDictionary as MCBrow
108124
public foreign handler MCBrowserDictionaryGetList(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as MCBrowserListRef) returns CBool binds to "<builtin>"
109125
public foreign handler MCBrowserDictionaryGetDictionary(in pDictionary as MCBrowserDictionaryRef, in pKey as ZStringUTF8, out rValue as MCBrowserDictionaryRef) returns CBool binds to "<builtin>"
110126

111-
public foreign handler type MCBrowserRequestCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pType as MCBrowserRequestType, in pState as MCBrowserRequestState, in pFrame as CBool, in pUrl as ZStringUTF8, in pError as optional ZStringUTF8) returns nothing
127+
public foreign handler type MCBrowserNavigationRequestCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pRequest as MCBrowserNavigationRequestRef) returns CBool
128+
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
112129
public foreign handler type MCBrowserJavaScriptCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pHandler as ZStringUTF8, in pParams as MCBrowserListRef) returns nothing
113130
public foreign handler type MCBrowserProgressCallback(in pContext as optional Pointer, in pBrowser as MCBrowserRef, in pUrl as ZStringUTF8, in pProgress as UInt32) returns nothing
114131

115-
public foreign handler MCBrowserSetRequestHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserRequestCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
132+
public foreign handler MCBrowserSetNavigationRequestHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserNavigationRequestCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
133+
public foreign handler MCBrowserSetNavigationHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserNavigationCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
116134
public foreign handler MCBrowserSetJavaScriptHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserJavaScriptCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
117135
public foreign handler MCBrowserSetProgressHandler(in pBrowser as MCBrowserRef, in pCallback as optional MCBrowserProgressCallback, in pContext as optional Pointer) returns CBool binds to "<builtin>"
118136

@@ -138,34 +156,93 @@ public constant kMCBrowserPropertyUrl is 6
138156
public constant kMCBrowserPropertyHtmlText is 7
139157
public constant kMCBrowserPropertyUserAgent is 8
140158
public constant kMCBrowserPropertyJavaScriptHandlers is 9
159+
public constant kMCBrowserPropertyiOSDelayRequests is 10
160+
public constant kMCBrowserPropertyiOSAllowsInlineMediaPlayback is 11
161+
public constant kMCBrowserPropertyiOSMediaPlaybackRequiresUserAction is 12
162+
public constant kMCBrowserPropertyiOSAutoFit is 13
163+
public constant kMCBrowserPropertyCanGoForward is 14
164+
public constant kMCBrowserPropertyCanGoBack is 15
165+
public constant kMCBrowserPropertyDataDetectorTypes is 16
166+
public constant kMCBrowserPropertyScrollEnabled is 17
167+
public constant kMCBrowserPropertyScrollCanBounce is 18
168+
169+
public constant kMCBrowserPropertyMap is [ \
170+
"verticalScrollbarEnabled", \
171+
"horizontalScrollbarEnabled", \
172+
"allowNewWindows", \
173+
"enableContextMenu", \
174+
"allowUserInteraction", \
175+
"isSecure", \
176+
"url", \
177+
"htmlText", \
178+
"userAgent", \
179+
"javaScriptHandlers", \
180+
"delayRequests", \
181+
"allowsInlineMediaPlayback", \
182+
"mediaPlaybackRequiresUserAction", \
183+
"autoFit", \
184+
"canGoForward", \
185+
"canGoBack", \
186+
"dataDetectorTypes", \
187+
"scrollEnabled", \
188+
"scrollCanBounce" \
189+
]
190+
191+
--
192+
193+
public constant kMCBrowserNavigationTypeFollowLink is 0
194+
public constant kMCBrowserNavigationTypeSubmitForm is 1
195+
public constant kMCBrowserNavigationTypeBackForward is 2
196+
public constant kMCBrowserNavigationTypeReload is 3
197+
public constant kMCBrowserNavigationTypeResubmitForm is 4
198+
public constant kMCBrowserNavigationTypeOther is 5
141199

142-
public constant kMCBrowserPropertyMap is ["verticalScrollbarEnabled", "horizontalScrollbarEnabled", "allowNewWindows", "enableContextMenu", "allowUserInteraction", "isSecure", "url", "htmlText", "userAgent", "javaScriptHandlers"]
200+
public constant kMCBrowserNavigationTypeMap is ["followLink", "submitForm", "backForward", "reload", "resubmitForm", "other"]
143201

144202
--
145203

146-
public constant kMCBrowserRequestTypeNavigate is 0
147-
public constant kMCBrowserRequestTypeDocumentLoad is 1
204+
public constant kMCBrowserNavigationEventTypeNavigate is 0
205+
public constant kMCBrowserNavigationEventTypeDocumentLoad is 1
148206

149-
public constant kMCBrowserRequestTypeMap is ["navigate", "documentLoad"]
207+
public constant kMCBrowserNavigationEventTypeMap is ["navigate", "documentLoad"]
150208

151209
--
152210

153-
public constant kMCBrowserRequestStateBegin is 0
154-
public constant kMCBrowserRequestStateComplete is 1
155-
public constant kMCBrowserRequestStateFailed is 2
156-
public constant kMCBrowserRequestStateUnhandled is 3
211+
public constant kMCBrowserNavigationStateBegin is 0
212+
public constant kMCBrowserNavigationStateComplete is 1
213+
public constant kMCBrowserNavigationStateFailed is 2
214+
public constant kMCBrowserNavigationStateUnhandled is 3
157215

158-
public constant kMCBrowserRequestStateMap is ["begin", "complete", "failed", "unhandled"]
216+
public constant kMCBrowserNavigationStateMap is ["begin", "complete", "failed", "unhandled"]
159217

160218
--
161219

162220
-- constant kStringProps is ["url", "htmlText", "userAgent", "javaScriptHandlers"]
163221
-- TODO - replace literal values with constants when possible
164222
constant kStringProps is [6, 7, 8, 9]
165223

166-
-- constant kBoolProps is ["verticalScrollbarEnabled", "horizontalScrollbarEnabled", "allowNewWindows", "enableContextMenu", "allowUserInteraction", "isSecure"]
224+
-- constant kBoolProps is [ \
225+
-- "verticalScrollbarEnabled", \
226+
-- "horizontalScrollbarEnabled", \
227+
-- "allowNewWindows", \
228+
-- "enableContextMenu", \
229+
-- "allowUserInteraction", \
230+
-- "isSecure", \
231+
-- "delayRequests", \
232+
-- "allowsInlineMediaPlayback", \
233+
-- "mediaPlaybackRequiresUserAction", \
234+
-- "autoFit", \
235+
-- "canGoForward", \
236+
-- "canGoBack", \
237+
-- "scrollEnabled", \
238+
-- "scrollCanBounce", \
239+
--]
167240
-- TODO - replace literal values with constants when possible
168-
constant kBoolProps is [0, 1, 2, 3, 4, 5]
241+
constant kBoolProps is [0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 17, 18]
242+
243+
-- constant kIntProps is [ "dataDetectorTypes" ]
244+
-- TODO - replace literal values with constants when possible
245+
constant kIntProps is [ 16 ]
169246

170247
--------------------------------------------------------------------------------
171248

@@ -392,6 +469,8 @@ public handler browserGetEnumProperty(in pBrowser as MCBrowserRef, in pProperty
392469
return MCBrowserGetStringProperty(pBrowser, pProperty, rValue)
393470
else if pProperty is in kBoolProps then
394471
return MCBrowserGetBoolProperty(pBrowser, pProperty, rValue)
472+
else if pProperty is in kIntProps then
473+
return MCBrowserGetIntegerProperty(pBrowser, pProperty, rValue)
395474
end if
396475
end unsafe
397476

@@ -413,6 +492,8 @@ public handler browserSetEnumProperty(in pBrowser as MCBrowserRef, in pProperty
413492
return MCBrowserSetStringProperty(pBrowser, pProperty, pValue)
414493
else if pProperty is in kBoolProps then
415494
return MCBrowserSetBoolProperty(pBrowser, pProperty, pValue)
495+
else if pProperty is in kIntProps then
496+
return MCbrowserSetIntegerProperty(pBrowser, pProperty, pValue)
416497
end if
417498
end unsafe
418499

@@ -428,39 +509,18 @@ end handler
428509

429510
----------
430511

431-
private variable mInitialized as optional Boolean
432-
433-
private variable mRunloopAction as MCRunloopActionRef
434-
private variable mWaitHandler
512+
public foreign handler MCEngineBrowserLibrarySetupRunloop() returns CBool binds to "<builtin>"
513+
public foreign handler MCEngineBrowserLibraryTeardownRunloop() returns nothing binds to "<builtin>"
435514

436-
/* TODO - need to provide a wrapper handler here as we can't (yet) get a pointer to a foreign native handler */
437-
private unsafe handler doWait() returns CBool
438-
MCEngineRunloopWait()
439-
return true
440-
end handler
441-
442-
private unsafe handler doBreakWait() returns nothing
443-
MCEngineRunloopBreakWait()
444-
end handler
515+
private variable mInitialized as optional Boolean
445516

446517
public handler libbrowserInit() returns nothing
447518
if mInitialized is not nothing then
448519
return
449520
end if
450521

451522
unsafe
452-
if not MCBrowserLibraryInitialize() then
453-
return
454-
end if
455-
456-
MCBrowserLibrarySetWaitFunction(doWait)
457-
MCBrowserLibrarySetBreakWaitFunction(doBreakWait)
458-
459-
variable tCallback as MCRunloopActionCallback
460-
variable tContext as optional Pointer
461-
if MCBrowserLibraryGetRunloopCallback(tCallback, tContext) then
462-
MCEngineAddRunloopAction(tCallback, tContext, mRunloopAction)
463-
end if
523+
MCEngineBrowserLibrarySetupRunloop()
464524
end unsafe
465525

466526
put true into mInitialized

0 commit comments

Comments
 (0)