<link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_vars_css.html">
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/neon-animatable.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html">
<link rel="import" href="/clear_browsing_data_dialog/clear_browsing_data_dialog.html">
<link rel="import" href="/controls/settings_checkbox.html">
<link rel="import" href="/controls/settings_toggle_button.html">
<link rel="import" href="/lifetime_browser_proxy.html">
<link rel="import" href="/route.html">
<link rel="import" href="/settings_page/settings_animated_pages.html">
<link rel="import" href="/settings_page/settings_subpage.html">
<link rel="import" href="/settings_shared_css.html">
<link rel="import" href="/site_settings/all_sites.html">
<link rel="import" href="/site_settings/constants.html">
<link rel="import" href="/site_settings/media_picker.html">
<link rel="import" href="/site_settings/pdf_documents.html">
<link rel="import" href="/site_settings/protocol_handlers.html">
<link rel="import" href="/site_settings/site_data_details_subpage.html">
<link rel="import" href="/site_settings/site_settings_category.html">
<link rel="import" href="/site_settings/usb_devices.html">
<link rel="import" href="/site_settings/site_data.html">
<link rel="import" href="/site_settings/zoom_levels.html">
<link rel="import" href="/site_settings_page/site_settings_page.html">

<if expr="use_nss_certs">
<link rel="import" href="/certificate_manager_page/certificate_manager_page.html">
</if>
<link rel="import" href="/privacy_page/privacy_page_browser_proxy.html">

<dom-module id="settings-privacy-page">
  <template>
    <style include="settings-shared">
      button[is='paper-icon-button-light'].icon-help {
        background-image: url(../images/help_outline.svg);
      }

      /* TODO(dbeam): this is similar to a 1 line checkbox. Worth somehow
       * combining? */
      #metricsReporting,
      #safeBrowsingExtendedReporting {
        align-items: center;
        display: flex;
        min-height: var(--settings-row-min-height);       
      }

      #metricsReportingCheckbox,
      #safeBrowsingExtendedReportingCheckbox {
        display: inline-block;
      }

      #metricsReporting paper-tooltip {
        --paper-tooltip: var(--cr-policy-tooltip);
      }

      #indicator {
        -webkit-margin-start: var(--checkbox-spacing);
      }

      #restart {
        flex: 1;
        text-align: end;
      }      
    </style>
    <template is="dom-if" if="[[showClearBrowsingDataDialog_]]" restamp>
      <settings-clear-browsing-data-dialog prefs="{{prefs}}"
          on-close="onDialogClosed_">
      </settings-clear-browsing-data-dialog>
    </template>
    <settings-animated-pages id="pages" section="privacy">
      <neon-animatable route-path="default">
        <div class="settings-box block first">
          <p class="privacy-explanation">
            $i18nRaw{improveBrowsingExperience}
          </p>
          <settings-checkbox
              pref="{{prefs.alternate_error_pages.enabled}}"
              label="$i18n{linkDoctorPref}">
          </settings-checkbox>
          <settings-checkbox
              pref="{{prefs.search.suggest_enabled}}"
              label="$i18n{searchSuggestPref}"
              hidden="[[!pageVisibility.searchPrediction]]">
          </settings-checkbox>
          <settings-checkbox
              pref="{{prefs.net.network_prediction_options}}"
              label="$i18n{networkPredictionEnabled}"
              hidden="[[!pageVisibility.networkPrediction]]">
          </settings-checkbox>
          <div id="safeBrowsingExtendedReporting">
            <paper-checkbox id="safeBrowsingExtendedReportingCheckbox"
                on-tap="onSafeBrowsingExtendedReportingCheckboxTap_"
                checked="[[safeBrowsingExtendedReportingEnabled_]]">
              $i18n{safeBrowsingEnableExtendedReporting}
            </paper-checkbox>
          </div>
          <settings-checkbox pref="{{prefs.safebrowsing.enabled}}"
              label="$i18n{safeBrowsingEnableProtection}">
          </settings-checkbox>
<if expr="_google_chrome">
<if expr="chromeos">
          <settings-checkbox
              pref="{{prefs.cros.metrics.reportingEnabled}}"
              label="$i18n{enableLogging}">
          </settings-checkbox>
</if><!-- chromeos -->
<if expr="not chromeos">
          <div id="metricsReporting">
            <paper-checkbox id="metricsReportingCheckbox"
                on-tap="onMetricsReportingCheckboxTap_"
                checked="[[metricsReporting_.enabled]]"
                disabled="[[metricsReporting_.managed]]">
              $i18n{enableLogging}
            </paper-checkbox>
            <template is="dom-if" if="[[metricsReporting_.managed]]" restamp>
              <iron-icon id="indicator" tabindex=0 icon="cr:domain"></iron-icon>
              <paper-tooltip for="indicator" position="top"
                  fit-to-visible-bounds>
                $i18n{controlledSettingPolicy}
              </paper-tooltip>
            </template>
            <template is="dom-if" if="[[showRestart_]]" restamp>
              <div id="restart">
                <paper-button on-tap="onRestartTap_">
                  $i18n{restart}
                </paper-button>
              </div>
            </template>
          </div>
</if><!-- not chromeos -->
</if><!-- _google_chrome -->
          <settings-checkbox pref="{{prefs.enable_do_not_track}}"
              label="$i18n{doNotTrack}">
          </settings-checkbox>
<if expr="chromeos">
          <settings-checkbox
              pref="{{prefs.cros.device.attestation_for_content_protection_enabled}}"
              label="$i18n{enableContentProtectionAttestation}">
          </settings-checkbox>
          <settings-checkbox
              pref="{{prefs.settings.internet.wake_on_wifi_darkconnect}}"
              label="$i18n{wakeOnWifi}">
          </settings-checkbox>
