/usr/share/webbrowser-app/webcontainer/AccountsLogic.qml is in webapp-container 0.23+16.04.20160413-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | /*
* Copyright 2015 Canonical Ltd.
*
* This file is part of webbrowser-app.
*
* webbrowser-app is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* webbrowser-app is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import Qt.labs.settings 1.0
import Ubuntu.OnlineAccounts 0.1
import Ubuntu.OnlineAccounts.Client 0.1
import webcontainer.private 0.1
Item {
id: root
property alias providerId: accountsModelObject.provider
property alias applicationId: accountsModelObject.applicationId
property bool accountSwitcher: false
property var accountsModel: accountsModelObject
signal splashScreenRequested()
signal errorScreenRequested(string message)
signal accountSelected(int credentialsId, bool willMoveCookies)
signal contextReady()
signal quitRequested()
property var __account: null
property int __credentialsId: __account ? __account.authData.credentialsId : 0
Timer {
id: checkTimer
running: true
repeat: false
onTriggered: checkAccounts()
interval: 100
}
AccountServiceModel {
id: accountsModelObject
}
// This is only used if accountSwitcher is false
Setup {
id: setup
applicationId: root.applicationId
providerId: root.providerId
onFinished: {
if ("accountId" in reply) {
root.checkAccounts()
} else if ("errorName" in reply) {
root.errorScreenRequested(i18n.tr("Account window could not be opened. You can only create one account at a time; please try again after closing all other account windows."))
} else {
root.quitRequested()
}
}
}
Settings {
id: settings
property int selectedAccount: -1
property string initializedAccounts: "[]"
}
Component {
id: accountComponent
AccountService { }
}
Component {
id: onlineAccountStoreComponent
OnlineAccountsCookieStore { }
}
Component {
id: oxideCookieStoreComponent
ChromeCookieStore { }
}
function checkAccounts() {
checkTimer.stop()
console.log("Accounts: " + accountsModel.count)
/* If account switching is not supported, we just pick the first
* account here. */
if (!accountSwitcher) {
if (accountsModel.count === 0) {
setup.exec()
} else {
settings.selectedAccount = accountsModel.get(0, "accountId")
setupAccount(settings.selectedAccount)
}
return
}
if (accountsModel.count === 0) {
settings.selectedAccount = -1
} else if (settings.selectedAccount > 0) {
// check that the account exists
for (var i = 0; i < accountsModel.count; i++) {
if (accountsModel.get(i, "accountId") === settings.selectedAccount) {
break;
}
}
if (i >= accountsModel.count) {
// The selected account was not found
settings.selectedAccount = -1
}
}
if (settings.selectedAccount < 0) {
splashScreenRequested()
} else {
setupAccount(settings.selectedAccount)
}
}
function proceedWithNoAccount() {
__account = null
settings.selectedAccount = 0
accountSelected(__credentialsId, false)
}
function setupAccount(accountId) {
console.log("Setup account " + accountId)
if (__account && accountId === __account.accountId) {
console.log("Same as current account")
accountSelected(__credentialsId, false)
return
}
__account = null
for (var i = 0; i < accountsModel.count; i++) {
if (accountsModel.get(i, "accountId") === accountId) {
var accountHandle = accountsModel.get(i, "accountServiceHandle")
__account = accountComponent.createObject(root, {
objectHandle: accountHandle
})
break;
}
}
console.log("Credentials ID: " + __credentialsId)
settings.selectedAccount = accountId
accountSelected(__credentialsId, mustMoveCookies(accountId))
}
function login(account, callback) {
console.log("Preparing for login")
function authenticatedCallback() {
console.log("Authenticated!")
account.authenticated.disconnect(authenticatedCallback)
callback(true)
}
account.authenticated.connect(authenticatedCallback)
function errorCallback() {
console.log("Authentication error!")
account.authenticationError.disconnect(errorCallback)
callback(false)
}
account.authenticationError.connect(errorCallback)
account.authenticate(null)
}
function mustMoveCookies(accountId) {
var initializedAccounts
try {
initializedAccounts = JSON.parse(settings.initializedAccounts)
} catch(e) {
initializedAccounts = []
}
return initializedAccounts.indexOf(accountId) < 0
}
function rememberCookiesMoved(accountId) {
var initializedAccounts = JSON.parse(settings.initializedAccounts)
if (initializedAccounts.indexOf(accountId) < 0) {
initializedAccounts.push(accountId)
settings.initializedAccounts = JSON.stringify(initializedAccounts)
}
}
function onCookiesMoved(result) {
if (!result) {
console.log("Cookies were not moved")
} else {
console.log("cookies moved")
}
// Even if the cookies were not moved, we don't want to retry
rememberCookiesMoved(__account.accountId)
contextReady()
}
function setupWebcontextForAccount(webcontext) {
if (!__account || !mustMoveCookies(__account.accountId)) {
contextReady()
return
}
login(__account, function(authenticated) {
if (!authenticated) {
errorScreenRequested(i18n.it("Authentication failed"))
} else {
console.log("Authentication succeeded, moving cookies")
var accountsCookieStore = onlineAccountStoreComponent.createObject(root, {
"accountId": __credentialsId
})
var webappCookieStore = oxideCookieStoreComponent.createObject(root, {
"oxideStoreBackend": webcontext.cookieManager,
"dbPath": webcontext.dataPath + "/cookies.sqlite"
})
webappCookieStore.moved.connect(onCookiesMoved)
webappCookieStore.moveFrom(accountsCookieStore)
}
})
}
}
|