Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / resources / neterror.js
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('help-box-outer');
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
15 function diagnoseErrors() {
16   var extensionId = 'idddmepepmjcgiedknnmlbadcokidhoa';
17   var diagnoseFrame = document.getElementById('diagnose-frame');
18   diagnoseFrame.innerHTML =
19       '<iframe src="chrome-extension://' + extensionId +
20       '/index.html"></iframe>';
21 }
22
23 // Subframes use a different layout but the same html file.  This is to make it
24 // easier to support platforms that load the error page via different
25 // mechanisms (Currently just iOS).
26 if (window.top.location != window.location)
27   document.documentElement.setAttribute('subframe', '');
28
29 // Re-renders the error page using |strings| as the dictionary of values.
30 // Used by NetErrorTabHelper to update DNS error pages with probe results.
31 function updateForDnsProbe(strings) {
32   i18nTemplate.process(document, strings);
33   var context = new JsEvalContext(strings);
34   jstProcess(context, document.getElementById('t'));
35 }
36
37 // Given the classList property of an element, adds an icon class to the list
38 // and removes the previously-
39 function updateIconClass(classList, newClass) {
40   var oldClass;
41
42   if (classList.hasOwnProperty('last_icon_class')) {
43     oldClass = classList['last_icon_class'];
44     if (oldClass == newClass)
45       return;
46   }
47
48   classList.add(newClass);
49   if (oldClass !== undefined)
50     classList.remove(oldClass);
51
52   classList['last_icon_class'] = newClass;
53 }
54
55 // Does a search using |baseSearchUrl| and the text in the search box.
56 function search(baseSearchUrl) {
57   var searchTextNode = document.getElementById('search-box');
58   document.location = baseSearchUrl + searchTextNode.value;
59   return false;
60 }
61
62 // Use to track clicks on elements generated by the navigation correction
63 // service.  If |trackingId| is negative, the element does not come from the
64 // correction service.
65 function trackClick(trackingId) {
66   // This can't be done with XHRs because XHRs are cancelled on navigation
67   // start, and because these are cross-site requests.
68   if (trackingId >= 0 && errorPageController)
69     errorPageController.trackClick(trackingId);
70 }
71
72 // Called when an <a> tag generated by the navigation correction service is
73 // clicked.  Separate function from trackClick so the resources don't have to
74 // be updated if new data is added to jstdata.
75 function linkClicked(jstdata) {
76   trackClick(jstdata.trackingId);
77 }
78
79 // Implements button clicks.  This function is needed during the transition
80 // between implementing these in trunk chromium and implementing them in
81 // iOS.
82 function reloadButtonClick(url) {
83   if (window.errorPageController) {
84     errorPageController.reloadButtonClick();
85   } else {
86     location = url;
87   }
88 }
89
90 function loadStaleButtonClick() {
91   if (window.errorPageController) {
92     errorPageController.loadStaleButtonClick();
93   }
94 }
95
96 function detailsButtonClick() {
97   if (window.errorPageController)
98     errorPageController.detailsButtonClick();
99 }
100
101 var primaryControlOnLeft = true;
102 <if expr="is_macosx or is_ios or is_linux or is_android">
103 primaryControlOnLeft = false;
104 </if>
105
106 // Sets up the proper button layout for the current platform.
107 function setButtonLayout() {
108   var buttonsDiv = document.getElementById('buttons');
109   var controlButtonDiv = document.getElementById('control-buttons');
110   var reloadButton = document.getElementById('reload-button');
111   var detailsButton = document.getElementById('details-button');
112   var staleLoadButton = document.getElementById('stale-load-button');
113
114   var primaryButton = reloadButton;
115   var secondaryButton = staleLoadButton;
116
117   if (primaryControlOnLeft) {
118     buttons.classList.add('suggested-left');
119     controlButtonDiv.insertBefore(primaryButton, secondaryButton);
120   } else {
121     buttons.classList.add('suggested-right');
122     controlButtonDiv.insertBefore(secondaryButton, primaryButton);
123   }
124
125   if (reloadButton.style.display == 'none' &&
126       staleLoadButton.style.display == 'none') {
127     detailsButton.classList.add('singular');
128   }
129 }
130 document.addEventListener('DOMContentLoaded', setButtonLayout);