OLD | NEW |
1 // Copyright (c) 2010 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/search_engines/template_url_table_model.h" | 5 #include "chrome/browser/search_engines/template_url_table_model.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/table_model_observer.h" | 9 #include "app/table_model_observer.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 int TemplateURLTableModel::RowCount() { | 173 int TemplateURLTableModel::RowCount() { |
174 return static_cast<int>(entries_.size()); | 174 return static_cast<int>(entries_.size()); |
175 } | 175 } |
176 | 176 |
177 string16 TemplateURLTableModel::GetText(int row, int col_id) { | 177 string16 TemplateURLTableModel::GetText(int row, int col_id) { |
178 DCHECK(row >= 0 && row < RowCount()); | 178 DCHECK(row >= 0 && row < RowCount()); |
179 const TemplateURL& url = entries_[row]->template_url(); | 179 const TemplateURL& url = entries_[row]->template_url(); |
180 | 180 |
181 switch (col_id) { | 181 switch (col_id) { |
182 case IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN: { | 182 case IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN: { |
183 string16 url_short_name = WideToUTF16Hack(url.short_name()); | 183 string16 url_short_name = url.short_name(); |
184 // TODO(xji): Consider adding a special case if the short name is a URL, | 184 // TODO(xji): Consider adding a special case if the short name is a URL, |
185 // since those should always be displayed LTR. Please refer to | 185 // since those should always be displayed LTR. Please refer to |
186 // http://crbug.com/6726 for more information. | 186 // http://crbug.com/6726 for more information. |
187 base::i18n::AdjustStringForLocaleDirection(&url_short_name); | 187 base::i18n::AdjustStringForLocaleDirection(&url_short_name); |
188 if (template_url_model_->GetDefaultSearchProvider() == &url) { | 188 if (template_url_model_->GetDefaultSearchProvider() == &url) { |
189 return l10n_util::GetStringFUTF16( | 189 return l10n_util::GetStringFUTF16( |
190 IDS_SEARCH_ENGINES_EDITOR_DEFAULT_ENGINE, | 190 IDS_SEARCH_ENGINES_EDITOR_DEFAULT_ENGINE, |
191 url_short_name); | 191 url_short_name); |
192 } | 192 } |
193 return url_short_name; | 193 return url_short_name; |
194 } | 194 } |
195 | 195 |
196 case IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN: { | 196 case IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN: { |
197 // Keyword should be domain name. Force it to have LTR directionality. | 197 // Keyword should be domain name. Force it to have LTR directionality. |
198 string16 keyword = WideToUTF16(url.keyword()); | 198 string16 keyword = url.keyword(); |
199 keyword = base::i18n::GetDisplayStringInLTRDirectionality(keyword); | 199 keyword = base::i18n::GetDisplayStringInLTRDirectionality(keyword); |
200 return keyword; | 200 return keyword; |
201 } | 201 } |
202 | 202 |
203 default: | 203 default: |
204 NOTREACHED(); | 204 NOTREACHED(); |
205 return string16(); | 205 return string16(); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 template_url_model_->AddObserver(this); | 272 template_url_model_->AddObserver(this); |
273 } | 273 } |
274 | 274 |
275 void TemplateURLTableModel::ModifyTemplateURL(int index, | 275 void TemplateURLTableModel::ModifyTemplateURL(int index, |
276 const string16& title, | 276 const string16& title, |
277 const string16& keyword, | 277 const string16& keyword, |
278 const std::string& url) { | 278 const std::string& url) { |
279 DCHECK(index >= 0 && index <= RowCount()); | 279 DCHECK(index >= 0 && index <= RowCount()); |
280 const TemplateURL* template_url = &GetTemplateURL(index); | 280 const TemplateURL* template_url = &GetTemplateURL(index); |
281 template_url_model_->RemoveObserver(this); | 281 template_url_model_->RemoveObserver(this); |
282 template_url_model_->ResetTemplateURL(template_url, UTF16ToWideHack(title), | 282 template_url_model_->ResetTemplateURL(template_url, title, keyword, url); |
283 UTF16ToWideHack(keyword), url); | |
284 if (template_url_model_->GetDefaultSearchProvider() == template_url && | 283 if (template_url_model_->GetDefaultSearchProvider() == template_url && |
285 !TemplateURL::SupportsReplacement(template_url)) { | 284 !TemplateURL::SupportsReplacement(template_url)) { |
286 // The entry was the default search provider, but the url has been modified | 285 // The entry was the default search provider, but the url has been modified |
287 // so that it no longer supports replacement. Reset the default search | 286 // so that it no longer supports replacement. Reset the default search |
288 // provider so that it doesn't point to a bogus entry. | 287 // provider so that it doesn't point to a bogus entry. |
289 template_url_model_->SetDefaultSearchProvider(NULL); | 288 template_url_model_->SetDefaultSearchProvider(NULL); |
290 } | 289 } |
291 template_url_model_->AddObserver(this); | 290 template_url_model_->AddObserver(this); |
292 ReloadIcon(index); // Also calls NotifyChanged(). | 291 ReloadIcon(index); // Also calls NotifyChanged(). |
293 } | 292 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 void TemplateURLTableModel::FavIconAvailable(ModelEntry* entry) { | 372 void TemplateURLTableModel::FavIconAvailable(ModelEntry* entry) { |
374 std::vector<ModelEntry*>::iterator i = | 373 std::vector<ModelEntry*>::iterator i = |
375 find(entries_.begin(), entries_.end(), entry); | 374 find(entries_.begin(), entries_.end(), entry); |
376 DCHECK(i != entries_.end()); | 375 DCHECK(i != entries_.end()); |
377 NotifyChanged(static_cast<int>(i - entries_.begin())); | 376 NotifyChanged(static_cast<int>(i - entries_.begin())); |
378 } | 377 } |
379 | 378 |
380 void TemplateURLTableModel::OnTemplateURLModelChanged() { | 379 void TemplateURLTableModel::OnTemplateURLModelChanged() { |
381 Reload(); | 380 Reload(); |
382 } | 381 } |
OLD | NEW |