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 BrowserOptions = options.BrowserOptions;
11 var ClearBrowserDataOverlay = options.ClearBrowserDataOverlay;
12 var ConfirmDialog = options.ConfirmDialog;
13 var ContentSettingsExceptionsArea =
14 options.contentSettings.ContentSettingsExceptionsArea;
15 var ContentSettings = options.ContentSettings;
16 var CookiesView = options.CookiesView;
17 var CreateProfileOverlay = options.CreateProfileOverlay;
18 var EditDictionaryOverlay = cr.IsMac ? null : options.EditDictionaryOverlay;
19 var FactoryResetOverlay = options.FactoryResetOverlay;
20 <if expr="pp_ifdef('enable_google_now')">
21 var GeolocationOptions = options.GeolocationOptions;
23 var FontSettings = options.FontSettings;
24 var HandlerOptions = options.HandlerOptions;
25 var HomePageOverlay = options.HomePageOverlay;
26 var ImportDataOverlay = options.ImportDataOverlay;
27 var LanguageOptions = options.LanguageOptions;
28 var ManageProfileOverlay = options.ManageProfileOverlay;
29 var ManagedUserCreateConfirmOverlay = options.ManagedUserCreateConfirmOverlay;
30 var ManagedUserImportOverlay = options.ManagedUserImportOverlay;
31 var ManagedUserLearnMoreOverlay = options.ManagedUserLearnMoreOverlay;
32 var MediaGalleriesManager = options.MediaGalleriesManager;
33 var OptionsFocusManager = options.OptionsFocusManager;
34 var OptionsPage = options.OptionsPage;
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 SyncSetupOverlay = options.SyncSetupOverlay;
46 * DOMContentLoaded handler, sets up the page.
49 // Decorate the existing elements in the document.
50 cr.ui.decorate('input[pref][type=checkbox]', options.PrefCheckbox);
51 cr.ui.decorate('input[pref][type=number]', options.PrefNumber);
52 cr.ui.decorate('input[pref][type=radio]', options.PrefRadio);
53 cr.ui.decorate('input[pref][type=range]', options.PrefRange);
54 cr.ui.decorate('select[pref]', options.PrefSelect);
55 cr.ui.decorate('input[pref][type=text]', options.PrefTextField);
56 cr.ui.decorate('input[pref][type=url]', options.PrefTextField);
57 cr.ui.decorate('button[pref]', options.PrefButton);
58 cr.ui.decorate('#content-settings-page input[type=radio]:not(.handler-radio)',
59 options.ContentSettingsRadio);
60 cr.ui.decorate('#content-settings-page input[type=radio].handler-radio',
61 options.HandlersEnabledRadio);
62 cr.ui.decorate('span.controlled-setting-indicator',
63 options.ControlledSettingIndicator);
66 OptionsPage.register(SearchPage.getInstance());
67 OptionsPage.register(BrowserOptions.getInstance());
70 OptionsPage.registerOverlay(AddLanguageOverlay.getInstance(),
71 LanguageOptions.getInstance());
72 OptionsPage.registerOverlay(AlertOverlay.getInstance());
73 OptionsPage.registerOverlay(AutofillEditAddressOverlay.getInstance(),
74 AutofillOptions.getInstance());
75 OptionsPage.registerOverlay(AutofillEditCreditCardOverlay.getInstance(),
76 AutofillOptions.getInstance());
77 OptionsPage.registerOverlay(AutofillOptions.getInstance(),
78 BrowserOptions.getInstance(),
79 [$('autofill-settings')]);
80 OptionsPage.registerOverlay(ClearBrowserDataOverlay.getInstance(),
81 BrowserOptions.getInstance(),
82 [$('privacyClearDataButton')]);
83 OptionsPage.registerOverlay(
86 loadTimeData.getString('doNotTrackConfirmOverlayTabTitle'),
87 'do-not-track-confirm-overlay',
88 $('do-not-track-confirm-ok'),
89 $('do-not-track-confirm-cancel'),
90 $('do-not-track-enabled').pref,
91 $('do-not-track-enabled').metric),
92 BrowserOptions.getInstance());
93 // 'spelling-enabled-control' element is only present on Chrome branded
95 if ($('spelling-enabled-control')) {
96 OptionsPage.registerOverlay(
99 loadTimeData.getString('spellingConfirmOverlayTabTitle'),
100 'spelling-confirm-overlay',
101 $('spelling-confirm-ok'),
102 $('spelling-confirm-cancel'),
103 $('spelling-enabled-control').pref,
104 $('spelling-enabled-control').metric),
105 BrowserOptions.getInstance());
107 OptionsPage.registerOverlay(ContentSettings.getInstance(),
108 BrowserOptions.getInstance(),
109 [$('privacyContentSettingsButton')]);
110 OptionsPage.registerOverlay(ContentSettingsExceptionsArea.getInstance(),
111 ContentSettings.getInstance());
112 OptionsPage.registerOverlay(CookiesView.getInstance(),
113 ContentSettings.getInstance(),
114 [$('privacyContentSettingsButton'),
115 $('show-cookies-button')]);
116 OptionsPage.registerOverlay(CreateProfileOverlay.getInstance(),
117 BrowserOptions.getInstance());
119 OptionsPage.registerOverlay(EditDictionaryOverlay.getInstance(),
120 LanguageOptions.getInstance(),
121 [$('edit-dictionary-button')]);
123 OptionsPage.registerOverlay(FontSettings.getInstance(),
124 BrowserOptions.getInstance(),
125 [$('fontSettingsCustomizeFontsButton')]);
126 if (HandlerOptions && $('manage-handlers-button')) {
127 OptionsPage.registerOverlay(HandlerOptions.getInstance(),
128 ContentSettings.getInstance(),
129 [$('manage-handlers-button')]);
131 OptionsPage.registerOverlay(HomePageOverlay.getInstance(),
132 BrowserOptions.getInstance(),
133 [$('change-home-page')]);
134 OptionsPage.registerOverlay(ImportDataOverlay.getInstance(),
135 BrowserOptions.getInstance());
136 OptionsPage.registerOverlay(LanguageOptions.getInstance(),
137 BrowserOptions.getInstance(),
138 [$('language-button'),
139 $('manage-languages')]);
140 OptionsPage.registerOverlay(ManageProfileOverlay.getInstance(),
141 BrowserOptions.getInstance());
142 if (!cr.isChromeOS) {
143 OptionsPage.registerOverlay(ManagedUserCreateConfirmOverlay.getInstance(),
144 BrowserOptions.getInstance());
145 if (loadTimeData.getBoolean('allowCreateExistingManagedUsers')) {
146 OptionsPage.registerOverlay(ManagedUserImportOverlay.getInstance(),
147 BrowserOptions.getInstance());
149 OptionsPage.registerOverlay(ManagedUserLearnMoreOverlay.getInstance(),
150 CreateProfileOverlay.getInstance());
152 OptionsPage.registerOverlay(MediaGalleriesManager.getInstance(),
153 ContentSettings.getInstance(),
154 [$('manage-galleries-button')]);
155 OptionsPage.registerOverlay(PasswordManager.getInstance(),
156 BrowserOptions.getInstance(),
157 [$('manage-passwords')]);
158 OptionsPage.registerOverlay(ResetProfileSettingsOverlay.getInstance(),
159 BrowserOptions.getInstance(),
160 [$('reset-profile-settings')]);
161 OptionsPage.registerOverlay(SearchEngineManager.getInstance(),
162 BrowserOptions.getInstance(),
163 [$('manage-default-search-engines')]);
164 OptionsPage.registerOverlay(StartupOverlay.getInstance(),
165 BrowserOptions.getInstance());
166 OptionsPage.registerOverlay(SyncSetupOverlay.getInstance(),
167 BrowserOptions.getInstance(),
168 [$('customize-sync')]);
170 OptionsPage.registerOverlay(AccountsOptions.getInstance(),
171 BrowserOptions.getInstance(),
172 [$('manage-accounts-button')]);
173 OptionsPage.registerOverlay(BluetoothOptions.getInstance(),
174 BrowserOptions.getInstance(),
175 [$('bluetooth-add-device')]);
176 OptionsPage.registerOverlay(BluetoothPairing.getInstance(),
177 BrowserOptions.getInstance());
178 OptionsPage.registerOverlay(FactoryResetOverlay.getInstance(),
179 BrowserOptions.getInstance(),
180 [$('factory-reset-restart')]);
181 OptionsPage.registerOverlay(ChangePictureOptions.getInstance(),
182 BrowserOptions.getInstance(),
183 [$('account-picture')]);
184 OptionsPage.registerOverlay(DetailsInternetPage.getInstance(),
185 BrowserOptions.getInstance());
186 OptionsPage.registerOverlay(DisplayOptions.getInstance(),
187 BrowserOptions.getInstance(),
188 [$('display-options')]);
189 OptionsPage.registerOverlay(DisplayOverscan.getInstance(),
190 DisplayOptions.getInstance());
191 OptionsPage.registerOverlay(KeyboardOverlay.getInstance(),
192 BrowserOptions.getInstance(),
193 [$('keyboard-settings-button')]);
194 OptionsPage.registerOverlay(PointerOverlay.getInstance(),
195 BrowserOptions.getInstance(),
196 [$('pointer-settings-button')]);
197 OptionsPage.registerOverlay(PreferredNetworks.getInstance(),
198 BrowserOptions.getInstance());
201 if (!cr.isWindows && !cr.isMac) {
202 OptionsPage.registerOverlay(CertificateBackupOverlay.getInstance(),
203 CertificateManager.getInstance());
204 OptionsPage.registerOverlay(CertificateEditCaTrustOverlay.getInstance(),
205 CertificateManager.getInstance());
206 OptionsPage.registerOverlay(CertificateImportErrorOverlay.getInstance(),
207 CertificateManager.getInstance());
208 OptionsPage.registerOverlay(CertificateManager.getInstance(),
209 BrowserOptions.getInstance(),
210 [$('certificatesManageButton')]);
211 OptionsPage.registerOverlay(CertificateRestoreOverlay.getInstance(),
212 CertificateManager.getInstance());
215 cr.ui.FocusManager.disableMouseFocusOnButtons();
216 OptionsFocusManager.getInstance().initialize();
217 Preferences.getInstance().initialize();
218 ResetProfileSettingsBanner.getInstance().initialize();
219 OptionsPage.initialize();
221 var path = document.location.pathname;
223 if (path.length > 1) {
224 // Skip starting slash and remove trailing slash (if any).
225 var pageName = path.slice(1).replace(/\/$/, '');
226 OptionsPage.showPageByName(pageName, true, {replaceState: true});
228 OptionsPage.showDefaultPage();
231 var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs');
232 for (var i = 0; i < subpagesNavTabs.length; i++) {
233 subpagesNavTabs[i].onclick = function(event) {
234 OptionsPage.showTab(event.srcElement);
238 window.setTimeout(function() {
239 document.documentElement.classList.remove('loading');
243 document.documentElement.classList.add('loading');
244 document.addEventListener('DOMContentLoaded', load);
247 * Listener for the |beforeunload| event.
249 window.onbeforeunload = function() {
250 options.OptionsPage.willClose();
254 * Listener for the |popstate| event.
255 * @param {Event} e The |popstate| event.
257 window.onpopstate = function(e) {
258 options.OptionsPage.setState(e.state);