Home | History | Annotate | Download | only in options
      1 // Copyright (c) 2011 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 AdvancedOptions = options.AdvancedOptions;
      7 var AlertOverlay = options.AlertOverlay;
      8 var AutofillEditAddressOverlay = options.AutofillEditAddressOverlay;
      9 var AutofillEditCreditCardOverlay = options.AutofillEditCreditCardOverlay;
     10 var AutofillOptions = options.AutofillOptions;
     11 var BrowserOptions = options.BrowserOptions;
     12 var ClearBrowserDataOverlay = options.ClearBrowserDataOverlay;
     13 var ContentSettings = options.ContentSettings;
     14 var ContentSettingsExceptionsArea =
     15     options.contentSettings.ContentSettingsExceptionsArea;
     16 var CookiesView = options.CookiesView;
     17 var FontSettings = options.FontSettings;
     18 var ImportDataOverlay = options.ImportDataOverlay;
     19 var InstantConfirmOverlay = options.InstantConfirmOverlay;
     20 var LanguageOptions = options.LanguageOptions;
     21 var OptionsPage = options.OptionsPage;
     22 var PasswordManager = options.PasswordManager;
     23 var PersonalOptions = options.PersonalOptions;
     24 var Preferences = options.Preferences;
     25 var ProxyOptions = options.ProxyOptions;
     26 var SearchEngineManager = options.SearchEngineManager;
     27 var SearchPage = options.SearchPage;
     28 var SyncSetupOverlay = options.SyncSetupOverlay;
     29 
     30 /**
     31  * DOMContentLoaded handler, sets up the page.
     32  */
     33 function load() {
     34   // Decorate the existing elements in the document.
     35   cr.ui.decorate('input[pref][type=checkbox]', options.PrefCheckbox);
     36   cr.ui.decorate('input[pref][type=number]', options.PrefNumber);
     37   cr.ui.decorate('input[pref][type=radio]', options.PrefRadio);
     38   cr.ui.decorate('input[pref][type=range]', options.PrefRange);
     39   cr.ui.decorate('select[pref]', options.PrefSelect);
     40   cr.ui.decorate('input[pref][type=text]', options.PrefTextField);
     41   cr.ui.decorate('input[pref][type=url]', options.PrefTextField);
     42   cr.ui.decorate('#content-settings-page input[type=radio]',
     43       options.ContentSettingsRadio);
     44 
     45   var menuOffPattern = /(^\?|&)menu=off($|&)/;
     46   var menuDisabled = menuOffPattern.test(window.location.search);
     47   // document.documentElement.setAttribute('hide-menu', menuDisabled);
     48   // We can't use an attribute on the html element because of webkit bug
     49   // 12519. Instead, we add a class.
     50   if (menuDisabled)
     51     document.documentElement.classList.add('hide-menu');
     52 
     53   localStrings = new LocalStrings();
     54 
     55   OptionsPage.register(SearchPage.getInstance());
     56 
     57   OptionsPage.register(BrowserOptions.getInstance());
     58   OptionsPage.registerSubPage(SearchEngineManager.getInstance(),
     59                               BrowserOptions.getInstance(),
     60                               [$('defaultSearchManageEnginesButton')]);
     61   OptionsPage.register(PersonalOptions.getInstance());
     62   OptionsPage.registerSubPage(AutofillOptions.getInstance(),
     63                               PersonalOptions.getInstance(),
     64                               [$('autofill-settings')]);
     65   OptionsPage.registerSubPage(PasswordManager.getInstance(),
     66                               PersonalOptions.getInstance(),
     67                               [$('manage-passwords')]);
     68   if (cr.isChromeOS) {
     69     OptionsPage.register(SystemOptions.getInstance());
     70     OptionsPage.registerSubPage(AboutPage.getInstance(),
     71                                 SystemOptions.getInstance());
     72     OptionsPage.registerSubPage(LanguageOptions.getInstance(),
     73                                 SystemOptions.getInstance(),
     74                                 [$('language-button')]);
     75     OptionsPage.registerSubPage(
     76         new OptionsPage('languageChewing',
     77                         templateData.languageChewingPageTabTitle,
     78                         'languageChewingPage'),
     79         LanguageOptions.getInstance());
     80     OptionsPage.registerSubPage(
     81         new OptionsPage('languageHangul',
     82                         templateData.languageHangulPageTabTitle,
     83                         'languageHangulPage'),
     84         LanguageOptions.getInstance());
     85     OptionsPage.registerSubPage(
     86         new OptionsPage('languageMozc',
     87                         templateData.languageMozcPageTabTitle,
     88                         'languageMozcPage'),
     89         LanguageOptions.getInstance());
     90     OptionsPage.registerSubPage(
     91         new OptionsPage('languagePinyin',
     92                         templateData.languagePinyinPageTabTitle,
     93                         'languagePinyinPage'),
     94         LanguageOptions.getInstance());
     95     OptionsPage.register(InternetOptions.getInstance());
     96   }
     97   OptionsPage.register(AdvancedOptions.getInstance());
     98   OptionsPage.registerSubPage(ContentSettings.getInstance(),
     99                               AdvancedOptions.getInstance(),
    100                               [$('privacyContentSettingsButton')]);
    101   OptionsPage.registerSubPage(ContentSettingsExceptionsArea.getInstance(),
    102                               ContentSettings.getInstance());
    103   OptionsPage.registerSubPage(CookiesView.getInstance(),
    104                               ContentSettings.getInstance(),
    105                               [$('privacyContentSettingsButton'),
    106                                $('show-cookies-button')]);
    107   OptionsPage.registerSubPage(FontSettings.getInstance(),
    108                               AdvancedOptions.getInstance(),
    109                               [$('fontSettingsCustomizeFontsButton')]);
    110   if (!cr.isChromeOS) {
    111     OptionsPage.registerSubPage(LanguageOptions.getInstance(),
    112                                 AdvancedOptions.getInstance(),
    113                                 [$('language-button')]);
    114   }
    115   if (!cr.isWindows && !cr.isMac) {
    116     OptionsPage.registerSubPage(CertificateManager.getInstance(),
    117                                 AdvancedOptions.getInstance(),
    118                                 [$('show-cookies-button')]);
    119     OptionsPage.registerOverlay(CertificateRestoreOverlay.getInstance(),
    120                                 CertificateManager.getInstance());
    121     OptionsPage.registerOverlay(CertificateBackupOverlay.getInstance(),
    122                                 CertificateManager.getInstance());
    123     OptionsPage.registerOverlay(CertificateEditCaTrustOverlay.getInstance(),
    124                                 CertificateManager.getInstance());
    125     OptionsPage.registerOverlay(CertificateImportErrorOverlay.getInstance(),
    126                                 CertificateManager.getInstance());
    127   }
    128   OptionsPage.registerOverlay(AddLanguageOverlay.getInstance(),
    129                               LanguageOptions.getInstance());
    130   OptionsPage.registerOverlay(AlertOverlay.getInstance());
    131   OptionsPage.registerOverlay(AutofillEditAddressOverlay.getInstance(),
    132                               AutofillOptions.getInstance());
    133   OptionsPage.registerOverlay(AutofillEditCreditCardOverlay.getInstance(),
    134                               AutofillOptions.getInstance());
    135   OptionsPage.registerOverlay(ClearBrowserDataOverlay.getInstance(),
    136                               AdvancedOptions.getInstance(),
    137                               [$('privacyClearDataButton')]);
    138   OptionsPage.registerOverlay(ImportDataOverlay.getInstance(),
    139                               PersonalOptions.getInstance());
    140   OptionsPage.registerOverlay(InstantConfirmOverlay.getInstance(),
    141                               BrowserOptions.getInstance());
    142   OptionsPage.registerOverlay(SyncSetupOverlay.getInstance(),
    143                               PersonalOptions.getInstance());
    144 
    145   if (cr.isChromeOS) {
    146     OptionsPage.register(AccountsOptions.getInstance());
    147     OptionsPage.registerSubPage(ProxyOptions.getInstance(),
    148                                 AdvancedOptions.getInstance(),
    149                                 [$('proxiesConfigureButton')]);
    150     OptionsPage.registerSubPage(ChangePictureOptions.getInstance(),
    151                                 PersonalOptions.getInstance(),
    152                                 [$('change-picture-button')]);
    153     OptionsPage.registerOverlay(new OptionsPage('detailsInternetPage',
    154                                                 'detailsInternetPage',
    155                                                 'detailsInternetPage'),
    156                                 InternetOptions.getInstance());
    157 
    158     var languageModifierKeysOverlay = new OptionsPage(
    159         'languageCustomizeModifierKeysOverlay',
    160         localStrings.getString('languageCustomizeModifierKeysOverlay'),
    161         'languageCustomizeModifierKeysOverlay')
    162     OptionsPage.registerOverlay(languageModifierKeysOverlay,
    163                                 SystemOptions.getInstance(),
    164                                 [$('modifier-keys-button')]);
    165   }
    166 
    167   Preferences.getInstance().initialize();
    168   OptionsPage.initialize();
    169 
    170   var path = document.location.pathname;
    171 
    172   if (path.length > 1) {
    173     var pageName = path.slice(1);
    174     // Show page, but don't update history (there's already an entry for it).
    175     OptionsPage.showPageByName(pageName, false);
    176   } else {
    177     OptionsPage.showDefaultPage();
    178   }
    179 
    180   var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs');
    181   for(var i = 0; i < subpagesNavTabs.length; i++) {
    182     subpagesNavTabs[i].onclick = function(event) {
    183       OptionsPage.showTab(event.srcElement);
    184     }
    185   }
    186 
    187   // Allow platform specific CSS rules.
    188   if (cr.isMac)
    189     document.documentElement.setAttribute('os', 'mac');
    190   if (cr.isWindows)
    191     document.documentElement.setAttribute('os', 'windows');
    192   if (cr.isChromeOS)
    193     document.documentElement.setAttribute('os', 'chromeos');
    194   if (cr.isLinux) {
    195     document.documentElement.setAttribute('os', 'linux');
    196     document.documentElement.setAttribute('toolkit', 'gtk');
    197   }
    198   if (cr.isViews)
    199     document.documentElement.setAttribute('toolkit', 'views');
    200   if (navigator.plugins['Shockwave Flash'])
    201     document.documentElement.setAttribute('hasFlashPlugin', '');
    202 
    203   // Clicking on the Settings title brings up the 'Basics' page.
    204   $('settings-title').onclick = function() {
    205     OptionsPage.navigateToPage(BrowserOptions.getInstance().name);
    206   };
    207 }
    208 
    209 document.addEventListener('DOMContentLoaded', load);
    210 
    211 window.onpopstate = function(e) {
    212   options.OptionsPage.setState(e.state);
    213 };
    214 
    215 window.onbeforeunload = function() {
    216   options.OptionsPage.willClose();
    217 };
    218