Commit 8519ac7c authored by yilkal's avatar yilkal Committed by Commit Bot

Update blocking page title.

This Cl ensures that the blocking page title is the same as
the previous page title if the previous page title has been set.

Bug: 1061626
Change-Id: Ia9f813323b09d42aa5c2c12b139aabadea589ba1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142136
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758540}
parent 954515f6
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/child_accounts/time_limits/app_time_limits_whitelist_policy_test_utils.h" #include "chrome/browser/chromeos/child_accounts/time_limits/app_time_limits_whitelist_policy_test_utils.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h" #include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_enforcer.h" #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_enforcer.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_navigation_observer.h"
#include "chrome/browser/chromeos/login/test/scoped_policy_update.h" #include "chrome/browser/chromeos/login/test/scoped_policy_update.h"
#include "chrome/browser/chromeos/login/test/user_policy_mixin.h" #include "chrome/browser/chromeos/login/test/user_policy_mixin.h"
#include "chrome/browser/chromeos/policy/user_policy_test_helper.h" #include "chrome/browser/chromeos/policy/user_policy_test_helper.h"
...@@ -413,5 +414,27 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest, ...@@ -413,5 +414,27 @@ IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest,
EXPECT_TRUE(IsErrorPageBeingShownInWebContents(web_contents3)); EXPECT_TRUE(IsErrorPageBeingShownInWebContents(web_contents3));
} }
IN_PROC_BROWSER_TEST_F(WebTimeLimitEnforcerThrottleTest, WebContentTitleSet) {
GURL url = embedded_test_server()->GetURL(kExampleHost,
"/supervised_user/simple.html");
NavigateParams params(browser(), url,
ui::PageTransition::PAGE_TRANSITION_LINK);
// Navigates and waits for loading to finish.
ui_test_utils::NavigateToURL(&params);
auto* web_contents = params.navigated_or_inserted_contents;
auto* navigation_observer =
chromeos::app_time::WebTimeNavigationObserver::FromWebContents(
web_contents);
base::string16 title = web_contents->GetTitle();
EXPECT_EQ(title, navigation_observer->previous_title());
LoadFinishedWaiter waiter(web_contents, url);
BlockWeb();
waiter.Wait();
EXPECT_TRUE(IsErrorPageBeingShownInWebContents(web_contents));
EXPECT_EQ(web_contents->GetTitle(), title);
}
// TODO(yilkal): Add WhitelistedSchemeNotBlocked test for chrome://settings // TODO(yilkal): Add WhitelistedSchemeNotBlocked test for chrome://settings
// TODO(yilkal): Add test for blocked web contents without browser window. // TODO(yilkal): Add test for blocked web contents without browser window.
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_error_page/web_time_limit_error_page.h" #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_error_page/web_time_limit_error_page.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/string_piece_forward.h" #include "base/strings/string_piece_forward.h"
...@@ -29,15 +28,22 @@ base::string16 GetTimeLimitMessage(base::TimeDelta time_limit) { ...@@ -29,15 +28,22 @@ base::string16 GetTimeLimitMessage(base::TimeDelta time_limit) {
/* cutoff */ 3, time_limit); /* cutoff */ 3, time_limit);
} }
std::string GetWebTimeLimitErrorPage(base::string16 block_header, std::string GetWebTimeLimitErrorPage(
base::string16 block_message, base::string16 block_header,
base::TimeDelta time_limit, base::string16 block_message,
const std::string& app_locale) { base::TimeDelta time_limit,
const std::string& app_locale,
const base::Optional<base::string16>& title) {
base::DictionaryValue strings; base::DictionaryValue strings;
strings.SetString("blockPageTitle",
l10n_util::GetStringFUTF16( if (!title.has_value()) {
IDS_WEB_TIME_LIMIT_ERROR_PAGE_TITLE, strings.SetString("blockPageTitle",
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); l10n_util::GetStringFUTF16(
IDS_WEB_TIME_LIMIT_ERROR_PAGE_TITLE,
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
} else {
strings.SetString("blockPageTitle", title.value());
}
strings.SetString("blockPageHeader", block_header); strings.SetString("blockPageHeader", block_header);
strings.SetString( strings.SetString(
...@@ -58,9 +64,11 @@ std::string GetWebTimeLimitErrorPage(base::string16 block_header, ...@@ -58,9 +64,11 @@ std::string GetWebTimeLimitErrorPage(base::string16 block_header,
} // namespace } // namespace
std::string GetWebTimeLimitChromeErrorPage(const std::string& domain, std::string GetWebTimeLimitChromeErrorPage(
base::TimeDelta time_limit, const std::string& domain,
const std::string& app_locale) { const base::Optional<base::string16>& title,
base::TimeDelta time_limit,
const std::string& app_locale) {
auto block_header = l10n_util::GetStringFUTF16( auto block_header = l10n_util::GetStringFUTF16(
IDS_WEB_TIME_LIMIT_ERROR_PAGE_CHROME_HEADER, base::UTF8ToUTF16(domain)); IDS_WEB_TIME_LIMIT_ERROR_PAGE_CHROME_HEADER, base::UTF8ToUTF16(domain));
...@@ -69,20 +77,20 @@ std::string GetWebTimeLimitChromeErrorPage(const std::string& domain, ...@@ -69,20 +77,20 @@ std::string GetWebTimeLimitChromeErrorPage(const std::string& domain,
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
return GetWebTimeLimitErrorPage(block_header, block_message, time_limit, return GetWebTimeLimitErrorPage(block_header, block_message, time_limit,
app_locale); app_locale, title);
} }
std::string GetWebTimeLimitAppErrorPage(base::TimeDelta time_limit, std::string GetWebTimeLimitAppErrorPage(base::TimeDelta time_limit,
const std::string& app_locale, const std::string& app_locale,
const std::string& app_name) { const std::string& app_name) {
auto block_header = auto block_header = l10n_util::GetStringFUTF16(
l10n_util::GetStringFUTF16(IDS_WEB_TIME_LIMIT_ERROR_PAGE_APP_HEADER, IDS_WEB_TIME_LIMIT_ERROR_PAGE_APP_HEADER,
UTF8ToUTF16(base::StringPiece(app_name))); base::UTF8ToUTF16(base::StringPiece(app_name)));
auto block_message = l10n_util::GetStringFUTF16( auto block_message = l10n_util::GetStringFUTF16(
IDS_WEB_TIME_LIMIT_ERROR_PAGE_APP_MESSAGE, IDS_WEB_TIME_LIMIT_ERROR_PAGE_APP_MESSAGE,
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
return GetWebTimeLimitErrorPage(block_header, block_message, time_limit, return GetWebTimeLimitErrorPage(block_header, block_message, time_limit,
app_locale); app_locale, base::UTF8ToUTF16(app_name));
} }
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_TIME_LIMITS_WEB_TIME_LIMIT_ERROR_PAGE_WEB_TIME_LIMIT_ERROR_PAGE_H_ #define CHROME_BROWSER_CHROMEOS_CHILD_ACCOUNTS_TIME_LIMITS_WEB_TIME_LIMIT_ERROR_PAGE_WEB_TIME_LIMIT_ERROR_PAGE_H_
#include <string> #include <string>
#include "base/optional.h"
#include "base/strings/string16.h"
namespace base { namespace base {
...@@ -14,12 +16,17 @@ class TimeDelta; ...@@ -14,12 +16,17 @@ class TimeDelta;
} // namespace base } // namespace base
// Generates the appropriate time limit error page for Chrome. // Generates the appropriate time limit error page for Chrome.
// |domain| is the domain of the website that is being paused.
// |title| title is the title of the webcontents before it got paused. If there
// was no title set for the webcontents, the title will be "Chrome got paused".
// |time_limit| is used to specify the amount of time the user can use Chrome // |time_limit| is used to specify the amount of time the user can use Chrome
// and PWAs the following day. // and PWAs the following day.
// |app_locale| is used to specify the locale used by the browser. // |app_locale| is used to specify the locale used by the browser.
std::string GetWebTimeLimitChromeErrorPage(const std::string& domain, std::string GetWebTimeLimitChromeErrorPage(
base::TimeDelta time_limit, const std::string& domain,
const std::string& app_locale); const base::Optional<base::string16>& title,
base::TimeDelta time_limit,
const std::string& app_locale);
// Generates the appropriate time limit error page for PWAs. // Generates the appropriate time limit error page for PWAs.
std::string GetWebTimeLimitAppErrorPage(base::TimeDelta time_limit, std::string GetWebTimeLimitAppErrorPage(base::TimeDelta time_limit,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h" #include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_enforcer.h" #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_enforcer.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_error_page/web_time_limit_error_page.h" #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_error_page/web_time_limit_error_page.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_navigation_observer.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
...@@ -179,9 +180,15 @@ ThrottleCheckResult WebTimeLimitNavigationThrottle::WillStartOrRedirectRequest( ...@@ -179,9 +180,15 @@ ThrottleCheckResult WebTimeLimitNavigationThrottle::WillStartOrRedirectRequest(
if (domain.empty()) if (domain.empty())
domain = url.has_host() ? url.host() : url.spec(); domain = url.has_host() ? url.host() : url.spec();
app_time::WebTimeNavigationObserver* observer =
app_time::WebTimeNavigationObserver::FromWebContents(web_contents);
const base::Optional<base::string16>& prev_title =
observer ? observer->previous_title() : base::nullopt;
return NavigationThrottle::ThrottleCheckResult( return NavigationThrottle::ThrottleCheckResult(
CANCEL, net::ERR_BLOCKED_BY_CLIENT, CANCEL, net::ERR_BLOCKED_BY_CLIENT,
GetWebTimeLimitChromeErrorPage(domain, time_limit, app_locale)); GetWebTimeLimitChromeErrorPage(domain, prev_title, time_limit,
app_locale));
} }
// Don't throttle windowed applications. We show a notification and close // Don't throttle windowed applications. We show a notification and close
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/chromeos/child_accounts/time_limits/app_time_controller.h" #include "chrome/browser/chromeos/child_accounts/time_limits/app_time_controller.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_enforcer.h" #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_enforcer.h"
#include "chrome/browser/web_applications/components/web_app_tab_helper_base.h" #include "chrome/browser/web_applications/components/web_app_tab_helper_base.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -72,6 +73,10 @@ void WebTimeNavigationObserver::WebContentsDestroyed() { ...@@ -72,6 +73,10 @@ void WebTimeNavigationObserver::WebContentsDestroyed() {
listener.WebTimeNavigationObserverDestroyed(this); listener.WebTimeNavigationObserverDestroyed(this);
} }
void WebTimeNavigationObserver::TitleWasSet(content::NavigationEntry* entry) {
previous_title_ = web_contents()->GetTitle();
}
WebTimeNavigationObserver::WebTimeNavigationObserver( WebTimeNavigationObserver::WebTimeNavigationObserver(
content::WebContents* web_contents) content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {} : content::WebContentsObserver(web_contents) {}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h" #include "chrome/browser/chromeos/child_accounts/time_limits/app_types.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
namespace content { namespace content {
class WebContents; class WebContents;
class NavigationHandle; class NavigationHandle;
class NavigationEntry;
} // namespace content } // namespace content
class GURL; class GURL;
...@@ -63,11 +65,16 @@ class WebTimeNavigationObserver ...@@ -63,11 +65,16 @@ class WebTimeNavigationObserver
void DidFinishNavigation( void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
void WebContentsDestroyed() override; void WebContentsDestroyed() override;
void TitleWasSet(content::NavigationEntry* entry) override;
const base::Optional<NavigationInfo>& last_navigation_info() const { const base::Optional<NavigationInfo>& last_navigation_info() const {
return last_navigation_info_; return last_navigation_info_;
} }
const base::Optional<base::string16>& previous_title() const {
return previous_title_;
}
private: private:
friend class content::WebContentsUserData<WebTimeNavigationObserver>; friend class content::WebContentsUserData<WebTimeNavigationObserver>;
...@@ -80,6 +87,8 @@ class WebTimeNavigationObserver ...@@ -80,6 +87,8 @@ class WebTimeNavigationObserver
base::Optional<NavigationInfo> last_navigation_info_ = base::nullopt; base::Optional<NavigationInfo> last_navigation_info_ = base::nullopt;
base::Optional<base::string16> previous_title_;
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
}; };
......
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