Commit befe2a17 authored by jdufault's avatar jdufault Committed by Commit bot

cros: Ensure task manager shows correct title for lock screen webview

See https://codereview.chromium.org/2512473004/ for additional context.

BUG=669638

Review-Url: https://codereview.chromium.org/2550263002
Cr-Commit-Position: refs/heads/master@{#437969}
parent 88b833af
...@@ -2164,6 +2164,9 @@ Press any key to continue exploring. ...@@ -2164,6 +2164,9 @@ Press any key to continue exploring.
<message name="IDS_KIOSK_APPS_BUTTON" desc="Text shown on a button that brings up the kiosk apps menu on login screen"> <message name="IDS_KIOSK_APPS_BUTTON" desc="Text shown on a button that brings up the kiosk apps menu on login screen">
Apps Apps
</message> </message>
<message name="IDS_LOCK_SCREEN_TASK_MANAGER_NAME" desc="The name of the lock screen as it appears in the task manager. This will be prefixed with another string, such as 'Extension: ' (see IDS_TASK_MANAGER_EXTENSION_PREFIX)">
Lock Screen
</message>
<message name="IDS_LOGIN_USER_ADDING_BANNER" desc="Text shown on a banner in user adding screen."> <message name="IDS_LOGIN_USER_ADDING_BANNER" desc="Text shown on a banner in user adding screen.">
Add an account to multiple sign-in. All signed-in accounts can be accessed without a password, so this feature should only be used with trusted accounts. Add an account to multiple sign-in. All signed-in accounts can be accessed without a password, so this feature should only be used with trusted accounts.
</message> </message>
......
...@@ -887,6 +887,8 @@ source_set("chromeos") { ...@@ -887,6 +887,8 @@ source_set("chromeos") {
"login/ui/user_adding_screen.h", "login/ui/user_adding_screen.h",
"login/ui/user_adding_screen_input_methods_controller.cc", "login/ui/user_adding_screen_input_methods_controller.cc",
"login/ui/user_adding_screen_input_methods_controller.h", "login/ui/user_adding_screen_input_methods_controller.h",
"login/ui/web_contents_forced_title.cc",
"login/ui/web_contents_forced_title.h",
"login/ui/web_contents_set_background_color.cc", "login/ui/web_contents_set_background_color.cc",
"login/ui/web_contents_set_background_color.h", "login/ui/web_contents_set_background_color.h",
"login/ui/web_view_handle.cc", "login/ui/web_view_handle.cc",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/ui/web_contents_forced_title.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(chromeos::WebContentsForcedTitle);
namespace chromeos {
// static
void WebContentsForcedTitle::CreateForWebContentsWithTitle(
content::WebContents* web_contents,
const base::string16& title) {
if (FromWebContents(web_contents))
return;
web_contents->UpdateTitleForEntry(nullptr, title);
web_contents->SetUserData(UserDataKey(),
new WebContentsForcedTitle(web_contents, title));
}
WebContentsForcedTitle::WebContentsForcedTitle(
content::WebContents* web_contents,
const base::string16& title)
: content::WebContentsObserver(web_contents), title_(title) {}
WebContentsForcedTitle::~WebContentsForcedTitle() {}
void WebContentsForcedTitle::TitleWasSet(content::NavigationEntry* entry,
bool explicit_set) {
if (!entry || entry->GetTitle() != title_)
web_contents()->UpdateTitleForEntry(entry, title_);
}
} // namespace chromeos
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEB_CONTENTS_FORCED_TITLE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEB_CONTENTS_FORCED_TITLE_H_
#include "base/strings/string16.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace chromeos {
// Ensures that the title of the WebContents instance this object is attached
// to is always set to the given title value.
class WebContentsForcedTitle
: public content::WebContentsObserver,
public content::WebContentsUserData<WebContentsForcedTitle> {
public:
static void CreateForWebContentsWithTitle(content::WebContents* web_contents,
const base::string16& title);
~WebContentsForcedTitle() override;
private:
WebContentsForcedTitle(content::WebContents* web_contents,
const base::string16& title);
// content::WebContentsObserver:
void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
base::string16 title_;
DISALLOW_COPY_AND_ASSIGN(WebContentsForcedTitle);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_WEB_CONTENTS_FORCED_TITLE_H_
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h"
#include "chrome/browser/chromeos/login/ui/shared_web_view.h" #include "chrome/browser/chromeos/login/ui/shared_web_view.h"
#include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h" #include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h"
#include "chrome/browser/chromeos/login/ui/web_contents_forced_title.h"
#include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h" #include "chrome/browser/chromeos/login/ui/web_contents_set_background_color.h"
#include "chrome/browser/chromeos/login/ui/web_view_handle.h" #include "chrome/browser/chromeos/login/ui/web_view_handle.h"
#include "chrome/browser/chromeos/login/ui/webui_login_display.h" #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
...@@ -269,9 +270,13 @@ WebUILoginView::~WebUILoginView() { ...@@ -269,9 +270,13 @@ WebUILoginView::~WebUILoginView() {
} }
// static // static
void WebUILoginView::InitializeWebView(views::WebView* web_view) { void WebUILoginView::InitializeWebView(views::WebView* web_view,
const base::string16& title) {
WebContents* web_contents = web_view->GetWebContents(); WebContents* web_contents = web_view->GetWebContents();
if (!title.empty())
WebContentsForcedTitle::CreateForWebContentsWithTitle(web_contents, title);
WebContentsSetBackgroundColor::CreateForWebContentsWithColor( WebContentsSetBackgroundColor::CreateForWebContentsWithColor(
web_contents, SK_ColorTRANSPARENT); web_contents, SK_ColorTRANSPARENT);
...@@ -311,7 +316,7 @@ void WebUILoginView::Init() { ...@@ -311,7 +316,7 @@ void WebUILoginView::Init() {
WebContents* web_contents = web_view()->GetWebContents(); WebContents* web_contents = web_view()->GetWebContents();
if (!is_reusing_webview_) if (!is_reusing_webview_)
InitializeWebView(web_view()); InitializeWebView(web_view(), settings_.web_view_title);
web_view()->set_allow_accelerators(true); web_view()->set_allow_accelerators(true);
AddChildView(web_view()); AddChildView(web_view());
......
...@@ -47,6 +47,10 @@ class WebUILoginView : public views::View, ...@@ -47,6 +47,10 @@ class WebUILoginView : public views::View,
struct WebViewSettings { struct WebViewSettings {
// URL of the WebView to preload and reuse across WebUILoginView instances. // URL of the WebView to preload and reuse across WebUILoginView instances.
GURL preloaded_url; GURL preloaded_url;
// Title of the web contents. This will be shown in the task manager. If
// empty, the default webview title will be used.
base::string16 web_view_title;
}; };
// Internal class name. // Internal class name.
...@@ -111,7 +115,8 @@ class WebUILoginView : public views::View, ...@@ -111,7 +115,8 @@ class WebUILoginView : public views::View,
} }
protected: protected:
static void InitializeWebView(views::WebView* web_view); static void InitializeWebView(views::WebView* web_view,
const base::string16& title);
// Overridden from views::View: // Overridden from views::View:
void Layout() override; void Layout() override;
......
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