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

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

Issue 66993003: Most references to GetActiveEntry removed from chrome/browser/ui. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 command, observer); 247 command, observer);
248 } 248 }
249 249
250 int GetContentRestrictions(const Browser* browser) { 250 int GetContentRestrictions(const Browser* browser) {
251 int content_restrictions = 0; 251 int content_restrictions = 0;
252 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 252 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
253 if (current_tab) { 253 if (current_tab) {
254 CoreTabHelper* core_tab_helper = 254 CoreTabHelper* core_tab_helper =
255 CoreTabHelper::FromWebContents(current_tab); 255 CoreTabHelper::FromWebContents(current_tab);
256 content_restrictions = core_tab_helper->content_restrictions(); 256 content_restrictions = core_tab_helper->content_restrictions();
257 NavigationEntry* active_entry = 257 NavigationEntry* entry =
258 current_tab->GetController().GetActiveEntry(); 258 current_tab->GetController().GetLastCommittedEntry();
259 // See comment in UpdateCommandsForTabState about why we call url(). 259 // See comment in UpdateCommandsForTabState about why we call url().
260 if (!content::IsSavableURL( 260 if (!content::IsSavableURL(
261 active_entry ? active_entry->GetURL() : GURL()) || 261 entry ? entry->GetURL() : GURL()) ||
262 current_tab->ShowingInterstitialPage()) 262 current_tab->ShowingInterstitialPage())
263 content_restrictions |= CONTENT_RESTRICTION_SAVE; 263 content_restrictions |= CONTENT_RESTRICTION_SAVE;
264 if (current_tab->ShowingInterstitialPage()) 264 if (current_tab->ShowingInterstitialPage())
265 content_restrictions |= CONTENT_RESTRICTION_PRINT; 265 content_restrictions |= CONTENT_RESTRICTION_PRINT;
266 } 266 }
267 return content_restrictions; 267 return content_restrictions;
268 } 268 }
269 269
270 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { 270 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) {
271 bool incognito = profile->IsOffTheRecord(); 271 bool incognito = profile->IsOffTheRecord();
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 void ToggleSpeechInput(Browser* browser) { 973 void ToggleSpeechInput(Browser* browser) {
974 browser->tab_strip_model()->GetActiveWebContents()-> 974 browser->tab_strip_model()->GetActiveWebContents()->
975 GetRenderViewHost()->ToggleSpeechInput(); 975 GetRenderViewHost()->ToggleSpeechInput();
976 if (browser->instant_controller()) 976 if (browser->instant_controller())
977 browser->instant_controller()->ToggleVoiceSearch(); 977 browser->instant_controller()->ToggleVoiceSearch();
978 } 978 }
979 979
980 bool CanRequestTabletSite(WebContents* current_tab) { 980 bool CanRequestTabletSite(WebContents* current_tab) {
981 if (!current_tab) 981 if (!current_tab)
982 return false; 982 return false;
983 return current_tab->GetController().GetActiveEntry() != NULL; 983 return current_tab->GetController().GetVisibleEntry() != NULL;
nasko 2013/11/08 23:52:03 For this and the next two instances, have you trie
jww 2013/11/11 19:18:51 Done.
984 } 984 }
985 985
986 bool IsRequestingTabletSite(Browser* browser) { 986 bool IsRequestingTabletSite(Browser* browser) {
987 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 987 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
988 if (!current_tab) 988 if (!current_tab)
989 return false; 989 return false;
990 content::NavigationEntry* entry = 990 content::NavigationEntry* entry =
991 current_tab->GetController().GetActiveEntry(); 991 current_tab->GetController().GetVisibleEntry();
992 if (!entry) 992 if (!entry)
993 return false; 993 return false;
994 return entry->GetIsOverridingUserAgent(); 994 return entry->GetIsOverridingUserAgent();
995 } 995 }
996 996
997 void ToggleRequestTabletSite(Browser* browser) { 997 void ToggleRequestTabletSite(Browser* browser) {
998 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 998 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
999 if (!current_tab) 999 if (!current_tab)
1000 return; 1000 return;
1001 NavigationController& controller = current_tab->GetController(); 1001 NavigationController& controller = current_tab->GetController();
1002 NavigationEntry* entry = controller.GetActiveEntry(); 1002 NavigationEntry* entry = controller.GetVisibleEntry();
1003 if (!entry) 1003 if (!entry)
1004 return; 1004 return;
1005 if (entry->GetIsOverridingUserAgent()) { 1005 if (entry->GetIsOverridingUserAgent()) {
1006 entry->SetIsOverridingUserAgent(false); 1006 entry->SetIsOverridingUserAgent(false);
1007 } else { 1007 } else {
1008 entry->SetIsOverridingUserAgent(true); 1008 entry->SetIsOverridingUserAgent(true);
1009 chrome::VersionInfo version_info; 1009 chrome::VersionInfo version_info;
1010 std::string product; 1010 std::string product;
1011 if (version_info.is_valid()) 1011 if (version_info.is_valid())
1012 product = version_info.ProductNameAndVersionForUserAgent(); 1012 product = version_info.ProductNameAndVersionForUserAgent();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1048 }
1049 1049
1050 void ViewSource(Browser* browser, 1050 void ViewSource(Browser* browser,
1051 WebContents* contents, 1051 WebContents* contents,
1052 const GURL& url, 1052 const GURL& url,
1053 const content::PageState& page_state) { 1053 const content::PageState& page_state) {
1054 content::RecordAction(UserMetricsAction("ViewSource")); 1054 content::RecordAction(UserMetricsAction("ViewSource"));
1055 DCHECK(contents); 1055 DCHECK(contents);
1056 1056
1057 // Note that Clone does not copy the pending or transient entries, so the 1057 // Note that Clone does not copy the pending or transient entries, so the
1058 // active entry in view_source_contents will be the last committed entry. 1058 // active entry in view_source_contents will be the last committed entry.
nasko 2013/11/08 23:52:03 nit: "active entry" -> "visible entry"
jww 2013/11/11 19:18:51 Refactored the comment a bit more to align with th
1059 WebContents* view_source_contents = contents->Clone(); 1059 WebContents* view_source_contents = contents->Clone();
1060 DCHECK(view_source_contents->GetController().CanPruneAllButVisible()); 1060 DCHECK(view_source_contents->GetController().CanPruneAllButVisible());
jww 2013/11/11 19:18:51 On a side note, this function seems woefully misna
Charlie Reis 2013/11/11 22:58:23 Wow, that is poorly named. I'll take the blame fo
1061 view_source_contents->GetController().PruneAllButVisible(); 1061 view_source_contents->GetController().PruneAllButVisible();
1062 NavigationEntry* active_entry = 1062 NavigationEntry* entry =
1063 view_source_contents->GetController().GetActiveEntry(); 1063 view_source_contents->GetController().GetVisibleEntry();
nasko 2013/11/08 23:52:03 If the comment above is correct, why not use LastC
jww 2013/11/11 19:18:51 Done.
1064 if (!active_entry) 1064 if (!entry)
1065 return; 1065 return;
1066 1066
1067 GURL view_source_url = 1067 GURL view_source_url =
1068 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); 1068 GURL(content::kViewSourceScheme + std::string(":") + url.spec());
1069 active_entry->SetVirtualURL(view_source_url); 1069 entry->SetVirtualURL(view_source_url);
1070 1070
1071 // Do not restore scroller position. 1071 // Do not restore scroller position.
1072 active_entry->SetPageState(page_state.RemoveScrollOffset()); 1072 entry->SetPageState(page_state.RemoveScrollOffset());
1073 1073
1074 // Do not restore title, derive it from the url. 1074 // Do not restore title, derive it from the url.
1075 active_entry->SetTitle(string16()); 1075 entry->SetTitle(string16());
1076 1076
1077 // Now show view-source entry. 1077 // Now show view-source entry.
1078 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { 1078 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) {
1079 // If this is a tabbed browser, just create a duplicate tab inside the same 1079 // If this is a tabbed browser, just create a duplicate tab inside the same
1080 // window next to the tab being duplicated. 1080 // window next to the tab being duplicated.
1081 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1081 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1082 int add_types = TabStripModel::ADD_ACTIVE | 1082 int add_types = TabStripModel::ADD_ACTIVE |
1083 TabStripModel::ADD_INHERIT_GROUP; 1083 TabStripModel::ADD_INHERIT_GROUP;
1084 browser->tab_strip_model()->InsertWebContentsAt( 1084 browser->tab_strip_model()->InsertWebContentsAt(
1085 index + 1, 1085 index + 1,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 } 1129 }
1130 1130
1131 bool CanCreateApplicationShortcuts(const Browser* browser) { 1131 bool CanCreateApplicationShortcuts(const Browser* browser) {
1132 return extensions::TabHelper::FromWebContents( 1132 return extensions::TabHelper::FromWebContents(
1133 browser->tab_strip_model()->GetActiveWebContents())-> 1133 browser->tab_strip_model()->GetActiveWebContents())->
1134 CanCreateApplicationShortcuts(); 1134 CanCreateApplicationShortcuts();
1135 } 1135 }
1136 1136
1137 void ConvertTabToAppWindow(Browser* browser, 1137 void ConvertTabToAppWindow(Browser* browser,
1138 content::WebContents* contents) { 1138 content::WebContents* contents) {
1139 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); 1139 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL();
1140 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 1140 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
1141 1141
1142 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1142 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1143 if (index >= 0) 1143 if (index >= 0)
1144 browser->tab_strip_model()->DetachWebContentsAt(index); 1144 browser->tab_strip_model()->DetachWebContentsAt(index);
1145 1145
1146 Browser* app_browser = new Browser( 1146 Browser* app_browser = new Browser(
1147 Browser::CreateParams::CreateForApp( 1147 Browser::CreateParams::CreateForApp(
1148 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), 1148 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(),
1149 browser->host_desktop_type())); 1149 browser->host_desktop_type()));
1150 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1150 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1151 1151
1152 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1152 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1153 contents->GetRenderViewHost()->SyncRendererPrefs(); 1153 contents->GetRenderViewHost()->SyncRendererPrefs();
1154 app_browser->window()->Show(); 1154 app_browser->window()->Show();
1155 } 1155 }
1156 1156
1157 } // namespace chrome 1157 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698