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

Unified Diff: chrome/browser/resources/new_profile.js

Issue 7256002: Multi-Profiles: New Profile Setup UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/new_profile.js
diff --git a/chrome/browser/resources/new_profile.js b/chrome/browser/resources/new_profile.js
new file mode 100644
index 0000000000000000000000000000000000000000..d815e81c59d02c507b6e8a05d1c3eb4206ca9ea6
--- /dev/null
+++ b/chrome/browser/resources/new_profile.js
@@ -0,0 +1,80 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Tracks the currently selected avatar icon.
+var gSelectedAvatarIconIndex = 0;
+
+// Initializes everything once the document loads.
+function load() {
+ // Allow platform specific CSS rules.
+ cr.enablePlatformSpecificCSSRules();
+
+ // Add handlers to HTML elements.
+ $('create-button').onclick = function () { onCreate(); };
+ $('cancel-button').onclick = function () { onCancel(); };
+ $('profile-name-form').onsubmit = function () {
+ onCreate();
+ // Return false to prevent the submit handler from doing a post.
+ return false;
+ };
+
+ chrome.send('requestProfileInfo');
+ updateLogo();
+ $('profile-name').focus();
+}
+
+// Sends the profile information to the browser.
+function onCreate() {
+ chrome.send('create', [$('profile-name').value,
+ String(gSelectedAvatarIconIndex)]);
+}
+
+// Lets the browser know that the user doesn't want to create the profile.
+function onCancel() {
+ chrome.send('cancel');
+}
+
+// Changes the selected profile.
+function onAvatarClicked(index) {
+ var menu = $('avatar-menu');
+ for (var i = 0; i < menu.childNodes.length; i++) {
+ var button = menu.childNodes[i];
+ if (i == index)
+ button.classList.add("avatar-button-selected");
+ else
+ button.classList.remove("avatar-button-selected");
+ }
+ gSelectedAvatarIconIndex = index;
+}
+
+// Sets the logo image.
+function updateLogo() {
+ var imageId = 'IDR_PRODUCT_LOGO';
+ if (document.documentElement.getAttribute('customlogo') == 'true')
+ imageId = 'IDR_CUSTOM_PRODUCT_LOGO';
+
+ $('logo-img').src = 'chrome://theme/' + imageId + '?' + Date.now();
+}
+
+// Callback from the browser to set the profile information on the page.
+function setProfileInfo(profileName, profileIconIndex) {
+ $('profile-name').value = profileName;
+ onAvatarClicked(profileIconIndex);
+}
+
+// Callback from the browser to fill the avatar menu with default avatar
+// images.
+function setDefaultAvatarImages(imageUrlList) {
+ var menu = $('avatar-menu');
+ for (var i = 0; i < imageUrlList.length; i++) {
+ var button = document.createElement("input");
+ button.setAttribute("type", "image");
+ button.setAttribute("class", "avatar-button");
+ button.setAttribute("src", imageUrlList[i]);
+ button.setAttribute("onclick", "onAvatarClicked(" + i + ")");
+ menu.appendChild(button);
+ }
+}
+
+document.body.onload = load;

Powered by Google App Engine
This is Rietveld 408576698