Skip to content

Commit

Permalink
request permissions for xhr requests when update checking non-CWS ext…
Browse files Browse the repository at this point in the history
…ensions #59
  • Loading branch information
NeverDecaf committed Feb 21, 2021
1 parent f1a80bb commit 7744f68
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"contextMenus",
"downloads"
],
"optional_permissions": [ "https://*/", "http://*/" ],
"browser_action": {
"default_icon": {
"16": "assets/icon/icon_16.png",
Expand Down
92 changes: 56 additions & 36 deletions src/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const update_text = document.createElement('p');
update_text.innerHTML = chrome.i18n.getMessage("popup_checkingForUpdates");
update_status.appendChild(update_text);
update_status.setAttribute('class', 'message');
update_status.setAttribute('id','updateStatus');
update_status.setAttribute('id', 'updateStatus');
removed_text.innerHTML = chrome.i18n.getMessage("popup_removedExtensions");
removed_status.setAttribute('title', chrome.i18n.getMessage("popup_removedExtensionsTooltip"));
removed_status.appendChild(removed_text);
removed_status.setAttribute('id','removedStatus');
removed_status.setAttribute('id', 'removedStatus');
removed_status.setAttribute('class', 'message');
removed_status.classList.add('hidden');
container.appendChild(update_status);
Expand Down Expand Up @@ -54,41 +54,61 @@ checkForUpdates(function (updateCheck, installed_versions, appid, updatever, is_
update_status.classList.add('hidden');
}, function (was_removed, extData) {
let li = document.createElement('li');
li.setAttribute('data-enabled', extData.enabled ? 'true' : 'false');
li.setAttribute('data-enabled', extData.enabled ? 'true' : 'false');
li.setAttribute('class', 'updatefailure');
if ('icons' in extData) {
let img = document.createElement('img');
if (extData.icons)
img.setAttribute('src', 'chrome://extension-icon/' + extData.id + '/' + extData.icons[0].size + '/0');
else
img.setAttribute('src', 'chrome://extension-icon/ocaahdebbfolfmndjeplogmgcagdmblk/16/0');
li.appendChild(img);
}
let span = document.createElement('span');
li.appendChild(span);
if (was_removed) {
span.innerHTML = extData.name;
li.setAttribute('class', 'removedext');
removedcontainer.appendChild(li);
removed_status.classList.remove('hidden');
close_button = document.createElement('a');
close_button.setAttribute('target', '_blank');
close_button.innerHTML = '<svg class="svg-icon" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block;"><path d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46A11.804 11.804 0 0 0 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"></path></svg>';
li.appendChild(close_button);
close_button.onclick = () => {
let default_options = {'removed_extensions': {}};
chrome.storage.sync.get(default_options, function (stored_values) {
stored_values['removed_extensions'][extData.id] = true;
chrome.storage.sync.set({'removed_extensions': stored_values['removed_extensions']});
li.remove();
if (removedcontainer.getElementsByTagName("li").length == 0)
removed_status.classList.add('hidden');
});
};
}
else {
span.innerHTML = chrome.i18n.getMessage("popup_updateFailed", extData.name);
appcontainer.appendChild(li);
if ('icons' in extData) {
let img = document.createElement('img');
if (extData.icons)
img.setAttribute('src', 'chrome://extension-icon/' + extData.id + '/' + extData.icons[0].size + '/0');
else
img.setAttribute('src', 'chrome://extension-icon/ocaahdebbfolfmndjeplogmgcagdmblk/16/0');
li.appendChild(img);
}
let span = document.createElement('span');
li.appendChild(span);
if (was_removed) {
span.innerHTML = extData.name;
li.setAttribute('class', 'removedext');
removedcontainer.appendChild(li);
removed_status.classList.remove('hidden');
close_button = document.createElement('a');
close_button.setAttribute('target', '_blank');
close_button.innerHTML = '<svg class="svg-icon" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block;"><path d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46A11.804 11.804 0 0 0 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"></path></svg>';
li.appendChild(close_button);
close_button.onclick = () => {
let default_options = {
'removed_extensions': {}
};
chrome.storage.sync.get(default_options, function (stored_values) {
stored_values['removed_extensions'][extData.id] = true;
chrome.storage.sync.set({
'removed_extensions': stored_values['removed_extensions']
});
li.remove();
if (removedcontainer.getElementsByTagName("li").length == 0)
removed_status.classList.add('hidden');
});
};
} else {
span.innerHTML = chrome.i18n.getMessage("popup_updateFailed", extData.name);
appcontainer.appendChild(li);
if (extData.updateUrl) {
chrome.permissions.contains({
origins: [extData.updateUrl]
}, (e) => {
if (!e) {
fix_button = document.createElement('a');
fix_button.setAttribute('target', '_blank');
fix_button.innerHTML = '<svg class="svg-icon" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block;"><path d="M4.5.257l3.771 3.771c.409 1.889-2.33 4.66-4.242 4.242l-3.771-3.77c-.172.584-.258 1.188-.258 1.792 0 1.602.607 3.202 1.83 4.426 1.351 1.351 3.164 1.958 4.931 1.821.933-.072 1.852.269 2.514.931l9.662 9.662c.578.578 1.337.868 2.097.868 1.661 0 3.001-1.364 2.966-3.03-.016-.737-.306-1.47-.868-2.033l-9.662-9.663c-.662-.661-1.002-1.581-.931-2.514.137-1.767-.471-3.58-1.82-4.93-1.225-1.224-2.825-1.83-4.428-1.83-.603 0-1.207.086-1.791.257zm17.5 20.743c0 .553-.447 1-1 1-.553 0-1-.448-1-1s.447-1 1-1 1 .447 1 1z"></path></svg>';
li.appendChild(fix_button);
fix_button.onclick = () => {
chrome.permissions.request({
origins: [extData.updateUrl]
})
}
}
})
}
}
}, function () {
update_text.innerHTML = chrome.i18n.getMessage("popup_allUpToDate");
Expand Down
9 changes: 5 additions & 4 deletions src/sheets/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ a:hover {
.updatefailure,
.updatefailure:hover {
background-color: #ffcccb;
cursor: auto;
outline-style: none;
}

#removedStatus {
box-shadow: 0 0 0 1px red, 0 0 2px 0 red;
}

.removedext,
.removedext:hover {
.removedext:hover,
.updatefailure,
.updatefailure:hover {
cursor: auto;
outline-style: none;
}
Expand All @@ -111,7 +111,8 @@ svg {
width: 20px;
height: 20px;
}
.removedext svg {
.removedext svg,
.updatefailure svg {
width: 16px;
height: 16px;
}
Expand Down

0 comments on commit 7744f68

Please sign in to comment.