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

Side by Side Diff: content/renderer/renderer_clipboard_client.cc

Issue 289573002: Workaround bad bitmaps in clibpoard code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: if->DCHECK Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/webclipboard_impl.cc » ('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 // This file provides the embedder's side of the Clipboard interface. 5 // This file provides the embedder's side of the Clipboard interface.
6 6
7 #include "content/renderer/renderer_clipboard_client.h" 7 #include "content/renderer/renderer_clipboard_client.h"
8 8
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/numerics/safe_math.h"
10 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
11 #include "content/common/clipboard_messages.h" 12 #include "content/common/clipboard_messages.h"
12 #include "content/public/renderer/content_renderer_client.h" 13 #include "content/public/renderer/content_renderer_client.h"
13 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
14 #include "content/renderer/scoped_clipboard_writer_glue.h" 15 #include "content/renderer/scoped_clipboard_writer_glue.h"
15 #include "ui/base/clipboard/clipboard.h" 16 #include "ui/base/clipboard/clipboard.h"
16 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
17 18
18 namespace content { 19 namespace content {
19 20
(...skipping 22 matching lines...) Expand all
42 // This definition of WriteBitmapFromPixels uses shared memory to communicate 43 // This definition of WriteBitmapFromPixels uses shared memory to communicate
43 // across processes. 44 // across processes.
44 void RendererClipboardWriteContext::WriteBitmapFromPixels( 45 void RendererClipboardWriteContext::WriteBitmapFromPixels(
45 ui::Clipboard::ObjectMap* objects, 46 ui::Clipboard::ObjectMap* objects,
46 const void* pixels, 47 const void* pixels,
47 const gfx::Size& size) { 48 const gfx::Size& size) {
48 // Do not try to write a bitmap more than once 49 // Do not try to write a bitmap more than once
49 if (shared_buf_) 50 if (shared_buf_)
50 return; 51 return;
51 52
52 uint32 buf_size = 4 * size.width() * size.height(); 53 base::CheckedNumeric<uint32> checked_buf_size = 4;
54 checked_buf_size *= size.width();
55 checked_buf_size *= size.height();
56 if (!checked_buf_size.IsValid())
57 return;
58
59 uint32 buf_size = checked_buf_size.ValueOrDie();
53 60
54 // Allocate a shared memory buffer to hold the bitmap bits. 61 // Allocate a shared memory buffer to hold the bitmap bits.
55 shared_buf_.reset(ChildThread::current()->AllocateSharedMemory(buf_size)); 62 shared_buf_.reset(ChildThread::current()->AllocateSharedMemory(buf_size));
56 if (!shared_buf_) 63 if (!shared_buf_)
57 return; 64 return;
58 65
59 // Copy the bits into shared memory 66 // Copy the bits into shared memory
60 DCHECK(shared_buf_->memory()); 67 DCHECK(shared_buf_->memory());
61 memcpy(shared_buf_->memory(), pixels, buf_size); 68 memcpy(shared_buf_->memory(), pixels, buf_size);
62 shared_buf_->Unmap(); 69 shared_buf_->Unmap();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 base::string16* data) { 171 base::string16* data) {
165 RenderThreadImpl::current()->Send( 172 RenderThreadImpl::current()->Send(
166 new ClipboardHostMsg_ReadCustomData(clipboard_type, type, data)); 173 new ClipboardHostMsg_ReadCustomData(clipboard_type, type, data));
167 } 174 }
168 175
169 ClipboardClient::WriteContext* RendererClipboardClient::CreateWriteContext() { 176 ClipboardClient::WriteContext* RendererClipboardClient::CreateWriteContext() {
170 return new RendererClipboardWriteContext; 177 return new RendererClipboardWriteContext;
171 } 178 }
172 179
173 } // namespace content 180 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/webclipboard_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698