From 704d74b175e2270b8d1a63457e64b062a4dfb867 Mon Sep 17 00:00:00 2001 From: benweet Date: Mon, 19 May 2014 19:02:49 +0100 Subject: [PATCH] Fixed google oauth iframe leak --- public/res/helpers/googleHelper.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public/res/helpers/googleHelper.js b/public/res/helpers/googleHelper.js index 535a7ee1..f1d46ebf 100644 --- a/public/res/helpers/googleHelper.js +++ b/public/res/helpers/googleHelper.js @@ -108,6 +108,7 @@ define([ 'https://www.googleapis.com/auth/photos' ] }; + var oauthIframes = []; function authenticate(task, permission, accountId) { var authorizationMgr = authorizationMgrMap[accountId]; if(!authorizationMgr) { @@ -161,6 +162,16 @@ define([ immediate: immediate, authuser: immediate === false ? '' : authuser }, function(authResult) { + + // Hack to clean window from old oauth iframes + authorizationMgr.$oauthIframe && authorizationMgr.$oauthIframe.remove(); + var currentOauthIframes = _.filter(document.querySelectorAll('iframe'), function(iframe) { + var src = iframe.getAttribute('src'); + return src && src.indexOf('https://accounts.google.com/o/oauth2/auth') === 0; + }); + authorizationMgr.$oauthIframe = $(_.difference(currentOauthIframes, oauthIframes)); + oauthIframes = currentOauthIframes; + newToken = gapi.auth.getToken(); gapi.auth.setToken(currentToken); if(!authResult || authResult.error) { @@ -257,7 +268,7 @@ define([ var headers = { 'Content-Type': 'multipart/mixed; boundary="' + boundary + '"', }; - + var base64Data = utils.encodeBase64(content); var multipartRequestBody = [ delimiter,