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

Unified Diff: chrome/browser/resources/instant/instant.js

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/instant/instant.js
diff --git a/chrome/browser/resources/instant/instant.js b/chrome/browser/resources/instant/instant.js
index e874fca872930bca9d6cb42b3d137646a918353c..26963fa5dfebe6f63bf6fd296fcacebf638e837b 100644
--- a/chrome/browser/resources/instant/instant.js
+++ b/chrome/browser/resources/instant/instant.js
@@ -2,188 +2,62 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Redefine '$' here rather than including 'cr.js', since this is
-// the only function needed. This allows this file to be loaded
-// in a browser directly for layout and some testing purposes.
+// Redefine '$' here rather than including util.js, since this is the only
+// function needed.
var $ = function(id) { return document.getElementById(id); };
/**
- * WebUI for configuring instant.* preference values used by
- * Chrome's instant search system.
+ * WebUI for displaying Instant debug event information.
*/
var instantConfig = (function() {
'use strict';
- /** List of fields used to dynamically build form. **/
- var FIELDS = [
- {
- key: 'instant_ui.zero_suggest_url_prefix',
- label: 'Prefix URL for the experimental Instant ZeroSuggest provider',
- type: 'string',
- size: 40,
- units: '',
- default: ''
- },
- ];
-
/**
- * Returns a DOM element of the given type and class name.
+ * Request debug events; results arrive asynchronously via setDebugEvents().
*/
- function createElementWithClass(elementType, className) {
- var element = document.createElement(elementType);
- element.className = className;
- return element;
+ function getDebugEvents() {
+ chrome.send('getDebugEvents');
}
/**
- * Dynamically builds web-form based on FIELDS list.
- * @return {string} The form's HTML.
+ * Handles callback from getDebugEvents().
+ * @param {Array} events A list of debug events.
*/
- function buildForm() {
- var buf = [];
-
- for (var i = 0; i < FIELDS.length; i++) {
- var field = FIELDS[i];
-
- var row = createElementWithClass('div', 'row');
- row.id = '';
+ function setDebugEvents(events) {
+ var debugEvents = $('debug-events');
- var label = createElementWithClass('label', 'row-label');
- label.setAttribute('for', field.key);
- label.textContent = field.label;
- row.appendChild(label);
+ for (var i = 0; i < events.length; ++i) {
+ var event = document.createElement('p');
- var input = createElementWithClass('input', 'row-input');
- input.type = field.type;
- input.id = field.key;
- input.title = "Default Value: " + field.default;
- if (field.size) input.size = field.size;
- input.min = field.min || 0;
- if (field.max) input.max = field.max;
- if (field.step) input.step = field.step;
- row.appendChild(input);
+ var time = document.createElement('span');
+ time.className = 'time';
+ time.textContent = events[i].time;
+ event.appendChild(time);
- var units = createElementWithClass('div', 'row-units');
- if (field.units) units.innerHTML = field.units;
- row.appendChild(units);
-
- $('instant-form').appendChild(row);
- }
- }
+ var text = document.createElement('span');
+ text.textContent = events[i].text;
+ event.appendChild(text);
- /**
- * Initialize the form by adding 'onChange' listeners to all fields.
- */
- function initForm() {
- for (var i = 0; i < FIELDS.length; i++) {
- var field = FIELDS[i];
- $(field.key).onchange = (function(key) {
- setPreferenceValue(key);
- }).bind(null, field.key);
+ debugEvents.appendChild(event);
}
}
/**
- * Request a preference setting's value.
- * This method is asynchronous; the result is provided by a call to
- * getPreferenceValueResult.
- * @param {string} prefName The name of the preference value being requested.
- */
- function getPreferenceValue(prefName) {
- chrome.send('getPreferenceValue', [prefName]);
- }
-
- /**
- * Handle callback from call to getPreferenceValue.
- * @param {string} prefName The name of the requested preference value.
- * @param {value} value The current value associated with prefName.
- */
- function getPreferenceValueResult(prefName, value) {
- if ($(prefName).type == 'checkbox')
- $(prefName).checked = value;
- else
- $(prefName).value = value;
- }
-
- /**
- * Set a preference setting's value stored in the element with prefName.
- * @param {string} prefName The name of the preference value being set.
+ * Resets the list of debug events.
*/
- function setPreferenceValue(prefName) {
- var value;
- if ($(prefName).type == 'checkbox')
- value = $(prefName).checked;
- else if ($(prefName).type == 'number')
- value = parseFloat($(prefName).value);
- else
- value = $(prefName).value;
- chrome.send('setPreferenceValue', [prefName, value]);
+ function clearDebugEvents() {
+ $('debug-events').innerHTML = '';
+ chrome.send('clearDebugEvents');
}
- /**
- * Saves data back into Chrome preferences.
- */
- function onSave() {
- for (var i = 0; i < FIELDS.length; i++) {
- var field = FIELDS[i];
- setPreferenceValue(field.key);
- }
- return false;
- }
-
- /**
- * Request debug info.
- * The method is asynchronous, results being provided via getDebugInfoResult.
- */
- function getDebugInfo() {
- chrome.send('getDebugInfo');
- }
-
- /**
- * Handles callback from getDebugInfo.
- * @param {Object} info The debug info.
- */
- function getDebugInfoResult(info) {
- for (var i = 0; i < info.entries.length; ++i) {
- var entry = info.entries[i];
- var row = createElementWithClass('p', 'debug');
- row.appendChild(createElementWithClass('span', 'timestamp')).textContent =
- entry.time;
- row.appendChild(document.createElement('span')).textContent = entry.text;
- $('instant-debug-info').appendChild(row);
- }
- }
-
- /**
- * Resets list of debug events.
- */
- function clearDebugInfo() {
- $('instant-debug-info').innerHTML = '';
- chrome.send('clearDebugInfo');
- }
-
- function loadForm() {
- for (var i = 0; i < FIELDS.length; i++)
- getPreferenceValue(FIELDS[i].key);
- }
-
- /**
- * Build and initialize the configuration form.
- */
function initialize() {
- buildForm();
- loadForm();
- initForm();
- getDebugInfo();
-
- $('save-button').onclick = onSave.bind(this);
- $('clear-button').onclick = clearDebugInfo.bind(this);
+ $('clear-debug-events').onclick = clearDebugEvents.bind(this);
+ getDebugEvents();
}
return {
initialize: initialize,
- getDebugInfoResult: getDebugInfoResult,
- getPreferenceValueResult: getPreferenceValueResult
+ setDebugEvents: setDebugEvents,
};
})();

Powered by Google App Engine
This is Rietveld 408576698