OLD | NEW |
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 // Stores the list of suggestions we received in receiveContentSuggestions. | 8 // Stores the list of suggestions we received in receiveContentSuggestions. |
9 var lastSuggestions = []; | 9 var lastSuggestions = []; |
10 | 10 |
11 function initialize() { | 11 function initialize() { |
12 $('submit-download').addEventListener('click', function(event) { | 12 $('submit-download').addEventListener('click', function(event) { |
13 chrome.send('download'); | 13 chrome.send('download'); |
14 event.preventDefault(); | 14 event.preventDefault(); |
15 }); | 15 }); |
16 | 16 |
17 $('submit-dump').addEventListener('click', function(event) { | 17 $('submit-dump').addEventListener('click', function(event) { |
18 downloadJson(JSON.stringify(lastSuggestions)); | 18 downloadJson(JSON.stringify(lastSuggestions, null, 2)); |
19 event.preventDefault(); | 19 event.preventDefault(); |
20 }); | 20 }); |
21 | 21 |
22 $('last-json-button').addEventListener('click', function(event) { | 22 $('last-json-button').addEventListener('click', function(event) { |
23 $('last-json-container').classList.toggle('hidden'); | 23 $('last-json-container').classList.toggle('hidden'); |
24 }); | 24 }); |
25 | 25 |
26 $('last-json-dump').addEventListener('click', function(event) { | 26 $('last-json-dump').addEventListener('click', function(event) { |
27 downloadJson($('last-json-text').innerText); | 27 downloadJson($('last-json-text').innerText); |
28 event.preventDefault(); | 28 event.preventDefault(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 receiveProperty('last-background-fetch-time-label', | 118 receiveProperty('last-background-fetch-time-label', |
119 lastRemoteSuggestionsBackgroundFetchTime); | 119 lastRemoteSuggestionsBackgroundFetchTime); |
120 } | 120 } |
121 | 121 |
122 function downloadJson(json) { | 122 function downloadJson(json) { |
123 // Redirect the browser to download data in |json| as a file "snippets.json" | 123 // Redirect the browser to download data in |json| as a file "snippets.json" |
124 // (Setting Content-Disposition: attachment via a data: URL is not possible; | 124 // (Setting Content-Disposition: attachment via a data: URL is not possible; |
125 // create a link with download attribute and simulate a click, instead.) | 125 // create a link with download attribute and simulate a click, instead.) |
126 var link = document.createElement('a'); | 126 var link = document.createElement('a'); |
127 link.download = 'snippets.json'; | 127 link.download = 'snippets.json'; |
128 link.href = 'data:,' + json; | 128 link.href = 'data:application/json,' + encodeURI(json); |
129 link.click(); | 129 link.click(); |
130 } | 130 } |
131 | 131 |
132 function refreshContent() { | 132 function refreshContent() { |
133 chrome.send('refreshContent'); | 133 chrome.send('refreshContent'); |
134 } | 134 } |
135 | 135 |
136 function toggleHidden(event) { | 136 function toggleHidden(event) { |
137 var id = event.currentTarget.getAttribute('hidden-id'); | 137 var id = event.currentTarget.getAttribute('hidden-id'); |
138 $(id).classList.toggle('hidden'); | 138 $(id).classList.toggle('hidden'); |
(...skipping 29 matching lines...) Expand all Loading... |
168 receiveContentSuggestions: receiveContentSuggestions, | 168 receiveContentSuggestions: receiveContentSuggestions, |
169 receiveJson: receiveJson, | 169 receiveJson: receiveJson, |
170 receiveClassification: receiveClassification, | 170 receiveClassification: receiveClassification, |
171 receiveLastRemoteSuggestionsBackgroundFetchTime: | 171 receiveLastRemoteSuggestionsBackgroundFetchTime: |
172 receiveLastRemoteSuggestionsBackgroundFetchTime, | 172 receiveLastRemoteSuggestionsBackgroundFetchTime, |
173 }; | 173 }; |
174 }); | 174 }); |
175 | 175 |
176 document.addEventListener('DOMContentLoaded', | 176 document.addEventListener('DOMContentLoaded', |
177 chrome.SnippetsInternals.initialize); | 177 chrome.SnippetsInternals.initialize); |
OLD | NEW |