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

Side by Side Diff: chrome/browser/ui/browser_commands.cc

Issue 22577010: Printing: Add a basic printing mode without print preview and cloud print. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 4 months 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
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"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/bookmarks/bookmark_utils.h" 13 #include "chrome/browser/bookmarks/bookmark_utils.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/browsing_data/browsing_data_helper.h" 15 #include "chrome/browser/browsing_data/browsing_data_helper.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover.h" 16 #include "chrome/browser/browsing_data/browsing_data_remover.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chrome_page_zoom.h" 18 #include "chrome/browser/chrome_page_zoom.h"
19 #include "chrome/browser/devtools/devtools_window.h" 19 #include "chrome/browser/devtools/devtools_window.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/tab_helper.h" 21 #include "chrome/browser/extensions/tab_helper.h"
22 #include "chrome/browser/favicon/favicon_tab_helper.h" 22 #include "chrome/browser/favicon/favicon_tab_helper.h"
23 #include "chrome/browser/google/google_util.h" 23 #include "chrome/browser/google/google_util.h"
24 #include "chrome/browser/lifetime/application_lifetime.h" 24 #include "chrome/browser/lifetime/application_lifetime.h"
25 #include "chrome/browser/platform_util.h" 25 #include "chrome/browser/platform_util.h"
26 #include "chrome/browser/prefs/incognito_mode_prefs.h" 26 #include "chrome/browser/prefs/incognito_mode_prefs.h"
27 #include "chrome/browser/printing/print_preview_dialog_controller.h"
28 #include "chrome/browser/printing/print_view_manager.h"
29 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/rlz/rlz.h" 28 #include "chrome/browser/rlz/rlz.h"
31 #include "chrome/browser/sessions/session_service_factory.h" 29 #include "chrome/browser/sessions/session_service_factory.h"
32 #include "chrome/browser/sessions/tab_restore_service.h" 30 #include "chrome/browser/sessions/tab_restore_service.h"
33 #include "chrome/browser/sessions/tab_restore_service_delegate.h" 31 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
34 #include "chrome/browser/sessions/tab_restore_service_factory.h" 32 #include "chrome/browser/sessions/tab_restore_service_factory.h"
35 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h" 33 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h"
36 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 34 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
37 #include "chrome/browser/ui/browser.h" 35 #include "chrome/browser/ui/browser.h"
38 #include "chrome/browser/ui/browser_command_controller.h" 36 #include "chrome/browser/ui/browser_command_controller.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 73
76 #if defined(OS_MACOSX) 74 #if defined(OS_MACOSX)
77 #include "ui/base/cocoa/find_pasteboard.h" 75 #include "ui/base/cocoa/find_pasteboard.h"
78 #endif 76 #endif
79 77
80 #if defined(OS_WIN) 78 #if defined(OS_WIN)
81 #include "chrome/browser/ui/metro_pin_tab_helper_win.h" 79 #include "chrome/browser/ui/metro_pin_tab_helper_win.h"
82 #include "win8/util/win8_util.h" 80 #include "win8/util/win8_util.h"
83 #endif 81 #endif
84 82
83 #if defined(ENABLE_PRINTING)
84 #if defined(ENABLE_FULL_PRINTING)
85 #include "chrome/browser/printing/print_preview_dialog_controller.h"
86 #include "chrome/browser/printing/print_view_manager.h"
87 #else
88 #include "chrome/browser/printing/print_view_manager_basic.h"
89 #endif // defined(ENABLE_FULL_PRINTING)
90 #endif // defined(ENABLE_PRINTING)
91
85 namespace { 92 namespace {
86 const char kOsOverrideForTabletSite[] = "Linux; Android 4.0.3"; 93 const char kOsOverrideForTabletSite[] = "Linux; Android 4.0.3";
87 } 94 }
88 95
89 using content::NavigationController; 96 using content::NavigationController;
90 using content::NavigationEntry; 97 using content::NavigationEntry;
91 using content::OpenURLParams; 98 using content::OpenURLParams;
92 using content::Referrer; 99 using content::Referrer;
93 using content::SSLStatus; 100 using content::SSLStatus;
94 using content::UserMetricsAction; 101 using content::UserMetricsAction;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 browser->tab_strip_model()->GetActiveWebContents(); 187 browser->tab_strip_model()->GetActiveWebContents();
181 if (!web_contents) 188 if (!web_contents)
182 return false; 189 return false;
183 190
184 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 191 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
185 WebContentsModalDialogManager::FromWebContents(web_contents); 192 WebContentsModalDialogManager::FromWebContents(web_contents);
186 return web_contents_modal_dialog_manager->IsShowingDialog(); 193 return web_contents_modal_dialog_manager->IsShowingDialog();
187 } 194 }
188 195
189 bool PrintPreviewShowing(const Browser* browser) { 196 bool PrintPreviewShowing(const Browser* browser) {
197 #if defined(ENABLE_FULL_PRINTING)
190 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents(); 198 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents();
191 printing::PrintPreviewDialogController* controller = 199 printing::PrintPreviewDialogController* controller =
192 printing::PrintPreviewDialogController::GetInstance(); 200 printing::PrintPreviewDialogController::GetInstance();
193 return controller && (controller->GetPrintPreviewForContents(contents) || 201 return controller && (controller->GetPrintPreviewForContents(contents) ||
194 controller->is_creating_print_preview_dialog()); 202 controller->is_creating_print_preview_dialog());
203 #else
204 return false;
205 #endif
195 } 206 }
196 207
197 } // namespace 208 } // namespace
198 209
199 bool IsCommandEnabled(Browser* browser, int command) { 210 bool IsCommandEnabled(Browser* browser, int command) {
200 return browser->command_controller()->command_updater()->IsCommandEnabled( 211 return browser->command_controller()->command_updater()->IsCommandEnabled(
201 command); 212 command);
202 } 213 }
203 214
204 bool SupportsCommand(Browser* browser, int command) { 215 bool SupportsCommand(Browser* browser, int command) {
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 715
705 void ShowWebsiteSettings(Browser* browser, 716 void ShowWebsiteSettings(Browser* browser,
706 content::WebContents* web_contents, 717 content::WebContents* web_contents,
707 const GURL& url, 718 const GURL& url,
708 const SSLStatus& ssl) { 719 const SSLStatus& ssl) {
709 browser->window()->ShowWebsiteSettings( 720 browser->window()->ShowWebsiteSettings(
710 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 721 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
711 web_contents, url, ssl); 722 web_contents, url, ssl);
712 } 723 }
713 724
725
714 void Print(Browser* browser) { 726 void Print(Browser* browser) {
727 #if defined(ENABLE_PRINTING)
728 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents();
729 #if defined(ENABLE_FULL_PRINTING)
715 printing::PrintViewManager* print_view_manager = 730 printing::PrintViewManager* print_view_manager =
716 printing::PrintViewManager::FromWebContents( 731 printing::PrintViewManager::FromWebContents(contents);
717 browser->tab_strip_model()->GetActiveWebContents()); 732 if (browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled))
718 if (browser->profile()->GetPrefs()->GetBoolean(
719 prefs::kPrintPreviewDisabled))
720 print_view_manager->PrintNow(); 733 print_view_manager->PrintNow();
721 else 734 else
722 print_view_manager->PrintPreviewNow(false); 735 print_view_manager->PrintPreviewNow(false);
736 #else
737 printing::PrintViewManagerBasic* print_view_manager =
738 printing::PrintViewManagerBasic::FromWebContents(contents);
739 print_view_manager->PrintNow();
740 #endif // defined(ENABLE_FULL_PRINTING)
741 #endif // defined(ENABLE_PRINTING)
723 } 742 }
724 743
725 bool CanPrint(const Browser* browser) { 744 bool CanPrint(const Browser* browser) {
726 // Do not print when printing is disabled via pref or policy. 745 // Do not print when printing is disabled via pref or policy.
727 // Do not print when a constrained window is showing. It's confusing. 746 // Do not print when a constrained window is showing. It's confusing.
728 return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && 747 return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) &&
729 !(IsShowingWebContentsModalDialog(browser) || 748 !(IsShowingWebContentsModalDialog(browser) ||
730 GetContentRestrictions(browser) & CONTENT_RESTRICTION_PRINT); 749 GetContentRestrictions(browser) & CONTENT_RESTRICTION_PRINT);
731 } 750 }
732 751
733 void AdvancedPrint(Browser* browser) { 752 void AdvancedPrint(Browser* browser) {
753 #if defined(ENABLE_FULL_PRINTING)
734 printing::PrintViewManager* print_view_manager = 754 printing::PrintViewManager* print_view_manager =
735 printing::PrintViewManager::FromWebContents( 755 printing::PrintViewManager::FromWebContents(
736 browser->tab_strip_model()->GetActiveWebContents()); 756 browser->tab_strip_model()->GetActiveWebContents());
737 print_view_manager->AdvancedPrintNow(); 757 print_view_manager->AdvancedPrintNow();
758 #endif
738 } 759 }
739 760
740 bool CanAdvancedPrint(const Browser* browser) { 761 bool CanAdvancedPrint(const Browser* browser) {
741 // If printing is not disabled via pref or policy, it is always possible to 762 // If printing is not disabled via pref or policy, it is always possible to
742 // advanced print when the print preview is visible. 763 // advanced print when the print preview is visible.
743 return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && 764 return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) &&
744 (PrintPreviewShowing(browser) || CanPrint(browser)); 765 (PrintPreviewShowing(browser) || CanPrint(browser));
745 } 766 }
746 767
747 void PrintToDestination(Browser* browser) { 768 void PrintToDestination(Browser* browser) {
769 #if defined(ENABLE_FULL_PRINTING)
748 printing::PrintViewManager* print_view_manager = 770 printing::PrintViewManager* print_view_manager =
749 printing::PrintViewManager::FromWebContents( 771 printing::PrintViewManager::FromWebContents(
750 browser->tab_strip_model()->GetActiveWebContents()); 772 browser->tab_strip_model()->GetActiveWebContents());
751 print_view_manager->PrintToDestination(); 773 print_view_manager->PrintToDestination();
774 #endif
752 } 775 }
753 776
754 void EmailPageLocation(Browser* browser) { 777 void EmailPageLocation(Browser* browser) {
755 content::RecordAction(UserMetricsAction("EmailPageLocation")); 778 content::RecordAction(UserMetricsAction("EmailPageLocation"));
756 WebContents* wc = browser->tab_strip_model()->GetActiveWebContents(); 779 WebContents* wc = browser->tab_strip_model()->GetActiveWebContents();
757 DCHECK(wc); 780 DCHECK(wc);
758 781
759 std::string title = net::EscapeQueryParamValue( 782 std::string title = net::EscapeQueryParamValue(
760 UTF16ToUTF8(wc->GetTitle()), false); 783 UTF16ToUTF8(wc->GetTitle()), false);
761 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); 784 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(), 1120 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile(),
1098 browser->host_desktop_type())); 1121 browser->host_desktop_type()));
1099 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1122 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1100 1123
1101 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1124 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1102 contents->GetRenderViewHost()->SyncRendererPrefs(); 1125 contents->GetRenderViewHost()->SyncRendererPrefs();
1103 app_browser->window()->Show(); 1126 app_browser->window()->Show();
1104 } 1127 }
1105 1128
1106 } // namespace chrome 1129 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/apps/chrome_shell_window_delegate.cc ('k') | chrome/browser/ui/browser_tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698