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

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
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_clipboard_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..30ef8011320f8f5e34046c630fbeb209e429798d 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,36 @@ 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;
case PP_FLASH_CLIPBOARD_TYPE_SELECTION:
- return WebKit::WebClipboard::BufferSelection;
- 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_SELECTION;
}
+ NOTREACHED();
+ 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 +72,155 @@ 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:
+ break;
+ }
+
+ NOTREACHED();
+ return PP_FALSE;
}
-PP_Var PPB_Flash_Clipboard_Impl::ReadPlainText(
+PP_Var PPB_Flash_Clipboard_Impl::ReadData(
PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type) {
- WebKit::WebClipboard* web_clipboard =
- WebKit::webKitPlatformSupport()->clipboard();
- if (!web_clipboard) {
- NOTREACHED();
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) {
+ if (!Init())
+ return PP_MakeUndefined();
+
+ if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
+ NOTIMPLEMENTED();
+ return PP_MakeUndefined();
+ }
+
+ if (!IsFormatAvailable(instance, clipboard_type, format)) {
return PP_MakeNull();
}
- WebKit::WebCString s =
- web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8();
- return StringVar::StringToPPVar(s);
+
+ 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;
+ uint32 fragment_start;
+ uint32 fragment_end;
+ client_->ReadHTML(buffer_type,
+ &html_stdstr,
+ &gurl,
+ &fragment_start,
+ &fragment_end);
+ return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr));
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
+ break;
+ }
+
+ NOTREACHED();
+ return PP_MakeUndefined();
}
-int32_t PPB_Flash_Clipboard_Impl::WritePlainText(
+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()));
+ return PP_OK;
+ }
+ 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()), "");
+ return PP_OK;
+ }
+ case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
+ break;
+ }
+
+ NOTREACHED();
+ return PP_ERROR_BADARGUMENT;
+}
+
+int32_t PPB_Flash_Clipboard_Impl::WriteData(
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;
-
- if (text_string->value().length() > kMaxClipboardWriteSize)
- return PP_ERROR_NOSPACE;
+ uint32_t data_item_count,
+ const PP_Flash_Clipboard_Format formats[],
+ const PP_Var data_items[]) {
+ if (!Init())
+ return PP_ERROR_FAILED;
if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
NOTIMPLEMENTED();
return PP_ERROR_FAILED;
}
- WebKit::WebClipboard* web_clipboard =
- WebKit::webKitPlatformSupport()->clipboard();
- if (!web_clipboard) {
- NOTREACHED();
- return PP_ERROR_FAILED;
+ ScopedClipboardWriterGlue scw(client_.get());
+ if (data_item_count == 0) {
+ // TODO(raymes): implement clear()
+ return PP_ERROR_NOTSUPPORTED;
+ }
+ for (uint32_t i = 0; i < data_item_count; ++i) {
+ int32_t res = WriteDataItem(formats[i], data_items[i], &scw);
+ if (res != PP_OK) {
+ // Need to clear the objects so nothing is written.
+ scw.Reset();
+ return res;
+ }
}
- web_clipboard->writePlainText(
- WebKit::WebCString(text_string->value()).utf16());
return PP_OK;
}
« no previous file with comments | « 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