OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Javascript for suggestions_internals.html, served from | 6 * Javascript for suggestions_internals.html, served from |
7 * chrome://suggestions-internals/. This is used to debug suggestions ranking. | 7 * chrome://suggestions-internals/. This is used to debug suggestions ranking. |
8 * When loaded, the page will show the current set of suggestions, along with a | 8 * When loaded, the page will show the current set of suggestions, along with a |
9 * large set of information (e.g. all the signals that were taken into | 9 * large set of information (e.g. all the signals that were taken into |
10 * consideration for deciding which pages were selected to be shown to the user) | 10 * consideration for deciding which pages were selected to be shown to the user) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 return IGNORED_COLUMNS.indexOf(column) < 0; | 81 return IGNORED_COLUMNS.indexOf(column) < 0; |
82 }); | 82 }); |
83 | 83 |
84 // Move the preferred columns to the start of the column list. | 84 // Move the preferred columns to the start of the column list. |
85 for (var i = PREFERRED_COLUMN_ORDER.length - 1; i >= 0; i--) { | 85 for (var i = PREFERRED_COLUMN_ORDER.length - 1; i >= 0; i--) { |
86 var index = columns.indexOf(PREFERRED_COLUMN_ORDER[i]); | 86 var index = columns.indexOf(PREFERRED_COLUMN_ORDER[i]); |
87 if (index >= 0) | 87 if (index >= 0) |
88 columns.unshift(columns.splice(index, 1)[0]); | 88 columns.unshift(columns.splice(index, 1)[0]); |
89 } | 89 } |
90 | 90 |
91 // Prepend a "Rank" column. | 91 // Special columns. |
| 92 columns.unshift('favicon'); |
| 93 columns.unshift('screenshot'); |
92 columns.unshift('rank'); | 94 columns.unshift('rank'); |
93 | 95 |
94 // Erase whatever is currently being displayed. | 96 // Erase whatever is currently being displayed. |
95 var output = $('suggestions-debug-text'); | 97 var output = $('suggestions-debug-text'); |
96 output.innerHTML = ''; | 98 output.innerHTML = ''; |
97 | 99 |
98 // Create the container table and add the header row. | 100 // Create the container table and add the header row. |
99 var table = document.createElement('table'); | 101 var table = document.createElement('table'); |
100 table.className = 'suggestions-debug-table'; | 102 table.className = 'suggestions-debug-table'; |
101 var header = document.createElement('tr'); | 103 var header = document.createElement('tr'); |
(...skipping 18 matching lines...) Expand all Loading... |
120 if (/^https?:\/\/.+$/.test(data)) { | 122 if (/^https?:\/\/.+$/.test(data)) { |
121 var anchor = document.createElement('a'); | 123 var anchor = document.createElement('a'); |
122 anchor.href = data; | 124 anchor.href = data; |
123 anchor.innerText = data; | 125 anchor.innerText = data; |
124 column.appendChild(anchor); | 126 column.appendChild(anchor); |
125 } else { | 127 } else { |
126 column.innerText = data; | 128 column.innerText = data; |
127 } | 129 } |
128 } else if (column_name == 'rank') { | 130 } else if (column_name == 'rank') { |
129 column.innerText = rank++; | 131 column.innerText = rank++; |
| 132 } else if (column_name == 'screenshot') { |
| 133 var thumbnailUrl = 'chrome://thumb/' + entry.url; |
| 134 var img = document.createElement('img'); |
| 135 img.onload = function() { column.innerText = 'Y'; } |
| 136 img.onerror = function() { column.innerText = 'N'; } |
| 137 img.src = thumbnailUrl; |
| 138 } else if (column_name == 'favicon') { |
| 139 var faviconUrl = 'chrome://favicon/size/16/' + entry.url; |
| 140 column.style.backgroundImage = url(faviconUrl); |
| 141 column.style.backgroundRepeat = 'no-repeat'; |
| 142 column.style.backgroundPosition = 'center center'; |
130 } | 143 } |
131 row.appendChild(column); | 144 row.appendChild(column); |
132 }); | 145 }); |
133 table.appendChild(row); | 146 table.appendChild(row); |
134 }); | 147 }); |
135 | 148 |
136 output.appendChild(table); | 149 output.appendChild(table); |
137 } | 150 } |
138 | 151 |
139 return { | 152 return { |
140 initialize: initialize, | 153 initialize: initialize, |
141 setSuggestions: setSuggestions | 154 setSuggestions: setSuggestions |
142 }; | 155 }; |
143 }); | 156 }); |
144 | 157 |
145 document.addEventListener('DOMContentLoaded', suggestionsInternals.initialize); | 158 document.addEventListener('DOMContentLoaded', suggestionsInternals.initialize); |
OLD | NEW |