</if>
        </div>
<if expr="_google_chrome">
        <div class="settings-box two-line" actionable
            on-tap="onUseSpellingServiceTap_">
          <div class="start">
            $i18n{spellingPref}
            <div class="secondary">$i18n{spellingDescription}</div>
          </div>
          <paper-toggle-button id="spellingServiceToggleButton">
          </paper-toggle-button>
        </div>
</if>
<if expr="use_nss_certs or is_win or is_macosx">
        <div id="manageCertificates" class="settings-box two-line"
            actionable on-tap="onManageCertificatesTap_">
          <div class="start">
            <div>$i18n{manageCertificates}</div>
            <div class="secondary">$i18n{manageCertificatesDescription}</div>
          </div>
          <button class="subpage-arrow" is="paper-icon-button-light"></button>
        </div>
</if>
        <div id="site-settings-subpage-trigger"
            class="settings-box two-line" actionable
            on-tap="onSiteSettingsTap_">
          <div class="start">
            <div>[[siteSettingsPageTitle_()]]</div>
            <div class="secondary">$i18n{siteSettingsDescription}</div>
          </div>
          <button class="subpage-arrow" is="paper-icon-button-light"></button>
        </div>
        <div class="settings-box two-line" id="clearBrowsingData"
            on-tap="onClearBrowsingDataTap_" actionable>
          <div class="start">
            $i18n{clearBrowsingData}
            <div class="secondary">$i18n{clearBrowsingDataDescription}</div>
          </div>
          <button class="subpage-arrow" is="paper-icon-button-light"></button>
        </div>
      </neon-animatable>
<if expr="use_nss_certs">
      <template is="dom-if" route-path="/certificates">
        <settings-subpage
            associated-control="[[$$('#manageCertificates')]]"
            page-title="$i18n{manageCertificates}">
          <settings-certificate-manager-page>
          </settings-certificate-manager-page>
        </settings-subpage>
      </template>
</if>
      <template is="dom-if" route-path="/content">
        <settings-subpage
            associated-control="[[$$('#site-settings-subpage-trigger')]]"
            id="site-settings"
            page-title="[[siteSettingsPageTitle_()]]">
          <settings-site-settings-page category-selected="{{categorySelected}}">
          </settings-site-settings-page>
        </settings-subpage>
      </template>

      <template is="dom-if" route-path="/content/all" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryAllSites}">
          <all-sites selected-site="{{selectedSite}}"></all-sites>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/automaticDownloads" no-search>
        <settings-subpage page-title="$i18n{siteSettingsAutomaticDownloads}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.AUTOMATIC_DOWNLOADS}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/backgroundSync" no-search>
          no-search>
        <settings-subpage page-title="$i18n{siteSettingsBackgroundSync}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.BACKGROUND_SYNC}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/camera" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryCamera}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.CAMERA}}">
            <media-picker type="camera" class="media-picker"></media-picker>
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/cookies" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryCookies}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.COOKIES}}">
            <div class="settings-box cookie-controls">
              <settings-toggle-button class="start"
                  label="$i18n{thirdPartyCookie}"
                  sub-label="$i18n{thirdPartyCookieSublabel}"
                  pref="{{prefs.profile.block_third_party_cookies}}">
              </settings-toggle-button>
            </div>
            <site-data class="site-data"></site-data>
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/images" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryImages}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.IMAGES}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/location" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryLocation}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.GEOLOCATION}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/handlers" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryHandlers}">
          <protocol-handlers></protocol-handlers>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/zoomLevels" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryZoomLevels}">
          <zoom-levels></zoom-levels>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/pdfDocuments" no-search>
        <settings-subpage page-title="$i18n{siteSettingsPdfDocuments}">
          <settings-pdf-documents prefs="{{prefs}}"></settings-pdf-documents>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/javascript" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryJavascript}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.JAVASCRIPT}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/keygen" no-search>
        <settings-subpage page-title="$i18n{siteSettingsKeygen}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.KEYGEN}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/microphone" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryMicrophone}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.MIC}}">
            <media-picker type="mic" class="media-picker"></media-picker>
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/notifications" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryNotifications}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.NOTIFICATIONS}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/flash" no-search>
        <settings-subpage page-title="$i18n{siteSettingsFlash}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.PLUGINS}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/popups" no-search>
        <settings-subpage page-title="$i18n{siteSettingsCategoryPopups}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.POPUPS}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/unsandboxedPlugins" no-search>
        <settings-subpage page-title="$i18n{siteSettingsUnsandboxedPlugins}">
          <button class="icon-help subpage-title-extra"
              is="paper-icon-button-light" on-tap="onHelpTap_"></button>
          <site-settings-category
              selected-site="{{selectedSite}}"
              category="{{ContentSettingsTypes.UNSANDBOXED_PLUGINS}}">
          </site-settings-category>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/usbDevices" no-search>
        <settings-subpage page-title="$i18n{siteSettingsUsbDevices}">
          <usb-devices></usb-devices>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/content/siteDetails" no-search>
        <settings-subpage page-title="$i18n{siteSettingsSiteDetails}">
          <site-details site="[[selectedSite]]"></site-details>
        </settings-subpage>
      </template>
      <template is="dom-if" route-path="/cookies/detail"
          no-search>
        <settings-subpage page-title="[[pageTitle]]">
          <paper-button class="subpage-title-extra"
              on-tap="onRemoveAllCookiesFromSite_">
            $i18n{siteSettingsCookieRemoveAll}
          </paper-button>
          <site-data-details-subpage page-title="{{pageTitle}}">
          </site-data-details-subpage>
        </settings-subpage>
      </template>
    </settings-animated-pages>
  </template>
  <script src="privacy_page.js"></script>
</dom-module>