Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / renderer / resources / neterror.js
blob9b152e7d61906f8520f9299f04ade13dd1ae4c4d
1 // Copyright 2013 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 function toggleHelpBox() {
6 var helpBoxOuter = document.getElementById('details');
7 helpBoxOuter.classList.toggle('hidden');
8 var detailsButton = document.getElementById('details-button');
9 if (helpBoxOuter.classList.contains('hidden'))
10 detailsButton.innerText = detailsButton.detailsText;
11 else
12 detailsButton.innerText = detailsButton.hideDetailsText;
14 // Details appears over the main content on small screens.
15 if (mobileNav) {
16 document.getElementById('main-content').classList.toggle('hidden');
17 var runnerContainer = document.querySelector('.runner-container');
18 if (runnerContainer) {
19 runnerContainer.classList.toggle('hidden');
24 function diagnoseErrors() {
25 var extensionId = 'idddmepepmjcgiedknnmlbadcokidhoa';
26 var diagnoseFrame = document.getElementById('diagnose-frame');
27 diagnoseFrame.innerHTML =
28 '<iframe src="chrome-extension://' + extensionId +
29 '/index.html"></iframe>';
32 // Subframes use a different layout but the same html file. This is to make it
33 // easier to support platforms that load the error page via different
34 // mechanisms (Currently just iOS).
35 if (window.top.location != window.location)
36 document.documentElement.setAttribute('subframe', '');
38 // Re-renders the error page using |strings| as the dictionary of values.
39 // Used by NetErrorTabHelper to update DNS error pages with probe results.
40 function updateForDnsProbe(strings) {
41 var context = new JsEvalContext(strings);
42 jstProcess(context, document.getElementById('t'));
45 // Given the classList property of an element, adds an icon class to the list
46 // and removes the previously-
47 function updateIconClass(classList, newClass) {
48 var oldClass;
50 if (classList.hasOwnProperty('last_icon_class')) {
51 oldClass = classList['last_icon_class'];
52 if (oldClass == newClass)
53 return;
56 classList.add(newClass);
57 if (oldClass !== undefined)
58 classList.remove(oldClass);
60 classList['last_icon_class'] = newClass;
62 if (newClass == 'icon-offline') {
63 document.body.classList.add('offline');
64 new Runner('.interstitial-wrapper');
65 } else {
66 document.body.classList.add('neterror');
70 // Does a search using |baseSearchUrl| and the text in the search box.
71 function search(baseSearchUrl) {
72 var searchTextNode = document.getElementById('search-box');
73 document.location = baseSearchUrl + searchTextNode.value;
74 return false;
77 // Use to track clicks on elements generated by the navigation correction
78 // service. If |trackingId| is negative, the element does not come from the
79 // correction service.
80 function trackClick(trackingId) {
81 // This can't be done with XHRs because XHRs are cancelled on navigation
82 // start, and because these are cross-site requests.
83 if (trackingId >= 0 && errorPageController)
84 errorPageController.trackClick(trackingId);
87 // Called when an <a> tag generated by the navigation correction service is
88 // clicked. Separate function from trackClick so the resources don't have to
89 // be updated if new data is added to jstdata.
90 function linkClicked(jstdata) {
91 trackClick(jstdata.trackingId);
94 // Implements button clicks. This function is needed during the transition
95 // between implementing these in trunk chromium and implementing them in
96 // iOS.
97 function reloadButtonClick(url) {
98 if (window.errorPageController) {
99 errorPageController.reloadButtonClick();
100 } else {
101 location = url;
105 function showSavedCopyButtonClick() {
106 if (window.errorPageController) {
107 errorPageController.showSavedCopyButtonClick();
111 function detailsButtonClick() {
112 if (window.errorPageController)
113 errorPageController.detailsButtonClick();
117 * Replace the reload button with the Google cached copy suggestion.
119 function setUpCachedButton(buttonStrings) {
120 var reloadButton = document.getElementById('reload-button');
122 reloadButton.textContent = buttonStrings.msg;
123 var url = buttonStrings.cacheUrl;
124 var trackingId = buttonStrings.trackingId;
125 reloadButton.onclick = function(e) {
126 e.preventDefault();
127 trackClick(trackingId);
128 if (window.errorPageController) {
129 errorPageController.trackCachedCopyButtonClick(
130 buttonStrings.defaultLabel);
132 location = url;
134 reloadButton.style.display = '';
135 document.getElementById('control-buttons').hidden = false;
138 var primaryControlOnLeft = true;
139 <if expr="is_macosx or is_ios or is_linux or is_android">
140 primaryControlOnLeft = false;
141 </if>
143 function onDocumentLoad() {
144 var controlButtonDiv = document.getElementById('control-buttons');
145 var reloadButton = document.getElementById('reload-button');
146 var detailsButton = document.getElementById('details-button');
147 var showSavedCopyButton = document.getElementById('show-saved-copy-button');
149 var primaryButton, secondaryButton;
150 if (showSavedCopyButton.primary) {
151 primaryButton = showSavedCopyButton;
152 secondaryButton = reloadButton;
153 } else {
154 primaryButton = reloadButton;
155 secondaryButton = showSavedCopyButton;
158 // Sets up the proper button layout for the current platform.
159 if (primaryControlOnLeft) {
160 buttons.classList.add('suggested-left');
161 controlButtonDiv.insertBefore(secondaryButton, primaryButton);
162 } else {
163 buttons.classList.add('suggested-right');
164 controlButtonDiv.insertBefore(primaryButton, secondaryButton);
167 if (reloadButton.style.display == 'none' &&
168 showSavedCopyButton.style.display == 'none') {
169 detailsButton.classList.add('singular');
172 <if expr="not chromeos">
173 // Hide the details button if there are no details to show.
174 if (loadTimeData.valueExists('summary') &&
175 !loadTimeData.getValue('summary').msg) {
176 detailsButton.style.display = 'none';
178 </if>
180 // Show control buttons.
181 if (loadTimeData.valueExists('reloadButton') &&
182 loadTimeData.getValue('reloadButton').msg ||
183 loadTimeData.valueExists('showSavedCopyButton') &&
184 loadTimeData.getValue('showSavedCopyButton').msg) {
185 controlButtonDiv.hidden = false;
187 // Set the secondary button state in the cases of two call to actions.
188 if (loadTimeData.valueExists('reloadButton') &&
189 loadTimeData.getValue('reloadButton').msg &&
190 loadTimeData.valueExists('showSavedCopyButton') &&
191 loadTimeData.getValue('showSavedCopyButton').msg) {
192 secondaryButton.classList.add('secondary-button');
196 // Add a main message paragraph.
197 if (loadTimeData.valueExists('primaryParagraph')) {
198 var p = document.querySelector('#main-message p');
199 p.innerHTML = loadTimeData.getString('primaryParagraph');
200 p.hidden = false;
203 // Check for Google cached copy suggestion.
204 if (loadTimeData.valueExists('cacheButton')) {
205 setUpCachedButton(loadTimeData.getValue('cacheButton'));
209 document.addEventListener('DOMContentLoaded', onDocumentLoad);