Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: printing/pdf_metafile_skia.cc

Issue 1397333003: PDF Printing: embed browser user agent string in PDF metadata. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2015-11-05 (Thursday) 17:13:38 EST Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "printing/pdf_metafile_skia.h" 5 #include "printing/pdf_metafile_skia.h"
6 6
7 #include "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
11 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "printing/print_settings.h"
13 #include "skia/ext/refptr.h" 14 #include "skia/ext/refptr.h"
14 #include "third_party/skia/include/core/SkData.h" 15 #include "third_party/skia/include/core/SkData.h"
15 #include "third_party/skia/include/core/SkDocument.h" 16 #include "third_party/skia/include/core/SkDocument.h"
16 #include "third_party/skia/include/core/SkPictureRecorder.h" 17 #include "third_party/skia/include/core/SkPictureRecorder.h"
17 #include "third_party/skia/include/core/SkRect.h" 18 #include "third_party/skia/include/core/SkRect.h"
18 #include "third_party/skia/include/core/SkRefCnt.h" 19 #include "third_party/skia/include/core/SkRefCnt.h"
19 #include "third_party/skia/include/core/SkScalar.h" 20 #include "third_party/skia/include/core/SkScalar.h"
20 #include "third_party/skia/include/core/SkSize.h" 21 #include "third_party/skia/include/core/SkSize.h"
21 #include "third_party/skia/include/core/SkStream.h" 22 #include "third_party/skia/include/core/SkStream.h"
22 #include "ui/gfx/geometry/point.h" 23 #include "ui/gfx/geometry/point.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 skia::AdoptRef(SkDocument::CreatePDF(&pdf_stream)); 157 skia::AdoptRef(SkDocument::CreatePDF(&pdf_stream));
157 for (const auto& page : data_->pages_) { 158 for (const auto& page : data_->pages_) {
158 SkCanvas* canvas = pdf_doc->beginPage( 159 SkCanvas* canvas = pdf_doc->beginPage(
159 page.page_size_.width(), page.page_size_.height(), &page.content_area_); 160 page.page_size_.width(), page.page_size_.height(), &page.content_area_);
160 // No need to save/restore, since this canvas is not reused after endPage() 161 // No need to save/restore, since this canvas is not reused after endPage()
161 canvas->scale(page.scale_factor_, page.scale_factor_); 162 canvas->scale(page.scale_factor_, page.scale_factor_);
162 canvas->drawPicture(page.content_.get()); 163 canvas->drawPicture(page.content_.get());
163 pdf_doc->endPage(); 164 pdf_doc->endPage();
164 } 165 }
165 SkTArray<SkDocument::Attribute> info; 166 SkTArray<SkDocument::Attribute> info;
166 info.emplace_back(SkString("Creator"), SkString("Chromium")); 167 const std::string& user_agent = GetAgent();
168 info.emplace_back(SkString("Creator"),
169 user_agent.empty() ? SkString("Chromium")
170 : SkString(user_agent.c_str(), user_agent.size()));
Lei Zhang 2015/11/05 22:24:09 Can we do this in some way as suggested by the sty
hal.canary 2015/11/05 22:34:53 done
167 SkTime::DateTime now = TimeToSkTime(base::Time::Now()); 171 SkTime::DateTime now = TimeToSkTime(base::Time::Now());
168 pdf_doc->setMetadata(info, &now, &now); 172 pdf_doc->setMetadata(info, &now, &now);
169 if (!pdf_doc->close()) 173 if (!pdf_doc->close())
170 return false; 174 return false;
171 175
172 data_->pdf_data_.reset(pdf_stream.detachAsStream()); 176 data_->pdf_data_.reset(pdf_stream.detachAsStream());
173 return true; 177 return true;
174 } 178 }
175 179
176 uint32_t PdfMetafileSkia::GetDataSize() const { 180 uint32_t PdfMetafileSkia::GetDataSize() const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 305
302 metafile->data_->pages_.push_back(page); 306 metafile->data_->pages_.push_back(page);
303 307
304 if (!metafile->FinishDocument()) // Generate PDF. 308 if (!metafile->FinishDocument()) // Generate PDF.
305 metafile.reset(); 309 metafile.reset();
306 310
307 return metafile.Pass(); 311 return metafile.Pass();
308 } 312 }
309 313
310 } // namespace printing 314 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698