BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / resources / options / options.js
blobffea2c3dc1912f386e2a1895609a6f325787b21f
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 var AddLanguageOverlay = options.AddLanguageOverlay;
6 var AlertOverlay = options.AlertOverlay;
7 var AutofillEditAddressOverlay = options.AutofillEditAddressOverlay;
8 var AutofillEditCreditCardOverlay = options.AutofillEditCreditCardOverlay;
9 var AutofillOptions = options.AutofillOptions;
10 var AutomaticSettingsResetBanner = options.AutomaticSettingsResetBanner;
11 var BrowserOptions = options.BrowserOptions;
12 var ClearBrowserDataOverlay = options.ClearBrowserDataOverlay;
13 var ConfirmDialog = options.ConfirmDialog;
14 var ContentSettingsExceptionsArea =
15     options.contentSettings.ContentSettingsExceptionsArea;
16 var ContentSettings = options.ContentSettings;
17 var CookiesView = options.CookiesView;
18 var CreateProfileOverlay = options.CreateProfileOverlay;
19 var EditDictionaryOverlay = cr.IsMac ? null : options.EditDictionaryOverlay;
20 var EasyUnlockTurnOffOverlay = options.EasyUnlockTurnOffOverlay;
21 var FactoryResetOverlay = options.FactoryResetOverlay;
22 <if expr="enable_google_now">
23 var GeolocationOptions = options.GeolocationOptions;
24 </if>
25 var FontSettings = options.FontSettings;
26 var HandlerOptions = options.HandlerOptions;
27 var HomePageOverlay = options.HomePageOverlay;
28 var HotwordConfirmDialog = options.HotwordConfirmDialog;
29 var ImportDataOverlay = options.ImportDataOverlay;
30 var LanguageOptions = options.LanguageOptions;
31 var ManageProfileOverlay = options.ManageProfileOverlay;
32 var OptionsFocusManager = options.OptionsFocusManager;
33 var OptionsPage = options.OptionsPage;
34 var PageManager = cr.ui.pageManager.PageManager;
35 var PasswordManager = options.PasswordManager;
36 var Preferences = options.Preferences;
37 var PreferredNetworks = options.PreferredNetworks;
38 var ResetProfileSettingsBanner = options.ResetProfileSettingsBanner;
39 var ResetProfileSettingsOverlay = options.ResetProfileSettingsOverlay;
40 var SearchEngineManager = options.SearchEngineManager;
41 var SearchPage = options.SearchPage;
42 var StartupOverlay = options.StartupOverlay;
43 var SupervisedUserCreateConfirmOverlay =
44     options.SupervisedUserCreateConfirmOverlay;
45 var SupervisedUserImportOverlay = options.SupervisedUserImportOverlay;
46 var SupervisedUserLearnMoreOverlay = options.SupervisedUserLearnMoreOverlay;
47 var SyncSetupOverlay = options.SyncSetupOverlay;
48 var ThirdPartyImeConfirmOverlay = options.ThirdPartyImeConfirmOverlay;
50 /**
51  * DOMContentLoaded handler, sets up the page.
52  */
53 function load() {
54   // Decorate the existing elements in the document.
55   cr.ui.decorate('input[pref][type=checkbox]', options.PrefCheckbox);
56   cr.ui.decorate('input[pref][type=number]', options.PrefNumber);
57   cr.ui.decorate('input[pref][type=radio]', options.PrefRadio);
58   cr.ui.decorate('input[pref][type=range]', options.PrefRange);
59   cr.ui.decorate('select[pref]', options.PrefSelect);
60   cr.ui.decorate('input[pref][type=text]', options.PrefTextField);
61   cr.ui.decorate('input[pref][type=url]', options.PrefTextField);
62   cr.ui.decorate('button[pref]', options.PrefButton);
63   cr.ui.decorate('#content-settings-page input[type=radio]:not(.handler-radio)',
64       options.ContentSettingsRadio);
65   cr.ui.decorate('#content-settings-page input[type=radio].handler-radio',
66       options.HandlersEnabledRadio);
67   cr.ui.decorate('span.controlled-setting-indicator',
68       options.ControlledSettingIndicator);
70   // Top level pages.
71   PageManager.register(SearchPage.getInstance());
72   PageManager.register(BrowserOptions.getInstance());
74   // Overlays.
75   PageManager.registerOverlay(AddLanguageOverlay.getInstance(),
76                               LanguageOptions.getInstance());
77   PageManager.registerOverlay(AlertOverlay.getInstance());
78   PageManager.registerOverlay(AutofillEditAddressOverlay.getInstance(),
79                               AutofillOptions.getInstance());
80   PageManager.registerOverlay(AutofillEditCreditCardOverlay.getInstance(),
81                               AutofillOptions.getInstance());
82   PageManager.registerOverlay(AutofillOptions.getInstance(),
83                               BrowserOptions.getInstance(),
84                               [$('autofill-settings')]);
85   PageManager.registerOverlay(ClearBrowserDataOverlay.getInstance(),
86                               BrowserOptions.getInstance(),
87                               [$('privacyClearDataButton')]);
88   PageManager.registerOverlay(
89       new ConfirmDialog(
90           'doNotTrackConfirm',
91           loadTimeData.getString('doNotTrackConfirmOverlayTabTitle'),
92           'do-not-track-confirm-overlay',
93           /** @type {HTMLButtonElement} */($('do-not-track-confirm-ok')),
94           /** @type {HTMLButtonElement} */($('do-not-track-confirm-cancel')),
95           $('do-not-track-enabled')['pref'],
96           $('do-not-track-enabled')['metric']),
97       BrowserOptions.getInstance());
98   PageManager.registerOverlay(
99       new ConfirmDialog(
100           'spellingConfirm',
101           loadTimeData.getString('spellingConfirmOverlayTabTitle'),
102           'spelling-confirm-overlay',
103           /** @type {HTMLButtonElement} */($('spelling-confirm-ok')),
104           /** @type {HTMLButtonElement} */($('spelling-confirm-cancel')),
105           $('spelling-enabled-control')['pref'],
106           $('spelling-enabled-control')['metric']),
107       BrowserOptions.getInstance());
108   PageManager.registerOverlay(new HotwordConfirmDialog(),
109                               BrowserOptions.getInstance());
110   PageManager.registerOverlay(ContentSettings.getInstance(),
111                               BrowserOptions.getInstance(),
112                               [$('privacyContentSettingsButton')]);
113   PageManager.registerOverlay(ContentSettingsExceptionsArea.getInstance(),
114                               ContentSettings.getInstance());
115   PageManager.registerOverlay(CookiesView.getInstance(),
116                               ContentSettings.getInstance(),
117                               [$('privacyContentSettingsButton'),
118                                $('show-cookies-button')]);
119   PageManager.registerOverlay(CreateProfileOverlay.getInstance(),
120                               BrowserOptions.getInstance());
121   PageManager.registerOverlay(EasyUnlockTurnOffOverlay.getInstance(),
122                               BrowserOptions.getInstance(),
123                               [$('easy-unlock-turn-off-button')]);
124   if (!cr.isMac) {
125     PageManager.registerOverlay(EditDictionaryOverlay.getInstance(),
126                                 LanguageOptions.getInstance(),
127                                 [$('edit-custom-dictionary-button')]);
128   }
129   PageManager.registerOverlay(FontSettings.getInstance(),
130                               BrowserOptions.getInstance(),
131                               [$('fontSettingsCustomizeFontsButton')]);
132   if (HandlerOptions && $('manage-handlers-button')) {
133     PageManager.registerOverlay(HandlerOptions.getInstance(),
134                                 ContentSettings.getInstance(),
135                                 [$('manage-handlers-button')]);
136   }
137   PageManager.registerOverlay(HomePageOverlay.getInstance(),
138                               BrowserOptions.getInstance(),
139                               [$('change-home-page')]);
140   PageManager.registerOverlay(ImportDataOverlay.getInstance(),
141                               BrowserOptions.getInstance());
142   PageManager.registerOverlay(LanguageOptions.getInstance(),
143                               BrowserOptions.getInstance(),
144                               [$('language-button'),
145                                $('manage-languages')]);
146   PageManager.registerOverlay(ManageProfileOverlay.getInstance(),
147                               BrowserOptions.getInstance());
148   if (!cr.isChromeOS) {
149     PageManager.registerOverlay(SupervisedUserCreateConfirmOverlay.
150                                     getInstance(),
151                                 BrowserOptions.getInstance());
152     PageManager.registerOverlay(SupervisedUserImportOverlay.getInstance(),
153                                 CreateProfileOverlay.getInstance());
154     PageManager.registerOverlay(SupervisedUserLearnMoreOverlay.getInstance(),
155                                 CreateProfileOverlay.getInstance());
156   }
157   PageManager.registerOverlay(PasswordManager.getInstance(),
158                               BrowserOptions.getInstance(),
159                               [$('manage-passwords')]);
160   PageManager.registerOverlay(ResetProfileSettingsOverlay.getInstance(),
161                               BrowserOptions.getInstance(),
162                               [$('reset-profile-settings')]);
163   PageManager.registerOverlay(SearchEngineManager.getInstance(),
164                               BrowserOptions.getInstance(),
165                               [$('manage-default-search-engines')]);
166   PageManager.registerOverlay(StartupOverlay.getInstance(),
167                               BrowserOptions.getInstance());
168   PageManager.registerOverlay(SyncSetupOverlay.getInstance(),
169                               BrowserOptions.getInstance(),
170                               [$('customize-sync')]);
171   if (loadTimeData.getBoolean('showAbout')) {
172     PageManager.registerOverlay(help.HelpPage.getInstance(),
173                                 BrowserOptions.getInstance());
174     if (help.ChannelChangePage) {
175       PageManager.registerOverlay(help.ChannelChangePage.getInstance(),
176                                   help.HelpPage.getInstance());
177     }
178   }
179   if (cr.isChromeOS) {
180     PageManager.registerOverlay(AccountsOptions.getInstance(),
181                                 BrowserOptions.getInstance(),
182                                 [$('manage-accounts-button')]);
183     PageManager.registerOverlay(BluetoothOptions.getInstance(),
184                                 BrowserOptions.getInstance(),
185                                 [$('bluetooth-add-device')]);
186     PageManager.registerOverlay(BluetoothPairing.getInstance(),
187                                 BrowserOptions.getInstance());
188     PageManager.registerOverlay(FactoryResetOverlay.getInstance(),
189                                 BrowserOptions.getInstance(),
190                                 [$('factory-reset-restart')]);
191     PageManager.registerOverlay(ChangePictureOptions.getInstance(),
192                                 BrowserOptions.getInstance(),
193                                 [$('account-picture')]);
194     PageManager.registerOverlay(ConsumerManagementOverlay.getInstance(),
195                                 BrowserOptions.getInstance());
196     PageManager.registerOverlay(DetailsInternetPage.getInstance(),
197                                 BrowserOptions.getInstance());
198     PageManager.registerOverlay(DisplayOptions.getInstance(),
199                                 BrowserOptions.getInstance(),
200                                 [$('display-options')]);
201     PageManager.registerOverlay(DisplayOverscan.getInstance(),
202                                 DisplayOptions.getInstance());
203     PageManager.registerOverlay(KeyboardOverlay.getInstance(),
204                                 BrowserOptions.getInstance(),
205                                 [$('keyboard-settings-button')]);
206     PageManager.registerOverlay(PointerOverlay.getInstance(),
207                                 BrowserOptions.getInstance(),
208                                 [$('pointer-settings-button')]);
209     PageManager.registerOverlay(PreferredNetworks.getInstance(),
210                                 BrowserOptions.getInstance());
211     PageManager.registerOverlay(PowerOverlay.getInstance(),
212                                 BrowserOptions.getInstance(),
213                                 [$('power-settings-link')]);
214     PageManager.registerOverlay(ThirdPartyImeConfirmOverlay.getInstance(),
215                                 LanguageOptions.getInstance());
216   }
218   if (!cr.isWindows && !cr.isMac) {
219     PageManager.registerOverlay(CertificateBackupOverlay.getInstance(),
220                                 CertificateManager.getInstance());
221     PageManager.registerOverlay(CertificateEditCaTrustOverlay.getInstance(),
222                                 CertificateManager.getInstance());
223     PageManager.registerOverlay(CertificateImportErrorOverlay.getInstance(),
224                                 CertificateManager.getInstance());
225     PageManager.registerOverlay(CertificateManager.getInstance(),
226                                 BrowserOptions.getInstance(),
227                                 [$('certificatesManageButton')]);
228     PageManager.registerOverlay(CertificateRestoreOverlay.getInstance(),
229                                 CertificateManager.getInstance());
230   }
232   OptionsFocusManager.getInstance().initialize();
233   Preferences.getInstance().initialize();
234   ResetProfileSettingsBanner.getInstance().initialize();
235   AutomaticSettingsResetBanner.getInstance().initialize();
236   OptionsPage.initialize();
237   PageManager.initialize(BrowserOptions.getInstance());
238   PageManager.addObserver(new uber.PageManagerObserver());
239   uber.onContentFrameLoaded();
241   var pageName = PageManager.getPageNameFromPath();
242   // Still update history so that chrome://settings/nonexistant redirects
243   // appropriately to chrome://settings/. If the URL matches, updateHistory_
244   // will avoid the extra replaceState.
245   var updateHistory = true;
246   PageManager.showPageByName(pageName, updateHistory,
247                              {replaceState: true, hash: location.hash});
249   var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs');
250   for (var i = 0; i < subpagesNavTabs.length; i++) {
251     subpagesNavTabs[i].onclick = function(event) {
252       OptionsPage.showTab(event.srcElement);
253     };
254   }
256   window.setTimeout(function() {
257     document.documentElement.classList.remove('loading');
258     chrome.send('onFinishedLoadingOptions');
259   }, 0);
262 document.documentElement.classList.add('loading');
263 document.addEventListener('DOMContentLoaded', load);
266  * Listener for the |beforeunload| event.
267  */
268 window.onbeforeunload = function() {
269   PageManager.willClose();
273  * Listener for the |popstate| event.
274  * @param {Event} e The |popstate| event.
275  */
276 window.onpopstate = function(e) {
277   var pageName = PageManager.getPageNameFromPath();
278   PageManager.setState(pageName, location.hash, e.state);