Skip to content

Commit

Permalink
[MERGE] Link app menu managed UI to Family Link page
Browse files Browse the repository at this point in the history
For supervised users on a device which is not enterprise-managed, link
to the Family Link web page (instead of chrome://management) in the
app menu item.

Sending for early review ahead of adding test coverage.

(cherry picked from commit 0511fd2)

Bug: b/281641773, 1449228
Change-Id: Ia23d13cb5934de5d95dd6f96c4130c0a419d77e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4545254
Auto-Submit: James Lee <ljjlee@google.com>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: James Lee <ljjlee@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1149613}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4574445
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/branch-heads/5790@{#177}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
James Lee authored and Chromium LUCI CQ committed May 31, 2023
1 parent 03825f4 commit b2f11d1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chrome/browser/ui/browser_command_controller.cc
Expand Up @@ -38,6 +38,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/commander/commander.h"
#include "chrome/browser/ui/managed_ui.h"
#include "chrome/browser/ui/page_info/page_info_dialog.h"
#include "chrome/browser/ui/passwords/ui_utils.h"
#include "chrome/browser/ui/side_panel/side_panel_entry_id.h"
Expand Down Expand Up @@ -950,7 +951,7 @@ bool BrowserCommandController::ExecuteCommandWithDisposition(
CloseOtherTabs(browser_);
break;
case IDC_SHOW_MANAGEMENT_PAGE: {
ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
ShowSingletonTab(browser_, GetManagedUiMenuLinkUrl(profile()));
break;
}
case IDC_MUTE_TARGET_SITE:
Expand Down
17 changes: 17 additions & 0 deletions chrome/browser/ui/managed_ui.cc
Expand Up @@ -19,6 +19,7 @@
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/webui/management/management_ui_handler.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/policy/core/browser/webui/policy_data_utils.h"
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_manager.h"
Expand All @@ -30,6 +31,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/vector_icon_types.h"
#include "url/gurl.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/login/demo_mode/demo_session.h"
Expand Down Expand Up @@ -166,6 +168,21 @@ std::u16string GetManagedUiMenuItemLabel(Profile* profile) {
return l10n_util::GetStringUTF16(IDS_MANAGED_BY_PARENT);
}

GURL GetManagedUiMenuLinkUrl(Profile* profile) {
CHECK(ShouldDisplayManagedUi(profile));

if (enterprise_util::IsBrowserManaged(profile)) {
return GURL(kChromeUIManagementURL);
}

CHECK(ShouldDisplayManagedByParentUi(profile));
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
return GURL(supervised_user::kManagedByParentUiMoreInfoUrl.Get());
#else
NOTREACHED_NORETURN();
#endif
}

std::string GetManagedUiWebUIIcon(Profile* profile) {
if (enterprise_util::IsBrowserManaged(profile)) {
return "cr:domain";
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/ui/managed_ui.h
Expand Up @@ -11,6 +11,7 @@
#include "build/chromeos_buildflags.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

class GURL;
class Profile;

namespace gfx {
Expand Down Expand Up @@ -43,6 +44,11 @@ const gfx::VectorIcon& GetManagedUiIcon(Profile* profile);
// Must only be called if ShouldDisplayManagedUi(profile) is true.
std::u16string GetManagedUiMenuItemLabel(Profile* profile);

// The URL which the Managed UI in the app menu links to.
//
// Must only be called if ShouldDisplayManagedUi(profile) is true.
GURL GetManagedUiMenuLinkUrl(Profile* profile);

// An icon name/label recognized by <iron-icon> for the WebUI footnote for
// Managed UI indicating that the browser is managed.
//
Expand Down
40 changes: 40 additions & 0 deletions chrome/browser/ui/managed_ui_browsertest.cc
Expand Up @@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/managed_ui.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
Expand Down Expand Up @@ -170,6 +171,45 @@ IN_PROC_BROWSER_TEST_P(ManagedUiTest, GetManagedUiIconSupervised) {
chrome::GetManagedUiIcon(profile.get()).name);
}

IN_PROC_BROWSER_TEST_P(ManagedUiTest, GetManagedUiMenuLinkUrlEnterprise) {
// Simulate a managed device.
AddEnterpriseManagedPolicies();
policy::ScopedManagementServiceOverrideForTesting browser_management(
policy::ManagementServiceFactory::GetForProfile(browser()->profile()),
policy::EnterpriseManagementAuthority::CLOUD);

// An un-supervised profile.
TestingProfile::Builder builder;
auto profile = builder.Build();

// Simulate a supervised profile.
TestingProfile::Builder builder_supervised;
builder_supervised.SetIsSupervisedProfile();
std::unique_ptr<TestingProfile> profile_supervised =
builder_supervised.Build();

EXPECT_EQ(GURL(chrome::kChromeUIManagementURL),
chrome::GetManagedUiMenuLinkUrl(profile.get()));
// Enterprise management takes precedence over supervision in the management
// UI.
EXPECT_EQ(GURL(chrome::kChromeUIManagementURL),
chrome::GetManagedUiMenuLinkUrl(profile_supervised.get()));
}

IN_PROC_BROWSER_TEST_P(ManagedUiTest, GetManagedUiMenuLinkUrlSupervised) {
if (!IsManagedUiEnabledForSupervisedUsers()) {
return;
}

// Simulate a supervised profile.
TestingProfile::Builder builder;
builder.SetIsSupervisedProfile();
std::unique_ptr<TestingProfile> profile = builder.Build();

EXPECT_EQ(GURL(supervised_user::kManagedByParentUiMoreInfoUrl.Get()),
chrome::GetManagedUiMenuLinkUrl(profile.get()));
}

IN_PROC_BROWSER_TEST_P(ManagedUiTest, GetManagedUiMenuItemLabelEnterprise) {
// Simulate a managed profile.
AddEnterpriseManagedPolicies();
Expand Down

0 comments on commit b2f11d1

Please sign in to comment.