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

Unified Diff: webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc

Issue 9212066: Modified the flash cipboard interface to add html clipboard support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
index 3f2e083d2c5895de85759a4668896be7f20fe9ed..4639d59f9e25f6df88489a5a430e85db57d7b1e1 100644
--- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
@@ -9,14 +9,12 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
+#include "base/utf_string_conversions.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/shared_impl/var.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebClipboard.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "webkit/glue/clipboard_client.h"
+#include "webkit/glue/scoped_clipboard_writer_glue.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/host_globals.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
@@ -30,37 +28,38 @@ namespace {
const size_t kMaxClipboardWriteSize = 1000000;
-WebKit::WebClipboard::Buffer ConvertClipboardType(
+ui::Clipboard::Buffer ConvertClipboardType(
PP_Flash_Clipboard_Type type) {
switch (type) {
case PP_FLASH_CLIPBOARD_TYPE_STANDARD:
- return WebKit::WebClipboard::BufferStandard;
+ return ui::Clipboard::BUFFER_STANDARD;
+ break;
case PP_FLASH_CLIPBOARD_TYPE_SELECTION:
- return WebKit::WebClipboard::BufferSelection;
+ return ui::Clipboard::BUFFER_SELECTION;
default:
NOTREACHED();
- return WebKit::WebClipboard::BufferStandard;
- }
-}
-
-WebKit::WebClipboard::Format ConvertClipboardFormat(
- PP_Flash_Clipboard_Format format) {
- switch (format) {
- case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT:
- return WebKit::WebClipboard::FormatPlainText;
- case PP_FLASH_CLIPBOARD_FORMAT_HTML:
- return WebKit::WebClipboard::FormatHTML;
- case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
- default:
- NOTREACHED();
- return WebKit::WebClipboard::FormatPlainText; // Gotta return something.
+ return ui::Clipboard::BUFFER_STANDARD;
}
}
} // namespace
PPB_Flash_Clipboard_Impl::PPB_Flash_Clipboard_Impl(PluginInstance* instance)
- : instance_(instance) {
+ : instance_(instance),
+ client_() {
+}
+
+bool PPB_Flash_Clipboard_Impl::Init() {
+ // Initialize the ClipboardClient for writing to the clipboard.
+ if (!client_.get()) {
+ if (!instance_)
+ return false;
+ PluginDelegate* plugin_delegate = instance_->delegate();
+ if (!plugin_delegate)
+ return false;
+ client_.reset(plugin_delegate->CreateClipboardClient());
+ }
+ return true;
}
PPB_Flash_Clipboard_Impl::~PPB_Flash_Clipboard_Impl() {
@@ -75,56 +74,174 @@ PP_Bool PPB_Flash_Clipboard_Impl::IsFormatAvailable(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
- WebKit::WebClipboard* web_clipboard =
- WebKit::webKitPlatformSupport()->clipboard();
- if (!web_clipboard) {
- NOTREACHED();
+ if (!Init())
+ return PP_FALSE;
+
+ if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
+ NOTIMPLEMENTED();
return PP_FALSE;
}
- return BoolToPPBool(
- web_clipboard->isFormatAvailable(ConvertClipboardFormat(format),
- ConvertClipboardType(clipboard_type)));
+
+ ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type);
+ switch(format) {
+ case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: {
+ bool plain = client_->IsFormatAvailable(
+ ui::Clipboard::GetPlainTextFormatType(), buffer_type);
+ bool plainw = client_->IsFormatAvailable(
+ ui::Clipboard::GetPlainTextWFormatType(), buffer_type);
+ return BoolToPPBool(plain || plainw);
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_HTML: {
+ return BoolToPPBool(client_->IsFormatAvailable(
+ ui::Clipboard::GetHtmlFormatType(), buffer_type));
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_INVALID: {
+ default:
viettrungluu 2012/02/08 22:25:01 eh? I'd do a |break;| for the PP_FLASH_CLIPBOARD_F
raymes 2012/02/09 00:20:27 Done.
+ NOTREACHED();
+ return PP_FALSE;
+ }
+ }
}
PP_Var PPB_Flash_Clipboard_Impl::ReadPlainText(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type) {
- WebKit::WebClipboard* web_clipboard =
- WebKit::webKitPlatformSupport()->clipboard();
- if (!web_clipboard) {
- NOTREACHED();
- return PP_MakeNull();
- }
- WebKit::WebCString s =
- web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8();
- return StringVar::StringToPPVar(s);
+ return ReadData(instance, clipboard_type,
+ PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
}
int32_t PPB_Flash_Clipboard_Impl::WritePlainText(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
const PP_Var& text) {
- StringVar* text_string = StringVar::FromPPVar(text);
- if (!text_string)
- return PP_ERROR_BADARGUMENT;
+ PP_Flash_Clipboard_Data_Item item =
+ {PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, text};
+ return WriteData(instance, clipboard_type, 1, &item);
+}
- if (text_string->value().length() > kMaxClipboardWriteSize)
- return PP_ERROR_NOSPACE;
+
+PP_Var PPB_Flash_Clipboard_Impl::ReadData(
+ PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) {
+ if (!Init())
+ return PP_MakeNull();
if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
NOTIMPLEMENTED();
- return PP_ERROR_FAILED;
+ return PP_MakeNull();
+ }
+
+ if (!IsFormatAvailable(instance, clipboard_type, format)) {
+ return PP_MakeNull();
}
- WebKit::WebClipboard* web_clipboard =
- WebKit::webKitPlatformSupport()->clipboard();
- if (!web_clipboard) {
- NOTREACHED();
+ ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type);
+
+ switch(format) {
+ case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: {
+ if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
+ buffer_type)) {
+ string16 text;
+ client_->ReadText(buffer_type, &text);
+ if (!text.empty())
+ return StringVar::StringToPPVar(UTF16ToUTF8(text));
+ }
+
+ if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
+ buffer_type)) {
+ std::string text;
+ client_->ReadAsciiText(buffer_type, &text);
+ if (!text.empty())
+ return StringVar::StringToPPVar(text);
+ }
+ return PP_MakeNull();
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_HTML: {
+ string16 html_stdstr;
+ GURL gurl;
+ unsigned fragment_start;
+ unsigned fragment_end;
+ client_->ReadHTML(buffer_type, &html_stdstr, &gurl,
+ static_cast<uint32*>(&fragment_start),
+ static_cast<uint32*>(&fragment_end));
+ return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr));
+ break;
viettrungluu 2012/02/08 22:25:01 no break
raymes 2012/02/09 00:20:27 Done.
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
+ default: {
viettrungluu 2012/02/08 22:25:01 This one makes more sense (though the braces are u
raymes 2012/02/09 00:20:27 Done. The default style was copied from the existi
+ NOTREACHED();
+ return PP_MakeUndefined();
+ }
+ }
+
+ return PP_MakeNull();
+}
+
+int32_t PPB_Flash_Clipboard_Impl::WriteDataItem(
+ const PP_Flash_Clipboard_Format format,
+ const PP_Var& data,
+ ScopedClipboardWriterGlue* scw) {
+ switch(format) {
+ case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: {
+ StringVar* text_string = StringVar::FromPPVar(data);
+ if (!text_string)
+ return PP_ERROR_BADARGUMENT;
+
+ if (text_string->value().length() > kMaxClipboardWriteSize)
+ return PP_ERROR_NOSPACE;
+
+ scw->WriteText(UTF8ToUTF16(text_string->value()));
+ break;
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_HTML: {
+ StringVar* text_string = StringVar::FromPPVar(data);
+ if (!text_string)
+ return PP_ERROR_BADARGUMENT;
+
+ if (text_string->value().length() > kMaxClipboardWriteSize)
+ return PP_ERROR_NOSPACE;
+
+ scw->WriteHTML(UTF8ToUTF16(text_string->value()), "");
+ break;
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
+ default: {
viettrungluu 2012/02/08 22:25:01 "
raymes 2012/02/09 00:20:27 Done.
+ NOTREACHED();
+ return PP_ERROR_BADARGUMENT;
+ }
+ }
+ return PP_OK;
+}
+
+int32_t PPB_Flash_Clipboard_Impl::WriteData(
+ PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ uint32_t data_item_count,
+ const struct PP_Flash_Clipboard_Data_Item data_items[]) {
+ if (!Init())
+ return PP_ERROR_FAILED;
+
+ if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
+ NOTIMPLEMENTED();
return PP_ERROR_FAILED;
}
- web_clipboard->writePlainText(
- WebKit::WebCString(text_string->value()).utf16());
+ ScopedClipboardWriterGlue scw(client_.get());
+ if (data_item_count == 0) {
+ // TODO: implement clear()
+ return PP_OK;
+ }
+ for (uint32_t i = 0; i < data_item_count; ++i) {
+ int32_t res = WriteDataItem(data_items[i].format, data_items[i].data,
+ &scw);
+ if (res != PP_OK) {
+ // Need to clear the objects so nothing is written.
+ scw.Reset();
+ return res;
+ }
+ }
+
return PP_OK;
}
« ppapi/tests/test_flash_clipboard.h ('K') | « webkit/plugins/ppapi/ppb_flash_clipboard_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698