Merge lp:~mardy/signon-ui/skip-final-url into lp:signon-ui

Proposed by Alberto Mardegan
Status: Merged
Approved by: David King
Approved revision: 55
Merged at revision: 55
Proposed branch: lp:~mardy/signon-ui/skip-final-url
Merge into: lp:signon-ui
Diff against target: 71 lines (+28/-3)
1 file modified
src/browser-request.cpp (+28/-3)
To merge this branch: bzr merge lp:~mardy/signon-ui/skip-final-url
Reviewer Review Type Date Requested Status
David King (community) Approve
Review via email: mp+123485@code.launchpad.net

Description of the change

Avoid loading the final URL.

Successfully terminate the browser request as soon as we are requested to navigate to the final URL, without even attempting to load it.

To post a comment you must log in.
Revision history for this message
David King (amigadave) wrote :

Works fine here.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/browser-request.cpp'
2--- src/browser-request.cpp 2012-08-31 06:14:20 +0000
3+++ src/browser-request.cpp 2012-09-10 06:23:22 +0000
4@@ -85,6 +85,8 @@
5 m_allowedSchemes = schemes;
6 }
7
8+ void setFinalUrl(const QUrl &url) { m_finalUrl = url; }
9+
10 protected:
11 // reimplemented virtual methods
12 QString userAgentForUrl(const QUrl &url) const
13@@ -99,18 +101,32 @@
14 {
15 Q_UNUSED(type);
16
17- TRACE() << request.url();
18+ QUrl url = request.url();
19+ TRACE() << url;
20+
21+ /* We generally don't need to load the final URL, so skip loading it.
22+ * If this behaviour is not desired for some requests, then just avoid
23+ * calling setFinalUrl() */
24+ if (url.host() == m_finalUrl.host() &&
25+ url.path() == m_finalUrl.path()) {
26+ Q_EMIT finalUrlReached(url);
27+ return false;
28+ }
29+
30 /* open all new window requests (identified by "frame == 0") in the
31 * external browser, as well as other links according to the
32 * ExternalLinksPattern and InternalLinksPattern rules. */
33- if (frame == 0 || urlIsBlocked(request.url())) {
34- QDesktopServices::openUrl(request.url());
35+ if (frame == 0 || urlIsBlocked(url)) {
36+ QDesktopServices::openUrl(url);
37 return false;
38 }
39 /* Handle all other requests internally. */
40 return true;
41 }
42
43+Q_SIGNALS:
44+ void finalUrlReached(const QUrl &url);
45+
46 private:
47 bool urlIsBlocked(QUrl url) const;
48
49@@ -119,6 +135,7 @@
50 QRegExp m_externalLinksPattern;
51 QRegExp m_internalLinksPattern;
52 QStringList m_allowedSchemes;
53+ QUrl m_finalUrl;
54 };
55
56 bool WebPage::urlIsBlocked(QUrl url) const {
57@@ -375,6 +392,14 @@
58 this, SLOT(onContentsChanged()));
59 m_webView->setPage(page);
60
61+ /* The following couple of lines serve to instruct the QWebPage not to load
62+ * the final URL, but to block it and emit the finalUrlReached() signal
63+ * instead.
64+ */
65+ page->setFinalUrl(finalUrl);
66+ QObject::connect(page, SIGNAL(finalUrlReached(const QUrl&)),
67+ this, SLOT(onUrlChanged(const QUrl&)));
68+
69 /* set a per-identity cookie jar on the page */
70 uint identity = 0;
71 if (params.contains(SSOUI_KEY_IDENTITY)) {

Subscribers

People subscribed via source and target branches

to all changes: