diff options
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/cloud_print/DEPS | 1 | ||||
-rw-r--r-- | chrome/service/cloud_print/cdd_conversion_win.cc | 113 | ||||
-rw-r--r-- | chrome/service/cloud_print/cdd_conversion_win.h | 21 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_connector.cc | 4 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 44 | ||||
-rw-r--r-- | chrome/service/cloud_print/printer_job_handler.cc | 4 |
6 files changed, 184 insertions, 3 deletions
diff --git a/chrome/service/cloud_print/DEPS b/chrome/service/cloud_print/DEPS index 52393c8..eede8f5 100644 --- a/chrome/service/cloud_print/DEPS +++ b/chrome/service/cloud_print/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+components/cloud_devices", # sync notifier depends on the common jingle notifier classes. "+jingle/notifier", ] diff --git a/chrome/service/cloud_print/cdd_conversion_win.cc b/chrome/service/cloud_print/cdd_conversion_win.cc new file mode 100644 index 0000000..2c7a9a4 --- /dev/null +++ b/chrome/service/cloud_print/cdd_conversion_win.cc @@ -0,0 +1,113 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/service/cloud_print/cdd_conversion_win.h" + +#include "components/cloud_devices/printer_description.h" +#include "printing/backend/print_backend.h" +#include "printing/backend/win_helper.h" + +namespace cloud_print { + +std::string CapabilitiesToCdd( + const printing::PrinterSemanticCapsAndDefaults& semantic_info) { + using namespace cloud_devices::printer; + cloud_devices::CloudDeviceDescription description; + + ContentTypesCapability content_types; + content_types.AddOption("application/pdf"); + content_types.SaveTo(&description); + + ColorCapability color; + if (semantic_info.color_default || semantic_info.color_changeable) { + color.AddDefaultOption(Color(STANDARD_COLOR), semantic_info.color_default); + } + + if (!semantic_info.color_default || semantic_info.color_changeable) { + color.AddDefaultOption(Color(STANDARD_MONOCHROME), + !semantic_info.color_default); + } + color.SaveTo(&description); + + if (semantic_info.duplex_capable) { + DuplexCapability duplex; + duplex.AddDefaultOption( + NO_DUPLEX, semantic_info.duplex_default == printing::SIMPLEX); + duplex.AddDefaultOption( + LONG_EDGE, semantic_info.duplex_default == printing::LONG_EDGE); + duplex.AddDefaultOption( + SHORT_EDGE, semantic_info.duplex_default == printing::SHORT_EDGE); + duplex.SaveTo(&description); + } + + if (!semantic_info.papers.empty()) { + Media default_media(semantic_info.default_paper.name, + semantic_info.default_paper.size_um.width(), + semantic_info.default_paper.size_um.height()); + default_media.MatchBySize(); + + MediaCapability media; + bool is_default_set = false; + for (size_t i = 0; i < semantic_info.papers.size(); ++i) { + gfx::Size paper_size = semantic_info.papers[i].size_um; + if (paper_size.width() > paper_size.height()) + paper_size.SetSize(paper_size.height(), paper_size.width()); + Media new_media(semantic_info.papers[i].name, paper_size.width(), + paper_size.height()); + new_media.MatchBySize(); + if (new_media.IsValid() && !media.Contains(new_media)) { + if (!default_media.IsValid()) + default_media = new_media; + media.AddDefaultOption(new_media, new_media == default_media); + is_default_set = is_default_set || (new_media == default_media); + } + } + if (!is_default_set && default_media.IsValid()) + media.AddDefaultOption(default_media, true); + + if (media.IsValid()) { + media.SaveTo(&description); + } else { + NOTREACHED(); + } + } + + if (semantic_info.collate_capable) { + CollateCapability collate; + collate.set_default_value(semantic_info.collate_default); + collate.SaveTo(&description); + } + + if (semantic_info.copies_capable) { + CopiesCapability copies; + copies.SaveTo(&description); + } + + if (!semantic_info.dpis.empty()) { + DpiCapability dpi; + Dpi default_dpi(semantic_info.default_dpi.width(), + semantic_info.default_dpi.height()); + bool is_default_set = false; + for (size_t i = 0; i < semantic_info.dpis.size(); ++i) { + Dpi new_dpi(semantic_info.dpis[i].width(), + semantic_info.dpis[i].height()); + if (new_dpi.IsValid() && !dpi.Contains(new_dpi)) { + if (!default_dpi.IsValid()) + default_dpi = new_dpi; + dpi.AddDefaultOption(new_dpi, new_dpi == default_dpi); + is_default_set = is_default_set || (new_dpi == default_dpi); + } + } + if (!is_default_set && default_dpi.IsValid()) + dpi.AddDefaultOption(default_dpi, true); + if (dpi.IsValid()) { + dpi.SaveTo(&description); + } else { + NOTREACHED(); + } + } + return description.ToString(); +} + +} // namespace cloud_print diff --git a/chrome/service/cloud_print/cdd_conversion_win.h b/chrome/service/cloud_print/cdd_conversion_win.h new file mode 100644 index 0000000..0855922 --- /dev/null +++ b/chrome/service/cloud_print/cdd_conversion_win.h @@ -0,0 +1,21 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_SERVICE_CLOUD_PRINT_CDD_CONVERSION_WIN_H_ +#define CHROME_SERVICE_CLOUD_PRINT_CDD_CONVERSION_WIN_H_ + +#include <string> + +namespace printing { +struct PrinterSemanticCapsAndDefaults; +} + +namespace cloud_print { + +std::string CapabilitiesToCdd( + const printing::PrinterSemanticCapsAndDefaults& semantic_info); + +} // namespace cloud_print + +#endif // CHROME_SERVICE_CLOUD_PRINT_CDD_CONVERSION_WIN_H_ diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc index 03687d8..94c18f0 100644 --- a/chrome/service/cloud_print/cloud_print_connector.cc +++ b/chrome/service/cloud_print/cloud_print_connector.cc @@ -622,6 +622,10 @@ void CloudPrintConnector::OnReceivePrinterCaps( settings_.xmpp_ping_timeout_sec()), mime_boundary, std::string(), &post_data); post_data += GetPostDataForPrinterInfo(info, mime_boundary); + if (caps_and_defaults.caps_mime_type == kContentTypeCDD) { + net::AddMultipartValueForUpload(kUseCDD, "true", mime_boundary, + std::string(), &post_data); + } net::AddMultipartValueForUpload(kPrinterCapsValue, caps_and_defaults.printer_capabilities, mime_boundary, caps_and_defaults.caps_mime_type, &post_data); diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index e66c9d1..36891b8 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -13,6 +13,7 @@ #include "base/win/scoped_hdc.h" #include "chrome/common/cloud_print/cloud_print_constants.h" #include "chrome/common/crash_keys.h" +#include "chrome/service/cloud_print/cdd_conversion_win.h" #include "chrome/service/service_process.h" #include "chrome/service/service_utility_process_host.h" #include "grit/generated_resources.h" @@ -620,15 +621,35 @@ class PrinterCapsHandler : public ServiceUtilityProcessHost::Client { Release(); } - void Start() { + virtual void OnGetPrinterSemanticCapsAndDefaults( + bool succeeded, + const std::string& printer_name, + const printing::PrinterSemanticCapsAndDefaults& semantic_info) OVERRIDE { + printing::PrinterCapsAndDefaults printer_info; + if (succeeded) { + printer_info.caps_mime_type = kContentTypeCDD; + printer_info.printer_capabilities = CapabilitiesToCdd(semantic_info); + } + callback_.Run(succeeded, printer_name, printer_info); + callback_.Reset(); + Release(); + } + + void StartGetPrinterCapsAndDefaults() { g_service_process->io_thread()->message_loop_proxy()->PostTask( FROM_HERE, base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this, base::MessageLoopProxy::current())); } + void StartGetPrinterSemanticCapsAndDefaults() { + g_service_process->io_thread()->message_loop_proxy()->PostTask( + FROM_HERE, + base::Bind(&PrinterCapsHandler::GetPrinterSemanticCapsAndDefaultsImpl, + this, base::MessageLoopProxy::current())); + } + private: - // Called on the service process IO thread. void GetPrinterCapsAndDefaultsImpl( const scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy) { @@ -646,6 +667,23 @@ class PrinterCapsHandler : public ServiceUtilityProcessHost::Client { } } + void GetPrinterSemanticCapsAndDefaultsImpl( + const scoped_refptr<base::MessageLoopProxy>& + client_message_loop_proxy) { + DCHECK(g_service_process->io_thread()->message_loop_proxy()-> + BelongsToCurrentThread()); + scoped_ptr<ServiceUtilityProcessHost> utility_host( + new ServiceUtilityProcessHost(this, client_message_loop_proxy)); + if (utility_host->StartGetPrinterSemanticCapsAndDefaults(printer_name_)) { + // The object will self-destruct when the child process dies. + utility_host.release(); + } else { + client_message_loop_proxy->PostTask( + FROM_HERE, + base::Bind(&PrinterCapsHandler::OnChildDied, this)); + } + } + std::string printer_name_; PrintSystem::PrinterCapsAndDefaultsCallback callback_; }; @@ -714,7 +752,7 @@ void PrintSystemWin::GetPrinterCapsAndDefaults( PrinterCapsHandler* handler = new PrinterCapsHandler(printer_name, callback); handler->AddRef(); - handler->Start(); + handler->StartGetPrinterCapsAndDefaults(); } bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) { diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc index e7c1f14..0e8a3f8 100644 --- a/chrome/service/cloud_print/printer_job_handler.cc +++ b/chrome/service/cloud_print/printer_job_handler.cc @@ -683,6 +683,10 @@ void PrinterJobHandler::OnReceivePrinterCaps( // Hashes don't match, we need to upload new capabilities (the defaults // go for free along with the capabilities) printer_info_cloud_.caps_hash = caps_hash; + if (caps_and_defaults.caps_mime_type == kContentTypeCDD) { + net::AddMultipartValueForUpload(kUseCDD, "true", mime_boundary, + std::string(), &post_data); + } net::AddMultipartValueForUpload(kPrinterCapsValue, caps_and_defaults.printer_capabilities, mime_boundary, caps_and_defaults.caps_mime_type, &post_data); |