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

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

Issue 23536075: Fix multiple problems with omnibox text handling across focus changes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 search_delegate_->OnTabDeactivated(contents); 1040 search_delegate_->OnTabDeactivated(contents);
1041 1041
1042 // Save what the user's currently typing, so it can be restored when we 1042 // Save what the user's currently typing, so it can be restored when we
1043 // switch back to this tab. 1043 // switch back to this tab.
1044 window_->GetLocationBar()->SaveStateToContents(contents); 1044 window_->GetLocationBar()->SaveStateToContents(contents);
1045 1045
1046 if (instant_controller_) 1046 if (instant_controller_)
1047 instant_controller_->TabDeactivated(contents); 1047 instant_controller_->TabDeactivated(contents);
1048 } 1048 }
1049 1049
1050 void Browser::ActiveTabChanged(WebContents* old_contents,
1051 WebContents* new_contents,
1052 int index,
1053 int reason) {
1054 content::RecordAction(UserMetricsAction("ActiveTabChanged"));
1055
1056 // Discarded tabs always get reloaded.
1057 if (tab_strip_model_->IsTabDiscarded(index)) {
1058 LOG(WARNING) << "Reloading discarded tab at " << index;
1059 static int reload_count = 0;
1060 UMA_HISTOGRAM_CUSTOM_COUNTS(
1061 "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50);
1062 chrome::Reload(this, CURRENT_TAB);
1063 }
1064
1065 // If we have any update pending, do it now.
1066 if (chrome_updater_factory_.HasWeakPtrs() && old_contents)
1067 ProcessPendingUIUpdates();
1068
1069 // Propagate the profile to the location bar.
1070 UpdateToolbar((reason & CHANGE_REASON_REPLACED) == 0);
1071
1072 // Propagate tab state to toolbar, tab-strip, etc.
1073 UpdateSearchState(new_contents);
1074
1075 // Update reload/stop state.
1076 command_controller_->LoadingStateChanged(new_contents->IsLoading(), true);
1077
1078 // Update commands to reflect current state.
1079 command_controller_->TabStateChanged();
1080
1081 // Reset the status bubble.
1082 StatusBubble* status_bubble = GetStatusBubble();
1083 if (status_bubble) {
1084 status_bubble->Hide();
1085
1086 // Show the loading state (if any).
1087 status_bubble->SetStatus(CoreTabHelper::FromWebContents(
1088 tab_strip_model_->GetActiveWebContents())->GetStatusText());
1089 }
1090
1091 if (HasFindBarController()) {
1092 find_bar_controller_->ChangeWebContents(new_contents);
1093 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
1094 }
1095
1096 // Update sessions. Don't force creation of sessions. If sessions doesn't
1097 // exist, the change will be picked up by sessions when created.
1098 SessionService* session_service =
1099 SessionServiceFactory::GetForProfileIfExisting(profile_);
1100 if (session_service && !tab_strip_model_->closing_all()) {
1101 session_service->SetSelectedTabInWindow(session_id(),
1102 tab_strip_model_->active_index());
1103 }
1104
1105 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
1106
1107 // This needs to be called after UpdateSearchState().
1108 if (instant_controller_)
1109 instant_controller_->ActiveTabChanged();
1110
1111 autofill::TabAutofillManagerDelegate::FromWebContents(new_contents)->
1112 TabActivated(reason);
1113 }
1114
1115 void Browser::TabMoved(WebContents* contents, 1050 void Browser::TabMoved(WebContents* contents,
1116 int from_index, 1051 int from_index,
1117 int to_index) { 1052 int to_index) {
1118 DCHECK(from_index >= 0 && to_index >= 0); 1053 DCHECK(from_index >= 0 && to_index >= 0);
1119 // Notify the history service. 1054 // Notify the history service.
1120 SyncHistoryWithTabs(std::min(from_index, to_index)); 1055 SyncHistoryWithTabs(std::min(from_index, to_index));
1121 } 1056 }
1122 1057
1123 void Browser::TabReplacedAt(TabStripModel* tab_strip_model, 1058 void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
1124 WebContents* old_contents, 1059 WebContents* old_contents,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 // times. This is because it does not close the window if tabs are 1105 // times. This is because it does not close the window if tabs are
1171 // still present. 1106 // still present.
1172 base::MessageLoop::current()->PostTask( 1107 base::MessageLoop::current()->PostTask(
1173 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); 1108 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
1174 1109
1175 // Instant may have visible WebContents that need to be detached before the 1110 // Instant may have visible WebContents that need to be detached before the
1176 // window system closes. 1111 // window system closes.
1177 instant_controller_.reset(); 1112 instant_controller_.reset();
1178 } 1113 }
1179 1114
1115 void Browser::OnActiveTabChanged(WebContents* old_contents,
1116 WebContents* new_contents,
1117 int index,
1118 int reason) {
1119 content::RecordAction(UserMetricsAction("ActiveTabChanged"));
1120
1121 // Discarded tabs always get reloaded.
1122 if (tab_strip_model_->IsTabDiscarded(index)) {
1123 LOG(WARNING) << "Reloading discarded tab at " << index;
1124 static int reload_count = 0;
1125 UMA_HISTOGRAM_CUSTOM_COUNTS(
1126 "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50);
1127 chrome::Reload(this, CURRENT_TAB);
1128 }
1129
1130 // If we have any update pending, do it now.
1131 if (chrome_updater_factory_.HasWeakPtrs() && old_contents)
1132 ProcessPendingUIUpdates();
1133
1134 // Propagate the profile to the location bar.
1135 UpdateToolbar((reason & CHANGE_REASON_REPLACED) == 0);
1136
1137 // Propagate tab state to toolbar, tab-strip, etc.
1138 UpdateSearchState(new_contents);
1139
1140 // Update reload/stop state.
1141 command_controller_->LoadingStateChanged(new_contents->IsLoading(), true);
1142
1143 // Update commands to reflect current state.
1144 command_controller_->TabStateChanged();
1145
1146 // Reset the status bubble.
1147 StatusBubble* status_bubble = GetStatusBubble();
1148 if (status_bubble) {
1149 status_bubble->Hide();
1150
1151 // Show the loading state (if any).
1152 status_bubble->SetStatus(CoreTabHelper::FromWebContents(
1153 tab_strip_model_->GetActiveWebContents())->GetStatusText());
1154 }
1155
1156 if (HasFindBarController()) {
1157 find_bar_controller_->ChangeWebContents(new_contents);
1158 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
1159 }
1160
1161 // Update sessions. Don't force creation of sessions. If sessions doesn't
1162 // exist, the change will be picked up by sessions when created.
1163 SessionService* session_service =
1164 SessionServiceFactory::GetForProfileIfExisting(profile_);
1165 if (session_service && !tab_strip_model_->closing_all()) {
1166 session_service->SetSelectedTabInWindow(session_id(),
1167 tab_strip_model_->active_index());
1168 }
1169
1170 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
1171
1172 // This needs to be called after UpdateSearchState().
1173 if (instant_controller_)
1174 instant_controller_->ActiveTabChanged();
1175
1176 autofill::TabAutofillManagerDelegate::FromWebContents(new_contents)->
1177 TabActivated(reason);
1178 }
1179
1180 bool Browser::CanOverscrollContent() const { 1180 bool Browser::CanOverscrollContent() const {
1181 #if defined(USE_AURA) 1181 #if defined(USE_AURA)
1182 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> 1182 bool overscroll_enabled = CommandLine::ForCurrentProcess()->
1183 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 1183 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
1184 if (!overscroll_enabled) 1184 if (!overscroll_enabled)
1185 return false; 1185 return false;
1186 if (is_app() || is_devtools() || !is_type_tabbed()) 1186 if (is_app() || is_devtools() || !is_type_tabbed())
1187 return false; 1187 return false;
1188 1188
1189 // The detached bookmark bar has appearance of floating above the 1189 // The detached bookmark bar has appearance of floating above the
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 if (contents && !allow_js_access) { 2292 if (contents && !allow_js_access) {
2293 contents->web_contents()->GetController().LoadURL( 2293 contents->web_contents()->GetController().LoadURL(
2294 target_url, 2294 target_url,
2295 content::Referrer(), 2295 content::Referrer(),
2296 content::PAGE_TRANSITION_LINK, 2296 content::PAGE_TRANSITION_LINK,
2297 std::string()); // No extra headers. 2297 std::string()); // No extra headers.
2298 } 2298 }
2299 2299
2300 return contents != NULL; 2300 return contents != NULL;
2301 } 2301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698