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

Side by Side Diff: chrome/browser/resources/suggestions_internals/suggestions_internals.js

Issue 10666009: Added already_open column to chrome://suggestions-internals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed unit tests Created 8 years, 5 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
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 * columns. 54 * columns.
55 * @type {Array.<string>} 55 * @type {Array.<string>}
56 * @const 56 * @const
57 */ 57 */
58 var PREFERRED_COLUMN_ORDER = [ 58 var PREFERRED_COLUMN_ORDER = [
59 'title', 59 'title',
60 'url', 60 'url',
61 'score' 61 'score'
62 ]; 62 ];
63 63
64 function setBooleanColumn(column, value) {
65 if (value) {
66 column.innerText = 'Y';
67 column.classList.add('boolean-property-true');
68 } else {
69 column.innerText = 'N';
70 column.classList.add('boolean-property-false');
71 }
72 }
73
64 /** 74 /**
65 * Called by Chrome code, with a ranked list of suggestions. The columns 75 * Called by Chrome code, with a ranked list of suggestions. The columns
66 * to be displayed are calculated automatically from the properties of the 76 * to be displayed are calculated automatically from the properties of the
67 * elements in the list, such that all properties have a column. 77 * elements in the list, such that all properties have a column.
68 */ 78 */
69 function setSuggestions(list) { 79 function setSuggestions(list) {
70 // Build a list of all the columns that will be displayed. 80 // Build a list of all the columns that will be displayed.
71 var columns = []; 81 var columns = [];
72 list.forEach(function(entry) { 82 list.forEach(function(entry) {
73 for (var column in entry) { 83 for (var column in entry) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 var path = column_name.split('.'); 136 var path = column_name.split('.');
127 var data = entry; 137 var data = entry;
128 for (var i = 0; i < path.length; ++i) { 138 for (var i = 0; i < path.length; ++i) {
129 if (data && data.hasOwnProperty(path[i])) 139 if (data && data.hasOwnProperty(path[i]))
130 data = data[path[i]]; 140 data = data[path[i]];
131 else 141 else
132 data = undefined; 142 data = undefined;
133 } 143 }
134 // Only add the column if the current suggestion has this property 144 // Only add the column if the current suggestion has this property
135 // (otherwise, leave the cell empty). 145 // (otherwise, leave the cell empty).
136 if (data) { 146 if (typeof(data) != 'undefined') {
137 // If the text is a URL, make it an anchor element. 147 if (typeof(data) == 'boolean') {
138 if (/^https?:\/\/.+$/.test(data)) { 148 setBooleanColumn(column, data);
149 } else if (/^https?:\/\/.+$/.test(data)) {
150 // If the text is a URL, make it an anchor element.
139 var anchor = document.createElement('a'); 151 var anchor = document.createElement('a');
140 anchor.href = data; 152 anchor.href = data;
141 anchor.innerText = data; 153 anchor.innerText = data;
142 column.appendChild(anchor); 154 column.appendChild(anchor);
143 } else { 155 } else {
144 column.innerText = data; 156 column.innerText = data;
145 } 157 }
146 } else if (column_name == 'rank') { 158 } else if (column_name == 'rank') {
147 column.innerText = rank++; 159 column.innerText = rank++;
148 } else if (column_name == 'screenshot') { 160 } else if (column_name == 'screenshot') {
149 var thumbnailUrl = 'chrome://thumb/' + entry.url; 161 var thumbnailUrl = 'chrome://thumb/' + entry.url;
150 var img = document.createElement('img'); 162 var img = document.createElement('img');
151 img.onload = function() { 163 img.onload = function() { setBooleanColumn(column, true); }
152 column.innerText = 'Y'; 164 img.onerror = function() { setBooleanColumn(column, false); }
153 column.classList.add('has-screenshot');
154 }
155 img.onerror = function() { column.innerText = 'N'; }
156 img.src = thumbnailUrl; 165 img.src = thumbnailUrl;
157 } else if (column_name == 'favicon') { 166 } else if (column_name == 'favicon') {
158 var faviconUrl = 'chrome://favicon/size/16/' + entry.url; 167 var faviconUrl = 'chrome://favicon/size/16/' + entry.url;
159 column.style.backgroundImage = url(faviconUrl); 168 column.style.backgroundImage = url(faviconUrl);
160 column.style.backgroundRepeat = 'no-repeat'; 169 column.style.backgroundRepeat = 'no-repeat';
161 column.style.backgroundPosition = 'center center'; 170 column.style.backgroundPosition = 'center center';
162 } 171 }
163 row.appendChild(column); 172 row.appendChild(column);
164 }); 173 });
165 table.appendChild(row); 174 table.appendChild(row);
166 }); 175 });
167 176
168 output.appendChild(table); 177 output.appendChild(table);
169 } 178 }
170 179
171 return { 180 return {
172 initialize: initialize, 181 initialize: initialize,
173 setSuggestions: setSuggestions 182 setSuggestions: setSuggestions
174 }; 183 };
175 }); 184 });
176 185
177 document.addEventListener('DOMContentLoaded', suggestionsInternals.initialize); 186 document.addEventListener('DOMContentLoaded', suggestionsInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698