@@ -20,6 +20,10 @@ window.assignManager = {
20
20
}
21
21
} ,
22
22
23
+ getWildcardStoreKey ( wildcardHostname ) {
24
+ return `wildcardMap@@_${ wildcardHostname } ` ;
25
+ } ,
26
+
23
27
setExempted ( pageUrlorUrlKey , tabId ) {
24
28
const siteStoreKey = this . getSiteStoreKey ( pageUrlorUrlKey ) ;
25
29
if ( ! ( siteStoreKey in this . exemptedTabs ) ) {
@@ -46,6 +50,18 @@ window.assignManager = {
46
50
return this . getByUrlKey ( siteStoreKey ) ;
47
51
} ,
48
52
53
+ async getOrWildcardMatch ( pageUrlorUrlKey ) {
54
+ const siteStoreKey = this . getSiteStoreKey ( pageUrlorUrlKey ) ;
55
+ const siteSettings = await this . getByUrlKey ( siteStoreKey ) ;
56
+ if ( siteSettings ) {
57
+ return {
58
+ siteStoreKey,
59
+ siteSettings
60
+ } ;
61
+ }
62
+ return this . getByWildcardMatch ( siteStoreKey ) ;
63
+ } ,
64
+
49
65
async getSyncEnabled ( ) {
50
66
const { syncEnabled } = await browser . storage . local . get ( "syncEnabled" ) ;
51
67
return ! ! syncEnabled ;
@@ -69,39 +85,90 @@ window.assignManager = {
69
85
} ) ;
70
86
} ,
71
87
88
+ async getByWildcardMatch ( siteStoreKey ) {
89
+ // Keep stripping subdomains off site hostname until match a wildcard hostname
90
+ let remainingHostname = siteStoreKey . replace ( / ^ s i t e C o n t a i n e r M a p @ @ _ / , "" ) ;
91
+ while ( remainingHostname ) {
92
+ const wildcardStoreKey = this . getWildcardStoreKey ( remainingHostname ) ;
93
+ siteStoreKey = await this . getByUrlKey ( wildcardStoreKey ) ;
94
+ if ( siteStoreKey ) {
95
+ const siteSettings = await this . getByUrlKey ( siteStoreKey ) ;
96
+ if ( siteSettings ) {
97
+ return {
98
+ siteStoreKey,
99
+ siteSettings
100
+ } ;
101
+ }
102
+ }
103
+ const indexOfDot = remainingHostname . indexOf ( "." ) ;
104
+ remainingHostname = indexOfDot < 0 ? null : remainingHostname . substring ( indexOfDot + 1 ) ;
105
+ }
106
+ } ,
107
+
72
108
async set ( pageUrlorUrlKey , data , exemptedTabIds , backup = true ) {
73
109
const siteStoreKey = this . getSiteStoreKey ( pageUrlorUrlKey ) ;
74
110
if ( exemptedTabIds ) {
75
111
exemptedTabIds . forEach ( ( tabId ) => {
76
112
this . setExempted ( pageUrlorUrlKey , tabId ) ;
77
113
} ) ;
78
114
}
115
+ await this . removeWildcardLookup ( siteStoreKey ) ;
79
116
// eslint-disable-next-line require-atomic-updates
80
117
data . identityMacAddonUUID =
81
118
await identityState . lookupMACaddonUUID ( data . userContextId ) ;
82
119
await this . area . set ( {
83
120
[ siteStoreKey ] : data
84
121
} ) ;
122
+ if ( data . wildcardHostname ) {
123
+ await this . setWildcardLookup ( siteStoreKey , data . wildcardHostname ) ;
124
+ }
85
125
const syncEnabled = await this . getSyncEnabled ( ) ;
86
126
if ( backup && syncEnabled ) {
87
127
await sync . storageArea . backup ( { undeleteSiteStoreKey : siteStoreKey } ) ;
88
128
}
89
129
return ;
90
130
} ,
91
131
132
+ async setWildcardLookup ( siteStoreKey , wildcardHostname ) {
133
+ const wildcardStoreKey = this . getWildcardStoreKey ( wildcardHostname ) ;
134
+ return this . area . set ( {
135
+ [ wildcardStoreKey ] : siteStoreKey
136
+ } ) ;
137
+ } ,
138
+
92
139
async remove ( pageUrlorUrlKey , shouldSync = true ) {
93
140
const siteStoreKey = this . getSiteStoreKey ( pageUrlorUrlKey ) ;
94
141
// When we remove an assignment we should clear all the exemptions
95
142
this . removeExempted ( pageUrlorUrlKey ) ;
143
+ // When we remove an assignment we should clear the wildcard lookup
144
+ await this . removeWildcardLookup ( siteStoreKey ) ;
96
145
await this . area . remove ( [ siteStoreKey ] ) ;
97
146
const syncEnabled = await this . getSyncEnabled ( ) ;
98
147
if ( shouldSync && syncEnabled ) await sync . storageArea . backup ( { siteStoreKey} ) ;
99
148
return ;
100
149
} ,
101
150
151
+ async removeWildcardLookup ( siteStoreKey ) {
152
+ const siteSettings = await this . getByUrlKey ( siteStoreKey ) ;
153
+ const wildcardHostname = siteSettings && siteSettings . wildcardHostname ;
154
+ if ( wildcardHostname ) {
155
+ const wildcardStoreKey = this . getWildcardStoreKey ( wildcardHostname ) ;
156
+ await this . area . remove ( [ wildcardStoreKey ] ) ;
157
+ }
158
+ } ,
159
+
102
160
async deleteContainer ( userContextId ) {
103
161
const sitesByContainer = await this . getAssignedSites ( userContextId ) ;
104
162
this . area . remove ( Object . keys ( sitesByContainer ) ) ;
163
+ // Delete wildcard lookups
164
+ const wildcardStoreKeys = Object . values ( sitesByContainer )
165
+ . map ( ( site ) => {
166
+ if ( site && site . wildcardHostname ) {
167
+ return this . getWildcardStoreKey ( site . wildcardHostname ) ;
168
+ }
169
+ } )
170
+ . filter ( ( wildcardStoreKey ) => { return ! ! wildcardStoreKey ; } ) ;
171
+ this . area . remove ( wildcardStoreKeys ) ;
105
172
} ,
106
173
107
174
async getAssignedSites ( userContextId = null ) {
@@ -166,10 +233,10 @@ window.assignManager = {
166
233
if ( m . neverAsk === true ) {
167
234
// If we have existing data and for some reason it hasn't been
168
235
// deleted etc lets update it
169
- this . storageArea . get ( pageUrl ) . then ( ( siteSettings ) => {
170
- if ( siteSettings ) {
171
- siteSettings . neverAsk = true ;
172
- this . storageArea . set ( pageUrl , siteSettings ) ;
236
+ this . storageArea . getOrWildcardMatch ( pageUrl ) . then ( ( siteMatchResult ) => {
237
+ if ( siteMatchResult ) {
238
+ siteMatchResult . siteSettings . neverAsk = true ;
239
+ this . storageArea . set ( siteMatchResult . siteStoreKey , siteMatchResult . siteSettings ) ;
173
240
}
174
241
} ) . catch ( ( e ) => {
175
242
throw e ;
@@ -217,10 +284,11 @@ window.assignManager = {
217
284
return { } ;
218
285
}
219
286
this . removeContextMenu ( ) ;
220
- const [ tab , siteSettings ] = await Promise . all ( [
287
+ const [ tab , siteMatchResult ] = await Promise . all ( [
221
288
browser . tabs . get ( options . tabId ) ,
222
- this . storageArea . get ( options . url )
289
+ this . storageArea . getOrWildcardMatch ( options . url )
223
290
] ) ;
291
+ const siteSettings = siteMatchResult && siteMatchResult . siteSettings ;
224
292
let container ;
225
293
try {
226
294
container = await browser . contextualIdentities
@@ -620,6 +688,14 @@ window.assignManager = {
620
688
}
621
689
} ,
622
690
691
+ async _setWildcardHostnameForAssignment ( pageUrl , wildcardHostname ) {
692
+ const siteSettings = await this . storageArea . get ( pageUrl ) ;
693
+ if ( siteSettings ) {
694
+ siteSettings . wildcardHostname = wildcardHostname ;
695
+ await this . storageArea . set ( pageUrl , siteSettings ) ;
696
+ }
697
+ } ,
698
+
623
699
async _maybeRemoveSiteIsolation ( userContextId ) {
624
700
const assignments = await this . storageArea . getByContainer ( userContextId ) ;
625
701
const hasAssignments = assignments && Object . keys ( assignments ) . length > 0 ;
0 commit comments