Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: chrome/renderer/resources/neterror.js

Issue 1668963002: Componentize IDR_NET_ERROR_HTML for sharing it with iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase & remove jar@chromium.org from components/resources/OWNERS Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/resources/neterror.html ('k') | chrome/renderer/resources/offline.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
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;
13
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');
20 }
21 }
22 }
23
24 function diagnoseErrors() {
25 <if expr="not chromeos">
26 if (window.errorPageController)
27 errorPageController.diagnoseErrorsButtonClick();
28 </if>
29 <if expr="chromeos">
30 var extensionId = 'idddmepepmjcgiedknnmlbadcokidhoa';
31 var diagnoseFrame = document.getElementById('diagnose-frame');
32 diagnoseFrame.innerHTML =
33 '<iframe src="chrome-extension://' + extensionId +
34 '/index.html"></iframe>';
35 </if>
36 }
37
38 // Subframes use a different layout but the same html file. This is to make it
39 // easier to support platforms that load the error page via different
40 // mechanisms (Currently just iOS).
41 if (window.top.location != window.location)
42 document.documentElement.setAttribute('subframe', '');
43
44 // Re-renders the error page using |strings| as the dictionary of values.
45 // Used by NetErrorTabHelper to update DNS error pages with probe results.
46 function updateForDnsProbe(strings) {
47 var context = new JsEvalContext(strings);
48 jstProcess(context, document.getElementById('t'));
49 }
50
51 // Given the classList property of an element, adds an icon class to the list
52 // and removes the previously-
53 function updateIconClass(classList, newClass) {
54 var oldClass;
55
56 if (classList.hasOwnProperty('last_icon_class')) {
57 oldClass = classList['last_icon_class'];
58 if (oldClass == newClass)
59 return;
60 }
61
62 classList.add(newClass);
63 if (oldClass !== undefined)
64 classList.remove(oldClass);
65
66 classList['last_icon_class'] = newClass;
67
68 if (newClass == 'icon-offline') {
69 document.body.classList.add('offline');
70 new Runner('.interstitial-wrapper');
71 } else {
72 document.body.classList.add('neterror');
73 }
74 }
75
76 // Does a search using |baseSearchUrl| and the text in the search box.
77 function search(baseSearchUrl) {
78 var searchTextNode = document.getElementById('search-box');
79 document.location = baseSearchUrl + searchTextNode.value;
80 return false;
81 }
82
83 // Use to track clicks on elements generated by the navigation correction
84 // service. If |trackingId| is negative, the element does not come from the
85 // correction service.
86 function trackClick(trackingId) {
87 // This can't be done with XHRs because XHRs are cancelled on navigation
88 // start, and because these are cross-site requests.
89 if (trackingId >= 0 && errorPageController)
90 errorPageController.trackClick(trackingId);
91 }
92
93 // Called when an <a> tag generated by the navigation correction service is
94 // clicked. Separate function from trackClick so the resources don't have to
95 // be updated if new data is added to jstdata.
96 function linkClicked(jstdata) {
97 trackClick(jstdata.trackingId);
98 }
99
100 // Implements button clicks. This function is needed during the transition
101 // between implementing these in trunk chromium and implementing them in
102 // iOS.
103 function reloadButtonClick(url) {
104 if (window.errorPageController) {
105 errorPageController.reloadButtonClick();
106 } else {
107 location = url;
108 }
109 }
110
111 function showSavedCopyButtonClick() {
112 if (window.errorPageController) {
113 errorPageController.showSavedCopyButtonClick();
114 }
115 }
116
117 function showOfflinePagesButtonClick() {
118 if (window.errorPageController) {
119 errorPageController.showOfflinePagesButtonClick();
120 }
121 }
122
123 function showOfflineCopyButtonClick() {
124 if (window.errorPageController) {
125 errorPageController.showOfflineCopyButtonClick();
126 }
127 }
128
129 function detailsButtonClick() {
130 if (window.errorPageController)
131 errorPageController.detailsButtonClick();
132 }
133
134 /**
135 * Replace the reload button with the Google cached copy suggestion.
136 */
137 function setUpCachedButton(buttonStrings) {
138 var reloadButton = document.getElementById('reload-button');
139
140 reloadButton.textContent = buttonStrings.msg;
141 var url = buttonStrings.cacheUrl;
142 var trackingId = buttonStrings.trackingId;
143 reloadButton.onclick = function(e) {
144 e.preventDefault();
145 trackClick(trackingId);
146 if (window.errorPageController) {
147 errorPageController.trackCachedCopyButtonClick();
148 }
149 location = url;
150 };
151 reloadButton.style.display = '';
152 document.getElementById('control-buttons').hidden = false;
153 }
154
155 var primaryControlOnLeft = true;
156 <if expr="is_macosx or is_ios or is_linux or is_android">
157 primaryControlOnLeft = false;
158 </if>
159
160 function onDocumentLoad() {
161 var controlButtonDiv = document.getElementById('control-buttons');
162 var reloadButton = document.getElementById('reload-button');
163 var detailsButton = document.getElementById('details-button');
164 var showSavedCopyButton = document.getElementById('show-saved-copy-button');
165 var showOfflinePagesButton =
166 document.getElementById('show-offline-pages-button');
167 var showOfflineCopyButton =
168 document.getElementById('show-offline-copy-button');
169
170 var reloadButtonVisible = loadTimeData.valueExists('reloadButton') &&
171 loadTimeData.getValue('reloadButton').msg;
172 var showSavedCopyButtonVisible =
173 loadTimeData.valueExists('showSavedCopyButton') &&
174 loadTimeData.getValue('showSavedCopyButton').msg;
175 var showOfflinePagesButtonVisible =
176 loadTimeData.valueExists('showOfflinePagesButton') &&
177 loadTimeData.getValue('showOfflinePagesButton').msg;
178 var showOfflineCopyButtonVisible =
179 loadTimeData.valueExists('showOfflineCopyButton') &&
180 loadTimeData.getValue('showOfflineCopyButton').msg;
181
182 var primaryButton, secondaryButton;
183 if (showSavedCopyButton.primary) {
184 primaryButton = showSavedCopyButton;
185 secondaryButton = reloadButton;
186 } else {
187 primaryButton = reloadButton;
188 secondaryButton = showSavedCopyButton;
189 }
190
191 // Sets up the proper button layout for the current platform.
192 if (primaryControlOnLeft) {
193 buttons.classList.add('suggested-left');
194 controlButtonDiv.insertBefore(secondaryButton, primaryButton);
195 } else {
196 buttons.classList.add('suggested-right');
197 controlButtonDiv.insertBefore(primaryButton, secondaryButton);
198 }
199
200 // Check for Google cached copy suggestion.
201 if (loadTimeData.valueExists('cacheButton')) {
202 setUpCachedButton(loadTimeData.getValue('cacheButton'));
203 }
204
205 if (reloadButton.style.display == 'none' &&
206 showSavedCopyButton.style.display == 'none' &&
207 showOfflinePagesButton.style.display == 'none' &&
208 showOfflineCopyButton.style.display == 'none') {
209 detailsButton.classList.add('singular');
210 }
211
212 // Show control buttons.
213 if (reloadButtonVisible || showSavedCopyButtonVisible ||
214 showOfflinePagesButtonVisible || showOfflineCopyButton) {
215 controlButtonDiv.hidden = false;
216
217 // Set the secondary button state in the cases of two call to actions.
218 if ((reloadButtonVisible || showOfflinePagesButtonVisible ||
219 showOfflineCopyButton) &&
220 showSavedCopyButtonVisible) {
221 secondaryButton.classList.add('secondary-button');
222 }
223 }
224 }
225
226 document.addEventListener('DOMContentLoaded', onDocumentLoad);
OLDNEW
« no previous file with comments | « chrome/renderer/resources/neterror.html ('k') | chrome/renderer/resources/offline.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698