Commit 2c4aee05 authored by Huanzhong Huang's avatar Huanzhong Huang Committed by Commit Bot

Set an initial checked value of cookie controls toggle from setting

This to a great extent prevents the knob animation on every opening of
an incognito ntp.

Bug: 967668
Change-Id: Ib99ba020b419d8c9aed2c910049d2662a3850d4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1855962
Commit-Queue: Huanzhong Huang <huanzhong@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706340}
parent e87a59a6
...@@ -35,7 +35,8 @@ document.write('<link id="incognitothemecss" rel="stylesheet" ' + ...@@ -35,7 +35,8 @@ document.write('<link id="incognitothemecss" rel="stylesheet" ' +
<em>$i18n{cookieControlsTitle}</em> <em>$i18n{cookieControlsTitle}</em>
$i18n{cookieControlsDescription} $i18n{cookieControlsDescription}
</div> </div>
<cr-toggle id="cookie-controls-toggle" dark></cr-toggle> <cr-toggle id="cookie-controls-toggle"
$i18n{cookieControlsToggleChecked} dark></cr-toggle>
</div> </div>
<a class="learn-more-button" href="$i18n{learnMoreLink}">$i18n{learnMore}</a> <a class="learn-more-button" href="$i18n{learnMoreLink}">$i18n{learnMore}</a>
</div> </div>
......
...@@ -73,12 +73,13 @@ void CookieControlsHandler::HandleObserveCookieControlsSettingsChanges( ...@@ -73,12 +73,13 @@ void CookieControlsHandler::HandleObserveCookieControlsSettingsChanges(
void CookieControlsHandler::OnCookieControlsChanged() { void CookieControlsHandler::OnCookieControlsChanged() {
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
FireWebUIListener("cookie-controls-changed",
base::Value(GetToggleCheckedValue(profile)));
}
bool CookieControlsHandler::GetToggleCheckedValue(const Profile* profile) {
int mode = profile->GetPrefs()->GetInteger(prefs::kCookieControlsMode); int mode = profile->GetPrefs()->GetInteger(prefs::kCookieControlsMode);
base::Value checked( return mode != static_cast<int>(content_settings::CookieControlsMode::kOff);
mode == static_cast<int>(content_settings::CookieControlsMode::kOff)
? false
: true);
FireWebUIListener("cookie-controls-changed", checked);
} }
void CookieControlsHandler::OnThirdPartyCookieBlockingChanged() { void CookieControlsHandler::OnThirdPartyCookieBlockingChanged() {
......
...@@ -33,6 +33,8 @@ class CookieControlsHandler : public content::WebUIMessageHandler { ...@@ -33,6 +33,8 @@ class CookieControlsHandler : public content::WebUIMessageHandler {
// Whether cookie controls UI should be hidden in incognito ntp. // Whether cookie controls UI should be hidden in incognito ntp.
static bool ShouldHideCookieControlsUI(const Profile* profile); static bool ShouldHideCookieControlsUI(const Profile* profile);
static bool GetToggleCheckedValue(const Profile* profile);
private: private:
friend class CookieControlsHandlerTest; friend class CookieControlsHandlerTest;
......
...@@ -285,6 +285,8 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { ...@@ -285,6 +285,8 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() {
l10n_util::GetStringUTF8(IDS_SETTINGS_SITE_SETTINGS_THIRD_PARTY_COOKIE); l10n_util::GetStringUTF8(IDS_SETTINGS_SITE_SETTINGS_THIRD_PARTY_COOKIE);
replacements["cookieControlsDescription"] = replacements["cookieControlsDescription"] =
l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_COOKIE_CONTROLS_DESCRIPTION); l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_COOKIE_CONTROLS_DESCRIPTION);
replacements["cookieControlsToggleChecked"] =
CookieControlsHandler::GetToggleCheckedValue(profile_) ? "checked" : "";
const ui::ThemeProvider& tp = const ui::ThemeProvider& tp =
ThemeService::GetThemeProviderForProfile(profile_); ThemeService::GetThemeProviderForProfile(profile_);
......
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