Commit 16a1e303 authored by Xiqi Ruan's avatar Xiqi Ruan Committed by Commit Bot

cros: Block save-link-as when the URL isn't accessible by child account

Disable save-link-as when the target site is not allow for child user
when parent use Family Link App to set up "Allow only certain sites" for
filters on Google Chrome by Family Link app.

Bug: 1095762
Change-Id: I61290ef8eb2da4b8093e5fc9984f02a741d8b4fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335450Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarYilkal Abe <yilkal@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Xiqi Ruan <xiqiruan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796630}
parent 629d515b
...@@ -198,6 +198,12 @@ ...@@ -198,6 +198,12 @@
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
#endif // BUILDFLAG(ENABLE_PRINTING) #endif // BUILDFLAG(ENABLE_PRINTING)
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -2550,6 +2556,18 @@ bool RenderViewContextMenu::IsSaveLinkAsEnabled() const { ...@@ -2550,6 +2556,18 @@ bool RenderViewContextMenu::IsSaveLinkAsEnabled() const {
return false; return false;
} }
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
Profile* const profile = Profile::FromBrowserContext(browser_context_);
if (profile->IsChild()) {
SupervisedUserService* supervised_user_service =
SupervisedUserServiceFactory::GetForProfile(profile);
SupervisedUserURLFilter* url_filter = supervised_user_service->GetURLFilter();
if (url_filter->GetFilteringBehaviorForURL(params_.link_url) !=
SupervisedUserURLFilter::FilteringBehavior::ALLOW)
return false;
}
#endif
return params_.link_url.is_valid() && return params_.link_url.is_valid() &&
ProfileIOData::IsHandledProtocol(params_.link_url.scheme()); ProfileIOData::IsHandledProtocol(params_.link_url.scheme());
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "chrome/browser/web_applications/components/web_app_provider_base.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_render_frame.mojom.h" #include "chrome/common/chrome_render_frame.mojom.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -93,6 +94,13 @@ ...@@ -93,6 +94,13 @@
#include "ui/gfx/codec/jpeg_codec.h" #include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/supervised_user/supervised_user_url_filter.h"
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "ash/public/cpp/window_pin_type.h" #include "ash/public/cpp/window_pin_type.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
...@@ -388,6 +396,34 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -388,6 +396,34 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SAVELINKAS)); EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SAVELINKAS));
} }
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
SaveLinkAsEntryIsDisabledForUrlsNotAccessibleForChild) {
// Set up child user profile.
Profile* profile = browser()->profile();
browser()->profile()->GetPrefs()->SetString(
prefs::kSupervisedUserId, supervised_users::kChildAccountSUID);
// Block access to http://www.google.com/ in the URL filter.
SupervisedUserService* supervised_user_service =
SupervisedUserServiceFactory::GetForProfile(profile);
SupervisedUserURLFilter* url_filter = supervised_user_service->GetURLFilter();
std::map<std::string, bool> hosts;
hosts["www.google.com"] = false;
url_filter->SetManualHosts(std::move(hosts));
base::RunLoop().RunUntilIdle();
std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNone(GURL("http://www.google.com/"),
GURL("http://www.google.com/"));
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_SAVELINKAS));
EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SAVELINKAS));
}
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
ContextMenuEntriesAreDisabledInLockedFullscreen) { ContextMenuEntriesAreDisabledInLockedFullscreen) {
......
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