Skip to content

Commit ea76543

Browse files
committed
add favicon support
1 parent 85999e8 commit ea76543

File tree

10 files changed

+75
-4
lines changed

10 files changed

+75
-4
lines changed

_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@
289289
"message": "Use Autofill",
290290
"description": "Use Autofill"
291291
},
292+
"show_favicon": {
293+
"message": "Show Issuer Icon",
294+
"description": "Show Issuer Icon"
295+
},
292296
"use_high_contrast": {
293297
"message": "Use High Contrast",
294298
"description": "Use High Contrast"

manifests/manifest-chrome-testing.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
],
5757
"optional_permissions": [
5858
"clipboardWrite",
59+
"favicon",
60+
"chrome://favicon/",
5961
"https://www.google.com/",
6062
"https://*.dropboxapi.com/*",
6163
"https://www.googleapis.com/*",
@@ -65,5 +67,5 @@
6567
],
6668
"offline_enabled": true,
6769
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjo5++7m6mlJGqKOnlYehr9tjIqahMZBJUG7PLa7dSRk6bDUu2pVodO1TQWviHlrDTLP+zfoVbDBS8v8cjloK5Tn90nzC6a957dPzOfyC1WUNYNDlGM0BCmZKVP/MWB3d0ffOmTwaxh0L47aLH5nTW0AUmuwCWCBEEl4Acuyp7rwLNGlazBpaom1Qb5ckn29gCJVVVIZ6wudmcrG/FPTNJXQbg8N6wObGrgGOaxmowbkzJmIfKTyHlYOKLAjZ7aJi0W6jsy47/aV+ojvn4gO+ka6BcRhUeWgoQxqEky119f3OWiVP46SJVbAi0pkknThUjDvX11lATGjB5EvJZGyotwIDAQAB",
68-
"content_security_policy": "script-src 'self' 'unsafe-eval'; font-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/ ws://localhost:9090; default-src 'none'"
70+
"content_security_policy": "script-src 'self' 'unsafe-eval'; font-src 'self'; img-src 'self' data: chrome://favicon/; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/ ws://localhost:9090; default-src 'none'"
6971
}

manifests/manifest-chrome.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
],
5757
"optional_permissions": [
5858
"clipboardWrite",
59+
"favicon",
60+
"chrome://favicon/",
5961
"https://www.google.com/",
6062
"https://*.dropboxapi.com/*",
6163
"https://www.googleapis.com/*",
@@ -64,5 +66,5 @@
6466
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
6567
],
6668
"offline_enabled": true,
67-
"content_security_policy": "script-src 'self'; font-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/; default-src 'none'"
69+
"content_security_policy": "script-src 'self'; font-src 'self'; img-src 'self' data: chrome://favicon/; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/; default-src 'none'"
6870
}

manifests/manifest-edge.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
],
5757
"optional_permissions": [
5858
"clipboardWrite",
59+
"favicon",
60+
"chrome://favicon/",
5961
"https://www.google.com/",
6062
"https://*.dropboxapi.com/*",
6163
"https://www.googleapis.com/*",
@@ -64,5 +66,5 @@
6466
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
6567
],
6668
"offline_enabled": true,
67-
"content_security_policy": "script-src 'self'; font-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/; default-src 'none'"
69+
"content_security_policy": "script-src 'self'; font-src 'self'; img-src 'self' data: chrome://favicon/; style-src 'self' 'unsafe-inline'; connect-src https://www.google.com/ https://*.dropboxapi.com https://www.googleapis.com/ https://accounts.google.com/o/oauth2/revoke https://login.microsoftonline.com/common/oauth2/v2.0/token https://graph.microsoft.com/; default-src 'none'"
6870
}

sass/popup.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ svg {
212212
display: none;
213213
}
214214

