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

Side by Side Diff: printing/pdf_metafile_cg_mac.cc

Issue 2458513003: Addressing C4267 warnings for printing. (Closed)
Patch Set: Rebase, IsValueInRangeForNumericType for CFIndex Created 4 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
« no previous file with comments | « printing/pdf_metafile_cg_mac.h ('k') | printing/pdf_metafile_skia.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_cg_mac.h" 5 #include "printing/pdf_metafile_cg_mac.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/numerics/safe_conversions.h"
14 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
15 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 18
18 using base::ScopedCFTypeRef; 19 using base::ScopedCFTypeRef;
19 20
20 namespace { 21 namespace {
21 22
22 // Rotate a page by |num_rotations| * 90 degrees, counter-clockwise. 23 // Rotate a page by |num_rotations| * 90 degrees, counter-clockwise.
23 void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) { 24 void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 context_.reset(CGPDFContextCreate(pdf_consumer, nullptr, nullptr)); 81 context_.reset(CGPDFContextCreate(pdf_consumer, nullptr, nullptr));
81 if (!context_.get()) { 82 if (!context_.get()) {
82 LOG(ERROR) << "Failed to create pdf context for metafile"; 83 LOG(ERROR) << "Failed to create pdf context for metafile";
83 pdf_data_.reset(); 84 pdf_data_.reset();
84 } 85 }
85 86
86 return true; 87 return true;
87 } 88 }
88 89
89 bool PdfMetafileCg::InitFromData(const void* src_buffer, 90 bool PdfMetafileCg::InitFromData(const void* src_buffer,
90 uint32_t src_buffer_size) { 91 size_t src_buffer_size) {
91 DCHECK(!context_.get()); 92 DCHECK(!context_.get());
92 DCHECK(!pdf_data_.get()); 93 DCHECK(!pdf_data_.get());
93 94
94 if (!src_buffer || src_buffer_size == 0) { 95 if (!src_buffer || !src_buffer_size)
95 return false; 96 return false;
96 } 97
98 if (!base::IsValueInRangeForNumericType<CFIndex>(src_buffer_size))
99 return false;
97 100
98 pdf_data_.reset(CFDataCreateMutable(kCFAllocatorDefault, src_buffer_size)); 101 pdf_data_.reset(CFDataCreateMutable(kCFAllocatorDefault, src_buffer_size));
99 CFDataAppendBytes(pdf_data_, static_cast<const UInt8*>(src_buffer), 102 CFDataAppendBytes(pdf_data_, static_cast<const UInt8*>(src_buffer),
100 src_buffer_size); 103 src_buffer_size);
101 104
102 return true; 105 return true;
103 } 106 }
104 107
105 void PdfMetafileCg::StartPage(const gfx::Size& page_size, 108 void PdfMetafileCg::StartPage(const gfx::Size& page_size,
106 const gfx::Rect& content_area, 109 const gfx::Rect& content_area,
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 292
290 if (!pdf_doc_.get()) { 293 if (!pdf_doc_.get()) {
291 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( 294 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider(
292 CGDataProviderCreateWithCFData(pdf_data_)); 295 CGDataProviderCreateWithCFData(pdf_data_));
293 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); 296 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider));
294 } 297 }
295 return pdf_doc_.get(); 298 return pdf_doc_.get();
296 } 299 }
297 300
298 } // namespace printing 301 } // namespace printing
OLDNEW
« no previous file with comments | « printing/pdf_metafile_cg_mac.h ('k') | printing/pdf_metafile_skia.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698