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

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

Issue 305243002: Replace usage of GetActiveEntry with GetLastCommittedEntry in chrome/browser/ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
« no previous file with comments | « chrome/browser/ui/browser_command_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_commands.h" 5 #include "chrome/browser/ui/browser_commands.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 command, observer); 306 command, observer);
307 } 307 }
308 308
309 int GetContentRestrictions(const Browser* browser) { 309 int GetContentRestrictions(const Browser* browser) {
310 int content_restrictions = 0; 310 int content_restrictions = 0;
311 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 311 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
312 if (current_tab) { 312 if (current_tab) {
313 CoreTabHelper* core_tab_helper = 313 CoreTabHelper* core_tab_helper =
314 CoreTabHelper::FromWebContents(current_tab); 314 CoreTabHelper::FromWebContents(current_tab);
315 content_restrictions = core_tab_helper->content_restrictions(); 315 content_restrictions = core_tab_helper->content_restrictions();
316 NavigationEntry* active_entry = 316 NavigationEntry* active_entry =
Peter Kasting 2014/06/02 18:38:58 Nit: Update this variable name
nasko 2014/06/02 20:44:23 Done.
317 current_tab->GetController().GetActiveEntry(); 317 current_tab->GetController().GetLastCommittedEntry();
318 // See comment in UpdateCommandsForTabState about why we call url(). 318 // See comment in UpdateCommandsForTabState about why we call url().
Peter Kasting 2014/06/02 18:38:58 Nit: While here: "url()" no longer seems to exist,
nasko 2014/06/02 20:44:23 There is no such comment that I can see, so it see
319 if (!content::IsSavableURL( 319 if (!content::IsSavableURL(
320 active_entry ? active_entry->GetURL() : GURL()) || 320 active_entry ? active_entry->GetURL() : GURL()) ||
321 current_tab->ShowingInterstitialPage()) 321 current_tab->ShowingInterstitialPage())
322 content_restrictions |= CONTENT_RESTRICTION_SAVE; 322 content_restrictions |= CONTENT_RESTRICTION_SAVE;
323 if (current_tab->ShowingInterstitialPage()) 323 if (current_tab->ShowingInterstitialPage())
324 content_restrictions |= CONTENT_RESTRICTION_PRINT; 324 content_restrictions |= CONTENT_RESTRICTION_PRINT;
325 } 325 }
326 return content_restrictions; 326 return content_restrictions;
327 } 327 }
328 328
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 search_tab_helper->ToggleVoiceSearch(); 1073 search_tab_helper->ToggleVoiceSearch();
1074 } 1074 }
1075 1075
1076 void DistillCurrentPage(Browser* browser) { 1076 void DistillCurrentPage(Browser* browser) {
1077 DistillCurrentPageAndView(browser->tab_strip_model()->GetActiveWebContents()); 1077 DistillCurrentPageAndView(browser->tab_strip_model()->GetActiveWebContents());
1078 } 1078 }
1079 1079
1080 bool CanRequestTabletSite(WebContents* current_tab) { 1080 bool CanRequestTabletSite(WebContents* current_tab) {
1081 if (!current_tab) 1081 if (!current_tab)
1082 return false; 1082 return false;
1083 return current_tab->GetController().GetActiveEntry() != NULL; 1083 return current_tab->GetController().GetLastCommittedEntry() != NULL;
Peter Kasting 2014/06/02 18:38:58 Nit: Simpler: return current_tab && current_tab
nasko 2014/06/02 20:44:23 Done.
1084 } 1084 }
1085 1085
1086 bool IsRequestingTabletSite(Browser* browser) { 1086 bool IsRequestingTabletSite(Browser* browser) {
1087 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 1087 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
1088 if (!current_tab) 1088 if (!current_tab)
1089 return false; 1089 return false;
1090 content::NavigationEntry* entry = 1090 content::NavigationEntry* entry =
1091 current_tab->GetController().GetActiveEntry(); 1091 current_tab->GetController().GetLastCommittedEntry();
1092 if (!entry) 1092 if (!entry)
1093 return false; 1093 return false;
1094 return entry->GetIsOverridingUserAgent(); 1094 return entry->GetIsOverridingUserAgent();
1095 } 1095 }
1096 1096
1097 void ToggleRequestTabletSite(Browser* browser) { 1097 void ToggleRequestTabletSite(Browser* browser) {
1098 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 1098 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
1099 if (!current_tab) 1099 if (!current_tab)
1100 return; 1100 return;
1101 NavigationController& controller = current_tab->GetController(); 1101 NavigationController& controller = current_tab->GetController();
1102 NavigationEntry* entry = controller.GetActiveEntry(); 1102 NavigationEntry* entry = controller.GetLastCommittedEntry();
1103 if (!entry) 1103 if (!entry)
1104 return; 1104 return;
1105 if (entry->GetIsOverridingUserAgent()) { 1105 if (entry->GetIsOverridingUserAgent()) {
1106 entry->SetIsOverridingUserAgent(false); 1106 entry->SetIsOverridingUserAgent(false);
1107 } else { 1107 } else {
1108 entry->SetIsOverridingUserAgent(true); 1108 entry->SetIsOverridingUserAgent(true);
1109 chrome::VersionInfo version_info; 1109 chrome::VersionInfo version_info;
1110 std::string product; 1110 std::string product;
1111 if (version_info.is_valid()) 1111 if (version_info.is_valid())
1112 product = version_info.ProductNameAndVersionForUserAgent(); 1112 product = version_info.ProductNameAndVersionForUserAgent();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 } 1148 }
1149 1149
1150 void ViewSource(Browser* browser, 1150 void ViewSource(Browser* browser,
1151 WebContents* contents, 1151 WebContents* contents,
1152 const GURL& url, 1152 const GURL& url,
1153 const content::PageState& page_state) { 1153 const content::PageState& page_state) {
1154 content::RecordAction(UserMetricsAction("ViewSource")); 1154 content::RecordAction(UserMetricsAction("ViewSource"));
1155 DCHECK(contents); 1155 DCHECK(contents);
1156 1156
1157 // Note that Clone does not copy the pending or transient entries, so the 1157 // Note that Clone does not copy the pending or transient entries, so the
1158 // active entry in view_source_contents will be the last committed entry. 1158 // active entry in view_source_contents will be the last committed entry.
Peter Kasting 2014/06/02 18:38:58 This comment seems like it can be removed.
nasko 2014/06/02 20:44:23 Done.
1159 WebContents* view_source_contents = contents->Clone(); 1159 WebContents* view_source_contents = contents->Clone();
1160 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted()); 1160 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted());
1161 view_source_contents->GetController().PruneAllButLastCommitted(); 1161 view_source_contents->GetController().PruneAllButLastCommitted();
1162 NavigationEntry* active_entry = 1162 NavigationEntry* active_entry =
Peter Kasting 2014/06/02 18:38:58 Nit: Update this variable name.
nasko 2014/06/02 20:44:23 Done.
1163 view_source_contents->GetController().GetActiveEntry(); 1163 view_source_contents->GetController().GetLastCommittedEntry();
1164 if (!active_entry) 1164 if (!active_entry)
1165 return; 1165 return;
1166 1166
1167 GURL view_source_url = 1167 GURL view_source_url =
1168 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); 1168 GURL(content::kViewSourceScheme + std::string(":") + url.spec());
1169 active_entry->SetVirtualURL(view_source_url); 1169 active_entry->SetVirtualURL(view_source_url);
1170 1170
1171 // Do not restore scroller position. 1171 // Do not restore scroller position.
1172 active_entry->SetPageState(page_state.RemoveScrollOffset()); 1172 active_entry->SetPageState(page_state.RemoveScrollOffset());
1173 1173
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 } 1243 }
1244 1244
1245 bool CanCreateBookmarkApp(const Browser* browser) { 1245 bool CanCreateBookmarkApp(const Browser* browser) {
1246 return extensions::TabHelper::FromWebContents( 1246 return extensions::TabHelper::FromWebContents(
1247 browser->tab_strip_model()->GetActiveWebContents()) 1247 browser->tab_strip_model()->GetActiveWebContents())
1248 ->CanCreateBookmarkApp(); 1248 ->CanCreateBookmarkApp();
1249 } 1249 }
1250 1250
1251 void ConvertTabToAppWindow(Browser* browser, 1251 void ConvertTabToAppWindow(Browser* browser,
1252 content::WebContents* contents) { 1252 content::WebContents* contents) {
1253 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); 1253 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL();
1254 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 1254 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
1255 1255
1256 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1256 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1257 if (index >= 0) 1257 if (index >= 0)
1258 browser->tab_strip_model()->DetachWebContentsAt(index); 1258 browser->tab_strip_model()->DetachWebContentsAt(index);
1259 1259
1260 Browser* app_browser = new Browser( 1260 Browser* app_browser = new Browser(
1261 Browser::CreateParams::CreateForApp(app_name, 1261 Browser::CreateParams::CreateForApp(app_name,
1262 true /* trusted_source */, 1262 true /* trusted_source */,
1263 gfx::Rect(), 1263 gfx::Rect(),
1264 browser->profile(), 1264 browser->profile(),
1265 browser->host_desktop_type())); 1265 browser->host_desktop_type()));
1266 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1266 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1267 1267
1268 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1268 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1269 contents->GetRenderViewHost()->SyncRendererPrefs(); 1269 contents->GetRenderViewHost()->SyncRendererPrefs();
1270 app_browser->window()->Show(); 1270 app_browser->window()->Show();
1271 } 1271 }
1272 1272
1273 } // namespace chrome 1273 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698