~mardy/webbrowser-app/cookie-sharing

« back to all changes in this revision

Viewing changes to src/app/webcontainer/webapp-container.qml

  • Committer: Alberto Mardegan
  • Date: 2015-05-11 10:00:59 UTC
  • Revision ID: alberto.mardegan@canonical.com-20150511100059-6lveyuq7gs2l2y6h
use shared cookie store

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    property string popupRedirectionUrlPrefixPattern: ""
42
42
    property url webviewOverrideFile: ""
43
43
    property var __webappCookieStore: null
 
44
    property bool sharedCookies: false
44
45
    property string localUserAgentOverride: ""
45
46
    property bool blockOpenExternalUrls: false
46
47
 
50
51
 
51
52
    title: getWindowTitle()
52
53
 
 
54
    onActiveChanged: if (sharedCookies) {
 
55
        if (!active) {
 
56
            console.log("Getting inactive, saving cookies to " + sharedCookieStore.dbPath)
 
57
 
 
58
            if (!__webappCookieStore && webappViewLoader.item) {
 
59
                var context = webappViewLoader.item.currentWebview.context
 
60
                __webappCookieStore = oxideCookieStoreComponent.createObject(this, {
 
61
                    "oxideStoreBackend": context.cookieManager,
 
62
                    "dbPath": context.dataPath + "/cookies.sqlite"
 
63
                })
 
64
            }
 
65
 
 
66
            sharedCookieStore.moveFrom(__webappCookieStore)
 
67
        } else {
 
68
            loadCookies()
 
69
        }
 
70
    }
 
71
 
 
72
    function loadCookies() {
 
73
        if (!webappViewLoader.item) return
 
74
        if (!__webappCookieStore) {
 
75
            var context = webappViewLoader.item.currentWebview.context
 
76
            __webappCookieStore = oxideCookieStoreComponent.createObject(this, {
 
77
                "oxideStoreBackend": context.cookieManager,
 
78
                "dbPath": context.dataPath + "/cookies.sqlite"
 
79
            })
 
80
        }
 
81
 
 
82
        console.log("Loading cookies from " + sharedCookieStore.dbPath)
 
83
        __webappCookieStore.moved.connect(onCookiesMoved)
 
84
        __webappCookieStore.moveFrom(sharedCookieStore)
 
85
    }
 
86
 
53
87
    // Used for testing
54
88
    signal intentUriHandleResult(string uri)
55
89
 
68
102
        }
69
103
    }
70
104
 
 
105
    SharedCookieStore {
 
106
        id: sharedCookieStore
 
107
        dbPath: "account-" + (webappViewLoader.credentialsId ? webappViewLoader.credentialsId : "0")
 
108
    }
 
109
 
71
110
    Component {
72
111
        id: webappViewComponent
73
112
 
74
113
        WebApp {
75
114
            id: browser
76
115
 
77
 
            url: accountProvider.length !== 0 ? "" : root.url
 
116
            url: (sharedCookies || accountProvider.length !== 0) ? "" : root.url
78
117
 
79
118
            dataPath: webappDataLocation
80
119
            webappName: root.webappName
176
215
        if (!result) {
177
216
            console.log("Cookies were not moved")
178
217
        }
179
 
        webappViewLoader.item.url = root.url
 
218
        if (!webappViewLoader.item.url) {
 
219
            webappViewLoader.item.url = root.url
 
220
        }
180
221
    }
181
222
 
182
223
    function moveCookies(credentialsId) {
238
279
 
239
280
        // check if we are to display the login view
240
281
        // or directly switch to the webapp view
241
 
        if (accountProvider.length !== 0) {
 
282
        if (!sharedCookies && accountProvider.length !== 0) {
242
283
            loadLoginView();
243
284
        } else {
244
285
            loadWebAppView();