summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/first_run_view.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views/first_run_view.cc')
-rw-r--r--chrome/browser/views/first_run_view.cc140
1 files changed, 100 insertions, 40 deletions
diff --git a/chrome/browser/views/first_run_view.cc b/chrome/browser/views/first_run_view.cc
index 2ba4bcd..23eb645 100644
--- a/chrome/browser/views/first_run_view.cc
+++ b/chrome/browser/views/first_run_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,11 @@
#include "chrome/browser/importer/importer.h"
#include "chrome/browser/first_run.h"
#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/views/first_run_customize_view.h"
+#include "chrome/browser/views/first_run_search_engine_view.h"
#include "chrome/installer/util/browser_distribution.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -35,9 +39,10 @@ std::wstring AddBullet(const std::wstring& text) {
} // namespace
FirstRunView::FirstRunView(Profile* profile, bool homepage_defined,
- int import_items, int dont_import_items)
+ int import_items, int dont_import_items,
+ bool search_engine_experiment)
: FirstRunViewBase(profile, homepage_defined, import_items,
- dont_import_items),
+ dont_import_items, search_engine_experiment),
welcome_label_(NULL),
actions_label_(NULL),
actions_import_(NULL),
@@ -66,31 +71,47 @@ void FirstRunView::SetupControls() {
welcome_label_->SizeToFit(0);
AddChildView(welcome_label_);
- actions_label_ = new Label(l10n_util::GetString(IDS_FIRSTRUN_DLG_DETAIL));
+ if (!search_engine_experiment_) {
+ actions_label_ = new Label(l10n_util::GetString(IDS_FIRSTRUN_DLG_DETAIL));
+ } else {
+ if (importer_host_->GetAvailableProfileCount() > 0) {
+ actions_label_ = new Label(l10n_util::GetStringF(
+ IDS_FIRSTRUN_DLG_ACTION1_ALT,
+ l10n_util::GetString(IDS_PRODUCT_NAME),
+ importer_host_->GetSourceProfileNameAt(0)));
+ actions_label_->SetMultiLine(true);
+ actions_label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
+ actions_label_->SizeToFit(0);
+ } else {
+ NOTREACHED();
+ }
+ }
+
actions_label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
AddChildView(actions_label_);
- // The first action label will tell what we are going to import from which
- // browser, which we obtain from the ImporterHost. We need that the first
- // browser profile be the default browser.
- std::wstring label1;
- if (importer_host_->GetAvailableProfileCount() > 0) {
- label1 = l10n_util::GetStringF(IDS_FIRSTRUN_DLG_ACTION1,
- importer_host_->GetSourceProfileNameAt(0));
- } else {
- NOTREACHED();
+ if (!search_engine_experiment_) {
+ // The first action label will tell what we are going to import from which
+ // browser, which we obtain from the ImporterHost. We need that the first
+ // browser profile be the default browser.
+ std::wstring label1;
+ if (importer_host_->GetAvailableProfileCount() > 0) {
+ label1 = l10n_util::GetStringF(IDS_FIRSTRUN_DLG_ACTION1,
+ importer_host_->GetSourceProfileNameAt(0));
+ } else {
+ NOTREACHED();
+ }
+ actions_import_ = new Label(AddBullet(label1));
+ actions_import_->SetMultiLine(true);
+ actions_import_->SetHorizontalAlignment(Label::ALIGN_LEFT);
+ AddChildView(actions_import_);
+ std::wstring label2 = l10n_util::GetString(IDS_FIRSTRUN_DLG_ACTION2);
+ actions_shorcuts_ = new Label(AddBullet(label2));
+ actions_shorcuts_->SetHorizontalAlignment(Label::ALIGN_LEFT);
+ actions_shorcuts_->SetMultiLine(true);
+ AddChildView(actions_shorcuts_);
}
- actions_import_ = new Label(AddBullet(label1));
- actions_import_->SetMultiLine(true);
- actions_import_->SetHorizontalAlignment(Label::ALIGN_LEFT);
- AddChildView(actions_import_);
- std::wstring label2 = l10n_util::GetString(IDS_FIRSTRUN_DLG_ACTION2);
- actions_shorcuts_ = new Label(AddBullet(label2));
- actions_shorcuts_->SetHorizontalAlignment(Label::ALIGN_LEFT);
- actions_shorcuts_->SetMultiLine(true);
- AddChildView(actions_shorcuts_);
-
customize_link_ = new Link(l10n_util::GetString(IDS_FIRSTRUN_DLG_OVERRIDE));
customize_link_->SetController(this);
AddChildView(customize_link_);
@@ -119,31 +140,34 @@ void FirstRunView::Layout() {
int next_v_space = background_image()->y() +
background_image()->height() + kPanelVertMargin;
+ label_width = width() - (2 * kPanelHorizMargin);
+
pref_size = actions_label_->GetPreferredSize();
actions_label_->SetBounds(kPanelHorizMargin, next_v_space,
- pref_size.width(), pref_size.height());
+ label_width, pref_size.height());
AdjustDialogWidth(actions_label_);
next_v_space = actions_label_->y() +
actions_label_->height() + kVertSpacing;
- label_width = width() - (2 * kPanelHorizMargin);
- int label_height = actions_import_->GetHeightForWidth(label_width);
- actions_import_->SetBounds(kPanelHorizMargin, next_v_space, label_width,
- label_height);
+ if (!search_engine_experiment_) {
+ int label_height = actions_import_->GetHeightForWidth(label_width);
+ actions_import_->SetBounds(kPanelHorizMargin, next_v_space, label_width,
+ label_height);
- next_v_space = actions_import_->y() +
- actions_import_->height() + kVertSpacing;
- AdjustDialogWidth(actions_import_);
+ next_v_space = actions_import_->y() +
+ actions_import_->height() + kVertSpacing;
+ AdjustDialogWidth(actions_import_);
- label_height = actions_shorcuts_->GetHeightForWidth(label_width);
- actions_shorcuts_->SetBounds(kPanelHorizMargin, next_v_space, label_width,
- label_height);
- AdjustDialogWidth(actions_shorcuts_);
+ label_height = actions_shorcuts_->GetHeightForWidth(label_width);
+ actions_shorcuts_->SetBounds(kPanelHorizMargin, next_v_space, label_width,
+ label_height);
+ AdjustDialogWidth(actions_shorcuts_);
- next_v_space = actions_shorcuts_->y() +
- actions_shorcuts_->height() +
- kUnrelatedControlVerticalSpacing;
+ next_v_space = actions_shorcuts_->y() +
+ actions_shorcuts_->height() +
+ kUnrelatedControlVerticalSpacing;
+ }
pref_size = customize_link_->GetPreferredSize();
customize_link_->SetBounds(kPanelHorizMargin, next_v_space,
@@ -161,7 +185,16 @@ void FirstRunView::OpenCustomizeDialog() {
default_browser_ && default_browser_->checked(),
homepage_defined_,
import_items_,
- dont_import_items_))->Show();
+ dont_import_items_,
+ search_engine_experiment_))->Show();
+}
+
+void FirstRunView::OpenSearchEngineDialog() {
+ views::Window::CreateChromeWindow(
+ window()->GetNativeWindow(),
+ gfx::Rect(),
+ new FirstRunSearchEngineView(this,
+ profile_))->Show();
}
void FirstRunView::LinkActivated(views::Link* source, int event_flags) {
@@ -194,6 +227,14 @@ bool FirstRunView::Accept() {
if (default_browser_ && default_browser_->checked())
SetDefaultBrowser();
+ // Launch the search engine dialog.
+ if (search_engine_experiment_) {
+ OpenSearchEngineDialog();
+ // Leave without shutting down; we'll observe the search engine dialog and
+ // shut down after it closes.
+ return false;
+ }
+
accepted_ = true;
FirstRunComplete();
MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
@@ -207,10 +248,17 @@ bool FirstRunView::Cancel() {
}
// Notification from the customize dialog that the user accepted. Since all
-// the work is done there we got nothing else to do.
+// the work is done there we have nothing else to do.
void FirstRunView::CustomizeAccepted() {
+ if (search_engine_experiment_) {
+ OpenSearchEngineDialog();
+ // We'll shut down after search engine has been chosen.
+ return;
+ }
accepted_ = true;
+ FirstRunComplete();
window()->Close();
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
}
// Notification from the customize dialog that the user cancelled.
@@ -218,3 +266,15 @@ void FirstRunView::CustomizeCanceled() {
UserMetrics::RecordAction(UserMetricsAction("FirstRunCustom_Cancel"),
profile_);
}
+
+void FirstRunView::SearchEngineChosen(const TemplateURL* default_search) {
+ // default_search may be NULL if the user closed the search view without
+ // making a choice, or if a choice was made through the KeywordEditor.
+ if (default_search)
+ profile_->GetTemplateURLModel()->SetDefaultSearchProvider(default_search);
+ accepted_ = true;
+ FirstRunComplete();
+ window()->Close();
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+}
+