Skip to content

Commit

Permalink
Clear WebView's cache on Android to avoid interference with authentic…
Browse files Browse the repository at this point in the history
…ation methods
  • Loading branch information
nirvn committed Oct 12, 2023
1 parent ac6dc33 commit ccf18a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/qml/BrowserPanel.qml
Expand Up @@ -12,8 +12,11 @@ Popup {
signal cancel()

property var browserView: undefined
property var browserCookies: []

property string url: ''
property bool fullscreen: false
property bool clearCookiesOnOpen: false

width: mainWindow.width - (browserPanel.fullscreen ? 0 : Theme.popupScreenEdgeMargin * 2)
height: mainWindow.height - (browserPanel.fullscreen ? 0 : Theme.popupScreenEdgeMargin * 2)
Expand Down Expand Up @@ -61,14 +64,56 @@ Popup {
}

onAboutToShow: {
// Reset tracked cookies
browserCookies = []

if (url != '') {
if (browserView === undefined) {
// avoid cost of WevView creation until needed
browserView = Qt.createQmlObject('import QtWebView 1.14; WebView { id: browserView; anchors { top: parent.top; left: parent.left; right: parent.right; } onLoadingChanged: { if ( !loading ) { anchors.fill = parent; width = parent.width; height = parent.height; opacity = 1; } } }', browserContent);
if (qVersion >= '6.0.0') {
browserView = Qt.createQmlObject('import QtWebView
WebView {
id: browserView
anchors { top: parent.top; left: parent.left; right: parent.right; }
onLoadingChanged: {
if ( !loading ) {
anchors.fill = parent; width = parent.width
height = parent.height; opacity = 1
}
}
onCookieAdded: (domain, name) => {
browserPanel.browserCookies.push([domain, name])
}
}', browserContent)
if (clearCookiesOnOpen) {
browserView.deleteAllCookies()
}
} else {
browserView = Qt.createQmlObject('import QtWebView 1.14
WebView {
id: browserView
anchors { top: parent.top; left: parent.left; right: parent.right; }
onLoadingChanged: {
if ( !loading ) {
anchors.fill = parent; width = parent.width
height = parent.height; opacity = 1
}
}
}', browserContent)
}
}
browserView.anchors.fill = undefined
browserView.url = url
browserView.opacity = 0
}

clearCookiesOnOpen = false
}

function deleteCookies() {
for(const [domain, name] of browserCookies) {
browserView.deleteCookie(domain, name)
}
browserCookies = [];
}
}
1 change: 1 addition & 0 deletions src/qml/qgismobileapp.qml
Expand Up @@ -3285,6 +3285,7 @@ ApplicationWindow {
function onShowLoginBrowser(url) {
browserPopup.url = url;
browserPopup.fullscreen = false;
browserPopup.clearCookiesOnOpen = true
browserPopup.open();
}

Expand Down

1 comment on commit ccf18a2

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.