Merge lp:~abreu-alexandre/webbrowser-app/webapp-navigation-handling into lp:webbrowser-app

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 297
Merged at revision: 305
Proposed branch: lp:~abreu-alexandre/webbrowser-app/webapp-navigation-handling
Merge into: lp:webbrowser-app
Diff against target: 273 lines (+117/-6)
7 files modified
src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml (+15/-2)
src/app/Browser.qml (+38/-2)
src/app/commandline-parser.cpp (+19/-0)
src/app/commandline-parser.h (+3/-1)
src/app/webbrowser-app.cpp (+10/-0)
src/app/webbrowser-app.qml (+2/-0)
tests/unittests/commandline-parser/tst_CommandLineParserTests.cpp (+30/-1)
To merge this branch: bzr merge lp:~abreu-alexandre/webbrowser-app/webapp-navigation-handling
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Alexandre Abreu (community) Approve
Olivier Tilloy Approve
Review via email: mp+183671@code.launchpad.net

Commit message

Navigation support

Description of the change

Navigation support

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:291
http://jenkins.qa.ubuntu.com/job/webbrowser-app-ci/293/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/2936/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/503/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-amd64-ci/176
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-armhf-ci/176
        deb: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-armhf-ci/176/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-i386-ci/176
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-i386/2942
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-i386/2942/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-saucy/2499/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/505
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/505/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/451/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/459/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/webbrowser-app-ci/293/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:292
http://jenkins.qa.ubuntu.com/job/webbrowser-app-ci/294/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/2946/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/513/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-amd64-ci/177
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-armhf-ci/177
        deb: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-armhf-ci/177/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-i386-ci/177
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-i386/2952
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-i386/2952/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-saucy/2508/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/515
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/515/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/460/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/468/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/webbrowser-app-ci/294/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

