OLD | NEW |
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 command, observer); | 249 command, observer); |
250 } | 250 } |
251 | 251 |
252 int GetContentRestrictions(const Browser* browser) { | 252 int GetContentRestrictions(const Browser* browser) { |
253 int content_restrictions = 0; | 253 int content_restrictions = 0; |
254 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 254 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
255 if (current_tab) { | 255 if (current_tab) { |
256 CoreTabHelper* core_tab_helper = | 256 CoreTabHelper* core_tab_helper = |
257 CoreTabHelper::FromWebContents(current_tab); | 257 CoreTabHelper::FromWebContents(current_tab); |
258 content_restrictions = core_tab_helper->content_restrictions(); | 258 content_restrictions = core_tab_helper->content_restrictions(); |
259 NavigationEntry* entry = | 259 NavigationEntry* active_entry = |
260 current_tab->GetController().GetLastCommittedEntry(); | 260 current_tab->GetController().GetActiveEntry(); |
261 // See comment in UpdateCommandsForTabState about why we call url(). | 261 // See comment in UpdateCommandsForTabState about why we call url(). |
262 if (!content::IsSavableURL(entry ? entry->GetURL() : GURL()) || | 262 if (!content::IsSavableURL( |
| 263 active_entry ? active_entry->GetURL() : GURL()) || |
263 current_tab->ShowingInterstitialPage()) | 264 current_tab->ShowingInterstitialPage()) |
264 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 265 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
265 if (current_tab->ShowingInterstitialPage()) | 266 if (current_tab->ShowingInterstitialPage()) |
266 content_restrictions |= CONTENT_RESTRICTION_PRINT; | 267 content_restrictions |= CONTENT_RESTRICTION_PRINT; |
267 } | 268 } |
268 return content_restrictions; | 269 return content_restrictions; |
269 } | 270 } |
270 | 271 |
271 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { | 272 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { |
272 bool incognito = profile->IsOffTheRecord(); | 273 bool incognito = profile->IsOffTheRecord(); |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 SearchTabHelper* search_tab_helper = | 981 SearchTabHelper* search_tab_helper = |
981 SearchTabHelper::FromWebContents(web_contents); | 982 SearchTabHelper::FromWebContents(web_contents); |
982 // |search_tab_helper| can be null in unit tests. | 983 // |search_tab_helper| can be null in unit tests. |
983 if (search_tab_helper) | 984 if (search_tab_helper) |
984 search_tab_helper->ToggleVoiceSearch(); | 985 search_tab_helper->ToggleVoiceSearch(); |
985 } | 986 } |
986 | 987 |
987 bool CanRequestTabletSite(WebContents* current_tab) { | 988 bool CanRequestTabletSite(WebContents* current_tab) { |
988 if (!current_tab) | 989 if (!current_tab) |
989 return false; | 990 return false; |
990 return current_tab->GetController().GetLastCommittedEntry() != NULL; | 991 return current_tab->GetController().GetActiveEntry() != NULL; |
991 } | 992 } |
992 | 993 |
993 bool IsRequestingTabletSite(Browser* browser) { | 994 bool IsRequestingTabletSite(Browser* browser) { |
994 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 995 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
995 if (!current_tab) | 996 if (!current_tab) |
996 return false; | 997 return false; |
997 content::NavigationEntry* entry = | 998 content::NavigationEntry* entry = |
998 current_tab->GetController().GetLastCommittedEntry(); | 999 current_tab->GetController().GetActiveEntry(); |
999 if (!entry) | 1000 if (!entry) |
1000 return false; | 1001 return false; |
1001 return entry->GetIsOverridingUserAgent(); | 1002 return entry->GetIsOverridingUserAgent(); |
1002 } | 1003 } |
1003 | 1004 |
1004 void ToggleRequestTabletSite(Browser* browser) { | 1005 void ToggleRequestTabletSite(Browser* browser) { |
1005 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 1006 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
1006 if (!current_tab) | 1007 if (!current_tab) |
1007 return; | 1008 return; |
1008 NavigationController& controller = current_tab->GetController(); | 1009 NavigationController& controller = current_tab->GetController(); |
1009 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 1010 NavigationEntry* entry = controller.GetActiveEntry(); |
1010 if (!entry) | 1011 if (!entry) |
1011 return; | 1012 return; |
1012 if (entry->GetIsOverridingUserAgent()) { | 1013 if (entry->GetIsOverridingUserAgent()) { |
1013 entry->SetIsOverridingUserAgent(false); | 1014 entry->SetIsOverridingUserAgent(false); |
1014 } else { | 1015 } else { |
1015 entry->SetIsOverridingUserAgent(true); | 1016 entry->SetIsOverridingUserAgent(true); |
1016 chrome::VersionInfo version_info; | 1017 chrome::VersionInfo version_info; |
1017 std::string product; | 1018 std::string product; |
1018 if (version_info.is_valid()) | 1019 if (version_info.is_valid()) |
1019 product = version_info.ProductNameAndVersionForUserAgent(); | 1020 product = version_info.ProductNameAndVersionForUserAgent(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); | 1055 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); |
1055 } | 1056 } |
1056 | 1057 |
1057 void ViewSource(Browser* browser, | 1058 void ViewSource(Browser* browser, |
1058 WebContents* contents, | 1059 WebContents* contents, |
1059 const GURL& url, | 1060 const GURL& url, |
1060 const content::PageState& page_state) { | 1061 const content::PageState& page_state) { |
1061 content::RecordAction(UserMetricsAction("ViewSource")); | 1062 content::RecordAction(UserMetricsAction("ViewSource")); |
1062 DCHECK(contents); | 1063 DCHECK(contents); |
1063 | 1064 |
1064 // Note that Clone does not copy the pending or transient entries, so we can | 1065 // Note that Clone does not copy the pending or transient entries, so the |
1065 // take the last committed entry in view_source_contents. | 1066 // active entry in view_source_contents will be the last committed entry. |
1066 WebContents* view_source_contents = contents->Clone(); | 1067 WebContents* view_source_contents = contents->Clone(); |
1067 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted()); | 1068 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted()); |
1068 view_source_contents->GetController().PruneAllButLastCommitted(); | 1069 view_source_contents->GetController().PruneAllButLastCommitted(); |
1069 NavigationEntry* entry = | 1070 NavigationEntry* active_entry = |
1070 view_source_contents->GetController().GetLastCommittedEntry(); | 1071 view_source_contents->GetController().GetActiveEntry(); |
1071 if (!entry) | 1072 if (!active_entry) |
1072 return; | 1073 return; |
1073 | 1074 |
1074 GURL view_source_url = | 1075 GURL view_source_url = |
1075 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); | 1076 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); |
1076 entry->SetVirtualURL(view_source_url); | 1077 active_entry->SetVirtualURL(view_source_url); |
1077 | 1078 |
1078 // Do not restore scroller position. | 1079 // Do not restore scroller position. |
1079 entry->SetPageState(page_state.RemoveScrollOffset()); | 1080 active_entry->SetPageState(page_state.RemoveScrollOffset()); |
1080 | 1081 |
1081 // Do not restore title, derive it from the url. | 1082 // Do not restore title, derive it from the url. |
1082 entry->SetTitle(base::string16()); | 1083 active_entry->SetTitle(string16()); |
1083 | 1084 |
1084 // Now show view-source entry. | 1085 // Now show view-source entry. |
1085 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { | 1086 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { |
1086 // If this is a tabbed browser, just create a duplicate tab inside the same | 1087 // If this is a tabbed browser, just create a duplicate tab inside the same |
1087 // window next to the tab being duplicated. | 1088 // window next to the tab being duplicated. |
1088 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1089 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
1089 int add_types = TabStripModel::ADD_ACTIVE | | 1090 int add_types = TabStripModel::ADD_ACTIVE | |
1090 TabStripModel::ADD_INHERIT_GROUP; | 1091 TabStripModel::ADD_INHERIT_GROUP; |
1091 browser->tab_strip_model()->InsertWebContentsAt( | 1092 browser->tab_strip_model()->InsertWebContentsAt( |
1092 index + 1, | 1093 index + 1, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 } | 1144 } |
1144 | 1145 |
1145 bool CanCreateApplicationShortcuts(const Browser* browser) { | 1146 bool CanCreateApplicationShortcuts(const Browser* browser) { |
1146 return extensions::TabHelper::FromWebContents( | 1147 return extensions::TabHelper::FromWebContents( |
1147 browser->tab_strip_model()->GetActiveWebContents())-> | 1148 browser->tab_strip_model()->GetActiveWebContents())-> |
1148 CanCreateApplicationShortcuts(); | 1149 CanCreateApplicationShortcuts(); |
1149 } | 1150 } |
1150 | 1151 |
1151 void ConvertTabToAppWindow(Browser* browser, | 1152 void ConvertTabToAppWindow(Browser* browser, |
1152 content::WebContents* contents) { | 1153 content::WebContents* contents) { |
1153 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL(); | 1154 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); |
1154 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 1155 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
1155 | 1156 |
1156 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1157 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
1157 if (index >= 0) | 1158 if (index >= 0) |
1158 browser->tab_strip_model()->DetachWebContentsAt(index); | 1159 browser->tab_strip_model()->DetachWebContentsAt(index); |
1159 | 1160 |
1160 Browser* app_browser = new Browser( | 1161 Browser* app_browser = new Browser( |
1161 Browser::CreateParams::CreateForApp( | 1162 Browser::CreateParams::CreateForApp( |
1162 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), | 1163 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), |
1163 browser->host_desktop_type())); | 1164 browser->host_desktop_type())); |
1164 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1165 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
1165 | 1166 |
1166 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1167 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1167 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1168 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1168 app_browser->window()->Show(); | 1169 app_browser->window()->Show(); |
1169 } | 1170 } |
1170 | 1171 |
1171 } // namespace chrome | 1172 } // namespace chrome |
OLD | NEW |