Debian Codegraph @

online-accounts-plugins/lib/module/qml6/WebView.qml

raw
1 import QtQuick 2.9
2 import Lomiri.Components
3 import Morph.Web 0.1
4
5 ChromedWebView {
6 id: root
7
8 property QtObject signonRequest
9 property string userAgent
10
11 onNewViewRequested: {
12 var popup = popupComponent.createObject(root, {
13 "context": context,
14 "url": request.requestedUrl,
15 })
16 popup.windowCloseRequested.connect(function() {
17 console.log("Close requested!")
18 popup.destroy()
19 })
20 }
21
22 Component {
23 id: popupComponent
24 ChromedWebView {
25 anchors.fill: parent
26 }
27 }
28
29 onSignonRequestChanged: if (signonRequest) {
30 signonRequest.authenticated.connect(onAuthenticated)
31 url = signonRequest.startUrl
32 }
33
34 onLoadingChanged: {
35 console.log("Loading changed")
36 if (loading && !lastLoadFailed) {
37 signonRequest.onLoadStarted()
38 } else if (lastLoadSucceeded) {
39 signonRequest.onLoadFinished(true)
40 } else if (lastLoadFailed) {
41 signonRequest.onLoadFinished(false)
42 }
43 }
44 onUrlChanged: signonRequest.currentUrl = url
45
46 context: WebContext {
47 dataPath: signonRequest ? signonRequest.rootDir : ""
48 userAgent: root.userAgent ? root.userAgent : defaultUserAgent
49 }
50
51 function onAuthenticated() {
52 /* Get the cookies and set them on the request */
53 console.log("Authenticated; getting cookies")
54 /* We could use the QWebEngineCookieStore class to get the cookies.
55 * This are then copied over to the webapps, in order to reduce login
56 * prompts and support multi account. However, the multi-account
57 * feature never landed, so for the moment this is not a priority.
58 *
59 * Let's just fake it and set empty cookies.
60
61 context.cookieManager.getCookiesResponse.connect(onGotCookies)
62 context.cookieManager.getAllCookies()
63 */
64 visible = false
65 onGotCookies(0, [])
66 }
67
68 function onGotCookies(requestId, cookies) {
69 signonRequest.setCookies(cookies)
70 }
71 }