| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var webview; | 5 var webview; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Points the webview to the starting URL of a scope authorization | 8 * Points the webview to the starting URL of a scope authorization |
| 9 * flow, and unhides the dialog once the page has loaded. | 9 * flow, and unhides the dialog once the page has loaded. |
| 10 * @param {string} url The url of the authorization entry point. | 10 * @param {string} url The url of the authorization entry point. |
| 11 * @param {Object} win The dialog window that contains this page. Can | 11 * @param {Object} win The dialog window that contains this page. Can |
| 12 * be left undefined if the caller does not want to display the | 12 * be left undefined if the caller does not want to display the |
| 13 * window. | 13 * window. |
| 14 */ | 14 */ |
| 15 function loadAuthUrlAndShowWindow(url, win) { | 15 function loadAuthUrlAndShowWindow(url, win) { |
| 16 // Send popups from the webview to a normal browser window. | 16 // Send popups from the webview to a normal browser window. |
| 17 webview.addEventListener('newwindow', function(e) { | 17 webview.addEventListener('newwindow', function(e) { |
| 18 e.window.discard(); | 18 e.window.discard(); |
| 19 window.open(e.targetUrl); | 19 window.open(e.targetUrl); |
| 20 }); | 20 }); |
| 21 | 21 |
| 22 // Request a customized view from GAIA. | 22 // Request a customized view from GAIA. |
| 23 webview.request.onBeforeSendHeaders.addListener(function(details) { | 23 webview.request.onBeforeSendHeaders.addListener( |
| 24 headers = details.requestHeaders || []; | 24 function(details) { |
| 25 headers.push({'name': 'X-Browser-View', | 25 headers = details.requestHeaders || []; |
| 26 'value': 'embedded'}); | 26 headers.push({'name': 'X-Browser-View', 'value': 'embedded'}); |
| 27 return { requestHeaders: headers }; | 27 return {requestHeaders: headers}; |
| 28 }, { | 28 }, |
| 29 urls: ['https://accounts.google.com/*'], | 29 { |
| 30 }, ['blocking', 'requestHeaders']); | 30 urls: ['https://accounts.google.com/*'], |
| 31 }, |
| 32 ['blocking', 'requestHeaders']); |
| 31 | 33 |
| 32 if (!url.toLowerCase().startsWith('https://accounts.google.com/')) | 34 if (!url.toLowerCase().startsWith('https://accounts.google.com/')) |
| 33 document.querySelector('.titlebar').classList.add('titlebar-border'); | 35 document.querySelector('.titlebar').classList.add('titlebar-border'); |
| 34 | 36 |
| 35 webview.src = url; | 37 webview.src = url; |
| 36 if (win) { | 38 if (win) { |
| 37 webview.addEventListener('loadstop', function() { | 39 webview.addEventListener('loadstop', function() { |
| 38 win.show(); | 40 win.show(); |
| 39 }); | 41 }); |
| 40 } | 42 } |
| 41 } | 43 } |
| 42 | 44 |
| 43 document.addEventListener('DOMContentLoaded', function() { | 45 document.addEventListener('DOMContentLoaded', function() { |
| 44 webview = document.querySelector('webview'); | 46 webview = document.querySelector('webview'); |
| 45 | 47 |
| 46 document.querySelector('.titlebar-close-button').onclick = function() { | 48 document.querySelector('.titlebar-close-button').onclick = function() { |
| 47 window.close(); | 49 window.close(); |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 chrome.resourcesPrivate.getStrings('identity', function(strings) { | 52 chrome.resourcesPrivate.getStrings('identity', function(strings) { |
| 51 document.title = strings['window-title']; | 53 document.title = strings['window-title']; |
| 52 }); | 54 }); |
| 53 }); | 55 }); |
| 54 | |
| OLD | NEW |