Home | History | Annotate | Download | only in webui
      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.
      4 
      5 #include "chrome/browser/ui/webui/welcome_ui_android.h"
      6 
      7 #include <string>
      8 
      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 "chrome/grit/chromium_strings.h"
     19 #include "chrome/grit/generated_resources.h"
     20 #include "chrome/grit/google_chrome_strings.h"
     21 #include "content/public/browser/web_ui.h"
     22 #include "content/public/browser/web_ui_data_source.h"
     23 #include "grit/browser_resources.h"
     24 #include "ui/base/l10n/l10n_util.h"
     25 
     26 const char kProductTourBaseURL[] =
     27     "http://www.google.com/intl/%s/chrome/browser/mobile/tour/android.html";
     28 
     29 const char kPrivacyNoticeBaseURL[] =
     30     "http://www.google.com/chrome/intl/%s/privacy.html";
     31 
     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();
     38 
     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);
     48 
     49   std::string locale = g_browser_process->GetApplicationLocale();
     50   std::string product_tour_url = base::StringPrintf(
     51       kProductTourBaseURL, locale.c_str());
     52 
     53   if (chrome::android::AccessibilityUtil::IsAccessibilityEnabled())
     54     product_tour_url += "?talkback";
     55 
     56   html_source->AddString("productTourUrl", product_tour_url);
     57 
     58   TabAndroid* tab = TabAndroid::FromWebContents(web_ui->GetWebContents());
     59   bool tos_visible = tab && tab->ShouldWelcomePageLinkToTermsOfService();
     60   html_source->AddBoolean("tosVisible", tos_visible);
     61 
     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));
     68   }
     69   html_source->AddString("tosHtml", tos_html);
     70 
     71   // Add required resources.
     72   html_source->SetJsonPath("strings.js");
     73   html_source->SetDefaultResource(IDR_ABOUT_WELCOME_HTML);
     74 
     75   Profile* profile = Profile::FromWebUI(web_ui);
     76   content::WebUIDataSource::Add(profile, html_source);
     77 
     78   // Add message handlers.
     79   web_ui->AddMessageHandler(new WelcomeHandler());
     80 }
     81 
     82 WelcomeUI::~WelcomeUI() {
     83 }
     84