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

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: Rebase on ToT 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(entry ? entry->GetURL() : GURL()) ||
261 active_entry ? active_entry->GetURL() : GURL()) ||
262 current_tab->ShowingInterstitialPage()) 261 current_tab->ShowingInterstitialPage())
263 content_restrictions |= CONTENT_RESTRICTION_SAVE; 262 content_restrictions |= CONTENT_RESTRICTION_SAVE;
264 if (current_tab->ShowingInterstitialPage()) 263 if (current_tab->ShowingInterstitialPage())
265 content_restrictions |= CONTENT_RESTRICTION_PRINT; 264 content_restrictions |= CONTENT_RESTRICTION_PRINT;
266 } 265 }
267 return content_restrictions; 266 return content_restrictions;
268 } 267 }
269 268
270 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { 269 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) {
271 bool incognito = profile->IsOffTheRecord(); 270 bool incognito = profile->IsOffTheRecord();
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 void ToggleSpeechInput(Browser* browser) { 972 void ToggleSpeechInput(Browser* browser) {
974 browser->tab_strip_model()->GetActiveWebContents()-> 973 browser->tab_strip_model()->GetActiveWebContents()->
975 GetRenderViewHost()->ToggleSpeechInput(); 974 GetRenderViewHost()->ToggleSpeechInput();
976 if (browser->instant_controller()) 975 if (browser->instant_controller())
977 browser->instant_controller()->ToggleVoiceSearch(); 976 browser->instant_controller()->ToggleVoiceSearch();
978 } 977 }
979 978
980 bool CanRequestTabletSite(WebContents* current_tab) { 979 bool CanRequestTabletSite(WebContents* current_tab) {
981 if (!current_tab) 980 if (!current_tab)
982 return false; 981 return false;
983 return current_tab->GetController().GetActiveEntry() != NULL; 982 return current_tab->GetController().GetLastCommittedEntry() != NULL;
jww 2013/11/15 23:10:50 @sky: I know you gave the LGTM already, but can yo
984 } 983 }
985 984
986 bool IsRequestingTabletSite(Browser* browser) { 985 bool IsRequestingTabletSite(Browser* browser) {
987 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 986 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
988 if (!current_tab) 987 if (!current_tab)
989 return false; 988 return false;
990 content::NavigationEntry* entry = 989 content::NavigationEntry* entry =
991 current_tab->GetController().GetActiveEntry(); 990 current_tab->GetController().GetLastCommittedEntry();
992 if (!entry) 991 if (!entry)
993 return false; 992 return false;
994 return entry->GetIsOverridingUserAgent(); 993 return entry->GetIsOverridingUserAgent();
995 } 994 }
996 995
997 void ToggleRequestTabletSite(Browser* browser) { 996 void ToggleRequestTabletSite(Browser* browser) {
998 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); 997 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents();
999 if (!current_tab) 998 if (!current_tab)
1000 return; 999 return;
1001 NavigationController& controller = current_tab->GetController(); 1000 NavigationController& controller = current_tab->GetController();
1002 NavigationEntry* entry = controller.GetActiveEntry(); 1001 NavigationEntry* entry = controller.GetLastCommittedEntry();
1003 if (!entry) 1002 if (!entry)
1004 return; 1003 return;
1005 if (entry->GetIsOverridingUserAgent()) { 1004 if (entry->GetIsOverridingUserAgent()) {
1006 entry->SetIsOverridingUserAgent(false); 1005 entry->SetIsOverridingUserAgent(false);
1007 } else { 1006 } else {
1008 entry->SetIsOverridingUserAgent(true); 1007 entry->SetIsOverridingUserAgent(true);
1009 chrome::VersionInfo version_info; 1008 chrome::VersionInfo version_info;
1010 std::string product; 1009 std::string product;
1011 if (version_info.is_valid()) 1010 if (version_info.is_valid())
1012 product = version_info.ProductNameAndVersionForUserAgent(); 1011 product = version_info.ProductNameAndVersionForUserAgent();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); 1046 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState());
1048 } 1047 }
1049 1048
1050 void ViewSource(Browser* browser, 1049 void ViewSource(Browser* browser,
1051 WebContents* contents, 1050 WebContents* contents,
1052 const GURL& url, 1051 const GURL& url,
1053 const content::PageState& page_state) { 1052 const content::PageState& page_state) {
1054 content::RecordAction(UserMetricsAction("ViewSource")); 1053 content::RecordAction(UserMetricsAction("ViewSource"));
1055 DCHECK(contents); 1054 DCHECK(contents);
1056 1055
1057 // Note that Clone does not copy the pending or transient entries, so the 1056 // Note that Clone does not copy the pending or transient entries, so we can
1058 // active entry in view_source_contents will be the last committed entry. 1057 // take the last committed entry in view_source_contents.
1059 WebContents* view_source_contents = contents->Clone(); 1058 WebContents* view_source_contents = contents->Clone();
1060 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted()); 1059 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted());
1061 view_source_contents->GetController().PruneAllButLastCommitted(); 1060 view_source_contents->GetController().PruneAllButLastCommitted();
1062 NavigationEntry* active_entry = 1061 NavigationEntry* entry =
1063 view_source_contents->GetController().GetActiveEntry(); 1062 view_source_contents->GetController().GetLastCommittedEntry();
1064 if (!active_entry) 1063 if (!entry)
1065 return; 1064 return;
1066 1065
1067 GURL view_source_url = 1066 GURL view_source_url =
1068 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); 1067 GURL(content::kViewSourceScheme + std::string(":") + url.spec());
1069 active_entry->SetVirtualURL(view_source_url); 1068 entry->SetVirtualURL(view_source_url);
1070 1069
1071 // Do not restore scroller position. 1070 // Do not restore scroller position.
1072 active_entry->SetPageState(page_state.RemoveScrollOffset()); 1071 entry->SetPageState(page_state.RemoveScrollOffset());
1073 1072
1074 // Do not restore title, derive it from the url. 1073 // Do not restore title, derive it from the url.
1075 active_entry->SetTitle(string16()); 1074 entry->SetTitle(string16());
1076 1075
1077 // Now show view-source entry. 1076 // Now show view-source entry.
1078 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { 1077 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) {
1079 // If this is a tabbed browser, just create a duplicate tab inside the same 1078 // If this is a tabbed browser, just create a duplicate tab inside the same
1080 // window next to the tab being duplicated. 1079 // window next to the tab being duplicated.
1081 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1080 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1082 int add_types = TabStripModel::ADD_ACTIVE | 1081 int add_types = TabStripModel::ADD_ACTIVE |
1083 TabStripModel::ADD_INHERIT_GROUP; 1082 TabStripModel::ADD_INHERIT_GROUP;
1084 browser->tab_strip_model()->InsertWebContentsAt( 1083 browser->tab_strip_model()->InsertWebContentsAt(
1085 index + 1, 1084 index + 1,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 } 1135 }
1137 1136
1138 bool CanCreateApplicationShortcuts(const Browser* browser) { 1137 bool CanCreateApplicationShortcuts(const Browser* browser) {
1139 return extensions::TabHelper::FromWebContents( 1138 return extensions::TabHelper::FromWebContents(
1140 browser->tab_strip_model()->GetActiveWebContents())-> 1139 browser->tab_strip_model()->GetActiveWebContents())->
1141 CanCreateApplicationShortcuts(); 1140 CanCreateApplicationShortcuts();
1142 } 1141 }
1143 1142
1144 void ConvertTabToAppWindow(Browser* browser, 1143 void ConvertTabToAppWindow(Browser* browser,
1145 content::WebContents* contents) { 1144 content::WebContents* contents) {
1146 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); 1145 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL();
1147 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 1146 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
1148 1147
1149 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1148 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1150 if (index >= 0) 1149 if (index >= 0)
1151 browser->tab_strip_model()->DetachWebContentsAt(index); 1150 browser->tab_strip_model()->DetachWebContentsAt(index);
1152 1151
1153 Browser* app_browser = new Browser( 1152 Browser* app_browser = new Browser(
1154 Browser::CreateParams::CreateForApp( 1153 Browser::CreateParams::CreateForApp(
1155 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), 1154 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(),
1156 browser->host_desktop_type())); 1155 browser->host_desktop_type()));
1157 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1156 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1158 1157
1159 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1158 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1160 contents->GetRenderViewHost()->SyncRendererPrefs(); 1159 contents->GetRenderViewHost()->SyncRendererPrefs();
1161 app_browser->window()->Show(); 1160 app_browser->window()->Show();
1162 } 1161 }
1163 1162
1164 } // namespace chrome 1163 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller.cc ('k') | chrome/browser/ui/cocoa/applescript/tab_applescript.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698