Warning, /plasma/aura-browser/app/qml/SandboxLoader.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.12
0008 import QtQuick.Controls 2.12
0009 import QtQuick.Window 2.12
0010 import QtWebChannel 1.0
0011 import QtQuick.Layouts 1.12
0012 import QtQuick.LocalStorage 2.12
0013 import Aura 1.0 as Aura
0014 import "code/RecentStorage.js" as RecentStorage
0015 import "code/Utils.js" as Utils
0016 import QtWebEngine
0017 import Qt5Compat.GraphicalEffects
0018 import org.kde.kirigami as Kirigami
0019 
0020 Item {
0021     id: mItem
0022     Layout.fillWidth: true
0023     Layout.fillHeight: true
0024     property var pageTitle
0025     property var pageUrl: sandboxURL
0026     property var pageId
0027     property var navMode: "vMouse"
0028     property bool vMouseEnabled: false
0029     property int currentScrollSpeed: Aura.GlobalSettings.virtualScrollSpeed
0030     signal returnFocus
0031 
0032     Rectangle {
0033         id: mouseCursor
0034         width: Kirigami.Units.gridUnit * 1.5
0035         height: Kirigami.Units.gridUnit * 1.5
0036         radius: 100
0037         border.width: Kirigami.Units.smallSpacing
0038         border.color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.9)
0039         color: Qt.rgba(Kirigami.Theme.linkColor.r, Kirigami.Theme.linkColor.g, Kirigami.Theme.linkColor.b, 0.8)
0040         x: Cursor.pos.x
0041         y: Cursor.pos.y
0042         z: 1002
0043         visible: Cursor.visible
0044         enabled: vMouseEnabled
0045     }
0046 
0047     Connections {
0048         target: root
0049 
0050         function onBlurFieldRequested() {
0051             if(mItem.visible) {
0052                 webView.runJavaScript('document.activeElement.blur()');
0053             }
0054         }
0055         function onMouseActivationRequested() {
0056             if(mItem.visible) {
0057                 vMouseEnabled = true
0058                 mouseCursor.forceActiveFocus();
0059             }
0060         }
0061         function onMouseDeActivationRequested() {
0062             if(mItem.visible) {
0063                 vMouseEnabled = false
0064             }
0065         }
0066         function onIgnoreInputRequested() {
0067             if(mItem.visible){
0068                 webView.forceActiveFocus()
0069             }
0070         }
0071     }
0072 
0073     onPageUrlChanged: {
0074         webView.url = pageUrl
0075     }
0076 
0077     Component.onCompleted: {
0078         var scriptFoo = WebEngine.script()
0079         scriptFoo.injectionPoint = WebEngineScript.DocumentCreation
0080         scriptFoo.name = "QWebChannel"
0081         scriptFoo.worldId = WebEngineScript.MainWorld
0082         scriptFoo.sourceUrl = Qt.resolvedUrl("./code/qwebchannel.js")
0083         webView.userScripts.insert(scriptFoo)
0084 
0085         var scriptRoo = WebEngine.script()  
0086         scriptRoo.injectionPoint = WebEngineScript.DocumentReady
0087         scriptRoo.name = "QWebInput"
0088         scriptRoo.worldId = WebEngineScript.MainWorld
0089         scriptRoo.runOnSubframes = true
0090         scriptRoo.sourceUrl = Qt.resolvedUrl("./code/qwebinput.js")
0091 
0092         webView.userScripts.insert(scriptRoo)
0093         webChannel.registerObject("foo", myObject)
0094     }
0095 
0096     QtObject {
0097         id: myObject
0098         objectName: "myObject"
0099         property string tInput: "";
0100         property string cName: "";
0101     }
0102 
0103     FocusScope {
0104         anchors.fill: parent
0105 
0106         TopBarSandbox{
0107             id: topBarPage
0108             anchors.top: parent.top
0109         }
0110 
0111         RequestHandler {
0112             id: interactionBar
0113             anchors.top: topBarPage.bottom
0114             z: 1001
0115         }
0116 
0117         WebChannel {
0118             id: webChannel
0119         }
0120 
0121         WebEngineView {
0122             id: webView
0123             anchors.top: interactionBar.bottom
0124             anchors.left: parent.left
0125             anchors.right: parent.right
0126             anchors.bottom: parent.bottom
0127 
0128             focus: true
0129             objectName: "webengineview"
0130             webChannel: webChannel
0131             profile: Aura.GlobalSettings.adblockEnabled == 1 ? adblockProfile : defaultProfile
0132         
0133 
0134             Connections {
0135                 target: adblockProfile
0136 
0137                 function onDownloadRequested() {
0138                     download.accept()
0139                     download.pause()
0140                     var downloadFileName = download.path.split('/').pop(-1)
0141                     interactionBar.setSource("DownloadRequest.qml")
0142                     interactionBar.interactionItem.download = download
0143                     interactionBar.interactionItem.actionsVisible = true
0144                     interactionBar.interactionItem.downloadName = downloadFileName
0145                     interactionBar.isRequested = true
0146                 }
0147 
0148                 function onDownloadFinished() {
0149                     if (download.state === WebEngineDownloadItem.DownloadCompleted) {
0150                         interactionBar.interactionItem.actionsVisible = false
0151                         interactionBar.interactionItem.isDownloading = false
0152                         interactionBar.interactionItem.messageText = i18n("Download finished")
0153                     }
0154                     else if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
0155                         interactionBar.interactionItem.actionsVisible = false
0156                         interactionBar.interactionItem.isDownloading = false
0157                         interactionBar.interactionItem.messageText = i18n("Download failed: %1", download.interruptReason)
0158                     }
0159                     else if (download.state === WebEngineDownloadItem.DownloadCancelled) {
0160                         interactionBar.interactionItem.isDownloading = false
0161                     }
0162                 }
0163             }
0164         
0165 
0166             WebEngineProfile {
0167                 id: defaultProfile
0168                 httpUserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"
0169 
0170                 onDownloadRequested: function(download) {
0171                     download.accept()
0172                     download.pause()
0173                     var downloadFileName = download.path.split('/').pop(-1)
0174                     interactionBar.setSource("DownloadRequest.qml")
0175                     interactionBar.interactionItem.download = download
0176                     interactionBar.interactionItem.actionsVisible = true
0177                     interactionBar.interactionItem.downloadName = downloadFileName
0178                     interactionBar.isRequested = true
0179                 }
0180 
0181                 onDownloadFinished: function(download) {
0182                     if (download.state === WebEngineDownloadItem.DownloadCompleted) {
0183                         interactionBar.interactionItem.actionsVisible = false
0184                         interactionBar.interactionItem.isDownloading = false
0185                         interactionBar.interactionItem.messageText = i18n("Download finished")
0186                     }
0187                     else if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
0188                         interactionBar.interactionItem.actionsVisible = false
0189                         interactionBar.interactionItem.isDownloading = false
0190                         interactionBar.interactionItem.messageText = i18n("Download failed: %1", download.interruptReason)
0191                     }
0192                     else if (download.state === WebEngineDownloadItem.DownloadCancelled) {
0193                         interactionBar.interactionItem.isDownloading = false
0194                     }
0195                 }
0196             }
0197 
0198             onFeaturePermissionRequested: function(securityOrigin, feature) {
0199                 interactionBar.setSource("FeatureRequest.qml")
0200                 interactionBar.interactionItem.securityOrigin = securityOrigin;
0201                 interactionBar.interactionItem.requestedFeature = feature;
0202                 interactionBar.isRequested = true;
0203             }
0204         
0205 
0206             onLoadingChanged: function(loadingInfo) {
0207                 vMouseEnabled = true;
0208                 Aura.GlobalSettings.focusOffVKeyboard();
0209                 mouseCursor.forceActiveFocus();
0210             }
0211 
0212             settings {
0213                 focusOnNavigationEnabled: false
0214                 pluginsEnabled: true
0215                 showScrollBars: false
0216             }
0217 
0218             onFullScreenRequested: function(request) {
0219                 request.accept()                
0220                 if (root.visibility !== Window.FullScreen) {
0221                     topBarPage.viewFullscreenMode = true
0222                     root.showFullScreen()
0223                 } else if (root.visibility == Window.FullScreen && !topBarPage.viewFullscreenMode){
0224                     topBarPage.viewFullscreenMode = true
0225                 } else {
0226                     topBarPage.viewFullscreenMode = false
0227                 }
0228             }
0229 
0230             onJavaScriptConsoleMessage: function(message, lineNumber, sourceID) {
0231                 try {
0232                     var jsonMessage = JSON.parse(message);
0233                 } catch(err) {
0234                     jsonMessage = JSON.parse('{"className": "None", "id": "None", "inputFocus": "None"}');
0235                 }
0236                 myObject.cName = jsonMessage.className
0237                 pageId = jsonMessage.id
0238                 if(jsonMessage.inputFocus == "GotInput"){
0239                     Aura.GlobalSettings.focusOnVKeyboard();
0240                 }
0241             }
0242         }
0243     }
0244 }