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"
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/tab_android.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/webui/welcome_handler_android.h"
16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_data_source.h"
19 #include "grit/browser_resources.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "grit/google_chrome_strings.h"
23 #include "ui/base/l10n/l10n_util.h"
25 const char kProductTourBaseURL
[] =
26 "http://www.google.com/intl/%s/chrome/browser/mobile/tour/android.html";
28 const char kPrivacyNoticeBaseURL
[] =
29 "http://www.google.com/chrome/intl/%s/privacy.html";
31 WelcomeUI::WelcomeUI(content::WebUI
* web_ui
)
32 : content::WebUIController(web_ui
) {
33 // Set up the chrome://welcome source.
34 content::WebUIDataSource
* html_source
=
35 content::WebUIDataSource::Create(chrome::kChromeUIWelcomeHost
);
36 html_source
->SetUseJsonJSFormatV2();
39 html_source
->AddLocalizedString("title",
40 IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE
);
41 html_source
->AddLocalizedString("takeATour", IDS_FIRSTRUN_TAKE_TOUR
);
42 html_source
->AddLocalizedString("firstRunSignedInTitle",
43 IDS_FIRSTRUN_SIGNED_IN_TITLE
);
44 html_source
->AddLocalizedString("firstRunSignedInDescription",
45 IDS_FIRSTRUN_SIGNED_IN_DESCRIPTION
);
46 html_source
->AddLocalizedString("settings", IDS_FIRSTRUN_SETTINGS_LINK
);
48 std::string locale
= g_browser_process
->GetApplicationLocale();
49 std::string product_tour_url
= base::StringPrintf(
50 kProductTourBaseURL
, locale
.c_str());
51 html_source
->AddString("productTourUrl", product_tour_url
);
53 TabAndroid
* tab
= TabAndroid::FromWebContents(web_ui
->GetWebContents());
54 bool tos_visible
= tab
&& tab
->ShouldWelcomePageLinkToTermsOfService();
55 html_source
->AddBoolean("tosVisible", tos_visible
);
57 base::string16 tos_html
;
59 std::string privacy_notice_url
=
60 base::StringPrintf(kPrivacyNoticeBaseURL
, locale
.c_str());
61 tos_html
= l10n_util::GetStringFUTF16(
62 IDS_FIRSTRUN_TOS_EXPLANATION
, base::UTF8ToUTF16(privacy_notice_url
));
64 html_source
->AddString("tosHtml", tos_html
);
66 // Add required resources.
67 html_source
->SetJsonPath("strings.js");
68 html_source
->AddResourcePath("about_welcome_android.css",
69 IDR_ABOUT_WELCOME_CSS
);
70 html_source
->AddResourcePath("about_welcome_android.js",
71 IDR_ABOUT_WELCOME_JS
);
72 html_source
->SetDefaultResource(IDR_ABOUT_WELCOME_HTML
);
74 Profile
* profile
= Profile::FromWebUI(web_ui
);
75 content::WebUIDataSource::Add(profile
, html_source
);
77 // Add message handlers.
78 web_ui
->AddMessageHandler(new WelcomeHandler());
81 WelcomeUI::~WelcomeUI() {