Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / first_run / first_run_ui.cc
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.
4
5 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
6
7 #include "ash/shell.h"
8 #include "base/command_line.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_handler.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/grit/chromium_strings.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "content/public/browser/web_ui.h"
16 #include "content/public/browser/web_ui_data_source.h"
17 #include "grit/browser_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/webui/web_ui_util.h"
20
21 namespace {
22
23 const char kFirstRunJSPath[] = "first_run.js";
24 const char kShelfAlignmentBottom[] = "bottom";
25 const char kShelfAlignmentLeft[] = "left";
26 const char kShelfAlignmentRight[] = "right";
27
28 void SetLocalizedStrings(base::DictionaryValue* localized_strings) {
29   localized_strings->SetString(
30       "appListHeader",
31       l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_HEADER));
32   localized_strings->SetString(
33       "appListText1",
34       l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_TEXT_1));
35   localized_strings->SetString(
36       "appListText2",
37       l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_TEXT_2));
38   localized_strings->SetString(
39       "trayHeader", l10n_util::GetStringUTF16(IDS_FIRST_RUN_TRAY_STEP_HEADER));
40   localized_strings->SetString(
41       "trayText", l10n_util::GetStringUTF16(IDS_FIRST_RUN_TRAY_STEP_TEXT));
42   localized_strings->SetString(
43       "helpHeader", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_HEADER));
44   base::string16 product_name =
45       l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
46   localized_strings->SetString(
47       "helpText1", l10n_util::GetStringFUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_1,
48                                               product_name));
49   localized_strings->SetString(
50       "helpText2", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_2));
51   localized_strings->SetString(
52       "helpKeepExploringButton",
53       l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_KEEP_EXPLORING_BUTTON));
54   localized_strings->SetString(
55       "helpFinishButton",
56       l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_FINISH_BUTTON));
57   localized_strings->SetString(
58       "nextButton", l10n_util::GetStringUTF16(IDS_FIRST_RUN_NEXT_BUTTON));
59   localized_strings->SetBoolean(
60       "transitionsEnabled",
61       CommandLine::ForCurrentProcess()->HasSwitch(
62           chromeos::switches::kEnableFirstRunUITransitions));
63   std::string shelf_alignment;
64   ash::Shell* shell = ash::Shell::GetInstance();
65   switch (shell->GetShelfAlignment(shell->GetPrimaryRootWindow())) {
66     case ash::SHELF_ALIGNMENT_BOTTOM:
67       shelf_alignment = kShelfAlignmentBottom;
68       break;
69     case ash::SHELF_ALIGNMENT_LEFT:
70       shelf_alignment = kShelfAlignmentLeft;
71       break;
72     case ash::SHELF_ALIGNMENT_RIGHT:
73       shelf_alignment = kShelfAlignmentRight;
74       break;
75     default:
76       NOTREACHED() << "Unsupported shelf alignment";
77   }
78   localized_strings->SetString("shelfAlignment", shelf_alignment);
79 }
80
81 content::WebUIDataSource* CreateDataSource() {
82   content::WebUIDataSource* source =
83       content::WebUIDataSource::Create(chrome::kChromeUIFirstRunHost);
84   source->SetUseJsonJSFormatV2();
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   webui::SetFontAndTextDirection(&localized_strings);
90   SetLocalizedStrings(&localized_strings);
91   source->AddLocalizedStrings(localized_strings);
92   return source;
93 }
94
95 }  // anonymous namespace
96
97 namespace chromeos {
98
99 FirstRunUI::FirstRunUI(content::WebUI* web_ui)
100     : WebUIController(web_ui),
101       actor_(NULL) {
102   FirstRunHandler* handler = new FirstRunHandler();
103   actor_ = handler;
104   web_ui->AddMessageHandler(handler);
105   content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), CreateDataSource());
106 }
107
108 }  // namespace chromeos
109