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

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

Powered by Google App Engine
This is Rietveld 408576698