PortalHelper: fix portals that don't redirect properly

We assumed that either a portal would give us a target URI, or we
would eventually reach the URI of our choice (which is http://www.gnome.org)

This is not always the case: even after a successful login we may
stay in a confirmation page, so make sure that every time we see a
redirect we trigger a connectivity check (or queue one for when
the user closes the window)

https://bugzilla.gnome.org/show_bug.cgi?id=733848
This commit is contained in:
Giovanni Campagna 2014-07-28 09:36:40 +02:00
parent 3842981c35
commit b6e6e097b7

View File

@ -49,13 +49,14 @@ const PortalWindow = new Lang.Class({
_init: function(application, url, timestamp, doneCallback) { _init: function(application, url, timestamp, doneCallback) {
this.parent({ application: application }); this.parent({ application: application });
if (url) { if (!url) {
this._uri = new Soup.URI(uri);
} else {
url = 'http://www.gnome.org'; url = 'http://www.gnome.org';
this._uri = null; this._originalUrlWasGnome = true;
this._everSeenRedirect = false; } else {
this._originalUrlWasGnome = false;
} }
this._uri = new Soup.URI(url);
this._everSeenRedirect = false;
this._originalUrl = url; this._originalUrl = url;
this._doneCallback = doneCallback; this._doneCallback = doneCallback;
this._lastRecheck = 0; this._lastRecheck = 0;
@ -110,37 +111,7 @@ const PortalWindow = new Lang.Class({
let request = decision.get_request(); let request = decision.get_request();
let uri = new Soup.URI(request.get_uri()); let uri = new Soup.URI(request.get_uri());
if (this._uri != null) { if (!uri.host_equal(this._uri) && this._originalUrlWasGnome) {
if (!uri.host_equal(uri, this._uri)) {
// We *may* have finished here, but we don't know for
// sure. Tell gnome-shell to run another connectivity check
// (but ratelimit the checks, we don't want to spam
// gnome.org for portals that have 10 or more internal
// redirects - and unfortunately they exist)
// If we hit the rate limit, we also queue a recheck
// when the window is closed, just in case we miss the
// final check and don't realize we're connected
// This should not be a problem in the cancelled logic,
// because if the user doesn't want to start the login,
// we should not see any redirect at all, outside this._uri
let now = GLib.get_monotonic_time();
let shouldRecheck = (now - this._lastRecheck) >
CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT;
if (shouldRecheck) {
this._lastRecheck = now;
this._recheckAtExit = false;
this._doneCallback(PortalHelperResult.RECHECK);
} else {
this._recheckAtExit = true;
}
}
// Update the URI, in case of chained redirects, so we still
// think we're doing the login until gnome-shell kills us
this._uri = uri;
} else {
if (uri.get_host() == 'www.gnome.org' && this._everSeenRedirect) { if (uri.get_host() == 'www.gnome.org' && this._everSeenRedirect) {
// Yay, we got to gnome! // Yay, we got to gnome!
decision.ignore(); decision.ignore();
@ -151,6 +122,34 @@ const PortalWindow = new Lang.Class({
} }
} }
// We *may* have finished here, but we don't know for
// sure. Tell gnome-shell to run another connectivity check
// (but ratelimit the checks, we don't want to spam
// nmcheck.gnome.org for portals that have 10 or more internal
// redirects - and unfortunately they exist)
// If we hit the rate limit, we also queue a recheck
// when the window is closed, just in case we miss the
// final check and don't realize we're connected
// This should not be a problem in the cancelled logic,
// because if the user doesn't want to start the login,
// we should not see any redirect at all, outside this._uri
let now = GLib.get_monotonic_time();
let shouldRecheck = (now - this._lastRecheck) >
CONNECTIVITY_RECHECK_RATELIMIT_TIMEOUT;
if (shouldRecheck) {
this._lastRecheck = now;
this._recheckAtExit = false;
this._doneCallback(PortalHelperResult.RECHECK);
} else {
this._recheckAtExit = true;
}
// Update the URI, in case of chained redirects, so we still
// think we're doing the login until gnome-shell kills us
this._uri = uri;
decision.use(); decision.use();
return true; return true;
}, },