Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 Google Inc. All rights reserved. | 1 // Copyright 2016 Google Inc. 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 // Disable the whitelist field when it's not relevant. | |
| 6 function updateEnabledInputs() { | |
| 7 var checkbox = document.getElementById('disableInApplets'); | |
| 8 document.getElementById('whitelist').disabled = !checkbox.checked; | |
|
Devlin
2016/11/01 15:12:15
Suggestion: at the top of this file (or in common.
| |
| 9 } | |
| 10 | |
| 5 // Initialize the page. | 11 // Initialize the page. |
| 6 function init() { | 12 function init() { |
| 7 LoadInternationalizedStrings(); | 13 loadInternationalizedStrings(); |
| 8 | 14 |
| 9 var blacklist = document.getElementById('blacklist'); | 15 var blacklist = document.getElementById('blacklist'); |
| 10 var checkbox = document.getElementById('disableInApplets'); | 16 var checkbox = document.getElementById('disableInApplets'); |
| 11 var whitelist = document.getElementById('whitelist'); | 17 var whitelist = document.getElementById('whitelist'); |
| 12 | 18 |
| 13 // Configure the textboxes, allowing 200 characters for JSON serialization | 19 // Configure the textboxes, allowing 200 characters for JSON serialization |
| 14 // and key length. | 20 // and key length. |
| 15 blacklist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; | 21 blacklist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; |
| 16 whitelist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; | 22 whitelist.maxlength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 200; |
| 17 | 23 |
| 18 // Set event handlers. | 24 // Set event handlers. |
| 19 document.getElementById('done_button').onclick = function() { | 25 document.getElementById('done-button').onclick = function() { |
| 20 chrome.storage.sync.set({ | 26 chrome.storage.sync.set({ |
| 21 // Split the lists into arrays at whitespace before saving. | 27 // Split the lists into arrays at whitespace before saving. |
| 22 blacklist: | 28 blacklist: |
| 23 document.getElementById('blacklist').value.split(/\s+/), | 29 document.getElementById('blacklist').value.split(/\s+/), |
|
Devlin
2016/11/01 15:12:15
Should we validate these are urls?
Pam (message me for reviews)
2016/11/01 21:29:03
Is there a handy, robust way to do that?
Devlin
2016/11/05 04:56:09
One way would be to try to construct an URL object
Pam (message me for reviews)
2016/11/16 19:23:24
Thinking about it, what I'd like to do is check th
| |
| 24 disableInApplets: document.getElementById('disableInApplets').checked, | 30 disableInApplets: document.getElementById('disableInApplets').checked, |
| 25 whitelist: | 31 whitelist: |
| 26 document.getElementById('whitelist').value.split(/\s+/) | 32 document.getElementById('whitelist').value.split(/\s+/) |
| 27 }, function() { | 33 }, function() { |
| 28 // One easy way to force an error for testing is to change "sync" to | 34 // One easy way to force an error for testing is to change "sync" to |
| 29 // "managed" in the chrome.storage.sync.set() call above. | 35 // "managed" in the chrome.storage.sync.set() call above. |
| 30 if (chrome.runtime.lastError) { | 36 if (chrome.runtime.lastError) { |
| 31 document.getElementById('error').textContent = | 37 document.getElementById('error').textContent = |
| 32 chrome.i18n.getMessage('errorSaving', | 38 chrome.i18n.getMessage('errorSaving', |
| 33 chrome.runtime.lastError.message); | 39 chrome.runtime.lastError.message); |
| 34 } else { | 40 } else { |
| 35 window.close(); | 41 window.close(); |
| 36 } | 42 } |
| 37 }); | 43 }); |
| 38 }; | 44 }; |
| 39 | 45 |
| 40 document.getElementById('cancel_button').onclick = function() { | 46 checkbox.onchange = updateEnabledInputs; |
| 47 | |
| 48 document.getElementById('cancel-button').onclick = function() { | |
|
Devlin
2016/11/01 15:12:15
$('cancel-button').onclick = window.close;
| |
| 41 window.close(); | 49 window.close(); |
| 42 }; | 50 }; |
| 43 | 51 |
| 44 document.getElementById('report_page').onclick = function() { | 52 document.getElementById('feedback-link').onclick = function() { |
|
Devlin
2016/11/01 15:12:15
$('feedback-link').onclick = sendFeedback;
Pam (message me for reviews)
2016/11/01 21:29:03
This one doesn't work, because sendFeedback takes
| |
| 45 reportPage(); | 53 sendFeedback(); |
| 46 }; | 54 }; |
| 47 | 55 |
| 48 // Load saved settings into the form fields. | 56 // Load saved settings into the form fields. |
| 49 chrome.storage.sync.get({ | 57 chrome.storage.sync.get({ |
| 50 blacklist: [], | 58 blacklist: [], |
| 51 disableInApplets: true, | 59 disableInApplets: true, |
| 52 whitelist: [] | 60 whitelist: [] |
| 53 }, function(items) { | 61 }, function(items) { |
| 54 blacklist.value = items.blacklist.join('\n'); | 62 blacklist.value = items.blacklist.join('\n'); |
| 55 checkbox.checked = items.disableInApplets; | 63 checkbox.checked = items.disableInApplets; |
| 56 whitelist.value = items.whitelist.join('\n'); | 64 whitelist.value = items.whitelist.join('\n'); |
| 65 | |
| 66 updateEnabledInputs(); | |
| 57 }); | 67 }); |
| 58 } | 68 } |
| 59 | 69 |
| 60 window.addEventListener('load', init, false); | 70 window.addEventListener('load', init, false); |
|
Devlin
2016/11/01 15:12:15
useCapture defaults to false.
| |
| OLD | NEW |