home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome.dll / 0 / BINDATA / 558 < prev    next >
Encoding:
Text File  |  2013-04-03  |  6.3 KB  |  192 lines

  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.
  4.  
  5. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  6. // Use of this source code is governed by a BSD-style license that can be
  7. // found in the LICENSE file.
  8.  
  9. /**
  10.  * Requests the database from the backend.
  11.  */
  12. function requestAutocompleteActionPredictorDb() {
  13.   chrome.send('requestAutocompleteActionPredictorDb');
  14. }
  15.  
  16. /**
  17.  * Callback from backend with the database contents. Sets up some globals and
  18.  * calls to create the UI.
  19.  * @param {Dictionary} database Information about AutocompleteActionPredictor
  20.  *     including the database as a flattened list, a boolean indicating if the
  21.  *     system is enabled and the current hit weight.
  22.  */
  23. function updateAutocompleteActionPredictorDb(database) {
  24.   console.debug('Updating Table NAP DB');
  25.  
  26.   var filter = $('filter');
  27.   filter.disabled = false;
  28.   filter.onchange = function() {
  29.     updateAutocompleteActionPredictorDbView(database);
  30.   };
  31.  
  32.   updateAutocompleteActionPredictorDbView(database);
  33. }
  34.  
  35. /**
  36.  * Updates the table from the database.
  37.  * @param {Dictionary} database Information about AutocompleteActionPredictor
  38.  *     including the database as a flattened list, a boolean indicating if the
  39.  *     system is enabled and the current hit weight.
  40.  */
  41. function updateAutocompleteActionPredictorDbView(database) {
  42.   var databaseSection = $('databaseTableBody');
  43.   var showEnabled = database.enabled && database.db;
  44.  
  45.   $('autocompleteActionPredictorEnabledMode').hidden = !showEnabled;
  46.   $('autocompleteActionPredictorDisabledMode').hidden = showEnabled;
  47.  
  48.   if (!showEnabled)
  49.     return;
  50.  
  51.   var filter = $('filter');
  52.  
  53.   // Clear any previous list.
  54.   databaseSection.textContent = '';
  55.  
  56.   for (var i = 0; i < database.db.length; ++i) {
  57.     var entry = database.db[i];
  58.  
  59.     if (!filter.checked || entry.confidence > 0) {
  60.       var row = document.createElement('tr');
  61.       row.className = (entry.confidence > 0.8 ? 'action-prerender' :
  62.                           (entry.confidence > 0.5 ? 'action-preconnect' :
  63.                               'action-none'));
  64.  
  65.       row.appendChild(document.createElement('td')).textContent =
  66.           entry.user_text;
  67.       row.appendChild(document.createElement('td')).textContent = entry.url;
  68.       row.appendChild(document.createElement('td')).textContent =
  69.           entry.hit_count;
  70.       row.appendChild(document.createElement('td')).textContent =
  71.           entry.miss_count;
  72.       row.appendChild(document.createElement('td')).textContent =
  73.           entry.confidence;
  74.  
  75.       databaseSection.appendChild(row);
  76.     }
  77.   }
  78.   $('countBanner').textContent = 'Entries: ' + databaseSection.children.length;
  79. }
  80.  
  81. document.addEventListener('DOMContentLoaded',
  82.                           requestAutocompleteActionPredictorDb);
  83.  
  84. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  85. // Use of this source code is governed by a BSD-style license that can be
  86. // found in the LICENSE file.
  87.  
  88. /**
  89.  * Requests the database from the backend.
  90.  */
  91. function requestResourcePrefetchPredictorDb() {
  92.   chrome.send('requestResourcePrefetchPredictorDb');
  93. }
  94.  
  95. /**
  96.  * Callback from backend with the database contents. Sets up some globals and
  97.  * calls to create the UI.
  98.  * @param {Dictionary} database Information about ResourcePrefetchPredictor
  99.  *     including the database as a flattened list, a boolean indicating if the
  100.  *     system is enabled.
  101.  */
  102. function updateResourcePrefetchPredictorDb(database) {
  103.   updateResourcePrefetchPredictorDbView(database);
  104. }
  105.  
  106. /**
  107.  * Truncates the string to keep the database readable.
  108.  * @param {String} str The string to truncate.
  109.  * @return {String} The truncated string.
  110.  */
  111. function truncateString(str) {
  112.   return str.length < 100 ? str : str.substring(0, 99);
  113. }
  114.  
  115. /**
  116.  * Updates the table from the database.
  117.  * @param {Dictionary} database Information about ResourcePrefetchPredictor
  118.  *     including the database as a flattened list, a boolean indicating if the
  119.  *     system is enabled and the current hit weight.
  120.  */
  121. function updateResourcePrefetchPredictorDbView(database) {
  122.   if (!database.enabled) {
  123.     $('rpp_enabled').style.display = 'none';
  124.     $('rpp_disabled').style.display = 'block';
  125.     return;
  126.   } else {
  127.     $('rpp_enabled').style.display = 'block';
  128.     $('rpp_disabled').style.display = 'none';
  129.   }
  130.  
  131.   var has_url_data = database.url_db && database.url_db.length > 0;
  132.   var has_host_data = database.host_db && database.host_db.length > 0;
  133.  
  134.   if (has_url_data)
  135.     renderCacheData($('rpp_url_body'), database.url_db);
  136.   if (has_host_data)
  137.     renderCacheData($('rpp_host_body'), database.host_db);
  138. }
  139.  
  140. /**
  141.  * Renders cache data for URL or host based data.
  142.  * @param {HTMLElement} body element of table to render into.
  143.  * @param {Dictionary} database to render.
  144.  */
  145. function renderCacheData(body, database) {
  146.   body.textContent = '';
  147.   for (var i = 0; i < database.length; ++i) {
  148.     var main = database[i];
  149.  
  150.     for (var j = 0; j < main.resources.length; ++j) {
  151.       var resource = main.resources[j];
  152.       var row = document.createElement('tr');
  153.  
  154.       if (j == 0) {
  155.         var t = document.createElement('td');
  156.         t.rowSpan = main.resources.length;
  157.         t.textContent = truncateString(main.main_frame_url);
  158.         t.className = 'last';
  159.         row.appendChild(t);
  160.       }
  161.  
  162.       if (j == main.resources.length - 1)
  163.         row.className = 'last';
  164.  
  165.       row.appendChild(document.createElement('td')).textContent =
  166.           truncateString(resource.resource_url);
  167.       row.appendChild(document.createElement('td')).textContent =
  168.           resource.resource_type;
  169.       row.appendChild(document.createElement('td')).textContent =
  170.           resource.number_of_hits;
  171.       row.appendChild(document.createElement('td')).textContent =
  172.           resource.number_of_misses;
  173.       row.appendChild(document.createElement('td')).textContent =
  174.           resource.consecutive_misses;
  175.       row.appendChild(document.createElement('td')).textContent =
  176.           resource.position;
  177.       row.appendChild(document.createElement('td')).textContent =
  178.           resource.score;
  179.       body.appendChild(row);
  180.     }
  181.   }
  182. }
  183.  
  184. document.addEventListener('DOMContentLoaded',
  185.                           requestResourcePrefetchPredictorDb);
  186.  
  187.  
  188. if (cr.isWindows)
  189.   document.documentElement.setAttribute('os', 'win');
  190.  
  191. cr.ui.decorate('tabbox', cr.ui.TabBox);
  192.