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_dom_handler.h" | |
15 #include "chrome/common/pref_names.h" | |
16 #include "chrome/common/url_constants.h" | |
17 #include "content/browser/tab_contents/tab_contents.h" | |
18 #include "grit/browser_resources.h" | |
19 #include "grit/chromium_strings.h" | |
20 #include "grit/generated_resources.h" | |
21 #include "grit/theme_resources.h" | |
22 #include "ui/base/l10n/l10n_util.h" | |
23 | |
24 static const char kStringsJsFile[] = "strings.js"; | |
25 static const char kNewProfileJsFile[] = "new_profile.js"; | |
26 | |
27 namespace { | |
28 | |
29 // Is the current time within a given date range? | |
30 bool InDateRange(double begin, double end) { | |
31 base::Time start_time = base::Time::FromDoubleT(begin); | |
32 base::Time end_time = base::Time::FromDoubleT(end); | |
33 return start_time < base::Time::Now() && end_time > base::Time::Now(); | |
34 } | |
35 | |
36 /////////////////////////////////////////////////////////////////////////////// | |
37 // | |
38 // NewProfileUIHTMLSource | |
39 // | |
40 /////////////////////////////////////////////////////////////////////////////// | |
41 | |
42 class NewProfileUIHTMLSource : public ChromeWebUIDataSource { | |
43 public: | |
44 explicit NewProfileUIHTMLSource(Profile* profile); | |
45 | |
46 // Called when the network layer has requested a resource underneath | |
47 // the path we registered. | |
48 virtual void StartDataRequest(const std::string& path, | |
49 bool is_incognito, | |
50 int request_id); | |
51 | |
52 virtual std::string GetMimeType(const std::string&) const; | |
53 | |
54 static int PathToIDR(const std::string& path); | |
55 | |
56 private: | |
57 ~NewProfileUIHTMLSource() {} | |
58 DISALLOW_COPY_AND_ASSIGN(NewProfileUIHTMLSource); | |
59 }; | |
60 | |
61 NewProfileUIHTMLSource::NewProfileUIHTMLSource(Profile* profile) | |
62 : ChromeWebUIDataSource(chrome::kChromeUINewProfileHost) { | |
63 AddLocalizedString("title", IDS_NEW_PROFILE_SETUP_TITLE); | |
64 AddLocalizedString("createProfile", IDS_NEW_PROFILE_SETUP_CREATE_PROFILE); | |
65 AddLocalizedString("cancelProfile", IDS_NEW_PROFILE_SETUP_CANCEL_PROFILE); | |
66 AddLocalizedString("profileNameLabel", IDS_NEW_PROFILE_SETUP_NAME_LABEL); | |
67 AddLocalizedString("profileIconLabel", IDS_NEW_PROFILE_SETUP_ICON_LABEL); | |
68 AddLocalizedString("summaryConclusion", | |
69 IDS_NEW_PROFILE_SETUP_SUMMARY_CONCLUSION); | |
70 | |
71 const string16 short_product_name = | |
72 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | |
Miranda Callahan
2011/06/27 16:42:08
indent
sail
2011/06/27 17:37:24
Done.
| |
73 AddLocalizedString("summaryTitle", l10n_util::GetStringFUTF16( | |
74 IDS_NEW_PROFILE_SETUP_SUMMARY_TITLE, short_product_name)); | |
75 AddLocalizedString("summaryBody", l10n_util::GetStringFUTF16( | |
76 IDS_NEW_PROFILE_SETUP_SUMMARY_BODY, short_product_name)); | |
77 | |
78 // If the user has preferences for a start and end time for a custom logo, | |
79 // and the time now is between these two times, show the custom logo. | |
Miranda Callahan
2011/06/27 16:42:08
Is this promo really going to be governed by a tim
sail
2011/06/27 17:37:24
So when designing this UI I thought it would be go
| |
80 bool hasCustomLogo = | |
81 profile->GetPrefs()->FindPreference(prefs::kNTPCustomLogoStart) && | |
82 profile->GetPrefs()->FindPreference(prefs::kNTPCustomLogoEnd) && | |
83 InDateRange(profile->GetPrefs()->GetDouble(prefs::kNTPCustomLogoStart), | |
84 profile->GetPrefs()->GetDouble(prefs::kNTPCustomLogoEnd)); | |
85 AddLocalizedString("customlogo", | |
86 ASCIIToUTF16(hasCustomLogo ? "true" : "false")); | |
87 } | |
88 | |
89 void NewProfileUIHTMLSource::StartDataRequest(const std::string& path, | |
90 bool is_incognito, | |
91 int request_id) { | |
92 if (path == kStringsJsFile) { | |
93 SendLocalizedStringsAsJSON(request_id); | |
94 } else { | |
95 int idr = path == kNewProfileJsFile ? IDR_NEW_PROFILE_JS : | |
96 IDR_NEW_PROFILE_HTML; | |
97 SendFromResourceBundle(request_id, idr); | |
98 } | |
99 } | |
100 | |
101 std::string NewProfileUIHTMLSource::GetMimeType(const std::string& path) const { | |
102 if (path == kStringsJsFile || path == kNewProfileJsFile) | |
103 return "application/javascript"; | |
104 | |
105 return "text/html"; | |
106 } | |
107 | |
108 } // namespace | |
109 | |
110 /////////////////////////////////////////////////////////////////////////////// | |
111 // | |
112 // NewProfileUI | |
113 // | |
114 /////////////////////////////////////////////////////////////////////////////// | |
115 | |
116 NewProfileUI::NewProfileUI(TabContents* contents) : ChromeWebUI(contents) { | |
117 should_hide_url_ = true; | |
118 | |
119 NewProfileDOMHandler* handler = new NewProfileDOMHandler(); | |
120 AddMessageHandler(handler); | |
121 handler->Attach(this); | |
122 | |
123 // Set up the new profile source. | |
124 NewProfileUIHTMLSource* html_source = | |
125 new NewProfileUIHTMLSource(GetProfile()); | |
126 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | |
127 } | |
OLD | NEW |