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
=== modified file 'src/browser-request.cpp'
--- src/browser-request.cpp 2012-08-31 06:14:20 +0000
+++ src/browser-request.cpp 2012-09-10 06:23:22 +0000
@@ -85,6 +85,8 @@
85 m_allowedSchemes = schemes;85 m_allowedSchemes = schemes;
86 }86 }
8787
88 void setFinalUrl(const QUrl &url) { m_finalUrl = url; }
89
88protected:90protected:
89 // reimplemented virtual methods91 // reimplemented virtual methods
90 QString userAgentForUrl(const QUrl &url) const92 QString userAgentForUrl(const QUrl &url) const
@@ -99,18 +101,32 @@
99 {101 {
100 Q_UNUSED(type);102 Q_UNUSED(type);
101103
102 TRACE() << request.url();104 QUrl url = request.url();
105 TRACE() << url;
106
107 /* We generally don't need to load the final URL, so skip loading it.
108 * If this behaviour is not desired for some requests, then just avoid
109 * calling setFinalUrl() */
110 if (url.host() == m_finalUrl.host() &&
111 url.path() == m_finalUrl.path()) {
112 Q_EMIT finalUrlReached(url);
113 return false;
114 }
115
103 /* open all new window requests (identified by "frame == 0") in the116 /* open all new window requests (identified by "frame == 0") in the
104 * external browser, as well as other links according to the117 * external browser, as well as other links according to the
105 * ExternalLinksPattern and InternalLinksPattern rules. */118 * ExternalLinksPattern and InternalLinksPattern rules. */
106 if (frame == 0 || urlIsBlocked(request.url())) {119 if (frame == 0 || urlIsBlocked(url)) {
107 QDesktopServices::openUrl(request.url());120 QDesktopServices::openUrl(url);
108 return false;121 return false;
109 }122 }
110 /* Handle all other requests internally. */123 /* Handle all other requests internally. */
111 return true;124 return true;
112 }125 }
113126
127Q_SIGNALS:
128 void finalUrlReached(const QUrl &url);
129
114private:130private:
115 bool urlIsBlocked(QUrl url) const;131 bool urlIsBlocked(QUrl url) const;
116132
@@ -119,6 +135,7 @@
119 QRegExp m_externalLinksPattern;135 QRegExp m_externalLinksPattern;
120 QRegExp m_internalLinksPattern;136 QRegExp m_internalLinksPattern;
121 QStringList m_allowedSchemes;137 QStringList m_allowedSchemes;
138 QUrl m_finalUrl;
122};139};
123140
124bool WebPage::urlIsBlocked(QUrl url) const {141bool WebPage::urlIsBlocked(QUrl url) const {
@@ -375,6 +392,14 @@
375 this, SLOT(onContentsChanged()));392 this, SLOT(onContentsChanged()));
376 m_webView->setPage(page);393 m_webView->setPage(page);
377394
395 /* The following couple of lines serve to instruct the QWebPage not to load
396 * the final URL, but to block it and emit the finalUrlReached() signal
397 * instead.
398 */
399 page->setFinalUrl(finalUrl);
400 QObject::connect(page, SIGNAL(finalUrlReached(const QUrl&)),
401 this, SLOT(onUrlChanged(const QUrl&)));
402
378 /* set a per-identity cookie jar on the page */403 /* set a per-identity cookie jar on the page */
379 uint identity = 0;404 uint identity = 0;
380 if (params.contains(SSOUI_KEY_IDENTITY)) {405 if (params.contains(SSOUI_KEY_IDENTITY)) {

Subscribers

People subscribed via source and target branches

to all changes: