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. 4 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 WebsiteSettingsEditor = options.WebsiteSettings.WebsiteSettingsEditor; 49 var WebsiteSettingsManager = options.ContentSettings.WebsiteSettingsManager; 50 var ThirdPartyImeConfirmOverlay = options.ThirdPartyImeConfirmOverlay; 51 52 /** 53 * DOMContentLoaded handler, sets up the page. 54 */ 55 function load() { 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); 71 72 // Top level pages. 73 PageManager.register(SearchPage.getInstance()); 74 PageManager.register(BrowserOptions.getInstance()); 75 76 // Overlays. 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( 91 new ConfirmDialog( 92 'doNotTrackConfirm', 93 loadTimeData.getString('doNotTrackConfirmOverlayTabTitle'), 94 'do-not-track-confirm-overlay', 95 /** @type {HTMLInputElement} */($('do-not-track-confirm-ok')), 96 /** @type {HTMLInputElement} */($('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 101 // builds. 102 if ($('spelling-enabled-control')) { 103 PageManager.registerOverlay( 104 new ConfirmDialog( 105 'spellingConfirm', 106 loadTimeData.getString('spellingConfirmOverlayTabTitle'), 107 'spelling-confirm-overlay', 108 /** @type {HTMLInputElement} */($('spelling-confirm-ok')), 109 /** @type {HTMLInputElement} */($('spelling-confirm-cancel')), 110 $('spelling-enabled-control')['pref'], 111 $('spelling-enabled-control')['metric']), 112 BrowserOptions.getInstance()); 113 } 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')]); 134 if (!cr.isMac) { 135 PageManager.registerOverlay(EditDictionaryOverlay.getInstance(), 136 LanguageOptions.getInstance(), 137 [$('edit-dictionary-button')]); 138 } 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')]); 146 } 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. 160 getInstance(), 161 BrowserOptions.getInstance()); 162 PageManager.registerOverlay(SupervisedUserImportOverlay.getInstance(), 163 CreateProfileOverlay.getInstance()); 164 PageManager.registerOverlay(SupervisedUserLearnMoreOverlay.getInstance(), 165 CreateProfileOverlay.getInstance()); 166 } 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()); 187 } 188 } 189 if (cr.isChromeOS) { 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(ThirdPartyImeConfirmOverlay.getInstance(), 222 LanguageOptions.getInstance()); 223 } 224 225 if (!cr.isWindows && !cr.isMac) { 226 PageManager.registerOverlay(CertificateBackupOverlay.getInstance(), 227 CertificateManager.getInstance()); 228 PageManager.registerOverlay(CertificateEditCaTrustOverlay.getInstance(), 229 CertificateManager.getInstance()); 230 PageManager.registerOverlay(CertificateImportErrorOverlay.getInstance(), 231 CertificateManager.getInstance()); 232 PageManager.registerOverlay(CertificateManager.getInstance(), 233 BrowserOptions.getInstance(), 234 [$('certificatesManageButton')]); 235 PageManager.registerOverlay(CertificateRestoreOverlay.getInstance(), 236 CertificateManager.getInstance()); 237 } 238 239 cr.ui.FocusManager.disableMouseFocusOnButtons(); 240 OptionsFocusManager.getInstance().initialize(); 241 Preferences.getInstance().initialize(); 242 ResetProfileSettingsBanner.getInstance().initialize(); 243 AutomaticSettingsResetBanner.getInstance().initialize(); 244 OptionsPage.initialize(); 245 PageManager.initialize(BrowserOptions.getInstance()); 246 PageManager.addObserver(new uber.PageManagerObserver()); 247 uber.onContentFrameLoaded(); 248 249 var pageName = PageManager.getPageNameFromPath(); 250 // Still update history so that chrome://settings/nonexistant redirects 251 // appropriately to chrome://settings/. If the URL matches, updateHistory_ 252 // will avoid the extra replaceState. 253 var updateHistory = true; 254 PageManager.showPageByName(pageName, updateHistory, 255 {replaceState: true, hash: location.hash}); 256 257 var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs'); 258 for (var i = 0; i < subpagesNavTabs.length; i++) { 259 subpagesNavTabs[i].onclick = function(event) { 260 OptionsPage.showTab(event.srcElement); 261 }; 262 } 263 264 window.setTimeout(function() { 265 document.documentElement.classList.remove('loading'); 266 chrome.send('onFinishedLoadingOptions'); 267 }, 0); 268 } 269 270 document.documentElement.classList.add('loading'); 271 document.addEventListener('DOMContentLoaded', load); 272 273 /** 274 * Listener for the |beforeunload| event. 275 */ 276 window.onbeforeunload = function() { 277 PageManager.willClose(); 278 }; 279 280 /** 281 * Listener for the |popstate| event. 282 * @param {Event} e The |popstate| event. 283 */ 284 window.onpopstate = function(e) { 285 var pageName = PageManager.getPageNameFromPath(); 286 PageManager.setState(pageName, location.hash, e.state); 287 }; 288