Upstream version 7.36.149.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 moreLessButton = document.getElementById('more-less-button');
9   if (helpBoxOuter.classList.contains('hidden')) {
10     moreLessButton.innerText = moreLessButton.moreText;
11   } else {
12     moreLessButton.innerText = moreLessButton.lessText;
13   }
14 }
15
16 function diagnoseErrors() {
17   var extension_id = "idddmepepmjcgiedknnmlbadcokidhoa";
18   var diagnose_frame = document.getElementById('diagnose-frame');
19   diagnose_frame.innerHTML =
20       '<iframe src="chrome-extension://' + extension_id +
21       '/index.html"></iframe>';
22 }
23
24 // Subframes use a different layout but the same html file.  This is to make it
25 // easier to support platforms that load the error page via different
26 // mechanisms (Currently just iOS).
27 if (window.top.location != window.location)
28   document.documentElement.setAttribute('subframe', '');
29
30 // Re-renders the error page using |strings| as the dictionary of values.
31 // Used by NetErrorTabHelper to update DNS error pages with probe results.
32 function updateForDnsProbe(strings) {
33   i18nTemplate.process(document, strings);
34   var context = new JsEvalContext(strings);
35   jstProcess(context, document.getElementById('t'));
36 }
37
38 // Given the classList property of an element, adds an icon class to the list
39 // and removes the previously-
40 function updateIconClass(classList, newClass) {
41   var oldClass;
42
43   if (classList.hasOwnProperty('last_icon_class')) {
44     oldClass = classList['last_icon_class']
45     if (oldClass == newClass)
46       return;
47   }
48
49   classList.add(newClass);
50   if (oldClass !== undefined)
51     classList.remove(oldClass);
52
53   classList['last_icon_class'] = newClass;
54 }
55
56 // Does a search using |baseSearchUrl| and the text in the search box.
57 function search(baseSearchUrl) {
58   var searchTextNode = document.getElementById('search-box');
59   document.location = baseSearchUrl + searchTextNode.value;
60   return false;
61 }
62
63 // Use to track clicks on elements generated by the navigation correction
64 // service.  If |trackingId| is negative, the element does not come from the
65 // correction service.
66 function trackClick(trackingId) {
67   // This can't be done with XHRs because XHRs are cancelled on navigation
68   // start, and because these are cross-site requests.
69   if (trackingId >= 0 && errorPageController)
70     errorPageController.trackClick(trackingId);
71 }
72
73 // Called when an <a> tag generated by the navigation correction service is
74 // clicked.  Separate function from trackClick so the resources don't have to
75 // be updated if new data is added to jstdata.
76 function linkClicked(jstdata) {
77   trackClick(jstdata.trackingId);
78 }
79
80 // Implements button clicks.  This function is needed during the transition
81 // between implementing these in trunk chromium and implementing them in
82 // iOS.
83 function reloadButtonClick(url) {
84   if (window.errorPageController) {
85     errorPageController.reloadButtonClick();
86   } else {
87     location = url;
88   }
89 }
90
91 function loadStaleButtonClick() {
92   if (window.errorPageController) {
93     errorPageController.loadStaleButtonClick();
94   }
95 }
96
97 function moreButtonClick() {
98   if (window.errorPageController) {
99     errorPageController.moreButtonClick();
100   }
101 }
102
103 <if expr="is_macosx or is_ios or is_linux or is_android">
104 // Re-orders buttons. Used on Mac, Linux, and Android, where reload should go
105 // on the right.
106 function swapButtonOrder() {
107   var reloadButton = document.getElementById('reload-button');
108   var moreLessButton = document.getElementById('more-less-button');
109   var staleLoadButton = document.getElementById('stale-load-button');
110   reloadButton.parentNode.insertBefore(moreLessButton, reloadButton);
111   reloadButton.parentNode.insertBefore(staleLoadButton, reloadButton)
112 }
113 document.addEventListener("DOMContentLoaded", swapButtonOrder);
114 </if>