[email protected] | 5cc4c42 | 2011-02-19 00:09:22 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 5 | #include "printing/printed_document.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 7d2d0d0e | 2010-03-06 22:16:10 | [diff] [blame] | 7 | #include <algorithm> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <set> |
[email protected] | 7d2d0d0e | 2010-03-06 22:16:10 | [diff] [blame] | 9 | #include <string> |
dcheng | e4860045 | 2015-12-28 02:24:50 | [diff] [blame] | 10 | #include <utility> |
[email protected] | 7d2d0d0e | 2010-03-06 22:16:10 | [diff] [blame] | 11 | #include <vector> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 13 | #include "base/bind.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
thestig | 22dfc401 | 2014-09-05 08:29:44 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | d0767cb54 | 2009-10-08 17:38:30 | [diff] [blame] | 16 | #include "base/i18n/file_util_icu.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 17 | #include "base/i18n/time_formatting.h" |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 19 | #include "base/lazy_instance.h" |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 20 | #include "base/memory/ref_counted_memory.h" |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 21 | #include "base/numerics/safe_conversions.h" |
[email protected] | 896d161f | 2013-06-11 22:52:24 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
| 23 | #include "base/strings/stringprintf.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 24 | #include "base/strings/utf_string_conversions.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 25 | #include "base/task/post_task.h" |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 26 | #include "base/time/time.h" |
| 27 | #include "base/values.h" |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 28 | #include "printing/metafile.h" |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 29 | #include "printing/page_number.h" |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 30 | #include "printing/print_settings_conversion.h" |
[email protected] | 4ae30d08 | 2009-02-20 17:55:55 | [diff] [blame] | 31 | #include "printing/units.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 32 | #include "ui/gfx/font.h" |
[email protected] | dbb97ba | 2013-09-09 22:15:25 | [diff] [blame] | 33 | #include "ui/gfx/text_elider.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 35 | #if defined(OS_WIN) |
| 36 | #include "printing/printed_page_win.h" |
| 37 | #endif |
| 38 | |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 39 | namespace printing { |
| 40 | |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 41 | namespace { |
| 42 | |
thestig | 6c884e64 | 2017-04-11 04:05:51 | [diff] [blame] | 43 | base::LazyInstance<base::FilePath>::Leaky g_debug_dump_info = |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 44 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 45 | |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 46 | #if defined(OS_WIN) |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 47 | void DebugDumpPageTask(const base::string16& doc_name, |
| 48 | const PrintedPage* page) { |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 49 | DCHECK(PrintedDocument::HasDebugDumpPath()); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 50 | |
Lei Zhang | 933d34b | 2017-11-13 20:59:29 | [diff] [blame] | 51 | static constexpr base::FilePath::CharType kExtension[] = |
Lei Zhang | 933d34b | 2017-11-13 20:59:29 | [diff] [blame] | 52 | FILE_PATH_LITERAL(".emf"); |
Lei Zhang | 933d34b | 2017-11-13 20:59:29 | [diff] [blame] | 53 | |
| 54 | base::string16 name = doc_name; |
| 55 | name += base::ASCIIToUTF16(base::StringPrintf("_%04d", page->page_number())); |
| 56 | base::FilePath path = PrintedDocument::CreateDebugDumpPath(name, kExtension); |
| 57 | base::File file(path, |
vitalybuka | 5d129058 | 2014-09-12 09:19:59 | [diff] [blame] | 58 | base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
| 59 | page->metafile()->SaveTo(&file); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 60 | } |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 61 | #else |
| 62 | void DebugDumpTask(const base::string16& doc_name, |
| 63 | const MetafilePlayer* metafile) { |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 64 | DCHECK(PrintedDocument::HasDebugDumpPath()); |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 65 | |
| 66 | static constexpr base::FilePath::CharType kExtension[] = |
| 67 | FILE_PATH_LITERAL(".pdf"); |
| 68 | |
| 69 | base::string16 name = doc_name; |
| 70 | base::FilePath path = PrintedDocument::CreateDebugDumpPath(name, kExtension); |
| 71 | base::File file(path, |
| 72 | base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
| 73 | metafile->SaveTo(&file); |
| 74 | } |
| 75 | #endif |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 76 | |
| 77 | void DebugDumpDataTask(const base::string16& doc_name, |
| 78 | const base::FilePath::StringType& extension, |
| 79 | const base::RefCountedMemory* data) { |
| 80 | base::FilePath path = |
| 81 | PrintedDocument::CreateDebugDumpPath(doc_name, extension); |
| 82 | if (path.empty()) |
| 83 | return; |
| 84 | base::WriteFile(path, |
| 85 | reinterpret_cast<const char*>(data->front()), |
| 86 | base::checked_cast<int>(data->size())); |
| 87 | } |
| 88 | |
| 89 | void DebugDumpSettings(const base::string16& doc_name, |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 90 | const PrintSettings& settings) { |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 91 | base::DictionaryValue job_settings; |
| 92 | PrintSettingsToJobSettingsDebug(settings, &job_settings); |
| 93 | std::string settings_str; |
| 94 | base::JSONWriter::WriteWithOptions( |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 95 | job_settings, base::JSONWriter::OPTIONS_PRETTY_PRINT, &settings_str); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 96 | scoped_refptr<base::RefCountedMemory> data = |
| 97 | base::RefCountedString::TakeString(&settings_str); |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 98 | base::PostTaskWithTraits( |
Gabriel Charette | b10aeeb | 2018-07-26 20:15:00 | [diff] [blame] | 99 | FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()}, |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 100 | base::BindOnce(&DebugDumpDataTask, doc_name, FILE_PATH_LITERAL(".json"), |
| 101 | base::RetainedRef(data))); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 102 | } |
| 103 | |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 104 | } // namespace |
| 105 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | PrintedDocument::PrintedDocument(const PrintSettings& settings, |
Vladislav Kuzkokov | ccceef0 | 2017-10-04 15:30:10 | [diff] [blame] | 107 | const base::string16& name, |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 108 | int cookie) |
Vladislav Kuzkokov | ccceef0 | 2017-10-04 15:30:10 | [diff] [blame] | 109 | : immutable_(settings, name, cookie) { |
Lei Zhang | 99bb78d3 | 2018-05-04 18:38:37 | [diff] [blame] | 110 | // If there is a range, set the number of page |
| 111 | for (const PageRange& range : settings.ranges()) |
| 112 | mutable_.expected_page_count_ += range.to - range.from + 1; |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 113 | |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 114 | if (HasDebugDumpPath()) |
Vladislav Kuzkokov | ccceef0 | 2017-10-04 15:30:10 | [diff] [blame] | 115 | DebugDumpSettings(name, settings); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | } |
| 117 | |
Chris Watkins | c360b97 | 2017-12-01 05:50:23 | [diff] [blame] | 118 | PrintedDocument::~PrintedDocument() = default; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 119 | |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 120 | #if defined(OS_WIN) |
rbpotter | d20e4ef3 | 2018-03-09 20:50:39 | [diff] [blame] | 121 | void PrintedDocument::SetConvertingPdf() { |
| 122 | base::AutoLock lock(lock_); |
| 123 | mutable_.converting_pdf_ = true; |
| 124 | } |
| 125 | |
[email protected] | 0e0fca3 | 2009-07-06 15:25:50 | [diff] [blame] | 126 | void PrintedDocument::SetPage(int page_number, |
dcheng | c3df9ba | 2016-04-07 23:09:32 | [diff] [blame] | 127 | std::unique_ptr<MetafilePlayer> metafile, |
pkasting | 46a6291 | 2014-10-09 21:30:00 | [diff] [blame] | 128 | float shrink, |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 129 | const gfx::Size& page_size, |
| 130 | const gfx::Rect& page_content_rect) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | // Notice the page_number + 1, the reason is that this is the value that will |
| 132 | // be shown. Users dislike 0-based counting. |
Lei Zhang | 76446180 | 2017-11-15 23:36:07 | [diff] [blame] | 133 | auto page = base::MakeRefCounted<PrintedPage>( |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 134 | page_number + 1, std::move(metafile), page_size, page_content_rect); |
[email protected] | 9de1347a | 2014-06-12 09:49:08 | [diff] [blame] | 135 | page->set_shrink_factor(shrink); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 137 | base::AutoLock lock(lock_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 138 | mutable_.pages_[page_number] = page; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | } |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 140 | |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 141 | if (HasDebugDumpPath()) { |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 142 | base::PostTaskWithTraits( |
Gabriel Charette | b10aeeb | 2018-07-26 20:15:00 | [diff] [blame] | 143 | FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()}, |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 144 | base::BindOnce(&DebugDumpPageTask, name(), base::RetainedRef(page))); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 145 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 148 | scoped_refptr<PrintedPage> PrintedDocument::GetPage(int page_number) { |
| 149 | scoped_refptr<PrintedPage> page; |
| 150 | { |
| 151 | base::AutoLock lock(lock_); |
Lei Zhang | 76446180 | 2017-11-15 23:36:07 | [diff] [blame] | 152 | PrintedPages::const_iterator it = mutable_.pages_.find(page_number); |
| 153 | if (it != mutable_.pages_.end()) |
| 154 | page = it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | } |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 156 | return page; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 157 | } |
| 158 | |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 159 | #else |
| 160 | void PrintedDocument::SetDocument(std::unique_ptr<MetafilePlayer> metafile, |
| 161 | const gfx::Size& page_size, |
| 162 | const gfx::Rect& page_content_rect) { |
| 163 | { |
| 164 | base::AutoLock lock(lock_); |
| 165 | mutable_.metafile_ = std::move(metafile); |
| 166 | #if defined(OS_MACOSX) |
| 167 | mutable_.page_size_ = page_size; |
| 168 | mutable_.page_content_rect_ = page_content_rect; |
| 169 | #endif |
| 170 | } |
| 171 | |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 172 | if (HasDebugDumpPath()) { |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 173 | base::PostTaskWithTraits( |
Gabriel Charette | b10aeeb | 2018-07-26 20:15:00 | [diff] [blame] | 174 | FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()}, |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 175 | base::BindOnce(&DebugDumpTask, name(), mutable_.metafile_.get())); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | const MetafilePlayer* PrintedDocument::GetMetafile() { |
| 180 | return mutable_.metafile_.get(); |
| 181 | } |
| 182 | |
| 183 | #endif |
| 184 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 185 | bool PrintedDocument::IsComplete() const { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 186 | base::AutoLock lock(lock_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | if (!mutable_.page_count_) |
| 188 | return false; |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 189 | #if defined(OS_WIN) |
rbpotter | d20e4ef3 | 2018-03-09 20:50:39 | [diff] [blame] | 190 | if (mutable_.converting_pdf_) |
| 191 | return true; |
| 192 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 193 | PageNumber page(immutable_.settings_, mutable_.page_count_); |
| 194 | if (page == PageNumber::npos()) |
| 195 | return false; |
[email protected] | 5cc4c42 | 2011-02-19 00:09:22 | [diff] [blame] | 196 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 197 | for (; page != PageNumber::npos(); ++page) { |
Lei Zhang | 76446180 | 2017-11-15 23:36:07 | [diff] [blame] | 198 | PrintedPages::const_iterator it = mutable_.pages_.find(page.ToInt()); |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 199 | if (it == mutable_.pages_.end() || !it->second.get() || |
| 200 | !it->second->metafile()) { |
[email protected] | 5cc4c42 | 2011-02-19 00:09:22 | [diff] [blame] | 201 | return false; |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 202 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 203 | } |
| 204 | return true; |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 205 | #else |
| 206 | return !!mutable_.metafile_; |
| 207 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 208 | } |
| 209 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 210 | void PrintedDocument::set_page_count(int max_page) { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 211 | base::AutoLock lock(lock_); |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 212 | DCHECK_EQ(0, mutable_.page_count_); |
| 213 | mutable_.page_count_ = max_page; |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 214 | if (immutable_.settings_.ranges().empty()) { |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 215 | mutable_.expected_page_count_ = max_page; |
| 216 | } else { |
| 217 | // If there is a range, don't bother since expected_page_count_ is already |
| 218 | // initialized. |
| 219 | DCHECK_NE(mutable_.expected_page_count_, 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 220 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | int PrintedDocument::page_count() const { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 224 | base::AutoLock lock(lock_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | return mutable_.page_count_; |
| 226 | } |
| 227 | |
| 228 | int PrintedDocument::expected_page_count() const { |
[email protected] | 20305ec | 2011-01-21 04:55:52 | [diff] [blame] | 229 | base::AutoLock lock(lock_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 230 | return mutable_.expected_page_count_; |
| 231 | } |
| 232 | |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 233 | // static |
| 234 | void PrintedDocument::SetDebugDumpPath(const base::FilePath& debug_dump_path) { |
| 235 | DCHECK(!debug_dump_path.empty()); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 236 | g_debug_dump_info.Get() = debug_dump_path; |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 237 | } |
| 238 | |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 239 | // static |
| 240 | bool PrintedDocument::HasDebugDumpPath() { |
| 241 | return g_debug_dump_info.IsCreated(); |
| 242 | } |
| 243 | |
| 244 | // static |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 245 | base::FilePath PrintedDocument::CreateDebugDumpPath( |
| 246 | const base::string16& document_name, |
| 247 | const base::FilePath::StringType& extension) { |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 248 | DCHECK(HasDebugDumpPath()); |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 249 | |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 250 | // Create a filename. |
| 251 | base::string16 filename; |
| 252 | base::Time now(base::Time::Now()); |
| 253 | filename = base::TimeFormatShortDateAndTime(now); |
| 254 | filename += base::ASCIIToUTF16("_"); |
| 255 | filename += document_name; |
| 256 | base::FilePath::StringType system_filename; |
| 257 | #if defined(OS_WIN) |
| 258 | system_filename = filename; |
| 259 | #else // OS_WIN |
| 260 | system_filename = base::UTF16ToUTF8(filename); |
| 261 | #endif // OS_WIN |
[email protected] | 6bc03de | 2014-08-07 23:59:15 | [diff] [blame] | 262 | base::i18n::ReplaceIllegalCharactersInPath(&system_filename, '_'); |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 263 | const auto& dump_path = g_debug_dump_info.Get(); |
| 264 | DCHECK(!dump_path.empty()); |
| 265 | return dump_path.Append(system_filename).AddExtension(extension); |
[email protected] | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void PrintedDocument::DebugDumpData( |
| 269 | const base::RefCountedMemory* data, |
| 270 | const base::FilePath::StringType& extension) { |
Lei Zhang | bdd6381 | 2017-12-12 06:29:51 | [diff] [blame] | 271 | DCHECK(HasDebugDumpPath()); |
tzik | df97f3d | 2017-06-28 08:11:51 | [diff] [blame] | 272 | base::PostTaskWithTraits(FROM_HERE, |
Gabriel Charette | b10aeeb | 2018-07-26 20:15:00 | [diff] [blame] | 273 | {base::TaskPriority::BEST_EFFORT, base::MayBlock()}, |
tzik | df97f3d | 2017-06-28 08:11:51 | [diff] [blame] | 274 | base::BindOnce(&DebugDumpDataTask, name(), extension, |
| 275 | base::RetainedRef(data))); |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 276 | } |
| 277 | |
rbpotter | 80cbe04 | 2017-12-08 07:00:52 | [diff] [blame] | 278 | #if defined(OS_WIN) || defined(OS_MACOSX) |
| 279 | gfx::Rect PrintedDocument::GetCenteredPageContentRect( |
| 280 | const gfx::Size& paper_size, |
| 281 | const gfx::Size& page_size, |
| 282 | const gfx::Rect& page_content_rect) const { |
| 283 | gfx::Rect content_rect = page_content_rect; |
| 284 | if (paper_size.width() > page_size.width()) { |
| 285 | int diff = paper_size.width() - page_size.width(); |
| 286 | content_rect.set_x(content_rect.x() + diff / 2); |
| 287 | } |
| 288 | if (paper_size.height() > page_size.height()) { |
| 289 | int diff = paper_size.height() - page_size.height(); |
| 290 | content_rect.set_y(content_rect.y() + diff / 2); |
| 291 | } |
| 292 | return content_rect; |
| 293 | } |
| 294 | #endif |
| 295 | |
Chris Watkins | c360b97 | 2017-12-01 05:50:23 | [diff] [blame] | 296 | PrintedDocument::Mutable::Mutable() = default; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 297 | |
Chris Watkins | c360b97 | 2017-12-01 05:50:23 | [diff] [blame] | 298 | PrintedDocument::Mutable::~Mutable() = default; |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 299 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 300 | PrintedDocument::Immutable::Immutable(const PrintSettings& settings, |
Vladislav Kuzkokov | ccceef0 | 2017-10-04 15:30:10 | [diff] [blame] | 301 | const base::string16& name, |
Xiyuan Xia | 863ce9d | 2017-06-20 22:36:00 | [diff] [blame] | 302 | int cookie) |
Vladislav Kuzkokov | ccceef0 | 2017-10-04 15:30:10 | [diff] [blame] | 303 | : settings_(settings), name_(name), cookie_(cookie) {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | |
Chris Watkins | c360b97 | 2017-12-01 05:50:23 | [diff] [blame] | 305 | PrintedDocument::Immutable::~Immutable() = default; |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 306 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 307 | } // namespace printing |