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

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: Fix global-replace bug 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
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 = document.getElementById('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 document.getElementById('file-url-message').hidden = false;
44 document.getElementById('status').hidden = true; 44 document.getElementById('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 document.getElementById('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'); 56 var status = document.getElementById('status');
57 if (placeholder === undefined) 57 if (placeholder === undefined)
58 status.textContent = chrome.i18n.getMessage(message_id); 58 status.textContent = chrome.i18n.getMessage(message_id);
59 else 59 else
60 status.textContent = chrome.i18n.getMessage(message_id, placeholder); 60 status.textContent = chrome.i18n.getMessage(message_id, placeholder);
61 } 61 }
62 62
63 // Initialize the page. 63 // Initialize the page.
64 function init() { 64 function init() {
65 LoadInternationalizedStrings(); 65 loadInternationalizedStrings();
66 66
67 // Load the active tab's URL, then set up page features that depend on it. 67 // 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) { 68 chrome.tabs.query({active: true, currentWindow: true}, function(tabList) {
69 var url = tabList[0].url; 69 var url = tabList[0].url;
70 var element = document.getElementById('current_url');
71 element.textContent = chrome.i18n.getMessage('popupCurrentURL', url);
72 70
73 // Load settings. 71 // Load settings.
74 var options = {}; 72 var options = {};
75 chrome.storage.sync.get({ 73 chrome.storage.sync.get({
76 blacklist: [], 74 blacklist: [],
77 disableInApplets: true, 75 disableInApplets: true,
78 whitelist: [] 76 whitelist: []
79 }, function(items) { 77 }, function(items) {
80 options = items; 78 options = items;
81 // Read the extension file-access permission and update the popup UI. 79 // Read the extension file-access permission and update the popup UI.
82 chrome.extension.isAllowedFileSchemeAccess(function(file_ok) { 80 chrome.extension.isAllowedFileSchemeAccess(function(file_ok) {
83 options.file_ok = file_ok; 81 options.file_ok = file_ok;
84 updatePopup(options, url); 82 updatePopup(options, url);
85 }); 83 });
86 }); 84 });
87 85
88 // Set event handlers that depend on the URL. 86 // Set event handlers that depend on the URL.
89 document.getElementById('list_edit_button').onclick = function() { 87 document.getElementById('list-edit-button').onclick = function() {
90 var index = options.blacklist.indexOf(url); 88 var index = options.blacklist.indexOf(url);
91 if (index > -1) 89 if (index > -1)
92 options.blacklist.splice(index, 1); 90 options.blacklist.splice(index, 1);
93 else 91 else
94 options.blacklist.push(url); 92 options.blacklist.push(url);
95 93
96 chrome.storage.sync.set({ 94 chrome.storage.sync.set({
97 blacklist: options.blacklist, 95 blacklist: options.blacklist,
98 whitelist: options.whitelist 96 whitelist: options.whitelist
99 }, function() { 97 }, function() {
100 if (chrome.runtime.lastError) { 98 if (chrome.runtime.lastError) {
101 setStatusError('errorSaving', chrome.runtime.lastError.message); 99 setStatusError('errorSaving', chrome.runtime.lastError.message);
102 } else { 100 } else {
103 updatePopup(options, url); 101 updatePopup(options, url);
104 setStatus('popupStatusSaved'); 102 setStatus('popupStatusSaved');
105 } 103 }
106 }); 104 });
107 }; 105 };
108 106
109 document.getElementById('report_page').onclick = function() { 107 document.getElementById('feedback-link').onclick = function() {
Devlin 2016/11/01 15:12:15 Same comments
Pam (message me for reviews) 2016/11/01 21:29:03 Done, except that these two need to stay inside an
110 reportPage(url); 108 sendFeedback(url);
111 }; 109 };
112 }); 110 });
113 111
114 // Set event handlers that don't need the URL. 112 // Set event handlers that don't need the URL.
115 document.getElementById('open_options').onclick = function() { 113 document.getElementById('options-link').onclick = function() {
116 chrome.runtime.openOptionsPage(); 114 chrome.runtime.openOptionsPage();
117 }; 115 };
118 116
119 document.getElementById('open_extensions').onclick = function() { 117 document.getElementById('open-extensions').onclick = function() {
120 chrome.tabs.create({url: 'chrome://extensions', active:true}); 118 chrome.tabs.create({url: 'chrome://extensions', active:true});
121 window.close(); 119 window.close();
122 }; 120 };
123 } 121 }
124 122
125 window.addEventListener('load', init, false); 123 window.addEventListener('load', init, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698