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

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

Issue 2325963003: Add options and a browser-action popup. (Closed) Base URL: https://chromium.googlesource.com/chromium/extensions-by-google.git@master
Patch Set: Comments and copyrights Created 4 years, 3 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
(Empty)
1 // Copyright 2016 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Return true if the extension is permitted to run on the given URL, with
6 // the indicated permission for file:// schemes.
7 function urlAllowed(url, file_ok) {
8 // Extensions are prohibited on the Chrome Web Store.
9 if (url.startsWith('https://chrome.google.com/webstore/'))
10 return false;
11
12 // Extensions are permitted to run on pages with schemes http, https, and
13 // ftp, plus file if enabled.
14 if (url.startsWith('http://') ||
15 url.startsWith('https://') ||
16 url.startsWith('ftp://'))
17 return true;
18
19 if (file_ok && url.startsWith('file://'))
20 return true;
21
22 return false;
23 }
24
25 // Update the popup display depending on the current options and the URL of
26 // the current page.
27 function updatePopup(options, url) {
28 var button = document.getElementById('list_edit_button');
29
30 if (!urlAllowed(url, options.file_ok)) {
31 button.textContent = chrome.i18n.getMessage('popupAddBlacklist');
32 button.disabled = true;
33 setStatusError('popupDisallowedURL');
34 } else if (options.blacklist.includes(url)) {
35 button.textContent = chrome.i18n.getMessage('popupRemoveBlacklist');
36 } else {
37 button.textContent = chrome.i18n.getMessage('popupAddBlacklist');
38 }
39
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.
42 if (!options.file_ok && url.startsWith('file://')) {
43 document.getElementById('file_url_message').hidden = false;
44 document.getElementById('status').hidden = true;
45 }
46 }
47
48 // Set the status text and display it in the error style.
49 function setStatusError(message_id, placeholder) {
50 setStatus(message_id, placeholder);
51 document.getElementById('status').classList.add('error');
52 }
53
54 // Set the status text.
55 function setStatus(message_id, placeholder) {
56 var status = document.getElementById('status');
57 if (placeholder === undefined)
58 status.textContent = chrome.i18n.getMessage(message_id);
59 else
60 status.textContent = chrome.i18n.getMessage(message_id, placeholder);
61 }
62
63 // Initialize the page.
64 function init() {
65 // Load internationalized strings.
66 var all = document.getElementsByTagName('*');
67 for (var i = 0; i < all.length; ++i) {
68 var i18n = all[i].getAttribute('i18n');
69 if (i18n)
70 all[i].textContent = chrome.i18n.getMessage(i18n);
71 }
72
73 // Load the active tab's URL, then set up page features that depend on it.
74 chrome.tabs.query({active: true, currentWindow: true}, function(tabList) {
75 var url = tabList[0].url;
76 var element = document.getElementById('current_url');
77 element.textContent = chrome.i18n.getMessage('popupCurrentURL', url);
78
79 // Load settings.
80 var options = {};
81 chrome.storage.sync.get({
82 blacklist: [],
83 disableInApplets: true,
84 whitelist: []
85 }, function(items) {
86 options = items;
87 // Read the extension file-access permission and update the popup UI.
88 chrome.extension.isAllowedFileSchemeAccess(function(file_ok) {
89 options.file_ok = file_ok;
90 updatePopup(options, url);
91 });
92 });
93
94 // Set event handlers that depend on the URL.
95 document.getElementById('list_edit_button').onclick = function() {
96 var index = options.blacklist.indexOf(url);
97 if (index > -1)
98 options.blacklist.splice(index, 1);
99 else
100 options.blacklist.push(url);
101
102 chrome.storage.sync.set({
103 blacklist: options.blacklist,
104 whitelist: options.whitelist
105 }, function() {
106 if (chrome.runtime.lastError) {
107 setStatusError('errorSaving', chrome.runtime.lastError.message);
108 } else {
109 updatePopup(options, url);
110 setStatus('popupStatusSaved');
111 }
112 });
113 };
114
115 document.getElementById('report_page').onclick = function() {
116 reportPage(url);
117 };
118 });
119
120 // Set event handlers that don't need the URL.
121 document.getElementById('open_options').onclick = function() {
122 chrome.runtime.openOptionsPage();
123 };
124
125 document.getElementById('open_extensions').onclick = function() {
126 chrome.tabs.create({url: 'chrome://extensions', active:true});
127 window.close();
128 };
129 }
130
131 window.addEventListener('load', init, false);
OLDNEW
« go-back-with-backspace/pages/options.js ('K') | « go-back-with-backspace/pages/popup.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698