Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / first_run / first_run_ui.cc
blob2cfe4cbe66f265d2a9bbdbe979e5452cd79db040
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
7 #include "ash/shell.h"
8 #include "base/command_line.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_handler.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_data_source.h"
18 #include "grit/browser_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/webui/web_ui_util.h"
22 namespace {
24 const char kFirstRunJSPath[] = "first_run.js";
25 const char kShelfAlignmentBottom[] = "bottom";
26 const char kShelfAlignmentLeft[] = "left";
27 const char kShelfAlignmentRight[] = "right";
29 void SetLocalizedStrings(base::DictionaryValue* localized_strings) {
30 localized_strings->SetString(
31 "appListHeader",
32 l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_HEADER));
33 localized_strings->SetString(
34 "appListText1",
35 l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_TEXT_1));
36 localized_strings->SetString(
37 "appListText2",
38 l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_TEXT_2));
39 localized_strings->SetString(
40 "trayHeader", l10n_util::GetStringUTF16(IDS_FIRST_RUN_TRAY_STEP_HEADER));
41 localized_strings->SetString(
42 "trayText", l10n_util::GetStringUTF16(IDS_FIRST_RUN_TRAY_STEP_TEXT));
43 localized_strings->SetString(
44 "helpHeader", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_HEADER));
45 base::string16 product_name =
46 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
47 localized_strings->SetString(
48 "helpText1", l10n_util::GetStringFUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_1,
49 product_name));
50 localized_strings->SetString(
51 "helpText2", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_2));
52 localized_strings->SetString(
53 "helpKeepExploringButton",
54 l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_KEEP_EXPLORING_BUTTON));
55 localized_strings->SetString(
56 "helpFinishButton",
57 l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_FINISH_BUTTON));
58 localized_strings->SetString(
59 "nextButton", l10n_util::GetStringUTF16(IDS_FIRST_RUN_NEXT_BUTTON));
60 localized_strings->SetBoolean(
61 "transitionsEnabled",
62 base::CommandLine::ForCurrentProcess()->HasSwitch(
63 chromeos::switches::kEnableFirstRunUITransitions));
64 std::string shelf_alignment;
65 ash::Shell* shell = ash::Shell::GetInstance();
66 switch (shell->GetShelfAlignment(shell->GetPrimaryRootWindow())) {
67 case ash::SHELF_ALIGNMENT_BOTTOM:
68 shelf_alignment = kShelfAlignmentBottom;
69 break;
70 case ash::SHELF_ALIGNMENT_LEFT:
71 shelf_alignment = kShelfAlignmentLeft;
72 break;
73 case ash::SHELF_ALIGNMENT_RIGHT:
74 shelf_alignment = kShelfAlignmentRight;
75 break;
76 default:
77 NOTREACHED() << "Unsupported shelf alignment";
79 localized_strings->SetString("shelfAlignment", shelf_alignment);
82 content::WebUIDataSource* CreateDataSource() {
83 content::WebUIDataSource* source =
84 content::WebUIDataSource::Create(chrome::kChromeUIFirstRunHost);
85 source->SetJsonPath("strings.js");
86 source->SetDefaultResource(IDR_FIRST_RUN_HTML);
87 source->AddResourcePath(kFirstRunJSPath, IDR_FIRST_RUN_JS);
88 base::DictionaryValue localized_strings;
89 const std::string& app_locale = g_browser_process->GetApplicationLocale();
90 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings);
91 SetLocalizedStrings(&localized_strings);
92 source->AddLocalizedStrings(localized_strings);
93 return source;
96 } // anonymous namespace
98 namespace chromeos {
100 FirstRunUI::FirstRunUI(content::WebUI* web_ui)
101 : WebUIController(web_ui),
102 actor_(NULL) {
103 FirstRunHandler* handler = new FirstRunHandler();
104 actor_ = handler;
105 web_ui->AddMessageHandler(handler);
106 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), CreateDataSource());
109 } // namespace chromeos