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

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

Issue 1883523002: chrome://snippets-internals page for debugging NTP snippets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit tests Created 4 years, 8 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/snippets_internals.js
diff --git a/chrome/browser/resources/snippets_internals.js b/chrome/browser/resources/snippets_internals.js
new file mode 100644
index 0000000000000000000000000000000000000000..533f3c83aad0220e7e97019108bb26e92cbe215a
--- /dev/null
+++ b/chrome/browser/resources/snippets_internals.js
@@ -0,0 +1,99 @@
+// Copyright 2015 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.
+
+cr.define('chrome.snippets_internals', function() {
+ 'use strict';
+
+ function initialize() {
+ function submitDownload(event) {
+ chrome.send('download', [$('hosts-input').value]);
+ event.preventDefault();
+ }
+
+ $('submit-download').addEventListener('click', submitDownload);
+
+ function submitClear(event) {
+ chrome.send('clear');
+ event.preventDefault();
+ }
+
+ $('submit-clear').addEventListener('click', submitClear);
+
+ function clearDiscarded(event) {
Marc Treib 2016/04/13 08:45:51 submitClearDiscarded, for consistency?
jkrcal 2016/04/14 15:27:00 Done.
+ chrome.send('clearDiscarded');
+ event.preventDefault();
+ }
+
+ $('discarded-snippets-clear').addEventListener('click', clearDiscarded);
+
+ chrome.send('loaded');
+ }
+
+ function receiveProperty(propertyId, value) {
+ if ($(propertyId)) $(propertyId).textContent = value;
+ }
+
+ function receiveHostsInput(value) {
+ $('hosts-input').value = value;
+ }
+
+ function receiveHosts(hosts) {
+ displayList(hosts, 'hosts');
+ }
+
+ function receiveSnippets(snippets) {
+ displayList(snippets, 'snippets', 'snippet-title');
+ }
+
+ function receiveDiscardedSnippets(discardedSnippets) {
+ displayList(discardedSnippets, 'discarded-snippets',
+ 'discarded-snippet-title');
+ }
+
+ function trigger(event) {
+ // The id of the div to (un)hide is stored to 'myid' attribute of the link.
+ var id = event.currentTarget.getAttribute('myid');
+ if ($(id)) $(id).classList.toggle('snippet-hidden');
+ }
+
+ function displayList(object, domId, titleClass) {
+ if (object == null || !object.list || object.list.constructor !== Array)
Marc Treib 2016/04/13 08:45:51 Are these checks actually required in any legitima
jkrcal 2016/04/14 15:27:00 Done.
+ return;
+
+ jstProcess(new JsEvalContext(object), $(domId));
+
+ var text;
+ var display;
+
+ if (object.list.length > 0) {
+ text = '';
+ display = 'inline';
+ } else {
+ text = 'The list is empty.';
+ display = 'none';
+ }
+
+ if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
+ if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
+
+ var links = document.getElementsByClassName(titleClass);
+ for (var link of links) {
+ link.addEventListener('click', trigger);
+ }
+ }
+
+ // Return an object with all of the exports.
+ return {
+ initialize: initialize,
+ receiveProperty: receiveProperty,
+ receiveHostsInput: receiveHostsInput,
+ receiveHosts: receiveHosts,
+ receiveSnippets: receiveSnippets,
+ receiveDiscardedSnippets: receiveDiscardedSnippets,
+ trigger: trigger,
Marc Treib 2016/04/13 08:45:51 I think "trigger" doesn't need to be listed here.
jkrcal 2016/04/14 15:27:00 Done.
+ };
+});
+
+document.addEventListener('DOMContentLoaded',
+ chrome.snippets_internals.initialize);

Powered by Google App Engine
This is Rietveld 408576698