| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 246 } |
| 247 | 247 |
| 248 int GetContentRestrictions(const Browser* browser) { | 248 int GetContentRestrictions(const Browser* browser) { |
| 249 int content_restrictions = 0; | 249 int content_restrictions = 0; |
| 250 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 250 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
| 251 if (current_tab) { | 251 if (current_tab) { |
| 252 CoreTabHelper* core_tab_helper = | 252 CoreTabHelper* core_tab_helper = |
| 253 CoreTabHelper::FromWebContents(current_tab); | 253 CoreTabHelper::FromWebContents(current_tab); |
| 254 content_restrictions = core_tab_helper->content_restrictions(); | 254 content_restrictions = core_tab_helper->content_restrictions(); |
| 255 NavigationEntry* active_entry = | 255 NavigationEntry* active_entry = |
| 256 current_tab->GetController().GetActiveEntry(); | 256 current_tab->GetController().GetVisibleEntry(); |
| 257 // See comment in UpdateCommandsForTabState about why we call url(). | 257 // See comment in UpdateCommandsForTabState about why we call url(). |
| 258 if (!content::IsSavableURL( | 258 if (!content::IsSavableURL( |
| 259 active_entry ? active_entry->GetURL() : GURL()) || | 259 active_entry ? active_entry->GetURL() : GURL()) || |
| 260 current_tab->ShowingInterstitialPage()) | 260 current_tab->ShowingInterstitialPage()) |
| 261 content_restrictions |= CONTENT_RESTRICTION_SAVE; | 261 content_restrictions |= CONTENT_RESTRICTION_SAVE; |
| 262 if (current_tab->ShowingInterstitialPage()) | 262 if (current_tab->ShowingInterstitialPage()) |
| 263 content_restrictions |= CONTENT_RESTRICTION_PRINT; | 263 content_restrictions |= CONTENT_RESTRICTION_PRINT; |
| 264 } | 264 } |
| 265 return content_restrictions; | 265 return content_restrictions; |
| 266 } | 266 } |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 void ToggleSpeechInput(Browser* browser) { | 950 void ToggleSpeechInput(Browser* browser) { |
| 951 browser->tab_strip_model()->GetActiveWebContents()-> | 951 browser->tab_strip_model()->GetActiveWebContents()-> |
| 952 GetRenderViewHost()->ToggleSpeechInput(); | 952 GetRenderViewHost()->ToggleSpeechInput(); |
| 953 if (browser->instant_controller()) | 953 if (browser->instant_controller()) |
| 954 browser->instant_controller()->ToggleVoiceSearch(); | 954 browser->instant_controller()->ToggleVoiceSearch(); |
| 955 } | 955 } |
| 956 | 956 |
| 957 bool CanRequestTabletSite(WebContents* current_tab) { | 957 bool CanRequestTabletSite(WebContents* current_tab) { |
| 958 if (!current_tab) | 958 if (!current_tab) |
| 959 return false; | 959 return false; |
| 960 return current_tab->GetController().GetActiveEntry() != NULL; | 960 return current_tab->GetController().GetVisibleEntry() != NULL; |
| 961 } | 961 } |
| 962 | 962 |
| 963 bool IsRequestingTabletSite(Browser* browser) { | 963 bool IsRequestingTabletSite(Browser* browser) { |
| 964 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 964 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
| 965 if (!current_tab) | 965 if (!current_tab) |
| 966 return false; | 966 return false; |
| 967 content::NavigationEntry* entry = | 967 content::NavigationEntry* entry = |
| 968 current_tab->GetController().GetActiveEntry(); | 968 current_tab->GetController().GetVisibleEntry(); |
| 969 if (!entry) | 969 if (!entry) |
| 970 return false; | 970 return false; |
| 971 return entry->GetIsOverridingUserAgent(); | 971 return entry->GetIsOverridingUserAgent(); |
| 972 } | 972 } |
| 973 | 973 |
| 974 void ToggleRequestTabletSite(Browser* browser) { | 974 void ToggleRequestTabletSite(Browser* browser) { |
| 975 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 975 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
| 976 if (!current_tab) | 976 if (!current_tab) |
| 977 return; | 977 return; |
| 978 NavigationController& controller = current_tab->GetController(); | 978 NavigationController& controller = current_tab->GetController(); |
| 979 NavigationEntry* entry = controller.GetActiveEntry(); | 979 NavigationEntry* entry = controller.GetVisibleEntry(); |
| 980 if (!entry) | 980 if (!entry) |
| 981 return; | 981 return; |
| 982 if (entry->GetIsOverridingUserAgent()) { | 982 if (entry->GetIsOverridingUserAgent()) { |
| 983 entry->SetIsOverridingUserAgent(false); | 983 entry->SetIsOverridingUserAgent(false); |
| 984 } else { | 984 } else { |
| 985 entry->SetIsOverridingUserAgent(true); | 985 entry->SetIsOverridingUserAgent(true); |
| 986 chrome::VersionInfo version_info; | 986 chrome::VersionInfo version_info; |
| 987 std::string product; | 987 std::string product; |
| 988 if (version_info.is_valid()) | 988 if (version_info.is_valid()) |
| 989 product = version_info.ProductNameAndVersionForUserAgent(); | 989 product = version_info.ProductNameAndVersionForUserAgent(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 const content::PageState& page_state) { | 1030 const content::PageState& page_state) { |
| 1031 content::RecordAction(UserMetricsAction("ViewSource")); | 1031 content::RecordAction(UserMetricsAction("ViewSource")); |
| 1032 DCHECK(contents); | 1032 DCHECK(contents); |
| 1033 | 1033 |
| 1034 // Note that Clone does not copy the pending or transient entries, so the | 1034 // Note that Clone does not copy the pending or transient entries, so the |
| 1035 // active entry in view_source_contents will be the last committed entry. | 1035 // active entry in view_source_contents will be the last committed entry. |
| 1036 WebContents* view_source_contents = contents->Clone(); | 1036 WebContents* view_source_contents = contents->Clone(); |
| 1037 DCHECK(view_source_contents->GetController().CanPruneAllButVisible()); | 1037 DCHECK(view_source_contents->GetController().CanPruneAllButVisible()); |
| 1038 view_source_contents->GetController().PruneAllButVisible(); | 1038 view_source_contents->GetController().PruneAllButVisible(); |
| 1039 NavigationEntry* active_entry = | 1039 NavigationEntry* active_entry = |
| 1040 view_source_contents->GetController().GetActiveEntry(); | 1040 view_source_contents->GetController().GetVisibleEntry(); |
| 1041 if (!active_entry) | 1041 if (!active_entry) |
| 1042 return; | 1042 return; |
| 1043 | 1043 |
| 1044 GURL view_source_url = | 1044 GURL view_source_url = |
| 1045 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); | 1045 GURL(content::kViewSourceScheme + std::string(":") + url.spec()); |
| 1046 active_entry->SetVirtualURL(view_source_url); | 1046 active_entry->SetVirtualURL(view_source_url); |
| 1047 | 1047 |
| 1048 // Do not restore scroller position. | 1048 // Do not restore scroller position. |
| 1049 active_entry->SetPageState(page_state.RemoveScrollOffset()); | 1049 active_entry->SetPageState(page_state.RemoveScrollOffset()); |
| 1050 | 1050 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 bool CanCreateApplicationShortcuts(const Browser* browser) { | 1108 bool CanCreateApplicationShortcuts(const Browser* browser) { |
| 1109 return extensions::TabHelper::FromWebContents( | 1109 return extensions::TabHelper::FromWebContents( |
| 1110 browser->tab_strip_model()->GetActiveWebContents())-> | 1110 browser->tab_strip_model()->GetActiveWebContents())-> |
| 1111 CanCreateApplicationShortcuts(); | 1111 CanCreateApplicationShortcuts(); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 void ConvertTabToAppWindow(Browser* browser, | 1114 void ConvertTabToAppWindow(Browser* browser, |
| 1115 content::WebContents* contents) { | 1115 content::WebContents* contents) { |
| 1116 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); | 1116 const GURL& url = contents->GetController().GetVisibleEntry()->GetURL(); |
| 1117 std::string app_name = web_app::GenerateApplicationNameFromURL(url); | 1117 std::string app_name = web_app::GenerateApplicationNameFromURL(url); |
| 1118 | 1118 |
| 1119 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); | 1119 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); |
| 1120 if (index >= 0) | 1120 if (index >= 0) |
| 1121 browser->tab_strip_model()->DetachWebContentsAt(index); | 1121 browser->tab_strip_model()->DetachWebContentsAt(index); |
| 1122 | 1122 |
| 1123 Browser* app_browser = new Browser( | 1123 Browser* app_browser = new Browser( |
| 1124 Browser::CreateParams::CreateForApp( | 1124 Browser::CreateParams::CreateForApp( |
| 1125 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), | 1125 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), |
| 1126 browser->host_desktop_type())); | 1126 browser->host_desktop_type())); |
| 1127 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1127 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
| 1128 | 1128 |
| 1129 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1129 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 1130 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1130 contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 1131 app_browser->window()->Show(); | 1131 app_browser->window()->Show(); |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 } // namespace chrome | 1134 } // namespace chrome |
| OLD | NEW |