~abreu-alexandre/webbrowser-app/support-oxide-and-qtwebkit

« back to all changes in this revision

Viewing changes to src/app/webcontainer/WebViewImplWebkit.qml

  • Committer: Alexandre Abreu
  • Date: 2014-03-26 15:22:53 UTC
  • Revision ID: alexandre.abreu@canonical.com-20140326152253-isam6oink1tbvblj
fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
        return webview.webappName && typeof(webview.webappName) === 'string' && webview.webappName.length != 0
85
85
    }
86
86
 
 
87
    function haveValidUrlPatterns() {
 
88
        return webappUrlPatterns && webappUrlPatterns.length !== 0
 
89
    }
 
90
 
87
91
    function navigationRequestedDelegate(request) {
88
92
        if (!request.isMainFrame) {
89
93
            request.action = WebView.AcceptRequest
90
94
            return
91
95
        }
92
96
 
93
 
        var action = WebView.AcceptRequest
 
97
        // Pass-through if we are not running as a named webapp (--webapp='Gmail')
 
98
        // or if we dont have a list of url patterns specified to filter the
 
99
        // browsing actions
 
100
        if ( ! haveValidUrlPatterns() && ! isRunningAsANamedWebapp()) {
 
101
            request.action = WebView.AcceptRequest
 
102
            return
 
103
        }
 
104
 
 
105
        var action = WebView.IgnoreRequest
94
106
        var url = request.url.toString()
95
107
 
96
108
        // The list of url patterns defined by the webapp takes precedence over command line
97
109
        if (isRunningAsANamedWebapp()) {
98
 
            if (unityWebapps.model.exists(webview.webappName) &&
99
 
                !unityWebapps.model.doesUrlMatchesWebapp(webview.webappName, url)) {
100
 
                action = WebView.IgnoreRequest
 
110
            if (unityWebapps.model.exists(unityWebapps.name) &&
 
111
                unityWebapps.model.doesUrlMatchesWebapp(unityWebapps.name, url)) {
 
112
                request.action = WebView.AcceptRequest
 
113
                return;
101
114
            }
102
 
        } else if (webview.webappUrlPatterns && webview.webappUrlPatterns.length !== 0) {
103
 
            action = WebView.IgnoreRequest
104
 
            for (var i = 0; i < webview.webappUrlPatterns.length; ++i) {
105
 
                var pattern = webview.webappUrlPatterns[i]
 
115
        }
 
116
 
 
117
        // We still take the possible additional patterns specified in the command line
 
118
        // (the in the case of finer grained ones specifically for the container and not
 
119
        // as an 'install source' for the webapp).
 
120
        if (webappUrlPatterns && webappUrlPatterns.length !== 0) {
 
121
            for (var i = 0; i < webappUrlPatterns.length; ++i) {
 
122
                var pattern = webappUrlPatterns[i]
106
123
                if (url.match(pattern)) {
107
124
                    action = WebView.AcceptRequest
108
125
                    break
112
129
 
113
130
        request.action = action
114
131
        if (action === WebView.IgnoreRequest) {
 
132
            console.debug('Opening: ' + url + ' in the browser window.')
115
133
            Qt.openUrlExternally(url)
116
134
        }
117
135
    }