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

Side by Side Diff: chrome/browser/views/first_run_view.cc

Issue 2934011: New first run sequence for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Added support for control of all import via master_preferences Created 10 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/views/first_run_view.h ('k') | chrome/browser/views/first_run_view_base.h » ('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) 2010 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/views/first_run_view.h"
6
7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h"
9 #include "base/win_util.h"
10 #include "chrome/browser/importer/importer.h"
11 #include "chrome/browser/first_run.h"
12 #include "chrome/browser/metrics/user_metrics.h"
13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/search_engines/template_url_model.h"
16 #include "chrome/browser/views/first_run_customize_view.h"
17 #include "chrome/browser/views/first_run_search_engine_view.h"
18 #include "chrome/installer/util/browser_distribution.h"
19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h"
21 #include "grit/locale_settings.h"
22 #include "grit/theme_resources.h"
23 #include "views/controls/button/checkbox.h"
24 #include "views/controls/image_view.h"
25 #include "views/controls/label.h"
26 #include "views/controls/throbber.h"
27 #include "views/controls/separator.h"
28 #include "views/standard_layout.h"
29 #include "views/window/window.h"
30
31 namespace {
32
33 // Adds a bullet glyph to a string.
34 std::wstring AddBullet(const std::wstring& text) {
35 std::wstring btext(L" " + text);
36 return btext.insert(0, 1, L'\u2022');
37 }
38
39 } // namespace
40
41 FirstRunView::FirstRunView(Profile* profile, bool homepage_defined,
42 int import_items, int dont_import_items,
43 bool search_engine_experiment,
44 bool randomize_search_engine_experiment)
45 : FirstRunViewBase(profile, homepage_defined, import_items,
46 dont_import_items, search_engine_experiment,
47 randomize_search_engine_experiment),
48 welcome_label_(NULL),
49 actions_label_(NULL),
50 actions_import_(NULL),
51 actions_shorcuts_(NULL),
52 customize_link_(NULL),
53 customize_selected_(false),
54 accepted_(false) {
55 importer_host_ = new ImporterHost();
56 SetupControls();
57 }
58
59 FirstRunView::~FirstRunView() {
60 }
61
62 void FirstRunView::SetupControls() {
63 using views::Label;
64 using views::Link;
65
66 if (default_browser_)
67 default_browser_->SetChecked(true);
68
69 welcome_label_ = new Label(l10n_util::GetString(IDS_FIRSTRUN_DLG_TEXT));
70 welcome_label_->SetColor(SK_ColorBLACK);
71 welcome_label_->SetMultiLine(true);
72 welcome_label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
73 welcome_label_->SizeToFit(0);
74 AddChildView(welcome_label_);
75
76 if (!search_engine_experiment_) {
77 actions_label_ = new Label(l10n_util::GetString(IDS_FIRSTRUN_DLG_DETAIL));
78 } else {
79 if (importer_host_->GetAvailableProfileCount() > 0) {
80 actions_label_ = new Label(l10n_util::GetStringF(
81 IDS_FIRSTRUN_DLG_ACTION1_ALT,
82 l10n_util::GetString(IDS_PRODUCT_NAME),
83 importer_host_->GetSourceProfileNameAt(0)));
84 actions_label_->SetMultiLine(true);
85 actions_label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
86 actions_label_->SizeToFit(0);
87 } else {
88 NOTREACHED();
89 }
90 }
91
92 actions_label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
93 AddChildView(actions_label_);
94
95 if (!search_engine_experiment_) {
96 // The first action label will tell what we are going to import from which
97 // browser, which we obtain from the ImporterHost. We need that the first
98 // browser profile be the default browser.
99 std::wstring label1;
100 if (importer_host_->GetAvailableProfileCount() > 0) {
101 label1 = l10n_util::GetStringF(IDS_FIRSTRUN_DLG_ACTION1,
102 importer_host_->GetSourceProfileNameAt(0));
103 } else {
104 NOTREACHED();
105 }
106 actions_import_ = new Label(AddBullet(label1));
107 actions_import_->SetMultiLine(true);
108 actions_import_->SetHorizontalAlignment(Label::ALIGN_LEFT);
109 AddChildView(actions_import_);
110 std::wstring label2 = l10n_util::GetString(IDS_FIRSTRUN_DLG_ACTION2);
111 actions_shorcuts_ = new Label(AddBullet(label2));
112 actions_shorcuts_->SetHorizontalAlignment(Label::ALIGN_LEFT);
113 actions_shorcuts_->SetMultiLine(true);
114 AddChildView(actions_shorcuts_);
115 }
116
117 customize_link_ = new Link(l10n_util::GetString(IDS_FIRSTRUN_DLG_OVERRIDE));
118 customize_link_->SetController(this);
119 AddChildView(customize_link_);
120 }
121
122 gfx::Size FirstRunView::GetPreferredSize() {
123 return gfx::Size(views::Window::GetLocalizedContentsSize(
124 IDS_FIRSTRUN_DIALOG_WIDTH_CHARS,
125 IDS_FIRSTRUN_DIALOG_HEIGHT_LINES));
126 }
127
128 void FirstRunView::Layout() {
129 FirstRunViewBase::Layout();
130
131 const int kVertSpacing = 8;
132 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
133
134 gfx::Size pref_size = welcome_label_->GetPreferredSize();
135 // Wrap the label text before we overlap the product icon.
136 int label_width = background_image()->width() -
137 rb.GetBitmapNamed(IDR_WIZARD_ICON)->width() - kPanelHorizMargin;
138 welcome_label_->SetBounds(kPanelHorizMargin, kPanelVertMargin,
139 label_width, pref_size.height());
140 AdjustDialogWidth(welcome_label_);
141
142 int next_v_space = background_image()->y() +
143 background_image()->height() + kPanelVertMargin;
144
145 label_width = width() - (2 * kPanelHorizMargin);
146
147 pref_size = actions_label_->GetPreferredSize();
148 actions_label_->SetBounds(kPanelHorizMargin, next_v_space,
149 label_width, pref_size.height());
150 AdjustDialogWidth(actions_label_);
151
152 next_v_space = actions_label_->y() +
153 actions_label_->height() + kVertSpacing;
154
155 if (!search_engine_experiment_) {
156 int label_height = actions_import_->GetHeightForWidth(label_width);
157 actions_import_->SetBounds(kPanelHorizMargin, next_v_space, label_width,
158 label_height);
159
160 next_v_space = actions_import_->y() +
161 actions_import_->height() + kVertSpacing;
162 AdjustDialogWidth(actions_import_);
163
164 label_height = actions_shorcuts_->GetHeightForWidth(label_width);
165 actions_shorcuts_->SetBounds(kPanelHorizMargin, next_v_space, label_width,
166 label_height);
167 AdjustDialogWidth(actions_shorcuts_);
168
169 next_v_space = actions_shorcuts_->y() +
170 actions_shorcuts_->height() +
171 kUnrelatedControlVerticalSpacing;
172 }
173
174 pref_size = customize_link_->GetPreferredSize();
175 customize_link_->SetBounds(kPanelHorizMargin, next_v_space,
176 pref_size.width(), pref_size.height());
177 }
178
179 void FirstRunView::OpenCustomizeDialog() {
180 // The customize dialog now owns the importer host object.
181 views::Window::CreateChromeWindow(
182 window()->GetNativeWindow(),
183 gfx::Rect(),
184 new FirstRunCustomizeView(profile_,
185 importer_host_,
186 this,
187 default_browser_ && default_browser_->checked(),
188 homepage_defined_,
189 import_items_,
190 dont_import_items_,
191 search_engine_experiment_,
192 randomize_search_engine_experiment_))->Show();
193 }
194
195 void FirstRunView::OpenSearchEngineDialog(bool randomize) {
196 views::Window::CreateChromeWindow(
197 window()->GetNativeWindow(),
198 gfx::Rect(),
199 new FirstRunSearchEngineView(this,
200 profile_,
201 randomize))->Show();
202 }
203
204 void FirstRunView::LinkActivated(views::Link* source, int event_flags) {
205 OpenCustomizeDialog();
206 }
207
208 std::wstring FirstRunView::GetWindowTitle() const {
209 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE);
210 }
211
212 views::View* FirstRunView::GetContentsView() {
213 return this;
214 }
215
216 bool FirstRunView::Accept() {
217 if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK))
218 return false;
219
220 DisableButtons();
221 customize_link_->SetEnabled(false);
222 CreateDesktopShortcut();
223 // Windows 7 has deprecated the quick launch bar.
224 if (win_util::GetWinVersion() < win_util::WINVERSION_WIN7)
225 CreateQuickLaunchShortcut();
226 // Index 0 is the default browser.
227 FirstRun::ImportSettings(profile_,
228 importer_host_->GetSourceProfileInfoAt(0).browser_type,
229 GetImportItems(), window()->GetNativeWindow());
230 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept"), profile_);
231 if (default_browser_ && default_browser_->checked())
232 SetDefaultBrowser();
233
234 // Launch the search engine dialog.
235 if (search_engine_experiment_) {
236 OpenSearchEngineDialog(randomize_search_engine_experiment_);
237 // Leave without shutting down; we'll observe the search engine dialog and
238 // shut down after it closes.
239 return false;
240 }
241
242 accepted_ = true;
243 FirstRunComplete();
244 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
245 return true;
246 }
247
248 bool FirstRunView::Cancel() {
249 UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Cancel"), profile_);
250 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
251 return true;
252 }
253
254 // Notification from the customize dialog that the user accepted. Since all
255 // the work is done there we have nothing else to do.
256 void FirstRunView::CustomizeAccepted() {
257 if (search_engine_experiment_) {
258 OpenSearchEngineDialog(randomize_search_engine_experiment_);
259 // We'll shut down after search engine has been chosen.
260 return;
261 }
262 accepted_ = true;
263 FirstRunComplete();
264 window()->Close();
265 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
266 }
267
268 // Notification from the customize dialog that the user cancelled.
269 void FirstRunView::CustomizeCanceled() {
270 UserMetrics::RecordAction(UserMetricsAction("FirstRunCustom_Cancel"),
271 profile_);
272 }
273
274 void FirstRunView::SearchEngineChosen(const TemplateURL* default_search) {
275 // default_search may be NULL if the user closed the search view without
276 // making a choice, or if a choice was made through the KeywordEditor.
277 if (default_search)
278 profile_->GetTemplateURLModel()->SetDefaultSearchProvider(default_search);
279 accepted_ = true;
280 FirstRunComplete();
281 window()->Close();
282 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
283 }
284
OLDNEW
« no previous file with comments | « chrome/browser/views/first_run_view.h ('k') | chrome/browser/views/first_run_view_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698