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

Side by Side Diff: chrome/browser/resources/options2/browser_options.js

Issue 9181013: [uber page] Migrate remaining Personal options into Browser options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: How about another rebase! (damn you generated_resources.grd) Created 8 years, 11 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 | Annotate | Revision Log
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 cr.define('options', function() { 5 cr.define('options', function() {
6 const OptionsPage = options.OptionsPage; 6 const OptionsPage = options.OptionsPage;
7 const ArrayDataModel = cr.ui.ArrayDataModel; 7 const ArrayDataModel = cr.ui.ArrayDataModel;
8 8
9 // 9 //
10 // BrowserOptions class 10 // BrowserOptions class
(...skipping 26 matching lines...) Expand all
37 // The cached value of the instant.confirm_dialog_shown preference. 37 // The cached value of the instant.confirm_dialog_shown preference.
38 instantConfirmDialogShown_: false, 38 instantConfirmDialogShown_: false,
39 39
40 /** 40 /**
41 * Initialize BrowserOptions page. 41 * Initialize BrowserOptions page.
42 */ 42 */
43 initializePage: function() { 43 initializePage: function() {
44 // Call base class implementation to start preference initialization. 44 // Call base class implementation to start preference initialization.
45 OptionsPage.prototype.initializePage.call(this); 45 OptionsPage.prototype.initializePage.call(this);
46 46
47 // Sync. 47 var self = this;
48
49 // Sync (Sign in) section.
48 $('sync-action-link').onclick = function(event) { 50 $('sync-action-link').onclick = function(event) {
49 SyncSetupOverlay.showErrorUI(); 51 SyncSetupOverlay.showErrorUI();
50 }; 52 };
51 $('start-stop-sync').onclick = function(event) { 53 $('start-stop-sync').onclick = function(event) {
52 if (self.syncSetupCompleted) 54 if (self.syncSetupCompleted)
53 SyncSetupOverlay.showStopSyncingUI(); 55 SyncSetupOverlay.showStopSyncingUI();
54 else 56 else
55 SyncSetupOverlay.showSetupUI(); 57 SyncSetupOverlay.showSetupUI();
56 }; 58 };
57 $('customize-sync').onclick = function(event) { 59 $('customize-sync').onclick = function(event) {
58 SyncSetupOverlay.showSetupUI(); 60 SyncSetupOverlay.showSetupUI();
59 }; 61 };
60 62
61 // Wire up controls. 63 // On Startup section.
62 $('startupSetPages').onclick = function() { 64 $('startupSetPages').onclick = function() {
63 OptionsPage.navigateToPage('startup'); 65 OptionsPage.navigateToPage('startup');
64 }; 66 };
67
68 // Appearance section.
69 $('change-home-page').onclick = function(event) {
70 OptionsPage.navigateToPage('homePageOverlay');
71 };
72 $('themes-gallery').onclick = function(event) {
73 window.open(localStrings.getString('themesGalleryURL'));
74 };
75 $('themes-reset').onclick = function(event) {
76 chrome.send('themesReset');
77 };
78 // Ensure that changes are committed when closing the page.
79 window.addEventListener('unload', function() {
80 if (document.activeElement == homepageField)
81 homepageField.blur();
82 });
83
84 // Search section.
65 $('defaultSearchManageEnginesButton').onclick = function(event) { 85 $('defaultSearchManageEnginesButton').onclick = function(event) {
66 OptionsPage.navigateToPage('searchEngines'); 86 OptionsPage.navigateToPage('searchEngines');
67 chrome.send('coreOptionsUserMetricsAction', 87 chrome.send('coreOptionsUserMetricsAction',
68 ['Options_ManageSearchEngines']); 88 ['Options_ManageSearchEngines']);
69 }; 89 };
70 $('advancedOptionsButton').onclick = function(event) {
71 OptionsPage.navigateToPage('advanced');
72 chrome.send('coreOptionsUserMetricsAction',
73 ['Options_OpenUnderTheHood']);
74 };
75 $('defaultSearchEngine').onchange = this.setDefaultSearchEngine_; 90 $('defaultSearchEngine').onchange = this.setDefaultSearchEngine_;
76 $('change-home-page').onclick = function(event) {
77 OptionsPage.navigateToPage('homePageOverlay');
78 };
79
80 var self = this;
81 $('instantEnabledCheckbox').customChangeHandler = function(event) { 91 $('instantEnabledCheckbox').customChangeHandler = function(event) {
82 if (this.checked) { 92 if (this.checked) {
83 if (self.instantConfirmDialogShown_) 93 if (self.instantConfirmDialogShown_)
84 chrome.send('enableInstant'); 94 chrome.send('enableInstant');
85 else 95 else
86 OptionsPage.navigateToPage('instantConfirm'); 96 OptionsPage.navigateToPage('instantConfirm');
87 } else { 97 } else {
88 chrome.send('disableInstant'); 98 chrome.send('disableInstant');
89 } 99 }
90 return true; 100 return true;
91 }; 101 };
92
93 $('instantFieldTrialCheckbox').addEventListener('change', 102 $('instantFieldTrialCheckbox').addEventListener('change',
94 function(event) { 103 function(event) {
95 this.checked = true; 104 this.checked = true;
96 chrome.send('disableInstant'); 105 chrome.send('disableInstant');
97 }); 106 });
98
99 Preferences.getInstance().addEventListener('instant.confirm_dialog_shown', 107 Preferences.getInstance().addEventListener('instant.confirm_dialog_shown',
100 this.onInstantConfirmDialogShownChanged_.bind(this)); 108 this.onInstantConfirmDialogShownChanged_.bind(this));
101
102 Preferences.getInstance().addEventListener('instant.enabled', 109 Preferences.getInstance().addEventListener('instant.enabled',
103 this.onInstantEnabledChanged_.bind(this)); 110 this.onInstantEnabledChanged_.bind(this));
104 111
105 // Text fields may change widths when the window changes size, so make 112 // Text fields may change widths when the window changes size, so make
106 // sure the suggestion list stays in sync. 113 // sure the suggestion list stays in sync.
107 window.addEventListener('resize', function() { 114 window.addEventListener('resize', function() {
108 self.autocompleteList_.syncWidthToInput(); 115 self.autocompleteList_.syncWidthToInput();
109 }); 116 });
110 117
111 // Ensure that changes are committed when closing the page.
112 window.addEventListener('unload', function() {
113 if (document.activeElement == homepageField)
114 homepageField.blur();
115 });
116
117 if (!cr.isChromeOS) {
118 $('defaultBrowserUseAsDefaultButton').onclick = function(event) {
119 chrome.send('becomeDefaultBrowser');
120 };
121 }
122
123 // Check if we are in the guest mode.
124 if (cr.commandLine && cr.commandLine.options['--bwsi']) { 118 if (cr.commandLine && cr.commandLine.options['--bwsi']) {
125 // Hide the startup section. 119 // Hide the startup section in Guest mode.
126 $('startupSection').hidden = true; 120 $('startupSection').hidden = true;
127 } 121 }
128 122
129 var suggestionList = new cr.ui.AutocompleteList(); 123 var suggestionList = new cr.ui.AutocompleteList();
130 suggestionList.autoExpands = true; 124 suggestionList.autoExpands = true;
131 suggestionList.suggestionUpdateRequestCallback = 125 suggestionList.suggestionUpdateRequestCallback =
132 this.requestAutocompleteSuggestions_.bind(this); 126 this.requestAutocompleteSuggestions_.bind(this);
133 $('main-content').appendChild(suggestionList); 127 $('main-content').appendChild(suggestionList);
134 this.autocompleteList_ = suggestionList; 128 this.autocompleteList_ = suggestionList;
129
130 // Users section.
131 var profilesList = $('profiles-list');
132 options.browser_options.ProfileList.decorate(profilesList);
133 profilesList.autoExpands = true;
134
135 profilesList.onchange = self.setProfileViewButtonsStatus_;
136 $('profiles-create').onclick = function(event) {
137 chrome.send('createProfile');
138 };
139 $('profiles-manage').onclick = function(event) {
140 var selectedProfile = self.getSelectedProfileItem_();
141 if (selectedProfile)
142 ManageProfileOverlay.showManageDialog(selectedProfile);
143 };
144 $('profiles-delete').onclick = function(event) {
145 var selectedProfile = self.getSelectedProfileItem_();
146 if (selectedProfile)
147 ManageProfileOverlay.showDeleteDialog(selectedProfile);
148 };
149
150 if (cr.isChromeOS) {
151 // Username (canonical email) of the currently logged in user or
152 // |kGuestUser| if a guest session is active.
153 this.username_ = localStrings.getString('username');
154
155 $('change-picture-button').onclick = function(event) {
156 OptionsPage.navigateToPage('changePicture');
157 };
158 this.updateAccountPicture_();
159
160 if (cr.commandLine && cr.commandLine.options['--bwsi']) {
161 // Disable the screen lock checkbox and change-picture-button in
162 // guest mode.
163 $('enable-screen-lock').disabled = true;
164 $('change-picture-button').disabled = true;
165 }
166 } else {
167 $('import-data').onclick = function(event) {
168 // Make sure that any previous import success message is hidden, and
169 // we're showing the UI to import further data.
170 $('import-data-configure').hidden = false;
171 $('import-data-success').hidden = true;
172 OptionsPage.navigateToPage('importData');
173 chrome.send('coreOptionsUserMetricsAction', ['Import_ShowDlg']);
174 };
175
176 if ($('themes-GTK-button')) {
177 $('themes-GTK-button').onclick = function(event) {
178 chrome.send('themesSetGTK');
179 };
180 }
181 }
182
183 // Default browser section.
184 if (!cr.isChromeOS) {
185 $('defaultBrowserUseAsDefaultButton').onclick = function(event) {
186 chrome.send('becomeDefaultBrowser');
187 };
188 }
189
190 // Under the hood section.
191 $('advancedOptionsButton').onclick = function(event) {
192 OptionsPage.navigateToPage('advanced');
193 chrome.send('coreOptionsUserMetricsAction',
194 ['Options_OpenUnderTheHood']);
195 };
135 }, 196 },
136 197
137 setSyncEnabled_: function(enabled) { 198 setSyncEnabled_: function(enabled) {
138 this.syncEnabled = enabled; 199 this.syncEnabled = enabled;
139 }, 200 },
140 201
141 setAutoLoginVisible_ : function(visible) { 202 setAutoLoginVisible_ : function(visible) {
142 $('enable-auto-login-checkbox').hidden = !visible; 203 $('enable-auto-login-checkbox').hidden = !visible;
143 }, 204 },
144 205
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // TODO(tbreisacher): remove the duplication by refactoring 423 // TODO(tbreisacher): remove the duplication by refactoring
363 updateAutocompleteSuggestions_: function(suggestions) { 424 updateAutocompleteSuggestions_: function(suggestions) {
364 var list = this.autocompleteList_; 425 var list = this.autocompleteList_;
365 // If the trigger for this update was a value being selected from the 426 // If the trigger for this update was a value being selected from the
366 // current list, do nothing. 427 // current list, do nothing.
367 if (list.targetInput && list.selectedItem && 428 if (list.targetInput && list.selectedItem &&
368 list.selectedItem['url'] == list.targetInput.value) 429 list.selectedItem['url'] == list.targetInput.value)
369 return; 430 return;
370 list.suggestions = suggestions; 431 list.suggestions = suggestions;
371 }, 432 },
433
434 /**
435 * Get the selected profile item from the profile list. This also works
436 * correctly if the list is not displayed.
437 * @return {Object} the profile item object, or null if nothing is selected.
438 * @private
439 */
440 getSelectedProfileItem_: function() {
441 var profilesList = $('profiles-list');
442 if (profilesList.hidden) {
443 if (profilesList.dataModel.length > 0)
444 return profilesList.dataModel.item(0);
445 } else {
446 return profilesList.selectedItem;
447 }
448 return null;
449 },
450
451 /**
452 * Helper function to set the status of profile view buttons to disabled or
453 * enabled, depending on the number of profiles and selection status of the
454 * profiles list.
455 */
456 setProfileViewButtonsStatus_: function() {
457 var profilesList = $('profiles-list');
458 var selectedProfile = profilesList.selectedItem;
459 var hasSelection = selectedProfile != null;
460 var hasSingleProfile = profilesList.dataModel.length == 1;
461 $('profiles-manage').disabled = !hasSelection ||
462 !selectedProfile.isCurrentProfile;
463 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile;
464 },
465
466 /**
467 * Display the correct dialog layout, depending on how many profiles are
468 * available.
469 * @param {number} numProfiles The number of profiles to display.
470 */
471 setProfileViewSingle_: function(numProfiles) {
472 var hasSingleProfile = numProfiles == 1;
473 $('profiles-list').hidden = hasSingleProfile;
474 $('profiles-single-message').hidden = !hasSingleProfile;
475 $('profiles-manage').hidden = hasSingleProfile;
476 $('profiles-delete').textContent = hasSingleProfile ?
477 templateData.profilesDeleteSingle :
478 templateData.profilesDelete;
479 },
480
481 /**
482 * Adds all |profiles| to the list.
483 * @param {Array.<Object>} An array of profile info objects.
484 * each object is of the form:
485 * profileInfo = {
486 * name: "Profile Name",
487 * iconURL: "chrome://path/to/icon/image",
488 * filePath: "/path/to/profile/data/on/disk",
489 * isCurrentProfile: false
490 * };
491 */
492 setProfilesInfo_: function(profiles) {
493 this.setProfileViewSingle_(profiles.length);
494 // add it to the list, even if the list is hidden so we can access it
495 // later.
496 $('profiles-list').dataModel = new ArrayDataModel(profiles);
497 this.setProfileViewButtonsStatus_();
498 },
499
500 setGtkThemeButtonEnabled_: function(enabled) {
501 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) {
502 $('themes-GTK-button').disabled = !enabled;
503 }
504 },
505
506 setThemesResetButtonEnabled_: function(enabled) {
507 $('themes-reset').disabled = !enabled;
508 },
509
510 /**
511 * (Re)loads IMG element with current user account picture.
512 */
513 updateAccountPicture_: function() {
514 $('account-picture').src =
515 'chrome://userimage/' + this.username_ +
516 '?id=' + (new Date()).getTime();
517 },
372 }; 518 };
373 519
374 //Forward public APIs to private implementations. 520 //Forward public APIs to private implementations.
375 [ 521 [
376 'getStartStopSyncButton', 522 'getStartStopSyncButton',
377 'hideSyncSection', 523 'hideSyncSection',
378 'setAutoLoginVisible', 524 'setAutoLoginVisible',
379 'setCustomizeSyncButtonEnabled', 525 'setCustomizeSyncButtonEnabled',
526 'setGtkThemeButtonEnabled',
527 'setInstantFieldTrialStatus',
528 'setProfilesInfo',
529 'setProfilesSectionVisible',
380 'setStartStopButtonEnabled', 530 'setStartStopButtonEnabled',
381 'setStartStopButtonLabel', 531 'setStartStopButtonLabel',
382 'setStartStopButtonVisible', 532 'setStartStopButtonVisible',
383 'setSyncActionLinkEnabled', 533 'setSyncActionLinkEnabled',
384 'setSyncActionLinkLabel', 534 'setSyncActionLinkLabel',
385 'setSyncEnabled', 535 'setSyncEnabled',
386 'setSyncSetupCompleted', 536 'setSyncSetupCompleted',
387 'setSyncStatus', 537 'setSyncStatus',
388 'setSyncStatusErrorVisible', 538 'setSyncStatusErrorVisible',
389 'setProfilesSectionVisible', 539 'setThemesResetButtonEnabled',
540 'updateAccountPicture',
541 'updateAutocompleteSuggestions',
390 'updateHomePageLabel', 542 'updateHomePageLabel',
391 'updateSearchEngines', 543 'updateSearchEngines',
392 'updateStartupPages', 544 'updateStartupPages',
393 'updateAutocompleteSuggestions',
394 'setInstantFieldTrialStatus',
395 ].forEach(function(name) { 545 ].forEach(function(name) {
396 BrowserOptions[name] = function(value) { 546 BrowserOptions[name] = function(value) {
397 return BrowserOptions.getInstance()[name + '_'](value); 547 return BrowserOptions.getInstance()[name + '_'](value);
398 }; 548 };
399 }); 549 });
400 550
401 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, 551 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault,
402 canBeDefault) { 552 canBeDefault) {
403 if (!cr.isChromeOS) { 553 if (!cr.isChromeOS) {
404 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, 554 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString,
405 isDefault, 555 isDefault,
406 canBeDefault); 556 canBeDefault);
407 } 557 }
408 }; 558 };
409 559
560 if (cr.isChromeOS) {
561 /**
562 * Returns username (canonical email) of the user logged in (ChromeOS only).
563 * @return {string} user email.
564 */
565 // TODO(jhawkins): Investigate the use case for this method.
566 BrowserOptions.getLoggedInUsername = function() {
567 return BrowserOptions.getInstance().username_;
568 };
569 }
570
410 // Export 571 // Export
411 return { 572 return {
412 BrowserOptions: BrowserOptions 573 BrowserOptions: BrowserOptions
413 }; 574 };
414 575
415 }); 576 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options2/browser_options.html ('k') | chrome/browser/resources/options2/browser_options_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698