Commit 9a795ad4 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Remove ash::Shell access from first-run webui handler

The old code was reaching into ash to get the shelf alignment. This
won't work with out-of-process ash (see //ash/README.md). Convert to
using ash/public/cpp and profile pref.

This enables the first run browser_tests under mash.

Bug: 770866, 756057
Test: browser_tests --enable-features=Mash
Change-Id: I43b202ef255301f637593e24a588a42bacdc7fff
Reviewed-on: https://chromium-review.googlesource.com/1022523Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552499}
parent d4f22170
specific_include_rules = {
"first_run_ui\.cc": [
# TODO(mash): Remove. http://crbug.com/770866
"+ash/shell.h",
"+ash/shelf/shelf.h",
],
}
......@@ -6,8 +6,7 @@
#include <memory>
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/public/cpp/shelf_prefs.h"
#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
......@@ -21,6 +20,8 @@
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
namespace {
......@@ -29,7 +30,8 @@ const char kShelfAlignmentBottom[] = "bottom";
const char kShelfAlignmentLeft[] = "left";
const char kShelfAlignmentRight[] = "right";
void SetLocalizedStrings(base::DictionaryValue* localized_strings) {
void SetLocalizedStrings(Profile* profile,
base::DictionaryValue* localized_strings) {
localized_strings->SetString(
"appListHeader",
l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_HEADER));
......@@ -62,9 +64,11 @@ void SetLocalizedStrings(base::DictionaryValue* localized_strings) {
localized_strings->SetString(
"accessibleTitle",
l10n_util::GetStringUTF16(IDS_FIRST_RUN_STEP_ACCESSIBLE_TITLE));
ash::Shelf* shelf = ash::Shelf::ForWindow(ash::Shell::GetPrimaryRootWindow());
ash::ShelfAlignment alignment = ash::GetShelfAlignmentPref(
profile->GetPrefs(),
display::Screen::GetScreen()->GetPrimaryDisplay().id());
std::string shelf_alignment;
switch (shelf->alignment()) {
switch (alignment) {
case ash::SHELF_ALIGNMENT_BOTTOM:
case ash::SHELF_ALIGNMENT_BOTTOM_LOCKED:
shelf_alignment = kShelfAlignmentBottom;
......@@ -79,7 +83,7 @@ void SetLocalizedStrings(base::DictionaryValue* localized_strings) {
localized_strings->SetString("shelfAlignment", shelf_alignment);
}
content::WebUIDataSource* CreateDataSource() {
content::WebUIDataSource* CreateDataSource(Profile* profile) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIFirstRunHost);
source->SetJsonPath("strings.js");
......@@ -88,7 +92,7 @@ content::WebUIDataSource* CreateDataSource() {
base::DictionaryValue localized_strings;
const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, &localized_strings);
SetLocalizedStrings(&localized_strings);
SetLocalizedStrings(profile, &localized_strings);
source->AddLocalizedStrings(localized_strings);
return source;
}
......@@ -103,7 +107,8 @@ FirstRunUI::FirstRunUI(content::WebUI* web_ui)
auto handler = std::make_unique<FirstRunHandler>();
actor_ = handler.get();
web_ui->AddMessageHandler(std::move(handler));
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), CreateDataSource());
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, CreateDataSource(profile));
}
} // namespace chromeos
......@@ -124,9 +124,6 @@
# SystemLogsFetcher -> TouchLogSource -> ash::TouchHudDebug -> ash::Shell
-FeedbackTest.*
# FirstRunController -> ash::Shell
-FirstRunUIBrowserTest.*
# ash::Shell::display_manager() to update displays.
# http://crbug.com/831826
-ForceMaximizeOnFirstRunTest.*
......
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