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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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* last_committed_entry = |
317 current_tab->GetController().GetActiveEntry(); | 317 current_tab->GetController().GetLastCommittedEntry(); |
318 // See comment in UpdateCommandsForTabState about why we call url(). | |
319 if (!content::IsSavableURL( | 318 if (!content::IsSavableURL( |
320 active_entry ? active_entry->GetURL() : GURL()) || | 319 last_committed_entry ? last_committed_entry->GetURL() : GURL()) || |
321 current_tab->ShowingInterstitialPage()) | 320 current_tab->ShowingInterstitialPage()) |
322 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 321 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
323 if (current_tab->ShowingInterstitialPage()) | 322 if (current_tab->ShowingInterstitialPage()) |
324 content_restrictions |= CONTENT_RESTRICTION_PRINT; | 323 content_restrictions |= CONTENT_RESTRICTION_PRINT; |
325 } | 324 } |
326 return content_restrictions; | 325 return content_restrictions; |
327 } | 326 } |
328 | 327 |
329 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { | 328 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { |
330 bool incognito = profile->IsOffTheRecord(); | 329 bool incognito = profile->IsOffTheRecord(); |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 // |search_tab_helper| can be null in unit tests. | 1070 // |search_tab_helper| can be null in unit tests. |
1072 if (search_tab_helper) | 1071 if (search_tab_helper) |
1073 search_tab_helper->ToggleVoiceSearch(); | 1072 search_tab_helper->ToggleVoiceSearch(); |
1074 } | 1073 } |
1075 | 1074 |
1076 void DistillCurrentPage(Browser* browser) { | 1075 void DistillCurrentPage(Browser* browser) { |
1077 DistillCurrentPageAndView(browser->tab_strip_model()->GetActiveWebContents()); | 1076 DistillCurrentPageAndView(browser->tab_strip_model()->GetActiveWebContents()); |
1078 } | 1077 } |
1079 | 1078 |
1080 bool CanRequestTabletSite(WebContents* current_tab) { | 1079 bool CanRequestTabletSite(WebContents* current_tab) { |
1081 if (!current_tab) | 1080 return current_tab && |
1082 return false; | 1081 current_tab->GetController().GetLastCommittedEntry() != NULL; |
1083 return current_tab->GetController().GetActiveEntry() != NULL; | |
1084 } | 1082 } |
1085 | 1083 |
1086 bool IsRequestingTabletSite(Browser* browser) { | 1084 bool IsRequestingTabletSite(Browser* browser) { |
1087 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 1085 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
1088 if (!current_tab) | 1086 if (!current_tab) |
1089 return false; | 1087 return false; |
1090 content::NavigationEntry* entry = | 1088 content::NavigationEntry* entry = |
1091 current_tab->GetController().GetActiveEntry(); | 1089 current_tab->GetController().GetLastCommittedEntry(); |
1092 if (!entry) | 1090 if (!entry) |
1093 return false; | 1091 return false; |
1094 return entry->GetIsOverridingUserAgent(); | 1092 return entry->GetIsOverridingUserAgent(); |
1095 } | 1093 } |
1096 | 1094 |
1097 void ToggleRequestTabletSite(Browser* browser) { | 1095 void ToggleRequestTabletSite(Browser* browser) { |
1098 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 1096 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
1099 if (!current_tab) | 1097 if (!current_tab) |
1100 return; | 1098 return; |
1101 NavigationController& controller = current_tab->GetController(); | 1099 NavigationController& controller = current_tab->GetController(); |
1102 NavigationEntry* entry = controller.GetActiveEntry(); | 1100 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
1103 if (!entry) | 1101 if (!entry) |
1104 return; | 1102 return; |
1105 if (entry->GetIsOverridingUserAgent()) { | 1103 if (entry->GetIsOverridingUserAgent()) { |
1106 entry->SetIsOverridingUserAgent(false); | 1104 entry->SetIsOverridingUserAgent(false); |
1107 } else { | 1105 } else { |
1108 entry->SetIsOverridingUserAgent(true); | 1106 entry->SetIsOverridingUserAgent(true); |
1109 chrome::VersionInfo version_info; | 1107 chrome::VersionInfo version_info; |
1110 std::string product; | 1108 std::string product; |
1111 if (version_info.is_valid()) | 1109 if (version_info.is_valid()) |
1112 product = version_info.ProductNameAndVersionForUserAgent(); | 1110 product = version_info.ProductNameAndVersionForUserAgent(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); | 1145 ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); |
1148 } | 1146 } |
1149 | 1147 |
1150 void ViewSource(Browser* browser, | 1148 void ViewSource(Browser* browser, |
1151 WebContents* contents, | 1149 WebContents* contents, |
1152 const GURL& url, | 1150 const GURL& url, |
1153 const content::PageState& page_state) { | 1151 const content::PageState& page_state) { |
1154 content::RecordAction(UserMetricsAction("ViewSource")); | 1152 content::RecordAction(UserMetricsAction("ViewSource")); |
1155 DCHECK(contents); | 1153 DCHECK(contents); |
1156 | 1154 |
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. | |
1159 WebContents* view_source_contents = contents->Clone(); | 1155 WebContents* view_source_contents = contents->Clone(); |
1160 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted()); | 1156 DCHECK(view_source_contents->GetController().CanPruneAllButLastCommitted()); |
1161 view_source_contents->GetController().PruneAllButLastCommitted(); | 1157 view_source_contents->GetController().PruneAllButLastCommitted(); |
1162 NavigationEntry* active_entry = | 1158 NavigationEntry* last_committed_entry = |
1163 view_source_contents->GetController().GetActiveEntry(); | 1159 view_source_contents->GetController().GetLastCommittedEntry(); |
1164 if (!active_entry) | 1160 if (!last_committed_entry) |
1165 return; | 1161 return; |
1166 | 1162 |
1167 GURL view_source_url = | 1163 GURL view_source_url = |
1168 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); | 1164 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); |
1169 active_entry->SetVirtualURL(view_source_url); | 1165 last_committed_entry->SetVirtualURL(view_source_url); |
1170 | 1166 |
1171 // Do not restore scroller position. | 1167 // Do not restore scroller position. |
1172 active_entry->SetPageState(page_state.RemoveScrollOffset()); | 1168 last_committed_entry->SetPageState(page_state.RemoveScrollOffset()); |
1173 | 1169 |
1174 // Do not restore title, derive it from the url. | 1170 // Do not restore title, derive it from the url. |
1175 active_entry->SetTitle(base::string16()); | 1171 last_committed_entry->SetTitle(base::string16()); |
1176 | 1172 |
1177 // Now show view-source entry. | 1173 // Now show view-source entry. |
1178 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { | 1174 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { |
1179 // If this is a tabbed browser, just create a duplicate tab inside the same | 1175 // If this is a tabbed browser, just create a duplicate tab inside the same |
1180 // window next to the tab being duplicated. | 1176 // window next to the tab being duplicated. |
1181 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1177 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
1182 int add_types = TabStripModel::ADD_ACTIVE | | 1178 int add_types = TabStripModel::ADD_ACTIVE | |
1183 TabStripModel::ADD_INHERIT_GROUP; | 1179 TabStripModel::ADD_INHERIT_GROUP; |
1184 browser->tab_strip_model()->InsertWebContentsAt( | 1180 browser->tab_strip_model()->InsertWebContentsAt( |
1185 index + 1, | 1181 index + 1, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 } | 1239 } |
1244 | 1240 |
1245 bool CanCreateBookmarkApp(const Browser* browser) { | 1241 bool CanCreateBookmarkApp(const Browser* browser) { |
1246 return extensions::TabHelper::FromWebContents( | 1242 return extensions::TabHelper::FromWebContents( |
1247 browser->tab_strip_model()->GetActiveWebContents()) | 1243 browser->tab_strip_model()->GetActiveWebContents()) |
1248 ->CanCreateBookmarkApp(); | 1244 ->CanCreateBookmarkApp(); |
1249 } | 1245 } |
1250 | 1246 |
1251 void ConvertTabToAppWindow(Browser* browser, | 1247 void ConvertTabToAppWindow(Browser* browser, |
1252 content::WebContents* contents) { | 1248 content::WebContents* contents) { |
1253 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); | 1249 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL(); |
1254 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 1250 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
1255 | 1251 |
1256 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1252 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
1257 if (index >= 0) | 1253 if (index >= 0) |
1258 browser->tab_strip_model()->DetachWebContentsAt(index); | 1254 browser->tab_strip_model()->DetachWebContentsAt(index); |
1259 | 1255 |
1260 Browser* app_browser = new Browser( | 1256 Browser* app_browser = new Browser( |
1261 Browser::CreateParams::CreateForApp(app_name, | 1257 Browser::CreateParams::CreateForApp(app_name, |
1262 true /* trusted_source */, | 1258 true /* trusted_source */, |
1263 gfx::Rect(), | 1259 gfx::Rect(), |
1264 browser->profile(), | 1260 browser->profile(), |
1265 browser->host_desktop_type())); | 1261 browser->host_desktop_type())); |
1266 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1262 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
1267 | 1263 |
1268 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1264 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1269 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1265 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1270 app_browser->window()->Show(); | 1266 app_browser->window()->Show(); |
1271 } | 1267 } |
1272 | 1268 |
1273 } // namespace chrome | 1269 } // namespace chrome |
OLD | NEW |