215+
.issuerFavicon {
216+
vertical-align: bottom;
217+
margin-right: 5px;
218+
height: 14px;
219+
width: 14px;
220+
}
221+
215222
&:hover {
216223
padding-right: 0;
217224
overflow-y: scroll;

src/components/Popup/EntryComponent.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@
3838
>
3939
<IconRedo />
4040
</div>
41-
<div class="issuer">{{ entry.issuer.split("::")[0] }}</div>
41+
<div class="issuer">
42+
<img
43+
class="issuerFavicon"
44+
v-if="shouldShowFavicon() && entry.issuer.split('::')[1]"
45+
v-bind:src="getFaviconUrl(entry.issuer.split('::')[1])"
46+
/><IconMedal
47+
class="issuerFavicon"
48+
v-if="shouldShowFavicon() && !entry.issuer.split('::')[1]"
49+
/>{{ entry.issuer.split("::")[0] }}
50+
</div>
4251
<div class="issuerEdit">
4352
<input
4453
v-bind:placeholder="i18n.issuer"
@@ -91,6 +100,7 @@ import IconRedo from "../../../svg/redo.svg";
91100
import IconQr from "../../../svg/qrcode.svg";
92101
import IconBars from "../../../svg/bars.svg";
93102
import IconPin from "../../../svg/pin.svg";
103+
import IconMedal from "../../../svg/medal.svg";
94104
95105
const computedPrototype = [
96106
mapState("accounts", [
@@ -131,6 +141,20 @@ export default Vue.extend({
131141
entry.type !== OTPType.steam
132142
);
133143
},
144+
shouldShowFavicon() {
145+
return (
146+
navigator.userAgent.indexOf("Firefox") === -1 &&
147+
this.$store.state.menu.showFavicon
148+
);
149+
},
150+
getFaviconUrl(u: string) {
151+
// for MV3
152+
// const url = new URL(chrome.runtime.getURL("/_favicon/"));
153+
// url.searchParams.set("pageUrl", "https://" + u);
154+
// url.searchParams.set("size", "16");
155+
// return url.toString();
156+
return "chrome://favicon/https://" + u;
157+
},
134158
showCode(code: string) {
135159
if (code === CodeState.Encrypted) {
136160
return this.i18n.encrypted;
@@ -255,6 +279,7 @@ export default Vue.extend({
255279
IconQr,
256280
IconBars,
257281
IconPin,
282+
IconMedal,
258283
},
259284
});
260285

src/components/Popup/PreferencesPage.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
:disabled="storageArea"
3535
@change="migrateStorage()"
3636
/>
37+
<a-toggle-input
38+
:label="i18n.show_favicon"
39+
v-model="showFavicon"
40+
v-if="isNotFirefox"
41+
/>
3742
<div class="control-group" v-show="encryption.getEncryptionStatus()">
3843
<label class="combo-label">{{ i18n.autolock }}</label>
3944
<input
@@ -118,11 +123,28 @@ export default Vue.extend({
118123
this.newStorageLocation = value ? "sync" : "local";
119124
},
120125
},
126+
showFavicon: {
127+
get(): boolean {
128+
return this.$store.state.menu.showFavicon;
129+
},
130+
set(showFavicon: boolean) {
131+
chrome.permissions.request(
132+
{ permissions: ["favicon"], origins: ["chrome://favicon/"] },
133+
(granted) => {
134+
this.$store.commit(
135+
"menu/setShowFavicon",
136+
granted ? showFavicon : false
137+
);
138+
}
139+
);
140+
},
141+
},
121142
},
122143
data() {
123144
return {
124145
newStorageLocation:
125146
this.$store.state.menu.storageArea || localStorage.storageLocation,
147+
isNotFirefox: navigator.userAgent.indexOf("Firefox") === -1,
126148
};
127149
},
128150
methods: {

src/definitions/module-interface.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface MenuState {
3737
theme: string;
3838
backupDisabled: boolean;
3939
storageArea: "sync" | "local";
40+
showFavicon: boolean;
4041
}
4142

4243
interface StyleState {

src/store/Menu.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export class Menu implements Module {
88
zoom: Number(localStorage.zoom) || 100,
99
useAutofill: localStorage.autofill === "true",
1010
smartFilter: localStorage.smartFilter !== "false",
11+
showFavicon: localStorage.showFavicon === "true",
1112
theme:
1213
localStorage.theme ||
1314
(localStorage.highContrast === "true" ? "accessibility" : "normal"),
@@ -37,6 +38,10 @@ export class Menu implements Module {
3738
state.smartFilter = smartFilter;
3839
localStorage.smartFilter = smartFilter;
3940
},
41+
setShowFavicon(state: MenuState, showFavicon: boolean) {
42+
state.showFavicon = showFavicon;
43+
localStorage.showFavicon = showFavicon;
44+
},
4045
setTheme(state: MenuState, theme: string) {
4146
state.theme = theme;
4247
localStorage.theme = theme;

svg/medal.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)