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" |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 : ConstrainedWebDialogUI(web_ui), | 441 : ConstrainedWebDialogUI(web_ui), |
438 initial_preview_start_time_(base::TimeTicks::Now()), | 442 initial_preview_start_time_(base::TimeTicks::Now()), |
439 id_(g_print_preview_ui_id_map.Get().Add(this)), | 443 id_(g_print_preview_ui_id_map.Get().Add(this)), |
440 handler_(nullptr), | 444 handler_(nullptr), |
441 source_is_modifiable_(true), | 445 source_is_modifiable_(true), |
442 source_has_selection_(false), | 446 source_has_selection_(false), |
443 print_selection_only_(false), | 447 print_selection_only_(false), |
444 dialog_closed_(false) { | 448 dialog_closed_(false) { |
445 // Set up the chrome://print/ data source. | 449 // Set up the chrome://print/ data source. |
446 Profile* profile = Profile::FromWebUI(web_ui); | 450 Profile* profile = Profile::FromWebUI(web_ui); |
447 content::WebUIDataSource::Add(profile, CreatePrintPreviewUISource()); | 451 content::WebUIDataSource* data_source = CreatePrintPreviewUISource(); |
452 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | |
453 bool use_system_default_printer = | |
454 profile->GetPrefs()->GetBoolean( | |
455 prefs::kUseSystemDefaultPrinterAsDefault) || | |
456 cmdline->HasSwitch(switches::kUseSystemDefaultPrinter); | |
457 data_source->AddBoolean("useSystemDefaultPrinter", | |
Lei Zhang
2017/06/15 18:29:34
Can we do this in CreatePrintPreviewUISource()? Lo
rbpotter
2017/06/16 02:21:46
Done.
| |
458 use_system_default_printer); | |
459 content::WebUIDataSource::Add(profile, data_source); | |
448 | 460 |
449 // Set up the chrome://theme/ source. | 461 // Set up the chrome://theme/ source. |
450 content::URLDataSource::Add(profile, new ThemeSource(profile)); | 462 content::URLDataSource::Add(profile, new ThemeSource(profile)); |
451 | 463 |
452 auto handler = base::MakeUnique<PrintPreviewHandler>(); | 464 auto handler = base::MakeUnique<PrintPreviewHandler>(); |
453 handler_ = handler.get(); | 465 handler_ = handler.get(); |
454 web_ui->AddMessageHandler(std::move(handler)); | 466 web_ui->AddMessageHandler(std::move(handler)); |
455 web_ui->AddMessageHandler(base::MakeUnique<MetricsHandler>()); | 467 web_ui->AddMessageHandler(base::MakeUnique<MetricsHandler>()); |
456 | 468 |
457 g_print_preview_request_id_map.Get().Set(id_, -1); | 469 g_print_preview_request_id_map.Get().Set(id_, -1); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 } | 700 } |
689 | 701 |
690 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { | 702 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { |
691 handler_->FileSelected(path, 0, NULL); | 703 handler_->FileSelected(path, 0, NULL); |
692 } | 704 } |
693 | 705 |
694 void PrintPreviewUI::SetPdfSavedClosureForTesting( | 706 void PrintPreviewUI::SetPdfSavedClosureForTesting( |
695 const base::Closure& closure) { | 707 const base::Closure& closure) { |
696 handler_->SetPdfSavedClosureForTesting(closure); | 708 handler_->SetPdfSavedClosureForTesting(closure); |
697 } | 709 } |
OLD | NEW |