0
# Legacy WebKit Components
1
2
This document covers the original WebView component and related classes that provide backward compatibility with older WebKit functionality. While these components have been superseded by the modern WKWebView system, they are still available and provide additional capabilities for DOM manipulation and legacy application support.
3
4
## Core Legacy WebView
5
6
### WebView Class
7
8
The original WebKit web view component for displaying web content.
9
10
```python { .api }
11
class WebView:
12
def initWithFrame_frameName_groupName_(self, frame, frameName, groupName):
13
"""Initialize web view with frame, frame name, and group name."""
14
15
def canShowMIMEType_(self, MIMEType):
16
"""Check if the specified MIME type can be displayed."""
17
18
def goBack(self):
19
"""Navigate to the previous page in history."""
20
21
def goForward(self):
22
"""Navigate to the next page in history."""
23
24
def canGoBack(self):
25
"""Check if backward navigation is possible."""
26
27
def canGoForward(self):
28
"""Check if forward navigation is possible."""
29
30
def searchFor_direction_caseSensitive_wrap_(self, string, forward, caseFlag, wrapFlag):
31
"""Search for text within the page with options for direction, case sensitivity, and wrapping."""
32
33
def isLoading(self):
34
"""Check if the web view is currently loading content."""
35
36
def setDrawsBackground_(self, flag):
37
"""Control whether the web view draws its background."""
38
39
def drawsBackground(self):
40
"""Get the current background drawing state."""
41
42
def mainFrame(self):
43
"""Get the main frame of the web view."""
44
45
def selectedFrame(self):
46
"""Get the currently selected frame."""
47
48
def backForwardList(self):
49
"""Get the back/forward list for navigation history."""
50
51
def setMaintainsBackForwardList_(self, flag):
52
"""Set whether to maintain a back/forward list."""
53
54
def setHostWindow_(self, hostWindow):
55
"""Set the host window for the web view."""
56
57
def hostWindow(self):
58
"""Get the host window of the web view."""
59
60
def setGroupName_(self, groupName):
61
"""Set the group name for resource sharing."""
62
63
def groupName(self):
64
"""Get the group name."""
65
66
def estimatedProgress(self):
67
"""Get the estimated loading progress (0.0 to 1.0)."""
68
69
def isEditable(self):
70
"""Check if the web view content is editable."""
71
72
def setEditable_(self, flag):
73
"""Set the editable state of the web view."""
74
75
def setUIDelegate_(self, delegate):
76
"""Set the UI delegate for handling user interface callbacks."""
77
78
def UIDelegate(self):
79
"""Get the current UI delegate."""
80
81
def setResourceLoadDelegate_(self, delegate):
82
"""Set the resource load delegate for handling resource loading."""
83
84
def resourceLoadDelegate(self):
85
"""Get the current resource load delegate."""
86
87
def setDownloadDelegate_(self, delegate):
88
"""Set the download delegate for handling file downloads."""
89
90
def downloadDelegate(self):
91
"""Get the current download delegate."""
92
93
def setFrameLoadDelegate_(self, delegate):
94
"""Set the frame load delegate for handling frame loading events."""
95
96
def frameLoadDelegate(self):
97
"""Get the current frame load delegate."""
98
99
def setPolicyDelegate_(self, delegate):
100
"""Set the policy delegate for handling navigation policies."""
101
102
def policyDelegate(self):
103
"""Get the current policy delegate."""
104
105
def setPreferences_(self, preferences):
106
"""Set the preferences for the web view."""
107
108
def preferences(self):
109
"""Get the current preferences."""
110
111
def setPreferencesIdentifier_(self, anIdentifier):
112
"""Set the preferences identifier for shared preferences."""
113
114
def preferencesIdentifier(self):
115
"""Get the preferences identifier."""
116
117
def setCustomUserAgent_(self, userAgent):
118
"""Set a custom user agent string."""
119
120
def customUserAgent(self):
121
"""Get the custom user agent string."""
122
123
def userAgentForURL_(self, URL):
124
"""Get the user agent string for a specific URL."""
125
126
def supportsTextEncoding(self):
127
"""Check if text encoding changes are supported."""
128
129
def setCustomTextEncodingName_(self, encodingName):
130
"""Set a custom text encoding name."""
131
132
def customTextEncodingName(self):
133
"""Get the custom text encoding name."""
134
135
def setApplicationNameForUserAgent_(self, applicationName):
136
"""Set the application name for the user agent string."""
137
138
def applicationNameForUserAgent(self):
139
"""Get the application name from the user agent."""
140
141
def setMediaStyle_(self, mediaStyle):
142
"""Set the media style for CSS media queries."""
143
144
def mediaStyle(self):
145
"""Get the current media style."""
146
147
def stringByEvaluatingJavaScriptFromString_(self, script):
148
"""Execute JavaScript and return the result as a string."""
149
150
def windowScriptObject(self):
151
"""Get the window script object for JavaScript interaction."""
152
```
153
154
## Web Preferences
155
156
Configuration settings for WebView behavior.
157
158
```python { .api }
159
class WebPreferences:
160
def init(self):
161
"""Initialize web preferences with default settings."""
162
163
def initWithIdentifier_(self, anIdentifier):
164
"""Initialize with a specific identifier for shared preferences."""
165
166
def identifier(self):
167
"""Get the preferences identifier."""
168
169
def setStandardFontFamily_(self, family):
170
"""Set the standard font family."""
171
172
def standardFontFamily(self):
173
"""Get the standard font family."""
174
175
def setFixedFontFamily_(self, family):
176
"""Set the fixed-width font family."""
177
178
def fixedFontFamily(self):
179
"""Get the fixed-width font family."""
180
181
def setSerifFontFamily_(self, family):
182
"""Set the serif font family."""
183
184
def serifFontFamily(self):
185
"""Get the serif font family."""
186
187
def setSansSerifFontFamily_(self, family):
188
"""Set the sans-serif font family."""
189
190
def sansSerifFontFamily(self):
191
"""Get the sans-serif font family."""
192
193
def setCursiveFontFamily_(self, family):
194
"""Set the cursive font family."""
195
196
def cursiveFontFamily(self):
197
"""Get the cursive font family."""
198
199
def setFantasyFontFamily_(self, family):
200
"""Set the fantasy font family."""
201
202
def fantasyFontFamily(self):
203
"""Get the fantasy font family."""
204
205
def setDefaultFontSize_(self, size):
206
"""Set the default font size."""
207
208
def defaultFontSize(self):
209
"""Get the default font size."""
210
211
def setDefaultFixedFontSize_(self, size):
212
"""Set the default fixed font size."""
213
214
def defaultFixedFontSize(self):
215
"""Get the default fixed font size."""
216
217
def setMinimumFontSize_(self, size):
218
"""Set the minimum font size."""
219
220
def minimumFontSize(self):
221
"""Get the minimum font size."""
222
223
def setMinimumLogicalFontSize_(self, size):
224
"""Set the minimum logical font size."""
225
226
def minimumLogicalFontSize(self):
227
"""Get the minimum logical font size."""
228
229
def setDefaultTextEncodingName_(self, encoding):
230
"""Set the default text encoding name."""
231
232
def defaultTextEncodingName(self):
233
"""Get the default text encoding name."""
234
235
def setUserStyleSheetEnabled_(self, flag):
236
"""Enable or disable user style sheet."""
237
238
def userStyleSheetEnabled(self):
239
"""Check if user style sheet is enabled."""
240
241
def setUserStyleSheetLocation_(self, URL):
242
"""Set the location of the user style sheet."""
243
244
def userStyleSheetLocation(self):
245
"""Get the user style sheet location."""
246
247
def setJavaEnabled_(self, flag):
248
"""Enable or disable Java support."""
249
250
def isJavaEnabled(self):
251
"""Check if Java is enabled."""
252
253
def setJavaScriptEnabled_(self, flag):
254
"""Enable or disable JavaScript."""
255
256
def isJavaScriptEnabled(self):
257
"""Check if JavaScript is enabled."""
258
259
def setJavaScriptCanOpenWindowsAutomatically_(self, flag):
260
"""Set whether JavaScript can open windows automatically."""
261
262
def javaScriptCanOpenWindowsAutomatically(self):
263
"""Check if JavaScript can open windows automatically."""
264
265
def setPlugInsEnabled_(self, flag):
266
"""Enable or disable plugins."""
267
268
def arePlugInsEnabled(self):
269
"""Check if plugins are enabled."""
270
271
def setAllowsAnimatedImages_(self, flag):
272
"""Set whether animated images are allowed."""
273
274
def allowsAnimatedImages(self):
275
"""Check if animated images are allowed."""
276
277
def setAllowsAnimatedImageLooping_(self, flag):
278
"""Set whether animated image looping is allowed."""
279
280
def allowsAnimatedImageLooping(self):
281
"""Check if animated image looping is allowed."""
282
283
def setLoadsImagesAutomatically_(self, flag):
284
"""Set whether images load automatically."""
285
286
def loadsImagesAutomatically(self):
287
"""Check if images load automatically."""
288
289
def setAutosaves_(self, flag):
290
"""Set whether preferences autosave."""
291
292
def autosaves(self):
293
"""Check if preferences autosave."""
294
295
def setShouldPrintBackgrounds_(self, flag):
296
"""Set whether backgrounds should print."""
297
298
def shouldPrintBackgrounds(self):
299
"""Check if backgrounds should print."""
300
301
def setPrivateBrowsingEnabled_(self, flag):
302
"""Enable or disable private browsing."""
303
304
def privateBrowsingEnabled(self):
305
"""Check if private browsing is enabled."""
306
307
def setTabsToLinks_(self, flag):
308
"""Set whether tab key moves to links."""
309
310
def tabsToLinks(self):
311
"""Check if tab key moves to links."""
312
313
def setUsesPageCache_(self, flag):
314
"""Set whether to use page cache."""
315
316
def usesPageCache(self):
317
"""Check if page cache is used."""
318
319
def setCacheModel_(self, cacheModel):
320
"""Set the cache model."""
321
322
def cacheModel(self):
323
"""Get the cache model."""
324
325
def setSuppressIncrementalRendering_(self, flag):
326
"""Set whether to suppress incremental rendering."""
327
328
def suppressIncrementalRendering(self):
329
"""Check if incremental rendering is suppressed."""
330
```
331
332
## WebScript Object Interface
333
334
Interface between JavaScript and Python objects in legacy WebView.
335
336
```python { .api }
337
class WebScriptObject:
338
def callWebScriptMethod_withArguments_(self, name, arguments):
339
"""Call a JavaScript method with arguments."""
340
341
def evaluateWebScript_(self, script):
342
"""Evaluate JavaScript code."""
343
344
def setWebScriptValueAtIndex_value_(self, index, value):
345
"""Set a JavaScript array element value."""
346
347
def webScriptValueAtIndex_(self, index):
348
"""Get a JavaScript array element value."""
349
350
def setException_(self, description):
351
"""Set a JavaScript exception."""
352
353
def stringRepresentation(self):
354
"""Get string representation of the object."""
355
356
def JSObject(self):
357
"""Get the underlying JavaScript object."""
358
```
359
360
## Navigation Constants
361
362
Legacy navigation type constants for WebView.
363
364
```python { .api }
365
# Web Navigation Types (Legacy)
366
WebNavigationTypeLinkClicked = 0
367
WebNavigationTypeFormSubmitted = 1
368
WebNavigationTypeBackForward = 2
369
WebNavigationTypeReload = 3
370
WebNavigationTypeFormResubmitted = 4
371
WebNavigationTypeOther = 5
372
```
373
374
## Usage Example
375
376
```python
377
import WebKit
378
from Foundation import NSRect, NSURL, NSURLRequest
379
380
# Create web view with legacy WebView
381
frame = NSRect((0, 0), (800, 600))
382
web_view = WebKit.WebView.alloc().initWithFrame_frameName_groupName_(
383
frame, None, None
384
)
385
386
# Configure preferences
387
prefs = WebKit.WebPreferences.alloc().init()
388
prefs.setJavaScriptEnabled_(True)
389
prefs.setJavaEnabled_(False)
390
web_view.setPreferences_(prefs)
391
392
# Load a URL
393
url = NSURL.URLWithString_("https://www.example.com")
394
request = NSURLRequest.requestWithURL_(url)
395
web_view.mainFrame().loadRequest_(request)
396
397
# Execute JavaScript
398
result = web_view.stringByEvaluatingJavaScriptFromString_("document.title")
399
print(f"Page title: {result}")
400
```
401
402
## Migration Notes
403
404
When migrating from legacy WebView to modern WKWebView:
405
406
- Replace `WebView` with `WKWebView`
407
- Use `WKWebViewConfiguration` instead of `WebPreferences`
408
- Replace `stringByEvaluatingJavaScriptFromString_` with `evaluateJavaScript_completionHandler_`
409
- Update delegate protocols to WK-prefixed equivalents
410
- Consider security implications of the new process model
411
412
Legacy WebView components are maintained for backward compatibility but new development should use the modern WKWebView system whenever possible.