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"
8 #include "base/command_line.h"
9 #include "chrome/browser/chromeos/login/user_manager.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 "chromeos/chromeos_switches.h"
14 #include "content/public/browser/web_ui.h"
15 #include "content/public/browser/web_ui_data_source.h"
16 #include "grit/browser_resources.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/webui/web_ui_util.h"
23 const char kFirstRunJSPath
[] = "first_run.js";
24 const char kShelfAlignmentBottom
[] = "bottom";
25 const char kShelfAlignmentLeft
[] = "left";
26 const char kShelfAlignmentRight
[] = "right";
28 void SetLocalizedStrings(base::DictionaryValue
* localized_strings
) {
29 localized_strings
->SetString(
31 l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_HEADER
));
32 localized_strings
->SetString(
34 l10n_util::GetStringUTF16(IDS_FIRST_RUN_APP_LIST_STEP_TEXT_1
));
35 localized_strings
->SetString(
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 localized_strings
->SetString(
45 "helpText1", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_1
));
46 localized_strings
->SetString(
47 "helpText2", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_2
));
48 localized_strings
->SetString(
49 "helpText3", l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_TEXT_3
));
50 localized_strings
->SetString(
51 "helpKeepExploringButton",
52 l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_KEEP_EXPLORING_BUTTON
));
53 localized_strings
->SetString(
55 l10n_util::GetStringUTF16(IDS_FIRST_RUN_HELP_STEP_FINISH_BUTTON
));
56 localized_strings
->SetString(
57 "nextButton", l10n_util::GetStringUTF16(IDS_FIRST_RUN_NEXT_BUTTON
));
58 localized_strings
->SetBoolean(
60 CommandLine::ForCurrentProcess()->HasSwitch(
61 chromeos::switches::kEnableFirstRunUITransitions
));
62 std::string shelf_alignment
;
63 ash::Shell
* shell
= ash::Shell::GetInstance();
64 switch (shell
->GetShelfAlignment(shell
->GetPrimaryRootWindow())) {
65 case ash::SHELF_ALIGNMENT_BOTTOM
:
66 shelf_alignment
= kShelfAlignmentBottom
;
68 case ash::SHELF_ALIGNMENT_LEFT
:
69 shelf_alignment
= kShelfAlignmentLeft
;
71 case ash::SHELF_ALIGNMENT_RIGHT
:
72 shelf_alignment
= kShelfAlignmentRight
;
75 NOTREACHED() << "Unsupported shelf alignment";
77 localized_strings
->SetString("shelfAlignment", shelf_alignment
);
80 content::WebUIDataSource
* CreateDataSource() {
81 content::WebUIDataSource
* source
=
82 content::WebUIDataSource::Create(chrome::kChromeUIFirstRunHost
);
83 source
->SetUseJsonJSFormatV2();
84 source
->SetJsonPath("strings.js");
85 source
->SetDefaultResource(IDR_FIRST_RUN_HTML
);
86 source
->AddResourcePath(kFirstRunJSPath
, IDR_FIRST_RUN_JS
);
87 base::DictionaryValue localized_strings
;
88 webui::SetFontAndTextDirection(&localized_strings
);
89 SetLocalizedStrings(&localized_strings
);
90 source
->AddLocalizedStrings(localized_strings
);
94 } // anonymous namespace
98 FirstRunUI::FirstRunUI(content::WebUI
* web_ui
)
99 : WebUIController(web_ui
),
101 FirstRunHandler
* handler
= new FirstRunHandler();
103 web_ui
->AddMessageHandler(handler
);
104 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui
), CreateDataSource());
107 } // namespace chromeos