Componentize SigninManager.
[chromium-blink-merge.git] / chrome / browser / ui / webui / welcome_ui_android.cc
blob0bcae1ca0da5ff985346b18b3b5a5230b7e6813b
1 // Copyright (c) 2012 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/welcome_ui_android.h"
7 #include <string>
9 #include "base/strings/string16.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/android/accessibility_util.h"
13 #include "chrome/browser/android/tab_android.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/webui/welcome_handler_android.h"
17 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/web_ui.h"
19 #include "content/public/browser/web_ui_data_source.h"
20 #include "grit/browser_resources.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "grit/google_chrome_strings.h"
24 #include "ui/base/l10n/l10n_util.h"
26 const char kProductTourBaseURL[] =
27 "http://www.google.com/intl/%s/chrome/browser/mobile/tour/android.html";
29 const char kPrivacyNoticeBaseURL[] =
30 "http://www.google.com/chrome/intl/%s/privacy.html";
32 WelcomeUI::WelcomeUI(content::WebUI* web_ui)
33 : content::WebUIController(web_ui) {
34 // Set up the chrome://welcome source.
35 content::WebUIDataSource* html_source =
36 content::WebUIDataSource::Create(chrome::kChromeUIWelcomeHost);
37 html_source->SetUseJsonJSFormatV2();
39 // Localized strings.
40 html_source->AddLocalizedString("title",
41 IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE);
42 html_source->AddLocalizedString("takeATour", IDS_FIRSTRUN_TAKE_TOUR);
43 html_source->AddLocalizedString("firstRunSignedInTitle",
44 IDS_FIRSTRUN_SIGNED_IN_TITLE);
45 html_source->AddLocalizedString("firstRunSignedInDescription",
46 IDS_FIRSTRUN_SIGNED_IN_DESCRIPTION);
47 html_source->AddLocalizedString("settings", IDS_FIRSTRUN_SETTINGS_LINK);
49 std::string locale = g_browser_process->GetApplicationLocale();
50 std::string product_tour_url = base::StringPrintf(
51 kProductTourBaseURL, locale.c_str());
53 if (chrome::android::AccessibilityUtil::IsAccessibilityEnabled())
54 product_tour_url += "?talkback";
56 html_source->AddString("productTourUrl", product_tour_url);
58 TabAndroid* tab = TabAndroid::FromWebContents(web_ui->GetWebContents());
59 bool tos_visible = tab && tab->ShouldWelcomePageLinkToTermsOfService();
60 html_source->AddBoolean("tosVisible", tos_visible);
62 base::string16 tos_html;
63 if (tos_visible) {
64 std::string privacy_notice_url =
65 base::StringPrintf(kPrivacyNoticeBaseURL, locale.c_str());
66 tos_html = l10n_util::GetStringFUTF16(
67 IDS_FIRSTRUN_TOS_EXPLANATION, base::UTF8ToUTF16(privacy_notice_url));
69 html_source->AddString("tosHtml", tos_html);
71 // Add required resources.
72 html_source->SetJsonPath("strings.js");
73 html_source->SetDefaultResource(IDR_ABOUT_WELCOME_HTML);
75 Profile* profile = Profile::FromWebUI(web_ui);
76 content::WebUIDataSource::Add(profile, html_source);
78 // Add message handlers.
79 web_ui->AddMessageHandler(new WelcomeHandler());
82 WelcomeUI::~WelcomeUI() {