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

Side by Side Diff: chrome/browser/resources/gaia_auth/util.js

Issue 902493003: cros: Pass gaia_auth init params via postMessage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits Created 5 years, 10 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 /** 5 /**
6 * Alias for document.getElementById. 6 * Alias for document.getElementById.
7 * @param {string} id The ID of the element to find. 7 * @param {string} id The ID of the element to find.
8 * @return {HTMLElement} The found element or null if not found. 8 * @return {HTMLElement} The found element or null if not found.
9 */ 9 */
10 function $(id) { 10 function $(id) {
11 return document.getElementById(id); 11 return document.getElementById(id);
12 } 12 }
13 13
14 /** 14 /**
15 * Extract query params from given search string of an URL.
16 * @param {string} search The search portion of an URL to extract params.
17 * @return {Object} The key value pairs of the extracted params.
18 */
19 function getUrlSearchParams(search) {
20 var params = {};
21
22 if (search) {
23 // Strips leading '?'
24 search = search.substring(1);
25 var pairs = search.split('&');
26 for (var i = 0; i < pairs.length; ++i) {
27 var pair = pairs[i].split('=');
28 if (pair.length == 2) {
29 params[pair[0]] = decodeURIComponent(pair[1]);
30 } else {
31 params[pair] = true;
32 }
33 }
34 }
35
36 return params;
37 }
38
39 /**
40 * Creates a new URL which is the old URL with a GET param of key=value. 15 * Creates a new URL which is the old URL with a GET param of key=value.
41 * Copied from ui/webui/resources/js/util.js. 16 * Copied from ui/webui/resources/js/util.js.
42 * @param {string} url The base URL. There is not sanity checking on the URL so 17 * @param {string} url The base URL. There is not sanity checking on the URL so
43 * it must be passed in a proper format. 18 * it must be passed in a proper format.
44 * @param {string} key The key of the param. 19 * @param {string} key The key of the param.
45 * @param {string} value The value of the param. 20 * @param {string} value The value of the param.
46 * @return {string} The new URL. 21 * @return {string} The new URL.
47 */ 22 */
48 function appendParam(url, key, value) { 23 function appendParam(url, key, value) {
49 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); 24 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value);
(...skipping 15 matching lines...) Expand all
65 /** 40 /**
66 * Extract domain name from an URL. 41 * Extract domain name from an URL.
67 * @param {string} url An URL string. 42 * @param {string} url An URL string.
68 * @return {string} The host name of the URL. 43 * @return {string} The host name of the URL.
69 */ 44 */
70 function extractDomain(url) { 45 function extractDomain(url) {
71 var a = document.createElement('a'); 46 var a = document.createElement('a');
72 a.href = url; 47 a.href = url;
73 return a.hostname; 48 return a.hostname;
74 } 49 }
75
76 /**
77 * Extract protocol from an URL.
78 * @param {string} url An URL string.
79 * @return {string} The protocol of the URL.
80 */
81 function extractProtocol(url) {
82 var a = document.createElement('a');
83 a.href = url;
84 return a.protocol;
85 }
86
OLDNEW
« no previous file with comments | « chrome/browser/resources/gaia_auth/offline.js ('k') | chrome/browser/resources/gaia_auth_host/gaia_auth_host.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698