Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mullvad Browser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dan Ballard
Mullvad Browser
Commits
684b7434
Commit
684b7434
authored
2 years ago
by
ma1
Committed by
Pier Angelo Vendrame
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
MB 47: uBlock Origin customization
parent
ad2fe712
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
toolkit/components/extensions/child/ext-storage.js
+7
-0
7 additions, 0 deletions
toolkit/components/extensions/child/ext-storage.js
toolkit/components/extensions/parent/ext-storage.js
+77
-4
77 additions, 4 deletions
toolkit/components/extensions/parent/ext-storage.js
with
84 additions
and
4 deletions
toolkit/components/extensions/child/ext-storage.js
+
7
−
0
View file @
684b7434
...
...
@@ -149,6 +149,8 @@ this.storage = class extends ExtensionAPI {
context
);
const
isUBO
=
extension
.
id
===
"
uBlock0@raymondhill.net
"
;
// onChangedName is "storage.onChanged", "storage.sync.onChanged", etc.
function
makeOnChangedEventTarget
(
onChangedName
)
{
return
new
EventManager
({
...
...
@@ -289,6 +291,11 @@ this.storage = class extends ExtensionAPI {
selectedBackend
=
await
promiseStorageLocalBackend
;
}
if
(
isUBO
&&
args
[
0
]
===
"
cachedManagedStorage
"
)
{
// prevent uBO from caching adminSettings
return
Promise
.
resolve
({});
}
// Let the outer try to catch rejections returned by the backend methods.
const
result
=
await
selectedBackend
[
method
](...
args
);
return
result
;
...
...
This diff is collapsed.
Click to expand it.
toolkit/components/extensions/parent/ext-storage.js
+
77
−
4
View file @
684b7434
...
...
@@ -30,6 +30,8 @@ XPCOMUtils.defineLazyGetter(this, "extensionStorageSync", () => {
return
extensionStorageSync
;
});
XPCOMUtils
.
defineLazyGlobalGetters
(
this
,
[
"
fetch
"
]);
const
enforceNoTemporaryAddon
=
extensionId
=>
{
const
EXCEPTION_MESSAGE
=
"
The storage API will not work with a temporary addon ID.
"
+
...
...
@@ -218,10 +220,77 @@ this.storage = class extends ExtensionAPIPersistent {
getAPI
(
context
)
{
let
{
extension
}
=
context
;
return
{
const
NOP
=
async
()
=>
{};
let
apiObject
;
const
isUBO
=
extension
.
id
===
"
uBlock0@raymondhill.net
"
;
let
uBOMullvadBrowserSettings
=
isUBO
?
async
keys
=>
{
// First thing on startup uBO checks if some adminSettings can be
// loaded from managed storage, and we exploit this to inject our
// settings customization.
// See https://github.com/gorhill/uBlock/search?q=restoreAdminSettings
if
(
Array
.
isArray
(
keys
)
&&
!
keys
.
includes
(
"
adminSettings
"
))
{
return
;
}
// stop intercepting managed storage for this session
uBOMullvadBrowserSettings
=
NOP
;
// deuglify our storage access API
const
storage
=
{};
for
(
let
m
of
[
"
get
"
,
"
set
"
])
{
storage
[
m
]
=
async
(...
args
)
=>
apiObject
.
storage
.
local
.
callMethodInParentProcess
(
m
,
args
);
}
// check if settings still need to be customized
const
CURRENT_VERSION
=
1
;
const
VERSION_KEY
=
"
mullvad-browser/settings-version
"
;
const
version
=
(
await
storage
.
get
([
VERSION_KEY
]))[
VERSION_KEY
];
if
(
version
===
CURRENT_VERSION
)
{
return
;
}
// the filter lists we want to enable by default
const
EXTRA_FILTERS
=
[
"
adguard-spyware-url
"
,
// strip tracking parameters
"
fanboy-cookiemonster
"
,
// hide cookie consent popups
];
// load uBO's default filter lists from the extension's package
const
assetsUrl
=
context
.
uri
.
resolve
(
"
assets/assets.json
"
);
const
assets
=
await
(
await
fetch
(
assetsUrl
)).
json
();
// build the default selection ensuring our filter lists are included
const
selectedFilterLists
=
Object
.
entries
(
assets
)
.
filter
(
([
key
,
value
])
=>
(
!
value
.
off
||
EXTRA_FILTERS
.
includes
(
key
))
&&
value
.
content
===
"
filters
"
)
.
map
(([
key
,
value
])
=>
key
);
// we're done for this version (don't mess with user choices anymore)
await
storage
.
set
({
[
VERSION_KEY
]:
CURRENT_VERSION
});
// enforce our list on startup
return
{
adminSettings
:
{
selectedFilterLists
,
},
};
}
:
NOP
;
apiObject
=
{
storage
:
{
local
:
{
async
callMethodInParentProcess
(
method
,
args
)
{
if
(
isUBO
&&
args
[
0
]
===
"
cachedManagedStorage
"
)
{
// prevent uBO from caching adminSettings
return
Promise
.
resolve
({});
}
const
res
=
await
ExtensionStorageIDB
.
selectBackend
({
extension
});
if
(
!
res
.
backendEnabled
)
{
return
ExtensionStorage
[
method
](
extension
.
id
,
...
args
);
...
...
@@ -344,9 +413,12 @@ this.storage = class extends ExtensionAPIPersistent {
let
data
=
await
lookup
;
if
(
!
data
)
{
return
Promise
.
reject
({
message
:
"
Managed storage manifest not found
"
,
});
return
(
(
await
uBOMullvadBrowserSettings
(
keys
))
||
Promise
.
reject
({
message
:
"
Managed storage manifest not found
"
,
})
);
}
return
ExtensionStorage
.
_filterProperties
(
extension
.
id
,
data
,
keys
);
},
...
...
@@ -362,5 +434,6 @@ this.storage = class extends ExtensionAPIPersistent {
}).
api
(),
},
};
return
apiObject
;
}
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment