| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" | 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 30 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 30 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/base/text/text_elider.h" | 33 #include "ui/base/text/text_elider.h" |
| 34 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/favicon_size.h" |
| 35 | 35 |
| 36 using content::NavigationController; | 36 using content::NavigationController; |
| 37 using content::NavigationEntry; | 37 using content::NavigationEntry; |
| 38 using content::UserMetricsAction; | 38 using content::UserMetricsAction; |
| 39 using content::WebContents; | 39 using content::WebContents; |
| 40 | 40 |
| 41 const int BackForwardMenuModel::kMaxHistoryItems = 12; | 41 const int BackForwardMenuModel::kMaxHistoryItems = 12; |
| 42 const int BackForwardMenuModel::kMaxChapterStops = 5; | 42 const int BackForwardMenuModel::kMaxChapterStops = 5; |
| 43 static const int kMaxWidth = 700; | 43 static const int kMaxWidth = 700; |
| 44 | 44 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // anything. | 243 // anything. |
| 244 if (requested_favicons_.find(entry->GetUniqueID()) != | 244 if (requested_favicons_.find(entry->GetUniqueID()) != |
| 245 requested_favicons_.end()) { | 245 requested_favicons_.end()) { |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 requested_favicons_.insert(entry->GetUniqueID()); | 248 requested_favicons_.insert(entry->GetUniqueID()); |
| 249 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 249 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 250 browser_->profile(), Profile::EXPLICIT_ACCESS); | 250 browser_->profile(), Profile::EXPLICIT_ACCESS); |
| 251 if (!favicon_service) | 251 if (!favicon_service) |
| 252 return; | 252 return; |
| 253 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 253 FaviconService::Handle handle = favicon_service->GetFaviconImageForURL( |
| 254 browser_->profile(), entry->GetURL(), history::FAVICON, &load_consumer_, | 254 browser_->profile(), entry->GetURL(), history::FAVICON, |
| 255 gfx::kFaviconSize, &load_consumer_, |
| 255 base::Bind(&BackForwardMenuModel::OnFavIconDataAvailable, | 256 base::Bind(&BackForwardMenuModel::OnFavIconDataAvailable, |
| 256 base::Unretained(this))); | 257 base::Unretained(this))); |
| 257 load_consumer_.SetClientData(favicon_service, handle, entry->GetUniqueID()); | 258 load_consumer_.SetClientData(favicon_service, handle, entry->GetUniqueID()); |
| 258 } | 259 } |
| 259 | 260 |
| 260 void BackForwardMenuModel::OnFavIconDataAvailable( | 261 void BackForwardMenuModel::OnFavIconDataAvailable( |
| 261 FaviconService::Handle handle, | 262 FaviconService::Handle handle, |
| 262 history::FaviconData favicon) { | 263 const history::FaviconImageResult& image_result) { |
| 263 if (favicon.is_valid()) { | 264 if (!image_result.image.IsEmpty()) { |
| 264 int unique_id = load_consumer_.GetClientDataForCurrentRequest(); | 265 int unique_id = load_consumer_.GetClientDataForCurrentRequest(); |
| 265 // Find the current model_index for the unique_id. | 266 // Find the current model_index for the unique_id. |
| 266 NavigationEntry* entry = NULL; | 267 NavigationEntry* entry = NULL; |
| 267 int model_index = -1; | 268 int model_index = -1; |
| 268 for (int i = 0; i < GetItemCount() - 1; i++) { | 269 for (int i = 0; i < GetItemCount() - 1; i++) { |
| 269 if (IsSeparator(i)) | 270 if (IsSeparator(i)) |
| 270 continue; | 271 continue; |
| 271 if (GetNavigationEntry(i)->GetUniqueID() == unique_id) { | 272 if (GetNavigationEntry(i)->GetUniqueID() == unique_id) { |
| 272 model_index = i; | 273 model_index = i; |
| 273 entry = GetNavigationEntry(i); | 274 entry = GetNavigationEntry(i); |
| 274 break; | 275 break; |
| 275 } | 276 } |
| 276 } | 277 } |
| 277 | 278 |
| 278 if (!entry) | 279 if (!entry) |
| 279 // The NavigationEntry wasn't found, this can happen if the user | 280 // The NavigationEntry wasn't found, this can happen if the user |
| 280 // navigates to another page and a NavigatationEntry falls out of the | 281 // navigates to another page and a NavigatationEntry falls out of the |
| 281 // range of kMaxHistoryItems. | 282 // range of kMaxHistoryItems. |
| 282 return; | 283 return; |
| 283 | 284 |
| 284 // Now that we have a valid NavigationEntry, decode the favicon and assign | 285 // Now that we have a valid NavigationEntry, decode the favicon and assign |
| 285 // it to the NavigationEntry. | 286 // it to the NavigationEntry. |
| 286 gfx::Image icon(favicon.image_data->front(), favicon.image_data->size()); | 287 entry->GetFavicon().valid = true; |
| 287 if (!icon.IsEmpty()) { | 288 entry->GetFavicon().url = image_result.icon_url; |
| 288 entry->GetFavicon().valid = true; | 289 // TODO: Once the history service returns more representations, |
| 289 entry->GetFavicon().url = favicon.icon_url; | 290 // use them all instead of having just the lodpi favicon. |
| 290 // TODO: Once the history service returns more representations, | 291 entry->GetFavicon().image = image_result.image; |
| 291 // use them all instead of having just the lodpi favicon. | 292 if (menu_model_delegate()) { |
| 292 entry->GetFavicon().image = icon; | 293 menu_model_delegate()->OnIconChanged(model_index); |
| 293 if (menu_model_delegate()) { | |
| 294 menu_model_delegate()->OnIconChanged(model_index); | |
| 295 } | |
| 296 } | 294 } |
| 297 } | 295 } |
| 298 } | 296 } |
| 299 | 297 |
| 300 int BackForwardMenuModel::GetHistoryItemCount() const { | 298 int BackForwardMenuModel::GetHistoryItemCount() const { |
| 301 WebContents* contents = GetWebContents(); | 299 WebContents* contents = GetWebContents(); |
| 302 int items = 0; | 300 int items = 0; |
| 303 | 301 |
| 304 if (model_type_ == FORWARD_MENU) { | 302 if (model_type_ == FORWARD_MENU) { |
| 305 // Only count items from n+1 to end (if n is current entry) | 303 // Only count items from n+1 to end (if n is current entry) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 metric_string += "ForwardMenu_"; | 470 metric_string += "ForwardMenu_"; |
| 473 else | 471 else |
| 474 metric_string += "BackMenu_"; | 472 metric_string += "BackMenu_"; |
| 475 metric_string += action; | 473 metric_string += action; |
| 476 if (index != -1) { | 474 if (index != -1) { |
| 477 // +1 is for historical reasons (indices used to start at 1). | 475 // +1 is for historical reasons (indices used to start at 1). |
| 478 metric_string += base::IntToString(index + 1); | 476 metric_string += base::IntToString(index + 1); |
| 479 } | 477 } |
| 480 return metric_string; | 478 return metric_string; |
| 481 } | 479 } |
| OLD | NEW |