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

Side by Side Diff: chrome/browser/resources/snippets_internals.js

Issue 1978513002: Getting the personalization info in chrome://snippets-internals correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Polish Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('chrome.SnippetsInternals', function() { 5 cr.define('chrome.SnippetsInternals', function() {
6 'use strict'; 6 'use strict';
7 7
8 function initialize() { 8 function initialize() {
9 $('submit-download').addEventListener('click', function(event) { 9 $('submit-download').addEventListener('click', function(event) {
10 chrome.send('download', [$('hosts-input').value]); 10 chrome.send('download', [$('hosts-input').value]);
(...skipping 20 matching lines...) Expand all
31 }); 31 });
32 32
33 $('discarded-snippets-clear').addEventListener('click', function(event) { 33 $('discarded-snippets-clear').addEventListener('click', function(event) {
34 chrome.send('clearDiscarded'); 34 chrome.send('clearDiscarded');
35 event.preventDefault(); 35 event.preventDefault();
36 }); 36 });
37 37
38 chrome.send('loaded'); 38 chrome.send('loaded');
39 } 39 }
40 40
41 function hideHostRestricts() {
42 $('hosts-restrict').classList.add('hidden');
43 }
44
41 function receiveProperty(propertyId, value) { 45 function receiveProperty(propertyId, value) {
42 $(propertyId).textContent = value; 46 $(propertyId).textContent = value;
43 } 47 }
44 48
45 function receiveHosts(hosts) { 49 function receiveHosts(hosts) {
46 displayList(hosts, 'hosts'); 50 displayList(hosts, 'hosts');
47 51
48 $('hosts-input').value = hosts.list.map( 52 $('hosts-input').value = hosts.list.map(
49 function(host) { return host.url;}).join(' '); 53 function(host) { return host.url;}).join(' ');
50 } 54 }
51 55
52 function receiveSnippets(snippets) { 56 function receiveSnippets(snippets) {
53 displayList(snippets, 'snippets', 'snippet-title'); 57 displayList(snippets, 'snippets', 'snippet-title');
54 } 58 }
55 59
56 function receiveDiscardedSnippets(discardedSnippets) { 60 function receiveDiscardedSnippets(discardedSnippets) {
57 displayList(discardedSnippets, 'discarded-snippets', 61 displayList(discardedSnippets, 'discarded-snippets',
58 'discarded-snippet-title'); 62 'discarded-snippet-title');
59 } 63 }
60 64
61 function receiveJson(json) { 65 function receiveJson(json) {
62 receiveProperty('last-json-text', json); 66 var trimmed = json.trim();
63 if (json) { 67 var hasContent = (trimmed && trimmed != '{}');
68
69 if (hasContent) {
70 receiveProperty('last-json-text', trimmed);
64 $('last-json').classList.remove('hidden'); 71 $('last-json').classList.remove('hidden');
65 } else { 72 } else {
66 $('last-json').classList.add('hidden'); 73 $('last-json').classList.add('hidden');
67 } 74 }
68 } 75 }
69 76
70 function receiveJsonToDownload(json) { 77 function receiveJsonToDownload(json) {
71 // Redirect the browser to download data in |json| as a file "snippets.json" 78 // Redirect the browser to download data in |json| as a file "snippets.json"
72 // (Setting Content-Disposition: attachment via a data: URL is not possible; 79 // (Setting Content-Disposition: attachment via a data: URL is not possible;
73 // create a link with download attribute and simulate a click, instead.) 80 // create a link with download attribute and simulate a click, instead.)
(...skipping 25 matching lines...) Expand all
99 link.addEventListener('click', function(event) { 106 link.addEventListener('click', function(event) {
100 var id = event.currentTarget.getAttribute('snippet-id'); 107 var id = event.currentTarget.getAttribute('snippet-id');
101 $(id).classList.toggle('hidden'); 108 $(id).classList.toggle('hidden');
102 }); 109 });
103 } 110 }
104 } 111 }
105 112
106 // Return an object with all of the exports. 113 // Return an object with all of the exports.
107 return { 114 return {
108 initialize: initialize, 115 initialize: initialize,
116 hideHostRestricts: hideHostRestricts,
109 receiveProperty: receiveProperty, 117 receiveProperty: receiveProperty,
110 receiveHosts: receiveHosts, 118 receiveHosts: receiveHosts,
111 receiveSnippets: receiveSnippets, 119 receiveSnippets: receiveSnippets,
112 receiveDiscardedSnippets: receiveDiscardedSnippets, 120 receiveDiscardedSnippets: receiveDiscardedSnippets,
113 receiveJson: receiveJson, 121 receiveJson: receiveJson,
114 receiveJsonToDownload: receiveJsonToDownload, 122 receiveJsonToDownload: receiveJsonToDownload,
115 }; 123 };
116 }); 124 });
117 125
118 document.addEventListener('DOMContentLoaded', 126 document.addEventListener('DOMContentLoaded',
119 chrome.SnippetsInternals.initialize); 127 chrome.SnippetsInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698