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
3 // found in the LICENSE file.
6 * Requests the database from the backend.
8 function requestAutocompleteActionPredictorDb() {
9 chrome
.send('requestAutocompleteActionPredictorDb');
13 * Callback from backend with the database contents. Sets up some globals and
14 * calls to create the UI.
15 * @param {Dictionary} database Information about AutocompleteActionPredictor
16 * including the database as a flattened list, a boolean indicating if the
17 * system is enabled and the current hit weight.
19 function updateAutocompleteActionPredictorDb(database
) {
20 console
.debug('Updating Table NAP DB');
22 var filter
= $('filter');
23 filter
.disabled
= false;
24 filter
.onchange = function() {
25 updateAutocompleteActionPredictorDbView(database
);
28 updateAutocompleteActionPredictorDbView(database
);
32 * Updates the table from the database.
33 * @param {Dictionary} database Information about AutocompleteActionPredictor
34 * including the database as a flattened list, a boolean indicating if the
35 * system is enabled and the current hit weight.
37 function updateAutocompleteActionPredictorDbView(database
) {
38 var databaseSection
= $('databaseTableBody');
39 var showEnabled
= database
.enabled
&& database
.db
;
41 $('autocompleteActionPredictorEnabledMode').hidden
= !showEnabled
;
42 $('autocompleteActionPredictorDisabledMode').hidden
= showEnabled
;
47 var filter
= $('filter');
49 // Clear any previous list.
50 databaseSection
.textContent
= '';
52 for (var i
= 0; i
< database
.db
.length
; ++i
) {
53 var entry
= database
.db
[i
];
55 if (!filter
.checked
|| entry
.confidence
> 0) {
56 var row
= document
.createElement('tr');
57 row
.className
= (entry
.confidence
> 0.8 ? 'action-prerender' :
58 (entry
.confidence
> 0.5 ? 'action-preconnect' :
61 row
.appendChild(document
.createElement('td')).textContent
=
63 row
.appendChild(document
.createElement('td')).textContent
= entry
.url
;
64 row
.appendChild(document
.createElement('td')).textContent
=
66 row
.appendChild(document
.createElement('td')).textContent
=
68 row
.appendChild(document
.createElement('td')).textContent
=
71 databaseSection
.appendChild(row
);
74 $('countBanner').textContent
= 'Entries: ' + databaseSection
.children
.length
;
77 document
.addEventListener('DOMContentLoaded',
78 requestAutocompleteActionPredictorDb
);