PDF Printing: embed browser user agent string in PDF metadata.
Review URL: https://codereview.chromium.org/1397333003 Cr-Commit-Position: refs/heads/master@{#358186}
This commit is contained in:
chrome/renderer
printing
@@ -125,8 +125,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_PRINTING)
|
#if defined(ENABLE_PRINTING)
|
||||||
|
#include "chrome/common/chrome_content_client.h"
|
||||||
#include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h"
|
#include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h"
|
||||||
#include "components/printing/renderer/print_web_view_helper.h"
|
#include "components/printing/renderer/print_web_view_helper.h"
|
||||||
|
#include "printing/print_settings.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_PRINT_PREVIEW)
|
#if defined(ENABLE_PRINT_PREVIEW)
|
||||||
@@ -355,6 +357,9 @@ ChromeContentRendererClient::ChromeContentRendererClient() {
|
|||||||
for (size_t i = 0; i < arraysize(kPredefinedAllowedCompositorOrigins); ++i)
|
for (size_t i = 0; i < arraysize(kPredefinedAllowedCompositorOrigins); ++i)
|
||||||
allowed_compositor_origins_.insert(kPredefinedAllowedCompositorOrigins[i]);
|
allowed_compositor_origins_.insert(kPredefinedAllowedCompositorOrigins[i]);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(ENABLE_PRINTING)
|
||||||
|
printing::SetAgent(GetUserAgent());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ChromeContentRendererClient::~ChromeContentRendererClient() {
|
ChromeContentRendererClient::~ChromeContentRendererClient() {
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "base/numerics/safe_conversions.h"
|
#include "base/numerics/safe_conversions.h"
|
||||||
#include "base/posix/eintr_wrapper.h"
|
#include "base/posix/eintr_wrapper.h"
|
||||||
#include "base/time/time.h"
|
#include "base/time/time.h"
|
||||||
|
#include "printing/print_settings.h"
|
||||||
#include "skia/ext/refptr.h"
|
#include "skia/ext/refptr.h"
|
||||||
#include "third_party/skia/include/core/SkData.h"
|
#include "third_party/skia/include/core/SkData.h"
|
||||||
#include "third_party/skia/include/core/SkDocument.h"
|
#include "third_party/skia/include/core/SkDocument.h"
|
||||||
@@ -163,7 +164,11 @@ bool PdfMetafileSkia::FinishDocument() {
|
|||||||
pdf_doc->endPage();
|
pdf_doc->endPage();
|
||||||
}
|
}
|
||||||
SkTArray<SkDocument::Attribute> info;
|
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());
|
SkTime::DateTime now = TimeToSkTime(base::Time::Now());
|
||||||
pdf_doc->setMetadata(info, &now, &now);
|
pdf_doc->setMetadata(info, &now, &now);
|
||||||
if (!pdf_doc->close())
|
if (!pdf_doc->close())
|
||||||
|
@@ -5,12 +5,23 @@
|
|||||||
#include "printing/print_settings.h"
|
#include "printing/print_settings.h"
|
||||||
|
|
||||||
#include "base/atomic_sequence_num.h"
|
#include "base/atomic_sequence_num.h"
|
||||||
|
#include "base/lazy_instance.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "printing/print_job_constants.h"
|
#include "printing/print_job_constants.h"
|
||||||
#include "printing/units.h"
|
#include "printing/units.h"
|
||||||
|
|
||||||
namespace printing {
|
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)
|
#if defined(USE_CUPS)
|
||||||
void GetColorModelForMode(
|
void GetColorModelForMode(
|
||||||
int color_mode, std::string* color_setting_name, std::string* color_value) {
|
int color_mode, std::string* color_setting_name, std::string* color_value) {
|
||||||
|
@@ -26,6 +26,11 @@ PRINTING_EXPORT void GetColorModelForMode(int color_mode,
|
|||||||
std::string* color_value);
|
std::string* color_value);
|
||||||
#endif
|
#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.
|
// OS-independent print settings.
|
||||||
class PRINTING_EXPORT PrintSettings {
|
class PRINTING_EXPORT PrintSettings {
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user