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;
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 WebsiteSettingsEditor = options.WebsiteSettings.WebsiteSettingsEditor;
49 var WebsiteSettingsManager = options.ContentSettings.WebsiteSettingsManager;
50 var ThirdPartyImeConfirmOverlay = options.ThirdPartyImeConfirmOverlay;
53 * DOMContentLoaded handler, sets up the page.
56 // Decorate the existing elements in the document.
57 cr.ui.decorate('input[pref][type=checkbox]', options.PrefCheckbox);
58 cr.ui.decorate('input[pref][type=number]', options.PrefNumber);
59 cr.ui.decorate('input[pref][type=radio]', options.PrefRadio);
60 cr.ui.decorate('input[pref][type=range]', options.PrefRange);
61 cr.ui.decorate('select[pref]', options.PrefSelect);
62 cr.ui.decorate('input[pref][type=text]', options.PrefTextField);
63 cr.ui.decorate('input[pref][type=url]', options.PrefTextField);
64 cr.ui.decorate('button[pref]', options.PrefButton);
65 cr.ui.decorate('#content-settings-page input[type=radio]:not(.handler-radio)',
66 options.ContentSettingsRadio);
67 cr.ui.decorate('#content-settings-page input[type=radio].handler-radio',
68 options.HandlersEnabledRadio);
69 cr.ui.decorate('span.controlled-setting-indicator',
70 options.ControlledSettingIndicator);
73 PageManager.register(SearchPage.getInstance());
74 PageManager.register(BrowserOptions.getInstance());
77 PageManager.registerOverlay(AddLanguageOverlay.getInstance(),
78 LanguageOptions.getInstance());
79 PageManager.registerOverlay(AlertOverlay.getInstance());
80 PageManager.registerOverlay(AutofillEditAddressOverlay.getInstance(),
81 AutofillOptions.getInstance());
82 PageManager.registerOverlay(AutofillEditCreditCardOverlay.getInstance(),
83 AutofillOptions.getInstance());
84 PageManager.registerOverlay(AutofillOptions.getInstance(),
85 BrowserOptions.getInstance(),
86 [$('autofill-settings')]);
87 PageManager.registerOverlay(ClearBrowserDataOverlay.getInstance(),
88 BrowserOptions.getInstance(),
89 [$('privacyClearDataButton')]);
90 PageManager.registerOverlay(
93 loadTimeData.getString('doNotTrackConfirmOverlayTabTitle'),
94 'do-not-track-confirm-overlay',
95 /** @type {HTMLButtonElement} */($('do-not-track-confirm-ok')),
96 /** @type {HTMLButtonElement} */($('do-not-track-confirm-cancel')),
97 $('do-not-track-enabled')['pref'],
98 $('do-not-track-enabled')['metric']),
99 BrowserOptions.getInstance());
100 // 'spelling-enabled-control' element is only present on Chrome branded
102 if ($('spelling-enabled-control')) {
103 PageManager.registerOverlay(
106 loadTimeData.getString('spellingConfirmOverlayTabTitle'),
107 'spelling-confirm-overlay',
108 /** @type {HTMLButtonElement} */($('spelling-confirm-ok')),
109 /** @type {HTMLButtonElement} */($('spelling-confirm-cancel')),
110 $('spelling-enabled-control')['pref'],
111 $('spelling-enabled-control')['metric']),
112 BrowserOptions.getInstance());
114 PageManager.registerOverlay(new HotwordConfirmDialog(),
115 BrowserOptions.getInstance());
116 PageManager.registerOverlay(ContentSettings.getInstance(),
117 BrowserOptions.getInstance(),
118 [$('privacyContentSettingsButton')]);
119 PageManager.registerOverlay(WebsiteSettingsManager.getInstance(),
120 ContentSettings.getInstance());
121 PageManager.registerOverlay(WebsiteSettingsEditor.getInstance(),
122 WebsiteSettingsManager.getInstance());
123 PageManager.registerOverlay(ContentSettingsExceptionsArea.getInstance(),
124 ContentSettings.getInstance());
125 PageManager.registerOverlay(CookiesView.getInstance(),
126 ContentSettings.getInstance(),
127 [$('privacyContentSettingsButton'),
128 $('show-cookies-button')]);
129 PageManager.registerOverlay(CreateProfileOverlay.getInstance(),
130 BrowserOptions.getInstance());
131 PageManager.registerOverlay(EasyUnlockTurnOffOverlay.getInstance(),
132 BrowserOptions.getInstance(),
133 [$('easy-unlock-turn-off-button')]);
135 PageManager.registerOverlay(EditDictionaryOverlay.getInstance(),
136 LanguageOptions.getInstance(),
137 [$('edit-dictionary-button')]);
139 PageManager.registerOverlay(FontSettings.getInstance(),
140 BrowserOptions.getInstance(),
141 [$('fontSettingsCustomizeFontsButton')]);
142 if (HandlerOptions && $('manage-handlers-button')) {
143 PageManager.registerOverlay(HandlerOptions.getInstance(),
144 ContentSettings.getInstance(),
145 [$('manage-handlers-button')]);
147 PageManager.registerOverlay(HomePageOverlay.getInstance(),
148 BrowserOptions.getInstance(),
149 [$('change-home-page')]);
150 PageManager.registerOverlay(ImportDataOverlay.getInstance(),
151 BrowserOptions.getInstance());
152 PageManager.registerOverlay(LanguageOptions.getInstance(),
153 BrowserOptions.getInstance(),
154 [$('language-button'),
155 $('manage-languages')]);
156 PageManager.registerOverlay(ManageProfileOverlay.getInstance(),
157 BrowserOptions.getInstance());
158 if (!cr.isChromeOS) {
159 PageManager.registerOverlay(SupervisedUserCreateConfirmOverlay.
161 BrowserOptions.getInstance());
162 PageManager.registerOverlay(SupervisedUserImportOverlay.getInstance(),
163 CreateProfileOverlay.getInstance());
164 PageManager.registerOverlay(SupervisedUserLearnMoreOverlay.getInstance(),
165 CreateProfileOverlay.getInstance());
167 PageManager.registerOverlay(PasswordManager.getInstance(),
168 BrowserOptions.getInstance(),
169 [$('manage-passwords')]);
170 PageManager.registerOverlay(ResetProfileSettingsOverlay.getInstance(),
171 BrowserOptions.getInstance(),
172 [$('reset-profile-settings')]);
173 PageManager.registerOverlay(SearchEngineManager.getInstance(),
174 BrowserOptions.getInstance(),
175 [$('manage-default-search-engines')]);
176 PageManager.registerOverlay(StartupOverlay.getInstance(),
177 BrowserOptions.getInstance());
178 PageManager.registerOverlay(SyncSetupOverlay.getInstance(),
179 BrowserOptions.getInstance(),
180 [$('customize-sync')]);
181 if (loadTimeData.getBoolean('showAbout')) {
182 PageManager.registerOverlay(help.HelpPage.getInstance(),
183 BrowserOptions.getInstance());
184 if (help.ChannelChangePage) {
185 PageManager.registerOverlay(help.ChannelChangePage.getInstance(),
186 help.HelpPage.getInstance());
190 PageManager.registerOverlay(AccountsOptions.getInstance(),
191 BrowserOptions.getInstance(),
192 [$('manage-accounts-button')]);
193 PageManager.registerOverlay(BluetoothOptions.getInstance(),
194 BrowserOptions.getInstance(),
195 [$('bluetooth-add-device')]);
196 PageManager.registerOverlay(BluetoothPairing.getInstance(),
197 BrowserOptions.getInstance());
198 PageManager.registerOverlay(FactoryResetOverlay.getInstance(),
199 BrowserOptions.getInstance(),
200 [$('factory-reset-restart')]);
201 PageManager.registerOverlay(ChangePictureOptions.getInstance(),
202 BrowserOptions.getInstance(),
203 [$('account-picture')]);
204 PageManager.registerOverlay(ConsumerManagementOverlay.getInstance(),
205 BrowserOptions.getInstance());
206 PageManager.registerOverlay(DetailsInternetPage.getInstance(),
207 BrowserOptions.getInstance());
208 PageManager.registerOverlay(DisplayOptions.getInstance(),
209 BrowserOptions.getInstance(),
210 [$('display-options')]);
211 PageManager.registerOverlay(DisplayOverscan.getInstance(),
212 DisplayOptions.getInstance());
213 PageManager.registerOverlay(KeyboardOverlay.getInstance(),
214 BrowserOptions.getInstance(),
215 [$('keyboard-settings-button')]);
216 PageManager.registerOverlay(PointerOverlay.getInstance(),
217 BrowserOptions.getInstance(),
218 [$('pointer-settings-button')]);
219 PageManager.registerOverlay(PreferredNetworks.getInstance(),
220 BrowserOptions.getInstance());
221 PageManager.registerOverlay(PowerOverlay.getInstance(),
222 BrowserOptions.getInstance(),
223 [$('power-settings-button')]);
224 PageManager.registerOverlay(ThirdPartyImeConfirmOverlay.getInstance(),
225 LanguageOptions.getInstance());
228 if (!cr.isWindows && !cr.isMac) {
229 PageManager.registerOverlay(CertificateBackupOverlay.getInstance(),
230 CertificateManager.getInstance());
231 PageManager.registerOverlay(CertificateEditCaTrustOverlay.getInstance(),
232 CertificateManager.getInstance());
233 PageManager.registerOverlay(CertificateImportErrorOverlay.getInstance(),
234 CertificateManager.getInstance());
235 PageManager.registerOverlay(CertificateManager.getInstance(),
236 BrowserOptions.getInstance(),
237 [$('certificatesManageButton')]);
238 PageManager.registerOverlay(CertificateRestoreOverlay.getInstance(),
239 CertificateManager.getInstance());
242 OptionsFocusManager.getInstance().initialize();
243 Preferences.getInstance().initialize();
244 ResetProfileSettingsBanner.getInstance().initialize();
245 AutomaticSettingsResetBanner.getInstance().initialize();
246 OptionsPage.initialize();
247 PageManager.initialize(BrowserOptions.getInstance());
248 PageManager.addObserver(new uber.PageManagerObserver());
249 uber.onContentFrameLoaded();
251 var pageName = PageManager.getPageNameFromPath();
252 // Still update history so that chrome://settings/nonexistant redirects
253 // appropriately to chrome://settings/. If the URL matches, updateHistory_
254 // will avoid the extra replaceState.
255 var updateHistory = true;
256 PageManager.showPageByName(pageName, updateHistory,
257 {replaceState: true, hash: location.hash});
259 var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs');
260 for (var i = 0; i < subpagesNavTabs.length; i++) {
261 subpagesNavTabs[i].onclick = function(event) {
262 OptionsPage.showTab(event.srcElement);
266 window.setTimeout(function() {
267 document.documentElement.classList.remove('loading');
268 chrome.send('onFinishedLoadingOptions');
272 document.documentElement.classList.add('loading');
273 document.addEventListener('DOMContentLoaded', load);
276 * Listener for the |beforeunload| event.
278 window.onbeforeunload = function() {
279 PageManager.willClose();
283 * Listener for the |popstate| event.
284 * @param {Event} e The |popstate| event.
286 window.onpopstate = function(e) {
287 var pageName = PageManager.getPageNameFromPath();
288 PageManager.setState(pageName, location.hash, e.state);