-
Notifications
You must be signed in to change notification settings - Fork 900
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
Added checks on shields v2 related classes #12927
Conversation
@@ -215,6 +216,14 @@ void BraveShieldsActionView::OnTabStripModelChanged( | |||
TabStripModel* tab_strip_model, | |||
const TabStripModelChange& change, | |||
const TabStripSelectionChange& selection) { | |||
|
|||
if (change.type() == TabStripModelChange::kRemoved) { |
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 assume that this kRemoved
noti will be sent after we receive active tab changed for that tab first.
Can you check this?
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 noti will be like below?
- Closing non active tab - maybe
Removed
is only sent. - Closing active tab - maybe we get active tab changing noti. and then
kRemoved
will be arrived.
If so, I think handling kRemoved
is not needed here.
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.
The flow is as below:
- Non active tab: removed is only fired
- Active tab:
[27785:259:0406/172038.657028:ERROR:brave_shields_action_view.cc(221)] removed
[27785:259:0406/172038.668865:ERROR:brave_shields_action_view.cc(229)] active tab
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.
Ok, in that case selection.old_contents
is null or removed one?
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.
selection.old_contents
is the removed one. It's not null.
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.
If BraveShieldsActionView
is destroyed first before tab strip model handles all tabs active state while shutdown,
we should do call RemoveObserver
for current active tab in dtor.
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.
WillCloseAllTabs
is called first and then dtor of BraveShieldsActionView
- so, tab strip model handles all tabs first and then dtor gets called
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.
as discussed in DM this is an issue with the view closing before the active tab. We originally discussed doing this in the destructor and then I got off track and forgot about the original issue when we looked at the tab strip observer stuff. I think both changes are necessary.
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.
implemented the dtor based on our discussion in DM
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.
@simonhong I actually don't think it should be possible for the view to be destroyed before the webcontents because it's the button in the urlbar, but I think it's still best to add it to the dtor in case we're missing something in the tab strip observing
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.
How about adding more defence code?
and it seems you need to check the result of npm run lint
@@ -121,6 +121,8 @@ ShieldsPanelDataHandler::GetActiveShieldsDataController() { | |||
DCHECK(profile); | |||
|
|||
Browser* browser = chrome::FindLastActiveWithProfile(profile); | |||
if (!browser) return nullptr; |
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.
How about handling like below on all caller?
auto* shields_data_ctrlr = GetActiveShieldsDataController();
if (!shields_data_ctrlr)
return;
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.
@bridiver suggested to add a check on the browser
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.
do we really need a check on all callers if we're doing a check that can be caught in debug mode?
->HandleItemBlocked(block_type, subresource); | ||
#endif | ||
auto* shields_data_ctrlr = brave_shields::BraveShieldsDataController::FromWebContents(web_contents); | ||
DCHECK(shields_data_ctrlr); |
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.
ditto
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.
@bridiver wanted this DCHECK
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.
added the check
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.
@simonhong a WebContentsUserData should never be destroyed before the webcontents. The only time this could be null is if the webcontents is not associated with a tab, but that seems like it would be a bug in the networking code and hence the DCHECK here
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.
Ok, I was worried some WebContents that not associated with tab might be reached here.
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.
@bridiver btw, curious how networking code is tied with tab's webcontents. can you point out where it is?
e4e7112
to
46fc972
Compare
if (selection.active_tab_changed()) { | ||
if (selection.new_contents) { | ||
brave_shields::BraveShieldsDataController::FromWebContents( | ||
selection.new_contents) | ||
->AddObserver(this); | ||
active_web_contents_ = selection.new_contents->GetWeakPtr(); |
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.
if new_contents is null we should set active_web_contents_ = base::WeakPtr<WebContents>()
// and if that's true, the last registered web_contents won't unregister | ||
// itself. By keeping a cache of last active web contents we ensure to | ||
// unregister from this edge case. | ||
if (active_web_contents_) { |
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.
on second thought I think this should be DCHECK(!active_web_contents_)
since a toolbar button should outlive the webcontents in the tab strip
38cc5e1
to
e528181
Compare
e528181
to
4781eb5
Compare
@@ -121,6 +121,9 @@ ShieldsPanelDataHandler::GetActiveShieldsDataController() { | |||
DCHECK(profile); | |||
|
|||
Browser* browser = chrome::FindLastActiveWithProfile(profile); |
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'm wondering if it would be better / possible to get the Browser
that the webui_controller_
is already associated with via FindBrowserWithWebContents
but maybe that only works for WebContents on the TabStrip, and not bubbles. Although if we have access to the tab strip, perhaps we could provide it directly to the controller.
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.
solved here: #12984 - we get the right browser in ShieldsPanelUI as PanelHandler::CreatePanel is async and it might get the wrong browser
Resolves brave/brave-browser#22031
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: