| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "chrome/browser/event_disposition.h" | 12 #include "chrome/browser/event_disposition.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "content/browser/tab_contents/navigation_controller.h" | 18 #include "content/browser/tab_contents/navigation_controller.h" |
| 19 #include "content/browser/tab_contents/navigation_entry.h" | 19 #include "content/browser/tab_contents/navigation_entry.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 24 #include "grit/theme_resources_standard.h" | 24 #include "grit/theme_resources_standard.h" |
| 25 #include "net/base/registry_controlled_domain.h" | 25 #include "net/base/registry_controlled_domain.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/base/text/text_elider.h" | 28 #include "ui/base/text/text_elider.h" |
| 29 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
| 30 | 30 |
| 31 using content::UserMetricsAction; |
| 32 |
| 31 const int BackForwardMenuModel::kMaxHistoryItems = 12; | 33 const int BackForwardMenuModel::kMaxHistoryItems = 12; |
| 32 const int BackForwardMenuModel::kMaxChapterStops = 5; | 34 const int BackForwardMenuModel::kMaxChapterStops = 5; |
| 33 static const int kMaxWidth = 700; | 35 static const int kMaxWidth = 700; |
| 34 | 36 |
| 35 BackForwardMenuModel::BackForwardMenuModel(Browser* browser, | 37 BackForwardMenuModel::BackForwardMenuModel(Browser* browser, |
| 36 ModelType model_type) | 38 ModelType model_type) |
| 37 : browser_(browser), | 39 : browser_(browser), |
| 38 test_tab_contents_(NULL), | 40 test_tab_contents_(NULL), |
| 39 model_type_(model_type), | 41 model_type_(model_type), |
| 40 menu_model_delegate_(NULL) { | 42 menu_model_delegate_(NULL) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 162 |
| 161 void BackForwardMenuModel::ActivatedAt(int index) { | 163 void BackForwardMenuModel::ActivatedAt(int index) { |
| 162 ActivatedAt(index, 0); | 164 ActivatedAt(index, 0); |
| 163 } | 165 } |
| 164 | 166 |
| 165 void BackForwardMenuModel::ActivatedAt(int index, int event_flags) { | 167 void BackForwardMenuModel::ActivatedAt(int index, int event_flags) { |
| 166 DCHECK(!IsSeparator(index)); | 168 DCHECK(!IsSeparator(index)); |
| 167 | 169 |
| 168 // Execute the command for the last item: "Show Full History". | 170 // Execute the command for the last item: "Show Full History". |
| 169 if (index == GetItemCount() - 1) { | 171 if (index == GetItemCount() - 1) { |
| 170 UserMetrics::RecordComputedAction(BuildActionName("ShowFullHistory", -1)); | 172 content::RecordComputedAction(BuildActionName("ShowFullHistory", -1)); |
| 171 browser_->ShowSingletonTabOverwritingNTP( | 173 browser_->ShowSingletonTabOverwritingNTP( |
| 172 browser_->GetSingletonTabNavigateParams( | 174 browser_->GetSingletonTabNavigateParams( |
| 173 GURL(chrome::kChromeUIHistoryURL))); | 175 GURL(chrome::kChromeUIHistoryURL))); |
| 174 return; | 176 return; |
| 175 } | 177 } |
| 176 | 178 |
| 177 // Log whether it was a history or chapter click. | 179 // Log whether it was a history or chapter click. |
| 178 if (index < GetHistoryItemCount()) { | 180 if (index < GetHistoryItemCount()) { |
| 179 UserMetrics::RecordComputedAction( | 181 content::RecordComputedAction( |
| 180 BuildActionName("HistoryClick", index)); | 182 BuildActionName("HistoryClick", index)); |
| 181 } else { | 183 } else { |
| 182 UserMetrics::RecordComputedAction( | 184 content::RecordComputedAction( |
| 183 BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1)); | 185 BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1)); |
| 184 } | 186 } |
| 185 | 187 |
| 186 int controller_index = MenuIndexToNavEntryIndex(index); | 188 int controller_index = MenuIndexToNavEntryIndex(index); |
| 187 WindowOpenDisposition disposition = | 189 WindowOpenDisposition disposition = |
| 188 browser::DispositionFromEventFlags(event_flags); | 190 browser::DispositionFromEventFlags(event_flags); |
| 189 if (!browser_->NavigateToIndexWithDisposition(controller_index, disposition)) | 191 if (!browser_->NavigateToIndexWithDisposition(controller_index, disposition)) |
| 190 NOTREACHED(); | 192 NOTREACHED(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 void BackForwardMenuModel::MenuWillShow() { | 195 void BackForwardMenuModel::MenuWillShow() { |
| 194 UserMetrics::RecordComputedAction(BuildActionName("Popup", -1)); | 196 content::RecordComputedAction(BuildActionName("Popup", -1)); |
| 195 requested_favicons_.clear(); | 197 requested_favicons_.clear(); |
| 196 load_consumer_.CancelAllRequests(); | 198 load_consumer_.CancelAllRequests(); |
| 197 } | 199 } |
| 198 | 200 |
| 199 bool BackForwardMenuModel::IsSeparator(int index) const { | 201 bool BackForwardMenuModel::IsSeparator(int index) const { |
| 200 int history_items = GetHistoryItemCount(); | 202 int history_items = GetHistoryItemCount(); |
| 201 // If the index is past the number of history items + separator, | 203 // If the index is past the number of history items + separator, |
| 202 // we then consider if it is a chapter-stop entry. | 204 // we then consider if it is a chapter-stop entry. |
| 203 if (index > history_items) { | 205 if (index > history_items) { |
| 204 // We either are in ChapterStop area, or at the end of the list (the "Show | 206 // We either are in ChapterStop area, or at the end of the list (the "Show |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 metric_string += "ForwardMenu_"; | 457 metric_string += "ForwardMenu_"; |
| 456 else | 458 else |
| 457 metric_string += "BackMenu_"; | 459 metric_string += "BackMenu_"; |
| 458 metric_string += action; | 460 metric_string += action; |
| 459 if (index != -1) { | 461 if (index != -1) { |
| 460 // +1 is for historical reasons (indices used to start at 1). | 462 // +1 is for historical reasons (indices used to start at 1). |
| 461 metric_string += base::IntToString(index + 1); | 463 metric_string += base::IntToString(index + 1); |
| 462 } | 464 } |
| 463 return metric_string; | 465 return metric_string; |
| 464 } | 466 } |
| OLD | NEW |