| 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 "chrome/browser/ui/toolbar/back_forward_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.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/metrics/user_metrics.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "chrome/browser/favicon/favicon_service_factory.h" | 14 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 16 #include "chrome/browser/ui/browser_navigator_params.h" | 17 #include "chrome/browser/ui/browser_navigator_params.h" |
| 17 #include "chrome/browser/ui/singleton_tabs.h" | 18 #include "chrome/browser/ui/singleton_tabs.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "components/favicon_base/favicon_types.h" | 21 #include "components/favicon_base/favicon_types.h" |
| 21 #include "components/grit/components_scaled_resources.h" | 22 #include "components/grit/components_scaled_resources.h" |
| 22 #include "components/strings/grit/components_strings.h" | 23 #include "components/strings/grit/components_strings.h" |
| 23 #include "content/public/browser/favicon_status.h" | 24 #include "content/public/browser/favicon_status.h" |
| 24 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.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 "net/base/registry_controlled_domains/registry_controlled_domain.h" | 28 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/base/window_open_disposition.h" | 31 #include "ui/base/window_open_disposition.h" |
| 32 #include "ui/gfx/text_elider.h" | 32 #include "ui/gfx/text_elider.h" |
| 33 | 33 |
| 34 using base::UserMetricsAction; | 34 using base::UserMetricsAction; |
| 35 using content::NavigationController; | 35 using content::NavigationController; |
| 36 using content::NavigationEntry; | 36 using content::NavigationEntry; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 void BackForwardMenuModel::ActivatedAt(int index) { | 171 void BackForwardMenuModel::ActivatedAt(int index) { |
| 172 ActivatedAt(index, 0); | 172 ActivatedAt(index, 0); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void BackForwardMenuModel::ActivatedAt(int index, int event_flags) { | 175 void BackForwardMenuModel::ActivatedAt(int index, int event_flags) { |
| 176 DCHECK(!IsSeparator(index)); | 176 DCHECK(!IsSeparator(index)); |
| 177 | 177 |
| 178 // Execute the command for the last item: "Show Full History". | 178 // Execute the command for the last item: "Show Full History". |
| 179 if (index == GetItemCount() - 1) { | 179 if (index == GetItemCount() - 1) { |
| 180 content::RecordComputedAction(BuildActionName("ShowFullHistory", -1)); | 180 base::RecordComputedAction(BuildActionName("ShowFullHistory", -1)); |
| 181 chrome::ShowSingletonTabOverwritingNTP(browser_, | 181 chrome::ShowSingletonTabOverwritingNTP(browser_, |
| 182 chrome::GetSingletonTabNavigateParams( | 182 chrome::GetSingletonTabNavigateParams( |
| 183 browser_, GURL(chrome::kChromeUIHistoryURL))); | 183 browser_, GURL(chrome::kChromeUIHistoryURL))); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Log whether it was a history or chapter click. | 187 // Log whether it was a history or chapter click. |
| 188 if (index < GetHistoryItemCount()) { | 188 if (index < GetHistoryItemCount()) { |
| 189 content::RecordComputedAction( | 189 base::RecordComputedAction(BuildActionName("HistoryClick", index)); |
| 190 BuildActionName("HistoryClick", index)); | |
| 191 } else { | 190 } else { |
| 192 content::RecordComputedAction( | 191 base::RecordComputedAction( |
| 193 BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1)); | 192 BuildActionName("ChapterClick", index - GetHistoryItemCount() - 1)); |
| 194 } | 193 } |
| 195 | 194 |
| 196 int controller_index = MenuIndexToNavEntryIndex(index); | 195 int controller_index = MenuIndexToNavEntryIndex(index); |
| 197 WindowOpenDisposition disposition = | 196 WindowOpenDisposition disposition = |
| 198 ui::DispositionFromEventFlags(event_flags); | 197 ui::DispositionFromEventFlags(event_flags); |
| 199 if (!chrome::NavigateToIndexWithDisposition(browser_, | 198 if (!chrome::NavigateToIndexWithDisposition(browser_, |
| 200 controller_index, | 199 controller_index, |
| 201 disposition)) { | 200 disposition)) { |
| 202 NOTREACHED(); | 201 NOTREACHED(); |
| 203 } | 202 } |
| 204 } | 203 } |
| 205 | 204 |
| 206 void BackForwardMenuModel::MenuWillShow() { | 205 void BackForwardMenuModel::MenuWillShow() { |
| 207 content::RecordComputedAction(BuildActionName("Popup", -1)); | 206 base::RecordComputedAction(BuildActionName("Popup", -1)); |
| 208 requested_favicons_.clear(); | 207 requested_favicons_.clear(); |
| 209 cancelable_task_tracker_.TryCancelAll(); | 208 cancelable_task_tracker_.TryCancelAll(); |
| 210 } | 209 } |
| 211 | 210 |
| 212 bool BackForwardMenuModel::IsSeparator(int index) const { | 211 bool BackForwardMenuModel::IsSeparator(int index) const { |
| 213 int history_items = GetHistoryItemCount(); | 212 int history_items = GetHistoryItemCount(); |
| 214 // If the index is past the number of history items + separator, | 213 // If the index is past the number of history items + separator, |
| 215 // we then consider if it is a chapter-stop entry. | 214 // we then consider if it is a chapter-stop entry. |
| 216 if (index > history_items) { | 215 if (index > history_items) { |
| 217 // We either are in ChapterStop area, or at the end of the list (the "Show | 216 // We either are in ChapterStop area, or at the end of the list (the "Show |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 metric_string += "ForwardMenu_"; | 469 metric_string += "ForwardMenu_"; |
| 471 else | 470 else |
| 472 metric_string += "BackMenu_"; | 471 metric_string += "BackMenu_"; |
| 473 metric_string += action; | 472 metric_string += action; |
| 474 if (index != -1) { | 473 if (index != -1) { |
| 475 // +1 is for historical reasons (indices used to start at 1). | 474 // +1 is for historical reasons (indices used to start at 1). |
| 476 metric_string += base::IntToString(index + 1); | 475 metric_string += base::IntToString(index + 1); |
| 477 } | 476 } |
| 478 return metric_string; | 477 return metric_string; |
| 479 } | 478 } |
| OLD | NEW |