| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/webui/print_preview/print_preview_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" |
| 11 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 12 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted_memory.h" | 17 #include "base/memory/ref_counted_memory.h" |
| 17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 24 #include "base/values.h" | 25 #include "base/values.h" |
| 25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 26 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/printing/background_printing_manager.h" | 28 #include "chrome/browser/printing/background_printing_manager.h" |
| 28 #include "chrome/browser/printing/print_preview_data_service.h" | 29 #include "chrome/browser/printing/print_preview_data_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/webui/metrics_handler.h" | 31 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 31 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 32 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 32 #include "chrome/browser/ui/webui/theme_source.h" | 33 #include "chrome/browser/ui/webui/theme_source.h" |
| 33 #include "chrome/common/chrome_features.h" | 34 #include "chrome/common/chrome_features.h" |
| 35 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 35 #include "chrome/grit/browser_resources.h" | 38 #include "chrome/grit/browser_resources.h" |
| 36 #include "chrome/grit/chromium_strings.h" | 39 #include "chrome/grit/chromium_strings.h" |
| 37 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
| 41 #include "components/prefs/pref_service.h" |
| 38 #include "components/printing/common/print_messages.h" | 42 #include "components/printing/common/print_messages.h" |
| 39 #include "components/strings/grit/components_strings.h" | 43 #include "components/strings/grit/components_strings.h" |
| 40 #include "content/public/browser/url_data_source.h" | 44 #include "content/public/browser/url_data_source.h" |
| 41 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/browser/web_ui_data_source.h" | 46 #include "content/public/browser/web_ui_data_source.h" |
| 43 #include "extensions/common/constants.h" | 47 #include "extensions/common/constants.h" |
| 44 #include "printing/features/features.h" | 48 #include "printing/features/features.h" |
| 45 #include "printing/page_size_margins.h" | 49 #include "printing/page_size_margins.h" |
| 46 #include "printing/print_job_constants.h" | 50 #include "printing/print_job_constants.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "ui/gfx/geometry/rect.h" | 52 #include "ui/gfx/geometry/rect.h" |
| 49 #include "ui/web_dialogs/web_dialog_delegate.h" | 53 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 50 #include "ui/web_dialogs/web_dialog_ui.h" | 54 #include "ui/web_dialogs/web_dialog_ui.h" |
| 51 | 55 |
| 52 #if defined(OS_CHROMEOS) | |
| 53 #include "base/command_line.h" | |
| 54 #include "chrome/common/chrome_switches.h" | |
| 55 #endif | |
| 56 | |
| 57 using content::WebContents; | 56 using content::WebContents; |
| 58 using printing::PageSizeMargins; | 57 using printing::PageSizeMargins; |
| 59 | 58 |
| 60 namespace { | 59 namespace { |
| 61 | 60 |
| 62 #if defined(OS_MACOSX) | 61 #if defined(OS_MACOSX) |
| 63 // U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8 | 62 // U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8 |
| 64 const char kBasicPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29"; | 63 const char kBasicPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29"; |
| 65 #elif !defined(OS_CHROMEOS) | 64 #elif !defined(OS_CHROMEOS) |
| 66 const char kBasicPrintShortcut[] = "(Ctrl+Shift+P)"; | 65 const char kBasicPrintShortcut[] = "(Ctrl+Shift+P)"; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (data.get()) { | 157 if (data.get()) { |
| 159 callback.Run(data.get()); | 158 callback.Run(data.get()); |
| 160 return true; | 159 return true; |
| 161 } | 160 } |
| 162 // Invalid request. | 161 // Invalid request. |
| 163 scoped_refptr<base::RefCountedBytes> empty_bytes(new base::RefCountedBytes); | 162 scoped_refptr<base::RefCountedBytes> empty_bytes(new base::RefCountedBytes); |
| 164 callback.Run(empty_bytes.get()); | 163 callback.Run(empty_bytes.get()); |
| 165 return true; | 164 return true; |
| 166 } | 165 } |
| 167 | 166 |
| 168 content::WebUIDataSource* CreatePrintPreviewUISource() { | 167 content::WebUIDataSource* CreatePrintPreviewUISource(Profile* profile) { |
| 169 content::WebUIDataSource* source = | 168 content::WebUIDataSource* source = |
| 170 content::WebUIDataSource::Create(chrome::kChromeUIPrintHost); | 169 content::WebUIDataSource::Create(chrome::kChromeUIPrintHost); |
| 171 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
| 172 source->AddLocalizedString("title", | 171 source->AddLocalizedString("title", |
| 173 IDS_PRINT_PREVIEW_GOOGLE_CLOUD_PRINT_TITLE); | 172 IDS_PRINT_PREVIEW_GOOGLE_CLOUD_PRINT_TITLE); |
| 174 #else | 173 #else |
| 175 source->AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE); | 174 source->AddLocalizedString("title", IDS_PRINT_PREVIEW_TITLE); |
| 176 #endif | 175 #endif |
| 177 source->AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING); | 176 source->AddLocalizedString("loading", IDS_PRINT_PREVIEW_LOADING); |
| 178 source->AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN); | 177 source->AddLocalizedString("noPlugin", IDS_PRINT_PREVIEW_NO_PLUGIN); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 features::kPrintPdfAsImage); | 417 features::kPrintPdfAsImage); |
| 419 source->AddBoolean("printPdfAsImageEnabled", print_pdf_as_image_enabled); | 418 source->AddBoolean("printPdfAsImageEnabled", print_pdf_as_image_enabled); |
| 420 #else | 419 #else |
| 421 source->AddBoolean("printPdfAsImageEnabled", false); | 420 source->AddBoolean("printPdfAsImageEnabled", false); |
| 422 #endif | 421 #endif |
| 423 #if defined(OS_CHROMEOS) | 422 #if defined(OS_CHROMEOS) |
| 424 bool cups_and_md_settings_enabled = | 423 bool cups_and_md_settings_enabled = |
| 425 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 424 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 426 ::switches::kDisableNativeCups); | 425 ::switches::kDisableNativeCups); |
| 427 source->AddBoolean("showLocalManageButton", cups_and_md_settings_enabled); | 426 source->AddBoolean("showLocalManageButton", cups_and_md_settings_enabled); |
| 427 source->AddBoolean("useSystemDefaultPrinter", false); |
| 428 #else | 428 #else |
| 429 source->AddBoolean("showLocalManageButton", true); | 429 source->AddBoolean("showLocalManageButton", true); |
| 430 bool system_default_printer = profile->GetPrefs()->GetBoolean( |
| 431 prefs::kPrintPreviewUseSystemDefaultPrinter); |
| 432 source->AddBoolean("useSystemDefaultPrinter", system_default_printer); |
| 430 #endif | 433 #endif |
| 431 return source; | 434 return source; |
| 432 } | 435 } |
| 433 | 436 |
| 434 } // namespace | 437 } // namespace |
| 435 | 438 |
| 436 PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) | 439 PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) |
| 437 : ConstrainedWebDialogUI(web_ui), | 440 : ConstrainedWebDialogUI(web_ui), |
| 438 initial_preview_start_time_(base::TimeTicks::Now()), | 441 initial_preview_start_time_(base::TimeTicks::Now()), |
| 439 id_(g_print_preview_ui_id_map.Get().Add(this)), | 442 id_(g_print_preview_ui_id_map.Get().Add(this)), |
| 440 handler_(nullptr), | 443 handler_(nullptr), |
| 441 source_is_modifiable_(true), | 444 source_is_modifiable_(true), |
| 442 source_has_selection_(false), | 445 source_has_selection_(false), |
| 443 print_selection_only_(false), | 446 print_selection_only_(false), |
| 444 dialog_closed_(false) { | 447 dialog_closed_(false) { |
| 445 // Set up the chrome://print/ data source. | 448 // Set up the chrome://print/ data source. |
| 446 Profile* profile = Profile::FromWebUI(web_ui); | 449 Profile* profile = Profile::FromWebUI(web_ui); |
| 447 content::WebUIDataSource::Add(profile, CreatePrintPreviewUISource()); | 450 content::WebUIDataSource::Add(profile, CreatePrintPreviewUISource(profile)); |
| 448 | 451 |
| 449 // Set up the chrome://theme/ source. | 452 // Set up the chrome://theme/ source. |
| 450 content::URLDataSource::Add(profile, new ThemeSource(profile)); | 453 content::URLDataSource::Add(profile, new ThemeSource(profile)); |
| 451 | 454 |
| 452 auto handler = base::MakeUnique<PrintPreviewHandler>(); | 455 auto handler = base::MakeUnique<PrintPreviewHandler>(); |
| 453 handler_ = handler.get(); | 456 handler_ = handler.get(); |
| 454 web_ui->AddMessageHandler(std::move(handler)); | 457 web_ui->AddMessageHandler(std::move(handler)); |
| 455 web_ui->AddMessageHandler(base::MakeUnique<MetricsHandler>()); | 458 web_ui->AddMessageHandler(base::MakeUnique<MetricsHandler>()); |
| 456 | 459 |
| 457 g_print_preview_request_id_map.Get().Set(id_, -1); | 460 g_print_preview_request_id_map.Get().Set(id_, -1); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 } | 691 } |
| 689 | 692 |
| 690 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { | 693 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { |
| 691 handler_->FileSelected(path, 0, NULL); | 694 handler_->FileSelected(path, 0, NULL); |
| 692 } | 695 } |
| 693 | 696 |
| 694 void PrintPreviewUI::SetPdfSavedClosureForTesting( | 697 void PrintPreviewUI::SetPdfSavedClosureForTesting( |
| 695 const base::Closure& closure) { | 698 const base::Closure& closure) { |
| 696 handler_->SetPdfSavedClosureForTesting(closure); | 699 handler_->SetPdfSavedClosureForTesting(closure); |
| 697 } | 700 } |
| OLD | NEW |