~michael-sheldon/webbrowser-app/implement-download-folder

« back to all changes in this revision

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

  • Committer: Michael Sheldon
  • Date: 2015-09-21 13:24:24 UTC
  • mfrom: (1106.25.15 webbrowser-app)
  • Revision ID: michael.sheldon@canonical.com-20150921132424-ffebrf4ok3he2e21
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
    property string localCookieStoreDbPath: ""
34
34
 
35
 
    property var intentFilterHandler
36
35
    property string url: ""
37
36
    property url webappIcon: ""
38
37
    property string webappName: ""
54
53
    title: getWindowTitle()
55
54
 
56
55
    // Used for testing
57
 
    signal intentUriHandleResult(string uri)
 
56
    signal schemeUriHandleFilterResult(string uri)
58
57
 
59
58
    function getWindowTitle() {
60
59
        var webappViewTitle =
229
228
        showWebView()
230
229
    }
231
230
 
232
 
    function makeUrlFromIntentResult(intentFilterResult) {
 
231
    function makeUrlFromResult(result) {
233
232
        var scheme = null
234
233
        var hostname = null
235
234
        var url = root.currentWebview.url || root.url
236
 
        if (intentFilterResult.host
237
 
                && intentFilterResult.host.length !== 0) {
238
 
            hostname = intentFilterResult.host
 
235
        if (result.host
 
236
                && result.host.length !== 0) {
 
237
            hostname = result.host
239
238
        }
240
239
        else {
241
240
            var matchHostname = url.toString().match(/.*:\/\/([^/]*)\/.*/)
243
242
                hostname = matchHostname[1]
244
243
            }
245
244
        }
246
 
        if (intentFilterResult.scheme
247
 
                && intentFilterResult.scheme.length !== 0) {
248
 
            scheme = intentFilterResult.scheme
 
245
 
 
246
        if (result.scheme
 
247
                && result.scheme.length !== 0) {
 
248
            scheme = result.scheme
249
249
        }
250
250
        else {
251
251
            var matchScheme = url.toString().match(/(.*):\/\/[^/]*\/.*/)
257
257
                + '://'
258
258
                + hostname
259
259
                + "/"
260
 
                + (intentFilterResult.uri
261
 
                    ? intentFilterResult.uri : "")
 
260
                + (result.path
 
261
                    ? result.path : "")
262
262
    }
263
263
 
264
264
    /**
265
 
     * Identity function for non-intent URIs.
266
265
     *
267
 
     * Otherwise if the URI is an intent, tries to apply a webapp
268
 
     * local filter (or identity) and reconstruct the target URI based
269
 
     * on its result.
270
266
     */
271
 
    function handleIntentUri(uri) {
272
 
        var _uri = uri;
273
 
        if (webappIntentFilter
274
 
                && webappIntentFilter.isValidIntentUri(_uri)) {
275
 
            var result = webappIntentFilter.applyFilter(_uri)
276
 
            _uri = makeUrlFromIntentResult(result)
277
 
 
278
 
            console.log("Intent URI '" + uri + "' was mapped to '" + _uri + "'")
 
267
    function translateHandlerUri(uri) {
 
268
        //
 
269
        var scheme = uri.substr(0, uri.indexOf(":"))
 
270
        if (scheme.indexOf("http") === 0) {
 
271
            schemeUriHandleFilterResult(uri)
 
272
            return uri
279
273
        }
280
274
 
 
275
        var result = webappSchemeFilter.applyFilter(uri)
 
276
        var mapped_uri = makeUrlFromResult(result)
 
277
 
 
278
        uri = mapped_uri
 
279
 
281
280
        // Report the result of the intent uri filtering (if any)
282
281
        // Done for testing purposed. It is not possible at this point
283
282
        // to have AP call a slot and retrieve its result synchronously.
284
 
        intentUriHandleResult(_uri)
 
283
        schemeUriHandleFilterResult(uri)
285
284
 
286
 
        return _uri
 
285
        return uri
287
286
    }
288
287
 
289
288
    // Handle runtime requests to open urls as defined
306
305
                return;
307
306
            }
308
307
 
309
 
            requestedUrl = handleIntentUri(requestedUrl);
 
308
            requestedUrl = translateHandlerUri(requestedUrl);
310
309
 
311
310
            // Add a small guard to prevent browsing to invalid urls
312
311
            if (currentWebview