summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/components.js
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2014-03-18 13:16:26 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-20 15:55:39 +0100
commit3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch)
tree92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/chrome/browser/resources/components.js
parente90d7c4b152c56919d963987e2503f9909a666d2 (diff)
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies needed on Windows. Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42 Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu> Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/chrome/browser/resources/components.js')
-rw-r--r--chromium/chrome/browser/resources/components.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/chromium/chrome/browser/resources/components.js b/chromium/chrome/browser/resources/components.js
new file mode 100644
index 00000000000..8753e3192ab
--- /dev/null
+++ b/chromium/chrome/browser/resources/components.js
@@ -0,0 +1,90 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+/**
+ * Takes the |componentsData| input argument which represents data about the
+ * currently installed components and populates the html jstemplate with
+ * that data. It expects an object structure like the above.
+ * @param {Object} componentsData Detailed info about installed components.
+ * Same expected format as returnComponentsData().
+ */
+function renderTemplate(componentsData) {
+ // This is the javascript code that processes the template:
+ var input = new JsEvalContext(componentsData);
+ var output = $('componentTemplate');
+ jstProcess(input, output);
+}
+
+/**
+ * Asks the C++ ComponentsDOMHandler to get details about the installed
+ * components.
+ * The ComponentsDOMHandler should reply to returnComponentsData() (below).
+ */
+function requestComponentsData() {
+ chrome.send('requestComponentsData');
+}
+
+/**
+ * Called by the WebUI to re-populate the page with data representing the
+ * current state of installed components.
+ * @param {Object} componentsData Detailed info about installed components. The
+ * template expects each component's format to match the following
+ * structure to correctly populate the page:
+ * {
+ * components: [
+ * {
+ * name: 'Component1',
+ * version: '1.2.3',
+ * },
+ * {
+ * name: 'Component2',
+ * version: '4.5.6',
+ * },
+ * ]
+ * }
+ */
+function returnComponentsData(componentsData) {
+ var bodyContainer = $('body-container');
+ var body = document.body;
+
+ bodyContainer.style.visibility = 'hidden';
+ body.className = '';
+
+ renderTemplate(componentsData);
+
+ // Add handlers to dynamically created HTML elements.
+ var links = document.getElementsByClassName('button-check-update');
+ for (var i = 0; i < links.length; i++) {
+ links[i].onclick = function(e) {
+ handleCheckUpdate(this);
+ e.preventDefault();
+ };
+ }
+
+ // Disable some controls for Guest in ChromeOS.
+ if (cr.isChromeOS)
+ uiAccountTweaks.UIAccountTweaks.applyGuestModeVisibility(document);
+
+ bodyContainer.style.visibility = 'visible';
+ body.className = 'show-tmi-mode-initial';
+}
+
+/**
+ * Handles an 'enable' or 'disable' button getting clicked.
+ * @param {HTMLElement} node The HTML element representing the component
+ * being checked for update.
+ */
+function handleCheckUpdate(node) {
+ node.disabled = true;
+ // Tell the C++ ComponentssDOMHandler to check for update.
+ chrome.send('checkUpdate', [String(node.id)]);
+}
+
+// Get data and have it displayed upon loading.
+document.addEventListener('DOMContentLoaded', requestComponentsData);
+
+// Add handlers to static HTML elements.
+$('button-check-update').onclick = handleCheckUpdate;