diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-03-22 18:54:01 +0300 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-04-01 17:55:34 +0300 |
commit | 752e6676e1c18eb269f4e2b19415c0f1f6c7c7cc (patch) | |
tree | e731b2fade8a13a19dbe9d6339a3fea3e9304cc8 /core | |
parent | 9c800f62ddac5e7e707f786758c75ecb85311431 (diff) |
Detect user navigating away, don't interpret as ajax error
Whenever a user navigates away, all ajax calls will fail with the same
result like a cross-domain redirect (SSO). To distinguish these cases,
we need to detect whether the error is a result of the user navigating
away. For this, we introduce a new flag that will be set in
"beforeunload".
Additional handling was required for false positives in case "beforeunload" is
used (ex: cancelled upload) and the user cancelled the navigation.
Diffstat (limited to 'core')
-rw-r--r-- | core/js/js.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/core/js/js.js b/core/js/js.js index e90ceaf4e18..584bf1c1c83 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -741,7 +741,9 @@ var OC={ */ _processAjaxError: function(xhr) { // purposefully aborted request ? - if (xhr.status === 0 && (xhr.statusText === 'abort' || xhr.statusText === 'timeout')) { + // this._userIsNavigatingAway needed to distinguish ajax calls cancelled by navigating away + // from calls cancelled by failed cross-domain ajax due to SSO redirect + if (xhr.status === 0 && (xhr.statusText === 'abort' || xhr.statusText === 'timeout' || this._userIsNavigatingAway)) { return; } @@ -1438,6 +1440,29 @@ function initCore() { $('html').addClass('edge'); } + $(window).on('unload', function() { + OC._unloadCalled = true; + }); + $(window).on('beforeunload', function() { + // super-trick thanks to http://stackoverflow.com/a/4651049 + // in case another handler displays a confirmation dialog (ex: navigating away + // during an upload), there are two possible outcomes: user clicked "ok" or + // "cancel" + + // first timeout handler is called after unload dialog is closed + setTimeout(function() { + OC._userIsNavigatingAway = true; + + // second timeout event is only called if user cancelled (Chrome), + // but in other browsers it might still be triggered, so need to + // set a higher delay... + setTimeout(function() { + if (!OC._unloadCalled) { + OC._userIsNavigatingAway = false; + } + }, 10000); + },1); + }); $(document).on('ajaxError.main', function( event, request, settings ) { if (settings && settings.allowAuthErrors) { return; |