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

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

Issue 4694008: Make pink's TabContentsWrapper change compile on Windows.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "chrome/browser/sessions/tab_restore_service.h" 75 #include "chrome/browser/sessions/tab_restore_service.h"
76 #include "chrome/browser/status_bubble.h" 76 #include "chrome/browser/status_bubble.h"
77 #include "chrome/browser/sync/profile_sync_service.h" 77 #include "chrome/browser/sync/profile_sync_service.h"
78 #include "chrome/browser/sync/sync_ui_util.h" 78 #include "chrome/browser/sync/sync_ui_util.h"
79 #include "chrome/browser/tab_closeable_state_watcher.h" 79 #include "chrome/browser/tab_closeable_state_watcher.h"
80 #include "chrome/browser/tab_contents/interstitial_page.h" 80 #include "chrome/browser/tab_contents/interstitial_page.h"
81 #include "chrome/browser/tab_contents/navigation_controller.h" 81 #include "chrome/browser/tab_contents/navigation_controller.h"
82 #include "chrome/browser/tab_contents/navigation_entry.h" 82 #include "chrome/browser/tab_contents/navigation_entry.h"
83 #include "chrome/browser/tab_contents/tab_contents.h" 83 #include "chrome/browser/tab_contents/tab_contents.h"
84 #include "chrome/browser/tab_contents/tab_contents_view.h" 84 #include "chrome/browser/tab_contents/tab_contents_view.h"
85 #include "chrome/browser/tab_contents_wrapper.h"
85 #include "chrome/browser/tab_menu_model.h" 86 #include "chrome/browser/tab_menu_model.h"
86 #include "chrome/browser/tabs/tab_strip_model.h" 87 #include "chrome/browser/tabs/tab_strip_model.h"
87 #include "chrome/browser/ui/browser_navigator.h" 88 #include "chrome/browser/ui/browser_navigator.h"
88 #include "chrome/browser/upgrade_detector.h" 89 #include "chrome/browser/upgrade_detector.h"
89 #include "chrome/browser/web_applications/web_app.h" 90 #include "chrome/browser/web_applications/web_app.h"
90 #include "chrome/browser/window_sizer.h" 91 #include "chrome/browser/window_sizer.h"
91 #include "chrome/common/chrome_constants.h" 92 #include "chrome/common/chrome_constants.h"
92 #include "chrome/common/chrome_switches.h" 93 #include "chrome/common/chrome_switches.h"
93 #include "chrome/common/content_restriction.h" 94 #include "chrome/common/content_restriction.h"
94 #include "chrome/common/extensions/extension.h" 95 #include "chrome/common/extensions/extension.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 322
322 // static 323 // static
323 Browser* Browser::CreateForPopup(Type type, 324 Browser* Browser::CreateForPopup(Type type,
324 Profile* profile, 325 Profile* profile,
325 TabContents* new_contents, 326 TabContents* new_contents,
326 const gfx::Rect& initial_bounds) { 327 const gfx::Rect& initial_bounds) {
327 DCHECK(type & TYPE_POPUP); 328 DCHECK(type & TYPE_POPUP);
328 Browser* browser = new Browser(type, profile); 329 Browser* browser = new Browser(type, profile);
329 browser->set_override_bounds(initial_bounds); 330 browser->set_override_bounds(initial_bounds);
330 browser->CreateBrowserWindow(); 331 browser->CreateBrowserWindow();
331 browser->tabstrip_model()->AppendTabContents(new_contents, true); 332 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents);
333 browser->tabstrip_model()->AppendTabContents(wrapper, true);
332 return browser; 334 return browser;
333 } 335 }
334 336
335 // static 337 // static
336 Browser* Browser::CreateForType(Type type, Profile* profile) { 338 Browser* Browser::CreateForType(Type type, Profile* profile) {
337 Browser* browser = new Browser(type, profile); 339 Browser* browser = new Browser(type, profile);
338 browser->CreateBrowserWindow(); 340 browser->CreateBrowserWindow();
339 return browser; 341 return browser;
340 } 342 }
341 343
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 url = extension->GetFullLaunchURL(); 556 url = extension->GetFullLaunchURL();
555 } 557 }
556 558
557 // TODO(erikkay) this can't be correct for extensions 559 // TODO(erikkay) this can't be correct for extensions
558 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 560 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
559 RegisterAppPrefs(app_name); 561 RegisterAppPrefs(app_name);
560 562
561 bool as_panel = extension && (container == extension_misc::LAUNCH_PANEL); 563 bool as_panel = extension && (container == extension_misc::LAUNCH_PANEL);
562 Browser* browser = Browser::CreateForApp(app_name, extension, profile, 564 Browser* browser = Browser::CreateForApp(app_name, extension, profile,
563 as_panel); 565 as_panel);
564 TabContents* contents = 566 TabContentsWrapper* wrapper =
565 browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE); 567 browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE);
568 TabContents* contents = wrapper->tab_contents();
566 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 569 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
567 contents->render_view_host()->SyncRendererPrefs(); 570 contents->render_view_host()->SyncRendererPrefs();
568 browser->window()->Show(); 571 browser->window()->Show();
569 572
570 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial 573 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
571 // focus explicitly. 574 // focus explicitly.
572 contents->view()->SetInitialFocus(); 575 contents->view()->SetInitialFocus();
573 576
574 if (!as_panel) { 577 if (!as_panel) {
575 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked 578 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 615
613 // TODO(erikkay): START_PAGE doesn't seem like the right transition in all 616 // TODO(erikkay): START_PAGE doesn't seem like the right transition in all
614 // cases. 617 // cases.
615 browser::NavigateParams params(browser, extension->GetFullLaunchURL(), 618 browser::NavigateParams params(browser, extension->GetFullLaunchURL(),
616 PageTransition::START_PAGE); 619 PageTransition::START_PAGE);
617 params.tabstrip_add_types = add_type; 620 params.tabstrip_add_types = add_type;
618 621
619 // Launch the application in the existing TabContents, if it was supplied. 622 // Launch the application in the existing TabContents, if it was supplied.
620 if (existing_tab) { 623 if (existing_tab) {
621 TabStripModel* model = browser->tabstrip_model(); 624 TabStripModel* model = browser->tabstrip_model();
622 int tab_index = model->GetIndexOfTabContents(existing_tab); 625 int tab_index = model->GetWrapperIndex(existing_tab);
623 626
624 existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(), 627 existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(),
625 CURRENT_TAB, PageTransition::LINK); 628 CURRENT_TAB, PageTransition::LINK);
626 if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { 629 if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) {
627 model->SetTabPinned(tab_index, true); 630 model->SetTabPinned(tab_index, true);
628 tab_index = model->GetIndexOfTabContents(existing_tab); 631 tab_index = model->GetWrapperIndex(existing_tab);
629 } 632 }
630 if (params.tabstrip_add_types & TabStripModel::ADD_SELECTED) 633 if (params.tabstrip_add_types & TabStripModel::ADD_SELECTED)
631 model->SelectTabContentsAt(tab_index, true); 634 model->SelectTabContentsAt(tab_index, true);
632 635
633 contents = existing_tab; 636 contents = existing_tab;
634 } else { 637 } else {
635 params.disposition = NEW_FOREGROUND_TAB; 638 params.disposition = NEW_FOREGROUND_TAB;
636 browser::Navigate(&params); 639 browser::Navigate(&params);
637 contents = params.target_contents; 640 contents = params.target_contents->tab_contents();
638 } 641 }
639 642
640 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN) 643 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN)
641 browser->window()->SetFullscreen(true); 644 browser->window()->SetFullscreen(true);
642 645
643 return contents; 646 return contents;
644 } 647 }
645 648
646 // static 649 // static
647 void Browser::OpenBookmarkManagerWindow(Profile* profile) { 650 void Browser::OpenBookmarkManagerWindow(Profile* profile) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 760 }
758 761
759 SkBitmap Browser::GetCurrentPageIcon() const { 762 SkBitmap Browser::GetCurrentPageIcon() const {
760 TabContents* contents = GetSelectedTabContents(); 763 TabContents* contents = GetSelectedTabContents();
761 // |contents| can be NULL since GetCurrentPageIcon() is called by the window 764 // |contents| can be NULL since GetCurrentPageIcon() is called by the window
762 // during the window's creation (before tabs have been added). 765 // during the window's creation (before tabs have been added).
763 return contents ? contents->GetFavIcon() : SkBitmap(); 766 return contents ? contents->GetFavIcon() : SkBitmap();
764 } 767 }
765 768
766 string16 Browser::GetWindowTitleForCurrentTab() const { 769 string16 Browser::GetWindowTitleForCurrentTab() const {
767 TabContents* contents = 770 TabContents* contents = GetSelectedTabContents();
768 tab_handler_->GetTabStripModel()->GetSelectedTabContents();
769 string16 title; 771 string16 title;
770 772
771 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the 773 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the
772 // window during the window's creation (before tabs have been added). 774 // window during the window's creation (before tabs have been added).
773 if (contents) { 775 if (contents) {
774 title = contents->GetTitle(); 776 title = contents->GetTitle();
775 FormatTitleForDisplay(&title); 777 FormatTitleForDisplay(&title);
776 } 778 }
777 if (title.empty()) 779 if (title.empty())
778 title = TabContents::GetDefaultTitle(); 780 title = TabContents::GetDefaultTitle();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 892
891 int Browser::selected_index() const { 893 int Browser::selected_index() const {
892 return tab_handler_->GetTabStripModel()->selected_index(); 894 return tab_handler_->GetTabStripModel()->selected_index();
893 } 895 }
894 896
895 int Browser::GetIndexOfController( 897 int Browser::GetIndexOfController(
896 const NavigationController* controller) const { 898 const NavigationController* controller) const {
897 return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); 899 return tab_handler_->GetTabStripModel()->GetIndexOfController(controller);
898 } 900 }
899 901
900 TabContents* Browser::GetTabContentsAt(int index) const { 902 TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const {
901 return tab_handler_->GetTabStripModel()->GetTabContentsAt(index); 903 return tabstrip_model()->GetSelectedTabContents();
904 }
905 TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const {
906 return tabstrip_model()->GetTabContentsAt(index);
902 } 907 }
903 908
904 TabContents* Browser::GetSelectedTabContents() const { 909 TabContents* Browser::GetSelectedTabContents() const {
905 return tab_handler_->GetTabStripModel()->GetSelectedTabContents(); 910 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper();
911 if (wrapper)
912 return wrapper->tab_contents();
913 return NULL;
914 }
915
916 TabContents* Browser::GetTabContentsAt(int index) const {
917 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index);
918 if (wrapper)
919 return wrapper->tab_contents();
920 return NULL;
906 } 921 }
907 922
908 void Browser::SelectTabContentsAt(int index, bool user_gesture) { 923 void Browser::SelectTabContentsAt(int index, bool user_gesture) {
909 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture); 924 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture);
910 } 925 }
911 926
912 void Browser::CloseAllTabs() { 927 void Browser::CloseAllTabs() {
913 tab_handler_->GetTabStripModel()->CloseAllTabs(); 928 tab_handler_->GetTabStripModel()->CloseAllTabs();
914 } 929 }
915 930
916 //////////////////////////////////////////////////////////////////////////////// 931 ////////////////////////////////////////////////////////////////////////////////
917 // Browser, Tab adding/showing functions: 932 // Browser, Tab adding/showing functions:
918 933
919 int Browser::GetIndexForInsertionDuringRestore(int relative_index) { 934 int Browser::GetIndexForInsertionDuringRestore(int relative_index) {
920 return (tab_handler_->GetTabStripModel()->insertion_policy() == 935 return (tab_handler_->GetTabStripModel()->insertion_policy() ==
921 TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; 936 TabStripModel::INSERT_AFTER) ? tab_count() : relative_index;
922 } 937 }
923 938
924 TabContents* Browser::AddSelectedTabWithURL(const GURL& url, 939 TabContentsWrapper* Browser::AddSelectedTabWithURL(const GURL& url,
925 PageTransition::Type transition) { 940 PageTransition::Type transition) {
926 browser::NavigateParams params(this, url, transition); 941 browser::NavigateParams params(this, url, transition);
927 params.disposition = NEW_FOREGROUND_TAB; 942 params.disposition = NEW_FOREGROUND_TAB;
928 browser::Navigate(&params); 943 browser::Navigate(&params);
929 return params.target_contents; 944 return params.target_contents;
930 } 945 }
931 946
932 TabContents* Browser::AddTab(TabContents* tab_contents, 947 TabContents* Browser::AddTab(TabContentsWrapper* tab_contents,
933 PageTransition::Type type) { 948 PageTransition::Type type) {
934 tab_handler_->GetTabStripModel()->AddTabContents( 949 tab_handler_->GetTabStripModel()->AddTabContents(
935 tab_contents, -1, type, TabStripModel::ADD_SELECTED); 950 tab_contents, -1, type, TabStripModel::ADD_SELECTED);
936 return tab_contents; 951 return tab_contents->tab_contents();
937 } 952 }
938 953
939 void Browser::AddTabContents(TabContents* new_contents, 954 void Browser::AddTabContents(TabContents* new_contents,
940 WindowOpenDisposition disposition, 955 WindowOpenDisposition disposition,
941 const gfx::Rect& initial_pos, 956 const gfx::Rect& initial_pos,
942 bool user_gesture) { 957 bool user_gesture) {
943 AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture); 958 AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture);
944 } 959 }
945 960
946 void Browser::CloseTabContents(TabContents* contents) { 961 void Browser::CloseTabContents(TabContents* contents) {
(...skipping 15 matching lines...) Expand all
962 977
963 TabContents* Browser::AddRestoredTab( 978 TabContents* Browser::AddRestoredTab(
964 const std::vector<TabNavigation>& navigations, 979 const std::vector<TabNavigation>& navigations,
965 int tab_index, 980 int tab_index,
966 int selected_navigation, 981 int selected_navigation,
967 const std::string& extension_app_id, 982 const std::string& extension_app_id,
968 bool select, 983 bool select,
969 bool pin, 984 bool pin,
970 bool from_last_session, 985 bool from_last_session,
971 SessionStorageNamespace* session_storage_namespace) { 986 SessionStorageNamespace* session_storage_namespace) {
972 TabContents* new_tab = new TabContents( 987 TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL,
973 profile(), NULL, MSG_ROUTING_NONE, 988 MSG_ROUTING_NONE,
974 tab_handler_->GetTabStripModel()->GetSelectedTabContents(), 989 GetSelectedTabContents(),
975 session_storage_namespace); 990 session_storage_namespace);
991 TabContents* new_tab = wrapper->tab_contents();
976 new_tab->SetExtensionAppById(extension_app_id); 992 new_tab->SetExtensionAppById(extension_app_id);
977 new_tab->controller().RestoreFromState(navigations, selected_navigation, 993 new_tab->controller().RestoreFromState(navigations, selected_navigation,
978 from_last_session); 994 from_last_session);
979 995
980 bool really_pin = 996 bool really_pin =
981 (pin && tab_index == tabstrip_model()->IndexOfFirstNonMiniTab()); 997 (pin && tab_index == tabstrip_model()->IndexOfFirstNonMiniTab());
982 tab_handler_->GetTabStripModel()->InsertTabContentsAt( 998 tab_handler_->GetTabStripModel()->InsertTabContentsAt(
983 tab_index, new_tab, 999 tab_index, wrapper,
984 select ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE); 1000 select ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE);
985 if (really_pin) 1001 if (really_pin)
986 tab_handler_->GetTabStripModel()->SetTabPinned(tab_index, true); 1002 tab_handler_->GetTabStripModel()->SetTabPinned(tab_index, true);
987 if (select) { 1003 if (select) {
988 window_->Activate(); 1004 window_->Activate();
989 } else { 1005 } else {
990 // We set the size of the view here, before WebKit does its initial 1006 // We set the size of the view here, before WebKit does its initial
991 // layout. If we don't, the initial layout of background tabs will be 1007 // layout. If we don't, the initial layout of background tabs will be
992 // performed with a view width of 0, which may cause script outputs and 1008 // performed with a view width of 0, which may cause script outputs and
993 // anchor link location calculations to be incorrect even after a new 1009 // anchor link location calculations to be incorrect even after a new
994 // layout with proper view dimensions. TabStripModel::AddTabContents() 1010 // layout with proper view dimensions. TabStripModel::AddTabContents()
995 // contains similar logic. 1011 // contains similar logic.
996 new_tab->view()->SizeContents(window_->GetRestoredBounds().size()); 1012 new_tab->view()->SizeContents(window_->GetRestoredBounds().size());
997 new_tab->HideContents(); 1013 new_tab->HideContents();
998 } 1014 }
999 if (profile_->HasSessionService()) { 1015 if (profile_->HasSessionService()) {
1000 SessionService* session_service = profile_->GetSessionService(); 1016 SessionService* session_service = profile_->GetSessionService();
1001 if (session_service) 1017 if (session_service)
1002 session_service->TabRestored(&new_tab->controller(), really_pin); 1018 session_service->TabRestored(&new_tab->controller(), really_pin);
1003 } 1019 }
1004 return new_tab; 1020 return new_tab;
1005 } 1021 }
1006 1022
1007 void Browser::ReplaceRestoredTab( 1023 void Browser::ReplaceRestoredTab(
1008 const std::vector<TabNavigation>& navigations, 1024 const std::vector<TabNavigation>& navigations,
1009 int selected_navigation, 1025 int selected_navigation,
1010 bool from_last_session, 1026 bool from_last_session,
1011 const std::string& extension_app_id, 1027 const std::string& extension_app_id,
1012 SessionStorageNamespace* session_storage_namespace) { 1028 SessionStorageNamespace* session_storage_namespace) {
1013 TabContents* replacement = new TabContents(profile(), NULL, 1029 TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL,
1014 MSG_ROUTING_NONE, 1030 MSG_ROUTING_NONE,
1015 tab_handler_->GetTabStripModel()->GetSelectedTabContents(), 1031 GetSelectedTabContents(),
1016 session_storage_namespace); 1032 session_storage_namespace);
1033 TabContents* replacement = wrapper->tab_contents();
1017 replacement->SetExtensionAppById(extension_app_id); 1034 replacement->SetExtensionAppById(extension_app_id);
1018 replacement->controller().RestoreFromState(navigations, selected_navigation, 1035 replacement->controller().RestoreFromState(navigations, selected_navigation,
1019 from_last_session); 1036 from_last_session);
1020 1037
1021 tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt( 1038 tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt(
1022 tab_handler_->GetTabStripModel()->selected_index(), 1039 tab_handler_->GetTabStripModel()->selected_index(),
1023 &replacement->controller()); 1040 wrapper);
1024 } 1041 }
1025 1042
1026 bool Browser::CanRestoreTab() { 1043 bool Browser::CanRestoreTab() {
1027 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); 1044 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB);
1028 } 1045 }
1029 1046
1030 bool Browser::NavigateToIndexWithDisposition(int index, 1047 bool Browser::NavigateToIndexWithDisposition(int index,
1031 WindowOpenDisposition disp) { 1048 WindowOpenDisposition disp) {
1032 NavigationController& controller = 1049 NavigationController& controller =
1033 GetOrCloneTabForDisposition(disp)->controller(); 1050 GetOrCloneTabForDisposition(disp)->controller();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 // Browser, Assorted browser commands: 1120 // Browser, Assorted browser commands:
1104 1121
1105 bool Browser::ShouldOpenNewTabForWindowDisposition( 1122 bool Browser::ShouldOpenNewTabForWindowDisposition(
1106 WindowOpenDisposition disposition) { 1123 WindowOpenDisposition disposition) {
1107 return (disposition == NEW_FOREGROUND_TAB || 1124 return (disposition == NEW_FOREGROUND_TAB ||
1108 disposition == NEW_BACKGROUND_TAB); 1125 disposition == NEW_BACKGROUND_TAB);
1109 } 1126 }
1110 1127
1111 TabContents* Browser::GetOrCloneTabForDisposition( 1128 TabContents* Browser::GetOrCloneTabForDisposition(
1112 WindowOpenDisposition disposition) { 1129 WindowOpenDisposition disposition) {
1113 TabContents* current_tab = GetSelectedTabContents(); 1130 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1114 if (ShouldOpenNewTabForWindowDisposition(disposition)) { 1131 if (ShouldOpenNewTabForWindowDisposition(disposition)) {
1115 current_tab = current_tab->Clone(); 1132 current_tab = current_tab->Clone();
1116 tab_handler_->GetTabStripModel()->AddTabContents( 1133 tab_handler_->GetTabStripModel()->AddTabContents(
1117 current_tab, -1, PageTransition::LINK, 1134 current_tab, -1, PageTransition::LINK,
1118 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : 1135 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED :
1119 TabStripModel::ADD_NONE); 1136 TabStripModel::ADD_NONE);
1120 } 1137 }
1121 return current_tab; 1138 return current_tab->tab_contents();
1122 } 1139 }
1123 1140
1124 void Browser::UpdateTabStripModelInsertionPolicy() { 1141 void Browser::UpdateTabStripModelInsertionPolicy() {
1125 tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ? 1142 tab_handler_->GetTabStripModel()->SetInsertionPolicy(UseVerticalTabs() ?
1126 TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER); 1143 TabStripModel::INSERT_BEFORE : TabStripModel::INSERT_AFTER);
1127 } 1144 }
1128 1145
1129 void Browser::UseVerticalTabsChanged() { 1146 void Browser::UseVerticalTabsChanged() {
1130 UpdateTabStripModelInsertionPolicy(); 1147 UpdateTabStripModelInsertionPolicy();
1131 window()->ToggleTabStripMode(); 1148 window()->ToggleTabStripMode();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 g_browser_process->tab_closeable_state_watcher(); 1191 g_browser_process->tab_closeable_state_watcher();
1175 bool can_close = !watcher || watcher->CanCloseBrowser(this); 1192 bool can_close = !watcher || watcher->CanCloseBrowser(this);
1176 if (!can_close && is_attempting_to_close_browser_) 1193 if (!can_close && is_attempting_to_close_browser_)
1177 CancelWindowClose(); 1194 CancelWindowClose();
1178 return can_close; 1195 return can_close;
1179 } 1196 }
1180 1197
1181 void Browser::GoBack(WindowOpenDisposition disposition) { 1198 void Browser::GoBack(WindowOpenDisposition disposition) {
1182 UserMetrics::RecordAction(UserMetricsAction("Back"), profile_); 1199 UserMetrics::RecordAction(UserMetricsAction("Back"), profile_);
1183 1200
1184 TabContents* current_tab = GetSelectedTabContents(); 1201 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1185 if (current_tab->controller().CanGoBack()) { 1202 if (current_tab->controller().CanGoBack()) {
1186 TabContents* new_tab = GetOrCloneTabForDisposition(disposition); 1203 TabContents* new_tab = GetOrCloneTabForDisposition(disposition);
1187 // If we are on an interstitial page and clone the tab, it won't be copied 1204 // If we are on an interstitial page and clone the tab, it won't be copied
1188 // to the new tab, so we don't need to go back. 1205 // to the new tab, so we don't need to go back.
1189 if (current_tab->showing_interstitial_page() && (new_tab != current_tab)) 1206 if (current_tab->tab_contents()->showing_interstitial_page() &&
1207 (new_tab != current_tab->tab_contents()))
1190 return; 1208 return;
1191 new_tab->controller().GoBack(); 1209 new_tab->controller().GoBack();
1192 } 1210 }
1193 } 1211 }
1194 1212
1195 void Browser::GoForward(WindowOpenDisposition disposition) { 1213 void Browser::GoForward(WindowOpenDisposition disposition) {
1196 UserMetrics::RecordAction(UserMetricsAction("Forward"), profile_); 1214 UserMetrics::RecordAction(UserMetricsAction("Forward"), profile_);
1197 if (GetSelectedTabContents()->controller().CanGoForward()) 1215 if (GetSelectedTabContentsWrapper()->controller().CanGoForward())
1198 GetOrCloneTabForDisposition(disposition)->controller().GoForward(); 1216 GetOrCloneTabForDisposition(disposition)->controller().GoForward();
1199 } 1217 }
1200 1218
1201 void Browser::Reload(WindowOpenDisposition disposition) { 1219 void Browser::Reload(WindowOpenDisposition disposition) {
1202 UserMetrics::RecordAction(UserMetricsAction("Reload"), profile_); 1220 UserMetrics::RecordAction(UserMetricsAction("Reload"), profile_);
1203 ReloadInternal(disposition, false); 1221 ReloadInternal(disposition, false);
1204 } 1222 }
1205 1223
1206 void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) { 1224 void Browser::ReloadIgnoringCache(WindowOpenDisposition disposition) {
1207 UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache"), profile_); 1225 UserMetrics::RecordAction(UserMetricsAction("ReloadIgnoringCache"), profile_);
1208 ReloadInternal(disposition, true); 1226 ReloadInternal(disposition, true);
1209 } 1227 }
1210 1228
1211 void Browser::ReloadInternal(WindowOpenDisposition disposition, 1229 void Browser::ReloadInternal(WindowOpenDisposition disposition,
1212 bool ignore_cache) { 1230 bool ignore_cache) {
1213 // If we are showing an interstitial, treat this as an OpenURL. 1231 // If we are showing an interstitial, treat this as an OpenURL.
1214 TabContents* current_tab = GetSelectedTabContents(); 1232 TabContents* current_tab = GetSelectedTabContents();
1215 if (current_tab && current_tab->showing_interstitial_page()) { 1233 if (current_tab && current_tab->showing_interstitial_page()) {
1216 NavigationEntry* entry = current_tab->controller().GetActiveEntry(); 1234 NavigationEntry* entry = current_tab->controller().GetActiveEntry();
1217 DCHECK(entry); // Should exist if interstitial is showing. 1235 DCHECK(entry); // Should exist if interstitial is showing.
1218 OpenURL(entry->url(), GURL(), disposition, PageTransition::RELOAD); 1236 OpenURL(entry->url(), GURL(), disposition, PageTransition::RELOAD);
1219 return; 1237 return;
1220 } 1238 }
1221 1239
1222 // As this is caused by a user action, give the focus to the page. 1240 // As this is caused by a user action, give the focus to the page.
1223 current_tab = GetOrCloneTabForDisposition(disposition); 1241 TabContents* tab = GetOrCloneTabForDisposition(disposition);
1224 if (!current_tab->FocusLocationBarByDefault()) 1242 if (!tab->FocusLocationBarByDefault())
1225 current_tab->Focus(); 1243 tab->Focus();
1226 if (ignore_cache) 1244 if (ignore_cache)
1227 current_tab->controller().ReloadIgnoringCache(true); 1245 tab->controller().ReloadIgnoringCache(true);
1228 else 1246 else
1229 current_tab->controller().Reload(true); 1247 tab->controller().Reload(true);
1230 } 1248 }
1231 1249
1232 void Browser::Home(WindowOpenDisposition disposition) { 1250 void Browser::Home(WindowOpenDisposition disposition) {
1233 UserMetrics::RecordAction(UserMetricsAction("Home"), profile_); 1251 UserMetrics::RecordAction(UserMetricsAction("Home"), profile_);
1234 OpenURL(GetHomePage(), GURL(), disposition, PageTransition::AUTO_BOOKMARK); 1252 OpenURL(GetHomePage(), GURL(), disposition, PageTransition::AUTO_BOOKMARK);
1235 } 1253 }
1236 1254
1237 void Browser::OpenCurrentURL() { 1255 void Browser::OpenCurrentURL() {
1238 UserMetrics::RecordAction(UserMetricsAction("LoadURL"), profile_); 1256 UserMetrics::RecordAction(UserMetricsAction("LoadURL"), profile_);
1239 LocationBar* location_bar = window_->GetLocationBar(); 1257 LocationBar* location_bar = window_->GetLocationBar();
1240 WindowOpenDisposition open_disposition = 1258 WindowOpenDisposition open_disposition =
1241 location_bar->GetWindowOpenDisposition(); 1259 location_bar->GetWindowOpenDisposition();
1242 if (OpenInstant(open_disposition)) 1260 if (OpenInstant(open_disposition))
1243 return; 1261 return;
1244 1262
1245 GURL url(WideToUTF8(location_bar->GetInputString())); 1263 GURL url(WideToUTF8(location_bar->GetInputString()));
1246 browser::NavigateParams params(this, url, location_bar->GetPageTransition()); 1264 browser::NavigateParams params(this, url, location_bar->GetPageTransition());
1247 params.disposition = open_disposition; 1265 params.disposition = open_disposition;
1248 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least 1266 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least
1249 // inherit the opener. In some cases the tabstrip will determine the group 1267 // inherit the opener. In some cases the tabstrip will determine the group
1250 // should be inherited, in which case the group is inherited instead of the 1268 // should be inherited, in which case the group is inherited instead of the
1251 // opener. 1269 // opener.
1252 params.tabstrip_add_types = 1270 params.tabstrip_add_types =
1253 TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; 1271 TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER;
1254 browser::Navigate(&params); 1272 browser::Navigate(&params);
1255 } 1273 }
1256 1274
1257 void Browser::Stop() { 1275 void Browser::Stop() {
1258 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); 1276 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_);
1259 GetSelectedTabContents()->Stop(); 1277 GetSelectedTabContentsWrapper()->tab_contents()->Stop();
1260 } 1278 }
1261 1279
1262 void Browser::NewWindow() { 1280 void Browser::NewWindow() {
1263 if (browser_defaults::kAlwaysOpenIncognitoWindow && 1281 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
1264 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) { 1282 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) {
1265 NewIncognitoWindow(); 1283 NewIncognitoWindow();
1266 return; 1284 return;
1267 } 1285 }
1268 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_); 1286 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_);
1269 SessionService* session_service = 1287 SessionService* session_service =
(...skipping 19 matching lines...) Expand all
1289 1307
1290 if (type() == TYPE_NORMAL) { 1308 if (type() == TYPE_NORMAL) {
1291 AddBlankTab(true); 1309 AddBlankTab(true);
1292 } else { 1310 } else {
1293 Browser* b = GetOrCreateTabbedBrowser(profile_); 1311 Browser* b = GetOrCreateTabbedBrowser(profile_);
1294 b->AddBlankTab(true); 1312 b->AddBlankTab(true);
1295 b->window()->Show(); 1313 b->window()->Show();
1296 // The call to AddBlankTab above did not set the focus to the tab as its 1314 // The call to AddBlankTab above did not set the focus to the tab as its
1297 // window was not active, so we have to do it explicitly. 1315 // window was not active, so we have to do it explicitly.
1298 // See http://crbug.com/6380. 1316 // See http://crbug.com/6380.
1299 b->GetSelectedTabContents()->view()->RestoreFocus(); 1317 b->GetSelectedTabContentsWrapper()->view()->RestoreFocus();
1300 } 1318 }
1301 } 1319 }
1302 1320
1303 void Browser::CloseTab() { 1321 void Browser::CloseTab() {
1304 UserMetrics::RecordAction(UserMetricsAction("CloseTab_Accelerator"), 1322 UserMetrics::RecordAction(UserMetricsAction("CloseTab_Accelerator"),
1305 profile_); 1323 profile_);
1306 if (CanCloseTab()) { 1324 if (CanCloseTab()) {
1307 tab_handler_->GetTabStripModel()->CloseTabContentsAt( 1325 tab_handler_->GetTabStripModel()->CloseTabContentsAt(
1308 tab_handler_->GetTabStripModel()->selected_index(), 1326 tab_handler_->GetTabStripModel()->selected_index(),
1309 TabStripModel::CLOSE_USER_GESTURE | 1327 TabStripModel::CLOSE_USER_GESTURE |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 1401
1384 chrome_browser_net::WriteURLToClipboard( 1402 chrome_browser_net::WriteURLToClipboard(
1385 contents->GetURL(), 1403 contents->GetURL(),
1386 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1404 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1387 g_browser_process->clipboard()); 1405 g_browser_process->clipboard());
1388 } 1406 }
1389 1407
1390 void Browser::ConvertPopupToTabbedBrowser() { 1408 void Browser::ConvertPopupToTabbedBrowser() {
1391 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab"), profile_); 1409 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab"), profile_);
1392 int tab_strip_index = tab_handler_->GetTabStripModel()->selected_index(); 1410 int tab_strip_index = tab_handler_->GetTabStripModel()->selected_index();
1393 TabContents* contents = 1411 TabContentsWrapper* contents =
1394 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); 1412 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index);
1395 Browser* browser = Browser::Create(profile_); 1413 Browser* browser = Browser::Create(profile_);
1396 browser->tabstrip_model()->AppendTabContents(contents, true); 1414 browser->tabstrip_model()->AppendTabContents(contents, true);
1397 browser->window()->Show(); 1415 browser->window()->Show();
1398 } 1416 }
1399 1417
1400 void Browser::ToggleFullscreenMode() { 1418 void Browser::ToggleFullscreenMode() {
1401 #if !defined(OS_MACOSX) 1419 #if !defined(OS_MACOSX)
1402 // In kiosk mode, we always want to be fullscreen. When the browser first 1420 // In kiosk mode, we always want to be fullscreen. When the browser first
1403 // starts we're not yet fullscreen, so let the initial toggle go through. 1421 // starts we're not yet fullscreen, so let the initial toggle go through.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 1597
1580 void Browser::Zoom(PageZoom::Function zoom_function) { 1598 void Browser::Zoom(PageZoom::Function zoom_function) {
1581 static const UserMetricsAction kActions[] = { 1599 static const UserMetricsAction kActions[] = {
1582 UserMetricsAction("ZoomMinus"), 1600 UserMetricsAction("ZoomMinus"),
1583 UserMetricsAction("ZoomNormal"), 1601 UserMetricsAction("ZoomNormal"),
1584 UserMetricsAction("ZoomPlus") 1602 UserMetricsAction("ZoomPlus")
1585 }; 1603 };
1586 1604
1587 UserMetrics::RecordAction(kActions[zoom_function - PageZoom::ZOOM_OUT], 1605 UserMetrics::RecordAction(kActions[zoom_function - PageZoom::ZOOM_OUT],
1588 profile_); 1606 profile_);
1589 TabContents* tab_contents = GetSelectedTabContents(); 1607 TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper();
1590 tab_contents->render_view_host()->Zoom(zoom_function); 1608 tab_contents->render_view_host()->Zoom(zoom_function);
1591 } 1609 }
1592 1610
1593 void Browser::FocusToolbar() { 1611 void Browser::FocusToolbar() {
1594 UserMetrics::RecordAction(UserMetricsAction("FocusToolbar"), profile_); 1612 UserMetrics::RecordAction(UserMetricsAction("FocusToolbar"), profile_);
1595 window_->FocusToolbar(); 1613 window_->FocusToolbar();
1596 } 1614 }
1597 1615
1598 void Browser::FocusAppMenu() { 1616 void Browser::FocusAppMenu() {
1599 UserMetrics::RecordAction(UserMetricsAction("FocusAppMenu"), profile_); 1617 UserMetrics::RecordAction(UserMetricsAction("FocusAppMenu"), profile_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, 1668 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE,
1651 string16(), directory, 1669 string16(), directory,
1652 NULL, 0, FILE_PATH_LITERAL(""), 1670 NULL, 0, FILE_PATH_LITERAL(""),
1653 parent_window, NULL); 1671 parent_window, NULL);
1654 #endif 1672 #endif
1655 } 1673 }
1656 1674
1657 void Browser::OpenCreateShortcutsDialog() { 1675 void Browser::OpenCreateShortcutsDialog() {
1658 UserMetrics::RecordAction(UserMetricsAction("CreateShortcut"), profile_); 1676 UserMetrics::RecordAction(UserMetricsAction("CreateShortcut"), profile_);
1659 #if defined(OS_WIN) || defined(OS_LINUX) 1677 #if defined(OS_WIN) || defined(OS_LINUX)
1660 TabContents* current_tab = GetSelectedTabContents(); 1678 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper();
1661 DCHECK(current_tab && web_app::IsValidUrl(current_tab->GetURL())) << 1679 DCHECK(current_tab &&
1662 "Menu item should be disabled."; 1680 web_app::IsValidUrl(current_tab->tab_contents()->GetURL())) <<
1681 "Menu item should be disabled.";
1663 1682
1664 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); 1683 NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry();
1665 if (!entry) 1684 if (!entry)
1666 return; 1685 return;
1667 1686
1668 // RVH's GetApplicationInfo should not be called before it returns. 1687 // RVH's GetApplicationInfo should not be called before it returns.
1669 DCHECK(pending_web_app_action_ == NONE); 1688 DCHECK(pending_web_app_action_ == NONE);
1670 pending_web_app_action_ = CREATE_SHORTCUT; 1689 pending_web_app_action_ = CREATE_SHORTCUT;
1671 1690
1672 // Start fetching web app info for CreateApplicationShortcut dialog and show 1691 // Start fetching web app info for CreateApplicationShortcut dialog and show
(...skipping 11 matching lines...) Expand all
1684 uma_string = "DevTools_ToggleConsole"; 1703 uma_string = "DevTools_ToggleConsole";
1685 break; 1704 break;
1686 case DEVTOOLS_TOGGLE_ACTION_NONE: 1705 case DEVTOOLS_TOGGLE_ACTION_NONE:
1687 case DEVTOOLS_TOGGLE_ACTION_INSPECT: 1706 case DEVTOOLS_TOGGLE_ACTION_INSPECT:
1688 default: 1707 default:
1689 uma_string = "DevTools_ToggleWindow"; 1708 uma_string = "DevTools_ToggleWindow";
1690 break; 1709 break;
1691 } 1710 }
1692 UserMetrics::RecordAction(UserMetricsAction(uma_string.c_str()), profile_); 1711 UserMetrics::RecordAction(UserMetricsAction(uma_string.c_str()), profile_);
1693 DevToolsManager::GetInstance()->ToggleDevToolsWindow( 1712 DevToolsManager::GetInstance()->ToggleDevToolsWindow(
1694 GetSelectedTabContents()->render_view_host(), action); 1713 GetSelectedTabContentsWrapper()->render_view_host(), action);
1695 } 1714 }
1696 1715
1697 void Browser::OpenTaskManager() { 1716 void Browser::OpenTaskManager() {
1698 UserMetrics::RecordAction(UserMetricsAction("TaskManager"), profile_); 1717 UserMetrics::RecordAction(UserMetricsAction("TaskManager"), profile_);
1699 window_->ShowTaskManager(); 1718 window_->ShowTaskManager();
1700 } 1719 }
1701 1720
1702 void Browser::OpenBugReportDialog() { 1721 void Browser::OpenBugReportDialog() {
1703 UserMetrics::RecordAction(UserMetricsAction("ReportBug"), profile_); 1722 UserMetrics::RecordAction(UserMetricsAction("ReportBug"), profile_);
1704 window_->ShowReportBugDialog(); 1723 window_->ShowReportBugDialog();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1758 ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL); 1777 ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL);
1759 ShowSingletonTab(GURL(report_page_url)); 1778 ShowSingletonTab(GURL(report_page_url));
1760 } 1779 }
1761 1780
1762 void Browser::ShowOptionsTab(const std::string& sub_page) { 1781 void Browser::ShowOptionsTab(const std::string& sub_page) {
1763 GURL url(chrome::kChromeUISettingsURL + sub_page); 1782 GURL url(chrome::kChromeUISettingsURL + sub_page);
1764 1783
1765 // See if there is already an options tab open that we can use. 1784 // See if there is already an options tab open that we can use.
1766 TabStripModel* model = tab_handler_->GetTabStripModel(); 1785 TabStripModel* model = tab_handler_->GetTabStripModel();
1767 for (int i = 0; i < model->count(); i++) { 1786 for (int i = 0; i < model->count(); i++) {
1768 TabContents* tc = model->GetTabContentsAt(i); 1787 TabContentsWrapper* tc = model->GetTabContentsAt(i);
1769 const GURL& tab_url = tc->GetURL(); 1788 const GURL& tab_url = tc->tab_contents()->GetURL();
1770 1789
1771 if (tab_url.scheme() == url.scheme() && tab_url.host() == url.host()) { 1790 if (tab_url.scheme() == url.scheme() && tab_url.host() == url.host()) {
1772 // We found an existing options tab, load the URL in this tab. (Note: 1791 // We found an existing options tab, load the URL in this tab. (Note:
1773 // this may cause us to unnecessarily reload the same page. We can't 1792 // this may cause us to unnecessarily reload the same page. We can't
1774 // really detect that unless the options page is permitted to change the 1793 // really detect that unless the options page is permitted to change the
1775 // URL in the address bar, but security policy doesn't allow that. 1794 // URL in the address bar, but security policy doesn't allow that.
1776 browser::NavigateParams params(this, url, PageTransition::GENERATED); 1795 browser::NavigateParams params(this, url, PageTransition::GENERATED);
1777 params.source_contents = tc; 1796 params.source_contents = tc;
1778 browser::Navigate(&params); 1797 browser::Navigate(&params);
1779 model->SelectTabContentsAt(i, false); 1798 model->SelectTabContentsAt(i, false);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 2075
2057 void Browser::ExecuteCommandWithDisposition( 2076 void Browser::ExecuteCommandWithDisposition(
2058 int id, WindowOpenDisposition disposition) { 2077 int id, WindowOpenDisposition disposition) {
2059 // No commands are enabled if there is not yet any selected tab. 2078 // No commands are enabled if there is not yet any selected tab.
2060 // TODO(pkasting): It seems like we should not need this, because either 2079 // TODO(pkasting): It seems like we should not need this, because either
2061 // most/all commands should not have been enabled yet anyway or the ones that 2080 // most/all commands should not have been enabled yet anyway or the ones that
2062 // are enabled should be global, or safe themselves against having no selected 2081 // are enabled should be global, or safe themselves against having no selected
2063 // tab. However, Ben says he tried removing this before and got lots of 2082 // tab. However, Ben says he tried removing this before and got lots of
2064 // crashes, e.g. from Windows sending WM_COMMANDs at random times during 2083 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
2065 // window construction. This probably could use closer examination someday. 2084 // window construction. This probably could use closer examination someday.
2066 if (!GetSelectedTabContents()) 2085 if (!GetSelectedTabContentsWrapper())
2067 return; 2086 return;
2068 2087
2069 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command"; 2088 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command";
2070 2089
2071 // If command execution is blocked then just record the command and return. 2090 // If command execution is blocked then just record the command and return.
2072 if (block_command_execution_) { 2091 if (block_command_execution_) {
2073 // We actually only allow no more than one blocked command, otherwise some 2092 // We actually only allow no more than one blocked command, otherwise some
2074 // commands maybe lost. 2093 // commands maybe lost.
2075 DCHECK_EQ(last_blocked_command_id_, -1); 2094 DCHECK_EQ(last_blocked_command_id_, -1);
2076 last_blocked_command_id_ = id; 2095 last_blocked_command_id_ = id;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 last_blocked_command_disposition_ = CURRENT_TAB; 2280 last_blocked_command_disposition_ = CURRENT_TAB;
2262 } 2281 }
2263 } 2282 }
2264 2283
2265 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { 2284 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) {
2266 if (disposition) 2285 if (disposition)
2267 *disposition = last_blocked_command_disposition_; 2286 *disposition = last_blocked_command_disposition_;
2268 return last_blocked_command_id_; 2287 return last_blocked_command_id_;
2269 } 2288 }
2270 2289
2271 void Browser::UpdateUIForNavigationInTab(TabContents* contents, 2290 void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents,
2272 PageTransition::Type transition, 2291 PageTransition::Type transition,
2273 bool user_initiated) { 2292 bool user_initiated) {
2274 tabstrip_model()->TabNavigating(contents, transition); 2293 tabstrip_model()->TabNavigating(contents, transition);
2275 2294
2276 bool contents_is_selected = contents == GetSelectedTabContents(); 2295 bool contents_is_selected = contents == GetSelectedTabContentsWrapper();
2277 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { 2296 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
2278 // Forcibly reset the location bar if the url is going to change in the 2297 // Forcibly reset the location bar if the url is going to change in the
2279 // current tab, since otherwise it won't discard any ongoing user edits, 2298 // current tab, since otherwise it won't discard any ongoing user edits,
2280 // since it doesn't realize this is a user-initiated action. 2299 // since it doesn't realize this is a user-initiated action.
2281 window()->GetLocationBar()->Revert(); 2300 window()->GetLocationBar()->Revert();
2282 } 2301 }
2283 2302
2284 if (GetStatusBubble()) 2303 if (GetStatusBubble())
2285 GetStatusBubble()->Hide(); 2304 GetStatusBubble()->Hide();
2286 2305
2287 // Update the location bar. This is synchronous. We specifically don't 2306 // Update the location bar. This is synchronous. We specifically don't
2288 // update the load state since the load hasn't started yet and updating it 2307 // update the load state since the load hasn't started yet and updating it
2289 // will put it out of sync with the actual state like whether we're 2308 // will put it out of sync with the actual state like whether we're
2290 // displaying a favicon, which controls the throbber. If we updated it here, 2309 // displaying a favicon, which controls the throbber. If we updated it here,
2291 // the throbber will show the default favicon for a split second when 2310 // the throbber will show the default favicon for a split second when
2292 // navigating away from the new tab page. 2311 // navigating away from the new tab page.
2293 ScheduleUIUpdate(contents, TabContents::INVALIDATE_URL); 2312 ScheduleUIUpdate(contents->tab_contents(), TabContents::INVALIDATE_URL);
2294 2313
2295 if (contents_is_selected) 2314 if (contents_is_selected)
2296 contents->Focus(); 2315 contents->tab_contents()->Focus();
2297 } 2316 }
2298 2317
2299 GURL Browser::GetHomePage() const { 2318 GURL Browser::GetHomePage() const {
2300 // --homepage overrides any preferences. 2319 // --homepage overrides any preferences.
2301 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 2320 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2302 if (command_line.HasSwitch(switches::kHomePage)) { 2321 if (command_line.HasSwitch(switches::kHomePage)) {
2303 // TODO(evanm): clean up usage of DIR_CURRENT. 2322 // TODO(evanm): clean up usage of DIR_CURRENT.
2304 // http://code.google.com/p/chromium/issues/detail?id=60630 2323 // http://code.google.com/p/chromium/issues/detail?id=60630
2305 // For now, allow this code to call getcwd(). 2324 // For now, allow this code to call getcwd().
2306 base::ThreadRestrictions::ScopedAllowIO allow_io; 2325 base::ThreadRestrictions::ScopedAllowIO allow_io;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 return profile(); 2365 return profile();
2347 } 2366 }
2348 2367
2349 Browser* Browser::AsBrowser() { 2368 Browser* Browser::AsBrowser() {
2350 return this; 2369 return this;
2351 } 2370 }
2352 2371
2353 /////////////////////////////////////////////////////////////////////////////// 2372 ///////////////////////////////////////////////////////////////////////////////
2354 // Browser, TabStripModelDelegate implementation: 2373 // Browser, TabStripModelDelegate implementation:
2355 2374
2356 TabContents* Browser::AddBlankTab(bool foreground) { 2375 TabContentsWrapper* Browser::AddBlankTab(bool foreground) {
2357 return AddBlankTabAt(-1, foreground); 2376 return AddBlankTabAt(-1, foreground);
2358 } 2377 }
2359 2378
2360 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { 2379 TabContentsWrapper* Browser::AddBlankTabAt(int index, bool foreground) {
2361 // Time new tab page creation time. We keep track of the timing data in 2380 // Time new tab page creation time. We keep track of the timing data in
2362 // TabContents, but we want to include the time it takes to create the 2381 // TabContents, but we want to include the time it takes to create the
2363 // TabContents object too. 2382 // TabContents object too.
2364 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); 2383 base::TimeTicks new_tab_start_time = base::TimeTicks::Now();
2365 browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), 2384 browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL),
2366 PageTransition::TYPED); 2385 PageTransition::TYPED);
2367 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 2386 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
2368 params.tabstrip_index = index; 2387 params.tabstrip_index = index;
2369 browser::Navigate(&params); 2388 browser::Navigate(&params);
2370 params.target_contents->set_new_tab_start_time(new_tab_start_time); 2389 params.target_contents->tab_contents()->set_new_tab_start_time(
2390 new_tab_start_time);
2371 return params.target_contents; 2391 return params.target_contents;
2372 } 2392 }
2373 2393
2374 Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, 2394 Browser* Browser::CreateNewStripWithContents(
2375 const gfx::Rect& window_bounds, 2395 TabContentsWrapper* detached_contents,
2376 const DockInfo& dock_info, 2396 const gfx::Rect& window_bounds,
2377 bool maximize) { 2397 const DockInfo& dock_info,
2398 bool maximize) {
2378 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); 2399 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP));
2379 2400
2380 gfx::Rect new_window_bounds = window_bounds; 2401 gfx::Rect new_window_bounds = window_bounds;
2381 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) 2402 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize))
2382 dock_info.AdjustOtherWindowBounds(); 2403 dock_info.AdjustOtherWindowBounds();
2383 2404
2384 // Create an empty new browser window the same size as the old one. 2405 // Create an empty new browser window the same size as the old one.
2385 Browser* browser = new Browser(TYPE_NORMAL, profile_); 2406 Browser* browser = new Browser(TYPE_NORMAL, profile_);
2386 browser->set_override_bounds(new_window_bounds); 2407 browser->set_override_bounds(new_window_bounds);
2387 browser->set_maximized_state( 2408 browser->set_maximized_state(
2388 maximize ? MAXIMIZED_STATE_MAXIMIZED : MAXIMIZED_STATE_UNMAXIMIZED); 2409 maximize ? MAXIMIZED_STATE_MAXIMIZED : MAXIMIZED_STATE_UNMAXIMIZED);
2389 browser->CreateBrowserWindow(); 2410 browser->CreateBrowserWindow();
2390 browser->tabstrip_model()->AppendTabContents(detached_contents, true); 2411 browser->tabstrip_model()->AppendTabContents(detached_contents, true);
2391 // Make sure the loading state is updated correctly, otherwise the throbber 2412 // Make sure the loading state is updated correctly, otherwise the throbber
2392 // won't start if the page is loading. 2413 // won't start if the page is loading.
2393 browser->LoadingStateChanged(detached_contents); 2414 browser->LoadingStateChanged(detached_contents->tab_contents());
2394 return browser; 2415 return browser;
2395 } 2416 }
2396 2417
2397 void Browser::ContinueDraggingDetachedTab(TabContents* contents, 2418 void Browser::ContinueDraggingDetachedTab(TabContentsWrapper* contents,
2398 const gfx::Rect& window_bounds, 2419 const gfx::Rect& window_bounds,
2399 const gfx::Rect& tab_bounds) { 2420 const gfx::Rect& tab_bounds) {
2400 Browser* browser = new Browser(TYPE_NORMAL, profile_); 2421 Browser* browser = new Browser(TYPE_NORMAL, profile_);
2401 browser->set_override_bounds(window_bounds); 2422 browser->set_override_bounds(window_bounds);
2402 browser->CreateBrowserWindow(); 2423 browser->CreateBrowserWindow();
2403 browser->tabstrip_model()->AppendTabContents(contents, true); 2424 browser->tabstrip_model()->AppendTabContents(contents, true);
2404 browser->LoadingStateChanged(contents); 2425 browser->LoadingStateChanged(contents->tab_contents());
2405 browser->window()->Show(); 2426 browser->window()->Show();
2406 browser->window()->ContinueDraggingDetachedTab(tab_bounds); 2427 browser->window()->ContinueDraggingDetachedTab(tab_bounds);
2407 } 2428 }
2408 2429
2409 int Browser::GetDragActions() const { 2430 int Browser::GetDragActions() const {
2410 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? 2431 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ?
2411 TabStripModelDelegate::TAB_MOVE_ACTION : 0); 2432 TabStripModelDelegate::TAB_MOVE_ACTION : 0);
2412 } 2433 }
2413 2434
2414 TabContents* Browser::CreateTabContentsForURL( 2435 TabContentsWrapper* Browser::CreateTabContentsForURL(
2415 const GURL& url, const GURL& referrer, Profile* profile, 2436 const GURL& url, const GURL& referrer, Profile* profile,
2416 PageTransition::Type transition, bool defer_load, 2437 PageTransition::Type transition, bool defer_load,
2417 SiteInstance* instance) const { 2438 SiteInstance* instance) const {
2418 TabContents* contents = new TabContents(profile, instance, 2439 TabContentsWrapper* contents = TabContentsFactory(profile, instance,
2419 MSG_ROUTING_NONE, 2440 MSG_ROUTING_NONE,
2420 tab_handler_->GetTabStripModel()->GetSelectedTabContents(), NULL); 2441 GetSelectedTabContents(), NULL);
2421
2422 if (!defer_load) { 2442 if (!defer_load) {
2423 // Load the initial URL before adding the new tab contents to the tab strip 2443 // Load the initial URL before adding the new tab contents to the tab strip
2424 // so that the tab contents has navigation state. 2444 // so that the tab contents has navigation state.
2425 contents->controller().LoadURL(url, referrer, transition); 2445 contents->controller().LoadURL(url, referrer, transition);
2426 } 2446 }
2427 2447
2428 return contents; 2448 return contents;
2429 } 2449 }
2430 2450
2431 bool Browser::CanDuplicateContentsAt(int index) { 2451 bool Browser::CanDuplicateContentsAt(int index) {
2432 NavigationController& nc = GetTabContentsAt(index)->controller(); 2452 NavigationController& nc = GetTabContentsAt(index)->controller();
2433 return nc.tab_contents() && nc.GetLastCommittedEntry(); 2453 return nc.tab_contents() && nc.GetLastCommittedEntry();
2434 } 2454 }
2435 2455
2436 void Browser::DuplicateContentsAt(int index) { 2456 void Browser::DuplicateContentsAt(int index) {
2437 TabContents* contents = GetTabContentsAt(index); 2457 TabContentsWrapper* contents = GetTabContentsWrapperAt(index);
2438 TabContents* new_contents = NULL; 2458 TabContents* new_contents = NULL;
2439 DCHECK(contents); 2459 DCHECK(contents);
2440 bool pinned = false; 2460 bool pinned = false;
2441 2461
2442 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2462 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
2443 // If this is a tabbed browser, just create a duplicate tab inside the same 2463 // If this is a tabbed browser, just create a duplicate tab inside the same
2444 // window next to the tab being duplicated. 2464 // window next to the tab being duplicated.
2445 new_contents = contents->Clone(); 2465 TabContentsWrapper* wrapper = contents->Clone();
2466 new_contents = wrapper->tab_contents();
2446 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); 2467 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index);
2447 int add_types = TabStripModel::ADD_SELECTED | 2468 int add_types = TabStripModel::ADD_SELECTED |
2448 TabStripModel::ADD_INHERIT_GROUP | 2469 TabStripModel::ADD_INHERIT_GROUP |
2449 (pinned ? TabStripModel::ADD_PINNED : 0); 2470 (pinned ? TabStripModel::ADD_PINNED : 0);
2450 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, 2471 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1,
2451 new_contents, 2472 wrapper,
2452 add_types); 2473 add_types);
2453 } else { 2474 } else {
2454 Browser* browser = NULL; 2475 Browser* browser = NULL;
2455 if (type_ & TYPE_APP) { 2476 if (type_ & TYPE_APP) {
2456 DCHECK((type_ & TYPE_POPUP) == 0); 2477 DCHECK((type_ & TYPE_POPUP) == 0);
2457 DCHECK(type_ != TYPE_APP_PANEL); 2478 DCHECK(type_ != TYPE_APP_PANEL);
2458 browser = Browser::CreateForApp(app_name_, extension_app_, profile_, 2479 browser = Browser::CreateForApp(app_name_, extension_app_, profile_,
2459 false); 2480 false);
2460 } else if (type_ == TYPE_POPUP) { 2481 } else if (type_ == TYPE_POPUP) {
2461 browser = Browser::CreateForType(TYPE_POPUP, profile_); 2482 browser = Browser::CreateForType(TYPE_POPUP, profile_);
2462 } 2483 }
2463 2484
2464 // Preserve the size of the original window. The new window has already 2485 // Preserve the size of the original window. The new window has already
2465 // been given an offset by the OS, so we shouldn't copy the old bounds. 2486 // been given an offset by the OS, so we shouldn't copy the old bounds.
2466 BrowserWindow* new_window = browser->window(); 2487 BrowserWindow* new_window = browser->window();
2467 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 2488 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
2468 window()->GetRestoredBounds().size())); 2489 window()->GetRestoredBounds().size()));
2469 2490
2470 // We need to show the browser now. Otherwise ContainerWin assumes the 2491 // We need to show the browser now. Otherwise ContainerWin assumes the
2471 // TabContents is invisible and won't size it. 2492 // TabContents is invisible and won't size it.
2472 browser->window()->Show(); 2493 browser->window()->Show();
2473 2494
2474 // The page transition below is only for the purpose of inserting the tab. 2495 // The page transition below is only for the purpose of inserting the tab.
2475 new_contents = browser->AddTab( 2496 new_contents = browser->AddTab(contents->Clone(), PageTransition::LINK);
2476 contents->Clone()->controller().tab_contents(),
2477 PageTransition::LINK);
2478 } 2497 }
2479 2498
2480 if (profile_->HasSessionService()) { 2499 if (profile_->HasSessionService()) {
2481 SessionService* session_service = profile_->GetSessionService(); 2500 SessionService* session_service = profile_->GetSessionService();
2482 if (session_service) 2501 if (session_service)
2483 session_service->TabRestored(&new_contents->controller(), pinned); 2502 session_service->TabRestored(&new_contents->controller(), pinned);
2484 } 2503 }
2485 } 2504 }
2486 2505
2487 void Browser::CloseFrameAfterDragSession() { 2506 void Browser::CloseFrameAfterDragSession() {
2488 #if defined(OS_WIN) || defined(OS_LINUX) 2507 #if defined(OS_WIN) || defined(OS_LINUX)
2489 // This is scheduled to run after we return to the message loop because 2508 // This is scheduled to run after we return to the message loop because
2490 // otherwise the frame will think the drag session is still active and ignore 2509 // otherwise the frame will think the drag session is still active and ignore
2491 // the request. 2510 // the request.
2492 // TODO(port): figure out what is required here in a cross-platform world 2511 // TODO(port): figure out what is required here in a cross-platform world
2493 MessageLoop::current()->PostTask( 2512 MessageLoop::current()->PostTask(
2494 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); 2513 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame));
2495 #endif 2514 #endif
2496 } 2515 }
2497 2516
2498 void Browser::CreateHistoricalTab(TabContents* contents) { 2517 void Browser::CreateHistoricalTab(TabContentsWrapper* contents) {
2499 // We don't create historical tabs for incognito windows or windows without 2518 // We don't create historical tabs for incognito windows or windows without
2500 // profiles. 2519 // profiles.
2501 if (!profile() || profile()->IsOffTheRecord() || 2520 if (!profile() || profile()->IsOffTheRecord() ||
2502 !profile()->GetTabRestoreService()) { 2521 !profile()->GetTabRestoreService()) {
2503 return; 2522 return;
2504 } 2523 }
2505 2524
2506 // We only create historical tab entries for tabbed browser windows. 2525 // We only create historical tab entries for tabbed browser windows.
2507 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2526 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
2508 profile()->GetTabRestoreService()->CreateHistoricalTab( 2527 profile()->GetTabRestoreService()->CreateHistoricalTab(
2509 &contents->controller()); 2528 &contents->controller());
2510 } 2529 }
2511 } 2530 }
2512 2531
2513 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { 2532 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) {
2514 return Browser::RunUnloadEventsHelper(contents); 2533 return Browser::RunUnloadEventsHelper(contents->tab_contents());
2515 } 2534 }
2516 2535
2517 bool Browser::CanReloadContents(TabContents* source) const { 2536 bool Browser::CanReloadContents(TabContents* source) const {
2518 return type() != TYPE_DEVTOOLS; 2537 return type() != TYPE_DEVTOOLS;
2519 } 2538 }
2520 2539
2521 bool Browser::CanCloseContentsAt(int index) { 2540 bool Browser::CanCloseContentsAt(int index) {
2522 if (!CanCloseTab()) 2541 if (!CanCloseTab())
2523 return false; 2542 return false;
2524 if (tab_handler_->GetTabStripModel()->count() > 1) 2543 if (tab_handler_->GetTabStripModel()->count() > 1)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 bool Browser::LargeIconsPermitted() const { 2582 bool Browser::LargeIconsPermitted() const {
2564 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because 2583 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
2565 // for those windows, we already have a big icon in the top-left outside any 2584 // for those windows, we already have a big icon in the top-left outside any
2566 // tab. Having big tab icons too looks kinda redonk. 2585 // tab. Having big tab icons too looks kinda redonk.
2567 return TYPE_EXTENSION_APP != type(); 2586 return TYPE_EXTENSION_APP != type();
2568 } 2587 }
2569 2588
2570 /////////////////////////////////////////////////////////////////////////////// 2589 ///////////////////////////////////////////////////////////////////////////////
2571 // Browser, TabStripModelObserver implementation: 2590 // Browser, TabStripModelObserver implementation:
2572 2591
2573 void Browser::TabInsertedAt(TabContents* contents, 2592 void Browser::TabInsertedAt(TabContentsWrapper* contents,
2574 int index, 2593 int index,
2575 bool foreground) { 2594 bool foreground) {
2576 contents->set_delegate(this); 2595 contents->tab_contents()->set_delegate(this);
2577 contents->controller().SetWindowID(session_id()); 2596 contents->controller().SetWindowID(session_id());
2578 2597
2579 SyncHistoryWithTabs(index); 2598 SyncHistoryWithTabs(index);
2580 2599
2581 // Make sure the loading state is updated correctly, otherwise the throbber 2600 // Make sure the loading state is updated correctly, otherwise the throbber
2582 // won't start if the page is loading. 2601 // won't start if the page is loading.
2583 LoadingStateChanged(contents); 2602 LoadingStateChanged(contents->tab_contents());
2584 2603
2585 // If the tab crashes in the beforeunload or unload handler, it won't be 2604 // If the tab crashes in the beforeunload or unload handler, it won't be
2586 // able to ack. But we know we can close it. 2605 // able to ack. But we know we can close it.
2587 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, 2606 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
2588 Source<TabContents>(contents)); 2607 Source<TabContentsWrapper>(contents));
2589 } 2608 }
2590 2609
2591 void Browser::TabClosingAt(TabStripModel* tab_strip_model, 2610 void Browser::TabClosingAt(TabStripModel* tab_strip_model,
2592 TabContents* contents, 2611 TabContentsWrapper* contents,
2593 int index) { 2612 int index) {
2594 NotificationService::current()->Notify( 2613 NotificationService::current()->Notify(
2595 NotificationType::TAB_CLOSING, 2614 NotificationType::TAB_CLOSING,
2596 Source<NavigationController>(&contents->controller()), 2615 Source<NavigationController>(&contents->controller()),
2597 NotificationService::NoDetails()); 2616 NotificationService::NoDetails());
2598 2617
2599 // Sever the TabContents' connection back to us. 2618 // Sever the TabContents' connection back to us.
2600 contents->set_delegate(NULL); 2619 contents->tab_contents()->set_delegate(NULL);
2601 } 2620 }
2602 2621
2603 void Browser::TabDetachedAt(TabContents* contents, int index) { 2622 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) {
2604 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); 2623 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
2605 } 2624 }
2606 2625
2607 void Browser::TabDeselectedAt(TabContents* contents, int index) { 2626 void Browser::TabDeselectedAt(TabContentsWrapper* contents, int index) {
2608 if (instant()) 2627 if (instant())
2609 instant()->DestroyPreviewContents(); 2628 instant()->DestroyPreviewContents();
2610 2629
2611 // Save what the user's currently typing, so it can be restored when we 2630 // Save what the user's currently typing, so it can be restored when we
2612 // switch back to this tab. 2631 // switch back to this tab.
2613 window_->GetLocationBar()->SaveStateToContents(contents); 2632 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents());
2614 } 2633 }
2615 2634
2616 void Browser::TabSelectedAt(TabContents* old_contents, 2635 void Browser::TabSelectedAt(TabContentsWrapper* old_contents,
2617 TabContents* new_contents, 2636 TabContentsWrapper* new_contents,
2618 int index, 2637 int index,
2619 bool user_gesture) { 2638 bool user_gesture) {
2620 DCHECK(old_contents != new_contents); 2639 DCHECK(old_contents != new_contents);
2621 2640
2622 // If we have any update pending, do it now. 2641 // If we have any update pending, do it now.
2623 if (!chrome_updater_factory_.empty() && old_contents) 2642 if (!chrome_updater_factory_.empty() && old_contents)
2624 ProcessPendingUIUpdates(); 2643 ProcessPendingUIUpdates();
2625 2644
2626 // Propagate the profile to the location bar. 2645 // Propagate the profile to the location bar.
2627 UpdateToolbar(true); 2646 UpdateToolbar(true);
2628 2647
2629 // Update reload/stop state. 2648 // Update reload/stop state.
2630 UpdateReloadStopState(new_contents->is_loading(), true); 2649 UpdateReloadStopState(new_contents->tab_contents()->is_loading(), true);
2631 2650
2632 // Update commands to reflect current state. 2651 // Update commands to reflect current state.
2633 UpdateCommandsForTabState(); 2652 UpdateCommandsForTabState();
2634 2653
2635 // Reset the status bubble. 2654 // Reset the status bubble.
2636 StatusBubble* status_bubble = GetStatusBubble(); 2655 StatusBubble* status_bubble = GetStatusBubble();
2637 if (status_bubble) { 2656 if (status_bubble) {
2638 status_bubble->Hide(); 2657 status_bubble->Hide();
2639 2658
2640 // Show the loading state (if any). 2659 // Show the loading state (if any).
2641 status_bubble->SetStatus(WideToUTF16Hack( 2660 status_bubble->SetStatus(WideToUTF16Hack(
2642 GetSelectedTabContents()->GetStatusText())); 2661 GetSelectedTabContents()->GetStatusText()));
2643 } 2662 }
2644 2663
2645 if (HasFindBarController()) { 2664 if (HasFindBarController()) {
2646 find_bar_controller_->ChangeTabContents(new_contents); 2665 find_bar_controller_->ChangeTabContents(new_contents->tab_contents());
2647 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); 2666 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
2648 } 2667 }
2649 2668
2650 // Update sessions. Don't force creation of sessions. If sessions doesn't 2669 // Update sessions. Don't force creation of sessions. If sessions doesn't
2651 // exist, the change will be picked up by sessions when created. 2670 // exist, the change will be picked up by sessions when created.
2652 if (profile_->HasSessionService()) { 2671 if (profile_->HasSessionService()) {
2653 SessionService* session_service = profile_->GetSessionService(); 2672 SessionService* session_service = profile_->GetSessionService();
2654 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { 2673 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) {
2655 session_service->SetSelectedTabInWindow( 2674 session_service->SetSelectedTabInWindow(
2656 session_id(), tab_handler_->GetTabStripModel()->selected_index()); 2675 session_id(), tab_handler_->GetTabStripModel()->selected_index());
2657 } 2676 }
2658 } 2677 }
2659 } 2678 }
2660 2679
2661 void Browser::TabMoved(TabContents* contents, 2680 void Browser::TabMoved(TabContentsWrapper* contents,
2662 int from_index, 2681 int from_index,
2663 int to_index) { 2682 int to_index) {
2664 DCHECK(from_index >= 0 && to_index >= 0); 2683 DCHECK(from_index >= 0 && to_index >= 0);
2665 // Notify the history service. 2684 // Notify the history service.
2666 SyncHistoryWithTabs(std::min(from_index, to_index)); 2685 SyncHistoryWithTabs(std::min(from_index, to_index));
2667 } 2686 }
2668 2687
2669 void Browser::TabReplacedAt(TabContents* old_contents, 2688 void Browser::TabReplacedAt(TabContentsWrapper* old_contents,
2670 TabContents* new_contents, 2689 TabContentsWrapper* new_contents,
2671 int index) { 2690 int index) {
2672 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); 2691 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
2673 TabInsertedAt(new_contents, index, 2692 TabInsertedAt(new_contents, index,
2674 (index == tab_handler_->GetTabStripModel()->selected_index())); 2693 (index == tab_handler_->GetTabStripModel()->selected_index()));
2675 2694
2676 int entry_count = new_contents->controller().entry_count(); 2695 int entry_count = new_contents->controller().entry_count();
2677 if (entry_count > 0) { 2696 if (entry_count > 0) {
2678 // Send out notification so that observers are updated appropriately. 2697 // Send out notification so that observers are updated appropriately.
2679 new_contents->controller().NotifyEntryChanged( 2698 new_contents->controller().NotifyEntryChanged(
2680 new_contents->controller().GetEntryAtIndex(entry_count - 1), 2699 new_contents->controller().GetEntryAtIndex(entry_count - 1),
2681 entry_count - 1); 2700 entry_count - 1);
2682 } 2701 }
2683 2702
2684 SessionService* session_service = profile()->GetSessionService(); 2703 SessionService* session_service = profile()->GetSessionService();
2685 if (session_service) { 2704 if (session_service) {
2686 // The new_contents may end up with a different navigation stack. Force 2705 // The new_contents may end up with a different navigation stack. Force
2687 // the session service to update itself. 2706 // the session service to update itself.
2688 session_service->TabRestored( 2707 session_service->TabRestored(
2689 &new_contents->controller(), 2708 &new_contents->controller(),
2690 tab_handler_->GetTabStripModel()->IsTabPinned(index)); 2709 tab_handler_->GetTabStripModel()->IsTabPinned(index));
2691 } 2710 }
2692 } 2711 }
2693 2712
2694 void Browser::TabPinnedStateChanged(TabContents* contents, int index) { 2713 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) {
2695 if (!profile()->HasSessionService()) 2714 if (!profile()->HasSessionService())
2696 return; 2715 return;
2697 SessionService* session_service = profile()->GetSessionService(); 2716 SessionService* session_service = profile()->GetSessionService();
2698 if (session_service) { 2717 if (session_service) {
2699 session_service->SetPinnedState( 2718 session_service->SetPinnedState(
2700 session_id(), 2719 session_id(),
2701 GetTabContentsAt(index)->controller().session_id(), 2720 GetTabContentsAt(index)->controller().session_id(),
2702 tab_handler_->GetTabStripModel()->IsTabPinned(index)); 2721 tab_handler_->GetTabStripModel()->IsTabPinned(index));
2703 } 2722 }
2704 } 2723 }
(...skipping 13 matching lines...) Expand all
2718 2737
2719 /////////////////////////////////////////////////////////////////////////////// 2738 ///////////////////////////////////////////////////////////////////////////////
2720 // Browser, TabContentsDelegate implementation: 2739 // Browser, TabContentsDelegate implementation:
2721 2740
2722 void Browser::OpenURLFromTab(TabContents* source, 2741 void Browser::OpenURLFromTab(TabContents* source,
2723 const GURL& url, 2742 const GURL& url,
2724 const GURL& referrer, 2743 const GURL& referrer,
2725 WindowOpenDisposition disposition, 2744 WindowOpenDisposition disposition,
2726 PageTransition::Type transition) { 2745 PageTransition::Type transition) {
2727 browser::NavigateParams params(this, url, transition); 2746 browser::NavigateParams params(this, url, transition);
2728 params.source_contents = source; 2747 params.source_contents =
2748 tabstrip_model()->GetTabContentsAt(
2749 tabstrip_model()->GetWrapperIndex(source));
2729 params.referrer = referrer; 2750 params.referrer = referrer;
2730 params.disposition = disposition; 2751 params.disposition = disposition;
2731 params.tabstrip_add_types = TabStripModel::ADD_NONE; 2752 params.tabstrip_add_types = TabStripModel::ADD_NONE;
2732 browser::Navigate(&params); 2753 browser::Navigate(&params);
2733 } 2754 }
2734 2755
2735 void Browser::NavigationStateChanged(const TabContents* source, 2756 void Browser::NavigationStateChanged(const TabContents* source,
2736 unsigned changed_flags) { 2757 unsigned changed_flags) {
2737 // Only update the UI when something visible has changed. 2758 // Only update the UI when something visible has changed.
2738 if (changed_flags) 2759 if (changed_flags)
(...skipping 26 matching lines...) Expand all
2765 GdkScreen* screen = gdk_screen_get_default(); 2786 GdkScreen* screen = gdk_screen_get_default();
2766 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; 2787 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor;
2767 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; 2788 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor;
2768 if (initial_pos.width() > max_width || initial_pos.width() == 0 || 2789 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
2769 initial_pos.height() > max_height || initial_pos.height() == 0) { 2790 initial_pos.height() > max_height || initial_pos.height() == 0) {
2770 disposition = NEW_FOREGROUND_TAB; 2791 disposition = NEW_FOREGROUND_TAB;
2771 } 2792 }
2772 } 2793 }
2773 #endif 2794 #endif
2774 2795
2775 browser::NavigateParams params(this, new_contents); 2796 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents);
2776 params.source_contents = source; 2797 browser::NavigateParams params(this, wrapper);
2777 params.disposition = disposition; 2798 params.source_contents =
2778 params.window_bounds = initial_pos; 2799 tabstrip_model()->GetTabContentsAt(
2779 browser::Navigate(&params); 2800 tabstrip_model()->GetWrapperIndex(source));
2801 params.disposition = disposition;
2802 params.window_bounds = initial_pos;
2803 browser::Navigate(&params);
2780 } 2804 }
2781 2805
2782 void Browser::ActivateContents(TabContents* contents) { 2806 void Browser::ActivateContents(TabContents* contents) {
2783 tab_handler_->GetTabStripModel()->SelectTabContentsAt( 2807 tab_handler_->GetTabStripModel()->SelectTabContentsAt(
2784 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents), false); 2808 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false);
2785 window_->Activate(); 2809 window_->Activate();
2786 } 2810 }
2787 2811
2788 void Browser::DeactivateContents(TabContents* contents) { 2812 void Browser::DeactivateContents(TabContents* contents) {
2789 window_->Deactivate(); 2813 window_->Deactivate();
2790 } 2814 }
2791 2815
2792 void Browser::LoadingStateChanged(TabContents* source) { 2816 void Browser::LoadingStateChanged(TabContents* source) {
2793 window_->UpdateLoadingAnimations( 2817 window_->UpdateLoadingAnimations(
2794 tab_handler_->GetTabStripModel()->TabsAreLoading()); 2818 tab_handler_->GetTabStripModel()->TabsAreLoading());
2795 window_->UpdateTitleBar(); 2819 window_->UpdateTitleBar();
2796 2820
2797 if (source == GetSelectedTabContents()) { 2821 TabContents* selected_contents = GetSelectedTabContents();
2822 if (source == selected_contents) {
2798 UpdateReloadStopState(source->is_loading(), false); 2823 UpdateReloadStopState(source->is_loading(), false);
2799 if (GetStatusBubble()) { 2824 if (GetStatusBubble()) {
2800 GetStatusBubble()->SetStatus(WideToUTF16( 2825 GetStatusBubble()->SetStatus(WideToUTF16(
2801 GetSelectedTabContents()->GetStatusText())); 2826 GetSelectedTabContents()->GetStatusText()));
2802 } 2827 }
2803 2828
2804 if (!source->is_loading() && 2829 if (!source->is_loading() &&
2805 pending_web_app_action_ == UPDATE_SHORTCUT) { 2830 pending_web_app_action_ == UPDATE_SHORTCUT) {
2806 // Schedule a shortcut update when web application info is available if 2831 // Schedule a shortcut update when web application info is available if
2807 // last committed entry is not NULL. Last committed entry could be NULL 2832 // last committed entry is not NULL. Last committed entry could be NULL
(...skipping 12 matching lines...) Expand all
2820 void Browser::CloseContents(TabContents* source) { 2845 void Browser::CloseContents(TabContents* source) {
2821 if (is_attempting_to_close_browser_) { 2846 if (is_attempting_to_close_browser_) {
2822 // If we're trying to close the browser, just clear the state related to 2847 // If we're trying to close the browser, just clear the state related to
2823 // waiting for unload to fire. Don't actually try to close the tab as it 2848 // waiting for unload to fire. Don't actually try to close the tab as it
2824 // will go down the slow shutdown path instead of the fast path of killing 2849 // will go down the slow shutdown path instead of the fast path of killing
2825 // all the renderer processes. 2850 // all the renderer processes.
2826 ClearUnloadState(source); 2851 ClearUnloadState(source);
2827 return; 2852 return;
2828 } 2853 }
2829 2854
2830 int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents(source); 2855 int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source);
2831 if (index == TabStripModel::kNoTab) { 2856 if (index == TabStripModel::kNoTab) {
2832 NOTREACHED() << "CloseContents called for tab not in our strip"; 2857 NOTREACHED() << "CloseContents called for tab not in our strip";
2833 return; 2858 return;
2834 } 2859 }
2835 tab_handler_->GetTabStripModel()->CloseTabContentsAt( 2860 tab_handler_->GetTabStripModel()->CloseTabContentsAt(
2836 index, 2861 index,
2837 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); 2862 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB);
2838 } 2863 }
2839 2864
2840 void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { 2865 void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) {
2841 if ((type() & TYPE_POPUP) == 0) { 2866 if ((type() & TYPE_POPUP) == 0) {
2842 NOTREACHED() << "moving invalid browser type"; 2867 NOTREACHED() << "moving invalid browser type";
2843 return; 2868 return;
2844 } 2869 }
2845 window_->SetBounds(pos); 2870 window_->SetBounds(pos);
2846 } 2871 }
2847 2872
2848 void Browser::DetachContents(TabContents* source) { 2873 void Browser::DetachContents(TabContents* source) {
2849 int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents(source); 2874 int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source);
2850 if (index >= 0) 2875 if (index >= 0)
2851 tab_handler_->GetTabStripModel()->DetachTabContentsAt(index); 2876 tab_handler_->GetTabStripModel()->DetachTabContentsAt(index);
2852 } 2877 }
2853 2878
2854 bool Browser::IsPopup(const TabContents* source) const { 2879 bool Browser::IsPopup(const TabContents* source) const {
2855 // A non-tabbed BROWSER is an unconstrained popup. 2880 // A non-tabbed BROWSER is an unconstrained popup.
2856 return !!(type() & TYPE_POPUP); 2881 return !!(type() & TYPE_POPUP);
2857 } 2882 }
2858 2883
2859 void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) { 2884 void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2903 void Browser::ContentsZoomChange(bool zoom_in) { 2928 void Browser::ContentsZoomChange(bool zoom_in) {
2904 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); 2929 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
2905 } 2930 }
2906 2931
2907 void Browser::OnContentSettingsChange(TabContents* source) { 2932 void Browser::OnContentSettingsChange(TabContents* source) {
2908 if (source == GetSelectedTabContents()) 2933 if (source == GetSelectedTabContents())
2909 window_->GetLocationBar()->UpdateContentSettingsIcons(); 2934 window_->GetLocationBar()->UpdateContentSettingsIcons();
2910 } 2935 }
2911 2936
2912 void Browser::SetTabContentBlocked(TabContents* contents, bool blocked) { 2937 void Browser::SetTabContentBlocked(TabContents* contents, bool blocked) {
2913 int index = tabstrip_model()->GetIndexOfTabContents(contents); 2938 int index = tabstrip_model()->GetWrapperIndex(contents);
2914 if (index == TabStripModel::kNoTab) { 2939 if (index == TabStripModel::kNoTab) {
2915 NOTREACHED(); 2940 NOTREACHED();
2916 return; 2941 return;
2917 } 2942 }
2918 tabstrip_model()->SetTabBlocked(index, blocked); 2943 tabstrip_model()->SetTabBlocked(index, blocked);
2919 } 2944 }
2920 2945
2921 void Browser::TabContentsFocused(TabContents* tab_content) { 2946 void Browser::TabContentsFocused(TabContents* tab_content) {
2922 window_->TabContentsFocused(tab_content); 2947 window_->TabContentsFocused(tab_content);
2923 } 2948 }
(...skipping 10 matching lines...) Expand all
2934 return (type_ & TYPE_APP) != 0; 2959 return (type_ & TYPE_APP) != 0;
2935 } 2960 }
2936 2961
2937 void Browser::ConvertContentsToApplication(TabContents* contents) { 2962 void Browser::ConvertContentsToApplication(TabContents* contents) {
2938 const GURL& url = contents->controller().GetActiveEntry()->url(); 2963 const GURL& url = contents->controller().GetActiveEntry()->url();
2939 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 2964 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
2940 RegisterAppPrefs(app_name); 2965 RegisterAppPrefs(app_name);
2941 2966
2942 DetachContents(contents); 2967 DetachContents(contents);
2943 Browser* browser = Browser::CreateForApp(app_name, NULL, profile_, false); 2968 Browser* browser = Browser::CreateForApp(app_name, NULL, profile_, false);
2944 browser->tabstrip_model()->AppendTabContents(contents, true); 2969 TabContentsWrapper* wrapper = new TabContentsWrapper(contents);
2945 TabContents* tab_contents = browser->GetSelectedTabContents(); 2970 browser->tabstrip_model()->AppendTabContents(wrapper, true);
2971 TabContents* tab_contents = GetSelectedTabContents();
2946 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 2972 tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
2947 tab_contents->render_view_host()->SyncRendererPrefs(); 2973 tab_contents->render_view_host()->SyncRendererPrefs();
2948 browser->window()->Show(); 2974 browser->window()->Show();
2949 } 2975 }
2950 2976
2951 bool Browser::ShouldDisplayURLField() { 2977 bool Browser::ShouldDisplayURLField() {
2952 return !IsApplication(); 2978 return !IsApplication();
2953 } 2979 }
2954 2980
2955 void Browser::BeforeUnloadFired(TabContents* tab, 2981 void Browser::BeforeUnloadFired(TabContents* tab,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
3199 } 3225 }
3200 3226
3201 case NotificationType::EXTENSION_UNLOADED: 3227 case NotificationType::EXTENSION_UNLOADED:
3202 case NotificationType::EXTENSION_UNLOADED_DISABLED: { 3228 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
3203 window()->GetLocationBar()->UpdatePageActions(); 3229 window()->GetLocationBar()->UpdatePageActions();
3204 3230
3205 // Close any tabs from the unloaded extension. 3231 // Close any tabs from the unloaded extension.
3206 const Extension* extension = Details<const Extension>(details).ptr(); 3232 const Extension* extension = Details<const Extension>(details).ptr();
3207 TabStripModel* model = tab_handler_->GetTabStripModel(); 3233 TabStripModel* model = tab_handler_->GetTabStripModel();
3208 for (int i = model->count() - 1; i >= 0; --i) { 3234 for (int i = model->count() - 1; i >= 0; --i) {
3209 TabContents* tc = model->GetTabContentsAt(i); 3235 TabContents* tc = model->GetTabContentsAt(i)->tab_contents();
3210 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && 3236 if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) &&
3211 tc->GetURL().host() == extension->id()) { 3237 tc->GetURL().host() == extension->id()) {
3212 CloseTabContents(tc); 3238 CloseTabContents(tc);
3213 } 3239 }
3214 } 3240 }
3215 3241
3216 break; 3242 break;
3217 } 3243 }
3218 3244
3219 case NotificationType::EXTENSION_PROCESS_TERMINATED: { 3245 case NotificationType::EXTENSION_PROCESS_TERMINATED: {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3329 show_main_ui && profile_->IsSyncAccessible()); 3355 show_main_ui && profile_->IsSyncAccessible());
3330 } 3356 }
3331 3357
3332 /////////////////////////////////////////////////////////////////////////////// 3358 ///////////////////////////////////////////////////////////////////////////////
3333 // Browser, InstantDelegate implementation: 3359 // Browser, InstantDelegate implementation:
3334 3360
3335 void Browser::PrepareForInstant() { 3361 void Browser::PrepareForInstant() {
3336 window_->PrepareForInstant(); 3362 window_->PrepareForInstant();
3337 } 3363 }
3338 3364
3339 void Browser::ShowInstant(TabContents* preview_contents) { 3365 void Browser::ShowInstant(TabContentsWrapper* preview_contents) {
3340 DCHECK(instant_->tab_contents() == GetSelectedTabContents()); 3366 DCHECK(instant_->tab_contents() == GetSelectedTabContentsWrapper());
3341 window_->ShowInstant(preview_contents); 3367 window_->ShowInstant(preview_contents->tab_contents());
3342 } 3368 }
3343 3369
3344 void Browser::HideInstant() { 3370 void Browser::HideInstant() {
3345 window_->HideInstant(); 3371 window_->HideInstant();
3346 } 3372 }
3347 3373
3348 void Browser::CommitInstant(TabContents* preview_contents) { 3374 void Browser::CommitInstant(TabContentsWrapper* preview_contents) {
3349 TabContents* tab_contents = instant_->tab_contents(); 3375 TabContentsWrapper* tab_contents = instant_->tab_contents();
3350 int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents( 3376 int index =
3351 tab_contents); 3377 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents);
3352 DCHECK_NE(-1, index); 3378 DCHECK_NE(TabStripModel::kNoTab, index);
3353 preview_contents->controller().CopyStateFromAndPrune( 3379 preview_contents->controller().CopyStateFromAndPrune(
3354 &tab_contents->controller()); 3380 &tab_contents->controller());
3355 // TabStripModel takes ownership of preview_contents. 3381 // TabStripModel takes ownership of preview_contents.
3356 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( 3382 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(
3357 index, preview_contents); 3383 index, preview_contents);
3358 } 3384 }
3359 3385
3360 void Browser::SetSuggestedText(const string16& text) { 3386 void Browser::SetSuggestedText(const string16& text) {
3361 window()->GetLocationBar()->SetSuggestedText(text); 3387 window()->GetLocationBar()->SetSuggestedText(text);
3362 } 3388 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
3617 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, 3643 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
3618 dev_tools_enabled); 3644 dev_tools_enabled);
3619 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, 3645 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
3620 dev_tools_enabled); 3646 dev_tools_enabled);
3621 } 3647 }
3622 3648
3623 /////////////////////////////////////////////////////////////////////////////// 3649 ///////////////////////////////////////////////////////////////////////////////
3624 // Browser, UI update coalescing and handling (private): 3650 // Browser, UI update coalescing and handling (private):
3625 3651
3626 void Browser::UpdateToolbar(bool should_restore_state) { 3652 void Browser::UpdateToolbar(bool should_restore_state) {
3627 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state); 3653 window_->UpdateToolbar(GetSelectedTabContentsWrapper(), should_restore_state);
3628 } 3654 }
3629 3655
3630 void Browser::ScheduleUIUpdate(const TabContents* source, 3656 void Browser::ScheduleUIUpdate(const TabContents* source,
3631 unsigned changed_flags) { 3657 unsigned changed_flags) {
3632 if (!source) 3658 if (!source)
3633 return; 3659 return;
3634 3660
3635 // Do some synchronous updates. 3661 // Do some synchronous updates.
3636 if (changed_flags & TabContents::INVALIDATE_URL && 3662 if (changed_flags & TabContents::INVALIDATE_URL &&
3637 source == GetSelectedTabContents()) { 3663 source == GetSelectedTabContents()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, 3757 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
3732 web_app::IsValidUrl(contents->GetURL())); 3758 web_app::IsValidUrl(contents->GetURL()));
3733 #endif 3759 #endif
3734 window_->UpdateTitleBar(); 3760 window_->UpdateTitleBar();
3735 } 3761 }
3736 } 3762 }
3737 3763
3738 // Updates that don't depend upon the selected state go here. 3764 // Updates that don't depend upon the selected state go here.
3739 if (flags & (TabContents::INVALIDATE_TAB | TabContents::INVALIDATE_TITLE)) { 3765 if (flags & (TabContents::INVALIDATE_TAB | TabContents::INVALIDATE_TITLE)) {
3740 tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( 3766 tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt(
3741 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents), 3767 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents),
3742 TabStripModelObserver::ALL); 3768 TabStripModelObserver::ALL);
3743 } 3769 }
3744 3770
3745 // We don't need to process INVALIDATE_STATE, since that's not visible. 3771 // We don't need to process INVALIDATE_STATE, since that's not visible.
3746 } 3772 }
3747 3773
3748 scheduled_updates_.clear(); 3774 scheduled_updates_.clear();
3749 } 3775 }
3750 3776
3751 void Browser::RemoveScheduledUpdatesFor(TabContents* contents) { 3777 void Browser::RemoveScheduledUpdatesFor(TabContents* contents) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3999 GetSelectedTabContents()->StartFinding(find_text, 4025 GetSelectedTabContents()->StartFinding(find_text,
4000 forward_direction, 4026 forward_direction,
4001 false); // Not case sensitive. 4027 false); // Not case sensitive.
4002 } 4028 }
4003 } 4029 }
4004 4030
4005 void Browser::CloseFrame() { 4031 void Browser::CloseFrame() {
4006 window_->Close(); 4032 window_->Close();
4007 } 4033 }
4008 4034
4009 void Browser::TabDetachedAtImpl(TabContents* contents, int index, 4035 void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index,
4010 DetachType type) { 4036 DetachType type) {
4011 if (type == DETACH_TYPE_DETACH) { 4037 if (type == DETACH_TYPE_DETACH) {
4012 // Save the current location bar state, but only if the tab being detached 4038 // Save the current location bar state, but only if the tab being detached
4013 // is the selected tab. Because saving state can conditionally revert the 4039 // is the selected tab. Because saving state can conditionally revert the
4014 // location bar, saving the current tab's location bar state to a 4040 // location bar, saving the current tab's location bar state to a
4015 // non-selected tab can corrupt both tabs. 4041 // non-selected tab can corrupt both tabs.
4016 if (contents == GetSelectedTabContents()) 4042 if (contents == GetSelectedTabContents())
4017 window_->GetLocationBar()->SaveStateToContents(contents); 4043 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents());
4018 4044
4019 if (!tab_handler_->GetTabStripModel()->closing_all()) 4045 if (!tab_handler_->GetTabStripModel()->closing_all())
4020 SyncHistoryWithTabs(0); 4046 SyncHistoryWithTabs(0);
4021 } 4047 }
4022 4048
4023 contents->set_delegate(NULL); 4049 contents->tab_contents()->set_delegate(NULL);
4024 RemoveScheduledUpdatesFor(contents); 4050 RemoveScheduledUpdatesFor(contents->tab_contents());
4025 4051
4026 if (find_bar_controller_.get() && 4052 if (find_bar_controller_.get() &&
4027 index == tab_handler_->GetTabStripModel()->selected_index()) { 4053 index == tab_handler_->GetTabStripModel()->selected_index()) {
4028 find_bar_controller_->ChangeTabContents(NULL); 4054 find_bar_controller_->ChangeTabContents(NULL);
4029 } 4055 }
4030 4056
4031 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, 4057 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
4032 Source<TabContents>(contents)); 4058 Source<TabContentsWrapper>(contents));
4033 } 4059 }
4034 4060
4035 // static 4061 // static
4036 void Browser::RegisterAppPrefs(const std::string& app_name) { 4062 void Browser::RegisterAppPrefs(const std::string& app_name) {
4037 // A set of apps that we've already started. 4063 // A set of apps that we've already started.
4038 static std::set<std::string>* g_app_names = NULL; 4064 static std::set<std::string>* g_app_names = NULL;
4039 4065
4040 if (!g_app_names) 4066 if (!g_app_names)
4041 g_app_names = new std::set<std::string>; 4067 g_app_names = new std::set<std::string>;
4042 4068
(...skipping 19 matching lines...) Expand all
4062 4088
4063 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { 4089 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) {
4064 if (!tab_restore_service_) 4090 if (!tab_restore_service_)
4065 return; 4091 return;
4066 4092
4067 DCHECK_EQ(tab_restore_service_, service); 4093 DCHECK_EQ(tab_restore_service_, service);
4068 tab_restore_service_->RemoveObserver(this); 4094 tab_restore_service_->RemoveObserver(this);
4069 tab_restore_service_ = NULL; 4095 tab_restore_service_ = NULL;
4070 } 4096 }
4071 4097
4098 // Centralized method for creating a TabContents, configuring and installing
4099 // all its supporting objects and observers.
4100 TabContentsWrapper* Browser::TabContentsFactory(
4101 Profile* profile,
4102 SiteInstance* site_instance,
4103 int routing_id,
4104 const TabContents* base_tab_contents,
4105 SessionStorageNamespace* session_storage_namespace) {
4106 TabContents* new_contents = new TabContents(profile, site_instance,
4107 routing_id, base_tab_contents,
4108 session_storage_namespace);
4109 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents);
4110 return wrapper;
4111 }
4112
4072 bool Browser::OpenInstant(WindowOpenDisposition disposition) { 4113 bool Browser::OpenInstant(WindowOpenDisposition disposition) {
4073 if (!instant() || !instant()->is_active() || !instant()->IsCurrent()) 4114 if (!instant() || !instant()->is_active() || !instant()->IsCurrent())
4074 return false; 4115 return false;
4075 4116
4076 if (disposition == CURRENT_TAB) { 4117 if (disposition == CURRENT_TAB) {
4077 instant()->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); 4118 instant()->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
4078 return true; 4119 return true;
4079 } 4120 }
4080 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { 4121 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) {
4081 HideInstant(); 4122 HideInstant();
4082 TabContents* preview_contents = instant()->ReleasePreviewContents( 4123 TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents(
4083 INSTANT_COMMIT_PRESSED_ENTER); 4124 INSTANT_COMMIT_PRESSED_ENTER);
4084 preview_contents->controller().PruneAllButActive(); 4125 preview_contents->controller().PruneAllButActive();
4085 tab_handler_->GetTabStripModel()->AddTabContents( 4126 tab_handler_->GetTabStripModel()->AddTabContents(
4086 preview_contents, 4127 preview_contents,
4087 -1, 4128 -1,
4088 instant()->last_transition_type(), 4129 instant()->last_transition_type(),
4089 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : 4130 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED :
4090 TabStripModel::ADD_NONE); 4131 TabStripModel::ADD_NONE);
4091 instant()->CompleteRelease(preview_contents); 4132 instant()->CompleteRelease(preview_contents->tab_contents());
4092 return true; 4133 return true;
4093 } 4134 }
4094 // The omnibox currently doesn't use other dispositions, so we don't attempt 4135 // The omnibox currently doesn't use other dispositions, so we don't attempt
4095 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 4136 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
4096 // support for the new disposition. 4137 // support for the new disposition.
4097 NOTREACHED(); 4138 NOTREACHED();
4098 return false; 4139 return false;
4099 } 4140 }
4100 4141
4101 void Browser::CreateInstantIfNecessary() { 4142 void Browser::CreateInstantIfNecessary() {
4102 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && 4143 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) &&
4103 !profile()->IsOffTheRecord()) { 4144 !profile()->IsOffTheRecord()) {
4104 instant_.reset(new InstantController(profile_, this)); 4145 instant_.reset(new InstantController(profile_, this));
4105 } 4146 }
4106 } 4147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698