17 + property var onNavigationRequestedDelegate: null
18 UserAgent {
19 id: userAgent
20 }
21 experimental.userAgent: userAgent.defaultUA
22 onNavigationRequested: {
23 + if (onNavigationRequestedDelegate && typeof(onNavigationRequestedDelegate) == 'function') {
24 + onNavigationRequestedDelegate (request);
25 + if (request.action === WebView.IgnoreRequest)
26 + return;
27 + }

This works, however I’m not convinced by the way it is implemented.
How about, instead of a property for a delegate function, implemented a default method in the base class (UbuntuWebView), called e.g. handleNavigationRequest(…), have onNavigationRequested call it, and override it in Browser.qml?

This would be functionally equivalent, but more elegant in my opinion.

Revision history for this message
Olivier Tilloy (osomon) wrote :

8 -import QtWebKit 3.0
9 +import QtWebKit 3.1

This will require the new version of QtWebKit to be in the archive, and backported to raring in a PPA. Is it already there?

review: Needs Information
Revision history for this message
Olivier Tilloy (osomon) wrote :

73 + var url = request.url + ' ';

Why is this needed?

Revision history for this message
Olivier Tilloy (osomon) wrote :

84 + var pattern = browser.urlIncludesPatterns[i].replace(/\*/g, '[^ ]*');

Why do you need to replace wildcards by '[^ ]*' ?
Couldn’t this substitution be done earlier on, when browser.urlIncludesPatterns is set (when the app is launched)?

Revision history for this message
Olivier Tilloy (osomon) wrote :

82 + var matched = false;

Instead of using an intermediate boolean var, how about initially setting action to WebView.IgnoreRequest just before the for loop, and if a given include pattern matches, set it to WebView.AcceptRequest ?

Revision history for this message
Olivier Tilloy (osomon) wrote :

226 + property alias includes: browser.urlIncludesPatterns

Can this property be renamed to something more explicit? I’d like to see 'webapps' in the name, to make it crystal clear that this property affects only webapps.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:292
http://jenkins.qa.ubuntu.com/job/webbrowser-app-ci/297/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/3036/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/597/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-amd64-ci/180
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-armhf-ci/180
        deb: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-armhf-ci/180/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/webbrowser-app-saucy-i386-ci/180
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-i386/3042
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-i386/3042/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-saucy/2570/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/599
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/599/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/521/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/533/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/webbrowser-app-ci/297/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 17 + property var onNavigationRequestedDelegate: null
> 18 UserAgent {
> 19 id: userAgent
> 20 }
> 21 experimental.userAgent: userAgent.defaultUA
> 22 onNavigationRequested: {
> 23 + if (onNavigationRequestedDelegate &&
> typeof(onNavigationRequestedDelegate) == 'function') {
> 24 + onNavigationRequestedDelegate (request);
> 25 + if (request.action === WebView.IgnoreRequest)
> 26 + return;
> 27 + }
>
> This works, however I’m not convinced by the way it is implemented.
> How about, instead of a property for a delegate function, implemented a
> default method in the base class (UbuntuWebView), called e.g.
> handleNavigationRequest(…), have onNavigationRequested call it, and override
> it in Browser.qml?
>
> This would be functionally equivalent, but more elegant in my opinion.

I am not really sure about that one, since it gives too much liberty to the
UbuntuWebView's client/user. The semantics is supposed to be a delegation of
some specialized behaviour that could override the basic one; but w/ your solution
nothing prevents the client to forget to call the default behaviour, or for example
behaviours from colliding/conflicting in their side-effects,

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 73 + var url = request.url + ' ';
>
> Why is this needed?

because request.url is not a js string, but an object that evaluates to a string, I force the coercion this way,

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 8 -import QtWebKit 3.0
> 9 +import QtWebKit 3.1
>
> This will require the new version of QtWebKit to be in the archive, and
> backported to raring in a PPA. Is it already there?

yes it's in the archive for S, I'll validate that's it's there for R w/ Mirv
before top-approving,

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 226 + property alias includes: browser.urlIncludesPatterns
>
> Can this property be renamed to something more explicit? I’d like to see
> 'webapps' in the name, to make it crystal clear that this property affects
> only webapps.

done.

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 82 + var matched = false;
>
> Instead of using an intermediate boolean var, how about initially setting
> action to WebView.IgnoreRequest just before the for loop, and if a given
> include pattern matches, set it to WebView.AcceptRequest ?

good idea, done

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 84 + var pattern =
> browser.urlIncludesPatterns[i].replace(/\*/g, '[^ ]*');
>
> Why do you need to replace wildcards by '[^ ]*' ?
> Couldn’t this substitution be done earlier on, when
> browser.urlIncludesPatterns is set (when the app is launched)?

+100, done

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

> > 17 + property var onNavigationRequestedDelegate: null
> > 18 UserAgent {
> > 19 id: userAgent
> > 20 }
> > 21 experimental.userAgent: userAgent.defaultUA
> > 22 onNavigationRequested: {
> > 23 + if (onNavigationRequestedDelegate &&
> > typeof(onNavigationRequestedDelegate) == 'function') {
> > 24 + onNavigationRequestedDelegate (request);
> > 25 + if (request.action === WebView.IgnoreRequest)
> > 26 + return;
> > 27 + }
> >
> > This works, however I’m not convinced by the way it is implemented.
> > How about, instead of a property for a delegate function, implemented a
> > default method in the base class (UbuntuWebView), called e.g.
> > handleNavigationRequest(…), have onNavigationRequested call it, and override
> > it in Browser.qml?
> >
> > This would be functionally equivalent, but more elegant in my opinion.
>
> I am not really sure about that one, since it gives too much liberty to the
> UbuntuWebView's client/user. The semantics is supposed to be a delegation of
> some specialized behaviour that could override the basic one; but w/ your
> solution
> nothing prevents the client to forget to call the default behaviour, or for
> example
> behaviours from colliding/conflicting in their side-effects,

I’m not sure I’m following you. What I’m proposing is a different implementation, but the semantics are exactly the same: the specialized behavior is delegated to a function (which by default does nothing and can be overridden) instead of being delegated to a function object stored as a property.

Revision history for this message
Olivier Tilloy (osomon) wrote :

> > 73 + var url = request.url + ' ';
> >
> > Why is this needed?
>
> because request.url is not a js string, but an object that evaluates to a
> string, I force the coercion this way,

Wouldn’t it be cleaner (and strictly equivalent) to do: var url = request.url.toString() ?

Revision history for this message
Olivier Tilloy (osomon) wrote :

> > 226 + property alias includes: browser.urlIncludesPatterns
> >
> > Can this property be renamed to something more explicit? I’d like to see
> > 'webapps' in the name, to make it crystal clear that this property affects
> > only webapps.
>
> done.

Thanks. Could you also rename the command-line argument and the property of the CommandLineParser class, for consistency?

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

>
> Thanks. Could you also rename the command-line argument and the property of
> the CommandLineParser class, for consistency?

done

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

>
> Wouldn’t it be cleaner (and strictly equivalent) to do: var url =
> request.url.toString() ?

done, although the previous expression is quite idiomatic

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> > > 17 + property var onNavigationRequestedDelegate: null
> > > 18 UserAgent {
> > > 19 id: userAgent
> > > 20 }
> > > 21 experimental.userAgent: userAgent.defaultUA
> > > 22 onNavigationRequested: {
> > > 23 + if (onNavigationRequestedDelegate &&
> > > typeof(onNavigationRequestedDelegate) == 'function') {
> > > 24 + onNavigationRequestedDelegate (request);
> > > 25 + if (request.action === WebView.IgnoreRequest)
> > > 26 + return;
> > > 27 + }
> > >
> > > This works, however I’m not convinced by the way it is implemented.
> > > How about, instead of a property for a delegate function, implemented a
> > > default method in the base class (UbuntuWebView), called e.g.
> > > handleNavigationRequest(…), have onNavigationRequested call it, and
> override
> > > it in Browser.qml?
> > >
> > > This would be functionally equivalent, but more elegant in my opinion.
> >
> > I am not really sure about that one, since it gives too much liberty to the
> > UbuntuWebView's client/user. The semantics is supposed to be a delegation of
> > some specialized behaviour that could override the basic one; but w/ your
> > solution
> > nothing prevents the client to forget to call the default behaviour, or for
> > example
> > behaviours from colliding/conflicting in their side-effects,
>
> I’m not sure I’m following you. What I’m proposing is a different
> implementation, but the semantics are exactly the same: the specialized
> behavior is delegated to a function (which by default does nothing and can be
> overridden) instead of being delegated to a function object stored as a
> property.

forget about my comment, I read to quickly and overlooked the fact that the
property usage was the issue ..

done

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

124 +#include <QtCore/QRegularExpression>

It looks like this is unused. Can it be removed?

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> 124 +#include <QtCore/QRegularExpression>
>
> It looks like this is unused. Can it be removed?

done

Revision history for this message
Olivier Tilloy (osomon) wrote :

In the two implementations of navigationRequestedDelegate(…), can the calls to console.debug() be removed?
Also, could you please add a comment in the default implementation (the one that does nothing) to explain that items inheriting UbuntuWebView may override this method to implement a specific behavior?

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> In the two implementations of navigationRequestedDelegate(…), can the calls to
> console.debug() be removed?
> Also, could you please add a comment in the default implementation (the one
> that does nothing) to explain that items inheriting UbuntuWebView may override
> this method to implement a specific behavior?

done

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

Looks good to me. Approving, and I’ll let you top-approve once we’re sure the required update to QtWebKit has been backported to Raring.

review: Approve
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

Timo just told me that the QtWebkit patch has been backported to R and build into the qtwebkit release found in the SDK ppa (version 5.0.1-0ubuntu7~raring1~test2)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

It appears there are conflicts when merging into the latest trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml'
--- src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml 2013-08-16 15:14:32 +0000
+++ src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml 2013-09-13 22:57:01 +0000
@@ -17,7 +17,7 @@
17 */17 */
1818
19import QtQuick 2.019import QtQuick 2.0
20import QtWebKit 3.020import QtWebKit 3.1
21import QtWebKit.experimental 1.021import QtWebKit.experimental 1.0
22import Ubuntu.Components 0.122import Ubuntu.Components 0.1
23import Ubuntu.Components.Extras.Browser 0.123import Ubuntu.Components.Extras.Browser 0.1
@@ -41,13 +41,26 @@
4141
42 property real scale: experimental.test.contentsScale * experimental.test.devicePixelRatio42 property real scale: experimental.test.contentsScale * experimental.test.devicePixelRatio
4343
44 /**
45 * Client overridable function called before the default treatment of a
46 * valid navigation request. This function can stop the navigation request
47 * if it sets the 'action' field of the request to IgnoreRequest.
48 *
49 */
50 function navigationRequestedDelegate(request) { }
51
44 UserAgent {52 UserAgent {
45 id: userAgent53 id: userAgent
46 }54 }
47 experimental.userAgent: userAgent.defaultUA55 experimental.userAgent: userAgent.defaultUA
48 onNavigationRequested: {56 onNavigationRequested: {
57 request.action = WebView.AcceptRequest;
58
59 navigationRequestedDelegate (request);
60 if (request.action === WebView.IgnoreRequest)
61 return;
62
49 _webview.experimental.userAgent = userAgent.getUAString(request.url)63 _webview.experimental.userAgent = userAgent.getUAString(request.url)
50 request.action = WebView.AcceptRequest
51 }64 }
5265
53 experimental.preferences.navigatorQtObjectEnabled: true66 experimental.preferences.navigatorQtObjectEnabled: true
5467
=== modified file 'src/app/Browser.qml'
--- src/app/Browser.qml 2013-09-03 20:28:36 +0000
+++ src/app/Browser.qml 2013-09-13 22:57:01 +0000
@@ -17,7 +17,7 @@
17 */17 */
1818
19import QtQuick 2.019import QtQuick 2.0
20import QtWebKit 3.020import QtWebKit 3.1
21import QtWebKit.experimental 1.021import QtWebKit.experimental 1.0
22import Ubuntu.Components 0.122import Ubuntu.Components 0.1
23import Ubuntu.Components.Extras.Browser 0.123import Ubuntu.Components.Extras.Browser 0.1
@@ -32,6 +32,8 @@
32 property real qtwebkitdpr32 property real qtwebkitdpr
33 property bool developerExtrasEnabled: false33 property bool developerExtrasEnabled: false
3434
35 property var webappUrlPatterns: null
36
35 property bool webapp: false37 property bool webapp: false
36 property string webappName: ""38 property string webappName: ""
3739
@@ -305,6 +307,7 @@
305 id: webappsComponent307 id: webappsComponent
306308
307 UnityWebApps.UnityWebApps {309 UnityWebApps.UnityWebApps {
310 id: webapps
308 name: browser.webappName311 name: browser.webappName
309 bindee: tabsModel.currentWebview312 bindee: tabsModel.currentWebview
310 actionsContext: browser.actionManager.globalContext313 actionsContext: browser.actionManager.globalContext
@@ -369,6 +372,38 @@
369 }372 }
370 }373 }
371374
375 function navigationRequestedDelegate(request) {
376 if (! request.isMainFrame) {
377 request.action = WebView.AcceptRequest;
378 return;
379 }
380
381 var action = WebView.AcceptRequest;
382 var url = request.url.toString();
383
384 // The list of url patterns defined by the webapp takes precedence over command line
385 if (webapp && isRunningAsANamedWebapp() && webapps.model && webapps.model.exists(webapps.name)) {
386 if ( ! webapps.model.doesUrlMatchesWebapp(webapps.name, url)) {
387 action = WebView.IgnoreRequest;
388 }
389 }
390 else if (browser.webappUrlPatterns && browser.webappUrlPatterns.length !== 0) {
391 action = WebView.IgnoreRequest;
392 for (var i = 0; i < browser.webappUrlPatterns.length; ++i) {
393 var pattern = browser.webappUrlPatterns[i];
394 if (url.match(pattern)) {
395 action = WebView.AcceptRequest;
396 break;
397 }
398 }
399 }
400
401 request.action = action;
402 if (action === WebView.IgnoreRequest) {
403 Qt.openUrlExternally(url);
404 }
405 }
406
372 onNewTabRequested: browser.newTab(url, true)407 onNewTabRequested: browser.newTab(url, true)
373408
374 // Small shim needed when running as a webapp to wire-up connections409 // Small shim needed when running as a webapp to wire-up connections
@@ -377,7 +412,8 @@
377 // component as a way to bind to a webview lookalike without412 // component as a way to bind to a webview lookalike without
378 // reaching out directly to its internals (see it as an interface).413 // reaching out directly to its internals (see it as an interface).
379 function getUnityWebappsProxies() {414 function getUnityWebappsProxies() {
380 return UnityWebAppsUtils.makeProxiesForQtWebViewBindee(webview)415 var handlers = {};
416 return UnityWebAppsUtils.makeProxiesForQtWebViewBindee(webview, handlers)
381 }417 }
382 }418 }
383 }419 }
384420
=== modified file 'src/app/commandline-parser.cpp'
--- src/app/commandline-parser.cpp 2013-09-06 16:29:55 +0000
+++ src/app/commandline-parser.cpp 2013-09-13 22:57:01 +0000
@@ -54,6 +54,19 @@
54 m_fullscreen = true;54 m_fullscreen = true;
55 } else if (argument == "--inspector") {55 } else if (argument == "--inspector") {
56 m_remoteInspector = true;56 m_remoteInspector = true;
57 } else if (argument.startsWith("--webappUrlPatterns=")) {
58 QString tail = argument.split("--webappUrlPatterns=")[1];
59 if (!tail.isEmpty()) {
60 QStringList includePatterns = tail.split(",");
61 Q_FOREACH(const QString & includePattern, includePatterns)
62 {
63 QString url = includePattern.trimmed();
64 if ( ! url.isEmpty())
65 {
66 m_webappUrlPatterns.append(url);
67 }
68 }
69 }
57 } else if (argument == "--enable-back-forward") {70 } else if (argument == "--enable-back-forward") {
58 m_chromeFlags |= BACK_FORWARD_BUTTONS;71 m_chromeFlags |= BACK_FORWARD_BUTTONS;
59 } else if (argument == "--enable-activity") {72 } else if (argument == "--enable-activity") {
@@ -121,6 +134,7 @@
121 out << " --inspector run a remote inspector on port " << REMOTE_INSPECTOR_PORT << endl;134 out << " --inspector run a remote inspector on port " << REMOTE_INSPECTOR_PORT << endl;
122 out << " --webapp[=name] launch the browser as a webapp trying to match it by name with an installed webapp integration script (if any)" << endl;135 out << " --webapp[=name] launch the browser as a webapp trying to match it by name with an installed webapp integration script (if any)" << endl;
123 out << " --app-id=APP_ID run the application with a specific APP_ID" << endl;136 out << " --app-id=APP_ID run the application with a specific APP_ID" << endl;
137 out << " --webappUrlPatterns=url-patterns when running as a webapp (see --webapp), list of ',' separated url patterns (wildcard based) that the webapp can navigate to" << endl;
124 out << "Chrome options (if none specified, the whole chrome is enabled by default):" << endl;138 out << "Chrome options (if none specified, the whole chrome is enabled by default):" << endl;
125 out << " --chromeless do not display any chrome (web application mode), if set it overrides the other chrome options" << endl;139 out << " --chromeless do not display any chrome (web application mode), if set it overrides the other chrome options" << endl;
126 out << " --enable-back-forward enable the display of the back and forward buttons" << endl;140 out << " --enable-back-forward enable the display of the back and forward buttons" << endl;
@@ -172,3 +186,8 @@
172{186{
173 return m_webappName;187 return m_webappName;
174}188}
189
190QStringList CommandLineParser::webappUrlPatterns() const
191{
192 return m_webappUrlPatterns;
193}
175194
=== modified file 'src/app/commandline-parser.h'
--- src/app/commandline-parser.h 2013-09-06 16:29:55 +0000
+++ src/app/commandline-parser.h 2013-09-13 22:57:01 +0000
@@ -22,6 +22,7 @@
22// Qt22// Qt
23#include <QtCore/QObject>23#include <QtCore/QObject>
24#include <QtCore/QString>24#include <QtCore/QString>
25#include <QtCore/QStringList>
25#include <QtCore/QUrl>26#include <QtCore/QUrl>
2627
27class CommandLineParser : public QObject28class CommandLineParser : public QObject
@@ -60,9 +61,9 @@
6061
61 QString appId() const;62 QString appId() const;
6263
64 QStringList webappUrlPatterns() const;
63 ChromeElementFlags chromeFlags() const;65 ChromeElementFlags chromeFlags() const;
6466
65
66private:67private:
67 bool m_help;68 bool m_help;
68 bool m_fullscreen;69 bool m_fullscreen;
@@ -71,6 +72,7 @@
71 bool m_webapp;72 bool m_webapp;
72 QString m_webappName;73 QString m_webappName;
73 QString m_appid;74 QString m_appid;
75 QStringList m_webappUrlPatterns;
74 ChromeElementFlags m_chromeFlags;76 ChromeElementFlags m_chromeFlags;
75};77};
7678
7779
=== modified file 'src/app/webbrowser-app.cpp'
--- src/app/webbrowser-app.cpp 2013-09-06 16:29:55 +0000
+++ src/app/webbrowser-app.cpp 2013-09-13 22:57:01 +0000
@@ -120,6 +120,16 @@
120 browser->setProperty("activityButtonVisible", activityButtonVisible);120 browser->setProperty("activityButtonVisible", activityButtonVisible);
121 }121 }
122122
123 QStringList urlPatterns = m_arguments->webappUrlPatterns();
124 if ( ! urlPatterns.isEmpty())
125 {
126 for (int i = 0; i < urlPatterns.count(); ++i)
127 {
128 urlPatterns[i].replace("*", "[^ ]*");
129 }
130 browser->setProperty("webappUrlPatterns", urlPatterns);
131 }
132
123 // Set the desired pixel ratio (not needed once we use Qt's way of calculating133 // Set the desired pixel ratio (not needed once we use Qt's way of calculating
124 // the proper pixel ratio by device/screen)134 // the proper pixel ratio by device/screen)
125 float webkitDpr = getQtWebkitDpr();135 float webkitDpr = getQtWebkitDpr();
126136
=== modified file 'src/app/webbrowser-app.qml'
--- src/app/webbrowser-app.qml 2013-09-03 20:28:36 +0000
+++ src/app/webbrowser-app.qml 2013-09-13 22:57:01 +0000
@@ -25,6 +25,8 @@
25 property alias qtwebkitdpr: browser.qtwebkitdpr25 property alias qtwebkitdpr: browser.qtwebkitdpr
26 property alias developerExtrasEnabled: browser.developerExtrasEnabled26 property alias developerExtrasEnabled: browser.developerExtrasEnabled
2727
28 property alias webappUrlPatterns: browser.webappUrlPatterns
29
28 property alias backForwardButtonsVisible: browser.backForwardButtonsVisible30 property alias backForwardButtonsVisible: browser.backForwardButtonsVisible
29 property alias activityButtonVisible: browser.activityButtonVisible31 property alias activityButtonVisible: browser.activityButtonVisible
30 property alias addressBarVisible: browser.addressBarVisible32 property alias addressBarVisible: browser.addressBarVisible
3133
=== modified file 'tests/unittests/commandline-parser/tst_CommandLineParserTests.cpp'
--- tests/unittests/commandline-parser/tst_CommandLineParserTests.cpp 2013-09-06 16:13:18 +0000
+++ tests/unittests/commandline-parser/tst_CommandLineParserTests.cpp 2013-09-13 22:57:01 +0000
@@ -205,13 +205,42 @@
205 QCOMPARE(CommandLineParser(args).webappName(), webappName);205 QCOMPARE(CommandLineParser(args).webappName(), webappName);
206 }206 }
207207
208 void shouldUseIncludes_data()
209 {
210 QTest::addColumn<QStringList>("args");
211 QTest::addColumn<QStringList>("patterns");
212
213 QString BINARY("webbrowser-app");
214 QString INCLUDE_PATTERN("http://www.ubuntu.*/*");
215 QString INCLUDE_PATTERN2("http://www.bbc.*/*");
216
217 QTest::newRow("no switch") << (QStringList() << BINARY) << QStringList();
218
219 QTest::newRow("switch only") << (QStringList() << BINARY << "--webappUrlPatterns") << QStringList();
220 QTest::newRow("empty switch") << (QStringList() << BINARY << "--webappUrlPatterns=") << QStringList();
221
222 QTest::newRow("switch and one pattern")
223 << (QStringList() << BINARY << (QString("--webappUrlPatterns=") + INCLUDE_PATTERN))
224 << (QStringList() << INCLUDE_PATTERN);
225
226 QTest::newRow("switch and multiple trimmed pattern")
227 << (QStringList() << BINARY << (QString("--webappUrlPatterns=") + INCLUDE_PATTERN + " , " + INCLUDE_PATTERN2 + " , "))
228 << (QStringList() << INCLUDE_PATTERN << INCLUDE_PATTERN2);
229 }
230
231 void shouldUseIncludes()
232 {
233 QFETCH(QStringList, args);
234 QFETCH(QStringList, patterns);
235 QCOMPARE(CommandLineParser(args).webappUrlPatterns(), patterns);
236 }
237
208 void shouldUseChrome_data()238 void shouldUseChrome_data()
209 {239 {
210 QTest::addColumn<QStringList>("args");240 QTest::addColumn<QStringList>("args");
211 QTest::addColumn<uint>("chrome");241 QTest::addColumn<uint>("chrome");
212242
213 QString BINARY("webbrowser-app");243 QString BINARY("webbrowser-app");
214
215 QString CHROME_BACK_FORWARD("--enable-back-forward");244 QString CHROME_BACK_FORWARD("--enable-back-forward");
216 QString CHROME_ACTIVIY("--enable-activity");245 QString CHROME_ACTIVIY("--enable-activity");
217 QString CHROME_ADDRESS_BAR("--enable-addressbar");246 QString CHROME_ADDRESS_BAR("--enable-addressbar");

Subscribers

People subscribed via source and target branches

to status/vote changes: