-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscription list metadata #13421
Subscription list metadata #13421
Conversation
@nullhook - added you as a reviewer since this is relevant to the brave://adblock UI refresh (#12827). The new JS interface should be self-explanatory from the changes in @rillian - added you as a reviewer for changes to the Rust FFI. Sadly we don't use |
A Storybook has been deployed to preview UI for the latest push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach is good. Some comments and questions below.
BTW, the bug mentions exposing the version but this pr only adds title and homepage fields.
include_guard = "ADBLOCK_RUST_FFI_H" | ||
include_guard = "BRAVE_COMPONENTS_ADBLOCK_RUST_FFI_SRC_LIB_H_" | ||
|
||
header = "/* Copyright (c) 2019 The Brave Authors. All rights reserved.\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this file,\n * You can obtain one at http://mozilla.org/MPL/2.0/. */" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better as a multi-line string. e.g.
header = """\
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is ...
*/"""
Might as well use the current copyright year as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the policy is not to update the year on copyright headers, but the multi-line string is a good idea.
/** | ||
* Create a new `Engine`. | ||
*/ | ||
struct C_Engine* engine_create(const char* rules); | ||
struct C_Engine* engine_create_from_buffer(const char* data, size_t data_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be merged with the new "Create a new Engine
" section immediately below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is autogenerated by cbindgen
; those comments are taken directly from the doc comments in lib.rs
. I can try to make them a little more useful at least.
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn engine_create_with_metadata(rules: *const c_char, metadata: *mut *mut FilterListMetadata) -> *mut Engine { | ||
let rules = CStr::from_ptr(rules).to_str().unwrap_or(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the functions use unwrap_or_else(|_| { eprinln!(); ""}
to log something about the utf-8 validation failure. Seems like a good idea; is there a reason not to do it everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just failure to read the docs and connect the two cases together 😅
#[no_mangle] | ||
pub unsafe extern "C" fn filter_list_metadata_homepage(metadata: *const FilterListMetadata, homepage: *mut *mut c_char) -> bool { | ||
if let Some(this_homepage) = (*metadata).homepage.as_ref() { | ||
*homepage = CString::new(this_homepage.as_str()).expect("Error: CString::new()").into_raw(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect
aborts here if the input contains a null byte. I assume this String comes from the adblock filter list; is that something we consider sufficiently "under our control" that failing fast is appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! The lists may come from third-parties in the case of custom subscriptions. The list contents are passed in from C++, which I think handles the early null bytes to begin with. I can double-check on that.
But, either way, expect
is probably not the best choice here.
data_size: size_t, | ||
metadata: *mut *mut FilterListMetadata, | ||
) -> *mut Engine { | ||
let data: &[u8] = std::slice::from_raw_parts(data as *const u8, data_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally include an early return if data.is_null()
or if data_size
exceeds some reasonable maximum. There's not much to be done about invalid pointers, but I think it's good defensive programming.
That's obviously not directly related to this patch. Just a suggestion for the implementation in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's address this with the cxx
port; it's already equally valid in the previous code and there's currently no handling for not returning an engine pointer from these functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me, although you could return a ptr::null_mut
and check for that on the other side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I'd also like to see if we can get rid of the out param, but waiting for cxx is fine
@@ -5,8 +5,12 @@ | |||
|
|||
#ifndef BRAVE_COMPONENTS_ADBLOCK_RUST_FFI_SRC_WRAPPER_H_ | |||
#define BRAVE_COMPONENTS_ADBLOCK_RUST_FFI_SRC_WRAPPER_H_ | |||
|
|||
#include <optional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this sorted with the other libstd headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had them grouped together and then sorted as per clang-format
, but lint
was complaining about the order of C vs. C++ headers being wrong. This was the only way I found to satisfy both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! This is something like a linter bug, since <optional>
is definitely a C++ header.
However, std::optional is still banned in chromium code, based on hardening concerns. Best to replace this with absl::optional, and then the include order will make sense. 🙃
a6958c3
to
dbfacbf
Compare
@rillian good catch, but yep, that's intended. The version field is supposed to be a numeric string according to the "official" ABP documentation, but I've seen several examples in the wild of lists using semantic versioning or even full human readable dates in the version string. I also haven't seen any adblockers actually using the version code for anything, even exposing it in the UI. If there's a request for it that makes sense we can add it in pretty easily, but I don't see any good reason to add it for now. |
dbfacbf
to
1ccc97b
Compare
A Storybook has been deployed to preview UI for the latest push |
266ed7a
to
554bc52
Compare
A Storybook has been deployed to preview UI for the latest push |
A Storybook has been deployed to preview UI for the latest push |
7509127
to
73a3e44
Compare
|
||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
|
||
auto info = GetInfo(sub_url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you are calling GetInfo on more than one thread now. Please add a thread check to it
components/brave_shields/browser/ad_block_subscription_service_manager.cc
Show resolved
Hide resolved
A Storybook has been deployed to preview UI for the latest push |
73a3e44
to
8ce904f
Compare
8ce904f
to
ecbd1ed
Compare
A Storybook has been deployed to preview UI for the latest push |
A Storybook has been deployed to preview UI for the latest push |
Windows CI failures unrelated |
Resolves brave/brave-browser#17910
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Find a subscription list of your choice
Visit https://filterlists.com and use the filter icon on the
Syntaxes
column to selectAdblock Plus
lists. Click on the blue(i)
icon at the left of an entry of your choice, then click theView
button in the info panel. Look for a list that has a! Title: ...
and/or! Homepage: ...
comment near the top.Subscribe to the list
Copy the URL of the list text from the previous step, then visit brave://adblock and create a new list subscription using that URL (
Add filter list via URL
button).Verify updated state
Once the list has been downloaded, visit brave://local-state and identify the entry for the new subscription (under
brave
->ad_block
->list_subscriptions
). It should havetitle
andhomepage
fields that match the ones you previously saw in the list text.