• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3// found in the LICENSE file.
4
5var webview;
6
7/**
8 * Points the webview to the starting URL of a scope authorization
9 * flow, and unhides the dialog once the page has loaded.
10 * @param {string} url The url of the authorization entry point.
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
13 *     window.
14 */
15function loadAuthUrlAndShowWindow(url, win) {
16  // Send popups from the webview to a normal browser window.
17  webview.addEventListener('newwindow', function(e) {
18    e.window.discard();
19    window.open(e.targetUrl);
20  });
21
22  // Request a customized view from GAIA.
23  webview.request.onBeforeSendHeaders.addListener(function(details) {
24    headers = details.requestHeaders || [];
25    headers.push({'name': 'X-Browser-View',
26                  'value': 'embedded'});
27    return { requestHeaders: headers };
28  }, {
29    urls: ['https://accounts.google.com/*'],
30  }, ['blocking', 'requestHeaders']);
31
32  if (url.toLowerCase().indexOf('https://accounts.google.com/') != 0)
33    document.querySelector('.titlebar').classList.add('titlebar-border');
34
35  webview.src = url;
36  if (win) {
37    webview.addEventListener('loadstop', function() {
38      win.show();
39    });
40  }
41}
42
43document.addEventListener('DOMContentLoaded', function() {
44  webview = document.querySelector('webview');
45
46  document.querySelector('.titlebar-close-button').onclick = function() {
47    window.close();
48  };
49
50  chrome.identityPrivate.getResources(function(resources) {
51    var style = document.styleSheets[0];
52
53    function insertRule(selector, url) {
54      style.insertRule(selector + ' { background-image: url(' + url + '); }',
55                       style.cssRules.length);
56    }
57
58    insertRule('.titlebar-close-button', resources.IDR_CLOSE_DIALOG);
59    insertRule('.titlebar-close-button:hover', resources.IDR_CLOSE_DIALOG_H);
60    insertRule('.titlebar-close-button:active', resources.IDR_CLOSE_DIALOG_P);
61
62    document.title = resources.IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE;
63  });
64});
65
66