0

Pepper/Flapper: Add very basic clipboard support.

Note that this is a trusted private interface; we rely on Flash to do a user
action check.

BUG=none
TEST=Trung can cut-and-paste in his Flapper

Review URL: http://codereview.chromium.org/6611034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76857 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
viettrungluu@chromium.org
2011-03-04 01:43:39 +00:00
parent 24fc860b86
commit c5f29a5ef0
7 changed files with 164 additions and 2 deletions

@ -0,0 +1,33 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
#define PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_var.h"
#define PPB_FLASH_CLIPBOARD_INTERFACE "PPB_Flash_Clipboard;2"
typedef enum {
PP_FLASH_CLIPBOARD_TYPE_STANDARD = 0,
PP_FLASH_CLIPBOARD_TYPE_SELECTION = 1,
PP_FLASH_CLIPBOARD_TYPE_DRAG = 2
} PP_Flash_Clipboard_Type;
struct PPB_Flash_Clipboard {
// Reads plain text data from the clipboard.
struct PP_Var (*ReadPlainText)(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type);
// Writes plain text data to the clipboard. If |text| is too large, it will
// return |PP_ERROR_NOSPACE| (and not write to the clipboard).
int32_t (*WritePlainText)(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
struct PP_Var text);
// TODO(vtl): More formats, a |IsFormatAvailable()|, ....
};
#endif // PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_

@ -10,8 +10,6 @@
#include "ppapi/c/pp_point.h"
#include "ppapi/c/pp_resource.h"
// PPB_Flash -------------------------------------------------------------------
#define PPB_FLASH_MENU_INTERFACE "PPB_Flash_Menu;1"
struct PP_CompletionCallback;

@ -82,6 +82,8 @@
# Private interfaces.
'c/private/ppb_flash.h',
'c/private/ppb_flash_clipboard.h',
'c/private/ppb_flash_file.h',
'c/private/ppb_flash_menu.h',
'c/private/ppb_flash_net_connector.h',
'c/private/ppb_nacl_private.h',

@ -297,6 +297,8 @@
'../plugins/ppapi/ppb_file_ref_impl.h',
'../plugins/ppapi/ppb_file_system_impl.cc',
'../plugins/ppapi/ppb_file_system_impl.h',
'../plugins/ppapi/ppb_flash_clipboard_impl.cc',
'../plugins/ppapi/ppb_flash_clipboard_impl.h',
'../plugins/ppapi/ppb_flash_file_impl.cc',
'../plugins/ppapi/ppb_flash_file_impl.h',
'../plugins/ppapi/ppb_flash_impl.cc',

@ -50,6 +50,7 @@
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/c/private/ppb_flash_file.h"
#include "ppapi/c/private/ppb_flash_menu.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
@ -70,6 +71,7 @@
#include "webkit/plugins/ppapi/ppb_file_io_impl.h"
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_file_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_menu_impl.h"
@ -250,6 +252,8 @@ const void* GetInterface(const char* name) {
return PluginInstance::GetFindInterface();
if (strcmp(name, PPB_FLASH_INTERFACE) == 0)
return PPB_Flash_Impl::GetInterface();
if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE) == 0)
return PPB_Flash_Clipboard_Impl::GetInterface();
if (strcmp(name, PPB_FLASH_FILE_FILEREF_INTERFACE) == 0)
return PPB_Flash_File_FileRef_Impl::GetInterface();
if (strcmp(name, PPB_FLASH_FILE_MODULELOCAL_INTERFACE) == 0)

@ -0,0 +1,102 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
#include <algorithm>
#include <string>
#include "base/logging.h"
#include "base/ref_counted.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebClipboard.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
#include "webkit/plugins/ppapi/var.h"
namespace webkit {
namespace ppapi {
namespace {
const size_t kMaxClipboardWriteSize = 1000000;
WebKit::WebClipboard::Buffer ConvertClipboardType(
PP_Flash_Clipboard_Type type) {
switch (type) {
case PP_FLASH_CLIPBOARD_TYPE_STANDARD:
return WebKit::WebClipboard::BufferStandard;
case PP_FLASH_CLIPBOARD_TYPE_SELECTION:
return WebKit::WebClipboard::BufferSelection;
case PP_FLASH_CLIPBOARD_TYPE_DRAG:
return WebKit::WebClipboard::BufferDrag;
default:
NOTREACHED();
return WebKit::WebClipboard::BufferStandard;
}
}
PP_Var ReadPlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeNull();
WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
if (!web_clipboard) {
NOTREACHED();
return PP_MakeNull();
}
WebKit::WebCString s =
web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8();
return StringVar::StringToPPVar(instance->module(), s);
}
int32_t WritePlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Var text) {
scoped_refptr<StringVar> text_string(StringVar::FromPPVar(text));
if (!text_string)
return PP_ERROR_BADARGUMENT;
if (text_string->value().length() > kMaxClipboardWriteSize)
return PP_ERROR_NOSPACE;
if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
NOTIMPLEMENTED();
return PP_ERROR_FAILED;
}
WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
if (!web_clipboard) {
NOTREACHED();
return PP_ERROR_FAILED;
}
web_clipboard->writePlainText(
WebKit::WebCString(text_string->value()).utf16());
return PP_OK;
}
const PPB_Flash_Clipboard ppb_flash_clipboard = {
&ReadPlainText,
&WritePlainText,
};
} // namespace
// static
const PPB_Flash_Clipboard*
PPB_Flash_Clipboard_Impl::GetInterface() {
return &ppb_flash_clipboard;
}
} // namespace ppapi
} // namespace webkit

@ -0,0 +1,21 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_
struct PPB_Flash_Clipboard;
namespace webkit {
namespace ppapi {
class PPB_Flash_Clipboard_Impl {
public:
static const PPB_Flash_Clipboard* GetInterface();
};
} // namespace ppapi
} // namespace webkit
#endif // WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_