Commit b60fcce6 authored by elawrence's avatar elawrence Committed by Commit bot

Disable Open in Incognito menu item for urls disallowed in Incognito

Some URLs are not permitted to load in Incognito mode, instead opening back in the regular browser window, making the "Open Link in Incognito Window" context menu link misleading.

To address this, disable the menu command for links that are disallowed in Incognito mode.

BUG=682163

Review-Url: https://codereview.chromium.org/2850153002
Cr-Commit-Position: refs/heads/master@{#468958}
parent d23690e9
...@@ -2116,6 +2116,9 @@ bool RenderViewContextMenu::IsOpenLinkOTREnabled() const { ...@@ -2116,6 +2116,9 @@ bool RenderViewContextMenu::IsOpenLinkOTREnabled() const {
if (browser_context_->IsOffTheRecord() || !params_.link_url.is_valid()) if (browser_context_->IsOffTheRecord() || !params_.link_url.is_valid())
return false; return false;
if (!chrome::IsURLAllowedInIncognito(params_.link_url, browser_context_))
return false;
IncognitoModePrefs::Availability incognito_avail = IncognitoModePrefs::Availability incognito_avail =
IncognitoModePrefs::GetAvailability(GetPrefs(browser_context_)); IncognitoModePrefs::GetAvailability(GetPrefs(browser_context_));
return incognito_avail != IncognitoModePrefs::DISABLED; return incognito_avail != IncognitoModePrefs::DISABLED;
......
...@@ -380,6 +380,18 @@ class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness { ...@@ -380,6 +380,18 @@ class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness {
return ::CreateContextMenu(web_contents(), registry_.get()); return ::CreateContextMenu(web_contents(), registry_.get());
} }
// Returns a test context menu for a chrome:// url not permitted to open in
// incognito mode.
std::unique_ptr<TestRenderViewContextMenu> CreateContextMenuOnChromeLink() {
content::ContextMenuParams params = CreateParams(MenuItem::LINK);
params.unfiltered_link_url = params.link_url = GURL("chrome://settings");
std::unique_ptr<TestRenderViewContextMenu> menu(
new TestRenderViewContextMenu(web_contents()->GetMainFrame(), params));
menu->set_protocol_handler_registry(registry_.get());
menu->Init();
return menu;
}
void AppendImageItems(TestRenderViewContextMenu* menu) { void AppendImageItems(TestRenderViewContextMenu* menu) {
menu->AppendImageItems(); menu->AppendImageItems();
} }
...@@ -455,6 +467,17 @@ TEST_F(RenderViewContextMenuPrefsTest, ...@@ -455,6 +467,17 @@ TEST_F(RenderViewContextMenuPrefsTest,
menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD));
} }
// Verifies Incognito Mode is not enabled for links disallowed in Incognito.
TEST_F(RenderViewContextMenuPrefsTest,
DisableOpenInIncognitoWindowForDisallowedUrls) {
std::unique_ptr<TestRenderViewContextMenu> menu(
CreateContextMenuOnChromeLink());
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD));
EXPECT_FALSE(
menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD));
}
// Make sure the checking custom command id that is not enabled will not // Make sure the checking custom command id that is not enabled will not
// cause DCHECK failure. // cause DCHECK failure.
TEST_F(RenderViewContextMenuPrefsTest, TEST_F(RenderViewContextMenuPrefsTest,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment