diff options
author | Vitaly Buka <vitalybuka@chromium.org> | 2014-08-26 01:57:54 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@chromium.org> | 2014-08-26 09:00:31 +0000 |
commit | bd7c981343caf492e552ae6c9498a15bbc38f1c7 (patch) | |
tree | db09e4d4292f5ca88788635fe0e1f1439f4d9106 /printing | |
parent | 4d18cc81f71b4edf191e359526224080e275d65e (diff) | |
download | chromium_src-bd7c981343caf492e552ae6c9498a15bbc38f1c7.zip chromium_src-bd7c981343caf492e552ae6c9498a15bbc38f1c7.tar.gz chromium_src-bd7c981343caf492e552ae6c9498a15bbc38f1c7.tar.bz2 |
Added PrintingContext::Delegate to get parent view handle and application locale.
BUG=374321
Committed: https://chromium.googlesource.com/chromium/src/+/ee8f4e4029c09ba77e7dbb8fddd85186642b3de8
R=jschuh@chromium.org, noamsml@chromium.org, thestig@chromium.org, yzshen@chromium.org
Review URL: https://codereview.chromium.org/478183005
Cr-Commit-Position: refs/heads/master@{#291871}
Diffstat (limited to 'printing')
-rw-r--r-- | printing/emf_win_unittest.cc | 12 | ||||
-rw-r--r-- | printing/print_job_constants.cc | 6 | ||||
-rw-r--r-- | printing/print_job_constants.h | 2 | ||||
-rw-r--r-- | printing/printing_context.cc | 9 | ||||
-rw-r--r-- | printing/printing_context.h | 29 | ||||
-rw-r--r-- | printing/printing_context_android.cc | 12 | ||||
-rw-r--r-- | printing/printing_context_android.h | 3 | ||||
-rw-r--r-- | printing/printing_context_linux.cc | 13 | ||||
-rw-r--r-- | printing/printing_context_linux.h | 3 | ||||
-rw-r--r-- | printing/printing_context_mac.h | 3 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 10 | ||||
-rw-r--r-- | printing/printing_context_no_system_dialog.cc | 14 | ||||
-rw-r--r-- | printing/printing_context_no_system_dialog.h | 3 | ||||
-rw-r--r-- | printing/printing_context_win.cc | 14 | ||||
-rw-r--r-- | printing/printing_context_win.h | 5 | ||||
-rw-r--r-- | printing/printing_context_win_unittest.cc | 19 |
16 files changed, 92 insertions, 65 deletions
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc index 8a5daaf..ec65c28 100644 --- a/printing/emf_win_unittest.cc +++ b/printing/emf_win_unittest.cc @@ -22,11 +22,13 @@ #include "ui/gfx/point.h" #include "ui/gfx/size.h" +namespace printing { + namespace { // This test is automatically disabled if no printer named "UnitTest Printer" is // available. -class EmfPrintingTest : public testing::Test { +class EmfPrintingTest : public testing::Test, public PrintingContext::Delegate { public: typedef testing::Test Parent; static bool IsTestCaseDisabled() { @@ -37,14 +39,16 @@ class EmfPrintingTest : public testing::Test { DeleteDC(hdc); return false; } + + // PrintingContext::Delegate methods. + virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; } + virtual std::string GetAppLocale() OVERRIDE { return std::string(); } }; const uint32 EMF_HEADER_SIZE = 128; } // namespace -namespace printing { - TEST(EmfTest, DC) { // Simplest use case. uint32 size; @@ -83,7 +87,7 @@ TEST_F(EmfPrintingTest, Enumerate) { settings.set_device_name(L"UnitTest Printer"); // Initialize it. - scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); + scoped_ptr<PrintingContext> context(PrintingContext::Create(this)); EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); base::FilePath emf_file; diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc index 8ac5db4..6ac461c 100644 --- a/printing/print_job_constants.cc +++ b/printing/print_job_constants.cc @@ -12,6 +12,12 @@ const char kIsFirstRequest[] = "isFirstRequest"; // Unique ID sent along every preview request. const char kPreviewRequestID[] = "requestID"; +// Unique ID of Print Preview initiator host. +const char kPreviewInitiatorHostId[] = "previewInitiatorHostId"; + +// Routing ID of Print Preview initiator. +const char kPreviewInitiatorRoutingId[] = "previewInitiatorRoutingId"; + // Unique ID to identify a print preview UI. const char kPreviewUIID[] = "previewUIID"; diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h index 257cba6..646191b 100644 --- a/printing/print_job_constants.h +++ b/printing/print_job_constants.h @@ -12,6 +12,8 @@ namespace printing { PRINTING_EXPORT extern const char kIsFirstRequest[]; PRINTING_EXPORT extern const char kPreviewRequestID[]; +PRINTING_EXPORT extern const char kPreviewInitiatorHostId[]; +PRINTING_EXPORT extern const char kPreviewInitiatorRoutingId[]; PRINTING_EXPORT extern const char kPreviewUIID[]; PRINTING_EXPORT extern const char kSettingCapabilities[]; PRINTING_EXPORT extern const char kSettingCloudPrintId[]; diff --git a/printing/printing_context.cc b/printing/printing_context.cc index c7f22a5..d2b1e68 100644 --- a/printing/printing_context.cc +++ b/printing/printing_context.cc @@ -18,11 +18,12 @@ namespace { const float kCloudPrintMarginInch = 0.25; } -PrintingContext::PrintingContext(const std::string& app_locale) - : dialog_box_dismissed_(false), +PrintingContext::PrintingContext(Delegate* delegate) + : delegate_(delegate), + dialog_box_dismissed_(false), in_print_job_(false), - abort_printing_(false), - app_locale_(app_locale) { + abort_printing_(false) { + CHECK(delegate_); } PrintingContext::~PrintingContext() { diff --git a/printing/printing_context.h b/printing/printing_context.h index 823a5af..875c070 100644 --- a/printing/printing_context.h +++ b/printing/printing_context.h @@ -25,6 +25,19 @@ namespace printing { // printer and manage the document and page breaks. class PRINTING_EXPORT PrintingContext { public: + // Printing context delegate. + class Delegate { + public: + Delegate() {}; + virtual ~Delegate() {}; + + // Returns parent view to use for modal dialogs. + virtual gfx::NativeView GetParentView() = 0; + + // Returns application locale. + virtual std::string GetAppLocale() = 0; + }; + // Tri-state result for user behavior-dependent functions. enum Result { OK, @@ -42,8 +55,7 @@ class PRINTING_EXPORT PrintingContext { // context with the select device settings. The result of the call is returned // in the callback. This is necessary for Linux, which only has an // asynchronous printing API. - virtual void AskUserForSettings(gfx::NativeView parent_view, - int max_pages, + virtual void AskUserForSettings(int max_pages, bool has_selection, const PrintSettingsCallback& callback) = 0; @@ -98,9 +110,8 @@ class PRINTING_EXPORT PrintingContext { virtual gfx::NativeDrawingContext context() const = 0; // Creates an instance of this object. Implementers of this interface should - // implement this method to create an object of their implementation. The - // caller owns the returned object. - static PrintingContext* Create(const std::string& app_locale); + // implement this method to create an object of their implementation. + static scoped_ptr<PrintingContext> Create(Delegate* delegate); void set_margin_type(MarginType type); @@ -109,7 +120,7 @@ class PRINTING_EXPORT PrintingContext { } protected: - explicit PrintingContext(const std::string& app_locale); + explicit PrintingContext(Delegate* delegate); // Reinitializes the settings for object reuse. void ResetSettings(); @@ -120,6 +131,9 @@ class PRINTING_EXPORT PrintingContext { // Complete print context settings. PrintSettings settings_; + // Printing context delegate. + Delegate* delegate_; + // The dialog box has been dismissed. volatile bool dialog_box_dismissed_; @@ -129,9 +143,6 @@ class PRINTING_EXPORT PrintingContext { // Did the user cancel the print job. volatile bool abort_printing_; - // The application locale. - std::string app_locale_; - private: DISALLOW_COPY_AND_ASSIGN(PrintingContext); }; diff --git a/printing/printing_context_android.cc b/printing/printing_context_android.cc index 5729267..39f1c6d 100644 --- a/printing/printing_context_android.cc +++ b/printing/printing_context_android.cc @@ -61,8 +61,8 @@ void GetPageRanges(JNIEnv* env, namespace printing { // static -PrintingContext* PrintingContext::Create(const std::string& app_locale) { - return new PrintingContextAndroid(app_locale); +scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { + return make_scoped_ptr<PrintingContext>(new PrintingContextAndroid(delegate)); } // static @@ -71,8 +71,8 @@ void PrintingContextAndroid::PdfWritingDone(int fd, bool success) { Java_PrintingContext_pdfWritingDone(env, fd, success); } -PrintingContextAndroid::PrintingContextAndroid(const std::string& app_locale) - : PrintingContext(app_locale) { +PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate) + : PrintingContext(delegate) { // The constructor is run in the IO thread. } @@ -80,7 +80,6 @@ PrintingContextAndroid::~PrintingContextAndroid() { } void PrintingContextAndroid::AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) { @@ -149,7 +148,8 @@ gfx::Size PrintingContextAndroid::GetPdfPaperSizeDeviceUnits() { int32_t width = 0; int32_t height = 0; UErrorCode error = U_ZERO_ERROR; - ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); + ulocdata_getPaperSize( + delegate_->GetAppLocale().c_str(), &height, &width, &error); if (error > U_ZERO_ERROR) { // If the call failed, assume a paper size of 8.5 x 11 inches. LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " diff --git a/printing/printing_context_android.h b/printing/printing_context_android.h index b198e7b..56068a1 100644 --- a/printing/printing_context_android.h +++ b/printing/printing_context_android.h @@ -19,7 +19,7 @@ namespace printing { // Java side through JNI. class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext { public: - explicit PrintingContextAndroid(const std::string& app_locale); + explicit PrintingContextAndroid(Delegate* delegate); virtual ~PrintingContextAndroid(); // Called when the page is successfully written to a PDF using the file @@ -32,7 +32,6 @@ class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext { // PrintingContext implementation. virtual void AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) OVERRIDE; diff --git a/printing/printing_context_linux.cc b/printing/printing_context_linux.cc index 3b6d2ee..c267478 100644 --- a/printing/printing_context_linux.cc +++ b/printing/printing_context_linux.cc @@ -27,13 +27,12 @@ gfx::Size (*get_pdf_paper_size_)( namespace printing { // static -PrintingContext* PrintingContext::Create(const std::string& app_locale) { - return static_cast<PrintingContext*>(new PrintingContextLinux(app_locale)); +scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { + return make_scoped_ptr<PrintingContext>(new PrintingContextLinux(delegate)); } -PrintingContextLinux::PrintingContextLinux(const std::string& app_locale) - : PrintingContext(app_locale), - print_dialog_(NULL) { +PrintingContextLinux::PrintingContextLinux(Delegate* delegate) + : PrintingContext(delegate), print_dialog_(NULL) { } PrintingContextLinux::~PrintingContextLinux() { @@ -67,7 +66,6 @@ void PrintingContextLinux::PrintDocument(const Metafile* metafile) { } void PrintingContextLinux::AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) { @@ -79,7 +77,8 @@ void PrintingContextLinux::AskUserForSettings( return; } - print_dialog_->ShowDialog(parent_view, has_selection, callback); + print_dialog_->ShowDialog( + delegate_->GetParentView(), has_selection, callback); } PrintingContext::Result PrintingContextLinux::UseDefaultSettings() { diff --git a/printing/printing_context_linux.h b/printing/printing_context_linux.h index 3076014..984d7dc 100644 --- a/printing/printing_context_linux.h +++ b/printing/printing_context_linux.h @@ -21,7 +21,7 @@ class PrintDialogGtkInterface; // PrintingContext with optional native UI for print dialog and pdf_paper_size. class PRINTING_EXPORT PrintingContextLinux : public PrintingContext { public: - explicit PrintingContextLinux(const std::string& app_locale); + explicit PrintingContextLinux(Delegate* delegate); virtual ~PrintingContextLinux(); // Sets the function that creates the print dialog. @@ -38,7 +38,6 @@ class PRINTING_EXPORT PrintingContextLinux : public PrintingContext { // PrintingContext implementation. virtual void AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) OVERRIDE; diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h index f16ef54..9eb924a 100644 --- a/printing/printing_context_mac.h +++ b/printing/printing_context_mac.h @@ -21,12 +21,11 @@ namespace printing { class PRINTING_EXPORT PrintingContextMac : public PrintingContext { public: - explicit PrintingContextMac(const std::string& app_locale); + explicit PrintingContextMac(Delegate* delegate); virtual ~PrintingContextMac(); // PrintingContext implementation. virtual void AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) OVERRIDE; diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index 9bbe5ac1..fa907b5 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -68,12 +68,12 @@ PMPaper MatchPaper(CFArrayRef paper_list, } // namespace // static -PrintingContext* PrintingContext::Create(const std::string& app_locale) { - return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); +scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { + return make_scoped_ptr<PrintingContext>(new PrintingContextMac(delegate)); } -PrintingContextMac::PrintingContextMac(const std::string& app_locale) - : PrintingContext(app_locale), +PrintingContextMac::PrintingContextMac(Delegate* delegate) + : PrintingContext(delegate), print_info_([[NSPrintInfo sharedPrintInfo] copy]), context_(NULL) { } @@ -83,7 +83,6 @@ PrintingContextMac::~PrintingContextMac() { } void PrintingContextMac::AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) { @@ -115,6 +114,7 @@ void PrintingContextMac::AskUserForSettings( [panel setOptions:options]; // Set the print job title text. + gfx::NativeView parent_view = delegate_->GetParentView(); if (parent_view) { NSString* job_title = [[parent_view window] title]; if (job_title) { diff --git a/printing/printing_context_no_system_dialog.cc b/printing/printing_context_no_system_dialog.cc index 4768e4d..fd6e166 100644 --- a/printing/printing_context_no_system_dialog.cc +++ b/printing/printing_context_no_system_dialog.cc @@ -15,13 +15,13 @@ namespace printing { // static -PrintingContext* PrintingContext::Create(const std::string& app_locale) { - return static_cast<PrintingContext*>( - new PrintingContextNoSystemDialog(app_locale)); +scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { + return make_scoped_ptr<PrintingContext>( + new PrintingContextNoSystemDialog(delegate)); } -PrintingContextNoSystemDialog::PrintingContextNoSystemDialog( - const std::string& app_locale) : PrintingContext(app_locale) { +PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate) + : PrintingContext(delegate) { } PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() { @@ -29,7 +29,6 @@ PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() { } void PrintingContextNoSystemDialog::AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) { @@ -54,7 +53,8 @@ gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() { int32_t width = 0; int32_t height = 0; UErrorCode error = U_ZERO_ERROR; - ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); + ulocdata_getPaperSize( + delegate_->GetAppLocale().c_str(), &height, &width, &error); if (error > U_ZERO_ERROR) { // If the call failed, assume a paper size of 8.5 x 11 inches. LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " diff --git a/printing/printing_context_no_system_dialog.h b/printing/printing_context_no_system_dialog.h index 5472a81..fbc69aa 100644 --- a/printing/printing_context_no_system_dialog.h +++ b/printing/printing_context_no_system_dialog.h @@ -17,12 +17,11 @@ namespace printing { class PRINTING_EXPORT PrintingContextNoSystemDialog : public PrintingContext { public: - explicit PrintingContextNoSystemDialog(const std::string& app_locale); + explicit PrintingContextNoSystemDialog(Delegate* delegate); virtual ~PrintingContextNoSystemDialog(); // PrintingContext implementation. virtual void AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) OVERRIDE; diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index b0a9644..dd0e2c4 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -45,24 +45,26 @@ HWND GetRootWindow(gfx::NativeView view) { namespace printing { // static -PrintingContext* PrintingContext::Create(const std::string& app_locale) { - return static_cast<PrintingContext*>(new PrintingContextWin(app_locale)); +scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { + return make_scoped_ptr<PrintingContext>(new PrintingContextWin(delegate)); } -PrintingContextWin::PrintingContextWin(const std::string& app_locale) - : PrintingContext(app_locale), context_(NULL), dialog_box_(NULL) {} +PrintingContextWin::PrintingContextWin(Delegate* delegate) + : PrintingContext(delegate), context_(NULL), dialog_box_(NULL) { +} PrintingContextWin::~PrintingContextWin() { ReleaseContext(); } void PrintingContextWin::AskUserForSettings( - gfx::NativeView view, int max_pages, bool has_selection, + int max_pages, + bool has_selection, const PrintSettingsCallback& callback) { DCHECK(!in_print_job_); dialog_box_dismissed_ = false; - HWND window = GetRootWindow(view); + HWND window = GetRootWindow(delegate_->GetParentView()); DCHECK(window); // Show the OS-dependent dialog box. diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h index 6c1e420..94fd041 100644 --- a/printing/printing_context_win.h +++ b/printing/printing_context_win.h @@ -19,12 +19,11 @@ namespace printing { class PRINTING_EXPORT PrintingContextWin : public PrintingContext { public: - explicit PrintingContextWin(const std::string& app_locale); - ~PrintingContextWin(); + explicit PrintingContextWin(Delegate* delegate); + virtual ~PrintingContextWin(); // PrintingContext implementation. virtual void AskUserForSettings( - gfx::NativeView parent_view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) OVERRIDE; diff --git a/printing/printing_context_win_unittest.cc b/printing/printing_context_win_unittest.cc index c9facc9..1d27935 100644 --- a/printing/printing_context_win_unittest.cc +++ b/printing/printing_context_win_unittest.cc @@ -22,12 +22,17 @@ namespace printing { // This test is automatically disabled if no printer is available. -class PrintingContextTest : public PrintingTest<testing::Test> { +class PrintingContextTest : public PrintingTest<testing::Test>, + public PrintingContext::Delegate { public: void PrintSettingsCallback(PrintingContext::Result result) { result_ = result; } + // PrintingContext::Delegate methods. + virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; } + virtual std::string GetAppLocale() OVERRIDE { return std::string(); } + protected: PrintingContext::Result result() const { return result_; } @@ -37,7 +42,7 @@ class PrintingContextTest : public PrintingTest<testing::Test> { class MockPrintingContextWin : public PrintingContextWin { public: - MockPrintingContextWin() : PrintingContextWin("") {} + MockPrintingContextWin(Delegate* delegate) : PrintingContextWin(delegate) {} protected: // This is a fake PrintDlgEx implementation that sets the right fields in @@ -159,7 +164,7 @@ TEST_F(PrintingContextTest, Base) { PrintSettings settings; settings.set_device_name(GetDefaultPrinter()); // Initialize it. - scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); + scoped_ptr<PrintingContext> context(PrintingContext::Create(this)); EXPECT_EQ(PrintingContext::OK, context->InitWithSettings(settings)); // The print may lie to use and may not support world transformation. @@ -174,10 +179,12 @@ TEST_F(PrintingContextTest, PrintAll) { if (IsTestCaseDisabled()) return; - MockPrintingContextWin context; + MockPrintingContextWin context(this); context.AskUserForSettings( - NULL, 123, false, base::Bind(&PrintingContextTest::PrintSettingsCallback, - base::Unretained(this))); + 123, + false, + base::Bind(&PrintingContextTest::PrintSettingsCallback, + base::Unretained(this))); EXPECT_EQ(PrintingContext::OK, result()); PrintSettings settings = context.settings(); EXPECT_EQ(settings.ranges().size(), 0); |