Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: chrome/browser/ui/toolbar/back_forward_menu_model.cc

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "content/browser/tab_contents/navigation_controller.h"
20 #include "content/public/browser/favicon_status.h" 19 #include "content/public/browser/favicon_status.h"
20 #include "content/public/browser/navigation_controller.h"
21 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/user_metrics.h" 22 #include "content/public/browser/user_metrics.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "grit/theme_resources_standard.h" 26 #include "grit/theme_resources_standard.h"
27 #include "net/base/registry_controlled_domain.h" 27 #include "net/base/registry_controlled_domain.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/text/text_elider.h" 30 #include "ui/base/text/text_elider.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 ++chapter_stops; 328 ++chapter_stops;
329 } while (chapter_id != -1 && chapter_stops < kMaxChapterStops); 329 } while (chapter_id != -1 && chapter_stops < kMaxChapterStops);
330 } 330 }
331 331
332 return chapter_stops; 332 return chapter_stops;
333 } 333 }
334 334
335 int BackForwardMenuModel::GetIndexOfNextChapterStop(int start_from, 335 int BackForwardMenuModel::GetIndexOfNextChapterStop(int start_from,
336 bool forward) const { 336 bool forward) const {
337 WebContents* contents = GetWebContents(); 337 WebContents* contents = GetWebContents();
338 NavigationController& controller = contents->GetController(); 338 content::NavigationController& controller = contents->GetController();
339 339
340 int max_count = controller.GetEntryCount(); 340 int max_count = controller.GetEntryCount();
341 if (start_from < 0 || start_from >= max_count) 341 if (start_from < 0 || start_from >= max_count)
342 return -1; // Out of bounds. 342 return -1; // Out of bounds.
343 343
344 if (forward) { 344 if (forward) {
345 if (start_from < max_count - 1) { 345 if (start_from < max_count - 1) {
346 // We want to advance over the current chapter stop, so we add one. 346 // We want to advance over the current chapter stop, so we add one.
347 // We don't need to do this when direction is backwards. 347 // We don't need to do this when direction is backwards.
348 start_from++; 348 start_from++;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // This menu item is a chapter stop located between the two separators. 438 // This menu item is a chapter stop located between the two separators.
439 index = FindChapterStop(history_items, 439 index = FindChapterStop(history_items,
440 model_type_ == FORWARD_MENU, 440 model_type_ == FORWARD_MENU,
441 index - history_items - 1); 441 index - history_items - 1);
442 442
443 return index; 443 return index;
444 } 444 }
445 445
446 NavigationEntry* BackForwardMenuModel::GetNavigationEntry(int index) const { 446 NavigationEntry* BackForwardMenuModel::GetNavigationEntry(int index) const {
447 int controller_index = MenuIndexToNavEntryIndex(index); 447 int controller_index = MenuIndexToNavEntryIndex(index);
448 NavigationController& controller = GetWebContents()->GetController(); 448 content::NavigationController& controller = GetWebContents()->GetController();
449 if (controller_index >= 0 && controller_index < controller.GetEntryCount()) 449 if (controller_index >= 0 && controller_index < controller.GetEntryCount())
450 return controller.GetEntryAtIndex(controller_index); 450 return controller.GetEntryAtIndex(controller_index);
451 451
452 NOTREACHED(); 452 NOTREACHED();
453 return NULL; 453 return NULL;
454 } 454 }
455 455
456 std::string BackForwardMenuModel::BuildActionName( 456 std::string BackForwardMenuModel::BuildActionName(
457 const std::string& action, int index) const { 457 const std::string& action, int index) const {
458 DCHECK(!action.empty()); 458 DCHECK(!action.empty());
459 DCHECK(index >= -1); 459 DCHECK(index >= -1);
460 std::string metric_string; 460 std::string metric_string;
461 if (model_type_ == FORWARD_MENU) 461 if (model_type_ == FORWARD_MENU)
462 metric_string += "ForwardMenu_"; 462 metric_string += "ForwardMenu_";
463 else 463 else
464 metric_string += "BackMenu_"; 464 metric_string += "BackMenu_";
465 metric_string += action; 465 metric_string += action;
466 if (index != -1) { 466 if (index != -1) {
467 // +1 is for historical reasons (indices used to start at 1). 467 // +1 is for historical reasons (indices used to start at 1).
468 metric_string += base::IntToString(index + 1); 468 metric_string += base::IntToString(index + 1);
469 } 469 }
470 return metric_string; 470 return metric_string;
471 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698