Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: appengine/swarming/elements/res/imp/common/auth-signin.html

Issue 2401763003: Fix background page loading (Closed)
Patch Set: Get rid of popup/signin Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 5
6 The `auth-signin` element displays sign-in/sign-out button, user email and 6 The `auth-signin` element displays sign-in/sign-out button, user email and
7 avatar. 7 avatar.
8 It has a google-signin/google-signin-aware element under the hood that handles 8 It has a google-signin/google-signin-aware element under the hood that handles
9 the actual OAuth logic. 9 the actual OAuth logic.
10 10
(...skipping 29 matching lines...) Expand all
40 a { 40 a {
41 color: white; 41 color: white;
42 } 42 }
43 .center { 43 .center {
44 vertical-align: middle; 44 vertical-align: middle;
45 } 45 }
46 </style> 46 </style>
47 47
48 <google-signin-aware id="aware" 48 <google-signin-aware id="aware"
49 client-id="[[client_id]]" 49 client-id="[[client_id]]"
50 offline
50 scopes="email" 51 scopes="email"
51 on-google-signin-aware-success="_onSignin" 52 on-google-signin-aware-success="_onSignin"
52 on-google-signin-aware-signed-out="_onSignout"> 53 on-google-signin-aware-signed-out="_onSignout">
53 </google-signin-aware> 54 </google-signin-aware>
54 55
55 <template is="dom-if" if="[[!signed_in]]"> 56 <template is="dom-if" if="[[!signed_in]]">
56 <div id="signinContainer"> 57 <div id="signinContainer">
57 <a on-tap="signIn" href="#">Sign in</a> 58 <a on-tap="signIn" href="#">Sign in</a>
58 </div> 59 </div>
59 </template> 60 </template>
(...skipping 28 matching lines...) Expand all
88 notify: true, 89 notify: true,
89 }, 90 },
90 signed_in: { 91 signed_in: {
91 type: Boolean, 92 type: Boolean,
92 readOnly: true, 93 readOnly: true,
93 value: false, 94 value: false,
94 notify: true, 95 notify: true,
95 }, 96 },
96 }, 97 },
97 98
98 attached: function() { 99 ready: function() {
99 if (!this.client_id) { 100 if (!this.client_id) {
100 return; 101 return;
101 } 102 }
102 // If a page is opened in a new tab, we are (likely) already logged in 103 // If a page is opened in a new tab, we are (likely) already logged in
103 // so we wait for the gapi and auth2 to be loaded and re-extract our 104 // so we wait for the gapi and auth2 to be loaded and re-extract our
104 // access_token. 105 // access_token.
105 var trySignin = window.setTimeout(function(){ 106 window.setTimeout(function(){
106 // The 'gapi' checks are the same that signin-aware does. We do them 107 // The 'gapi' checks are the same that signin-aware does. We do them
107 // to avoid extraneous errors in the console. 108 // to avoid extraneous errors in the console.
108 if (('gapi' in window) && ('auth2' in window.gapi) && 109 if (!this.signed_in && !this._signingIn){
109 !this.signed_in && !this._signingIn) { 110 if (('gapi' in window) && ('auth2' in window.gapi)) {
110 var user = gapi.auth2.getAuthInstance().currentUser.get(); 111 var user = gapi.auth2.getAuthInstance().currentUser.get();
111 if (user && user.getAuthResponse().access_token) { 112 if (user && user.getAuthResponse().access_token) {
112 // User is already logged in, can use the access_token. 113 // User is already logged in, can use the access_token.
113 this._onSignin(); 114 this._onSignin();
115 } else {
116 window.setTimeout(this.ready.bind(this), 50);
117 }
114 } else { 118 } else {
115 this.$.aware.signIn(); 119 window.setTimeout(this.ready.bind(this), 50);
116 } 120 }
117 } else {
118 window.setTimeout(this.attached.bind(this));
119 } 121 }
120 }.bind(this), 122 }.bind(this), 50);
121 // 300 ms is chosen because this seems to be long enough for the signin
122 // to happen normally on a "visible" page and avoid the popup that
123 // always happens when signIn() is manually called. It is also short
124 // enough such that when the page is opened in a new tab, it seems to
125 // happen automatically.
126 300);
127 }, 123 },
128 124
129 _onSignin: function() { 125 _onSignin: function() {
130 this._signingIn = true; 126 this._signingIn = true;
131 var user = gapi.auth2.getAuthInstance().currentUser.get(); 127 var user = gapi.auth2.getAuthInstance().currentUser.get();
132 var profile = user.getBasicProfile(); 128 var profile = user.getBasicProfile();
133 this._setProfile({ 129 this._setProfile({
134 email: profile.getEmail(), 130 email: profile.getEmail(),
135 imageUrl: profile.getImageUrl() 131 imageUrl: profile.getImageUrl()
136 }); 132 });
(...skipping 27 matching lines...) Expand all
164 signIn: function() { 160 signIn: function() {
165 this.$.aware.signIn(); 161 this.$.aware.signIn();
166 }, 162 },
167 163
168 signOut: function() { 164 signOut: function() {
169 this.$.aware.signOut(); 165 this.$.aware.signOut();
170 } 166 }
171 }); 167 });
172 </script> 168 </script>
173 </dom-module> 169 </dom-module>
OLDNEW
« no previous file with comments | « appengine/swarming/elements/build/elements.html ('k') | appengine/swarming/elements/res/imp/taskpage/task-page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698