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 "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 157 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
158 if (history_service) { | 158 if (history_service) { |
159 entry->title_handle = history_service->QueryURL(entry->url, false, | 159 entry->title_handle = history_service->QueryURL(entry->url, false, |
160 &query_consumer_, | 160 &query_consumer_, |
161 NewCallback(this, &CustomHomePagesTableModel::OnGotTitle)); | 161 NewCallback(this, &CustomHomePagesTableModel::OnGotTitle)); |
162 } | 162 } |
163 FaviconService* favicon_service = | 163 FaviconService* favicon_service = |
164 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 164 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
165 if (favicon_service) { | 165 if (favicon_service) { |
166 entry->favicon_handle = favicon_service->GetFaviconForURL(entry->url, | 166 entry->favicon_handle = favicon_service->GetFaviconForURL(entry->url, |
167 &query_consumer_, | 167 history::FAVICON, &query_consumer_, |
168 NewCallback(this, &CustomHomePagesTableModel::OnGotFavIcon)); | 168 NewCallback(this, &CustomHomePagesTableModel::OnGotFavIcon)); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 void CustomHomePagesTableModel::OnGotTitle(HistoryService::Handle handle, | 172 void CustomHomePagesTableModel::OnGotTitle(HistoryService::Handle handle, |
173 bool found_url, | 173 bool found_url, |
174 const history::URLRow* row, | 174 const history::URLRow* row, |
175 history::VisitVector* visits) { | 175 history::VisitVector* visits) { |
176 int entry_index; | 176 int entry_index; |
177 Entry* entry = | 177 Entry* entry = |
178 GetEntryByLoadHandle(&Entry::title_handle, handle, &entry_index); | 178 GetEntryByLoadHandle(&Entry::title_handle, handle, &entry_index); |
179 if (!entry) { | 179 if (!entry) { |
180 // The URLs changed before we were called back. | 180 // The URLs changed before we were called back. |
181 return; | 181 return; |
182 } | 182 } |
183 entry->title_handle = 0; | 183 entry->title_handle = 0; |
184 if (found_url && !row->title().empty()) { | 184 if (found_url && !row->title().empty()) { |
185 entry->title = row->title(); | 185 entry->title = row->title(); |
186 if (observer_) | 186 if (observer_) |
187 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); | 187 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void CustomHomePagesTableModel::OnGotFavIcon( | 191 void CustomHomePagesTableModel::OnGotFavIcon( |
192 FaviconService::Handle handle, | 192 FaviconService::Handle handle, |
193 bool know_favicon, | 193 history::FaviconData favicon) { |
194 scoped_refptr<RefCountedMemory> image_data, | |
195 bool is_expired, | |
196 GURL icon_url) { | |
197 int entry_index; | 194 int entry_index; |
198 Entry* entry = | 195 Entry* entry = |
199 GetEntryByLoadHandle(&Entry::favicon_handle, handle, &entry_index); | 196 GetEntryByLoadHandle(&Entry::favicon_handle, handle, &entry_index); |
200 if (!entry) { | 197 if (!entry) { |
201 // The URLs changed before we were called back. | 198 // The URLs changed before we were called back. |
202 return; | 199 return; |
203 } | 200 } |
204 entry->favicon_handle = 0; | 201 entry->favicon_handle = 0; |
205 if (know_favicon && image_data.get() && image_data->size()) { | 202 if (favicon.is_valid()) { |
206 int width, height; | 203 int width, height; |
207 std::vector<unsigned char> decoded_data; | 204 std::vector<unsigned char> decoded_data; |
208 if (gfx::PNGCodec::Decode(image_data->front(), | 205 if (gfx::PNGCodec::Decode(favicon.image_data->front(), |
209 image_data->size(), | 206 favicon.image_data->size(), |
210 gfx::PNGCodec::FORMAT_BGRA, &decoded_data, | 207 gfx::PNGCodec::FORMAT_BGRA, &decoded_data, |
211 &width, &height)) { | 208 &width, &height)) { |
212 entry->icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 209 entry->icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
213 entry->icon.allocPixels(); | 210 entry->icon.allocPixels(); |
214 memcpy(entry->icon.getPixels(), &decoded_data.front(), | 211 memcpy(entry->icon.getPixels(), &decoded_data.front(), |
215 width * height * 4); | 212 width * height * 4); |
216 if (observer_) | 213 if (observer_) |
217 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); | 214 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); |
218 } | 215 } |
219 } | 216 } |
(...skipping 13 matching lines...) Expand all Loading... |
233 return NULL; | 230 return NULL; |
234 } | 231 } |
235 | 232 |
236 string16 CustomHomePagesTableModel::FormattedURL(int row) const { | 233 string16 CustomHomePagesTableModel::FormattedURL(int row) const { |
237 std::string languages = | 234 std::string languages = |
238 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 235 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
239 string16 url = net::FormatUrl(entries_[row].url, languages); | 236 string16 url = net::FormatUrl(entries_[row].url, languages); |
240 url = base::i18n::GetDisplayStringInLTRDirectionality(url); | 237 url = base::i18n::GetDisplayStringInLTRDirectionality(url); |
241 return url; | 238 return url; |
242 } | 239 } |
OLD | NEW |