| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/support/simple_clipboard_impl.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/stl_util.h" | |
| 11 #include "base/strings/string16.h" | |
| 12 #include "googleurl/src/gurl.h" | |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | |
| 14 #include "third_party/zlib/zlib.h" | |
| 15 #include "ui/base/clipboard/clipboard.h" | |
| 16 #include "ui/gfx/codec/png_codec.h" | |
| 17 #include "ui/gfx/size.h" | |
| 18 #include "webkit/glue/webkit_glue.h" | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 } // anonymous namespace | |
| 23 | |
| 24 SimpleClipboardClient::SimpleClipboardClient() { | |
| 25 } | |
| 26 | |
| 27 SimpleClipboardClient::~SimpleClipboardClient() { | |
| 28 } | |
| 29 | |
| 30 | |
| 31 ui::Clipboard* SimpleClipboardClient::GetClipboard() { | |
| 32 return ui::Clipboard::GetForCurrentThread(); | |
| 33 } | |
| 34 | |
| 35 uint64 SimpleClipboardClient::GetSequenceNumber(ui::Clipboard::Buffer buffer) { | |
| 36 return GetClipboard()->GetSequenceNumber(buffer); | |
| 37 } | |
| 38 | |
| 39 bool SimpleClipboardClient::IsFormatAvailable( | |
| 40 const ui::Clipboard::FormatType& format, | |
| 41 ui::Clipboard::Buffer buffer) { | |
| 42 return GetClipboard()->IsFormatAvailable(format, buffer); | |
| 43 } | |
| 44 | |
| 45 void SimpleClipboardClient::Clear(ui::Clipboard::Buffer buffer) { | |
| 46 GetClipboard()->Clear(buffer); | |
| 47 } | |
| 48 | |
| 49 void SimpleClipboardClient::ReadAvailableTypes( | |
| 50 ui::Clipboard::Buffer buffer, | |
| 51 std::vector<base::string16>* types, | |
| 52 bool* contains_filenames) { | |
| 53 return GetClipboard()->ReadAvailableTypes(buffer, types, contains_filenames); | |
| 54 } | |
| 55 | |
| 56 void SimpleClipboardClient::ReadText(ui::Clipboard::Buffer buffer, | |
| 57 base::string16* result) { | |
| 58 GetClipboard()->ReadText(buffer, result); | |
| 59 } | |
| 60 | |
| 61 void SimpleClipboardClient::ReadAsciiText(ui::Clipboard::Buffer buffer, | |
| 62 std::string* result) { | |
| 63 GetClipboard()->ReadAsciiText(buffer, result); | |
| 64 } | |
| 65 | |
| 66 void SimpleClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer, | |
| 67 base::string16* markup, | |
| 68 GURL* url, uint32* fragment_start, | |
| 69 uint32* fragment_end) { | |
| 70 std::string url_str; | |
| 71 GetClipboard()->ReadHTML(buffer, markup, url ? &url_str : NULL, | |
| 72 fragment_start, fragment_end); | |
| 73 if (url) | |
| 74 *url = GURL(url_str); | |
| 75 } | |
| 76 | |
| 77 void SimpleClipboardClient::ReadRTF(ui::Clipboard::Buffer buffer, | |
| 78 std::string* result) { | |
| 79 GetClipboard()->ReadRTF(buffer, result); | |
| 80 } | |
| 81 | |
| 82 void SimpleClipboardClient::ReadImage(ui::Clipboard::Buffer buffer, | |
| 83 std::string* data) { | |
| 84 SkBitmap bitmap = GetClipboard()->ReadImage(buffer); | |
| 85 if (bitmap.isNull()) | |
| 86 return; | |
| 87 | |
| 88 std::vector<unsigned char> png_data; | |
| 89 SkAutoLockPixels lock(bitmap); | |
| 90 if (gfx::PNGCodec::EncodeWithCompressionLevel( | |
| 91 static_cast<const unsigned char*>(bitmap.getPixels()), | |
| 92 gfx::PNGCodec::FORMAT_BGRA, | |
| 93 gfx::Size(bitmap.width(), bitmap.height()), | |
| 94 bitmap.rowBytes(), | |
| 95 false, | |
| 96 std::vector<gfx::PNGCodec::Comment>(), | |
| 97 Z_BEST_SPEED, | |
| 98 &png_data)) { | |
| 99 data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)), | |
| 100 png_data.size()); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 void SimpleClipboardClient::ReadCustomData(ui::Clipboard::Buffer buffer, | |
| 105 const base::string16& type, | |
| 106 base::string16* data) { | |
| 107 GetClipboard()->ReadCustomData(buffer, type, data); | |
| 108 } | |
| 109 | |
| 110 void SimpleClipboardClient::ReadData(const ui::Clipboard::FormatType& format, | |
| 111 std::string* data) { | |
| 112 GetClipboard()->ReadData(format, data); | |
| 113 } | |
| 114 | |
| 115 webkit_glue::ClipboardClient::WriteContext* | |
| 116 SimpleClipboardClient::CreateWriteContext() { | |
| 117 return NULL; | |
| 118 } | |
| OLD | NEW |