Debian Codegraph @

webview/platforms/android/jclass/webkit.py

raw
1 __all__ = (
2 'PyWebViewClient',
3 'PyWebChromeClient',
4 'PyJavascriptInterface',
5 'CookieManager',
6 'WebView',
7 )
8
9 from jnius import (
10 JavaClass,
11 JavaMethod,
12 JavaMultipleMethod,
13 JavaStaticField,
14 JavaStaticMethod,
15 MetaJavaClass,
16 )
17
18
19 class PyWebViewClient(JavaClass, metaclass=MetaJavaClass):
20 """
21 Represents a Java WebView client wrapper for interaction with Python.
22
23 This class serves as a bridge between a Java WebView client in the Android
24 platform and Python. It allows setting callbacks for events and intercepting
25 requests, enabling Python code to handle Java WebView behaviors dynamically.
26
27 Attributes:
28 __javaclass__: str
29 The fully qualified Java class name for the associated Java object.
30
31 Methods:
32 setCallback:
33 Sets the callback wrapper to handle specific WebView events, along
34 with an option to decide whether to enable or disable a specific
35 callback mechanism.
36
37 setRequestInterceptor:
38 Sets a request interceptor to manage and modify WebView requests
39 before they are processed.
40 """
41
42 __javaclass__ = 'com/pywebview/PyWebViewClient'
43 setCallback = JavaMethod('(Lcom/pywebview/EventCallbackWrapper;Z)V')
44 setRequestInterceptor = JavaMethod('(Lcom/pywebview/WebViewRequestInterceptor;)V')
45
46
47 class PyWebChromeClient(JavaClass, metaclass=MetaJavaClass):
48 """
49 Handles communication with the WebView's JavaScript environment.
50
51 The PyWebChromeClient class acts as a bridge between JavaScript running in a WebView
52 and the Python environment. By defining methods that handle JavaScript interactions,
53 such as alert dialogs and confirmation dialogs, this class provides mechanisms
54 to integrate JavaScript behaviors into Python-based applications.
55
56 Attributes:
57 __javaclass__: The fully qualified class name of the Java class that this Python
58 bridge wraps for interaction.
59
60 Methods:
61 setCallback: Sets the callback mechanism for handling JavaScript events. Takes an
62 EventCallbackWrapper as an argument.
63 onJsAlert: Handles JavaScript alert dialogs presented within a WebView. It processes
64 the dialog content and determines whether the alert is handled in
65 the Python environment.
66 onJsConfirm: Handles JavaScript confirmation dialogs within a WebView, allowing the
67 Python application to process the user's response to the dialog.
68 """
69
70 __javaclass__ = 'com/pywebview/PyWebChromeClient'
71 setCallback = JavaMethod('(Lcom/pywebview/EventCallbackWrapper;)V')
72
73
74 class PyJavascriptInterface(JavaClass, metaclass=MetaJavaClass):
75 """
76 Interface that acts as a bridge between Python and the JavaScript context.
77
78 This class provides methods to set a callback and to handle JavaScript
79 calls by interfacing with the Java-based functionality. It enables
80 interactions between Python code and JavaScript running on a web view or
81 similar component by defining Java methods that can be invoked from
82 JavaScript.
83
84 Attributes:
85 __javaclass__ (str): Represents the Java class path of the associated
86 Java implementation.
87
88 Methods:
89 setCallback: Registers a JavaScript API callback wrapper to handle
90 responses from JavaScript to Python.
91 call: Executes a specified JavaScript function with provided context
92 and arguments.
93 """
94
95 __javaclass__ = 'com/pywebview/PyJavascriptInterface'
96 setCallback = JavaMethod('(Lcom/pywebview/JsApiCallbackWrapper;)V')
97 call = JavaMethod('(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V')
98
99
100 class CookieManager(JavaClass, metaclass=MetaJavaClass):
101 """
102 Manages browser cookies for the WebView component and provides methods for
103 cookie handling.
104
105 The CookieManager class offers a variety of methods to control HTTP cookie
106 management within a WebView environment. Using this class, you can query,
107 set, accept, and delete cookies, as well as enable or disable the acceptance
108 of third-party or file-scheme cookies. Cookie management features are essential
109 for maintaining session persistence and enforcing privacy policies in web views
110 embedded within Android applications.
111
112 Attributes:
113 __javaclass__ (str): Specifies the underlying Java class representation
114 of the `android.webkit.CookieManager`.
115
116 Methods:
117 getInstance(): Retrieves the singleton instance of the CookieManager.
118
119 setAcceptCookie(accept: bool): Sets whether the WebView should accept
120 cookies globally.
121
122 acceptCookie(accept: bool): Checks whether the web environment accepts cookies.
123
124 setAcceptThirdPartyCookies(view, accept: bool): Determines whether the
125 specified WebView should accept third-party cookies.
126
127 acceptThirdPartyCookies(view): Indicates whether the given WebView accepts
128 third-party cookies.
129
130 setCookie(url: str, value: str, callback: Optional = None): Sets a cookie
131 for the specified URL, optionally performing an action asynchronously
132 upon completion.
133
134 getCookie(url: str): Retrieves the cookie(s) associated with the specified
135 URL.
136
137 removeSessionCookie(): Removes all session cookies synchronously.
138
139 removeSessionCookies(callback): Removes all session cookies asynchronously,
140 triggering the provided ValueCallback upon completion.
141
142 removeAllCookie(): Deletes all cookies synchronously.
143
144 removeAllCookies(callback): Deletes all cookies asynchronously, using the
145 provided ValueCallback to notify when the task is completed.
146
147 hasCookies(): Indicates whether any cookies are stored.
148
149 removeExpiredCookie(): Removes cookies that are no longer valid based on
150 their expiration attributes.
151
152 flush(): Forces synchronous writing of the cookie state to storage.
153
154 allowFileSchemeCookies(): Checks if cookies for file-scheme URLs are
155 accepted.
156
157 setAcceptFileSchemeCookies(accept: bool): Enables or disables the
158 acceptance of cookies for file-scheme URLs.
159 """
160
161 __javaclass__ = 'android/webkit/CookieManager'
162
163 getInstance = JavaStaticMethod('()Landroid/webkit/CookieManager;')
164 setAcceptCookie = JavaMethod('(Z)V')
165 acceptCookie = JavaMethod('()V')
166 setAcceptThirdPartyCookies = JavaMethod('(Landroid/webkit/WebView;Z)V')
167 acceptThirdPartyCookies = JavaMethod('(Landroid/webkit/WebView;)Z')
168 setCookie = JavaMultipleMethod(
169 [
170 ('(Ljava/lang/String;Ljava/lang/String;)V', False, False),
171 ('(Ljava/lang/String;Ljava/lang/String;Landroid/webkit/ValueCallback;)V', False, False),
172 ]
173 )
174 getCookie = JavaMethod('(Ljava/lang/String;)Ljava/lang/String;')
175 removeSessionCookie = JavaMethod('()V')
176 removeSessionCookies = JavaMethod('(Landroid/webkit/ValueCallback;)V')
177 removeAllCookie = JavaMethod('()V')
178 removeAllCookies = JavaMethod('(Landroid/webkit/ValueCallback;)V')
179 hasCookies = JavaMethod('()Z')
180 removeExpiredCookie = JavaMethod('()V')
181 flush = JavaMethod('()V')
182 allowFileSchemeCookies = JavaStaticMethod('()Z')
183 setAcceptFileSchemeCookies = JavaStaticMethod('(Z)V')
184
185
186 class WebView(JavaClass, metaclass=MetaJavaClass):
187 __javaclass__ = 'android/webkit/WebView'
188 __javaconstructor__ = [
189 ('(Landroid/content/Context;)V', False),
190 ('(Landroid/content/Context;Landroid/util/AttributeSet;)V', False),
191 ('(Landroid/content/Context;Landroid/util/AttributeSet;I)V', False),
192 ('(Landroid/content/Context;Landroid/util/AttributeSet;II)V', False),
193 ('(Landroid/content/Context;Landroid/util/AttributeSet;IZ)V', False),
194 ]
195
196 RENDERER_PRIORITY_BOUND = JavaStaticField('I')
197 RENDERER_PRIORITY_IMPORTANT = JavaStaticField('I')
198 RENDERER_PRIORITY_WAIVED = JavaStaticField('I')
199 SCHEME_GEO = JavaStaticField('Ljava/lang/String;')
200 SCHEME_MAILTO = JavaStaticField('Ljava/lang/String;')
201 SCHEME_TEL = JavaStaticField('Ljava/lang/String;')
202
203 setHorizontalScrollbarOverlay = JavaMethod('(Z)V')
204 setVerticalScrollbarOverlay = JavaMethod('(Z)V')
205 overlayHorizontalScrollbar = JavaMethod('()Z')
206 overlayVerticalScrollbar = JavaMethod('()Z')
207 getCertificate = JavaMethod('()Landroid/net/http/SslCertificate;')
208 setCertificate = JavaMethod('(Landroid/net/http/SslCertificate;)V')
209 savePassword = JavaMethod('(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V')
210 setHttpAuthUsernamePassword = JavaMethod(
211 '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V'
212 )
213 getHttpAuthUsernamePassword = JavaMethod(
214 '(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;'
215 )
216 destroy = JavaMethod('()V')
217 setNetworkAvailable = JavaMethod('(Z)V')
218 saveState = JavaMethod('(Landroid/os/Bundle;)Landroid/webkit/WebBackForwardList;')
219 restoreState = JavaMethod('(Landroid/os/Bundle;)Landroid/webkit/WebBackForwardList;')
220
221 loadUrl = JavaMultipleMethod(
222 [
223 ('(Ljava/lang/String;)V', False, False),
224 ('(Ljava/lang/String;Ljava/util/Map;)V', False, False),
225 ]
226 )
227
228 postUrl = JavaMethod('(Ljava/lang/String;[B)V')
229 loadData = JavaMethod('(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V')
230 loadDataWithBaseURL = JavaMethod(
231 '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V'
232 )
233 evaluateJavascript = JavaMethod('(Ljava/lang/String;Landroid/webkit/ValueCallback;)V')
234 saveWebArchive = JavaMultipleMethod(
235 [
236 ('(Ljava/lang/String;)V', False, False),
237 ('(Ljava/lang/String;ZLandroid/webkit/ValueCallback;)V', False, False),
238 ]
239 )
240 stopLoading = JavaMethod('()V')
241 reload = JavaMethod('()V')
242 canGoBack = JavaMethod('()Z')
243 goBack = JavaMethod('()V')
244 canGoForward = JavaMethod('()Z')
245 goForward = JavaMethod('()V')
246 canGoBackOrForward = JavaMethod('(I)Z')
247 goBackOrForward = JavaMethod('(I)V')
248 isPrivateBrowsingEnabled = JavaMethod('()Z')
249 pageUp = JavaMethod('(Z)Z')
250 pageDown = JavaMethod('(Z)Z')
251 postVisualStateCallback = JavaMethod('(JLandroid/webkit/WebView$VisualStateCallback;)V')
252 clearView = JavaMethod('()V')
253 capturePicture = JavaMethod('()Landroid/graphics/Picture;')
254 createPrintDocumentAdapter = JavaMultipleMethod(
255 [
256 ('()Landroid/print/PrintDocumentAdapter;', False, False),
257 ('(Ljava/lang/String;)Landroid/print/PrintDocumentAdapter;', False, False),
258 ]
259 )
260 getScale = JavaMethod('()F')
261 setInitialScale = JavaMethod('(I)V')
262 invokeZoomPicker = JavaMethod('()V')
263 getHitTestResult = JavaMethod('()Landroid/webkit/WebView$HitTestResult;')
264 requestFocusNodeHref = JavaMethod('(Landroid/os/Message;)V')
265 requestImageRef = JavaMethod('(Landroid/os/Message;)V')
266 getUrl = JavaMethod('()Ljava/lang/String;')
267 getOriginalUrl = JavaMethod('()Ljava/lang/String;')
268 getTitle = JavaMethod('()Ljava/lang/String;')
269 getFavicon = JavaMethod('()Landroid/graphics/Bitmap;')
270 getProgress = JavaMethod('()I')
271 getContentHeight = JavaMethod('()I')
272 getHeight = JavaMethod('()I')
273 getWidth = JavaMethod('()I')
274 pauseTimers = JavaMethod('()V')
275 resumeTimers = JavaMethod('()V')
276 onPause = JavaMethod('()V')
277 onResume = JavaMethod('()V')
278 freeMemory = JavaMethod('()V')
279 clearCache = JavaMethod('(Z)V')
280 clearFormData = JavaMethod('()V')
281 clearHistory = JavaMethod('()V')
282 clearSslPreferences = JavaMethod('()V')
283 clearClientCertPreferences = JavaStaticMethod('(Ljava/lang/Runnable;)V')
284 startSafeBrowsing = JavaStaticMethod(
285 '(Landroid/content/Context;Landroid/webkit/ValueCallback;)V'
286 )
287 setSafeBrowsingWhitelist = JavaStaticMethod('(Ljava/util/List;Landroid/webkit/ValueCallback;)V')
288 getSafeBrowsingPrivacyPolicyUrl = JavaStaticMethod('()Landroid/net/Uri;')
289 copyBackForwardList = JavaMethod('()Landroid/webkit/WebBackForwardList;')
290 setFindListener = JavaMethod('(Landroid/webkit/WebView$FindListener;)V')
291 findNext = JavaMethod('(Z)V')
292 findAll = JavaMethod('(Ljava/lang/String;)I')
293 findAllAsync = JavaMethod('(Ljava/lang/String;)V')
294 showFindDialog = JavaMethod('(Ljava/lang/String;Z)Z')
295 findAddress = JavaStaticMethod('(Ljava/lang/String;)Ljava/lang/String;')
296 enableSlowWholeDocumentDraw = JavaStaticMethod('()V')
297
298 clearMatches = JavaMethod('()V')
299 documentHasImages = JavaMethod('(Landroid/os/Message;)V')
300 setWebViewClient = JavaMethod('(Landroid/webkit/WebViewClient;)V')
301 getWebViewClient = JavaMethod('()Landroid/webkit/WebViewClient;')
302 getWebViewRenderProcess = JavaMethod('()Landroid/webkit/WebViewRenderProcess;')
303 setWebViewRenderProcessClient_with_executor = JavaMethod(
304 'Ljava/util/concurrent/Executor;Landroid/webkit/WebViewRenderProcessClient;V'
305 )
306 setWebViewRenderProcessClient = JavaMultipleMethod(
307 [
308 (
309 '(Ljava/util/concurrent/Executor;Landroid/webkit/WebViewRenderProcessClient;)V',
310 False,
311 False,
312 ),
313 ('Landroid/webkit/WebViewRenderProcessClient;V', False, False),
314 ]
315 )
316 getWebViewRenderProcessClient = JavaMethod('()Landroid/webkit/WebViewRenderProcessClient;')
317 setDownloadListener = JavaMethod('(Landroid/webkit/DownloadListener;)V')
318 setWebChromeClient = JavaMethod('(Landroid/webkit/WebChromeClient;)V')
319 getWebChromeClient = JavaMethod('()Landroid/webkit/WebChromeClient;')
320 setPictureListener = JavaMethod('(Landroid/webkit/WebView$PictureListener;)V')
321 setOnKeyListener = JavaMethod('(Landroid/view/View$OnKeyListener;)V')
322 addJavascriptInterface = JavaMethod('(Ljava/lang/Object;Ljava/lang/String;)V')
323 removeJavascriptInterface = JavaMethod('(Ljava/lang/String;)V')
324 createWebMessageChannel = JavaMethod('()[Landroid/webkit/WebMessagePort;')
325 postWebMessage = JavaMethod('(Landroid/webkit/WebMessage;Landroid/net/Uri;)V')
326 getSettings = JavaMethod('()Landroid/webkit/WebSettings;')
327 setWebContentsDebuggingEnabled = JavaStaticMethod('(Z)V')
328 setDataDirectorySuffix = JavaStaticMethod('(Ljava/lang/String;)V')
329 disableWebView = JavaStaticMethod('()V')
330 onChildViewAdded = JavaMethod('(Landroid/view/View;Landroid/view/View;)V')
331 onChildViewRemoved = JavaMethod('(Landroid/view/View;Landroid/view/View;)V')
332 onGlobalFocusChanged = JavaMethod('(Landroid/view/View;Landroid/view/View;)V')
333 setMapTrackballToArrowKeys = JavaMethod('(Z)V')
334 flingScroll = JavaMethod('(II)V')
335 canZoomIn = JavaMethod('()Z')
336 canZoomOut = JavaMethod('()Z')
337 zoomBy = JavaMethod('(F)V')
338 zoomIn = JavaMethod('()Z')
339 zoomOut = JavaMethod('()Z')
340 setRendererPriorityPolicy = JavaMethod('(IZ)V')
341 getRendererRequestedPriority = JavaMethod('()I')
342 getRendererPriorityWaivedWhenNotVisible = JavaMethod('()Z')
343 setTextClassifier = JavaMethod('(Landroid/view/textclassifier/TextClassifier;)V')
344 getTextClassifier = JavaMethod('()Landroid/view/textclassifier/TextClassifier;')
345 getWebViewClassLoader = JavaStaticMethod('()Ljava/lang/ClassLoader;')
346 getWebViewLooper = JavaMethod('()Landroid/os/Looper;')
347 onAttachedToWindow = JavaMethod('()V')
348 setLayoutParams = JavaMethod('(Landroid/view/ViewGroup$LayoutParams;)V')
349 setOverScrollMode = JavaMethod('(I)V')
350 setScrollBarStyle = JavaMethod('(I)V')
351 computeScroll = JavaMethod('()V')
352 onHoverEvent = JavaMethod('(Landroid/view/MotionEvent;)Z')
353 onTouchEvent = JavaMethod('(Landroid/view/MotionEvent;)Z')
354 onGenericMotionEvent = JavaMethod('(Landroid/view/MotionEvent;)Z')
355 onTrackballEvent = JavaMethod('(Landroid/view/MotionEvent;)Z')
356 onKeyDown = JavaMethod('(ILandroid/view/KeyEvent;)Z')
357 onKeyUp = JavaMethod('(ILandroid/view/KeyEvent;)Z')
358 onKeyMultiple = JavaMethod('(IILandroid/view/KeyEvent;)Z')
359 getAccessibilityNodeProvider = JavaMethod(
360 '()Landroid/view/accessibility/AccessibilityNodeProvider;'
361 )
362 shouldDelayChildPressedState = JavaMethod('()Z')
363 getAccessibilityClassName = JavaMethod('()Ljava/lang/CharSequence;')
364 onProvideVirtualStructure = JavaMethod('(Landroid/view/ViewStructure;)V')
365 onProvideAutofillVirtualStructure = JavaMethod('(Landroid/view/ViewStructure;I)V')
366 onProvideContentCaptureStructure = JavaMethod('(Landroid/view/ViewStructure;I)V')
367 autofill = JavaMethod('(Landroid/util/SparseArray;)V')
368 isVisibleToUserForAutofill = JavaMethod('(I)Z')
369 onCreateVirtualViewTranslationRequests = JavaMethod('([J[ILjava/util/function/Consumer;)V')
370 dispatchCreateViewTranslationRequest = JavaMethod(
371 '(Ljava/util/Map;[ILandroid/view/translation/TranslationCapability;Ljava/util/List;)V'
372 )
373 onVirtualViewTranslationResponses = JavaMethod('(Landroid/util/LongSparseArray;)V')
374 onOverScrolled = JavaMethod('(IIZZ)V')
375 onWindowVisibilityChanged = JavaMethod('(I)V')
376 onDraw = JavaMethod('(Landroid/graphics/Canvas;)V')
377 performLongClick = JavaMethod('()Z')
378 onConfigurationChanged = JavaMethod('(Landroid/content/res/Configuration;)V')
379 onCreateInputConnection = JavaMethod(
380 '(Landroid/view/inputmethod/EditorInfo;)Landroid/view/inputmethod/InputConnection;'
381 )
382 onDragEvent = JavaMethod('(Landroid/view/DragEvent;)Z')
383 onVisibilityChanged = JavaMethod('(Landroid/view/View;I)V')
384 onWindowFocusChanged = JavaMethod('(Z)V')
385 onFocusChanged = JavaMethod('(ZILandroid/graphics/Rect;)V')
386 onSizeChanged = JavaMethod('(IIII)V')
387 onScrollChanged = JavaMethod('(IIII)V')
388 dispatchKeyEvent = JavaMethod('(Landroid/view/KeyEvent;)Z')
389 requestFocus = JavaMethod('(ILandroid/graphics/Rect;)Z')
390 onMeasure = JavaMethod('(II)V')
391 requestChildRectangleOnScreen = JavaMethod('(Landroid/view/View;Landroid/graphics/Rect;Z)Z')
392 setBackgroundColor = JavaMethod('(I)V')
393 setLayerType = JavaMethod('(ILandroid/graphics/Paint;)V')
394 dispatchDraw = JavaMethod('(Landroid/graphics/Canvas;)V')
395 onStartTemporaryDetach = JavaMethod('()V')
396 onFinishTemporaryDetach = JavaMethod('()V')
397 getHandler = JavaMethod('()Landroid/os/Handler;')
398 findFocus = JavaMethod('()Landroid/view/View;')
399 getCurrentWebViewPackage = JavaStaticMethod('()Landroid/content/pm/PackageInfo;')
400 onCheckIsTextEditor = JavaMethod('()Z')
401 onApplyWindowInsets = JavaMethod('(Landroid/view/WindowInsets;)Landroid/view/WindowInsets;')
402 onResolvePointerIcon = JavaMethod('(Landroid/view/MotionEvent;I)Landroid/view/PointerIcon;')