OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/custom_home_pages_table_model.h" | 5 #include "chrome/browser/custom_home_pages_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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
13 #include "chrome/browser/pref_service.h" | 13 #include "chrome/browser/pref_service.h" |
14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "gfx/codec/png_codec.h" | 17 #include "gfx/codec/png_codec.h" |
18 #include "grit/app_resources.h" | 18 #include "grit/app_resources.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
21 | 21 |
22 // static | |
23 SkBitmap CustomHomePagesTableModel::default_favicon_; | |
24 | |
25 CustomHomePagesTableModel::CustomHomePagesTableModel(Profile* profile) | 22 CustomHomePagesTableModel::CustomHomePagesTableModel(Profile* profile) |
26 : profile_(profile), | 23 : default_favicon_(NULL), |
| 24 profile_(profile), |
27 observer_(NULL) { | 25 observer_(NULL) { |
28 InitClass(); | 26 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 27 default_favicon_ = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
29 } | 28 } |
30 | 29 |
31 void CustomHomePagesTableModel::SetURLs(const std::vector<GURL>& urls) { | 30 void CustomHomePagesTableModel::SetURLs(const std::vector<GURL>& urls) { |
32 entries_.resize(urls.size()); | 31 entries_.resize(urls.size()); |
33 for (size_t i = 0; i < urls.size(); ++i) { | 32 for (size_t i = 0; i < urls.size(); ++i) { |
34 entries_[i].url = urls[i]; | 33 entries_[i].url = urls[i]; |
35 LoadTitleAndFavIcon(&(entries_[i])); | 34 LoadTitleAndFavIcon(&(entries_[i])); |
36 } | 35 } |
37 // Complete change, so tell the view to just rebuild itself. | 36 // Complete change, so tell the view to just rebuild itself. |
38 if (observer_) | 37 if (observer_) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 101 } |
103 | 102 |
104 std::wstring CustomHomePagesTableModel::GetText(int row, int column_id) { | 103 std::wstring CustomHomePagesTableModel::GetText(int row, int column_id) { |
105 DCHECK(column_id == 0); | 104 DCHECK(column_id == 0); |
106 DCHECK(row >= 0 && row < RowCount()); | 105 DCHECK(row >= 0 && row < RowCount()); |
107 return entries_[row].title.empty() ? FormattedURL(row) : entries_[row].title; | 106 return entries_[row].title.empty() ? FormattedURL(row) : entries_[row].title; |
108 } | 107 } |
109 | 108 |
110 SkBitmap CustomHomePagesTableModel::GetIcon(int row) { | 109 SkBitmap CustomHomePagesTableModel::GetIcon(int row) { |
111 DCHECK(row >= 0 && row < RowCount()); | 110 DCHECK(row >= 0 && row < RowCount()); |
112 return entries_[row].icon.isNull() ? default_favicon_ : entries_[row].icon; | 111 return entries_[row].icon.isNull() ? *default_favicon_ : entries_[row].icon; |
113 } | 112 } |
114 | 113 |
115 std::wstring CustomHomePagesTableModel::GetTooltip(int row) { | 114 std::wstring CustomHomePagesTableModel::GetTooltip(int row) { |
116 return entries_[row].title.empty() ? std::wstring() : | 115 return entries_[row].title.empty() ? std::wstring() : |
117 l10n_util::GetStringF(IDS_OPTIONS_STARTUP_PAGE_TOOLTIP, | 116 l10n_util::GetStringF(IDS_OPTIONS_STARTUP_PAGE_TOOLTIP, |
118 entries_[row].title, FormattedURL(row)); | 117 entries_[row].title, FormattedURL(row)); |
119 } | 118 } |
120 | 119 |
121 void CustomHomePagesTableModel::SetObserver(TableModelObserver* observer) { | 120 void CustomHomePagesTableModel::SetObserver(TableModelObserver* observer) { |
122 observer_ = observer; | 121 observer_ = observer; |
123 } | 122 } |
124 | 123 |
125 void CustomHomePagesTableModel::InitClass() { | |
126 static bool initialized = false; | |
127 if (!initialized) { | |
128 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
129 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | |
130 initialized = true; | |
131 } | |
132 } | |
133 | |
134 void CustomHomePagesTableModel::LoadTitleAndFavIcon(Entry* entry) { | 124 void CustomHomePagesTableModel::LoadTitleAndFavIcon(Entry* entry) { |
135 HistoryService* history_service = | 125 HistoryService* history_service = |
136 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 126 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
137 if (history_service) { | 127 if (history_service) { |
138 entry->title_handle = history_service->QueryURL(entry->url, false, | 128 entry->title_handle = history_service->QueryURL(entry->url, false, |
139 &query_consumer_, | 129 &query_consumer_, |
140 NewCallback(this, &CustomHomePagesTableModel::OnGotTitle)); | 130 NewCallback(this, &CustomHomePagesTableModel::OnGotTitle)); |
141 } | 131 } |
142 FaviconService* favicon_service = | 132 FaviconService* favicon_service = |
143 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 133 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 return NULL; | 202 return NULL; |
213 } | 203 } |
214 | 204 |
215 std::wstring CustomHomePagesTableModel::FormattedURL(int row) const { | 205 std::wstring CustomHomePagesTableModel::FormattedURL(int row) const { |
216 std::wstring languages = | 206 std::wstring languages = |
217 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 207 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
218 std::wstring url(net::FormatUrl(entries_[row].url, languages)); | 208 std::wstring url(net::FormatUrl(entries_[row].url, languages)); |
219 base::i18n::GetDisplayStringInLTRDirectionality(&url); | 209 base::i18n::GetDisplayStringInLTRDirectionality(&url); |
220 return url; | 210 return url; |
221 } | 211 } |
OLD | NEW |