diff options
author | halcanary <halcanary@google.com> | 2015-11-05 16:02:14 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-06 00:03:07 +0000 |
commit | 73b63fd9d4501782f0033ba72f21a33e43fe290c (patch) | |
tree | b292cdfc092718dcd5432fb30c3b1eb539308859 | |
parent | 738f72f173985d46f0fb1596209981c1cfe1e53a (diff) | |
download | chromium_src-73b63fd9d4501782f0033ba72f21a33e43fe290c.zip chromium_src-73b63fd9d4501782f0033ba72f21a33e43fe290c.tar.gz chromium_src-73b63fd9d4501782f0033ba72f21a33e43fe290c.tar.bz2 |
PDF Printing: embed browser user agent string in PDF metadata.
Review URL: https://codereview.chromium.org/1397333003
Cr-Commit-Position: refs/heads/master@{#358186}
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 5 | ||||
-rw-r--r-- | printing/pdf_metafile_skia.cc | 7 | ||||
-rw-r--r-- | printing/print_settings.cc | 11 | ||||
-rw-r--r-- | printing/print_settings.h | 5 |
4 files changed, 27 insertions, 1 deletions
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 3d815b12..2ce1501 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -125,8 +125,10 @@ #endif #if defined(ENABLE_PRINTING) +#include "chrome/common/chrome_content_client.h" #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h" #include "components/printing/renderer/print_web_view_helper.h" +#include "printing/print_settings.h" #endif #if defined(ENABLE_PRINT_PREVIEW) @@ -355,6 +357,9 @@ ChromeContentRendererClient::ChromeContentRendererClient() { for (size_t i = 0; i < arraysize(kPredefinedAllowedCompositorOrigins); ++i) allowed_compositor_origins_.insert(kPredefinedAllowedCompositorOrigins[i]); #endif +#if defined(ENABLE_PRINTING) + printing::SetAgent(GetUserAgent()); +#endif } ChromeContentRendererClient::~ChromeContentRendererClient() { diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc index bb22792..1e7a7d1 100644 --- a/printing/pdf_metafile_skia.cc +++ b/printing/pdf_metafile_skia.cc @@ -10,6 +10,7 @@ #include "base/numerics/safe_conversions.h" #include "base/posix/eintr_wrapper.h" #include "base/time/time.h" +#include "printing/print_settings.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkDocument.h" @@ -163,7 +164,11 @@ bool PdfMetafileSkia::FinishDocument() { pdf_doc->endPage(); } SkTArray<SkDocument::Attribute> info; - info.emplace_back(SkString("Creator"), SkString("Chromium")); + const std::string& user_agent = GetAgent(); + info.emplace_back(SkString("Creator"), + user_agent.empty() + ? SkString("Chromium") + : SkString(user_agent.c_str(), user_agent.size())); SkTime::DateTime now = TimeToSkTime(base::Time::Now()); pdf_doc->setMetadata(info, &now, &now); if (!pdf_doc->close()) diff --git a/printing/print_settings.cc b/printing/print_settings.cc index b1c50c9..7f555f0 100644 --- a/printing/print_settings.cc +++ b/printing/print_settings.cc @@ -5,12 +5,23 @@ #include "printing/print_settings.h" #include "base/atomic_sequence_num.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "printing/print_job_constants.h" #include "printing/units.h" namespace printing { +base::LazyInstance<std::string> g_user_agent; + +void SetAgent(const std::string& user_agent) { + g_user_agent.Get() = user_agent; +} + +const std::string& GetAgent() { + return g_user_agent.Get(); +} + #if defined(USE_CUPS) void GetColorModelForMode( int color_mode, std::string* color_setting_name, std::string* color_value) { diff --git a/printing/print_settings.h b/printing/print_settings.h index 1f35e90..08c7d56 100644 --- a/printing/print_settings.h +++ b/printing/print_settings.h @@ -26,6 +26,11 @@ PRINTING_EXPORT void GetColorModelForMode(int color_mode, std::string* color_value); #endif +// Inform the printing system that it may embed this user-agent string +// in its output's metadata. +PRINTING_EXPORT void SetAgent(const std::string& user_agent); +PRINTING_EXPORT const std::string& GetAgent(); + // OS-independent print settings. class PRINTING_EXPORT PrintSettings { public: |