| 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->fav_icon_handle = favicon_service->GetFaviconForURL(entry->url, | 166 entry->fav_icon_handle = favicon_service->GetFaviconForURL(entry->url, |
| 167 &query_consumer_, | 167 history::FAV_ICON, &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_fav_icon, | 193 FaviconService::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::fav_icon_handle, handle, &entry_index); | 196 GetEntryByLoadHandle(&Entry::fav_icon_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->fav_icon_handle = 0; | 201 entry->fav_icon_handle = 0; |
| 205 if (know_fav_icon && image_data.get() && image_data->size()) { | 202 if (favicon.known_icon && favicon.image_data.get() && |
| 203 favicon.image_data->size()) { |
| 206 int width, height; | 204 int width, height; |
| 207 std::vector<unsigned char> decoded_data; | 205 std::vector<unsigned char> decoded_data; |
| 208 if (gfx::PNGCodec::Decode(image_data->front(), | 206 if (gfx::PNGCodec::Decode(favicon.image_data->front(), |
| 209 image_data->size(), | 207 favicon.image_data->size(), |
| 210 gfx::PNGCodec::FORMAT_BGRA, &decoded_data, | 208 gfx::PNGCodec::FORMAT_BGRA, &decoded_data, |
| 211 &width, &height)) { | 209 &width, &height)) { |
| 212 entry->icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 210 entry->icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 213 entry->icon.allocPixels(); | 211 entry->icon.allocPixels(); |
| 214 memcpy(entry->icon.getPixels(), &decoded_data.front(), | 212 memcpy(entry->icon.getPixels(), &decoded_data.front(), |
| 215 width * height * 4); | 213 width * height * 4); |
| 216 if (observer_) | 214 if (observer_) |
| 217 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); | 215 observer_->OnItemsChanged(static_cast<int>(entry_index), 1); |
| 218 } | 216 } |
| 219 } | 217 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 233 return NULL; | 231 return NULL; |
| 234 } | 232 } |
| 235 | 233 |
| 236 string16 CustomHomePagesTableModel::FormattedURL(int row) const { | 234 string16 CustomHomePagesTableModel::FormattedURL(int row) const { |
| 237 std::string languages = | 235 std::string languages = |
| 238 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 236 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 239 string16 url = net::FormatUrl(entries_[row].url, languages); | 237 string16 url = net::FormatUrl(entries_[row].url, languages); |
| 240 url = base::i18n::GetDisplayStringInLTRDirectionality(url); | 238 url = base::i18n::GetDisplayStringInLTRDirectionality(url); |
| 241 return url; | 239 return url; |
| 242 } | 240 } |
| OLD | NEW |