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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "chrome/browser/web_applications/web_app.h" | 57 #include "chrome/browser/web_applications/web_app.h" |
58 #include "chrome/common/chrome_switches.h" | 58 #include "chrome/common/chrome_switches.h" |
59 #include "chrome/common/chrome_version_info.h" | 59 #include "chrome/common/chrome_version_info.h" |
60 #include "chrome/common/content_restriction.h" | 60 #include "chrome/common/content_restriction.h" |
61 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 61 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
62 #include "chrome/common/pref_names.h" | 62 #include "chrome/common/pref_names.h" |
63 #include "components/bookmarks/browser/bookmark_model.h" | 63 #include "components/bookmarks/browser/bookmark_model.h" |
64 #include "components/bookmarks/browser/bookmark_utils.h" | 64 #include "components/bookmarks/browser/bookmark_utils.h" |
65 #include "components/google/core/browser/google_util.h" | 65 #include "components/google/core/browser/google_util.h" |
66 #include "components/translate/core/browser/language_state.h" | 66 #include "components/translate/core/browser/language_state.h" |
67 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 67 #include "components/web_modal/popup_manager.h" |
68 #include "content/public/browser/devtools_agent_host.h" | 68 #include "content/public/browser/devtools_agent_host.h" |
69 #include "content/public/browser/navigation_controller.h" | 69 #include "content/public/browser/navigation_controller.h" |
70 #include "content/public/browser/navigation_entry.h" | 70 #include "content/public/browser/navigation_entry.h" |
71 #include "content/public/browser/notification_service.h" | 71 #include "content/public/browser/notification_service.h" |
72 #include "content/public/browser/page_navigator.h" | 72 #include "content/public/browser/page_navigator.h" |
73 #include "content/public/browser/render_view_host.h" | 73 #include "content/public/browser/render_view_host.h" |
74 #include "content/public/browser/render_widget_host_view.h" | 74 #include "content/public/browser/render_widget_host_view.h" |
75 #include "content/public/browser/user_metrics.h" | 75 #include "content/public/browser/user_metrics.h" |
76 #include "content/public/browser/web_contents.h" | 76 #include "content/public/browser/web_contents.h" |
77 #include "content/public/common/renderer_preferences.h" | 77 #include "content/public/common/renderer_preferences.h" |
(...skipping 24 matching lines...) Expand all Loading... |
102 const char kOsOverrideForTabletSite[] = "Linux; Android 4.0.3"; | 102 const char kOsOverrideForTabletSite[] = "Linux; Android 4.0.3"; |
103 } | 103 } |
104 | 104 |
105 using base::UserMetricsAction; | 105 using base::UserMetricsAction; |
106 using content::NavigationController; | 106 using content::NavigationController; |
107 using content::NavigationEntry; | 107 using content::NavigationEntry; |
108 using content::OpenURLParams; | 108 using content::OpenURLParams; |
109 using content::Referrer; | 109 using content::Referrer; |
110 using content::SSLStatus; | 110 using content::SSLStatus; |
111 using content::WebContents; | 111 using content::WebContents; |
112 using web_modal::WebContentsModalDialogManager; | |
113 | 112 |
114 namespace chrome { | 113 namespace chrome { |
115 namespace { | 114 namespace { |
116 | 115 |
117 bool CanBookmarkCurrentPageInternal(const Browser* browser, | 116 bool CanBookmarkCurrentPageInternal(const Browser* browser, |
118 bool check_remove_bookmark_ui) { | 117 bool check_remove_bookmark_ui) { |
119 BookmarkModel* model = | 118 BookmarkModel* model = |
120 BookmarkModelFactory::GetForProfile(browser->profile()); | 119 BookmarkModelFactory::GetForProfile(browser->profile()); |
121 return browser_defaults::bookmarks_enabled && | 120 return browser_defaults::bookmarks_enabled && |
122 browser->profile()->GetPrefs()->GetBoolean( | 121 browser->profile()->GetPrefs()->GetBoolean( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 WebContents* new_tab = GetTabAndRevertIfNecessary(browser, disposition); | 237 WebContents* new_tab = GetTabAndRevertIfNecessary(browser, disposition); |
239 new_tab->UserGestureDone(); | 238 new_tab->UserGestureDone(); |
240 if (!new_tab->FocusLocationBarByDefault()) | 239 if (!new_tab->FocusLocationBarByDefault()) |
241 new_tab->Focus(); | 240 new_tab->Focus(); |
242 if (ignore_cache) | 241 if (ignore_cache) |
243 new_tab->GetController().ReloadIgnoringCache(true); | 242 new_tab->GetController().ReloadIgnoringCache(true); |
244 else | 243 else |
245 new_tab->GetController().Reload(true); | 244 new_tab->GetController().Reload(true); |
246 } | 245 } |
247 | 246 |
248 bool IsShowingWebContentsModalDialog(const Browser* browser) { | 247 bool IsShowingWebContentsModalDialog(Browser* browser) { |
249 WebContents* web_contents = | 248 WebContents* web_contents = |
250 browser->tab_strip_model()->GetActiveWebContents(); | 249 browser->tab_strip_model()->GetActiveWebContents(); |
251 if (!web_contents) | 250 if (!web_contents) |
252 return false; | 251 return false; |
253 | 252 |
254 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 253 // In test code we may not have a popup manager. |
255 WebContentsModalDialogManager::FromWebContents(web_contents); | 254 if (!browser->popup_manager()) |
256 return web_contents_modal_dialog_manager->IsDialogActive(); | 255 return false; |
| 256 |
| 257 // TODO(gbillock): This is currently called in production by the CanPrint |
| 258 // method, and may be too restrictive if we allow print preview to overlap. |
| 259 // Re-assess how to queue print preview after we know more about popup |
| 260 // management policy. |
| 261 return browser->popup_manager()->IsWebModalDialogActive(web_contents); |
257 } | 262 } |
258 | 263 |
259 bool PrintPreviewShowing(const Browser* browser) { | 264 bool PrintPreviewShowing(const Browser* browser) { |
260 #if defined(ENABLE_FULL_PRINTING) | 265 #if defined(ENABLE_FULL_PRINTING) |
261 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents(); | 266 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents(); |
262 printing::PrintPreviewDialogController* controller = | 267 printing::PrintPreviewDialogController* controller = |
263 printing::PrintPreviewDialogController::GetInstance(); | 268 printing::PrintPreviewDialogController::GetInstance(); |
264 return controller && (controller->GetPrintPreviewForContents(contents) || | 269 return controller && (controller->GetPrintPreviewForContents(contents) || |
265 controller->is_creating_print_preview_dialog()); | 270 controller->is_creating_print_preview_dialog()); |
266 #else | 271 #else |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 else | 851 else |
847 print_view_manager->PrintPreviewNow(false); | 852 print_view_manager->PrintPreviewNow(false); |
848 #else | 853 #else |
849 printing::PrintViewManagerBasic* print_view_manager = | 854 printing::PrintViewManagerBasic* print_view_manager = |
850 printing::PrintViewManagerBasic::FromWebContents(contents); | 855 printing::PrintViewManagerBasic::FromWebContents(contents); |
851 print_view_manager->PrintNow(); | 856 print_view_manager->PrintNow(); |
852 #endif // defined(ENABLE_FULL_PRINTING) | 857 #endif // defined(ENABLE_FULL_PRINTING) |
853 #endif // defined(ENABLE_PRINTING) | 858 #endif // defined(ENABLE_PRINTING) |
854 } | 859 } |
855 | 860 |
856 bool CanPrint(const Browser* browser) { | 861 bool CanPrint(Browser* browser) { |
857 // Do not print when printing is disabled via pref or policy. | 862 // Do not print when printing is disabled via pref or policy. |
858 // Do not print when a constrained window is showing. It's confusing. | 863 // Do not print when a constrained window is showing. It's confusing. |
| 864 // TODO(gbillock): Need to re-assess the call to |
| 865 // IsShowingWebContentsModalDialog after a popup management policy is |
| 866 // refined -- we will probably want to just queue the print request, not |
| 867 // block it. |
859 return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && | 868 return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && |
860 !(IsShowingWebContentsModalDialog(browser) || | 869 !(IsShowingWebContentsModalDialog(browser) || |
861 GetContentRestrictions(browser) & CONTENT_RESTRICTION_PRINT); | 870 GetContentRestrictions(browser) & CONTENT_RESTRICTION_PRINT); |
862 } | 871 } |
863 | 872 |
864 void AdvancedPrint(Browser* browser) { | 873 void AdvancedPrint(Browser* browser) { |
865 #if defined(ENABLE_FULL_PRINTING) | 874 #if defined(ENABLE_FULL_PRINTING) |
866 printing::PrintViewManager* print_view_manager = | 875 printing::PrintViewManager* print_view_manager = |
867 printing::PrintViewManager::FromWebContents( | 876 printing::PrintViewManager::FromWebContents( |
868 browser->tab_strip_model()->GetActiveWebContents()); | 877 browser->tab_strip_model()->GetActiveWebContents()); |
869 print_view_manager->AdvancedPrintNow(); | 878 print_view_manager->AdvancedPrintNow(); |
870 #endif | 879 #endif |
871 } | 880 } |
872 | 881 |
873 bool CanAdvancedPrint(const Browser* browser) { | 882 bool CanAdvancedPrint(Browser* browser) { |
874 // If printing is not disabled via pref or policy, it is always possible to | 883 // If printing is not disabled via pref or policy, it is always possible to |
875 // advanced print when the print preview is visible. The exception to this | 884 // advanced print when the print preview is visible. The exception to this |
876 // is under Win8 ash, since showing the advanced print dialog will open it | 885 // is under Win8 ash, since showing the advanced print dialog will open it |
877 // modally on the Desktop and hang the browser. We can remove this check | 886 // modally on the Desktop and hang the browser. We can remove this check |
878 // once we integrate with the system print charm. | 887 // once we integrate with the system print charm. |
879 #if defined(OS_WIN) | 888 #if defined(OS_WIN) |
880 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) | 889 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
881 return false; | 890 return false; |
882 #endif | 891 #endif |
883 | 892 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 browser->profile(), | 1275 browser->profile(), |
1267 browser->host_desktop_type())); | 1276 browser->host_desktop_type())); |
1268 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1277 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
1269 | 1278 |
1270 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1279 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
1271 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1280 contents->GetRenderViewHost()->SyncRendererPrefs(); |
1272 app_browser->window()->Show(); | 1281 app_browser->window()->Show(); |
1273 } | 1282 } |
1274 | 1283 |
1275 } // namespace chrome | 1284 } // namespace chrome |
OLD | NEW |