Commit 85e8fd9e authored by Alex Ilin's avatar Alex Ilin Committed by Chromium LUCI CQ

[signin] Force light mode in the reauth dialog

To force the light mode on the Reauth confirmation screen, we override
the preferred_color_scheme web preference in SigninReauthViewController.
However, a web preference overridden via WebContents::SetWebPreferences
doesn't survive a recomputation of WebPreferences. This means that the
preferred_color_scheme returns back to its default value.

The comment to the SetWebPreferences method suggests to put the
recomputation logic in ChromeContentBrowserClient. This CL does exactly
that.

This CL also adds a browser test to verify the behavior and catch
possible regressions.

Bug: 1153368
Change-Id: I8697e13095ba58d120f6ce61352caa32a982be0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2565684
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832324}
parent 2018771d
...@@ -2984,21 +2984,26 @@ bool UpdatePreferredColorScheme(WebPreferences* web_prefs, ...@@ -2984,21 +2984,26 @@ bool UpdatePreferredColorScheme(WebPreferences* web_prefs,
ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme()); ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
bool force_light = false;
// Force a light preferred color scheme on certain URLs if kWebUIDarkMode is // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
// disabled; some of the UI is not yet correctly themed. // disabled; some of the UI is not yet correctly themed.
if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) { if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
// Update based on last committed url. // Update based on last committed url.
bool force_light = url.SchemeIs(content::kChromeUIScheme); force_light |= url.SchemeIs(content::kChromeUIScheme);
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
if (!force_light) { force_light |= url.SchemeIs(extensions::kExtensionScheme) &&
force_light = url.SchemeIs(extensions::kExtensionScheme) && url.host_piece() == extension_misc::kPdfExtensionId;
url.host_piece() == extension_misc::kPdfExtensionId;
}
#endif #endif
if (force_light) { }
web_prefs->preferred_color_scheme =
blink::mojom::PreferredColorScheme::kLight; // Reauth WebUI doesn't support dark mode yet because it shares the dialog
} // with GAIA web contents that is not correctly themed.
force_light |= url.SchemeIs(content::kChromeUIScheme) &&
url.host_piece() == chrome::kChromeUISigninReauthHost;
if (force_light) {
web_prefs->preferred_color_scheme =
blink::mojom::PreferredColorScheme::kLight;
} }
return old_preferred_color_scheme != web_prefs->preferred_color_scheme; return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom.h"
namespace { namespace {
...@@ -311,15 +309,10 @@ void SigninReauthViewController::ShowReauthConfirmationDialog() { ...@@ -311,15 +309,10 @@ void SigninReauthViewController::ShowReauthConfirmationDialog() {
browser_, account_id_, access_point_); browser_, account_id_, access_point_);
dialog_delegate_observer_.Add(dialog_delegate_); dialog_delegate_observer_.Add(dialog_delegate_);
// Gaia Reauth page doesn't support dark mode. Force the confirmation dialog SigninReauthUI* web_dialog_ui = dialog_delegate_->GetWebContents()
// to use the light mode as well to match the style. ->GetWebUI()
auto* web_contents = dialog_delegate_->GetWebContents(); ->GetController()
auto prefs = web_contents->GetOrCreateWebPreferences(); ->GetAs<SigninReauthUI>();
prefs.preferred_color_scheme = blink::mojom::PreferredColorScheme::kLight;
web_contents->SetWebPreferences(prefs);
SigninReauthUI* web_dialog_ui =
web_contents->GetWebUI()->GetController()->GetAs<SigninReauthUI>();
web_dialog_ui->InitializeMessageHandlerWithReauthController(this); web_dialog_ui->InitializeMessageHandlerWithReauthController(this);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/test/bind.h" #include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/reauth_result.h" #include "chrome/browser/signin/reauth_result.h"
#include "chrome/browser/signin/signin_features.h" #include "chrome/browser/signin/signin_features.h"
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
#include "chrome/browser/ui/signin_reauth_view_controller.h" #include "chrome/browser/ui/signin_reauth_view_controller.h"
#include "chrome/browser/ui/signin_view_controller.h" #include "chrome/browser/ui/signin_view_controller.h"
#include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/signin/public/base/signin_metrics.h" #include "components/signin/public/base/signin_metrics.h"
...@@ -38,6 +40,7 @@ ...@@ -38,6 +40,7 @@
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h" #include "net/test/embedded_test_server/request_handler_util.h"
#include "ui/base/ui_base_switches.h"
using ::testing::ElementsAre; using ::testing::ElementsAre;
...@@ -541,3 +544,39 @@ IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest, ...@@ -541,3 +544,39 @@ IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
browser(), kReauthDialogTimeout)); browser(), kReauthDialogTimeout));
EXPECT_EQ(WaitForReauthResult(), signin::ReauthResult::kUnexpectedResponse); EXPECT_EQ(WaitForReauthResult(), signin::ReauthResult::kUnexpectedResponse);
} }
class SigninReauthViewControllerDarkModeBrowserTest
: public SigninReauthViewControllerBrowserTest {
public:
SigninReauthViewControllerDarkModeBrowserTest() {
scoped_feature_list_.InitAndEnableFeature(features::kWebUIDarkMode);
}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kForceDarkMode);
SigninReauthViewControllerBrowserTest::SetUpCommandLine(command_line);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Tests the light mode is enforced for the reauth confirmation dialog even if
// the dark mode is enabled.
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerDarkModeBrowserTest,
ConfirmationDialogDarkModeDisabled) {
ShowReauthPrompt();
content::WebContents* confirmation_dialog_contents =
signin_reauth_view_controller()->GetWebContents();
content::TestNavigationObserver navigation_observer(
confirmation_dialog_contents);
navigation_observer.WaitForNavigationFinished();
bool prefers_dark_mode = true;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
confirmation_dialog_contents,
"window.domAutomationController.send("
"window.matchMedia('(prefers-color-scheme: dark)').matches)",
&prefers_dark_mode));
EXPECT_EQ(prefers_dark_mode, false);
}
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