OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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/new_profile_ui.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "base/time.h" | |
9 #include "chrome/browser/defaults.h" | |
10 #include "chrome/browser/prefs/pref_service.h" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
13 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | |
14 #include "chrome/browser/ui/webui/new_profile_handler.h" | |
15 #include "chrome/browser/ui/webui/theme_source.h" | |
16 #include "chrome/common/pref_names.h" | |
17 #include "chrome/common/url_constants.h" | |
18 #include "content/browser/tab_contents/tab_contents.h" | |
19 #include "grit/browser_resources.h" | |
20 #include "grit/chromium_strings.h" | |
21 #include "grit/generated_resources.h" | |
22 #include "grit/theme_resources.h" | |
23 #include "ui/base/l10n/l10n_util.h" | |
24 | |
25 namespace { | |
26 | |
27 const char kStringsJsFile[] = "strings.js"; | |
28 const char kNewProfileJsFile[] = "new_profile.js"; | |
29 | |
30 // Checks if this is the current time within a given date range? | |
31 bool InDateRange(double begin, double end) { | |
32 base::Time start_time = base::Time::FromDoubleT(begin); | |
33 base::Time end_time = base::Time::FromDoubleT(end); | |
34 return start_time < base::Time::Now() && end_time > base::Time::Now(); | |
35 } | |
36 | |
37 /////////////////////////////////////////////////////////////////////////////// | |
38 // | |
39 // NewProfileUIHTMLSource | |
40 // | |
41 /////////////////////////////////////////////////////////////////////////////// | |
42 | |
43 class NewProfileUIHTMLSource : public ChromeWebUIDataSource { | |
44 public: | |
45 explicit NewProfileUIHTMLSource(Profile* profile); | |
46 | |
47 private: | |
48 ~NewProfileUIHTMLSource() {} | |
49 DISALLOW_COPY_AND_ASSIGN(NewProfileUIHTMLSource); | |
50 }; | |
51 | |
52 NewProfileUIHTMLSource::NewProfileUIHTMLSource(Profile* profile) | |
53 : ChromeWebUIDataSource(chrome::kChromeUINewProfileHost) { | |
54 AddLocalizedString("title", IDS_NEW_PROFILE_SETUP_TITLE); | |
55 AddLocalizedString("createProfile", IDS_NEW_PROFILE_SETUP_CREATE_PROFILE); | |
56 AddLocalizedString("cancelProfile", IDS_NEW_PROFILE_SETUP_CANCEL_PROFILE); | |
57 AddLocalizedString("profileNameLabel", IDS_NEW_PROFILE_SETUP_NAME_LABEL); | |
58 AddLocalizedString("profileIconLabel", IDS_NEW_PROFILE_SETUP_ICON_LABEL); | |
59 AddLocalizedString("summaryConclusion", | |
60 IDS_NEW_PROFILE_SETUP_SUMMARY_CONCLUSION); | |
61 | |
62 const string16 short_product_name = | |
63 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | |
64 AddString("summaryTitle", l10n_util::GetStringFUTF16( | |
65 IDS_NEW_PROFILE_SETUP_SUMMARY_TITLE, short_product_name)); | |
66 AddString("summaryBody", l10n_util::GetStringFUTF16( | |
67 IDS_NEW_PROFILE_SETUP_SUMMARY_BODY, short_product_name)); | |
68 | |
69 // If the user has preferences for a start and end time for a custom logo, | |
70 // and the time now is between these two times, show the custom logo. | |
71 // TODO(sail): We should also update the logo if the theme changes or | |
72 // if these prefs change. | |
73 // TODO(sail): This code is copy pasted from the NTP code. This should be | |
74 // refactored. | |
75 bool hasCustomLogo = | |
76 profile->GetPrefs()->FindPreference(prefs::kNTPCustomLogoStart) && | |
77 profile->GetPrefs()->FindPreference(prefs::kNTPCustomLogoEnd) && | |
78 InDateRange(profile->GetPrefs()->GetDouble(prefs::kNTPCustomLogoStart), | |
79 profile->GetPrefs()->GetDouble(prefs::kNTPCustomLogoEnd)); | |
80 AddString("customlogo", ASCIIToUTF16(hasCustomLogo ? "true" : "false")); | |
81 } | |
82 | |
83 } // namespace | |
84 | |
85 /////////////////////////////////////////////////////////////////////////////// | |
86 // | |
87 // NewProfileUI | |
88 // | |
89 /////////////////////////////////////////////////////////////////////////////// | |
90 | |
91 NewProfileUI::NewProfileUI(TabContents* contents) : ChromeWebUI(contents) { | |
92 should_hide_url_ = true; | |
93 | |
94 NewProfileHandler* handler = new NewProfileHandler(); | |
95 AddMessageHandler(handler); | |
96 handler->Attach(this); | |
97 | |
98 // Set up the chrome://theme/ source. | |
99 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | |
100 ThemeSource* theme = new ThemeSource(profile); | |
101 profile->GetChromeURLDataManager()->AddDataSource(theme); | |
102 | |
103 // Set up the new profile source. | |
104 NewProfileUIHTMLSource* html_source = | |
105 new NewProfileUIHTMLSource(GetProfile()); | |
106 html_source->set_json_path(kStringsJsFile); | |
107 html_source->add_resource_path(kNewProfileJsFile, IDR_NEW_PROFILE_JS); | |
108 html_source->set_default_resource(IDR_NEW_PROFILE_HTML); | |
109 profile->GetChromeURLDataManager()->AddDataSource(html_source); | |
110 } | |
OLD | NEW |