OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/default_search_view.h" | 5 #include "chrome/browser/ui/views/default_search_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "views/controls/image_view.h" | 23 #include "views/controls/image_view.h" |
24 #include "views/controls/label.h" | 24 #include "views/controls/label.h" |
25 #include "views/layout/grid_layout.h" | 25 #include "views/layout/grid_layout.h" |
26 #include "views/layout/layout_constants.h" | 26 #include "views/layout/layout_constants.h" |
27 #include "views/window/dialog_client_view.h" | 27 #include "views/window/dialog_client_view.h" |
28 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Returns a short name and logo resource id for the given host. | 32 // Returns a short name and logo resource id for the given host. |
33 void GetShortNameAndLogoId(PrefService* prefs, | 33 void GetShortNameAndLogoId(Profile* profile, |
34 const TemplateURL* turl, | 34 const TemplateURL* turl, |
35 std::wstring* short_name, | 35 std::wstring* short_name, |
36 int* logo_id) { | 36 int* logo_id) { |
37 DCHECK(prefs); | 37 DCHECK(profile); |
38 DCHECK(turl); | 38 DCHECK(turl); |
39 DCHECK(short_name); | 39 DCHECK(short_name); |
40 DCHECK(logo_id); | 40 DCHECK(logo_id); |
41 | 41 |
42 GURL url = TemplateURLService::GenerateSearchURL(turl); | 42 PrefService* prefs = profile->GetPrefs(); |
| 43 DCHECK(prefs); |
| 44 |
| 45 GURL url = TemplateURLService::GenerateSearchURL(profile, turl); |
43 scoped_ptr<TemplateURL> built_in_data( | 46 scoped_ptr<TemplateURL> built_in_data( |
44 TemplateURLPrepopulateData::GetEngineForOrigin(prefs, url)); | 47 TemplateURLPrepopulateData::GetEngineForOrigin(prefs, url)); |
45 | 48 |
46 // Use the built-in information to generate the short name (to ensure | 49 // Use the built-in information to generate the short name (to ensure |
47 // that we don't use a name given by the search engine to itself which | 50 // that we don't use a name given by the search engine to itself which |
48 // in the worst case could be misleading). | 51 // in the worst case could be misleading). |
49 if (built_in_data.get()) { | 52 if (built_in_data.get()) { |
50 *short_name = built_in_data->short_name(); | 53 *short_name = built_in_data->short_name(); |
51 *logo_id = built_in_data->logo_id(); | 54 *logo_id = built_in_data->logo_id(); |
52 } else { | 55 } else { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 DefaultSearchView::DefaultSearchView(TabContents* tab_contents, | 185 DefaultSearchView::DefaultSearchView(TabContents* tab_contents, |
183 TemplateURL* proposed_default_turl, | 186 TemplateURL* proposed_default_turl, |
184 TemplateURLService* template_url_service) | 187 TemplateURLService* template_url_service) |
185 : background_image_(NULL), | 188 : background_image_(NULL), |
186 default_provider_button_(NULL), | 189 default_provider_button_(NULL), |
187 proposed_provider_button_(NULL), | 190 proposed_provider_button_(NULL), |
188 proposed_turl_(proposed_default_turl), | 191 proposed_turl_(proposed_default_turl), |
189 template_url_service_(template_url_service) { | 192 template_url_service_(template_url_service) { |
190 Profile* profile = | 193 Profile* profile = |
191 Profile::FromBrowserContext(tab_contents->browser_context()); | 194 Profile::FromBrowserContext(tab_contents->browser_context()); |
192 PrefService* prefs = profile->GetPrefs(); | 195 SetupControls(profile); |
193 SetupControls(prefs); | |
194 | 196 |
195 // Show the dialog. | 197 // Show the dialog. |
196 tab_contents->CreateConstrainedDialog(this); | 198 tab_contents->CreateConstrainedDialog(this); |
197 } | 199 } |
198 | 200 |
199 void DefaultSearchView::SetupControls(PrefService* prefs) { | 201 void DefaultSearchView::SetupControls(Profile* profile) { |
200 using views::ColumnSet; | 202 using views::ColumnSet; |
201 using views::GridLayout; | 203 using views::GridLayout; |
202 using views::ImageView; | 204 using views::ImageView; |
203 using views::Label; | 205 using views::Label; |
204 | 206 |
205 // Column set id's. | 207 // Column set id's. |
206 const int kWholeDialogViewSetId = 0; | 208 const int kWholeDialogViewSetId = 0; |
207 const int kPaddedWholeDialogViewSetId = 1; | 209 const int kPaddedWholeDialogViewSetId = 1; |
208 const int kChoicesViewSetId = 2; | 210 const int kChoicesViewSetId = 2; |
209 | 211 |
210 // Set up the information for the proposed default. | 212 // Set up the information for the proposed default. |
211 std::wstring proposed_short_name; | 213 std::wstring proposed_short_name; |
212 int proposed_logo_id = kNoSearchEngineLogo; | 214 int proposed_logo_id = kNoSearchEngineLogo; |
213 GetShortNameAndLogoId(prefs, | 215 GetShortNameAndLogoId(profile, |
214 proposed_turl_.get(), | 216 proposed_turl_.get(), |
215 &proposed_short_name, | 217 &proposed_short_name, |
216 &proposed_logo_id); | 218 &proposed_logo_id); |
217 if (proposed_logo_id != kNoSearchEngineLogo) | 219 if (proposed_logo_id != kNoSearchEngineLogo) |
218 proposed_turl_->set_logo_id(proposed_logo_id); | 220 proposed_turl_->set_logo_id(proposed_logo_id); |
219 | 221 |
220 | 222 |
221 // Set up the information for the current default. | 223 // Set up the information for the current default. |
222 std::wstring default_short_name; | 224 std::wstring default_short_name; |
223 int default_logo_id = kNoSearchEngineLogo; | 225 int default_logo_id = kNoSearchEngineLogo; |
224 GetShortNameAndLogoId(prefs, | 226 GetShortNameAndLogoId(profile, |
225 template_url_service_->GetDefaultSearchProvider(), | 227 template_url_service_->GetDefaultSearchProvider(), |
226 &default_short_name, | 228 &default_short_name, |
227 &default_logo_id); | 229 &default_logo_id); |
228 | 230 |
229 // Now set-up the dialog contents. | 231 // Now set-up the dialog contents. |
230 GridLayout* layout = new views::GridLayout(this); | 232 GridLayout* layout = new views::GridLayout(this); |
231 layout->SetInsets(0, 0, views::kPanelVertMargin, 0); | 233 layout->SetInsets(0, 0, views::kPanelVertMargin, 0); |
232 SetLayoutManager(layout); | 234 SetLayoutManager(layout); |
233 | 235 |
234 // Add a column set that spans the whole dialog. | 236 // Add a column set that spans the whole dialog. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 this, | 305 this, |
304 IDS_DEFAULT_SEARCH_PROMPT_CURRENT, | 306 IDS_DEFAULT_SEARCH_PROMPT_CURRENT, |
305 default_short_name); | 307 default_short_name); |
306 layout->AddView(default_provider_button_); | 308 layout->AddView(default_provider_button_); |
307 proposed_provider_button_ = CreateProviderChoiceButton( | 309 proposed_provider_button_ = CreateProviderChoiceButton( |
308 this, | 310 this, |
309 IDS_DEFAULT_SEARCH_PROMPT_PROPOSED, | 311 IDS_DEFAULT_SEARCH_PROMPT_PROPOSED, |
310 proposed_short_name); | 312 proposed_short_name); |
311 layout->AddView(proposed_provider_button_); | 313 layout->AddView(proposed_provider_button_); |
312 } | 314 } |
OLD | NEW |