Skip to content

Commit

Permalink
Content picker follow up (#25956)
Browse files Browse the repository at this point in the history
* Disable the menu item when Shields are down
* Prevent picker re-entrancy
* Update the tests
  • Loading branch information
atuchin-m authored Oct 15, 2024
1 parent b04bb97 commit 4443309
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions browser/brave_shields/ad_block_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,18 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, ContentPicker) {
ASSERT_TRUE(content::WaitForLoadStop(web_contents()));
EXPECT_EQ(web_contents()->GetLastCommittedURL(),
"chrome://settings/shields/filters");

ShieldsDown(tab_url);
NavigateToURL(tab_url);
{
content::ContextMenuParams params;
params.page_url = tab_url;
TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
params);
menu.Init();
// No menu item if Shields are down.
EXPECT_FALSE(menu.IsItemEnabled(IDC_ADBLOCK_CONTEXT_BLOCK_ELEMENTS));
}
}
#endif // !BUILDFLAG(IS_ANDROID)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,9 @@ void BraveRenderViewContextMenu::AppendDeveloperItems() {
auto* shields_tab_helper =
brave_shields::BraveShieldsTabHelper::FromWebContents(
source_web_contents_);
bool add_block_elements =
shields_tab_helper && shields_tab_helper->GetAdBlockMode() !=
bool add_block_elements = shields_tab_helper &&
shields_tab_helper->GetBraveShieldsEnabled() &&
shields_tab_helper->GetAdBlockMode() !=
brave_shields::mojom::AdBlockMode::ALLOW;
#if BUILDFLAG(IS_ANDROID)
// Content picker doesn't available for Android.
Expand Down
5 changes: 4 additions & 1 deletion components/cosmetic_filters/resources/data/element_picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,7 @@ const highlightElements = (coords: TargetRect[]) => {
}
}

launchElementPicker(attachElementPicker())
const active = document.getElementById('brave-element-picker')
if (!active) {
launchElementPicker(attachElementPicker())
}

0 comments on commit 4443309

Please sign in to comment.