Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / remoting / webapp / oauth2_callback.js
blobb5c05583d29451a50c1dac05e0d9cbb52ce7fb39
1 // Copyright (c) 2012 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.
5 /**
6 * @fileoverview
7 * OAuth2 class that handles retrieval/storage of an OAuth2 token.
9 * Uses a content script to trampoline the OAuth redirect page back into the
10 * extension context. This works around the lack of native support for
11 * chrome-extensions in OAuth2.
14 'use strict';
16 function retrieveRefreshToken() {
17 var query = window.location.search.substring(1);
18 var parts = query.split('&');
19 var queryArgs = {};
20 for (var i = 0; i < parts.length; i++) {
21 var pair = parts[i].split('=');
22 queryArgs[pair[0]] = pair[1];
24 if ('code' in queryArgs) {
25 var oauth2 = new remoting.OAuth2();
26 oauth2.exchangeCodeForToken(queryArgs['code'], function() {
27 window.location.replace(chrome.extension.getURL('main.html'));
28 });
29 } else {
30 window.location.replace(chrome.extension.getURL('main.html'));
34 window.addEventListener('load', retrieveRefreshToken, false);