2011-10-12 21:09:15 +02:00
|
|
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
2010-08-09 21:13:43 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/simple_clipboard_impl.h"
|
2010-08-09 21:13:43 +02:00
|
|
|
|
|
|
|
#include "base/lazy_instance.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "base/stl_util.h"
|
2010-08-09 21:13:43 +02:00
|
|
|
#include "base/string16.h"
|
|
|
|
#include "googleurl/src/gurl.h"
|
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
2012-02-18 01:19:52 +01:00
|
|
|
#if defined(USE_SYSTEM_ZLIB)
|
|
|
|
#include <zlib.h>
|
|
|
|
#else
|
2011-05-16 18:56:12 +02:00
|
|
|
#include "third_party/zlib/zlib.h"
|
2012-02-18 01:19:52 +01:00
|
|
|
#endif
|
2011-01-12 00:46:14 +01:00
|
|
|
#include "ui/base/clipboard/clipboard.h"
|
2011-05-16 18:56:12 +02:00
|
|
|
#include "ui/gfx/codec/png_codec.h"
|
|
|
|
#include "ui/gfx/size.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
2010-08-09 21:13:43 +02:00
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
namespace {
|
2010-08-09 21:13:43 +02:00
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
base::LazyInstance<ui::Clipboard> clipboard = LAZY_INSTANCE_INITIALIZER;
|
|
|
|
|
|
|
|
} // anonymous namespace
|
2010-08-09 21:13:43 +02:00
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
SimpleClipboardClient::SimpleClipboardClient() {
|
2010-08-09 21:13:43 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
SimpleClipboardClient::~SimpleClipboardClient() {
|
|
|
|
}
|
2010-08-09 21:13:43 +02:00
|
|
|
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
ui::Clipboard* SimpleClipboardClient::GetClipboard() {
|
2010-08-09 21:13:43 +02:00
|
|
|
return clipboard.Pointer();
|
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
uint64 SimpleClipboardClient::GetSequenceNumber(ui::Clipboard::Buffer buffer) {
|
|
|
|
return GetClipboard()->GetSequenceNumber(buffer);
|
2011-11-05 00:12:18 +01:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
bool SimpleClipboardClient::IsFormatAvailable(
|
|
|
|
const ui::Clipboard::FormatType& format,
|
|
|
|
ui::Clipboard::Buffer buffer) {
|
|
|
|
return GetClipboard()->IsFormatAvailable(format, buffer);
|
2010-08-09 21:13:43 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
void SimpleClipboardClient::ReadAvailableTypes(ui::Clipboard::Buffer buffer,
|
|
|
|
std::vector<string16>* types,
|
|
|
|
bool* contains_filenames) {
|
|
|
|
return GetClipboard()->ReadAvailableTypes(buffer, types,
|
2011-11-05 00:12:18 +01:00
|
|
|
contains_filenames);
|
2011-05-16 18:56:12 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
void SimpleClipboardClient::ReadText(ui::Clipboard::Buffer buffer,
|
|
|
|
string16* result) {
|
|
|
|
GetClipboard()->ReadText(buffer, result);
|
2010-08-09 21:13:43 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
void SimpleClipboardClient::ReadAsciiText(ui::Clipboard::Buffer buffer,
|
|
|
|
std::string* result) {
|
|
|
|
GetClipboard()->ReadAsciiText(buffer, result);
|
2010-08-09 21:13:43 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
void SimpleClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer,
|
|
|
|
string16* markup,
|
|
|
|
GURL* url, uint32* fragment_start,
|
|
|
|
uint32* fragment_end) {
|
2010-08-09 21:13:43 +02:00
|
|
|
std::string url_str;
|
2011-12-16 15:51:10 +01:00
|
|
|
GetClipboard()->ReadHTML(buffer, markup, url ? &url_str : NULL,
|
|
|
|
fragment_start, fragment_end);
|
2010-08-09 21:13:43 +02:00
|
|
|
if (url)
|
|
|
|
*url = GURL(url_str);
|
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
void SimpleClipboardClient::ReadImage(ui::Clipboard::Buffer buffer,
|
|
|
|
std::string* data) {
|
|
|
|
SkBitmap bitmap = GetClipboard()->ReadImage(buffer);
|
2011-05-16 18:56:12 +02:00
|
|
|
if (bitmap.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<unsigned char> png_data;
|
|
|
|
SkAutoLockPixels lock(bitmap);
|
|
|
|
if (gfx::PNGCodec::EncodeWithCompressionLevel(
|
|
|
|
static_cast<const unsigned char*>(bitmap.getPixels()),
|
|
|
|
gfx::PNGCodec::FORMAT_BGRA,
|
|
|
|
gfx::Size(bitmap.width(), bitmap.height()),
|
|
|
|
bitmap.rowBytes(),
|
|
|
|
false,
|
|
|
|
std::vector<gfx::PNGCodec::Comment>(),
|
|
|
|
Z_BEST_SPEED,
|
|
|
|
&png_data)) {
|
|
|
|
data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)),
|
|
|
|
png_data.size());
|
|
|
|
}
|
2010-08-09 21:13:43 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
void SimpleClipboardClient::ReadCustomData(ui::Clipboard::Buffer buffer,
|
|
|
|
const string16& type,
|
|
|
|
string16* data) {
|
|
|
|
GetClipboard()->ReadCustomData(buffer, type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
webkit_glue::ClipboardClient::WriteContext*
|
|
|
|
SimpleClipboardClient::CreateWriteContext() {
|
|
|
|
return NULL;
|
|
|
|
}
|