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

Side by Side Diff: go-back-with-backspace/pages/popup.js

Issue 2400303003: Update UI and catch executeScript errors now shown in Canary (Closed)
Patch Set: Add TODO to validate URLs Created 4 years, 1 month 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
« no previous file with comments | « go-back-with-backspace/pages/popup.html ('k') | go-back-with-backspace/pages/settings.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Return true if the extension is permitted to run on the given URL, with 5 // Return true if the extension is permitted to run on the given URL, with
6 // the indicated permission for file:// schemes. 6 // the indicated permission for file:// schemes.
7 function urlAllowed(url, file_ok) { 7 function urlAllowed(url, file_ok) {
8 // Extensions are prohibited on the Chrome Web Store. 8 // Extensions are prohibited on the Chrome Web Store.
9 if (url.startsWith('https://chrome.google.com/webstore/')) 9 if (url.startsWith('https://chrome.google.com/webstore/'))
10 return false; 10 return false;
11 11
12 // Extensions are permitted to run on pages with schemes http, https, and 12 // Extensions are permitted to run on pages with schemes http, https, and
13 // ftp, plus file if enabled. 13 // ftp, plus file if enabled.
14 if (url.startsWith('http://') || 14 if (url.startsWith('http://') ||
15 url.startsWith('https://') || 15 url.startsWith('https://') ||
16 url.startsWith('ftp://')) 16 url.startsWith('ftp://'))
17 return true; 17 return true;
18 18
19 if (file_ok && url.startsWith('file://')) 19 if (file_ok && url.startsWith('file://'))
20 return true; 20 return true;
21 21
22 return false; 22 return false;
23 } 23 }
24 24
25 // Update the popup display depending on the current options and the URL of 25 // Update the popup display depending on the current options and the URL of
26 // the current page. 26 // the current page.
27 function updatePopup(options, url) { 27 function updatePopup(options, url) {
28 var button = document.getElementById('list_edit_button'); 28 var button = $('list-edit-button');
29 29
30 if (!urlAllowed(url, options.file_ok)) { 30 if (!urlAllowed(url, options.file_ok)) {
31 button.textContent = chrome.i18n.getMessage('popupAddBlacklist'); 31 button.textContent = chrome.i18n.getMessage('popupAddBlacklist');
32 button.disabled = true; 32 button.disabled = true;
33 setStatusError('popupDisallowedURL'); 33 setStatusError('popupDisallowedURL');
34 } else if (options.blacklist.includes(url)) { 34 } else if (options.blacklist.includes(url)) {
35 button.textContent = chrome.i18n.getMessage('popupRemoveBlacklist'); 35 button.textContent = chrome.i18n.getMessage('popupRemoveBlacklist');
36 } else { 36 } else {
37 button.textContent = chrome.i18n.getMessage('popupAddBlacklist'); 37 button.textContent = chrome.i18n.getMessage('popupAddBlacklist');
38 } 38 }
39 39
40 // If the current page is prohibited because it's a file:// scheme, show a 40 // If the current page is prohibited because it's a file:// scheme, show a
41 // link to chrome://extensions, where that setting can be changed. 41 // link to chrome://extensions, where that setting can be changed.
42 if (!options.file_ok && url.startsWith('file://')) { 42 if (!options.file_ok && url.startsWith('file://')) {
43 document.getElementById('file_url_message').hidden = false; 43 $('file-url-message').hidden = false;
44 document.getElementById('status').hidden = true; 44 $('status').hidden = true;
45 } 45 }
46 } 46 }
47 47
48 // Set the status text and display it in the error style. 48 // Set the status text and display it in the error style.
49 function setStatusError(message_id, placeholder) { 49 function setStatusError(message_id, placeholder) {
50 setStatus(message_id, placeholder); 50 setStatus(message_id, placeholder);
51 document.getElementById('status').classList.add('error'); 51 $('status').classList.add('error');
52 } 52 }
53 53
54 // Set the status text. 54 // Set the status text.
55 function setStatus(message_id, placeholder) { 55 function setStatus(message_id, placeholder) {
56 var status = document.getElementById('status');
57 if (placeholder === undefined) 56 if (placeholder === undefined)
58 status.textContent = chrome.i18n.getMessage(message_id); 57 $('status').textContent = chrome.i18n.getMessage(message_id);
59 else 58 else
60 status.textContent = chrome.i18n.getMessage(message_id, placeholder); 59 $('status').textContent = chrome.i18n.getMessage(message_id, placeholder);
61 } 60 }
62 61
63 // Initialize the page. 62 // Initialize the page.
64 function init() { 63 function init() {
65 LoadInternationalizedStrings(); 64 loadInternationalizedStrings();
66 65
67 // Load the active tab's URL, then set up page features that depend on it. 66 // Load the active tab's URL, then set up page features that depend on it.
68 chrome.tabs.query({active: true, currentWindow: true}, function(tabList) { 67 chrome.tabs.query({active: true, currentWindow: true}, function(tabList) {
69 var url = tabList[0].url; 68 var url = tabList[0].url;
70 var element = document.getElementById('current_url');
71 element.textContent = chrome.i18n.getMessage('popupCurrentURL', url);
72 69
73 // Load settings. 70 // Load settings.
74 var options = {}; 71 var options = {};
75 chrome.storage.sync.get({ 72 chrome.storage.sync.get({
76 blacklist: [], 73 blacklist: [],
77 disableInApplets: true, 74 disableInApplets: true,
78 whitelist: [] 75 whitelist: []
79 }, function(items) { 76 }, function(items) {
80 options = items; 77 options = items;
81 // Read the extension file-access permission and update the popup UI. 78 // Read the extension file-access permission and update the popup UI.
82 chrome.extension.isAllowedFileSchemeAccess(function(file_ok) { 79 chrome.extension.isAllowedFileSchemeAccess(function(file_ok) {
83 options.file_ok = file_ok; 80 options.file_ok = file_ok;
84 updatePopup(options, url); 81 updatePopup(options, url);
85 }); 82 });
86 }); 83 });
87 84
88 // Set event handlers that depend on the URL. 85 // Set event handlers that depend on the URL.
89 document.getElementById('list_edit_button').onclick = function() { 86 $('list-edit-button').onclick = function() {
90 var index = options.blacklist.indexOf(url); 87 var index = options.blacklist.indexOf(url);
91 if (index > -1) 88 if (index > -1)
92 options.blacklist.splice(index, 1); 89 options.blacklist.splice(index, 1);
93 else 90 else
94 options.blacklist.push(url); 91 options.blacklist.push(url);
95 92
96 chrome.storage.sync.set({ 93 chrome.storage.sync.set({
97 blacklist: options.blacklist, 94 blacklist: options.blacklist,
98 whitelist: options.whitelist 95 whitelist: options.whitelist
99 }, function() { 96 }, function() {
100 if (chrome.runtime.lastError) { 97 if (chrome.runtime.lastError) {
101 setStatusError('errorSaving', chrome.runtime.lastError.message); 98 setStatusError('errorSaving', chrome.runtime.lastError.message);
102 } else { 99 } else {
103 updatePopup(options, url); 100 updatePopup(options, url);
104 setStatus('popupStatusSaved'); 101 setStatus('popupStatusSaved');
105 } 102 }
106 }); 103 });
107 }; 104 };
108 105
109 document.getElementById('report_page').onclick = function() { 106 $('feedback-link').onclick = function() {
110 reportPage(url); 107 sendFeedback(url);
111 }; 108 };
112 }); 109 });
113 110
114 // Set event handlers that don't need the URL. 111 // Set event handlers that don't need the URL.
115 document.getElementById('open_options').onclick = function() { 112 $('options-link').onclick = function() {
116 chrome.runtime.openOptionsPage(); 113 chrome.runtime.openOptionsPage();
117 }; 114 };
118 115
119 document.getElementById('open_extensions').onclick = function() { 116 $('open-extensions').onclick = function() {
120 chrome.tabs.create({url: 'chrome://extensions', active:true}); 117 chrome.tabs.create({url: 'chrome://extensions', active:true});
121 window.close(); 118 window.close();
122 }; 119 };
123 } 120 }
124 121
125 window.addEventListener('load', init, false); 122 window.addEventListener('load', init);
OLDNEW
« no previous file with comments | « go-back-with-backspace/pages/popup.html ('k') | go-back-with-backspace/pages/settings.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698