Home | History | Annotate | Download | only in renderer
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "content/renderer/scoped_clipboard_writer_glue.h"
      6 #include "base/logging.h"
      7 
      8 namespace content {
      9 
     10 ScopedClipboardWriterGlue::ScopedClipboardWriterGlue(ClipboardClient* client)
     11     : ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE),
     12       context_(client->CreateWriteContext()) {
     13   DCHECK(context_);
     14 }
     15 
     16 ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
     17   if (!objects_.empty() && context_) {
     18     context_->Flush(objects_);
     19     // TODO(dcheng): Temporary hack while the clipboard IPCs are cleaned up.
     20     // This prevents the base class destructor from also trying to (probably
     21     // unsuccessfully) flush things to the clipboard.
     22     objects_.clear();
     23   }
     24 }
     25 
     26 void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels,
     27                                                       const gfx::Size& size) {
     28   if (context_) {
     29     context_->WriteBitmapFromPixels(&objects_, pixels, size);
     30   } else {
     31     NOTREACHED();
     32   }
     33 }
     34 
     35 }  // namespace content
     36 
     37