Commit fe833c99 authored by brettw@chromium.org's avatar brettw@chromium.org

Convert the flash clipboard API to thunk system.

This adds a new clipboard API and thunks for it, and converts the existing
proxy to use the new system. This adds a UI test for this feature.

BUG=
TEST=included

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106857 0039d316-1c4b-4281-b951-d872f2087c98
parent 56c802fa
......@@ -274,6 +274,9 @@ TEST_F(OutOfProcessPPAPITest, DISABLED_Fullscreen) {
}
#endif
TEST_PPAPI_IN_PROCESS(FlashClipboard)
TEST_PPAPI_OUT_OF_PROCESS(FlashClipboard)
#if defined(OS_POSIX)
#define MAYBE_DirectoryReader FLAKY_DirectoryReader
#else
......
......@@ -121,6 +121,8 @@
'thunk/ppb_file_system_api.h',
'thunk/ppb_file_system_thunk.cc',
'thunk/ppb_find_thunk.cc',
'thunk/ppb_flash_clipboard_api.h',
'thunk/ppb_flash_clipboard_thunk.cc',
'thunk/ppb_flash_fullscreen_thunk.cc',
'thunk/ppb_flash_menu_api.h',
'thunk/ppb_flash_menu_thunk.cc',
......
......@@ -85,23 +85,25 @@
'tests/test_char_set.h',
'tests/test_core.cc',
'tests/test_core.h',
'tests/test_cpp_includes.cc',
'tests/test_crypto.cc',
'tests/test_crypto.h',
'tests/test_cpp_includes.cc',
'tests/test_cursor_control.cc',
'tests/test_cursor_control.h',
'tests/test_directory_reader.cc',
'tests/test_directory_reader.h',
'tests/test_fullscreen.cc',
'tests/test_fullscreen.h',
'tests/test_flash_fullscreen.cc',
'tests/test_flash_fullscreen.h',
'tests/test_file_io.cc',
'tests/test_file_io.h',
'tests/test_file_ref.cc',
'tests/test_file_ref.h',
'tests/test_file_system.cc',
'tests/test_file_system.h',
'tests/test_flash_clipboard.cc',
'tests/test_flash_clipboard.h',
'tests/test_flash_fullscreen.cc',
'tests/test_flash_fullscreen.h',
'tests/test_fullscreen.cc',
'tests/test_fullscreen.h',
'tests/test_graphics_2d.cc',
'tests/test_graphics_2d.h',
'tests/test_graphics_3d.cc',
......
......@@ -240,7 +240,7 @@ void InterfaceList::AddFlashInterfaces() {
AddProxy(API_ID_PPB_FLASH_CLIPBOARD,
&ProxyFactory<PPB_Flash_Clipboard_Proxy>);
AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE, API_ID_PPB_FLASH_CLIPBOARD,
PPB_Flash_Clipboard_Proxy::GetInterface());
thunk::GetPPB_Flash_Clipboard_Thunk());
AddProxy(API_ID_PPB_FLASH_FILE_MODULELOCAL,
&ProxyFactory<PPB_Flash_File_ModuleLocal_Proxy>);
......
......@@ -9,12 +9,18 @@
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/thunk/enter.h"
using ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI;
namespace ppapi {
namespace proxy {
namespace {
typedef thunk::EnterFunctionNoLock<PPB_Flash_Clipboard_FunctionAPI>
EnterFlashClipboardNoLock;
bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) {
return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD ||
clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION ||
......@@ -27,90 +33,66 @@ bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) {
format == PP_FLASH_CLIPBOARD_FORMAT_HTML;
}
PP_Bool IsFormatAvailable(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
if (!dispatcher)
return PP_FALSE;
} // namespace
PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher)
: InterfaceProxy(dispatcher) {
}
PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() {
}
PPB_Flash_Clipboard_FunctionAPI*
PPB_Flash_Clipboard_Proxy::AsPPB_Flash_Clipboard_FunctionAPI() {
return this;
}
PP_Bool PPB_Flash_Clipboard_Proxy::IsFormatAvailable(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
return PP_FALSE;
bool result = false;
dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable(
dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable(
API_ID_PPB_FLASH_CLIPBOARD,
instance_id,
instance,
static_cast<int>(clipboard_type),
static_cast<int>(format),
&result));
return PP_FromBool(result);
}
PP_Var ReadPlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
if (!dispatcher)
return PP_MakeUndefined();
PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type) {
if (!IsValidClipboardType(clipboard_type))
return PP_MakeUndefined();
ReceiveSerializedVarReturnValue result;
dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText(
API_ID_PPB_FLASH_CLIPBOARD, instance_id,
dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText(
API_ID_PPB_FLASH_CLIPBOARD, instance,
static_cast<int>(clipboard_type), &result));
return result.Return(dispatcher);
return result.Return(dispatcher());
}
int32_t WritePlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Var text) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t PPB_Flash_Clipboard_Proxy::WritePlainText(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
const PP_Var& text) {
if (!IsValidClipboardType(clipboard_type))
return PP_ERROR_BADARGUMENT;
dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText(
dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText(
API_ID_PPB_FLASH_CLIPBOARD,
instance_id,
instance,
static_cast<int>(clipboard_type),
SerializedVarSendInput(dispatcher, text)));
SerializedVarSendInput(dispatcher(), text)));
// Assume success, since it allows us to avoid a sync IPC.
return PP_OK;
}
const PPB_Flash_Clipboard flash_clipboard_interface = {
&IsFormatAvailable,
&ReadPlainText,
&WritePlainText
};
InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher) {
return new PPB_Flash_Clipboard_Proxy(dispatcher);
}
} // namespace
PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher)
: InterfaceProxy(dispatcher),
ppb_flash_clipboard_impl_(NULL) {
if (!dispatcher->IsPlugin()) {
ppb_flash_clipboard_impl_ = static_cast<const PPB_Flash_Clipboard*>(
dispatcher->local_get_interface()(PPB_FLASH_CLIPBOARD_INTERFACE));
}
}
PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() {
}
// static
const PPB_Flash_Clipboard* PPB_Flash_Clipboard_Proxy::GetInterface() {
return &flash_clipboard_interface;
}
bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
......@@ -126,35 +108,47 @@ bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
}
void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
PP_Instance instance_id,
PP_Instance instance,
int clipboard_type,
int format,
bool* result) {
*result = PP_ToBool(ppb_flash_clipboard_impl_->IsFormatAvailable(
instance_id,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
static_cast<PP_Flash_Clipboard_Format>(format)));
EnterFlashClipboardNoLock enter(instance, true);
if (enter.succeeded()) {
*result = PP_ToBool(enter.functions()->IsFormatAvailable(
instance,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
static_cast<PP_Flash_Clipboard_Format>(format)));
} else {
*result = false;
}
}
void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText(
PP_Instance instance_id,
PP_Instance instance,
int clipboard_type,
SerializedVarReturnValue result) {
result.Return(dispatcher(),
ppb_flash_clipboard_impl_->ReadPlainText(
instance_id,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type)));
EnterFlashClipboardNoLock enter(instance, true);
if (enter.succeeded()) {
result.Return(dispatcher(),
enter.functions()->ReadPlainText(
instance,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type)));
}
}
void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText(
PP_Instance instance_id,
PP_Instance instance,
int clipboard_type,
SerializedVarReceiveInput text) {
int32_t result = ppb_flash_clipboard_impl_->WritePlainText(
instance_id,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
text.Get(dispatcher()));
LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly.";
EnterFlashClipboardNoLock enter(instance, true);
if (enter.succeeded()) {
int32_t result = enter.functions()->WritePlainText(
instance,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
text.Get(dispatcher()));
DLOG_IF(WARNING, result != PP_OK)
<< "Write to clipboard failed unexpectedly.";
}
}
} // namespace proxy
......
......@@ -7,6 +7,7 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/thunk/ppb_flash_clipboard_api.h"
struct PPB_Flash_Clipboard;
......@@ -16,33 +17,44 @@ namespace proxy {
class SerializedVarReceiveInput;
class SerializedVarReturnValue;
class PPB_Flash_Clipboard_Proxy : public InterfaceProxy {
class PPB_Flash_Clipboard_Proxy
: public InterfaceProxy,
public thunk::PPB_Flash_Clipboard_FunctionAPI {
public:
PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher);
virtual ~PPB_Flash_Clipboard_Proxy();
static const PPB_Flash_Clipboard* GetInterface();
// FunctionGroupBase overrides.
thunk::PPB_Flash_Clipboard_FunctionAPI* AsPPB_Flash_Clipboard_FunctionAPI()
OVERRIDE;
// PPB_Flash_Clipboard_FunctionAPI implementation.
virtual PP_Bool IsFormatAvailable(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) OVERRIDE;
virtual PP_Var ReadPlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type) OVERRIDE;
virtual int32_t WritePlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
const PP_Var& text) OVERRIDE;
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
static const ApiID kApiID = API_ID_PPB_FLASH_CLIPBOARD;
private:
// Message handlers.
void OnMsgIsFormatAvailable(PP_Instance instance_id,
void OnMsgIsFormatAvailable(PP_Instance instance,
int clipboard_type,
int format,
bool* result);
void OnMsgReadPlainText(PP_Instance instance_id,
void OnMsgReadPlainText(PP_Instance instance,
int clipboard_type,
SerializedVarReturnValue result);
void OnMsgWritePlainText(PP_Instance instance_id,
void OnMsgWritePlainText(PP_Instance instance,
int clipboard_type,
SerializedVarReceiveInput text);
// When this proxy is in the host side, this value caches the interface
// pointer so we don't have to retrieve it from the dispatcher each time.
// In the plugin, this value is always NULL.
const PPB_Flash_Clipboard* ppb_flash_clipboard_impl_;
};
} // namespace proxy
......
......@@ -12,6 +12,7 @@
#define FOR_ALL_PPAPI_FUNCTION_APIS(F) \
F(PPB_CharSet_FunctionAPI) \
F(PPB_CursorControl_FunctionAPI) \
F(PPB_Flash_Clipboard_FunctionAPI) \
F(PPB_Font_FunctionAPI) \
F(PPB_Fullscreen_FunctionAPI) \
F(PPB_Instance_FunctionAPI) \
......
// 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 "ppapi/tests/test_flash_clipboard.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/point.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(FlashClipboard);
TestFlashClipboard::TestFlashClipboard(TestingInstance* instance)
: TestCase(instance),
clipboard_interface_(NULL) {
}
bool TestFlashClipboard::Init() {
clipboard_interface_ = static_cast<const PPB_Flash_Clipboard*>(
pp::Module::Get()->GetBrowserInterface(PPB_FLASH_CLIPBOARD_INTERFACE));
return !!clipboard_interface_;
}
void TestFlashClipboard::RunTest() {
RUN_TEST(ReadWrite);
}
std::string TestFlashClipboard::TestReadWrite() {
std::string input_str("Hello, world");
pp::Var input_var(input_str);
clipboard_interface_->WritePlainText(instance_->pp_instance(),
PP_FLASH_CLIPBOARD_TYPE_STANDARD,
input_var.pp_var());
ASSERT_TRUE(clipboard_interface_->IsFormatAvailable(
instance_->pp_instance(),
PP_FLASH_CLIPBOARD_TYPE_STANDARD,
PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT));
pp::Var result_var(pp::Var::PassRef(),
clipboard_interface_->ReadPlainText(instance_->pp_instance(),
PP_FLASH_CLIPBOARD_TYPE_STANDARD));
ASSERT_TRUE(result_var.is_string());
std::string result_str = result_var.AsString();
ASSERT_TRUE(result_str == input_str);
PASS();
}
// 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_TESTS_TEST_FLASH_CLIPBOARD_H_
#define PPAPI_TESTS_TEST_FLASH_CLIPBOARD_H_
#include <string>
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/tests/test_case.h"
#include "ppapi/tests/test_utils.h"
class TestFlashClipboard : public TestCase {
public:
explicit TestFlashClipboard(TestingInstance* instance);
// TestCase implementation.
virtual bool Init();
virtual void RunTest();
private:
std::string TestReadWrite();
const PPB_Flash_Clipboard* clipboard_interface_;
};
#endif // PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_
#define PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_
#ifndef PPAPI_TESTS_TEST_FLASH_FULLSCREEN_H_
#define PPAPI_TESTS_TEST_FLASH_FULLSCREEN_H_
#include <string>
......@@ -38,4 +38,4 @@ class TestFlashFullscreen : public TestCase {
TestCompletionCallback normal_callback_;
};
#endif // PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_
#endif // PPAPI_TESTS_TEST_FLASH_FULLSCREEN_H_
// 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_THUNK_PPB_FLASH_CLIPBOARD_API_H_
#define PPAPI_THUNK_PPB_FLASH_CLIPBOARD_API_H_
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/shared_impl/api_id.h"
namespace ppapi {
namespace thunk {
class PPB_Flash_Clipboard_FunctionAPI {
public:
virtual ~PPB_Flash_Clipboard_FunctionAPI() {}
virtual PP_Bool IsFormatAvailable(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) = 0;
virtual PP_Var ReadPlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type) = 0;
virtual int32_t WritePlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
const PP_Var& text) = 0;
static const ApiID kApiID = API_ID_PPB_FLASH_CLIPBOARD;
};
} // namespace thunk
} // namespace ppapi
#endif // PPAPI_THUNK_PPB_FLASH_CLIPBOARD_API_H_
// 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 "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_flash_clipboard_api.h"
namespace ppapi {
namespace thunk {
namespace {
typedef EnterFunction<PPB_Flash_Clipboard_FunctionAPI> EnterFlashClipboard;
PP_Bool IsFormatAvailable(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
EnterFlashClipboard enter(instance, true);
if (enter.failed())
return PP_FALSE;
return enter.functions()->IsFormatAvailable(instance, clipboard_type, format);
}
PP_Var ReadPlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type) {
EnterFlashClipboard enter(instance, true);
if (enter.failed())
return PP_MakeUndefined();
return enter.functions()->ReadPlainText(instance, clipboard_type);
}
int32_t WritePlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Var text) {
EnterFlashClipboard enter(instance, true);
if (enter.failed())
return PP_ERROR_NOINTERFACE;
return enter.functions()->WritePlainText(instance, clipboard_type, text);
}
const PPB_Flash_Clipboard g_ppb_flash_clipboard_thunk = {
&IsFormatAvailable,
&ReadPlainText,
&WritePlainText
};
} // namespace
const PPB_Flash_Clipboard* GetPPB_Flash_Clipboard_Thunk() {
return &g_ppb_flash_clipboard_thunk;
}
} // namespace thunk
} // namespace ppapi
......@@ -33,6 +33,7 @@ struct PPB_BufferTrusted;
struct PPB_Context3DTrusted_Dev;
struct PPB_FileChooserTrusted;
struct PPB_FileIOTrusted;
struct PPB_Flash_Clipboard;
struct PPB_Flash_Menu;
struct PPB_Flash_NetConnector;
struct PPB_Flash_TCPSocket;
......@@ -59,6 +60,7 @@ PPAPI_THUNK_EXPORT const PPB_Context3DTrusted_Dev*
PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted*
GetPPB_FileChooser_Trusted_Thunk();
PPAPI_THUNK_EXPORT const PPB_FileIOTrusted* GetPPB_FileIOTrusted_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_Clipboard* GetPPB_Flash_Clipboard_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector*
GetPPB_Flash_NetConnector_Thunk();
......
......@@ -14,6 +14,7 @@
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_cursor_control_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
#include "webkit/plugins/ppapi/ppb_font_impl.h"
#include "webkit/plugins/ppapi/ppb_text_input_impl.h"
#include "webkit/plugins/ppapi/resource_creation_impl.h"
......@@ -88,6 +89,9 @@ HostGlobals::~HostGlobals() {
case ::ppapi::API_ID_RESOURCE_CREATION:
proxy.reset(new ResourceCreationImpl(instance));
break;
case ::ppapi::API_ID_PPB_FLASH_CLIPBOARD:
proxy.reset(new PPB_Flash_Clipboard_Impl(instance));
break;
default:
NOTREACHED();
}
......
......@@ -273,7 +273,7 @@ const void* GetInterface(const char* name) {
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();
return ::ppapi::thunk::GetPPB_Flash_Clipboard_Thunk();
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)
......
......@@ -60,47 +60,53 @@ WebKit::WebClipboard::Format ConvertClipboardFormat(
}
}
PP_Bool IsFormatAvailable(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
// If you don't give us an instance, we don't give you anything.
PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
if (!instance)
return PP_FALSE;
} // namespace
PPB_Flash_Clipboard_Impl::PPB_Flash_Clipboard_Impl(PluginInstance* instance)
: instance_(instance) {
}
PPB_Flash_Clipboard_Impl::~PPB_Flash_Clipboard_Impl() {
}
::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI*
PPB_Flash_Clipboard_Impl::AsPPB_Flash_Clipboard_FunctionAPI() {
return this;
}
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();
return PP_FALSE;
}
return BoolToPPBool(
web_clipboard->isFormatAvailable(ConvertClipboardFormat(format),
ConvertClipboardType(clipboard_type)));
}
PP_Var ReadPlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type) {
PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id);
if (!instance)
return PP_MakeNull();
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(instance->module()->pp_module(), s);
return StringVar::StringToPPVar(instance_->module()->pp_module(), s);
}
int32_t WritePlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Var text) {
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;
......@@ -125,19 +131,5 @@ int32_t WritePlainText(PP_Instance instance_id,
return PP_OK;
}
const PPB_Flash_Clipboard ppb_flash_clipboard = {
&IsFormatAvailable,
&ReadPlainText,
&WritePlainText,
};
} // namespace
// static
const PPB_Flash_Clipboard*
PPB_Flash_Clipboard_Impl::GetInterface() {
return &ppb_flash_clipboard;
}
} // namespace ppapi
} // namespace webkit
......@@ -5,14 +5,43 @@
#ifndef WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ppapi/shared_impl/function_group_base.h"
#include "ppapi/thunk/ppb_flash_clipboard_api.h"
struct PPB_Flash_Clipboard;
namespace webkit {
namespace ppapi {
class PPB_Flash_Clipboard_Impl {
class PluginInstance;
class PPB_Flash_Clipboard_Impl
: public ::ppapi::FunctionGroupBase,
public ::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI {
public:
static const PPB_Flash_Clipboard* GetInterface();
PPB_Flash_Clipboard_Impl(PluginInstance* instance);
virtual ~PPB_Flash_Clipboard_Impl();
// FunctionGroupBase overrides.
virtual ::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI*
AsPPB_Flash_Clipboard_FunctionAPI() OVERRIDE;
// PPB_Flash_Clipboard_FunctionAPI implementation.
virtual PP_Bool IsFormatAvailable(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) OVERRIDE;
virtual PP_Var ReadPlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type) OVERRIDE;
virtual int32_t WritePlainText(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
const PP_Var& text) OVERRIDE;
private:
PluginInstance* instance_;
DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Clipboard_Impl);
};
} // namespace ppapi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment