Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/ui/webui/new_profile_ui.cc

Issue 7275026: Revert 90820 - Multi-Profiles: New Profile Setup UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/new_profile_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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);
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.
80 // TODO(sail): We should also update the logo if the theme changes or
81 // if these prefs change.
82 // TODO(sail): This code is copy pasted from the NTP code. This should be
83 // refactored.
84 bool hasCustomLogo =
85 profile->GetPrefs()->FindPreference(prefs::kNTPCustomLogoStart) &&
86 profile->GetPrefs()->FindPreference(prefs::kNTPCustomLogoEnd) &&
87 InDateRange(profile->GetPrefs()->GetDouble(prefs::kNTPCustomLogoStart),
88 profile->GetPrefs()->GetDouble(prefs::kNTPCustomLogoEnd));
89 AddLocalizedString("customlogo",
90 ASCIIToUTF16(hasCustomLogo ? "true" : "false"));
91 }
92
93 void NewProfileUIHTMLSource::StartDataRequest(const std::string& path,
94 bool is_incognito,
95 int request_id) {
96 if (path == kStringsJsFile) {
97 SendLocalizedStringsAsJSON(request_id);
98 } else {
99 int idr = path == kNewProfileJsFile ? IDR_NEW_PROFILE_JS :
100 IDR_NEW_PROFILE_HTML;
101 SendFromResourceBundle(request_id, idr);
102 }
103 }
104
105 std::string NewProfileUIHTMLSource::GetMimeType(const std::string& path) const {
106 if (path == kStringsJsFile || path == kNewProfileJsFile)
107 return "application/javascript";
108
109 return "text/html";
110 }
111
112 } // namespace
113
114 ///////////////////////////////////////////////////////////////////////////////
115 //
116 // NewProfileUI
117 //
118 ///////////////////////////////////////////////////////////////////////////////
119
120 NewProfileUI::NewProfileUI(TabContents* contents) : ChromeWebUI(contents) {
121 should_hide_url_ = true;
122
123 NewProfileDOMHandler* handler = new NewProfileDOMHandler();
124 AddMessageHandler(handler);
125 handler->Attach(this);
126
127 // Set up the new profile source.
128 NewProfileUIHTMLSource* html_source =
129 new NewProfileUIHTMLSource(GetProfile());
130 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
131 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/new_profile_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698