| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 161 |
| 160 void BackForwardMenuModel::ActivatedAt(int index) { | 162 void BackForwardMenuModel::ActivatedAt(int index) { |
| 161 ActivatedAt(index, 0); | 163 ActivatedAt(index, 0); |
| 162 } | 164 } |
| 163 | 165 |
| 164 void BackForwardMenuModel::ActivatedAt(int index, int event_flags) { | 166 void BackForwardMenuModel::ActivatedAt(int index, int event_flags) { |
| 165 DCHECK(!IsSeparator(index)); | 167 DCHECK(!IsSeparator(index)); |
| 166 | 168 |
| 167 // Execute the command for the last item: "Show Full History". | 169 // Execute the command for the last item: "Show Full History". |
| 168 if (index == GetItemCount() - 1) { | 170 if (index == GetItemCount() - 1) { |
| 169 UserMetrics::RecordComputedAction(BuildActionName("ShowFullHistory", -1)); | 171 content::RecordComputedAction(BuildActionName("ShowFullHistory", -1)); |
| 170 browser_->ShowSingletonTabOverwritingNTP( | 172 browser_->ShowSingletonTabOverwritingNTP( |
| 171 browser_->GetSingletonTabNavigateParams( | 173 browser_->GetSingletonTabNavigateParams( |
| 172 GURL(chrome::kChromeUIHistoryURL))); | 174 GURL(chrome::kChromeUIHistoryURL))); |
| 173 return; | 175 return; |
| 174 } | 176 } |
| 175 | 177 |
| 176 // Log whether it was a history or chapter click. | 178 // Log whether it was a history or chapter click. |
| 177 if (index < GetHistoryItemCount()) { | 179 if (index < GetHistoryItemCount()) { |
| 178 UserMetrics::RecordComputedAction( | 180 content::RecordComputedAction( |
| 179 BuildActionName("HistoryClick", index)); | 181 BuildActionName("HistoryClick", index)); |
| 180 } else { | 182 } else { |
| 181 UserMetrics::RecordComputedAction( | 183 content::RecordComputedAction( |
| 182 BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1)); | 184 BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1)); |
| 183 } | 185 } |
| 184 | 186 |
| 185 int controller_index = MenuIndexToNavEntryIndex(index); | 187 int controller_index = MenuIndexToNavEntryIndex(index); |
| 186 WindowOpenDisposition disposition = | 188 WindowOpenDisposition disposition = |
| 187 browser::DispositionFromEventFlags(event_flags); | 189 browser::DispositionFromEventFlags(event_flags); |
| 188 if (!browser_->NavigateToIndexWithDisposition(controller_index, disposition)) | 190 if (!browser_->NavigateToIndexWithDisposition(controller_index, disposition)) |
| 189 NOTREACHED(); | 191 NOTREACHED(); |
| 190 } | 192 } |
| 191 | 193 |
| 192 void BackForwardMenuModel::MenuWillShow() { | 194 void BackForwardMenuModel::MenuWillShow() { |
| 193 UserMetrics::RecordComputedAction(BuildActionName("Popup", -1)); | 195 content::RecordComputedAction(BuildActionName("Popup", -1)); |
| 194 requested_favicons_.clear(); | 196 requested_favicons_.clear(); |
| 195 load_consumer_.CancelAllRequests(); | 197 load_consumer_.CancelAllRequests(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 bool BackForwardMenuModel::IsSeparator(int index) const { | 200 bool BackForwardMenuModel::IsSeparator(int index) const { |
| 199 int history_items = GetHistoryItemCount(); | 201 int history_items = GetHistoryItemCount(); |
| 200 // If the index is past the number of history items + separator, | 202 // If the index is past the number of history items + separator, |
| 201 // we then consider if it is a chapter-stop entry. | 203 // we then consider if it is a chapter-stop entry. |
| 202 if (index > history_items) { | 204 if (index > history_items) { |
| 203 // We either are in ChapterStop area, or at the end of the list (the "Show | 205 // 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... |
| 454 metric_string += "ForwardMenu_"; | 456 metric_string += "ForwardMenu_"; |
| 455 else | 457 else |
| 456 metric_string += "BackMenu_"; | 458 metric_string += "BackMenu_"; |
| 457 metric_string += action; | 459 metric_string += action; |
| 458 if (index != -1) { | 460 if (index != -1) { |
| 459 // +1 is for historical reasons (indices used to start at 1). | 461 // +1 is for historical reasons (indices used to start at 1). |
| 460 metric_string += base::IntToString(index + 1); | 462 metric_string += base::IntToString(index + 1); |
| 461 } | 463 } |
| 462 return metric_string; | 464 return metric_string; |
| 463 } | 465 } |
| OLD | NEW |