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
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Applications
Mullvad Browser
Commits
491ce587
Verified
Commit
491ce587
authored
Mar 6, 2023
by
ma1
Committed by
Pier Angelo Vendrame
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
MB 47: uBlock Origin customization
parent
2c851df1
No related branches found
No related tags found
1 merge request
!146
MB 371: Rebased the future 14.0 release onto 128.4.0
Changes
2
Show 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 @
491ce587
...
...
@@ -137,6 +137,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
({
...
...
@@ -279,6 +281,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 @
491ce587
...
...
@@ -30,6 +30,8 @@ ChromeUtils.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
;
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
])
=>
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
({
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