| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/search_engines/template_url_table_model.h" | 5 #include "chrome/browser/ui/search_engines/template_url_table_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/favicon/favicon_service.h" | 12 #include "chrome/browser/favicon/favicon_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
| 15 #include "chrome/browser/search_engines/template_url_service.h" | 15 #include "chrome/browser/search_engines/template_url_service.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/models/table_model_observer.h" | 20 #include "ui/base/models/table_model_observer.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/codec/png_codec.h" | 22 #include "ui/gfx/codec/png_codec.h" |
| 23 #include "ui/gfx/image/image_skia.h" |
| 23 | 24 |
| 24 // Group IDs used by TemplateURLTableModel. | 25 // Group IDs used by TemplateURLTableModel. |
| 25 static const int kMainGroupID = 0; | 26 static const int kMainGroupID = 0; |
| 26 static const int kOtherGroupID = 1; | 27 static const int kOtherGroupID = 1; |
| 27 | 28 |
| 28 // ModelEntry ---------------------------------------------------- | 29 // ModelEntry ---------------------------------------------------- |
| 29 | 30 |
| 30 // ModelEntry wraps a TemplateURL as returned from the TemplateURL. | 31 // ModelEntry wraps a TemplateURL as returned from the TemplateURL. |
| 31 // ModelEntry also tracks state information about the URL. | 32 // ModelEntry also tracks state information about the URL. |
| 32 | 33 |
| 33 // Icon used while loading, or if a specific favicon can't be found. | 34 // Icon used while loading, or if a specific favicon can't be found. |
| 34 static SkBitmap* default_icon = NULL; | 35 static SkBitmap* default_icon = NULL; |
| 35 | 36 |
| 36 class ModelEntry { | 37 class ModelEntry { |
| 37 public: | 38 public: |
| 38 ModelEntry(TemplateURLTableModel* model, TemplateURL* template_url) | 39 ModelEntry(TemplateURLTableModel* model, TemplateURL* template_url) |
| 39 : template_url_(template_url), | 40 : template_url_(template_url), |
| 40 load_state_(NOT_LOADED), | 41 load_state_(NOT_LOADED), |
| 41 model_(model) { | 42 model_(model) { |
| 42 if (!default_icon) { | 43 if (!default_icon) { |
| 43 default_icon = ResourceBundle::GetSharedInstance(). | 44 default_icon = ResourceBundle::GetSharedInstance(). |
| 44 GetBitmapNamed(IDR_DEFAULT_FAVICON); | 45 GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 TemplateURL* template_url() { | 49 TemplateURL* template_url() { |
| 49 return template_url_; | 50 return template_url_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 SkBitmap GetIcon() { | 53 gfx::ImageSkia GetIcon() { |
| 53 if (load_state_ == NOT_LOADED) | 54 if (load_state_ == NOT_LOADED) |
| 54 LoadFavicon(); | 55 LoadFavicon(); |
| 55 if (!favicon_.isNull()) | 56 if (!favicon_.isNull()) |
| 56 return favicon_; | 57 return favicon_; |
| 57 return *default_icon; | 58 return *default_icon; |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Resets internal status so that the next time the icon is asked for its | 61 // Resets internal status so that the next time the icon is asked for its |
| 61 // fetched again. This should be invoked if the url is modified. | 62 // fetched again. This should be invoked if the url is modified. |
| 62 void ResetIcon() { | 63 void ResetIcon() { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return (template_url_service_->GetDefaultSearchProvider() == url) ? | 187 return (template_url_service_->GetDefaultSearchProvider() == url) ? |
| 187 l10n_util::GetStringFUTF16(IDS_SEARCH_ENGINES_EDITOR_DEFAULT_ENGINE, | 188 l10n_util::GetStringFUTF16(IDS_SEARCH_ENGINES_EDITOR_DEFAULT_ENGINE, |
| 188 url_short_name) : url_short_name; | 189 url_short_name) : url_short_name; |
| 189 } | 190 } |
| 190 | 191 |
| 191 DCHECK_EQ(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN, col_id); | 192 DCHECK_EQ(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN, col_id); |
| 192 // Keyword should be domain name. Force it to have LTR directionality. | 193 // Keyword should be domain name. Force it to have LTR directionality. |
| 193 return base::i18n::GetDisplayStringInLTRDirectionality(url->keyword()); | 194 return base::i18n::GetDisplayStringInLTRDirectionality(url->keyword()); |
| 194 } | 195 } |
| 195 | 196 |
| 196 SkBitmap TemplateURLTableModel::GetIcon(int row) { | 197 gfx::ImageSkia TemplateURLTableModel::GetIcon(int row) { |
| 197 DCHECK(row >= 0 && row < RowCount()); | 198 DCHECK(row >= 0 && row < RowCount()); |
| 198 return entries_[row]->GetIcon(); | 199 return entries_[row]->GetIcon(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 void TemplateURLTableModel::SetObserver(ui::TableModelObserver* observer) { | 202 void TemplateURLTableModel::SetObserver(ui::TableModelObserver* observer) { |
| 202 observer_ = observer; | 203 observer_ = observer; |
| 203 } | 204 } |
| 204 | 205 |
| 205 bool TemplateURLTableModel::HasGroups() { | 206 bool TemplateURLTableModel::HasGroups() { |
| 206 return true; | 207 return true; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { | 366 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { |
| 366 std::vector<ModelEntry*>::iterator i = | 367 std::vector<ModelEntry*>::iterator i = |
| 367 std::find(entries_.begin(), entries_.end(), entry); | 368 std::find(entries_.begin(), entries_.end(), entry); |
| 368 DCHECK(i != entries_.end()); | 369 DCHECK(i != entries_.end()); |
| 369 NotifyChanged(static_cast<int>(i - entries_.begin())); | 370 NotifyChanged(static_cast<int>(i - entries_.begin())); |
| 370 } | 371 } |
| 371 | 372 |
| 372 void TemplateURLTableModel::OnTemplateURLServiceChanged() { | 373 void TemplateURLTableModel::OnTemplateURLServiceChanged() { |
| 373 Reload(); | 374 Reload(); |
| 374 } | 375 } |
| OLD | NEW |